]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.8.2-201303111845.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.2-201303111845.patch
CommitLineData
789b9290
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 20d5318..d5cec9c 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 ab98fdd..6b19938 100644
1544--- a/arch/arm/include/asm/delay.h
1545+++ b/arch/arm/include/asm/delay.h
1546@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1547 void (*delay)(unsigned long);
1548 void (*const_udelay)(unsigned long);
1549 void (*udelay)(unsigned long);
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@@ -47,8 +47,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 9c82f988..514705a 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,7 +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 | L_PTE_NONE;
2070+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2071 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2072 return pte;
2073 }
2074diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2075index f3628fb..a0672dd 100644
2076--- a/arch/arm/include/asm/proc-fns.h
2077+++ b/arch/arm/include/asm/proc-fns.h
2078@@ -75,7 +75,7 @@ extern struct processor {
2079 unsigned int suspend_size;
2080 void (*do_suspend)(void *);
2081 void (*do_resume)(void *);
2082-} processor;
2083+} __do_const processor;
2084
2085 #ifndef MULTI_CPU
2086 extern void cpu_proc_init(void);
2087diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2088index 06e7d50..8a8e251 100644
2089--- a/arch/arm/include/asm/processor.h
2090+++ b/arch/arm/include/asm/processor.h
2091@@ -65,9 +65,8 @@ struct thread_struct {
2092 regs->ARM_cpsr |= PSR_ENDSTATE; \
2093 regs->ARM_pc = pc & ~1; /* pc */ \
2094 regs->ARM_sp = sp; /* sp */ \
2095- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2096- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2097- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2098+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2099+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2100 nommu_start_thread(regs); \
2101 })
2102
2103diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2104index d3a22be..3a69ad5 100644
2105--- a/arch/arm/include/asm/smp.h
2106+++ b/arch/arm/include/asm/smp.h
2107@@ -107,7 +107,7 @@ struct smp_operations {
2108 int (*cpu_disable)(unsigned int cpu);
2109 #endif
2110 #endif
2111-};
2112+} __no_const;
2113
2114 /*
2115 * set platform specific SMP operations
2116diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2117index cddda1f..ff357f7 100644
2118--- a/arch/arm/include/asm/thread_info.h
2119+++ b/arch/arm/include/asm/thread_info.h
2120@@ -77,9 +77,9 @@ struct thread_info {
2121 .flags = 0, \
2122 .preempt_count = INIT_PREEMPT_COUNT, \
2123 .addr_limit = KERNEL_DS, \
2124- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2125- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2126- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2127+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2128+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2129+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2130 .restart_block = { \
2131 .fn = do_no_restart_syscall, \
2132 }, \
2133@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2134 #define TIF_SYSCALL_AUDIT 9
2135 #define TIF_SYSCALL_TRACEPOINT 10
2136 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2137+
2138+/* within 8 bits of TIF_SYSCALL_TRACE
2139+ * to meet flexible second operand requirements
2140+ */
2141+#define TIF_GRSEC_SETXID 12
2142+
2143 #define TIF_USING_IWMMXT 17
2144 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2145 #define TIF_RESTORE_SIGMASK 20
2146@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2147 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2148 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2149 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2150+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2151
2152 /* Checks for any syscall work in entry-common.S */
2153 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2154- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2155+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2156
2157 /*
2158 * Change these and you break ASM code in entry-common.S
2159diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2160index 7e1f760..752fcb7 100644
2161--- a/arch/arm/include/asm/uaccess.h
2162+++ b/arch/arm/include/asm/uaccess.h
2163@@ -18,6 +18,7 @@
2164 #include <asm/domain.h>
2165 #include <asm/unified.h>
2166 #include <asm/compiler.h>
2167+#include <asm/pgtable.h>
2168
2169 #define VERIFY_READ 0
2170 #define VERIFY_WRITE 1
2171@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2172 #define USER_DS TASK_SIZE
2173 #define get_fs() (current_thread_info()->addr_limit)
2174
2175+static inline void pax_open_userland(void)
2176+{
2177+
2178+#ifdef CONFIG_PAX_MEMORY_UDEREF
2179+ if (get_fs() == USER_DS) {
2180+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2181+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2182+ }
2183+#endif
2184+
2185+}
2186+
2187+static inline void pax_close_userland(void)
2188+{
2189+
2190+#ifdef CONFIG_PAX_MEMORY_UDEREF
2191+ if (get_fs() == USER_DS) {
2192+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2193+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2194+ }
2195+#endif
2196+
2197+}
2198+
2199 static inline void set_fs(mm_segment_t fs)
2200 {
2201 current_thread_info()->addr_limit = fs;
2202- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2203+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2204 }
2205
2206 #define segment_eq(a,b) ((a) == (b))
2207@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2208
2209 #define get_user(x,p) \
2210 ({ \
2211+ int __e; \
2212 might_fault(); \
2213- __get_user_check(x,p); \
2214+ pax_open_userland(); \
2215+ __e = __get_user_check(x,p); \
2216+ pax_close_userland(); \
2217+ __e; \
2218 })
2219
2220 extern int __put_user_1(void *, unsigned int);
2221@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2222
2223 #define put_user(x,p) \
2224 ({ \
2225+ int __e; \
2226 might_fault(); \
2227- __put_user_check(x,p); \
2228+ pax_open_userland(); \
2229+ __e = __put_user_check(x,p); \
2230+ pax_close_userland(); \
2231+ __e; \
2232 })
2233
2234 #else /* CONFIG_MMU */
2235@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2236 #define __get_user(x,ptr) \
2237 ({ \
2238 long __gu_err = 0; \
2239+ pax_open_userland(); \
2240 __get_user_err((x),(ptr),__gu_err); \
2241+ pax_close_userland(); \
2242 __gu_err; \
2243 })
2244
2245 #define __get_user_error(x,ptr,err) \
2246 ({ \
2247+ pax_open_userland(); \
2248 __get_user_err((x),(ptr),err); \
2249+ pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253@@ -312,13 +349,17 @@ do { \
2254 #define __put_user(x,ptr) \
2255 ({ \
2256 long __pu_err = 0; \
2257+ pax_open_userland(); \
2258 __put_user_err((x),(ptr),__pu_err); \
2259+ pax_close_userland(); \
2260 __pu_err; \
2261 })
2262
2263 #define __put_user_error(x,ptr,err) \
2264 ({ \
2265+ pax_open_userland(); \
2266 __put_user_err((x),(ptr),err); \
2267+ pax_close_userland(); \
2268 (void) 0; \
2269 })
2270
2271@@ -418,11 +459,44 @@ do { \
2272
2273
2274 #ifdef CONFIG_MMU
2275-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2276-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2277+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2278+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2279+
2280+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2281+{
2282+ unsigned long ret;
2283+
2284+ check_object_size(to, n, false);
2285+ pax_open_userland();
2286+ ret = ___copy_from_user(to, from, n);
2287+ pax_close_userland();
2288+ return ret;
2289+}
2290+
2291+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2292+{
2293+ unsigned long ret;
2294+
2295+ check_object_size(from, n, true);
2296+ pax_open_userland();
2297+ ret = ___copy_to_user(to, from, n);
2298+ pax_close_userland();
2299+ return ret;
2300+}
2301+
2302 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2303-extern unsigned long __must_check __clear_user(void __user *addr, 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_std(void __user *addr, unsigned long n);
2306+
2307+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2308+{
2309+ unsigned long ret;
2310+ pax_open_userland();
2311+ ret = ___clear_user(addr, n);
2312+ pax_close_userland();
2313+ return ret;
2314+}
2315+
2316 #else
2317 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2318 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2319@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2320
2321 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2322 {
2323+ if ((long)n < 0)
2324+ return n;
2325+
2326 if (access_ok(VERIFY_READ, from, n))
2327 n = __copy_from_user(to, from, n);
2328 else /* security hole - plug it */
2329@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2330
2331 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2332 {
2333+ if ((long)n < 0)
2334+ return n;
2335+
2336 if (access_ok(VERIFY_WRITE, to, n))
2337 n = __copy_to_user(to, from, n);
2338 return n;
2339diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2340index 96ee092..37f1844 100644
2341--- a/arch/arm/include/uapi/asm/ptrace.h
2342+++ b/arch/arm/include/uapi/asm/ptrace.h
2343@@ -73,7 +73,7 @@
2344 * ARMv7 groups of PSR bits
2345 */
2346 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2347-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2348+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2349 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2350 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2351
2352diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2353index 60d3b73..d27ee09 100644
2354--- a/arch/arm/kernel/armksyms.c
2355+++ b/arch/arm/kernel/armksyms.c
2356@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2357 #ifdef CONFIG_MMU
2358 EXPORT_SYMBOL(copy_page);
2359
2360-EXPORT_SYMBOL(__copy_from_user);
2361-EXPORT_SYMBOL(__copy_to_user);
2362-EXPORT_SYMBOL(__clear_user);
2363+EXPORT_SYMBOL(___copy_from_user);
2364+EXPORT_SYMBOL(___copy_to_user);
2365+EXPORT_SYMBOL(___clear_user);
2366
2367 EXPORT_SYMBOL(__get_user_1);
2368 EXPORT_SYMBOL(__get_user_2);
2369diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2370index 0f82098..3dbd3ee 100644
2371--- a/arch/arm/kernel/entry-armv.S
2372+++ b/arch/arm/kernel/entry-armv.S
2373@@ -47,6 +47,87 @@
2374 9997:
2375 .endm
2376
2377+ .macro pax_enter_kernel
2378+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2379+ @ make aligned space for saved DACR
2380+ sub sp, sp, #8
2381+ @ save regs
2382+ stmdb sp!, {r1, r2}
2383+ @ read DACR from cpu_domain into r1
2384+ mov r2, sp
2385+ @ assume 8K pages, since we have to split the immediate in two
2386+ bic r2, r2, #(0x1fc0)
2387+ bic r2, r2, #(0x3f)
2388+ ldr r1, [r2, #TI_CPU_DOMAIN]
2389+ @ store old DACR on stack
2390+ str r1, [sp, #8]
2391+#ifdef CONFIG_PAX_KERNEXEC
2392+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2393+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2394+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2395+#endif
2396+#ifdef CONFIG_PAX_MEMORY_UDEREF
2397+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2398+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2399+#endif
2400+ @ write r1 to current_thread_info()->cpu_domain
2401+ str r1, [r2, #TI_CPU_DOMAIN]
2402+ @ write r1 to DACR
2403+ mcr p15, 0, r1, c3, c0, 0
2404+ @ instruction sync
2405+ instr_sync
2406+ @ restore regs
2407+ ldmia sp!, {r1, r2}
2408+#endif
2409+ .endm
2410+
2411+ .macro pax_open_userland
2412+#ifdef CONFIG_PAX_MEMORY_UDEREF
2413+ @ save regs
2414+ stmdb sp!, {r0, r1}
2415+ @ read DACR from cpu_domain into r1
2416+ mov r0, sp
2417+ @ assume 8K pages, since we have to split the immediate in two
2418+ bic r0, r0, #(0x1fc0)
2419+ bic r0, r0, #(0x3f)
2420+ ldr r1, [r0, #TI_CPU_DOMAIN]
2421+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2422+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2423+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2424+ @ write r1 to current_thread_info()->cpu_domain
2425+ str r1, [r0, #TI_CPU_DOMAIN]
2426+ @ write r1 to DACR
2427+ mcr p15, 0, r1, c3, c0, 0
2428+ @ instruction sync
2429+ instr_sync
2430+ @ restore regs
2431+ ldmia sp!, {r0, r1}
2432+#endif
2433+ .endm
2434+
2435+ .macro pax_close_userland
2436+#ifdef CONFIG_PAX_MEMORY_UDEREF
2437+ @ save regs
2438+ stmdb sp!, {r0, r1}
2439+ @ read DACR from cpu_domain into r1
2440+ mov r0, sp
2441+ @ assume 8K pages, since we have to split the immediate in two
2442+ bic r0, r0, #(0x1fc0)
2443+ bic r0, r0, #(0x3f)
2444+ ldr r1, [r0, #TI_CPU_DOMAIN]
2445+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2446+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2447+ @ write r1 to current_thread_info()->cpu_domain
2448+ str r1, [r0, #TI_CPU_DOMAIN]
2449+ @ write r1 to DACR
2450+ mcr p15, 0, r1, c3, c0, 0
2451+ @ instruction sync
2452+ instr_sync
2453+ @ restore regs
2454+ ldmia sp!, {r0, r1}
2455+#endif
2456+ .endm
2457+
2458 .macro pabt_helper
2459 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2460 #ifdef MULTI_PABORT
2461@@ -89,11 +170,15 @@
2462 * Invalid mode handlers
2463 */
2464 .macro inv_entry, reason
2465+
2466+ pax_enter_kernel
2467+
2468 sub sp, sp, #S_FRAME_SIZE
2469 ARM( stmib sp, {r1 - lr} )
2470 THUMB( stmia sp, {r0 - r12} )
2471 THUMB( str sp, [sp, #S_SP] )
2472 THUMB( str lr, [sp, #S_LR] )
2473+
2474 mov r1, #\reason
2475 .endm
2476
2477@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2478 .macro svc_entry, stack_hole=0
2479 UNWIND(.fnstart )
2480 UNWIND(.save {r0 - pc} )
2481+
2482+ pax_enter_kernel
2483+
2484 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2485+
2486 #ifdef CONFIG_THUMB2_KERNEL
2487 SPFIX( str r0, [sp] ) @ temporarily saved
2488 SPFIX( mov r0, sp )
2489@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2490 ldmia r0, {r3 - r5}
2491 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2492 mov r6, #-1 @ "" "" "" ""
2493+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2494+ @ offset sp by 8 as done in pax_enter_kernel
2495+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2496+#else
2497 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2498+#endif
2499 SPFIX( addeq r2, r2, #4 )
2500 str r3, [sp, #-4]! @ save the "real" r0 copied
2501 @ from the exception stack
2502@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2503 .macro usr_entry
2504 UNWIND(.fnstart )
2505 UNWIND(.cantunwind ) @ don't unwind the user space
2506+
2507+ pax_enter_kernel_user
2508+
2509 sub sp, sp, #S_FRAME_SIZE
2510 ARM( stmib sp, {r1 - r12} )
2511 THUMB( stmia sp, {r0 - r12} )
2512@@ -456,7 +553,9 @@ __und_usr:
2513 tst r3, #PSR_T_BIT @ Thumb mode?
2514 bne __und_usr_thumb
2515 sub r4, r2, #4 @ ARM instr at LR - 4
2516+ pax_open_userland
2517 1: ldrt r0, [r4]
2518+ pax_close_userland
2519 #ifdef CONFIG_CPU_ENDIAN_BE8
2520 rev r0, r0 @ little endian instruction
2521 #endif
2522@@ -491,10 +590,14 @@ __und_usr_thumb:
2523 */
2524 .arch armv6t2
2525 #endif
2526+ pax_open_userland
2527 2: ldrht r5, [r4]
2528+ pax_close_userland
2529 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2530 blo __und_usr_fault_16 @ 16bit undefined instruction
2531+ pax_open_userland
2532 3: ldrht r0, [r2]
2533+ pax_close_userland
2534 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2535 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2536 orr r0, r0, r5, lsl #16
2537@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2538 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2539 THUMB( str sp, [ip], #4 )
2540 THUMB( str lr, [ip], #4 )
2541-#ifdef CONFIG_CPU_USE_DOMAINS
2542+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2543 ldr r6, [r2, #TI_CPU_DOMAIN]
2544 #endif
2545 set_tls r3, r4, r5
2546@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2547 ldr r8, =__stack_chk_guard
2548 ldr r7, [r7, #TSK_STACK_CANARY]
2549 #endif
2550-#ifdef CONFIG_CPU_USE_DOMAINS
2551+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2552 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2553 #endif
2554 mov r5, r0
2555diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2556index a6c301e..908821b 100644
2557--- a/arch/arm/kernel/entry-common.S
2558+++ b/arch/arm/kernel/entry-common.S
2559@@ -10,18 +10,46 @@
2560
2561 #include <asm/unistd.h>
2562 #include <asm/ftrace.h>
2563+#include <asm/domain.h>
2564 #include <asm/unwind.h>
2565
2566+#include "entry-header.S"
2567+
2568 #ifdef CONFIG_NEED_RET_TO_USER
2569 #include <mach/entry-macro.S>
2570 #else
2571 .macro arch_ret_to_user, tmp1, tmp2
2572+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2573+ @ save regs
2574+ stmdb sp!, {r1, r2}
2575+ @ read DACR from cpu_domain into r1
2576+ mov r2, sp
2577+ @ assume 8K pages, since we have to split the immediate in two
2578+ bic r2, r2, #(0x1fc0)
2579+ bic r2, r2, #(0x3f)
2580+ ldr r1, [r2, #TI_CPU_DOMAIN]
2581+#ifdef CONFIG_PAX_KERNEXEC
2582+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2583+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2584+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2585+#endif
2586+#ifdef CONFIG_PAX_MEMORY_UDEREF
2587+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2588+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2589+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2590+#endif
2591+ @ write r1 to current_thread_info()->cpu_domain
2592+ str r1, [r2, #TI_CPU_DOMAIN]
2593+ @ write r1 to DACR
2594+ mcr p15, 0, r1, c3, c0, 0
2595+ @ instruction sync
2596+ instr_sync
2597+ @ restore regs
2598+ ldmia sp!, {r1, r2}
2599+#endif
2600 .endm
2601 #endif
2602
2603-#include "entry-header.S"
2604-
2605-
2606 .align 5
2607 /*
2608 * This is the fast syscall return path. We do as little as
2609@@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2610
2611 .align 5
2612 ENTRY(vector_swi)
2613+
2614 sub sp, sp, #S_FRAME_SIZE
2615 stmia sp, {r0 - r12} @ Calling r0 - r12
2616 ARM( add r8, sp, #S_PC )
2617@@ -388,6 +417,12 @@ ENTRY(vector_swi)
2618 ldr scno, [lr, #-4] @ get SWI instruction
2619 #endif
2620
2621+ /*
2622+ * do this here to avoid a performance hit of wrapping the code above
2623+ * that directly dereferences userland to parse the SWI instruction
2624+ */
2625+ pax_enter_kernel_user
2626+
2627 #ifdef CONFIG_ALIGNMENT_TRAP
2628 ldr ip, __cr_alignment
2629 ldr ip, [ip]
2630diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2631index 9a8531e..812e287 100644
2632--- a/arch/arm/kernel/entry-header.S
2633+++ b/arch/arm/kernel/entry-header.S
2634@@ -73,9 +73,66 @@
2635 msr cpsr_c, \rtemp @ switch back to the SVC mode
2636 .endm
2637
2638+ .macro pax_enter_kernel_user
2639+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2640+ @ save regs
2641+ stmdb sp!, {r0, r1}
2642+ @ read DACR from cpu_domain into r1
2643+ mov r0, sp
2644+ @ assume 8K pages, since we have to split the immediate in two
2645+ bic r0, r0, #(0x1fc0)
2646+ bic r0, r0, #(0x3f)
2647+ ldr r1, [r0, #TI_CPU_DOMAIN]
2648+#ifdef CONFIG_PAX_MEMORY_UDEREF
2649+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2650+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2651+#endif
2652+#ifdef CONFIG_PAX_KERNEXEC
2653+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2654+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2655+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2656+#endif
2657+ @ write r1 to current_thread_info()->cpu_domain
2658+ str r1, [r0, #TI_CPU_DOMAIN]
2659+ @ write r1 to DACR
2660+ mcr p15, 0, r1, c3, c0, 0
2661+ @ instruction sync
2662+ instr_sync
2663+ @ restore regs
2664+ ldmia sp!, {r0, r1}
2665+#endif
2666+ .endm
2667+
2668+ .macro pax_exit_kernel
2669+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2670+ @ save regs
2671+ stmdb sp!, {r0, r1}
2672+ @ read old DACR from stack into r1
2673+ ldr r1, [sp, #(8 + S_SP)]
2674+ sub r1, r1, #8
2675+ ldr r1, [r1]
2676+
2677+ @ write r1 to current_thread_info()->cpu_domain
2678+ mov r0, sp
2679+ @ assume 8K pages, since we have to split the immediate in two
2680+ bic r0, r0, #(0x1fc0)
2681+ bic r0, r0, #(0x3f)
2682+ str r1, [r0, #TI_CPU_DOMAIN]
2683+ @ write r1 to DACR
2684+ mcr p15, 0, r1, c3, c0, 0
2685+ @ instruction sync
2686+ instr_sync
2687+ @ restore regs
2688+ ldmia sp!, {r0, r1}
2689+#endif
2690+ .endm
2691+
2692 #ifndef CONFIG_THUMB2_KERNEL
2693 .macro svc_exit, rpsr
2694 msr spsr_cxsf, \rpsr
2695+
2696+ pax_exit_kernel
2697+
2698 #if defined(CONFIG_CPU_V6)
2699 ldr r0, [sp]
2700 strex r1, r2, [sp] @ clear the exclusive monitor
2701@@ -121,6 +178,9 @@
2702 .endm
2703 #else /* CONFIG_THUMB2_KERNEL */
2704 .macro svc_exit, rpsr
2705+
2706+ pax_exit_kernel
2707+
2708 ldr lr, [sp, #S_SP] @ top of the stack
2709 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2710 clrex @ clear the exclusive monitor
2711diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2712index 2adda11..7fbe958 100644
2713--- a/arch/arm/kernel/fiq.c
2714+++ b/arch/arm/kernel/fiq.c
2715@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2716 #if defined(CONFIG_CPU_USE_DOMAINS)
2717 memcpy((void *)0xffff001c, start, length);
2718 #else
2719+ pax_open_kernel();
2720 memcpy(vectors_page + 0x1c, start, length);
2721+ pax_close_kernel();
2722 #endif
2723 flush_icache_range(0xffff001c, 0xffff001c + length);
2724 if (!vectors_high())
2725diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2726index 486a15a..2d6880e 100644
2727--- a/arch/arm/kernel/head.S
2728+++ b/arch/arm/kernel/head.S
2729@@ -52,7 +52,9 @@
2730 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2731
2732 .macro pgtbl, rd, phys
2733- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2734+ mov \rd, #TEXT_OFFSET
2735+ sub \rd, #PG_DIR_SIZE
2736+ add \rd, \rd, \phys
2737 .endm
2738
2739 /*
2740@@ -416,7 +418,7 @@ __enable_mmu:
2741 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2742 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2743 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2744- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2745+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2746 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2747 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2748 #endif
2749diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2750index 5ff2e77..556d030 100644
2751--- a/arch/arm/kernel/hw_breakpoint.c
2752+++ b/arch/arm/kernel/hw_breakpoint.c
2753@@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2754 return NOTIFY_OK;
2755 }
2756
2757-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2758+static struct notifier_block dbg_reset_nb = {
2759 .notifier_call = dbg_reset_notify,
2760 };
2761
2762diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2763index 1e9be5d..03edbc2 100644
2764--- a/arch/arm/kernel/module.c
2765+++ b/arch/arm/kernel/module.c
2766@@ -37,12 +37,37 @@
2767 #endif
2768
2769 #ifdef CONFIG_MMU
2770-void *module_alloc(unsigned long size)
2771+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2772 {
2773+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2774+ return NULL;
2775 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2776- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2777+ GFP_KERNEL, prot, -1,
2778 __builtin_return_address(0));
2779 }
2780+
2781+void *module_alloc(unsigned long size)
2782+{
2783+
2784+#ifdef CONFIG_PAX_KERNEXEC
2785+ return __module_alloc(size, PAGE_KERNEL);
2786+#else
2787+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2788+#endif
2789+
2790+}
2791+
2792+#ifdef CONFIG_PAX_KERNEXEC
2793+void module_free_exec(struct module *mod, void *module_region)
2794+{
2795+ module_free(mod, module_region);
2796+}
2797+
2798+void *module_alloc_exec(unsigned long size)
2799+{
2800+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2801+}
2802+#endif
2803 #endif
2804
2805 int
2806diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2807index 07314af..c46655c 100644
2808--- a/arch/arm/kernel/patch.c
2809+++ b/arch/arm/kernel/patch.c
2810@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2811 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2812 int size;
2813
2814+ pax_open_kernel();
2815 if (thumb2 && __opcode_is_thumb16(insn)) {
2816 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2817 size = sizeof(u16);
2818@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2819 *(u32 *)addr = insn;
2820 size = sizeof(u32);
2821 }
2822+ pax_close_kernel();
2823
2824 flush_icache_range((uintptr_t)(addr),
2825 (uintptr_t)(addr) + size);
2826diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2827index 5f66206..dce492f 100644
2828--- a/arch/arm/kernel/perf_event_cpu.c
2829+++ b/arch/arm/kernel/perf_event_cpu.c
2830@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2831 return NOTIFY_OK;
2832 }
2833
2834-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2835+static struct notifier_block cpu_pmu_hotplug_notifier = {
2836 .notifier_call = cpu_pmu_notify,
2837 };
2838
2839diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2840index c6dec5f..f853532 100644
2841--- a/arch/arm/kernel/process.c
2842+++ b/arch/arm/kernel/process.c
2843@@ -28,7 +28,6 @@
2844 #include <linux/tick.h>
2845 #include <linux/utsname.h>
2846 #include <linux/uaccess.h>
2847-#include <linux/random.h>
2848 #include <linux/hw_breakpoint.h>
2849 #include <linux/cpuidle.h>
2850 #include <linux/leds.h>
2851@@ -256,9 +255,10 @@ void machine_power_off(void)
2852 machine_shutdown();
2853 if (pm_power_off)
2854 pm_power_off();
2855+ BUG();
2856 }
2857
2858-void machine_restart(char *cmd)
2859+__noreturn void machine_restart(char *cmd)
2860 {
2861 machine_shutdown();
2862
2863@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2864 init_utsname()->release,
2865 (int)strcspn(init_utsname()->version, " "),
2866 init_utsname()->version);
2867- print_symbol("PC is at %s\n", instruction_pointer(regs));
2868- print_symbol("LR is at %s\n", regs->ARM_lr);
2869+ printk("PC is at %pA\n", instruction_pointer(regs));
2870+ printk("LR is at %pA\n", regs->ARM_lr);
2871 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2872 "sp : %08lx ip : %08lx fp : %08lx\n",
2873 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2874@@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2875 return 0;
2876 }
2877
2878-unsigned long arch_randomize_brk(struct mm_struct *mm)
2879-{
2880- unsigned long range_end = mm->brk + 0x02000000;
2881- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2882-}
2883-
2884 #ifdef CONFIG_MMU
2885 /*
2886 * The vectors page is always readable from user space for the
2887diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2888index 03deeff..741ce88 100644
2889--- a/arch/arm/kernel/ptrace.c
2890+++ b/arch/arm/kernel/ptrace.c
2891@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2892 return current_thread_info()->syscall;
2893 }
2894
2895+#ifdef CONFIG_GRKERNSEC_SETXID
2896+extern void gr_delayed_cred_worker(void);
2897+#endif
2898+
2899 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2900 {
2901 current_thread_info()->syscall = scno;
2902
2903+#ifdef CONFIG_GRKERNSEC_SETXID
2904+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2905+ gr_delayed_cred_worker();
2906+#endif
2907+
2908 /* Do the secure computing check first; failures should be fast. */
2909 if (secure_computing(scno) == -1)
2910 return -1;
2911diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2912index 3f6cbb2..6d856f5 100644
2913--- a/arch/arm/kernel/setup.c
2914+++ b/arch/arm/kernel/setup.c
2915@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2916 unsigned int elf_hwcap __read_mostly;
2917 EXPORT_SYMBOL(elf_hwcap);
2918
2919+pteval_t __supported_pte_mask __read_only;
2920+pmdval_t __supported_pmd_mask __read_only;
2921
2922 #ifdef MULTI_CPU
2923-struct processor processor __read_mostly;
2924+struct processor processor;
2925 #endif
2926 #ifdef MULTI_TLB
2927-struct cpu_tlb_fns cpu_tlb __read_mostly;
2928+struct cpu_tlb_fns cpu_tlb __read_only;
2929 #endif
2930 #ifdef MULTI_USER
2931-struct cpu_user_fns cpu_user __read_mostly;
2932+struct cpu_user_fns cpu_user __read_only;
2933 #endif
2934 #ifdef MULTI_CACHE
2935-struct cpu_cache_fns cpu_cache __read_mostly;
2936+struct cpu_cache_fns cpu_cache __read_only;
2937 #endif
2938 #ifdef CONFIG_OUTER_CACHE
2939-struct outer_cache_fns outer_cache __read_mostly;
2940+struct outer_cache_fns outer_cache __read_only;
2941 EXPORT_SYMBOL(outer_cache);
2942 #endif
2943
2944@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2945 asm("mrc p15, 0, %0, c0, c1, 4"
2946 : "=r" (mmfr0));
2947 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2948- (mmfr0 & 0x000000f0) >= 0x00000030)
2949+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2950 cpu_arch = CPU_ARCH_ARMv7;
2951- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2952+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2953+ __supported_pte_mask |= L_PTE_PXN;
2954+ __supported_pmd_mask |= PMD_PXNTABLE;
2955+ }
2956+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2957 (mmfr0 & 0x000000f0) == 0x00000020)
2958 cpu_arch = CPU_ARCH_ARMv6;
2959 else
2960@@ -462,7 +468,7 @@ static void __init setup_processor(void)
2961 __cpu_architecture = __get_cpu_architecture();
2962
2963 #ifdef MULTI_CPU
2964- processor = *list->proc;
2965+ memcpy((void *)&processor, list->proc, sizeof processor);
2966 #endif
2967 #ifdef MULTI_TLB
2968 cpu_tlb = *list->tlb;
2969diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2970index 84f4cbf..672f5b8 100644
2971--- a/arch/arm/kernel/smp.c
2972+++ b/arch/arm/kernel/smp.c
2973@@ -70,7 +70,7 @@ enum ipi_msg_type {
2974
2975 static DECLARE_COMPLETION(cpu_running);
2976
2977-static struct smp_operations smp_ops;
2978+static struct smp_operations smp_ops __read_only;
2979
2980 void __init smp_set_ops(struct smp_operations *ops)
2981 {
2982diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2983index b0179b8..b7b16c7 100644
2984--- a/arch/arm/kernel/traps.c
2985+++ b/arch/arm/kernel/traps.c
2986@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2987 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2988 {
2989 #ifdef CONFIG_KALLSYMS
2990- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2991+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2992 #else
2993 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2994 #endif
2995@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2996 static int die_owner = -1;
2997 static unsigned int die_nest_count;
2998
2999+extern void gr_handle_kernel_exploit(void);
3000+
3001 static unsigned long oops_begin(void)
3002 {
3003 int cpu;
3004@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3005 panic("Fatal exception in interrupt");
3006 if (panic_on_oops)
3007 panic("Fatal exception");
3008+
3009+ gr_handle_kernel_exploit();
3010+
3011 if (signr)
3012 do_exit(signr);
3013 }
3014@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3015 * The user helper at 0xffff0fe0 must be used instead.
3016 * (see entry-armv.S for details)
3017 */
3018+ pax_open_kernel();
3019 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3020+ pax_close_kernel();
3021 }
3022 return 0;
3023
3024@@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
3025 sigreturn_codes, sizeof(sigreturn_codes));
3026
3027 flush_icache_range(vectors, vectors + PAGE_SIZE);
3028- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3029+
3030+#ifndef CONFIG_PAX_MEMORY_UDEREF
3031+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3032+#endif
3033+
3034 }
3035diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3036index 11c1785..c67d54c 100644
3037--- a/arch/arm/kernel/vmlinux.lds.S
3038+++ b/arch/arm/kernel/vmlinux.lds.S
3039@@ -8,7 +8,11 @@
3040 #include <asm/thread_info.h>
3041 #include <asm/memory.h>
3042 #include <asm/page.h>
3043-
3044+
3045+#ifdef CONFIG_PAX_KERNEXEC
3046+#include <asm/pgtable.h>
3047+#endif
3048+
3049 #define PROC_INFO \
3050 . = ALIGN(4); \
3051 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3052@@ -90,6 +94,11 @@ SECTIONS
3053 _text = .;
3054 HEAD_TEXT
3055 }
3056+
3057+#ifdef CONFIG_PAX_KERNEXEC
3058+ . = ALIGN(1<<SECTION_SHIFT);
3059+#endif
3060+
3061 .text : { /* Real text segment */
3062 _stext = .; /* Text and read-only data */
3063 __exception_text_start = .;
3064@@ -144,6 +153,10 @@ SECTIONS
3065
3066 _etext = .; /* End of text and rodata section */
3067
3068+#ifdef CONFIG_PAX_KERNEXEC
3069+ . = ALIGN(1<<SECTION_SHIFT);
3070+#endif
3071+
3072 #ifndef CONFIG_XIP_KERNEL
3073 . = ALIGN(PAGE_SIZE);
3074 __init_begin = .;
3075@@ -203,6 +216,11 @@ SECTIONS
3076 . = PAGE_OFFSET + TEXT_OFFSET;
3077 #else
3078 __init_end = .;
3079+
3080+#ifdef CONFIG_PAX_KERNEXEC
3081+ . = ALIGN(1<<SECTION_SHIFT);
3082+#endif
3083+
3084 . = ALIGN(THREAD_SIZE);
3085 __data_loc = .;
3086 #endif
3087diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3088index 14a0d98..7771a7d 100644
3089--- a/arch/arm/lib/clear_user.S
3090+++ b/arch/arm/lib/clear_user.S
3091@@ -12,14 +12,14 @@
3092
3093 .text
3094
3095-/* Prototype: int __clear_user(void *addr, size_t sz)
3096+/* Prototype: int ___clear_user(void *addr, size_t sz)
3097 * Purpose : clear some user memory
3098 * Params : addr - user memory address to clear
3099 * : sz - number of bytes to clear
3100 * Returns : number of bytes NOT cleared
3101 */
3102 ENTRY(__clear_user_std)
3103-WEAK(__clear_user)
3104+WEAK(___clear_user)
3105 stmfd sp!, {r1, lr}
3106 mov r2, #0
3107 cmp r1, #4
3108@@ -44,7 +44,7 @@ WEAK(__clear_user)
3109 USER( strnebt r2, [r0])
3110 mov r0, #0
3111 ldmfd sp!, {r1, pc}
3112-ENDPROC(__clear_user)
3113+ENDPROC(___clear_user)
3114 ENDPROC(__clear_user_std)
3115
3116 .pushsection .fixup,"ax"
3117diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3118index 66a477a..bee61d3 100644
3119--- a/arch/arm/lib/copy_from_user.S
3120+++ b/arch/arm/lib/copy_from_user.S
3121@@ -16,7 +16,7 @@
3122 /*
3123 * Prototype:
3124 *
3125- * size_t __copy_from_user(void *to, const void *from, size_t n)
3126+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3127 *
3128 * Purpose:
3129 *
3130@@ -84,11 +84,11 @@
3131
3132 .text
3133
3134-ENTRY(__copy_from_user)
3135+ENTRY(___copy_from_user)
3136
3137 #include "copy_template.S"
3138
3139-ENDPROC(__copy_from_user)
3140+ENDPROC(___copy_from_user)
3141
3142 .pushsection .fixup,"ax"
3143 .align 0
3144diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3145index 6ee2f67..d1cce76 100644
3146--- a/arch/arm/lib/copy_page.S
3147+++ b/arch/arm/lib/copy_page.S
3148@@ -10,6 +10,7 @@
3149 * ASM optimised string functions
3150 */
3151 #include <linux/linkage.h>
3152+#include <linux/const.h>
3153 #include <asm/assembler.h>
3154 #include <asm/asm-offsets.h>
3155 #include <asm/cache.h>
3156diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3157index d066df6..df28194 100644
3158--- a/arch/arm/lib/copy_to_user.S
3159+++ b/arch/arm/lib/copy_to_user.S
3160@@ -16,7 +16,7 @@
3161 /*
3162 * Prototype:
3163 *
3164- * size_t __copy_to_user(void *to, const void *from, size_t n)
3165+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3166 *
3167 * Purpose:
3168 *
3169@@ -88,11 +88,11 @@
3170 .text
3171
3172 ENTRY(__copy_to_user_std)
3173-WEAK(__copy_to_user)
3174+WEAK(___copy_to_user)
3175
3176 #include "copy_template.S"
3177
3178-ENDPROC(__copy_to_user)
3179+ENDPROC(___copy_to_user)
3180 ENDPROC(__copy_to_user_std)
3181
3182 .pushsection .fixup,"ax"
3183diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3184index 7d08b43..f7ca7ea 100644
3185--- a/arch/arm/lib/csumpartialcopyuser.S
3186+++ b/arch/arm/lib/csumpartialcopyuser.S
3187@@ -57,8 +57,8 @@
3188 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3189 */
3190
3191-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3192-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3193+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3194+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3195
3196 #include "csumpartialcopygeneric.S"
3197
3198diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3199index 0dc5385..45833ef 100644
3200--- a/arch/arm/lib/delay.c
3201+++ b/arch/arm/lib/delay.c
3202@@ -28,12 +28,14 @@
3203 /*
3204 * Default to the loop-based delay implementation.
3205 */
3206-struct arm_delay_ops arm_delay_ops = {
3207+static struct arm_delay_ops arm_loop_delay_ops = {
3208 .delay = __loop_delay,
3209 .const_udelay = __loop_const_udelay,
3210 .udelay = __loop_udelay,
3211 };
3212
3213+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3214+
3215 static const struct delay_timer *delay_timer;
3216 static bool delay_calibrated;
3217
3218@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3219 __timer_const_udelay(usecs * UDELAY_MULT);
3220 }
3221
3222+static struct arm_delay_ops arm_timer_delay_ops = {
3223+ .delay = __timer_delay,
3224+ .const_udelay = __timer_const_udelay,
3225+ .udelay = __timer_udelay,
3226+};
3227+
3228 void __init register_current_timer_delay(const struct delay_timer *timer)
3229 {
3230 if (!delay_calibrated) {
3231@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3232 delay_timer = timer;
3233 lpj_fine = timer->freq / HZ;
3234 loops_per_jiffy = lpj_fine;
3235- arm_delay_ops.delay = __timer_delay;
3236- arm_delay_ops.const_udelay = __timer_const_udelay;
3237- arm_delay_ops.udelay = __timer_udelay;
3238+ arm_delay_ops = &arm_timer_delay_ops;
3239 delay_calibrated = true;
3240 } else {
3241 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3242diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3243index 025f742..8432b08 100644
3244--- a/arch/arm/lib/uaccess_with_memcpy.c
3245+++ b/arch/arm/lib/uaccess_with_memcpy.c
3246@@ -104,7 +104,7 @@ out:
3247 }
3248
3249 unsigned long
3250-__copy_to_user(void __user *to, const void *from, unsigned long n)
3251+___copy_to_user(void __user *to, const void *from, unsigned long n)
3252 {
3253 /*
3254 * This test is stubbed out of the main function above to keep
3255diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3256index bac21a5..b67ef8e 100644
3257--- a/arch/arm/mach-kirkwood/common.c
3258+++ b/arch/arm/mach-kirkwood/common.c
3259@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3260 clk_gate_ops.disable(hw);
3261 }
3262
3263-static struct clk_ops clk_gate_fn_ops;
3264+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3265+{
3266+ return clk_gate_ops.is_enabled(hw);
3267+}
3268+
3269+static struct clk_ops clk_gate_fn_ops = {
3270+ .enable = clk_gate_fn_enable,
3271+ .disable = clk_gate_fn_disable,
3272+ .is_enabled = clk_gate_fn_is_enabled,
3273+};
3274
3275 static struct clk __init *clk_register_gate_fn(struct device *dev,
3276 const char *name,
3277@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3278 gate_fn->fn_en = fn_en;
3279 gate_fn->fn_dis = fn_dis;
3280
3281- /* ops is the gate ops, but with our enable/disable functions */
3282- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3283- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3284- clk_gate_fn_ops = clk_gate_ops;
3285- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3286- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3287- }
3288-
3289 clk = clk_register(dev, &gate_fn->gate.hw);
3290
3291 if (IS_ERR(clk))
3292diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3293index 0abb30f..54064da 100644
3294--- a/arch/arm/mach-omap2/board-n8x0.c
3295+++ b/arch/arm/mach-omap2/board-n8x0.c
3296@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3297 }
3298 #endif
3299
3300-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3301+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3302 .late_init = n8x0_menelaus_late_init,
3303 };
3304
3305diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3306index 5d3b4f4..ddba3c0 100644
3307--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3308+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3309@@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3310 return NOTIFY_OK;
3311 }
3312
3313-static struct notifier_block __refdata irq_hotplug_notifier = {
3314+static struct notifier_block irq_hotplug_notifier = {
3315 .notifier_call = irq_cpu_hotplug_notify,
3316 };
3317
3318diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3319index 4653efb..8c60bf7 100644
3320--- a/arch/arm/mach-omap2/omap_hwmod.c
3321+++ b/arch/arm/mach-omap2/omap_hwmod.c
3322@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3323 int (*init_clkdm)(struct omap_hwmod *oh);
3324 void (*update_context_lost)(struct omap_hwmod *oh);
3325 int (*get_context_lost)(struct omap_hwmod *oh);
3326-};
3327+} __no_const;
3328
3329 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3330-static struct omap_hwmod_soc_ops soc_ops;
3331+static struct omap_hwmod_soc_ops soc_ops __read_only;
3332
3333 /* omap_hwmod_list contains all registered struct omap_hwmods */
3334 static LIST_HEAD(omap_hwmod_list);
3335diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3336index 7c2b4ed..b2ea51f 100644
3337--- a/arch/arm/mach-omap2/wd_timer.c
3338+++ b/arch/arm/mach-omap2/wd_timer.c
3339@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3340 struct omap_hwmod *oh;
3341 char *oh_name = "wd_timer2";
3342 char *dev_name = "omap_wdt";
3343- struct omap_wd_timer_platform_data pdata;
3344+ static struct omap_wd_timer_platform_data pdata = {
3345+ .read_reset_sources = prm_read_reset_sources
3346+ };
3347
3348 if (!cpu_class_is_omap2() || of_have_populated_dt())
3349 return 0;
3350@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3351 return -EINVAL;
3352 }
3353
3354- pdata.read_reset_sources = prm_read_reset_sources;
3355-
3356 pdev = omap_device_build(dev_name, id, oh, &pdata,
3357 sizeof(struct omap_wd_timer_platform_data),
3358 NULL, 0, 0);
3359diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3360index 6be4c4d..32ac32a 100644
3361--- a/arch/arm/mach-ux500/include/mach/setup.h
3362+++ b/arch/arm/mach-ux500/include/mach/setup.h
3363@@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3364 .type = MT_DEVICE, \
3365 }
3366
3367-#define __MEM_DEV_DESC(x, sz) { \
3368- .virtual = IO_ADDRESS(x), \
3369- .pfn = __phys_to_pfn(x), \
3370- .length = sz, \
3371- .type = MT_MEMORY, \
3372-}
3373-
3374 extern struct smp_operations ux500_smp_ops;
3375 extern void ux500_cpu_die(unsigned int cpu);
3376
3377diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3378index 3fd629d..8b1aca9 100644
3379--- a/arch/arm/mm/Kconfig
3380+++ b/arch/arm/mm/Kconfig
3381@@ -425,7 +425,7 @@ config CPU_32v5
3382
3383 config CPU_32v6
3384 bool
3385- select CPU_USE_DOMAINS if CPU_V6 && MMU
3386+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3387 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3388
3389 config CPU_32v6K
3390@@ -577,6 +577,7 @@ config CPU_CP15_MPU
3391
3392 config CPU_USE_DOMAINS
3393 bool
3394+ depends on !ARM_LPAE && !PAX_KERNEXEC
3395 help
3396 This option enables or disables the use of domain switching
3397 via the set_fs() function.
3398diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3399index 5dbf13f..6393f55 100644
3400--- a/arch/arm/mm/fault.c
3401+++ b/arch/arm/mm/fault.c
3402@@ -25,6 +25,7 @@
3403 #include <asm/system_misc.h>
3404 #include <asm/system_info.h>
3405 #include <asm/tlbflush.h>
3406+#include <asm/sections.h>
3407
3408 #include "fault.h"
3409
3410@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3411 if (fixup_exception(regs))
3412 return;
3413
3414+#ifdef CONFIG_PAX_KERNEXEC
3415+ if ((fsr & FSR_WRITE) &&
3416+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3417+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3418+ {
3419+ if (current->signal->curr_ip)
3420+ 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),
3421+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3422+ else
3423+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3424+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3425+ }
3426+#endif
3427+
3428 /*
3429 * No handler, we'll have to terminate things with extreme prejudice.
3430 */
3431@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3432 }
3433 #endif
3434
3435+#ifdef CONFIG_PAX_PAGEEXEC
3436+ if (fsr & FSR_LNX_PF) {
3437+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3438+ do_group_exit(SIGKILL);
3439+ }
3440+#endif
3441+
3442 tsk->thread.address = addr;
3443 tsk->thread.error_code = fsr;
3444 tsk->thread.trap_no = 14;
3445@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3446 }
3447 #endif /* CONFIG_MMU */
3448
3449+#ifdef CONFIG_PAX_PAGEEXEC
3450+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3451+{
3452+ long i;
3453+
3454+ printk(KERN_ERR "PAX: bytes at PC: ");
3455+ for (i = 0; i < 20; i++) {
3456+ unsigned char c;
3457+ if (get_user(c, (__force unsigned char __user *)pc+i))
3458+ printk(KERN_CONT "?? ");
3459+ else
3460+ printk(KERN_CONT "%02x ", c);
3461+ }
3462+ printk("\n");
3463+
3464+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3465+ for (i = -1; i < 20; i++) {
3466+ unsigned long c;
3467+ if (get_user(c, (__force unsigned long __user *)sp+i))
3468+ printk(KERN_CONT "???????? ");
3469+ else
3470+ printk(KERN_CONT "%08lx ", c);
3471+ }
3472+ printk("\n");
3473+}
3474+#endif
3475+
3476 /*
3477 * First Level Translation Fault Handler
3478 *
3479@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3480 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3481 struct siginfo info;
3482
3483+#ifdef CONFIG_PAX_MEMORY_UDEREF
3484+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3485+ if (current->signal->curr_ip)
3486+ 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),
3487+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3488+ else
3489+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3490+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3491+ goto die;
3492+ }
3493+#endif
3494+
3495 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3496 return;
3497
3498+die:
3499 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3500 inf->name, fsr, addr);
3501
3502@@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3503 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3504 struct siginfo info;
3505
3506+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3507+ if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3508+ if (current->signal->curr_ip)
3509+ 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),
3510+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3511+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3512+ else
3513+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3514+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3515+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3516+ goto die;
3517+ }
3518+#endif
3519+
3520+#ifdef CONFIG_PAX_REFCOUNT
3521+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3522+ unsigned int bkpt;
3523+
3524+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3525+ current->thread.error_code = ifsr;
3526+ current->thread.trap_no = 0;
3527+ pax_report_refcount_overflow(regs);
3528+ fixup_exception(regs);
3529+ return;
3530+ }
3531+ }
3532+#endif
3533+
3534 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3535 return;
3536
3537+die:
3538 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3539 inf->name, ifsr, addr);
3540
3541diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3542index cf08bdf..772656c 100644
3543--- a/arch/arm/mm/fault.h
3544+++ b/arch/arm/mm/fault.h
3545@@ -3,6 +3,7 @@
3546
3547 /*
3548 * Fault status register encodings. We steal bit 31 for our own purposes.
3549+ * Set when the FSR value is from an instruction fault.
3550 */
3551 #define FSR_LNX_PF (1 << 31)
3552 #define FSR_WRITE (1 << 11)
3553@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3554 }
3555 #endif
3556
3557+/* valid for LPAE and !LPAE */
3558+static inline int is_xn_fault(unsigned int fsr)
3559+{
3560+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3561+}
3562+
3563+static inline int is_domain_fault(unsigned int fsr)
3564+{
3565+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3566+}
3567+
3568 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3569 unsigned long search_exception_table(unsigned long addr);
3570
3571diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3572index ad722f1..763fdd3 100644
3573--- a/arch/arm/mm/init.c
3574+++ b/arch/arm/mm/init.c
3575@@ -30,6 +30,8 @@
3576 #include <asm/setup.h>
3577 #include <asm/tlb.h>
3578 #include <asm/fixmap.h>
3579+#include <asm/system_info.h>
3580+#include <asm/cp15.h>
3581
3582 #include <asm/mach/arch.h>
3583 #include <asm/mach/map.h>
3584@@ -736,7 +738,46 @@ void free_initmem(void)
3585 {
3586 #ifdef CONFIG_HAVE_TCM
3587 extern char __tcm_start, __tcm_end;
3588+#endif
3589
3590+#ifdef CONFIG_PAX_KERNEXEC
3591+ unsigned long addr;
3592+ pgd_t *pgd;
3593+ pud_t *pud;
3594+ pmd_t *pmd;
3595+ int cpu_arch = cpu_architecture();
3596+ unsigned int cr = get_cr();
3597+
3598+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3599+ /* make pages tables, etc before .text NX */
3600+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3601+ pgd = pgd_offset_k(addr);
3602+ pud = pud_offset(pgd, addr);
3603+ pmd = pmd_offset(pud, addr);
3604+ __section_update(pmd, addr, PMD_SECT_XN);
3605+ }
3606+ /* make init NX */
3607+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3608+ pgd = pgd_offset_k(addr);
3609+ pud = pud_offset(pgd, addr);
3610+ pmd = pmd_offset(pud, addr);
3611+ __section_update(pmd, addr, PMD_SECT_XN);
3612+ }
3613+ /* make kernel code/rodata RX */
3614+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3615+ pgd = pgd_offset_k(addr);
3616+ pud = pud_offset(pgd, addr);
3617+ pmd = pmd_offset(pud, addr);
3618+#ifdef CONFIG_ARM_LPAE
3619+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3620+#else
3621+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3622+#endif
3623+ }
3624+ }
3625+#endif
3626+
3627+#ifdef CONFIG_HAVE_TCM
3628 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3629 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3630 __phys_to_pfn(__pa(&__tcm_end)),
3631diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3632index 88fd86c..7a224ce 100644
3633--- a/arch/arm/mm/ioremap.c
3634+++ b/arch/arm/mm/ioremap.c
3635@@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3636 unsigned int mtype;
3637
3638 if (cached)
3639- mtype = MT_MEMORY;
3640+ mtype = MT_MEMORY_RX;
3641 else
3642- mtype = MT_MEMORY_NONCACHED;
3643+ mtype = MT_MEMORY_NONCACHED_RX;
3644
3645 return __arm_ioremap_caller(phys_addr, size, mtype,
3646 __builtin_return_address(0));
3647diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3648index 10062ce..aa96dd7 100644
3649--- a/arch/arm/mm/mmap.c
3650+++ b/arch/arm/mm/mmap.c
3651@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3652 struct vm_area_struct *vma;
3653 int do_align = 0;
3654 int aliasing = cache_is_vipt_aliasing();
3655+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3656 struct vm_unmapped_area_info info;
3657
3658 /*
3659@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3660 if (len > TASK_SIZE)
3661 return -ENOMEM;
3662
3663+#ifdef CONFIG_PAX_RANDMMAP
3664+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3665+#endif
3666+
3667 if (addr) {
3668 if (do_align)
3669 addr = COLOUR_ALIGN(addr, pgoff);
3670@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3671 addr = PAGE_ALIGN(addr);
3672
3673 vma = find_vma(mm, addr);
3674- if (TASK_SIZE - len >= addr &&
3675- (!vma || addr + len <= vma->vm_start))
3676+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3677 return addr;
3678 }
3679
3680@@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3681 unsigned long addr = addr0;
3682 int do_align = 0;
3683 int aliasing = cache_is_vipt_aliasing();
3684+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3685 struct vm_unmapped_area_info info;
3686
3687 /*
3688@@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3689 return addr;
3690 }
3691
3692+#ifdef CONFIG_PAX_RANDMMAP
3693+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3694+#endif
3695+
3696 /* requesting a specific address */
3697 if (addr) {
3698 if (do_align)
3699@@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3700 else
3701 addr = PAGE_ALIGN(addr);
3702 vma = find_vma(mm, addr);
3703- if (TASK_SIZE - len >= addr &&
3704- (!vma || addr + len <= vma->vm_start))
3705+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3706 return addr;
3707 }
3708
3709@@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3710 VM_BUG_ON(addr != -ENOMEM);
3711 info.flags = 0;
3712 info.low_limit = mm->mmap_base;
3713+
3714+#ifdef CONFIG_PAX_RANDMMAP
3715+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3716+ info.low_limit += mm->delta_mmap;
3717+#endif
3718+
3719 info.high_limit = TASK_SIZE;
3720 addr = vm_unmapped_area(&info);
3721 }
3722@@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3723 {
3724 unsigned long random_factor = 0UL;
3725
3726+#ifdef CONFIG_PAX_RANDMMAP
3727+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3728+#endif
3729+
3730 /* 8 bits of randomness in 20 address space bits */
3731 if ((current->flags & PF_RANDOMIZE) &&
3732 !(current->personality & ADDR_NO_RANDOMIZE))
3733@@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3734
3735 if (mmap_is_legacy()) {
3736 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3737+
3738+#ifdef CONFIG_PAX_RANDMMAP
3739+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3740+ mm->mmap_base += mm->delta_mmap;
3741+#endif
3742+
3743 mm->get_unmapped_area = arch_get_unmapped_area;
3744 mm->unmap_area = arch_unmap_area;
3745 } else {
3746 mm->mmap_base = mmap_base(random_factor);
3747+
3748+#ifdef CONFIG_PAX_RANDMMAP
3749+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3750+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3751+#endif
3752+
3753 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3754 mm->unmap_area = arch_unmap_area_topdown;
3755 }
3756diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3757index ce328c7..f82bebb 100644
3758--- a/arch/arm/mm/mmu.c
3759+++ b/arch/arm/mm/mmu.c
3760@@ -35,6 +35,23 @@
3761
3762 #include "mm.h"
3763
3764+
3765+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3766+void modify_domain(unsigned int dom, unsigned int type)
3767+{
3768+ struct thread_info *thread = current_thread_info();
3769+ unsigned int domain = thread->cpu_domain;
3770+ /*
3771+ * DOMAIN_MANAGER might be defined to some other value,
3772+ * use the arch-defined constant
3773+ */
3774+ domain &= ~domain_val(dom, 3);
3775+ thread->cpu_domain = domain | domain_val(dom, type);
3776+ set_domain(thread->cpu_domain);
3777+}
3778+EXPORT_SYMBOL(modify_domain);
3779+#endif
3780+
3781 /*
3782 * empty_zero_page is a special page that is used for
3783 * zero-initialized data and COW.
3784@@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3785 }
3786 #endif
3787
3788-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3789+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3790 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3791
3792-static struct mem_type mem_types[] = {
3793+#ifdef CONFIG_PAX_KERNEXEC
3794+#define L_PTE_KERNEXEC L_PTE_RDONLY
3795+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3796+#else
3797+#define L_PTE_KERNEXEC L_PTE_DIRTY
3798+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3799+#endif
3800+
3801+static struct mem_type mem_types[] __read_only = {
3802 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3803 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3804 L_PTE_SHARED,
3805@@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3806 [MT_UNCACHED] = {
3807 .prot_pte = PROT_PTE_DEVICE,
3808 .prot_l1 = PMD_TYPE_TABLE,
3809- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3810+ .prot_sect = PROT_SECT_DEVICE,
3811 .domain = DOMAIN_IO,
3812 },
3813 [MT_CACHECLEAN] = {
3814- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3815+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3816 .domain = DOMAIN_KERNEL,
3817 },
3818 #ifndef CONFIG_ARM_LPAE
3819 [MT_MINICLEAN] = {
3820- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3821+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3822 .domain = DOMAIN_KERNEL,
3823 },
3824 #endif
3825@@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3826 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3827 L_PTE_RDONLY,
3828 .prot_l1 = PMD_TYPE_TABLE,
3829- .domain = DOMAIN_USER,
3830+ .domain = DOMAIN_VECTORS,
3831 },
3832 [MT_HIGH_VECTORS] = {
3833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3834 L_PTE_USER | L_PTE_RDONLY,
3835 .prot_l1 = PMD_TYPE_TABLE,
3836- .domain = DOMAIN_USER,
3837+ .domain = DOMAIN_VECTORS,
3838 },
3839- [MT_MEMORY] = {
3840+ [MT_MEMORY_RWX] = {
3841 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3842 .prot_l1 = PMD_TYPE_TABLE,
3843 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3844 .domain = DOMAIN_KERNEL,
3845 },
3846+ [MT_MEMORY_RW] = {
3847+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3848+ .prot_l1 = PMD_TYPE_TABLE,
3849+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3850+ .domain = DOMAIN_KERNEL,
3851+ },
3852+ [MT_MEMORY_RX] = {
3853+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3854+ .prot_l1 = PMD_TYPE_TABLE,
3855+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3856+ .domain = DOMAIN_KERNEL,
3857+ },
3858 [MT_ROM] = {
3859- .prot_sect = PMD_TYPE_SECT,
3860+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3861 .domain = DOMAIN_KERNEL,
3862 },
3863- [MT_MEMORY_NONCACHED] = {
3864+ [MT_MEMORY_NONCACHED_RW] = {
3865 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3866 L_PTE_MT_BUFFERABLE,
3867 .prot_l1 = PMD_TYPE_TABLE,
3868 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3869 .domain = DOMAIN_KERNEL,
3870 },
3871+ [MT_MEMORY_NONCACHED_RX] = {
3872+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3873+ L_PTE_MT_BUFFERABLE,
3874+ .prot_l1 = PMD_TYPE_TABLE,
3875+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3876+ .domain = DOMAIN_KERNEL,
3877+ },
3878 [MT_MEMORY_DTCM] = {
3879- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3880- L_PTE_XN,
3881+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3882 .prot_l1 = PMD_TYPE_TABLE,
3883- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3884+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3885 .domain = DOMAIN_KERNEL,
3886 },
3887 [MT_MEMORY_ITCM] = {
3888@@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3889 },
3890 [MT_MEMORY_SO] = {
3891 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3892- L_PTE_MT_UNCACHED | L_PTE_XN,
3893+ L_PTE_MT_UNCACHED,
3894 .prot_l1 = PMD_TYPE_TABLE,
3895 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3896- PMD_SECT_UNCACHED | PMD_SECT_XN,
3897+ PMD_SECT_UNCACHED,
3898 .domain = DOMAIN_KERNEL,
3899 },
3900 [MT_MEMORY_DMA_READY] = {
3901@@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3902 * to prevent speculative instruction fetches.
3903 */
3904 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3905+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3906 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3907+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3908 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3909+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3910 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3911+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3912+
3913+ /* Mark other regions on ARMv6+ as execute-never */
3914+
3915+#ifdef CONFIG_PAX_KERNEXEC
3916+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3917+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3918+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3919+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3920+#ifndef CONFIG_ARM_LPAE
3921+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3922+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3923+#endif
3924+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3925+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3926+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3927+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3928+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3929+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3930+#endif
3931+
3932+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3933+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3934 }
3935 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3936 /*
3937@@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3938 * from SVC mode and no access from userspace.
3939 */
3940 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3941+#ifdef CONFIG_PAX_KERNEXEC
3942+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3943+#endif
3944 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3945 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3946 #endif
3947@@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3948 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3949 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3950 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3951- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3952- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3953+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3954+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3955+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3956+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3957+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3958+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3959 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3960- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3961- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3962+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3963+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3964+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3965+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3966 }
3967 }
3968
3969@@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3970 if (cpu_arch >= CPU_ARCH_ARMv6) {
3971 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3972 /* Non-cacheable Normal is XCB = 001 */
3973- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3974+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3975+ PMD_SECT_BUFFERED;
3976+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3977 PMD_SECT_BUFFERED;
3978 } else {
3979 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3980- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3981+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3982+ PMD_SECT_TEX(1);
3983+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3984 PMD_SECT_TEX(1);
3985 }
3986 } else {
3987- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3988+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3989+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3990 }
3991
3992 #ifdef CONFIG_ARM_LPAE
3993@@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3994 vecs_pgprot |= PTE_EXT_AF;
3995 #endif
3996
3997+ user_pgprot |= __supported_pte_mask;
3998+
3999 for (i = 0; i < 16; i++) {
4000 pteval_t v = pgprot_val(protection_map[i]);
4001 protection_map[i] = __pgprot(v | user_pgprot);
4002@@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
4003
4004 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4005 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4006- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4007- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4008+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4009+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4010+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4011+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4012+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4013+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4014 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4015- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4016+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4017+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4018 mem_types[MT_ROM].prot_sect |= cp->pmd;
4019
4020 switch (cp->pmd) {
4021@@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
4022 * called function. This means you can't use any function or debugging
4023 * method which may touch any device, otherwise the kernel _will_ crash.
4024 */
4025+
4026+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4027+
4028 static void __init devicemaps_init(struct machine_desc *mdesc)
4029 {
4030 struct map_desc map;
4031 unsigned long addr;
4032- void *vectors;
4033
4034- /*
4035- * Allocate the vector page early.
4036- */
4037- vectors = early_alloc(PAGE_SIZE);
4038-
4039- early_trap_init(vectors);
4040+ early_trap_init(&vectors);
4041
4042 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4043 pmd_clear(pmd_off_k(addr));
4044@@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4045 * location (0xffff0000). If we aren't using high-vectors, also
4046 * create a mapping at the low-vectors virtual address.
4047 */
4048- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4049+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4050 map.virtual = 0xffff0000;
4051 map.length = PAGE_SIZE;
4052 map.type = MT_HIGH_VECTORS;
4053@@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
4054 map.pfn = __phys_to_pfn(start);
4055 map.virtual = __phys_to_virt(start);
4056 map.length = end - start;
4057- map.type = MT_MEMORY;
4058
4059+#ifdef CONFIG_PAX_KERNEXEC
4060+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4061+ struct map_desc kernel;
4062+ struct map_desc initmap;
4063+
4064+ /* when freeing initmem we will make this RW */
4065+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4066+ initmap.virtual = (unsigned long)__init_begin;
4067+ initmap.length = _sdata - __init_begin;
4068+ initmap.type = MT_MEMORY_RWX;
4069+ create_mapping(&initmap);
4070+
4071+ /* when freeing initmem we will make this RX */
4072+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4073+ kernel.virtual = (unsigned long)_stext;
4074+ kernel.length = __init_begin - _stext;
4075+ kernel.type = MT_MEMORY_RWX;
4076+ create_mapping(&kernel);
4077+
4078+ if (map.virtual < (unsigned long)_stext) {
4079+ map.length = (unsigned long)_stext - map.virtual;
4080+ map.type = MT_MEMORY_RWX;
4081+ create_mapping(&map);
4082+ }
4083+
4084+ map.pfn = __phys_to_pfn(__pa(_sdata));
4085+ map.virtual = (unsigned long)_sdata;
4086+ map.length = end - __pa(_sdata);
4087+ }
4088+#endif
4089+
4090+ map.type = MT_MEMORY_RW;
4091 create_mapping(&map);
4092 }
4093 }
4094diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4095index 6d98c13..3cfb174 100644
4096--- a/arch/arm/mm/proc-v7-2level.S
4097+++ b/arch/arm/mm/proc-v7-2level.S
4098@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4099 tst r1, #L_PTE_XN
4100 orrne r3, r3, #PTE_EXT_XN
4101
4102+ tst r1, #L_PTE_PXN
4103+ orrne r3, r3, #PTE_EXT_PXN
4104+
4105 tst r1, #L_PTE_YOUNG
4106 tstne r1, #L_PTE_VALID
4107 #ifndef CONFIG_CPU_USE_DOMAINS
4108diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4109index a5bc92d..0bb4730 100644
4110--- a/arch/arm/plat-omap/sram.c
4111+++ b/arch/arm/plat-omap/sram.c
4112@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4113 * Looks like we need to preserve some bootloader code at the
4114 * beginning of SRAM for jumping to flash for reboot to work...
4115 */
4116+ pax_open_kernel();
4117 memset_io(omap_sram_base + omap_sram_skip, 0,
4118 omap_sram_size - omap_sram_skip);
4119+ pax_close_kernel();
4120 }
4121diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4122index b76c065..b6e766b 100644
4123--- a/arch/arm/plat-orion/include/plat/addr-map.h
4124+++ b/arch/arm/plat-orion/include/plat/addr-map.h
4125@@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4126 value in bridge_virt_base */
4127 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4128 const int win);
4129-};
4130+} __no_const;
4131
4132 /*
4133 * Information needed to setup one address mapping.
4134diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4135index f5144cd..71f6d1f 100644
4136--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4137+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4138@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4139 int (*started)(unsigned ch);
4140 int (*flush)(unsigned ch);
4141 int (*stop)(unsigned ch);
4142-};
4143+} __no_const;
4144
4145 extern void *samsung_dmadev_get_ops(void);
4146 extern void *s3c_dma_get_ops(void);
4147diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4148index 0c3ba9f..95722b3 100644
4149--- a/arch/arm64/kernel/debug-monitors.c
4150+++ b/arch/arm64/kernel/debug-monitors.c
4151@@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4152 return NOTIFY_OK;
4153 }
4154
4155-static struct notifier_block __cpuinitdata os_lock_nb = {
4156+static struct notifier_block os_lock_nb = {
4157 .notifier_call = os_lock_notify,
4158 };
4159
4160diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4161index 5ab825c..96aaec8 100644
4162--- a/arch/arm64/kernel/hw_breakpoint.c
4163+++ b/arch/arm64/kernel/hw_breakpoint.c
4164@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4165 return NOTIFY_OK;
4166 }
4167
4168-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4169+static struct notifier_block hw_breakpoint_reset_nb = {
4170 .notifier_call = hw_breakpoint_reset_notify,
4171 };
4172
4173diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4174index c3a58a1..78fbf54 100644
4175--- a/arch/avr32/include/asm/cache.h
4176+++ b/arch/avr32/include/asm/cache.h
4177@@ -1,8 +1,10 @@
4178 #ifndef __ASM_AVR32_CACHE_H
4179 #define __ASM_AVR32_CACHE_H
4180
4181+#include <linux/const.h>
4182+
4183 #define L1_CACHE_SHIFT 5
4184-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4185+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4186
4187 /*
4188 * Memory returned by kmalloc() may be used for DMA, so we must make
4189diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4190index e2c3287..6c4f98c 100644
4191--- a/arch/avr32/include/asm/elf.h
4192+++ b/arch/avr32/include/asm/elf.h
4193@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4194 the loader. We need to make sure that it is out of the way of the program
4195 that it will "exec", and that there is sufficient room for the brk. */
4196
4197-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4198+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4199
4200+#ifdef CONFIG_PAX_ASLR
4201+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4202+
4203+#define PAX_DELTA_MMAP_LEN 15
4204+#define PAX_DELTA_STACK_LEN 15
4205+#endif
4206
4207 /* This yields a mask that user programs can use to figure out what
4208 instruction set this CPU supports. This could be done in user space,
4209diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4210index 479330b..53717a8 100644
4211--- a/arch/avr32/include/asm/kmap_types.h
4212+++ b/arch/avr32/include/asm/kmap_types.h
4213@@ -2,9 +2,9 @@
4214 #define __ASM_AVR32_KMAP_TYPES_H
4215
4216 #ifdef CONFIG_DEBUG_HIGHMEM
4217-# define KM_TYPE_NR 29
4218+# define KM_TYPE_NR 30
4219 #else
4220-# define KM_TYPE_NR 14
4221+# define KM_TYPE_NR 15
4222 #endif
4223
4224 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4225diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4226index b2f2d2d..d1c85cb 100644
4227--- a/arch/avr32/mm/fault.c
4228+++ b/arch/avr32/mm/fault.c
4229@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4230
4231 int exception_trace = 1;
4232
4233+#ifdef CONFIG_PAX_PAGEEXEC
4234+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4235+{
4236+ unsigned long i;
4237+
4238+ printk(KERN_ERR "PAX: bytes at PC: ");
4239+ for (i = 0; i < 20; i++) {
4240+ unsigned char c;
4241+ if (get_user(c, (unsigned char *)pc+i))
4242+ printk(KERN_CONT "???????? ");
4243+ else
4244+ printk(KERN_CONT "%02x ", c);
4245+ }
4246+ printk("\n");
4247+}
4248+#endif
4249+
4250 /*
4251 * This routine handles page faults. It determines the address and the
4252 * problem, and then passes it off to one of the appropriate routines.
4253@@ -174,6 +191,16 @@ bad_area:
4254 up_read(&mm->mmap_sem);
4255
4256 if (user_mode(regs)) {
4257+
4258+#ifdef CONFIG_PAX_PAGEEXEC
4259+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4260+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4261+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4262+ do_group_exit(SIGKILL);
4263+ }
4264+ }
4265+#endif
4266+
4267 if (exception_trace && printk_ratelimit())
4268 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4269 "sp %08lx ecr %lu\n",
4270diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4271index 568885a..f8008df 100644
4272--- a/arch/blackfin/include/asm/cache.h
4273+++ b/arch/blackfin/include/asm/cache.h
4274@@ -7,6 +7,7 @@
4275 #ifndef __ARCH_BLACKFIN_CACHE_H
4276 #define __ARCH_BLACKFIN_CACHE_H
4277
4278+#include <linux/const.h>
4279 #include <linux/linkage.h> /* for asmlinkage */
4280
4281 /*
4282@@ -14,7 +15,7 @@
4283 * Blackfin loads 32 bytes for cache
4284 */
4285 #define L1_CACHE_SHIFT 5
4286-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4287+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4288 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4289
4290 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4291diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4292index aea2718..3639a60 100644
4293--- a/arch/cris/include/arch-v10/arch/cache.h
4294+++ b/arch/cris/include/arch-v10/arch/cache.h
4295@@ -1,8 +1,9 @@
4296 #ifndef _ASM_ARCH_CACHE_H
4297 #define _ASM_ARCH_CACHE_H
4298
4299+#include <linux/const.h>
4300 /* Etrax 100LX have 32-byte cache-lines. */
4301-#define L1_CACHE_BYTES 32
4302 #define L1_CACHE_SHIFT 5
4303+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4304
4305 #endif /* _ASM_ARCH_CACHE_H */
4306diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4307index 7caf25d..ee65ac5 100644
4308--- a/arch/cris/include/arch-v32/arch/cache.h
4309+++ b/arch/cris/include/arch-v32/arch/cache.h
4310@@ -1,11 +1,12 @@
4311 #ifndef _ASM_CRIS_ARCH_CACHE_H
4312 #define _ASM_CRIS_ARCH_CACHE_H
4313
4314+#include <linux/const.h>
4315 #include <arch/hwregs/dma.h>
4316
4317 /* A cache-line is 32 bytes. */
4318-#define L1_CACHE_BYTES 32
4319 #define L1_CACHE_SHIFT 5
4320+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4321
4322 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4323
4324diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4325index b86329d..6709906 100644
4326--- a/arch/frv/include/asm/atomic.h
4327+++ b/arch/frv/include/asm/atomic.h
4328@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4329 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4330 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4331
4332+#define atomic64_read_unchecked(v) atomic64_read(v)
4333+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4334+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4335+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4336+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4337+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4338+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4339+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4340+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4341+
4342 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4343 {
4344 int c, old;
4345diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4346index 2797163..c2a401d 100644
4347--- a/arch/frv/include/asm/cache.h
4348+++ b/arch/frv/include/asm/cache.h
4349@@ -12,10 +12,11 @@
4350 #ifndef __ASM_CACHE_H
4351 #define __ASM_CACHE_H
4352
4353+#include <linux/const.h>
4354
4355 /* bytes per L1 cache line */
4356 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4357-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4358+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4359
4360 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4361 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4362diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4363index 43901f2..0d8b865 100644
4364--- a/arch/frv/include/asm/kmap_types.h
4365+++ b/arch/frv/include/asm/kmap_types.h
4366@@ -2,6 +2,6 @@
4367 #ifndef _ASM_KMAP_TYPES_H
4368 #define _ASM_KMAP_TYPES_H
4369
4370-#define KM_TYPE_NR 17
4371+#define KM_TYPE_NR 18
4372
4373 #endif
4374diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4375index 385fd30..3aaf4fe 100644
4376--- a/arch/frv/mm/elf-fdpic.c
4377+++ b/arch/frv/mm/elf-fdpic.c
4378@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4379 {
4380 struct vm_area_struct *vma;
4381 unsigned long limit;
4382+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4383
4384 if (len > TASK_SIZE)
4385 return -ENOMEM;
4386@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4387 if (addr) {
4388 addr = PAGE_ALIGN(addr);
4389 vma = find_vma(current->mm, addr);
4390- if (TASK_SIZE - len >= addr &&
4391- (!vma || addr + len <= vma->vm_start))
4392+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4393 goto success;
4394 }
4395
4396@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4397 for (; vma; vma = vma->vm_next) {
4398 if (addr > limit)
4399 break;
4400- if (addr + len <= vma->vm_start)
4401+ if (check_heap_stack_gap(vma, addr, len, offset))
4402 goto success;
4403 addr = vma->vm_end;
4404 }
4405@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4406 for (; vma; vma = vma->vm_next) {
4407 if (addr > limit)
4408 break;
4409- if (addr + len <= vma->vm_start)
4410+ if (check_heap_stack_gap(vma, addr, len, offset))
4411 goto success;
4412 addr = vma->vm_end;
4413 }
4414diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4415index f4ca594..adc72fd6 100644
4416--- a/arch/hexagon/include/asm/cache.h
4417+++ b/arch/hexagon/include/asm/cache.h
4418@@ -21,9 +21,11 @@
4419 #ifndef __ASM_CACHE_H
4420 #define __ASM_CACHE_H
4421
4422+#include <linux/const.h>
4423+
4424 /* Bytes per L1 cache line */
4425-#define L1_CACHE_SHIFT (5)
4426-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4427+#define L1_CACHE_SHIFT 5
4428+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4429
4430 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4431 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4432diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4433index 6e6fe18..a6ae668 100644
4434--- a/arch/ia64/include/asm/atomic.h
4435+++ b/arch/ia64/include/asm/atomic.h
4436@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4437 #define atomic64_inc(v) atomic64_add(1, (v))
4438 #define atomic64_dec(v) atomic64_sub(1, (v))
4439
4440+#define atomic64_read_unchecked(v) atomic64_read(v)
4441+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4442+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4443+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4444+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4445+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4446+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4447+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4448+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4449+
4450 /* Atomic operations are already serializing */
4451 #define smp_mb__before_atomic_dec() barrier()
4452 #define smp_mb__after_atomic_dec() barrier()
4453diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4454index 988254a..e1ee885 100644
4455--- a/arch/ia64/include/asm/cache.h
4456+++ b/arch/ia64/include/asm/cache.h
4457@@ -1,6 +1,7 @@
4458 #ifndef _ASM_IA64_CACHE_H
4459 #define _ASM_IA64_CACHE_H
4460
4461+#include <linux/const.h>
4462
4463 /*
4464 * Copyright (C) 1998-2000 Hewlett-Packard Co
4465@@ -9,7 +10,7 @@
4466
4467 /* Bytes per L1 (data) cache line. */
4468 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4469-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4470+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4471
4472 #ifdef CONFIG_SMP
4473 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4474diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4475index b5298eb..67c6e62 100644
4476--- a/arch/ia64/include/asm/elf.h
4477+++ b/arch/ia64/include/asm/elf.h
4478@@ -42,6 +42,13 @@
4479 */
4480 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4481
4482+#ifdef CONFIG_PAX_ASLR
4483+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4484+
4485+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4486+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4487+#endif
4488+
4489 #define PT_IA_64_UNWIND 0x70000001
4490
4491 /* IA-64 relocations: */
4492diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4493index 96a8d92..617a1cf 100644
4494--- a/arch/ia64/include/asm/pgalloc.h
4495+++ b/arch/ia64/include/asm/pgalloc.h
4496@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4497 pgd_val(*pgd_entry) = __pa(pud);
4498 }
4499
4500+static inline void
4501+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4502+{
4503+ pgd_populate(mm, pgd_entry, pud);
4504+}
4505+
4506 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4507 {
4508 return quicklist_alloc(0, GFP_KERNEL, NULL);
4509@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4510 pud_val(*pud_entry) = __pa(pmd);
4511 }
4512
4513+static inline void
4514+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4515+{
4516+ pud_populate(mm, pud_entry, pmd);
4517+}
4518+
4519 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4520 {
4521 return quicklist_alloc(0, GFP_KERNEL, NULL);
4522diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4523index 815810c..d60bd4c 100644
4524--- a/arch/ia64/include/asm/pgtable.h
4525+++ b/arch/ia64/include/asm/pgtable.h
4526@@ -12,7 +12,7 @@
4527 * David Mosberger-Tang <davidm@hpl.hp.com>
4528 */
4529
4530-
4531+#include <linux/const.h>
4532 #include <asm/mman.h>
4533 #include <asm/page.h>
4534 #include <asm/processor.h>
4535@@ -142,6 +142,17 @@
4536 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4537 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4538 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4539+
4540+#ifdef CONFIG_PAX_PAGEEXEC
4541+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4542+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4543+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4544+#else
4545+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4546+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4547+# define PAGE_COPY_NOEXEC PAGE_COPY
4548+#endif
4549+
4550 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4551 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4552 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4553diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4554index 54ff557..70c88b7 100644
4555--- a/arch/ia64/include/asm/spinlock.h
4556+++ b/arch/ia64/include/asm/spinlock.h
4557@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4558 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4559
4560 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4561- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4562+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4563 }
4564
4565 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4566diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4567index 449c8c0..50cdf87 100644
4568--- a/arch/ia64/include/asm/uaccess.h
4569+++ b/arch/ia64/include/asm/uaccess.h
4570@@ -42,6 +42,8 @@
4571 #include <asm/pgtable.h>
4572 #include <asm/io.h>
4573
4574+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4575+
4576 /*
4577 * For historical reasons, the following macros are grossly misnamed:
4578 */
4579@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4580 static inline unsigned long
4581 __copy_to_user (void __user *to, const void *from, unsigned long count)
4582 {
4583+ if (count > INT_MAX)
4584+ return count;
4585+
4586+ if (!__builtin_constant_p(count))
4587+ check_object_size(from, count, true);
4588+
4589 return __copy_user(to, (__force void __user *) from, count);
4590 }
4591
4592 static inline unsigned long
4593 __copy_from_user (void *to, const void __user *from, unsigned long count)
4594 {
4595+ if (count > INT_MAX)
4596+ return count;
4597+
4598+ if (!__builtin_constant_p(count))
4599+ check_object_size(to, count, false);
4600+
4601 return __copy_user((__force void __user *) to, from, count);
4602 }
4603
4604@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4605 ({ \
4606 void __user *__cu_to = (to); \
4607 const void *__cu_from = (from); \
4608- long __cu_len = (n); \
4609+ unsigned long __cu_len = (n); \
4610 \
4611- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4612+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4613+ if (!__builtin_constant_p(n)) \
4614+ check_object_size(__cu_from, __cu_len, true); \
4615 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4616+ } \
4617 __cu_len; \
4618 })
4619
4620@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4621 ({ \
4622 void *__cu_to = (to); \
4623 const void __user *__cu_from = (from); \
4624- long __cu_len = (n); \
4625+ unsigned long __cu_len = (n); \
4626 \
4627 __chk_user_ptr(__cu_from); \
4628- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4629+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4630+ if (!__builtin_constant_p(n)) \
4631+ check_object_size(__cu_to, __cu_len, false); \
4632 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4633+ } \
4634 __cu_len; \
4635 })
4636
4637diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4638index 2d67317..07d8bfa 100644
4639--- a/arch/ia64/kernel/err_inject.c
4640+++ b/arch/ia64/kernel/err_inject.c
4641@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4642 return NOTIFY_OK;
4643 }
4644
4645-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4646+static struct notifier_block err_inject_cpu_notifier =
4647 {
4648 .notifier_call = err_inject_cpu_callback,
4649 };
4650diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4651index 65bf9cd..794f06b 100644
4652--- a/arch/ia64/kernel/mca.c
4653+++ b/arch/ia64/kernel/mca.c
4654@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4655 return NOTIFY_OK;
4656 }
4657
4658-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4659+static struct notifier_block mca_cpu_notifier = {
4660 .notifier_call = mca_cpu_callback
4661 };
4662
4663diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4664index 24603be..948052d 100644
4665--- a/arch/ia64/kernel/module.c
4666+++ b/arch/ia64/kernel/module.c
4667@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4668 void
4669 module_free (struct module *mod, void *module_region)
4670 {
4671- if (mod && mod->arch.init_unw_table &&
4672- module_region == mod->module_init) {
4673+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4674 unw_remove_unwind_table(mod->arch.init_unw_table);
4675 mod->arch.init_unw_table = NULL;
4676 }
4677@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4678 }
4679
4680 static inline int
4681+in_init_rx (const struct module *mod, uint64_t addr)
4682+{
4683+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4684+}
4685+
4686+static inline int
4687+in_init_rw (const struct module *mod, uint64_t addr)
4688+{
4689+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4690+}
4691+
4692+static inline int
4693 in_init (const struct module *mod, uint64_t addr)
4694 {
4695- return addr - (uint64_t) mod->module_init < mod->init_size;
4696+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4697+}
4698+
4699+static inline int
4700+in_core_rx (const struct module *mod, uint64_t addr)
4701+{
4702+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4703+}
4704+
4705+static inline int
4706+in_core_rw (const struct module *mod, uint64_t addr)
4707+{
4708+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4709 }
4710
4711 static inline int
4712 in_core (const struct module *mod, uint64_t addr)
4713 {
4714- return addr - (uint64_t) mod->module_core < mod->core_size;
4715+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4716 }
4717
4718 static inline int
4719@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4720 break;
4721
4722 case RV_BDREL:
4723- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4724+ if (in_init_rx(mod, val))
4725+ val -= (uint64_t) mod->module_init_rx;
4726+ else if (in_init_rw(mod, val))
4727+ val -= (uint64_t) mod->module_init_rw;
4728+ else if (in_core_rx(mod, val))
4729+ val -= (uint64_t) mod->module_core_rx;
4730+ else if (in_core_rw(mod, val))
4731+ val -= (uint64_t) mod->module_core_rw;
4732 break;
4733
4734 case RV_LTV:
4735@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4736 * addresses have been selected...
4737 */
4738 uint64_t gp;
4739- if (mod->core_size > MAX_LTOFF)
4740+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4741 /*
4742 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4743 * at the end of the module.
4744 */
4745- gp = mod->core_size - MAX_LTOFF / 2;
4746+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4747 else
4748- gp = mod->core_size / 2;
4749- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4750+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4751+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4752 mod->arch.gp = gp;
4753 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4754 }
4755diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4756index 77597e5..6f28f3f 100644
4757--- a/arch/ia64/kernel/palinfo.c
4758+++ b/arch/ia64/kernel/palinfo.c
4759@@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4760 return NOTIFY_OK;
4761 }
4762
4763-static struct notifier_block __refdata palinfo_cpu_notifier =
4764+static struct notifier_block palinfo_cpu_notifier =
4765 {
4766 .notifier_call = palinfo_cpu_callback,
4767 .priority = 0,
4768diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4769index 79802e5..1a89ec5 100644
4770--- a/arch/ia64/kernel/salinfo.c
4771+++ b/arch/ia64/kernel/salinfo.c
4772@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4773 return NOTIFY_OK;
4774 }
4775
4776-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4777+static struct notifier_block salinfo_cpu_notifier =
4778 {
4779 .notifier_call = salinfo_cpu_callback,
4780 .priority = 0,
4781diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4782index d9439ef..d0cac6b 100644
4783--- a/arch/ia64/kernel/sys_ia64.c
4784+++ b/arch/ia64/kernel/sys_ia64.c
4785@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4786 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4787 struct mm_struct *mm = current->mm;
4788 struct vm_area_struct *vma;
4789+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4790
4791 if (len > RGN_MAP_LIMIT)
4792 return -ENOMEM;
4793@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4794 if (REGION_NUMBER(addr) == RGN_HPAGE)
4795 addr = 0;
4796 #endif
4797+
4798+#ifdef CONFIG_PAX_RANDMMAP
4799+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4800+ addr = mm->free_area_cache;
4801+ else
4802+#endif
4803+
4804 if (!addr)
4805 addr = mm->free_area_cache;
4806
4807@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4808 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4809 /* At this point: (!vma || addr < vma->vm_end). */
4810 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4811- if (start_addr != TASK_UNMAPPED_BASE) {
4812+ if (start_addr != mm->mmap_base) {
4813 /* Start a new search --- just in case we missed some holes. */
4814- addr = TASK_UNMAPPED_BASE;
4815+ addr = mm->mmap_base;
4816 goto full_search;
4817 }
4818 return -ENOMEM;
4819 }
4820- if (!vma || addr + len <= vma->vm_start) {
4821+ if (check_heap_stack_gap(vma, addr, len, offset)) {
4822 /* Remember the address where we stopped this search: */
4823 mm->free_area_cache = addr + len;
4824 return addr;
4825diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4826index dc00b2c..cce53c2 100644
4827--- a/arch/ia64/kernel/topology.c
4828+++ b/arch/ia64/kernel/topology.c
4829@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4830 return NOTIFY_OK;
4831 }
4832
4833-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4834+static struct notifier_block cache_cpu_notifier =
4835 {
4836 .notifier_call = cache_cpu_callback
4837 };
4838diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4839index 0ccb28f..8992469 100644
4840--- a/arch/ia64/kernel/vmlinux.lds.S
4841+++ b/arch/ia64/kernel/vmlinux.lds.S
4842@@ -198,7 +198,7 @@ SECTIONS {
4843 /* Per-cpu data: */
4844 . = ALIGN(PERCPU_PAGE_SIZE);
4845 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4846- __phys_per_cpu_start = __per_cpu_load;
4847+ __phys_per_cpu_start = per_cpu_load;
4848 /*
4849 * ensure percpu data fits
4850 * into percpu page size
4851diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4852index 6cf0341..d352594 100644
4853--- a/arch/ia64/mm/fault.c
4854+++ b/arch/ia64/mm/fault.c
4855@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4856 return pte_present(pte);
4857 }
4858
4859+#ifdef CONFIG_PAX_PAGEEXEC
4860+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4861+{
4862+ unsigned long i;
4863+
4864+ printk(KERN_ERR "PAX: bytes at PC: ");
4865+ for (i = 0; i < 8; i++) {
4866+ unsigned int c;
4867+ if (get_user(c, (unsigned int *)pc+i))
4868+ printk(KERN_CONT "???????? ");
4869+ else
4870+ printk(KERN_CONT "%08x ", c);
4871+ }
4872+ printk("\n");
4873+}
4874+#endif
4875+
4876 # define VM_READ_BIT 0
4877 # define VM_WRITE_BIT 1
4878 # define VM_EXEC_BIT 2
4879@@ -149,8 +166,21 @@ retry:
4880 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4881 goto bad_area;
4882
4883- if ((vma->vm_flags & mask) != mask)
4884+ if ((vma->vm_flags & mask) != mask) {
4885+
4886+#ifdef CONFIG_PAX_PAGEEXEC
4887+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4888+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4889+ goto bad_area;
4890+
4891+ up_read(&mm->mmap_sem);
4892+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4893+ do_group_exit(SIGKILL);
4894+ }
4895+#endif
4896+
4897 goto bad_area;
4898+ }
4899
4900 /*
4901 * If for any reason at all we couldn't handle the fault, make
4902diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4903index 5ca674b..127c3cb 100644
4904--- a/arch/ia64/mm/hugetlbpage.c
4905+++ b/arch/ia64/mm/hugetlbpage.c
4906@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4907 unsigned long pgoff, unsigned long flags)
4908 {
4909 struct vm_area_struct *vmm;
4910+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4911
4912 if (len > RGN_MAP_LIMIT)
4913 return -ENOMEM;
4914@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4915 /* At this point: (!vmm || addr < vmm->vm_end). */
4916 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4917 return -ENOMEM;
4918- if (!vmm || (addr + len) <= vmm->vm_start)
4919+ if (check_heap_stack_gap(vmm, addr, len, offset))
4920 return addr;
4921 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4922 }
4923diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4924index b755ea9..b9a969e 100644
4925--- a/arch/ia64/mm/init.c
4926+++ b/arch/ia64/mm/init.c
4927@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4928 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4929 vma->vm_end = vma->vm_start + PAGE_SIZE;
4930 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4931+
4932+#ifdef CONFIG_PAX_PAGEEXEC
4933+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4934+ vma->vm_flags &= ~VM_EXEC;
4935+
4936+#ifdef CONFIG_PAX_MPROTECT
4937+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
4938+ vma->vm_flags &= ~VM_MAYEXEC;
4939+#endif
4940+
4941+ }
4942+#endif
4943+
4944 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4945 down_write(&current->mm->mmap_sem);
4946 if (insert_vm_struct(current->mm, vma)) {
4947diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4948index 40b3ee9..8c2c112 100644
4949--- a/arch/m32r/include/asm/cache.h
4950+++ b/arch/m32r/include/asm/cache.h
4951@@ -1,8 +1,10 @@
4952 #ifndef _ASM_M32R_CACHE_H
4953 #define _ASM_M32R_CACHE_H
4954
4955+#include <linux/const.h>
4956+
4957 /* L1 cache line size */
4958 #define L1_CACHE_SHIFT 4
4959-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4960+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4961
4962 #endif /* _ASM_M32R_CACHE_H */
4963diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4964index 82abd15..d95ae5d 100644
4965--- a/arch/m32r/lib/usercopy.c
4966+++ b/arch/m32r/lib/usercopy.c
4967@@ -14,6 +14,9 @@
4968 unsigned long
4969 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4970 {
4971+ if ((long)n < 0)
4972+ return n;
4973+
4974 prefetch(from);
4975 if (access_ok(VERIFY_WRITE, to, n))
4976 __copy_user(to,from,n);
4977@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4978 unsigned long
4979 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4980 {
4981+ if ((long)n < 0)
4982+ return n;
4983+
4984 prefetchw(to);
4985 if (access_ok(VERIFY_READ, from, n))
4986 __copy_user_zeroing(to,from,n);
4987diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4988index 0395c51..5f26031 100644
4989--- a/arch/m68k/include/asm/cache.h
4990+++ b/arch/m68k/include/asm/cache.h
4991@@ -4,9 +4,11 @@
4992 #ifndef __ARCH_M68K_CACHE_H
4993 #define __ARCH_M68K_CACHE_H
4994
4995+#include <linux/const.h>
4996+
4997 /* bytes per L1 cache line */
4998 #define L1_CACHE_SHIFT 4
4999-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5000+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5001
5002 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5003
5004diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5005index 4efe96a..60e8699 100644
5006--- a/arch/microblaze/include/asm/cache.h
5007+++ b/arch/microblaze/include/asm/cache.h
5008@@ -13,11 +13,12 @@
5009 #ifndef _ASM_MICROBLAZE_CACHE_H
5010 #define _ASM_MICROBLAZE_CACHE_H
5011
5012+#include <linux/const.h>
5013 #include <asm/registers.h>
5014
5015 #define L1_CACHE_SHIFT 5
5016 /* word-granular cache in microblaze */
5017-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5018+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5019
5020 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5021
5022diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5023index 01cc6ba..bcb7a5d 100644
5024--- a/arch/mips/include/asm/atomic.h
5025+++ b/arch/mips/include/asm/atomic.h
5026@@ -21,6 +21,10 @@
5027 #include <asm/cmpxchg.h>
5028 #include <asm/war.h>
5029
5030+#ifdef CONFIG_GENERIC_ATOMIC64
5031+#include <asm-generic/atomic64.h>
5032+#endif
5033+
5034 #define ATOMIC_INIT(i) { (i) }
5035
5036 /*
5037@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5038 */
5039 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5040
5041+#define atomic64_read_unchecked(v) atomic64_read(v)
5042+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5043+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5044+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5045+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5046+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5047+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5048+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5049+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5050+
5051 #endif /* CONFIG_64BIT */
5052
5053 /*
5054diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5055index b4db69f..8f3b093 100644
5056--- a/arch/mips/include/asm/cache.h
5057+++ b/arch/mips/include/asm/cache.h
5058@@ -9,10 +9,11 @@
5059 #ifndef _ASM_CACHE_H
5060 #define _ASM_CACHE_H
5061
5062+#include <linux/const.h>
5063 #include <kmalloc.h>
5064
5065 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5066-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5067+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5068
5069 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5070 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5071diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5072index 455c0ac..ad65fbe 100644
5073--- a/arch/mips/include/asm/elf.h
5074+++ b/arch/mips/include/asm/elf.h
5075@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5076 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5077 #endif
5078
5079+#ifdef CONFIG_PAX_ASLR
5080+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5081+
5082+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5083+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5084+#endif
5085+
5086 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5087 struct linux_binprm;
5088 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5089 int uses_interp);
5090
5091-struct mm_struct;
5092-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5093-#define arch_randomize_brk arch_randomize_brk
5094-
5095 #endif /* _ASM_ELF_H */
5096diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5097index c1f6afa..38cc6e9 100644
5098--- a/arch/mips/include/asm/exec.h
5099+++ b/arch/mips/include/asm/exec.h
5100@@ -12,6 +12,6 @@
5101 #ifndef _ASM_EXEC_H
5102 #define _ASM_EXEC_H
5103
5104-extern unsigned long arch_align_stack(unsigned long sp);
5105+#define arch_align_stack(x) ((x) & ~0xfUL)
5106
5107 #endif /* _ASM_EXEC_H */
5108diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5109index dbaec94..6a14935 100644
5110--- a/arch/mips/include/asm/page.h
5111+++ b/arch/mips/include/asm/page.h
5112@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5113 #ifdef CONFIG_CPU_MIPS32
5114 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5115 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5116- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5117+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5118 #else
5119 typedef struct { unsigned long long pte; } pte_t;
5120 #define pte_val(x) ((x).pte)
5121diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5122index 881d18b..cea38bc 100644
5123--- a/arch/mips/include/asm/pgalloc.h
5124+++ b/arch/mips/include/asm/pgalloc.h
5125@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5126 {
5127 set_pud(pud, __pud((unsigned long)pmd));
5128 }
5129+
5130+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5131+{
5132+ pud_populate(mm, pud, pmd);
5133+}
5134 #endif
5135
5136 /*
5137diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5138index b2050b9..d71bb1b 100644
5139--- a/arch/mips/include/asm/thread_info.h
5140+++ b/arch/mips/include/asm/thread_info.h
5141@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5142 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5143 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5144 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5145+/* li takes a 32bit immediate */
5146+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5147 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5148
5149 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5150@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5151 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5152 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5153 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5154+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5155+
5156+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5157
5158 /* work to do in syscall_trace_leave() */
5159-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5160+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5161
5162 /* work to do on interrupt/exception return */
5163 #define _TIF_WORK_MASK \
5164 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5165 /* work to do on any return to u-space */
5166-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5167+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5168
5169 #endif /* __KERNEL__ */
5170
5171diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5172index 9fdd8bc..4bd7f1a 100644
5173--- a/arch/mips/kernel/binfmt_elfn32.c
5174+++ b/arch/mips/kernel/binfmt_elfn32.c
5175@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5176 #undef ELF_ET_DYN_BASE
5177 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5178
5179+#ifdef CONFIG_PAX_ASLR
5180+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5181+
5182+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5183+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5184+#endif
5185+
5186 #include <asm/processor.h>
5187 #include <linux/module.h>
5188 #include <linux/elfcore.h>
5189diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5190index ff44823..97f8906 100644
5191--- a/arch/mips/kernel/binfmt_elfo32.c
5192+++ b/arch/mips/kernel/binfmt_elfo32.c
5193@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5194 #undef ELF_ET_DYN_BASE
5195 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5196
5197+#ifdef CONFIG_PAX_ASLR
5198+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5199+
5200+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5201+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5202+#endif
5203+
5204 #include <asm/processor.h>
5205
5206 /*
5207diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5208index a11c6f9..be5e164 100644
5209--- a/arch/mips/kernel/process.c
5210+++ b/arch/mips/kernel/process.c
5211@@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5212 out:
5213 return pc;
5214 }
5215-
5216-/*
5217- * Don't forget that the stack pointer must be aligned on a 8 bytes
5218- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5219- */
5220-unsigned long arch_align_stack(unsigned long sp)
5221-{
5222- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5223- sp -= get_random_int() & ~PAGE_MASK;
5224-
5225- return sp & ALMASK;
5226-}
5227diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5228index 4812c6d..2069554 100644
5229--- a/arch/mips/kernel/ptrace.c
5230+++ b/arch/mips/kernel/ptrace.c
5231@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5232 return arch;
5233 }
5234
5235+#ifdef CONFIG_GRKERNSEC_SETXID
5236+extern void gr_delayed_cred_worker(void);
5237+#endif
5238+
5239 /*
5240 * Notification of system call entry/exit
5241 * - triggered by current->work.syscall_trace
5242@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5243 /* do the secure computing check first */
5244 secure_computing_strict(regs->regs[2]);
5245
5246+#ifdef CONFIG_GRKERNSEC_SETXID
5247+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5248+ gr_delayed_cred_worker();
5249+#endif
5250+
5251 if (!(current->ptrace & PT_PTRACED))
5252 goto out;
5253
5254diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5255index d20a4bc..7096ae5 100644
5256--- a/arch/mips/kernel/scall32-o32.S
5257+++ b/arch/mips/kernel/scall32-o32.S
5258@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5259
5260 stack_done:
5261 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5262- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5263+ li t1, _TIF_SYSCALL_WORK
5264 and t0, t1
5265 bnez t0, syscall_trace_entry # -> yes
5266
5267diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5268index b64f642..0fe6eab 100644
5269--- a/arch/mips/kernel/scall64-64.S
5270+++ b/arch/mips/kernel/scall64-64.S
5271@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5272
5273 sd a3, PT_R26(sp) # save a3 for syscall restarting
5274
5275- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5276+ li t1, _TIF_SYSCALL_WORK
5277 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5278 and t0, t1, t0
5279 bnez t0, syscall_trace_entry
5280diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5281index c29ac19..c592d05 100644
5282--- a/arch/mips/kernel/scall64-n32.S
5283+++ b/arch/mips/kernel/scall64-n32.S
5284@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5285
5286 sd a3, PT_R26(sp) # save a3 for syscall restarting
5287
5288- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5289+ li t1, _TIF_SYSCALL_WORK
5290 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5291 and t0, t1, t0
5292 bnez t0, n32_syscall_trace_entry
5293diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5294index cf3e75e..72e93fe 100644
5295--- a/arch/mips/kernel/scall64-o32.S
5296+++ b/arch/mips/kernel/scall64-o32.S
5297@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5298 PTR 4b, bad_stack
5299 .previous
5300
5301- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5302+ li t1, _TIF_SYSCALL_WORK
5303 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5304 and t0, t1, t0
5305 bnez t0, trace_a_syscall
5306diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5307index ddcec1e..c7f983e 100644
5308--- a/arch/mips/mm/fault.c
5309+++ b/arch/mips/mm/fault.c
5310@@ -27,6 +27,23 @@
5311 #include <asm/highmem.h> /* For VMALLOC_END */
5312 #include <linux/kdebug.h>
5313
5314+#ifdef CONFIG_PAX_PAGEEXEC
5315+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5316+{
5317+ unsigned long i;
5318+
5319+ printk(KERN_ERR "PAX: bytes at PC: ");
5320+ for (i = 0; i < 5; i++) {
5321+ unsigned int c;
5322+ if (get_user(c, (unsigned int *)pc+i))
5323+ printk(KERN_CONT "???????? ");
5324+ else
5325+ printk(KERN_CONT "%08x ", c);
5326+ }
5327+ printk("\n");
5328+}
5329+#endif
5330+
5331 /*
5332 * This routine handles page faults. It determines the address,
5333 * and the problem, and then passes it off to one of the appropriate
5334diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5335index 7e5fe27..479a219 100644
5336--- a/arch/mips/mm/mmap.c
5337+++ b/arch/mips/mm/mmap.c
5338@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5339 struct vm_area_struct *vma;
5340 unsigned long addr = addr0;
5341 int do_color_align;
5342+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5343 struct vm_unmapped_area_info info;
5344
5345 if (unlikely(len > TASK_SIZE))
5346@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5347 do_color_align = 1;
5348
5349 /* requesting a specific address */
5350+
5351+#ifdef CONFIG_PAX_RANDMMAP
5352+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5353+#endif
5354+
5355 if (addr) {
5356 if (do_color_align)
5357 addr = COLOUR_ALIGN(addr, pgoff);
5358@@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5359 addr = PAGE_ALIGN(addr);
5360
5361 vma = find_vma(mm, addr);
5362- if (TASK_SIZE - len >= addr &&
5363- (!vma || addr + len <= vma->vm_start))
5364+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5365 return addr;
5366 }
5367
5368@@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5369 {
5370 unsigned long random_factor = 0UL;
5371
5372+#ifdef CONFIG_PAX_RANDMMAP
5373+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5374+#endif
5375+
5376 if (current->flags & PF_RANDOMIZE) {
5377 random_factor = get_random_int();
5378 random_factor = random_factor << PAGE_SHIFT;
5379@@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5380
5381 if (mmap_is_legacy()) {
5382 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5383+
5384+#ifdef CONFIG_PAX_RANDMMAP
5385+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5386+ mm->mmap_base += mm->delta_mmap;
5387+#endif
5388+
5389 mm->get_unmapped_area = arch_get_unmapped_area;
5390 mm->unmap_area = arch_unmap_area;
5391 } else {
5392 mm->mmap_base = mmap_base(random_factor);
5393+
5394+#ifdef CONFIG_PAX_RANDMMAP
5395+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5396+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5397+#endif
5398+
5399 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5400 mm->unmap_area = arch_unmap_area_topdown;
5401 }
5402 }
5403
5404-static inline unsigned long brk_rnd(void)
5405-{
5406- unsigned long rnd = get_random_int();
5407-
5408- rnd = rnd << PAGE_SHIFT;
5409- /* 8MB for 32bit, 256MB for 64bit */
5410- if (TASK_IS_32BIT_ADDR)
5411- rnd = rnd & 0x7ffffful;
5412- else
5413- rnd = rnd & 0xffffffful;
5414-
5415- return rnd;
5416-}
5417-
5418-unsigned long arch_randomize_brk(struct mm_struct *mm)
5419-{
5420- unsigned long base = mm->brk;
5421- unsigned long ret;
5422-
5423- ret = PAGE_ALIGN(base + brk_rnd());
5424-
5425- if (ret < mm->brk)
5426- return mm->brk;
5427-
5428- return ret;
5429-}
5430-
5431 int __virt_addr_valid(const volatile void *kaddr)
5432 {
5433 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5434diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5435index 967d144..db12197 100644
5436--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5437+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5438@@ -11,12 +11,14 @@
5439 #ifndef _ASM_PROC_CACHE_H
5440 #define _ASM_PROC_CACHE_H
5441
5442+#include <linux/const.h>
5443+
5444 /* L1 cache */
5445
5446 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5447 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5448-#define L1_CACHE_BYTES 16 /* bytes per entry */
5449 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5450+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5451 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5452
5453 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5454diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5455index bcb5df2..84fabd2 100644
5456--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5457+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5458@@ -16,13 +16,15 @@
5459 #ifndef _ASM_PROC_CACHE_H
5460 #define _ASM_PROC_CACHE_H
5461
5462+#include <linux/const.h>
5463+
5464 /*
5465 * L1 cache
5466 */
5467 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5468 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5469-#define L1_CACHE_BYTES 32 /* bytes per entry */
5470 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5471+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5472 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5473
5474 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5475diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5476index 4ce7a01..449202a 100644
5477--- a/arch/openrisc/include/asm/cache.h
5478+++ b/arch/openrisc/include/asm/cache.h
5479@@ -19,11 +19,13 @@
5480 #ifndef __ASM_OPENRISC_CACHE_H
5481 #define __ASM_OPENRISC_CACHE_H
5482
5483+#include <linux/const.h>
5484+
5485 /* FIXME: How can we replace these with values from the CPU...
5486 * they shouldn't be hard-coded!
5487 */
5488
5489-#define L1_CACHE_BYTES 16
5490 #define L1_CACHE_SHIFT 4
5491+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5492
5493 #endif /* __ASM_OPENRISC_CACHE_H */
5494diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5495index af9cf30..2aae9b2 100644
5496--- a/arch/parisc/include/asm/atomic.h
5497+++ b/arch/parisc/include/asm/atomic.h
5498@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5499
5500 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5501
5502+#define atomic64_read_unchecked(v) atomic64_read(v)
5503+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5504+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5505+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5506+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5507+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5508+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5509+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5510+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5511+
5512 #endif /* !CONFIG_64BIT */
5513
5514
5515diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5516index 47f11c7..3420df2 100644
5517--- a/arch/parisc/include/asm/cache.h
5518+++ b/arch/parisc/include/asm/cache.h
5519@@ -5,6 +5,7 @@
5520 #ifndef __ARCH_PARISC_CACHE_H
5521 #define __ARCH_PARISC_CACHE_H
5522
5523+#include <linux/const.h>
5524
5525 /*
5526 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5527@@ -15,13 +16,13 @@
5528 * just ruin performance.
5529 */
5530 #ifdef CONFIG_PA20
5531-#define L1_CACHE_BYTES 64
5532 #define L1_CACHE_SHIFT 6
5533 #else
5534-#define L1_CACHE_BYTES 32
5535 #define L1_CACHE_SHIFT 5
5536 #endif
5537
5538+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5539+
5540 #ifndef __ASSEMBLY__
5541
5542 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5543diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5544index 19f6cb1..6c78cf2 100644
5545--- a/arch/parisc/include/asm/elf.h
5546+++ b/arch/parisc/include/asm/elf.h
5547@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5548
5549 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5550
5551+#ifdef CONFIG_PAX_ASLR
5552+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5553+
5554+#define PAX_DELTA_MMAP_LEN 16
5555+#define PAX_DELTA_STACK_LEN 16
5556+#endif
5557+
5558 /* This yields a mask that user programs can use to figure out what
5559 instruction set this CPU supports. This could be done in user space,
5560 but it's not easy, and we've already done it here. */
5561diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5562index fc987a1..6e068ef 100644
5563--- a/arch/parisc/include/asm/pgalloc.h
5564+++ b/arch/parisc/include/asm/pgalloc.h
5565@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5566 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5567 }
5568
5569+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5570+{
5571+ pgd_populate(mm, pgd, pmd);
5572+}
5573+
5574 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5575 {
5576 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5577@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5578 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5579 #define pmd_free(mm, x) do { } while (0)
5580 #define pgd_populate(mm, pmd, pte) BUG()
5581+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5582
5583 #endif
5584
5585diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5586index 7df49fa..38b62bf 100644
5587--- a/arch/parisc/include/asm/pgtable.h
5588+++ b/arch/parisc/include/asm/pgtable.h
5589@@ -218,6 +218,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5590 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5591 #define PAGE_COPY PAGE_EXECREAD
5592 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5593+
5594+#ifdef CONFIG_PAX_PAGEEXEC
5595+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5596+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5597+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5598+#else
5599+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5600+# define PAGE_COPY_NOEXEC PAGE_COPY
5601+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5602+#endif
5603+
5604 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5605 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5606 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5607diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5608index 4ba2c93..f5e3974 100644
5609--- a/arch/parisc/include/asm/uaccess.h
5610+++ b/arch/parisc/include/asm/uaccess.h
5611@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5612 const void __user *from,
5613 unsigned long n)
5614 {
5615- int sz = __compiletime_object_size(to);
5616+ size_t sz = __compiletime_object_size(to);
5617 int ret = -EFAULT;
5618
5619- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5620+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5621 ret = __copy_from_user(to, from, n);
5622 else
5623 copy_from_user_overflow();
5624diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5625index 2a625fb..9908930 100644
5626--- a/arch/parisc/kernel/module.c
5627+++ b/arch/parisc/kernel/module.c
5628@@ -98,16 +98,38 @@
5629
5630 /* three functions to determine where in the module core
5631 * or init pieces the location is */
5632+static inline int in_init_rx(struct module *me, void *loc)
5633+{
5634+ return (loc >= me->module_init_rx &&
5635+ loc < (me->module_init_rx + me->init_size_rx));
5636+}
5637+
5638+static inline int in_init_rw(struct module *me, void *loc)
5639+{
5640+ return (loc >= me->module_init_rw &&
5641+ loc < (me->module_init_rw + me->init_size_rw));
5642+}
5643+
5644 static inline int in_init(struct module *me, void *loc)
5645 {
5646- return (loc >= me->module_init &&
5647- loc <= (me->module_init + me->init_size));
5648+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5649+}
5650+
5651+static inline int in_core_rx(struct module *me, void *loc)
5652+{
5653+ return (loc >= me->module_core_rx &&
5654+ loc < (me->module_core_rx + me->core_size_rx));
5655+}
5656+
5657+static inline int in_core_rw(struct module *me, void *loc)
5658+{
5659+ return (loc >= me->module_core_rw &&
5660+ loc < (me->module_core_rw + me->core_size_rw));
5661 }
5662
5663 static inline int in_core(struct module *me, void *loc)
5664 {
5665- return (loc >= me->module_core &&
5666- loc <= (me->module_core + me->core_size));
5667+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5668 }
5669
5670 static inline int in_local(struct module *me, void *loc)
5671@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5672 }
5673
5674 /* align things a bit */
5675- me->core_size = ALIGN(me->core_size, 16);
5676- me->arch.got_offset = me->core_size;
5677- me->core_size += gots * sizeof(struct got_entry);
5678+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5679+ me->arch.got_offset = me->core_size_rw;
5680+ me->core_size_rw += gots * sizeof(struct got_entry);
5681
5682- me->core_size = ALIGN(me->core_size, 16);
5683- me->arch.fdesc_offset = me->core_size;
5684- me->core_size += fdescs * sizeof(Elf_Fdesc);
5685+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5686+ me->arch.fdesc_offset = me->core_size_rw;
5687+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5688
5689 me->arch.got_max = gots;
5690 me->arch.fdesc_max = fdescs;
5691@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5692
5693 BUG_ON(value == 0);
5694
5695- got = me->module_core + me->arch.got_offset;
5696+ got = me->module_core_rw + me->arch.got_offset;
5697 for (i = 0; got[i].addr; i++)
5698 if (got[i].addr == value)
5699 goto out;
5700@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5701 #ifdef CONFIG_64BIT
5702 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5703 {
5704- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5705+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5706
5707 if (!value) {
5708 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5709@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5710
5711 /* Create new one */
5712 fdesc->addr = value;
5713- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5714+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5715 return (Elf_Addr)fdesc;
5716 }
5717 #endif /* CONFIG_64BIT */
5718@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5719
5720 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5721 end = table + sechdrs[me->arch.unwind_section].sh_size;
5722- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5723+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5724
5725 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5726 me->arch.unwind_section, table, end, gp);
5727diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5728index f76c108..92bad82 100644
5729--- a/arch/parisc/kernel/sys_parisc.c
5730+++ b/arch/parisc/kernel/sys_parisc.c
5731@@ -33,9 +33,11 @@
5732 #include <linux/utsname.h>
5733 #include <linux/personality.h>
5734
5735-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5736+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5737+ unsigned long flags)
5738 {
5739 struct vm_area_struct *vma;
5740+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5741
5742 addr = PAGE_ALIGN(addr);
5743
5744@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5745 /* At this point: (!vma || addr < vma->vm_end). */
5746 if (TASK_SIZE - len < addr)
5747 return -ENOMEM;
5748- if (!vma || addr + len <= vma->vm_start)
5749+ if (check_heap_stack_gap(vma, addr, len, offset))
5750 return addr;
5751 addr = vma->vm_end;
5752 }
5753@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5754 return offset & 0x3FF000;
5755 }
5756
5757-static unsigned long get_shared_area(struct address_space *mapping,
5758- unsigned long addr, unsigned long len, unsigned long pgoff)
5759+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5760+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5761 {
5762 struct vm_area_struct *vma;
5763 int offset = mapping ? get_offset(mapping) : 0;
5764+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5765
5766 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5767
5768@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5769 /* At this point: (!vma || addr < vma->vm_end). */
5770 if (TASK_SIZE - len < addr)
5771 return -ENOMEM;
5772- if (!vma || addr + len <= vma->vm_start)
5773+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
5774 return addr;
5775 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5776 if (addr < vma->vm_end) /* handle wraparound */
5777@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5778 if (flags & MAP_FIXED)
5779 return addr;
5780 if (!addr)
5781- addr = TASK_UNMAPPED_BASE;
5782+ addr = current->mm->mmap_base;
5783
5784 if (filp) {
5785- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5786+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5787 } else if(flags & MAP_SHARED) {
5788- addr = get_shared_area(NULL, addr, len, pgoff);
5789+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5790 } else {
5791- addr = get_unshared_area(addr, len);
5792+ addr = get_unshared_area(filp, addr, len, flags);
5793 }
5794 return addr;
5795 }
5796diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5797index 45ba99f..8e22c33 100644
5798--- a/arch/parisc/kernel/traps.c
5799+++ b/arch/parisc/kernel/traps.c
5800@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5801
5802 down_read(&current->mm->mmap_sem);
5803 vma = find_vma(current->mm,regs->iaoq[0]);
5804- if (vma && (regs->iaoq[0] >= vma->vm_start)
5805- && (vma->vm_flags & VM_EXEC)) {
5806-
5807+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5808 fault_address = regs->iaoq[0];
5809 fault_space = regs->iasq[0];
5810
5811diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5812index 18162ce..94de376 100644
5813--- a/arch/parisc/mm/fault.c
5814+++ b/arch/parisc/mm/fault.c
5815@@ -15,6 +15,7 @@
5816 #include <linux/sched.h>
5817 #include <linux/interrupt.h>
5818 #include <linux/module.h>
5819+#include <linux/unistd.h>
5820
5821 #include <asm/uaccess.h>
5822 #include <asm/traps.h>
5823@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5824 static unsigned long
5825 parisc_acctyp(unsigned long code, unsigned int inst)
5826 {
5827- if (code == 6 || code == 16)
5828+ if (code == 6 || code == 7 || code == 16)
5829 return VM_EXEC;
5830
5831 switch (inst & 0xf0000000) {
5832@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5833 }
5834 #endif
5835
5836+#ifdef CONFIG_PAX_PAGEEXEC
5837+/*
5838+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5839+ *
5840+ * returns 1 when task should be killed
5841+ * 2 when rt_sigreturn trampoline was detected
5842+ * 3 when unpatched PLT trampoline was detected
5843+ */
5844+static int pax_handle_fetch_fault(struct pt_regs *regs)
5845+{
5846+
5847+#ifdef CONFIG_PAX_EMUPLT
5848+ int err;
5849+
5850+ do { /* PaX: unpatched PLT emulation */
5851+ unsigned int bl, depwi;
5852+
5853+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5854+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5855+
5856+ if (err)
5857+ break;
5858+
5859+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5860+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5861+
5862+ err = get_user(ldw, (unsigned int *)addr);
5863+ err |= get_user(bv, (unsigned int *)(addr+4));
5864+ err |= get_user(ldw2, (unsigned int *)(addr+8));
5865+
5866+ if (err)
5867+ break;
5868+
5869+ if (ldw == 0x0E801096U &&
5870+ bv == 0xEAC0C000U &&
5871+ ldw2 == 0x0E881095U)
5872+ {
5873+ unsigned int resolver, map;
5874+
5875+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5876+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5877+ if (err)
5878+ break;
5879+
5880+ regs->gr[20] = instruction_pointer(regs)+8;
5881+ regs->gr[21] = map;
5882+ regs->gr[22] = resolver;
5883+ regs->iaoq[0] = resolver | 3UL;
5884+ regs->iaoq[1] = regs->iaoq[0] + 4;
5885+ return 3;
5886+ }
5887+ }
5888+ } while (0);
5889+#endif
5890+
5891+#ifdef CONFIG_PAX_EMUTRAMP
5892+
5893+#ifndef CONFIG_PAX_EMUSIGRT
5894+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5895+ return 1;
5896+#endif
5897+
5898+ do { /* PaX: rt_sigreturn emulation */
5899+ unsigned int ldi1, ldi2, bel, nop;
5900+
5901+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5902+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5903+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5904+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5905+
5906+ if (err)
5907+ break;
5908+
5909+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5910+ ldi2 == 0x3414015AU &&
5911+ bel == 0xE4008200U &&
5912+ nop == 0x08000240U)
5913+ {
5914+ regs->gr[25] = (ldi1 & 2) >> 1;
5915+ regs->gr[20] = __NR_rt_sigreturn;
5916+ regs->gr[31] = regs->iaoq[1] + 16;
5917+ regs->sr[0] = regs->iasq[1];
5918+ regs->iaoq[0] = 0x100UL;
5919+ regs->iaoq[1] = regs->iaoq[0] + 4;
5920+ regs->iasq[0] = regs->sr[2];
5921+ regs->iasq[1] = regs->sr[2];
5922+ return 2;
5923+ }
5924+ } while (0);
5925+#endif
5926+
5927+ return 1;
5928+}
5929+
5930+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5931+{
5932+ unsigned long i;
5933+
5934+ printk(KERN_ERR "PAX: bytes at PC: ");
5935+ for (i = 0; i < 5; i++) {
5936+ unsigned int c;
5937+ if (get_user(c, (unsigned int *)pc+i))
5938+ printk(KERN_CONT "???????? ");
5939+ else
5940+ printk(KERN_CONT "%08x ", c);
5941+ }
5942+ printk("\n");
5943+}
5944+#endif
5945+
5946 int fixup_exception(struct pt_regs *regs)
5947 {
5948 const struct exception_table_entry *fix;
5949@@ -192,8 +303,33 @@ good_area:
5950
5951 acc_type = parisc_acctyp(code,regs->iir);
5952
5953- if ((vma->vm_flags & acc_type) != acc_type)
5954+ if ((vma->vm_flags & acc_type) != acc_type) {
5955+
5956+#ifdef CONFIG_PAX_PAGEEXEC
5957+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5958+ (address & ~3UL) == instruction_pointer(regs))
5959+ {
5960+ up_read(&mm->mmap_sem);
5961+ switch (pax_handle_fetch_fault(regs)) {
5962+
5963+#ifdef CONFIG_PAX_EMUPLT
5964+ case 3:
5965+ return;
5966+#endif
5967+
5968+#ifdef CONFIG_PAX_EMUTRAMP
5969+ case 2:
5970+ return;
5971+#endif
5972+
5973+ }
5974+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5975+ do_group_exit(SIGKILL);
5976+ }
5977+#endif
5978+
5979 goto bad_area;
5980+ }
5981
5982 /*
5983 * If for any reason at all we couldn't handle the fault, make
5984diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5985index e3b1d41..8e81edf 100644
5986--- a/arch/powerpc/include/asm/atomic.h
5987+++ b/arch/powerpc/include/asm/atomic.h
5988@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5989 return t1;
5990 }
5991
5992+#define atomic64_read_unchecked(v) atomic64_read(v)
5993+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5994+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5995+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5996+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5997+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5998+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5999+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6000+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6001+
6002 #endif /* __powerpc64__ */
6003
6004 #endif /* __KERNEL__ */
6005diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6006index 9e495c9..b6878e5 100644
6007--- a/arch/powerpc/include/asm/cache.h
6008+++ b/arch/powerpc/include/asm/cache.h
6009@@ -3,6 +3,7 @@
6010
6011 #ifdef __KERNEL__
6012
6013+#include <linux/const.h>
6014
6015 /* bytes per L1 cache line */
6016 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6017@@ -22,7 +23,7 @@
6018 #define L1_CACHE_SHIFT 7
6019 #endif
6020
6021-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6022+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6023
6024 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6025
6026diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6027index 6abf0a1..459d0f1 100644
6028--- a/arch/powerpc/include/asm/elf.h
6029+++ b/arch/powerpc/include/asm/elf.h
6030@@ -28,8 +28,19 @@
6031 the loader. We need to make sure that it is out of the way of the program
6032 that it will "exec", and that there is sufficient room for the brk. */
6033
6034-extern unsigned long randomize_et_dyn(unsigned long base);
6035-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6036+#define ELF_ET_DYN_BASE (0x20000000)
6037+
6038+#ifdef CONFIG_PAX_ASLR
6039+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6040+
6041+#ifdef __powerpc64__
6042+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6043+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6044+#else
6045+#define PAX_DELTA_MMAP_LEN 15
6046+#define PAX_DELTA_STACK_LEN 15
6047+#endif
6048+#endif
6049
6050 /*
6051 * Our registers are always unsigned longs, whether we're a 32 bit
6052@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6053 (0x7ff >> (PAGE_SHIFT - 12)) : \
6054 (0x3ffff >> (PAGE_SHIFT - 12)))
6055
6056-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6057-#define arch_randomize_brk arch_randomize_brk
6058-
6059-
6060 #ifdef CONFIG_SPU_BASE
6061 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6062 #define NT_SPU 1
6063diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6064index 8196e9c..d83a9f3 100644
6065--- a/arch/powerpc/include/asm/exec.h
6066+++ b/arch/powerpc/include/asm/exec.h
6067@@ -4,6 +4,6 @@
6068 #ifndef _ASM_POWERPC_EXEC_H
6069 #define _ASM_POWERPC_EXEC_H
6070
6071-extern unsigned long arch_align_stack(unsigned long sp);
6072+#define arch_align_stack(x) ((x) & ~0xfUL)
6073
6074 #endif /* _ASM_POWERPC_EXEC_H */
6075diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6076index 5acabbd..7ea14fa 100644
6077--- a/arch/powerpc/include/asm/kmap_types.h
6078+++ b/arch/powerpc/include/asm/kmap_types.h
6079@@ -10,7 +10,7 @@
6080 * 2 of the License, or (at your option) any later version.
6081 */
6082
6083-#define KM_TYPE_NR 16
6084+#define KM_TYPE_NR 17
6085
6086 #endif /* __KERNEL__ */
6087 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6088diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6089index 8565c25..2865190 100644
6090--- a/arch/powerpc/include/asm/mman.h
6091+++ b/arch/powerpc/include/asm/mman.h
6092@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6093 }
6094 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6095
6096-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6097+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6098 {
6099 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6100 }
6101diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6102index f072e97..b436dee 100644
6103--- a/arch/powerpc/include/asm/page.h
6104+++ b/arch/powerpc/include/asm/page.h
6105@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6106 * and needs to be executable. This means the whole heap ends
6107 * up being executable.
6108 */
6109-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6110- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6111+#define VM_DATA_DEFAULT_FLAGS32 \
6112+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6113+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6114
6115 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6116 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6117@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6118 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6119 #endif
6120
6121+#define ktla_ktva(addr) (addr)
6122+#define ktva_ktla(addr) (addr)
6123+
6124 /*
6125 * Use the top bit of the higher-level page table entries to indicate whether
6126 * the entries we point to contain hugepages. This works because we know that
6127diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6128index cd915d6..c10cee8 100644
6129--- a/arch/powerpc/include/asm/page_64.h
6130+++ b/arch/powerpc/include/asm/page_64.h
6131@@ -154,15 +154,18 @@ do { \
6132 * stack by default, so in the absence of a PT_GNU_STACK program header
6133 * we turn execute permission off.
6134 */
6135-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6136- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6137+#define VM_STACK_DEFAULT_FLAGS32 \
6138+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6139+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6140
6141 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6142 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6143
6144+#ifndef CONFIG_PAX_PAGEEXEC
6145 #define VM_STACK_DEFAULT_FLAGS \
6146 (is_32bit_task() ? \
6147 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6148+#endif
6149
6150 #include <asm-generic/getorder.h>
6151
6152diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6153index 292725c..f87ae14 100644
6154--- a/arch/powerpc/include/asm/pgalloc-64.h
6155+++ b/arch/powerpc/include/asm/pgalloc-64.h
6156@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6157 #ifndef CONFIG_PPC_64K_PAGES
6158
6159 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6160+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6161
6162 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6163 {
6164@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6165 pud_set(pud, (unsigned long)pmd);
6166 }
6167
6168+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6169+{
6170+ pud_populate(mm, pud, pmd);
6171+}
6172+
6173 #define pmd_populate(mm, pmd, pte_page) \
6174 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6175 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6176@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6177 #else /* CONFIG_PPC_64K_PAGES */
6178
6179 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6180+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6181
6182 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6183 pte_t *pte)
6184diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6185index a9cbd3b..3b67efa 100644
6186--- a/arch/powerpc/include/asm/pgtable.h
6187+++ b/arch/powerpc/include/asm/pgtable.h
6188@@ -2,6 +2,7 @@
6189 #define _ASM_POWERPC_PGTABLE_H
6190 #ifdef __KERNEL__
6191
6192+#include <linux/const.h>
6193 #ifndef __ASSEMBLY__
6194 #include <asm/processor.h> /* For TASK_SIZE */
6195 #include <asm/mmu.h>
6196diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6197index 4aad413..85d86bf 100644
6198--- a/arch/powerpc/include/asm/pte-hash32.h
6199+++ b/arch/powerpc/include/asm/pte-hash32.h
6200@@ -21,6 +21,7 @@
6201 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6202 #define _PAGE_USER 0x004 /* usermode access allowed */
6203 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6204+#define _PAGE_EXEC _PAGE_GUARDED
6205 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6206 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6207 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6208diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6209index 3d5c9dc..62f8414 100644
6210--- a/arch/powerpc/include/asm/reg.h
6211+++ b/arch/powerpc/include/asm/reg.h
6212@@ -215,6 +215,7 @@
6213 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6214 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6215 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6216+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6217 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6218 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6219 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6220diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6221index 406b7b9..af63426 100644
6222--- a/arch/powerpc/include/asm/thread_info.h
6223+++ b/arch/powerpc/include/asm/thread_info.h
6224@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6225 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6226 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6227 #define TIF_SINGLESTEP 8 /* singlestepping active */
6228-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6229 #define TIF_SECCOMP 10 /* secure computing */
6230 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6231 #define TIF_NOERROR 12 /* Force successful syscall return */
6232@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6233 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6234 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6235 for stack store? */
6236+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6237+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6238+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6239
6240 /* as above, but as bit values */
6241 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6242@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6243 #define _TIF_UPROBE (1<<TIF_UPROBE)
6244 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6245 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6246+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6247 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6248- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6249+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6250+ _TIF_GRSEC_SETXID)
6251
6252 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6253 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6254diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6255index 4db4959..335e00c 100644
6256--- a/arch/powerpc/include/asm/uaccess.h
6257+++ b/arch/powerpc/include/asm/uaccess.h
6258@@ -13,6 +13,8 @@
6259 #define VERIFY_READ 0
6260 #define VERIFY_WRITE 1
6261
6262+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6263+
6264 /*
6265 * The fs value determines whether argument validity checking should be
6266 * performed or not. If get_fs() == USER_DS, checking is performed, with
6267@@ -318,52 +320,6 @@ do { \
6268 extern unsigned long __copy_tofrom_user(void __user *to,
6269 const void __user *from, unsigned long size);
6270
6271-#ifndef __powerpc64__
6272-
6273-static inline unsigned long copy_from_user(void *to,
6274- const void __user *from, unsigned long n)
6275-{
6276- unsigned long over;
6277-
6278- if (access_ok(VERIFY_READ, from, n))
6279- return __copy_tofrom_user((__force void __user *)to, from, n);
6280- if ((unsigned long)from < TASK_SIZE) {
6281- over = (unsigned long)from + n - TASK_SIZE;
6282- return __copy_tofrom_user((__force void __user *)to, from,
6283- n - over) + over;
6284- }
6285- return n;
6286-}
6287-
6288-static inline unsigned long copy_to_user(void __user *to,
6289- const void *from, unsigned long n)
6290-{
6291- unsigned long over;
6292-
6293- if (access_ok(VERIFY_WRITE, to, n))
6294- return __copy_tofrom_user(to, (__force void __user *)from, n);
6295- if ((unsigned long)to < TASK_SIZE) {
6296- over = (unsigned long)to + n - TASK_SIZE;
6297- return __copy_tofrom_user(to, (__force void __user *)from,
6298- n - over) + over;
6299- }
6300- return n;
6301-}
6302-
6303-#else /* __powerpc64__ */
6304-
6305-#define __copy_in_user(to, from, size) \
6306- __copy_tofrom_user((to), (from), (size))
6307-
6308-extern unsigned long copy_from_user(void *to, const void __user *from,
6309- unsigned long n);
6310-extern unsigned long copy_to_user(void __user *to, const void *from,
6311- unsigned long n);
6312-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6313- unsigned long n);
6314-
6315-#endif /* __powerpc64__ */
6316-
6317 static inline unsigned long __copy_from_user_inatomic(void *to,
6318 const void __user *from, unsigned long n)
6319 {
6320@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6321 if (ret == 0)
6322 return 0;
6323 }
6324+
6325+ if (!__builtin_constant_p(n))
6326+ check_object_size(to, n, false);
6327+
6328 return __copy_tofrom_user((__force void __user *)to, from, n);
6329 }
6330
6331@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6332 if (ret == 0)
6333 return 0;
6334 }
6335+
6336+ if (!__builtin_constant_p(n))
6337+ check_object_size(from, n, true);
6338+
6339 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6340 }
6341
6342@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6343 return __copy_to_user_inatomic(to, from, size);
6344 }
6345
6346+#ifndef __powerpc64__
6347+
6348+static inline unsigned long __must_check copy_from_user(void *to,
6349+ const void __user *from, unsigned long n)
6350+{
6351+ unsigned long over;
6352+
6353+ if ((long)n < 0)
6354+ return n;
6355+
6356+ if (access_ok(VERIFY_READ, from, n)) {
6357+ if (!__builtin_constant_p(n))
6358+ check_object_size(to, n, false);
6359+ return __copy_tofrom_user((__force void __user *)to, from, n);
6360+ }
6361+ if ((unsigned long)from < TASK_SIZE) {
6362+ over = (unsigned long)from + n - TASK_SIZE;
6363+ if (!__builtin_constant_p(n - over))
6364+ check_object_size(to, n - over, false);
6365+ return __copy_tofrom_user((__force void __user *)to, from,
6366+ n - over) + over;
6367+ }
6368+ return n;
6369+}
6370+
6371+static inline unsigned long __must_check copy_to_user(void __user *to,
6372+ const void *from, unsigned long n)
6373+{
6374+ unsigned long over;
6375+
6376+ if ((long)n < 0)
6377+ return n;
6378+
6379+ if (access_ok(VERIFY_WRITE, to, n)) {
6380+ if (!__builtin_constant_p(n))
6381+ check_object_size(from, n, true);
6382+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6383+ }
6384+ if ((unsigned long)to < TASK_SIZE) {
6385+ over = (unsigned long)to + n - TASK_SIZE;
6386+ if (!__builtin_constant_p(n))
6387+ check_object_size(from, n - over, true);
6388+ return __copy_tofrom_user(to, (__force void __user *)from,
6389+ n - over) + over;
6390+ }
6391+ return n;
6392+}
6393+
6394+#else /* __powerpc64__ */
6395+
6396+#define __copy_in_user(to, from, size) \
6397+ __copy_tofrom_user((to), (from), (size))
6398+
6399+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6400+{
6401+ if ((long)n < 0 || n > INT_MAX)
6402+ return n;
6403+
6404+ if (!__builtin_constant_p(n))
6405+ check_object_size(to, n, false);
6406+
6407+ if (likely(access_ok(VERIFY_READ, from, n)))
6408+ n = __copy_from_user(to, from, n);
6409+ else
6410+ memset(to, 0, n);
6411+ return n;
6412+}
6413+
6414+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6415+{
6416+ if ((long)n < 0 || n > INT_MAX)
6417+ return n;
6418+
6419+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6420+ if (!__builtin_constant_p(n))
6421+ check_object_size(from, n, true);
6422+ n = __copy_to_user(to, from, n);
6423+ }
6424+ return n;
6425+}
6426+
6427+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6428+ unsigned long n);
6429+
6430+#endif /* __powerpc64__ */
6431+
6432 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6433
6434 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6435diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6436index 4684e33..acc4d19e 100644
6437--- a/arch/powerpc/kernel/exceptions-64e.S
6438+++ b/arch/powerpc/kernel/exceptions-64e.S
6439@@ -715,6 +715,7 @@ storage_fault_common:
6440 std r14,_DAR(r1)
6441 std r15,_DSISR(r1)
6442 addi r3,r1,STACK_FRAME_OVERHEAD
6443+ bl .save_nvgprs
6444 mr r4,r14
6445 mr r5,r15
6446 ld r14,PACA_EXGEN+EX_R14(r13)
6447@@ -723,8 +724,7 @@ storage_fault_common:
6448 cmpdi r3,0
6449 bne- 1f
6450 b .ret_from_except_lite
6451-1: bl .save_nvgprs
6452- mr r5,r3
6453+1: mr r5,r3
6454 addi r3,r1,STACK_FRAME_OVERHEAD
6455 ld r4,_DAR(r1)
6456 bl .bad_page_fault
6457diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6458index 4665e82..080ea99 100644
6459--- a/arch/powerpc/kernel/exceptions-64s.S
6460+++ b/arch/powerpc/kernel/exceptions-64s.S
6461@@ -1206,10 +1206,10 @@ handle_page_fault:
6462 11: ld r4,_DAR(r1)
6463 ld r5,_DSISR(r1)
6464 addi r3,r1,STACK_FRAME_OVERHEAD
6465+ bl .save_nvgprs
6466 bl .do_page_fault
6467 cmpdi r3,0
6468 beq+ 12f
6469- bl .save_nvgprs
6470 mr r5,r3
6471 addi r3,r1,STACK_FRAME_OVERHEAD
6472 lwz r4,_DAR(r1)
6473diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6474index 2e3200c..72095ce 100644
6475--- a/arch/powerpc/kernel/module_32.c
6476+++ b/arch/powerpc/kernel/module_32.c
6477@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6478 me->arch.core_plt_section = i;
6479 }
6480 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6481- printk("Module doesn't contain .plt or .init.plt sections.\n");
6482+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6483 return -ENOEXEC;
6484 }
6485
6486@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6487
6488 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6489 /* Init, or core PLT? */
6490- if (location >= mod->module_core
6491- && location < mod->module_core + mod->core_size)
6492+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6493+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6494 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6495- else
6496+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6497+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6498 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6499+ else {
6500+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6501+ return ~0UL;
6502+ }
6503
6504 /* Find this entry, or if that fails, the next avail. entry */
6505 while (entry->jump[0]) {
6506diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6507index 8143067..21ae55b 100644
6508--- a/arch/powerpc/kernel/process.c
6509+++ b/arch/powerpc/kernel/process.c
6510@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6511 * Lookup NIP late so we have the best change of getting the
6512 * above info out without failing
6513 */
6514- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6515- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6516+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6517+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6518 #endif
6519 show_stack(current, (unsigned long *) regs->gpr[1]);
6520 if (!user_mode(regs))
6521@@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6522 newsp = stack[0];
6523 ip = stack[STACK_FRAME_LR_SAVE];
6524 if (!firstframe || ip != lr) {
6525- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6526+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6527 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6528 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6529- printk(" (%pS)",
6530+ printk(" (%pA)",
6531 (void *)current->ret_stack[curr_frame].ret);
6532 curr_frame--;
6533 }
6534@@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6535 struct pt_regs *regs = (struct pt_regs *)
6536 (sp + STACK_FRAME_OVERHEAD);
6537 lr = regs->link;
6538- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6539+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6540 regs->trap, (void *)regs->nip, (void *)lr);
6541 firstframe = 1;
6542 }
6543@@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6544 mtspr(SPRN_CTRLT, ctrl);
6545 }
6546 #endif /* CONFIG_PPC64 */
6547-
6548-unsigned long arch_align_stack(unsigned long sp)
6549-{
6550- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6551- sp -= get_random_int() & ~PAGE_MASK;
6552- return sp & ~0xf;
6553-}
6554-
6555-static inline unsigned long brk_rnd(void)
6556-{
6557- unsigned long rnd = 0;
6558-
6559- /* 8MB for 32bit, 1GB for 64bit */
6560- if (is_32bit_task())
6561- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6562- else
6563- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6564-
6565- return rnd << PAGE_SHIFT;
6566-}
6567-
6568-unsigned long arch_randomize_brk(struct mm_struct *mm)
6569-{
6570- unsigned long base = mm->brk;
6571- unsigned long ret;
6572-
6573-#ifdef CONFIG_PPC_STD_MMU_64
6574- /*
6575- * If we are using 1TB segments and we are allowed to randomise
6576- * the heap, we can put it above 1TB so it is backed by a 1TB
6577- * segment. Otherwise the heap will be in the bottom 1TB
6578- * which always uses 256MB segments and this may result in a
6579- * performance penalty.
6580- */
6581- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6582- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6583-#endif
6584-
6585- ret = PAGE_ALIGN(base + brk_rnd());
6586-
6587- if (ret < mm->brk)
6588- return mm->brk;
6589-
6590- return ret;
6591-}
6592-
6593-unsigned long randomize_et_dyn(unsigned long base)
6594-{
6595- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6596-
6597- if (ret < base)
6598- return base;
6599-
6600- return ret;
6601-}
6602diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6603index c497000..8fde506 100644
6604--- a/arch/powerpc/kernel/ptrace.c
6605+++ b/arch/powerpc/kernel/ptrace.c
6606@@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6607 return ret;
6608 }
6609
6610+#ifdef CONFIG_GRKERNSEC_SETXID
6611+extern void gr_delayed_cred_worker(void);
6612+#endif
6613+
6614 /*
6615 * We must return the syscall number to actually look up in the table.
6616 * This can be -1L to skip running any syscall at all.
6617@@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6618
6619 secure_computing_strict(regs->gpr[0]);
6620
6621+#ifdef CONFIG_GRKERNSEC_SETXID
6622+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6623+ gr_delayed_cred_worker();
6624+#endif
6625+
6626 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6627 tracehook_report_syscall_entry(regs))
6628 /*
6629@@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6630 {
6631 int step;
6632
6633+#ifdef CONFIG_GRKERNSEC_SETXID
6634+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6635+ gr_delayed_cred_worker();
6636+#endif
6637+
6638 audit_syscall_exit(regs);
6639
6640 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6641diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6642index 804e323..79181c1 100644
6643--- a/arch/powerpc/kernel/signal_32.c
6644+++ b/arch/powerpc/kernel/signal_32.c
6645@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6646 /* Save user registers on the stack */
6647 frame = &rt_sf->uc.uc_mcontext;
6648 addr = frame;
6649- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6650+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6651 if (save_user_regs(regs, frame, 0, 1))
6652 goto badframe;
6653 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6654diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6655index 1ca045d..139c3f7 100644
6656--- a/arch/powerpc/kernel/signal_64.c
6657+++ b/arch/powerpc/kernel/signal_64.c
6658@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6659 current->thread.fpscr.val = 0;
6660
6661 /* Set up to return from userspace. */
6662- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6663+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6664 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6665 } else {
6666 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6667diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6668index 3ce1f86..c30e629 100644
6669--- a/arch/powerpc/kernel/sysfs.c
6670+++ b/arch/powerpc/kernel/sysfs.c
6671@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6672 return NOTIFY_OK;
6673 }
6674
6675-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6676+static struct notifier_block sysfs_cpu_nb = {
6677 .notifier_call = sysfs_cpu_notify,
6678 };
6679
6680diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6681index 3251840..3f7c77a 100644
6682--- a/arch/powerpc/kernel/traps.c
6683+++ b/arch/powerpc/kernel/traps.c
6684@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6685 return flags;
6686 }
6687
6688+extern void gr_handle_kernel_exploit(void);
6689+
6690 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6691 int signr)
6692 {
6693@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6694 panic("Fatal exception in interrupt");
6695 if (panic_on_oops)
6696 panic("Fatal exception");
6697+
6698+ gr_handle_kernel_exploit();
6699+
6700 do_exit(signr);
6701 }
6702
6703diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6704index 1b2076f..835e4be 100644
6705--- a/arch/powerpc/kernel/vdso.c
6706+++ b/arch/powerpc/kernel/vdso.c
6707@@ -34,6 +34,7 @@
6708 #include <asm/firmware.h>
6709 #include <asm/vdso.h>
6710 #include <asm/vdso_datapage.h>
6711+#include <asm/mman.h>
6712
6713 #include "setup.h"
6714
6715@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6716 vdso_base = VDSO32_MBASE;
6717 #endif
6718
6719- current->mm->context.vdso_base = 0;
6720+ current->mm->context.vdso_base = ~0UL;
6721
6722 /* vDSO has a problem and was disabled, just don't "enable" it for the
6723 * process
6724@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6725 vdso_base = get_unmapped_area(NULL, vdso_base,
6726 (vdso_pages << PAGE_SHIFT) +
6727 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6728- 0, 0);
6729+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6730 if (IS_ERR_VALUE(vdso_base)) {
6731 rc = vdso_base;
6732 goto fail_mmapsem;
6733diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6734index 5eea6f3..5d10396 100644
6735--- a/arch/powerpc/lib/usercopy_64.c
6736+++ b/arch/powerpc/lib/usercopy_64.c
6737@@ -9,22 +9,6 @@
6738 #include <linux/module.h>
6739 #include <asm/uaccess.h>
6740
6741-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6742-{
6743- if (likely(access_ok(VERIFY_READ, from, n)))
6744- n = __copy_from_user(to, from, n);
6745- else
6746- memset(to, 0, n);
6747- return n;
6748-}
6749-
6750-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6751-{
6752- if (likely(access_ok(VERIFY_WRITE, to, n)))
6753- n = __copy_to_user(to, from, n);
6754- return n;
6755-}
6756-
6757 unsigned long copy_in_user(void __user *to, const void __user *from,
6758 unsigned long n)
6759 {
6760@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6761 return n;
6762 }
6763
6764-EXPORT_SYMBOL(copy_from_user);
6765-EXPORT_SYMBOL(copy_to_user);
6766 EXPORT_SYMBOL(copy_in_user);
6767
6768diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6769index 3a8489a..6a63b3b 100644
6770--- a/arch/powerpc/mm/fault.c
6771+++ b/arch/powerpc/mm/fault.c
6772@@ -32,6 +32,10 @@
6773 #include <linux/perf_event.h>
6774 #include <linux/magic.h>
6775 #include <linux/ratelimit.h>
6776+#include <linux/slab.h>
6777+#include <linux/pagemap.h>
6778+#include <linux/compiler.h>
6779+#include <linux/unistd.h>
6780
6781 #include <asm/firmware.h>
6782 #include <asm/page.h>
6783@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6784 }
6785 #endif
6786
6787+#ifdef CONFIG_PAX_PAGEEXEC
6788+/*
6789+ * PaX: decide what to do with offenders (regs->nip = fault address)
6790+ *
6791+ * returns 1 when task should be killed
6792+ */
6793+static int pax_handle_fetch_fault(struct pt_regs *regs)
6794+{
6795+ return 1;
6796+}
6797+
6798+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6799+{
6800+ unsigned long i;
6801+
6802+ printk(KERN_ERR "PAX: bytes at PC: ");
6803+ for (i = 0; i < 5; i++) {
6804+ unsigned int c;
6805+ if (get_user(c, (unsigned int __user *)pc+i))
6806+ printk(KERN_CONT "???????? ");
6807+ else
6808+ printk(KERN_CONT "%08x ", c);
6809+ }
6810+ printk("\n");
6811+}
6812+#endif
6813+
6814 /*
6815 * Check whether the instruction at regs->nip is a store using
6816 * an update addressing form which will update r1.
6817@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6818 * indicate errors in DSISR but can validly be set in SRR1.
6819 */
6820 if (trap == 0x400)
6821- error_code &= 0x48200000;
6822+ error_code &= 0x58200000;
6823 else
6824 is_write = error_code & DSISR_ISSTORE;
6825 #else
6826@@ -364,7 +395,7 @@ good_area:
6827 * "undefined". Of those that can be set, this is the only
6828 * one which seems bad.
6829 */
6830- if (error_code & 0x10000000)
6831+ if (error_code & DSISR_GUARDED)
6832 /* Guarded storage error. */
6833 goto bad_area;
6834 #endif /* CONFIG_8xx */
6835@@ -379,7 +410,7 @@ good_area:
6836 * processors use the same I/D cache coherency mechanism
6837 * as embedded.
6838 */
6839- if (error_code & DSISR_PROTFAULT)
6840+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6841 goto bad_area;
6842 #endif /* CONFIG_PPC_STD_MMU */
6843
6844@@ -462,6 +493,23 @@ bad_area:
6845 bad_area_nosemaphore:
6846 /* User mode accesses cause a SIGSEGV */
6847 if (user_mode(regs)) {
6848+
6849+#ifdef CONFIG_PAX_PAGEEXEC
6850+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6851+#ifdef CONFIG_PPC_STD_MMU
6852+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6853+#else
6854+ if (is_exec && regs->nip == address) {
6855+#endif
6856+ switch (pax_handle_fetch_fault(regs)) {
6857+ }
6858+
6859+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6860+ do_group_exit(SIGKILL);
6861+ }
6862+ }
6863+#endif
6864+
6865 _exception(SIGSEGV, regs, code, address);
6866 return 0;
6867 }
6868diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6869index 67a42ed..cd463e0 100644
6870--- a/arch/powerpc/mm/mmap_64.c
6871+++ b/arch/powerpc/mm/mmap_64.c
6872@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6873 {
6874 unsigned long rnd = 0;
6875
6876+#ifdef CONFIG_PAX_RANDMMAP
6877+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6878+#endif
6879+
6880 if (current->flags & PF_RANDOMIZE) {
6881 /* 8MB for 32bit, 1GB for 64bit */
6882 if (is_32bit_task())
6883@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6884 */
6885 if (mmap_is_legacy()) {
6886 mm->mmap_base = TASK_UNMAPPED_BASE;
6887+
6888+#ifdef CONFIG_PAX_RANDMMAP
6889+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6890+ mm->mmap_base += mm->delta_mmap;
6891+#endif
6892+
6893 mm->get_unmapped_area = arch_get_unmapped_area;
6894 mm->unmap_area = arch_unmap_area;
6895 } else {
6896 mm->mmap_base = mmap_base();
6897+
6898+#ifdef CONFIG_PAX_RANDMMAP
6899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6900+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6901+#endif
6902+
6903 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6904 mm->unmap_area = arch_unmap_area_topdown;
6905 }
6906diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6907index e779642..e5bb889 100644
6908--- a/arch/powerpc/mm/mmu_context_nohash.c
6909+++ b/arch/powerpc/mm/mmu_context_nohash.c
6910@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6911 return NOTIFY_OK;
6912 }
6913
6914-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6915+static struct notifier_block mmu_context_cpu_nb = {
6916 .notifier_call = mmu_context_cpu_notify,
6917 };
6918
6919diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6920index bba87ca..c346a33 100644
6921--- a/arch/powerpc/mm/numa.c
6922+++ b/arch/powerpc/mm/numa.c
6923@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6924 return ret;
6925 }
6926
6927-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6928+static struct notifier_block ppc64_numa_nb = {
6929 .notifier_call = cpu_numa_callback,
6930 .priority = 1 /* Must run before sched domains notifier. */
6931 };
6932diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6933index cf9dada..241529f 100644
6934--- a/arch/powerpc/mm/slice.c
6935+++ b/arch/powerpc/mm/slice.c
6936@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6937 if ((mm->task_size - len) < addr)
6938 return 0;
6939 vma = find_vma(mm, addr);
6940- return (!vma || (addr + len) <= vma->vm_start);
6941+ return check_heap_stack_gap(vma, addr, len, 0);
6942 }
6943
6944 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6945@@ -272,7 +272,7 @@ full_search:
6946 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6947 continue;
6948 }
6949- if (!vma || addr + len <= vma->vm_start) {
6950+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6951 /*
6952 * Remember the place where we stopped the search:
6953 */
6954@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6955 }
6956 }
6957
6958- addr = mm->mmap_base;
6959- while (addr > len) {
6960+ if (mm->mmap_base < len)
6961+ addr = -ENOMEM;
6962+ else
6963+ addr = mm->mmap_base - len;
6964+
6965+ while (!IS_ERR_VALUE(addr)) {
6966 /* Go down by chunk size */
6967- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6968+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
6969
6970 /* Check for hit with different page size */
6971 mask = slice_range_to_mask(addr, len);
6972@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6973 * return with success:
6974 */
6975 vma = find_vma(mm, addr);
6976- if (!vma || (addr + len) <= vma->vm_start) {
6977+ if (check_heap_stack_gap(vma, addr, len, 0)) {
6978 /* remember the address as a hint for next time */
6979 if (use_cache)
6980 mm->free_area_cache = addr;
6981@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6982 mm->cached_hole_size = vma->vm_start - addr;
6983
6984 /* try just below the current vma->vm_start */
6985- addr = vma->vm_start;
6986+ addr = skip_heap_stack_gap(vma, len, 0);
6987 }
6988
6989 /*
6990@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6991 if (fixed && addr > (mm->task_size - len))
6992 return -EINVAL;
6993
6994+#ifdef CONFIG_PAX_RANDMMAP
6995+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6996+ addr = 0;
6997+#endif
6998+
6999 /* If hint, make sure it matches our alignment restrictions */
7000 if (!fixed && addr) {
7001 addr = _ALIGN_UP(addr, 1ul << pshift);
7002diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7003index bdb738a..49c9f95 100644
7004--- a/arch/powerpc/platforms/powermac/smp.c
7005+++ b/arch/powerpc/platforms/powermac/smp.c
7006@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7007 return NOTIFY_OK;
7008 }
7009
7010-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7011+static struct notifier_block smp_core99_cpu_nb = {
7012 .notifier_call = smp_core99_cpu_notify,
7013 };
7014 #endif /* CONFIG_HOTPLUG_CPU */
7015diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7016index c797832..ce575c8 100644
7017--- a/arch/s390/include/asm/atomic.h
7018+++ b/arch/s390/include/asm/atomic.h
7019@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7020 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7021 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7022
7023+#define atomic64_read_unchecked(v) atomic64_read(v)
7024+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7025+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7026+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7027+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7028+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7029+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7030+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7031+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7032+
7033 #define smp_mb__before_atomic_dec() smp_mb()
7034 #define smp_mb__after_atomic_dec() smp_mb()
7035 #define smp_mb__before_atomic_inc() smp_mb()
7036diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7037index 4d7ccac..d03d0ad 100644
7038--- a/arch/s390/include/asm/cache.h
7039+++ b/arch/s390/include/asm/cache.h
7040@@ -9,8 +9,10 @@
7041 #ifndef __ARCH_S390_CACHE_H
7042 #define __ARCH_S390_CACHE_H
7043
7044-#define L1_CACHE_BYTES 256
7045+#include <linux/const.h>
7046+
7047 #define L1_CACHE_SHIFT 8
7048+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7049 #define NET_SKB_PAD 32
7050
7051 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7052diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7053index 178ff96..8c93bd1 100644
7054--- a/arch/s390/include/asm/elf.h
7055+++ b/arch/s390/include/asm/elf.h
7056@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7057 the loader. We need to make sure that it is out of the way of the program
7058 that it will "exec", and that there is sufficient room for the brk. */
7059
7060-extern unsigned long randomize_et_dyn(unsigned long base);
7061-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7062+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7063+
7064+#ifdef CONFIG_PAX_ASLR
7065+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7066+
7067+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7068+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7069+#endif
7070
7071 /* This yields a mask that user programs can use to figure out what
7072 instruction set this CPU supports. */
7073@@ -210,9 +216,6 @@ struct linux_binprm;
7074 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7075 int arch_setup_additional_pages(struct linux_binprm *, int);
7076
7077-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7078-#define arch_randomize_brk arch_randomize_brk
7079-
7080 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7081
7082 #endif
7083diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7084index c4a93d6..4d2a9b4 100644
7085--- a/arch/s390/include/asm/exec.h
7086+++ b/arch/s390/include/asm/exec.h
7087@@ -7,6 +7,6 @@
7088 #ifndef __ASM_EXEC_H
7089 #define __ASM_EXEC_H
7090
7091-extern unsigned long arch_align_stack(unsigned long sp);
7092+#define arch_align_stack(x) ((x) & ~0xfUL)
7093
7094 #endif /* __ASM_EXEC_H */
7095diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7096index 34268df..ea97318 100644
7097--- a/arch/s390/include/asm/uaccess.h
7098+++ b/arch/s390/include/asm/uaccess.h
7099@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7100 copy_to_user(void __user *to, const void *from, unsigned long n)
7101 {
7102 might_fault();
7103+
7104+ if ((long)n < 0)
7105+ return n;
7106+
7107 if (access_ok(VERIFY_WRITE, to, n))
7108 n = __copy_to_user(to, from, n);
7109 return n;
7110@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7111 static inline unsigned long __must_check
7112 __copy_from_user(void *to, const void __user *from, unsigned long n)
7113 {
7114+ if ((long)n < 0)
7115+ return n;
7116+
7117 if (__builtin_constant_p(n) && (n <= 256))
7118 return uaccess.copy_from_user_small(n, from, to);
7119 else
7120@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7121 static inline unsigned long __must_check
7122 copy_from_user(void *to, const void __user *from, unsigned long n)
7123 {
7124- unsigned int sz = __compiletime_object_size(to);
7125+ size_t sz = __compiletime_object_size(to);
7126
7127 might_fault();
7128- if (unlikely(sz != -1 && sz < n)) {
7129+
7130+ if ((long)n < 0)
7131+ return n;
7132+
7133+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7134 copy_from_user_overflow();
7135 return n;
7136 }
7137diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7138index 4610dea..cf0af21 100644
7139--- a/arch/s390/kernel/module.c
7140+++ b/arch/s390/kernel/module.c
7141@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7142
7143 /* Increase core size by size of got & plt and set start
7144 offsets for got and plt. */
7145- me->core_size = ALIGN(me->core_size, 4);
7146- me->arch.got_offset = me->core_size;
7147- me->core_size += me->arch.got_size;
7148- me->arch.plt_offset = me->core_size;
7149- me->core_size += me->arch.plt_size;
7150+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7151+ me->arch.got_offset = me->core_size_rw;
7152+ me->core_size_rw += me->arch.got_size;
7153+ me->arch.plt_offset = me->core_size_rx;
7154+ me->core_size_rx += me->arch.plt_size;
7155 return 0;
7156 }
7157
7158@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7159 if (info->got_initialized == 0) {
7160 Elf_Addr *gotent;
7161
7162- gotent = me->module_core + me->arch.got_offset +
7163+ gotent = me->module_core_rw + me->arch.got_offset +
7164 info->got_offset;
7165 *gotent = val;
7166 info->got_initialized = 1;
7167@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7168 else if (r_type == R_390_GOTENT ||
7169 r_type == R_390_GOTPLTENT)
7170 *(unsigned int *) loc =
7171- (val + (Elf_Addr) me->module_core - loc) >> 1;
7172+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7173 else if (r_type == R_390_GOT64 ||
7174 r_type == R_390_GOTPLT64)
7175 *(unsigned long *) loc = val;
7176@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7177 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7178 if (info->plt_initialized == 0) {
7179 unsigned int *ip;
7180- ip = me->module_core + me->arch.plt_offset +
7181+ ip = me->module_core_rx + me->arch.plt_offset +
7182 info->plt_offset;
7183 #ifndef CONFIG_64BIT
7184 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7185@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7186 val - loc + 0xffffUL < 0x1ffffeUL) ||
7187 (r_type == R_390_PLT32DBL &&
7188 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7189- val = (Elf_Addr) me->module_core +
7190+ val = (Elf_Addr) me->module_core_rx +
7191 me->arch.plt_offset +
7192 info->plt_offset;
7193 val += rela->r_addend - loc;
7194@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7195 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7196 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7197 val = val + rela->r_addend -
7198- ((Elf_Addr) me->module_core + me->arch.got_offset);
7199+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7200 if (r_type == R_390_GOTOFF16)
7201 *(unsigned short *) loc = val;
7202 else if (r_type == R_390_GOTOFF32)
7203@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7204 break;
7205 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7206 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7207- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7208+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7209 rela->r_addend - loc;
7210 if (r_type == R_390_GOTPC)
7211 *(unsigned int *) loc = val;
7212diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7213index 536d645..4a5bd9e 100644
7214--- a/arch/s390/kernel/process.c
7215+++ b/arch/s390/kernel/process.c
7216@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7217 }
7218 return 0;
7219 }
7220-
7221-unsigned long arch_align_stack(unsigned long sp)
7222-{
7223- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7224- sp -= get_random_int() & ~PAGE_MASK;
7225- return sp & ~0xf;
7226-}
7227-
7228-static inline unsigned long brk_rnd(void)
7229-{
7230- /* 8MB for 32bit, 1GB for 64bit */
7231- if (is_32bit_task())
7232- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7233- else
7234- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7235-}
7236-
7237-unsigned long arch_randomize_brk(struct mm_struct *mm)
7238-{
7239- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7240-
7241- if (ret < mm->brk)
7242- return mm->brk;
7243- return ret;
7244-}
7245-
7246-unsigned long randomize_et_dyn(unsigned long base)
7247-{
7248- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7249-
7250- if (!(current->flags & PF_RANDOMIZE))
7251- return base;
7252- if (ret < base)
7253- return base;
7254- return ret;
7255-}
7256diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7257index c59a5ef..3fae59c 100644
7258--- a/arch/s390/mm/mmap.c
7259+++ b/arch/s390/mm/mmap.c
7260@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7261 */
7262 if (mmap_is_legacy()) {
7263 mm->mmap_base = TASK_UNMAPPED_BASE;
7264+
7265+#ifdef CONFIG_PAX_RANDMMAP
7266+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7267+ mm->mmap_base += mm->delta_mmap;
7268+#endif
7269+
7270 mm->get_unmapped_area = arch_get_unmapped_area;
7271 mm->unmap_area = arch_unmap_area;
7272 } else {
7273 mm->mmap_base = mmap_base();
7274+
7275+#ifdef CONFIG_PAX_RANDMMAP
7276+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7277+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7278+#endif
7279+
7280 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7281 mm->unmap_area = arch_unmap_area_topdown;
7282 }
7283@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7284 */
7285 if (mmap_is_legacy()) {
7286 mm->mmap_base = TASK_UNMAPPED_BASE;
7287+
7288+#ifdef CONFIG_PAX_RANDMMAP
7289+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7290+ mm->mmap_base += mm->delta_mmap;
7291+#endif
7292+
7293 mm->get_unmapped_area = s390_get_unmapped_area;
7294 mm->unmap_area = arch_unmap_area;
7295 } else {
7296 mm->mmap_base = mmap_base();
7297+
7298+#ifdef CONFIG_PAX_RANDMMAP
7299+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7300+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7301+#endif
7302+
7303 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7304 mm->unmap_area = arch_unmap_area_topdown;
7305 }
7306diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7307index ae3d59f..f65f075 100644
7308--- a/arch/score/include/asm/cache.h
7309+++ b/arch/score/include/asm/cache.h
7310@@ -1,7 +1,9 @@
7311 #ifndef _ASM_SCORE_CACHE_H
7312 #define _ASM_SCORE_CACHE_H
7313
7314+#include <linux/const.h>
7315+
7316 #define L1_CACHE_SHIFT 4
7317-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7318+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7319
7320 #endif /* _ASM_SCORE_CACHE_H */
7321diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7322index f9f3cd5..58ff438 100644
7323--- a/arch/score/include/asm/exec.h
7324+++ b/arch/score/include/asm/exec.h
7325@@ -1,6 +1,6 @@
7326 #ifndef _ASM_SCORE_EXEC_H
7327 #define _ASM_SCORE_EXEC_H
7328
7329-extern unsigned long arch_align_stack(unsigned long sp);
7330+#define arch_align_stack(x) (x)
7331
7332 #endif /* _ASM_SCORE_EXEC_H */
7333diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7334index 7956846..5f37677 100644
7335--- a/arch/score/kernel/process.c
7336+++ b/arch/score/kernel/process.c
7337@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7338
7339 return task_pt_regs(task)->cp0_epc;
7340 }
7341-
7342-unsigned long arch_align_stack(unsigned long sp)
7343-{
7344- return sp;
7345-}
7346diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7347index ef9e555..331bd29 100644
7348--- a/arch/sh/include/asm/cache.h
7349+++ b/arch/sh/include/asm/cache.h
7350@@ -9,10 +9,11 @@
7351 #define __ASM_SH_CACHE_H
7352 #ifdef __KERNEL__
7353
7354+#include <linux/const.h>
7355 #include <linux/init.h>
7356 #include <cpu/cache.h>
7357
7358-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7359+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7360
7361 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7362
7363diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7364index 03f2b55..b027032 100644
7365--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7366+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7367@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7368 return NOTIFY_OK;
7369 }
7370
7371-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7372+static struct notifier_block shx3_cpu_notifier = {
7373 .notifier_call = shx3_cpu_callback,
7374 };
7375
7376diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7377index 6777177..cb5e44f 100644
7378--- a/arch/sh/mm/mmap.c
7379+++ b/arch/sh/mm/mmap.c
7380@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7381 struct mm_struct *mm = current->mm;
7382 struct vm_area_struct *vma;
7383 int do_colour_align;
7384+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7385 struct vm_unmapped_area_info info;
7386
7387 if (flags & MAP_FIXED) {
7388@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7389 if (filp || (flags & MAP_SHARED))
7390 do_colour_align = 1;
7391
7392+#ifdef CONFIG_PAX_RANDMMAP
7393+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7394+#endif
7395+
7396 if (addr) {
7397 if (do_colour_align)
7398 addr = COLOUR_ALIGN(addr, pgoff);
7399@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7400 addr = PAGE_ALIGN(addr);
7401
7402 vma = find_vma(mm, addr);
7403- if (TASK_SIZE - len >= addr &&
7404- (!vma || addr + len <= vma->vm_start))
7405+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7406 return addr;
7407 }
7408
7409 info.flags = 0;
7410 info.length = len;
7411- info.low_limit = TASK_UNMAPPED_BASE;
7412+ info.low_limit = mm->mmap_base;
7413 info.high_limit = TASK_SIZE;
7414 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7415 info.align_offset = pgoff << PAGE_SHIFT;
7416@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7417 struct mm_struct *mm = current->mm;
7418 unsigned long addr = addr0;
7419 int do_colour_align;
7420+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7421 struct vm_unmapped_area_info info;
7422
7423 if (flags & MAP_FIXED) {
7424@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7425 if (filp || (flags & MAP_SHARED))
7426 do_colour_align = 1;
7427
7428+#ifdef CONFIG_PAX_RANDMMAP
7429+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7430+#endif
7431+
7432 /* requesting a specific address */
7433 if (addr) {
7434 if (do_colour_align)
7435@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7436 addr = PAGE_ALIGN(addr);
7437
7438 vma = find_vma(mm, addr);
7439- if (TASK_SIZE - len >= addr &&
7440- (!vma || addr + len <= vma->vm_start))
7441+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7442 return addr;
7443 }
7444
7445@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7446 VM_BUG_ON(addr != -ENOMEM);
7447 info.flags = 0;
7448 info.low_limit = TASK_UNMAPPED_BASE;
7449+
7450+#ifdef CONFIG_PAX_RANDMMAP
7451+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7452+ info.low_limit += mm->delta_mmap;
7453+#endif
7454+
7455 info.high_limit = TASK_SIZE;
7456 addr = vm_unmapped_area(&info);
7457 }
7458diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7459index be56a24..443328f 100644
7460--- a/arch/sparc/include/asm/atomic_64.h
7461+++ b/arch/sparc/include/asm/atomic_64.h
7462@@ -14,18 +14,40 @@
7463 #define ATOMIC64_INIT(i) { (i) }
7464
7465 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7466+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7467+{
7468+ return v->counter;
7469+}
7470 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7471+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7472+{
7473+ return v->counter;
7474+}
7475
7476 #define atomic_set(v, i) (((v)->counter) = i)
7477+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7478+{
7479+ v->counter = i;
7480+}
7481 #define atomic64_set(v, i) (((v)->counter) = i)
7482+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7483+{
7484+ v->counter = i;
7485+}
7486
7487 extern void atomic_add(int, atomic_t *);
7488+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7489 extern void atomic64_add(long, atomic64_t *);
7490+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7491 extern void atomic_sub(int, atomic_t *);
7492+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7493 extern void atomic64_sub(long, atomic64_t *);
7494+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7495
7496 extern int atomic_add_ret(int, atomic_t *);
7497+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7498 extern long atomic64_add_ret(long, atomic64_t *);
7499+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7500 extern int atomic_sub_ret(int, atomic_t *);
7501 extern long atomic64_sub_ret(long, atomic64_t *);
7502
7503@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7504 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7505
7506 #define atomic_inc_return(v) atomic_add_ret(1, v)
7507+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7508+{
7509+ return atomic_add_ret_unchecked(1, v);
7510+}
7511 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7512+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7513+{
7514+ return atomic64_add_ret_unchecked(1, v);
7515+}
7516
7517 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7518 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7519
7520 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7521+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7522+{
7523+ return atomic_add_ret_unchecked(i, v);
7524+}
7525 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7526+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7527+{
7528+ return atomic64_add_ret_unchecked(i, v);
7529+}
7530
7531 /*
7532 * atomic_inc_and_test - increment and test
7533@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7534 * other cases.
7535 */
7536 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7537+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7538+{
7539+ return atomic_inc_return_unchecked(v) == 0;
7540+}
7541 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7542
7543 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7544@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7545 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7546
7547 #define atomic_inc(v) atomic_add(1, v)
7548+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7549+{
7550+ atomic_add_unchecked(1, v);
7551+}
7552 #define atomic64_inc(v) atomic64_add(1, v)
7553+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7554+{
7555+ atomic64_add_unchecked(1, v);
7556+}
7557
7558 #define atomic_dec(v) atomic_sub(1, v)
7559+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7560+{
7561+ atomic_sub_unchecked(1, v);
7562+}
7563 #define atomic64_dec(v) atomic64_sub(1, v)
7564+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7565+{
7566+ atomic64_sub_unchecked(1, v);
7567+}
7568
7569 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7570 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7571
7572 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7573+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7574+{
7575+ return cmpxchg(&v->counter, old, new);
7576+}
7577 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7578+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7579+{
7580+ return xchg(&v->counter, new);
7581+}
7582
7583 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7584 {
7585- int c, old;
7586+ int c, old, new;
7587 c = atomic_read(v);
7588 for (;;) {
7589- if (unlikely(c == (u)))
7590+ if (unlikely(c == u))
7591 break;
7592- old = atomic_cmpxchg((v), c, c + (a));
7593+
7594+ asm volatile("addcc %2, %0, %0\n"
7595+
7596+#ifdef CONFIG_PAX_REFCOUNT
7597+ "tvs %%icc, 6\n"
7598+#endif
7599+
7600+ : "=r" (new)
7601+ : "0" (c), "ir" (a)
7602+ : "cc");
7603+
7604+ old = atomic_cmpxchg(v, c, new);
7605 if (likely(old == c))
7606 break;
7607 c = old;
7608@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7609 #define atomic64_cmpxchg(v, o, n) \
7610 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7611 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7612+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7613+{
7614+ return xchg(&v->counter, new);
7615+}
7616
7617 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7618 {
7619- long c, old;
7620+ long c, old, new;
7621 c = atomic64_read(v);
7622 for (;;) {
7623- if (unlikely(c == (u)))
7624+ if (unlikely(c == u))
7625 break;
7626- old = atomic64_cmpxchg((v), c, c + (a));
7627+
7628+ asm volatile("addcc %2, %0, %0\n"
7629+
7630+#ifdef CONFIG_PAX_REFCOUNT
7631+ "tvs %%xcc, 6\n"
7632+#endif
7633+
7634+ : "=r" (new)
7635+ : "0" (c), "ir" (a)
7636+ : "cc");
7637+
7638+ old = atomic64_cmpxchg(v, c, new);
7639 if (likely(old == c))
7640 break;
7641 c = old;
7642 }
7643- return c != (u);
7644+ return c != u;
7645 }
7646
7647 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7648diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7649index 5bb6991..5c2132e 100644
7650--- a/arch/sparc/include/asm/cache.h
7651+++ b/arch/sparc/include/asm/cache.h
7652@@ -7,10 +7,12 @@
7653 #ifndef _SPARC_CACHE_H
7654 #define _SPARC_CACHE_H
7655
7656+#include <linux/const.h>
7657+
7658 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7659
7660 #define L1_CACHE_SHIFT 5
7661-#define L1_CACHE_BYTES 32
7662+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7663
7664 #ifdef CONFIG_SPARC32
7665 #define SMP_CACHE_BYTES_SHIFT 5
7666diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7667index ac74a2c..a9e58af 100644
7668--- a/arch/sparc/include/asm/elf_32.h
7669+++ b/arch/sparc/include/asm/elf_32.h
7670@@ -114,6 +114,13 @@ typedef struct {
7671
7672 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7673
7674+#ifdef CONFIG_PAX_ASLR
7675+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7676+
7677+#define PAX_DELTA_MMAP_LEN 16
7678+#define PAX_DELTA_STACK_LEN 16
7679+#endif
7680+
7681 /* This yields a mask that user programs can use to figure out what
7682 instruction set this cpu supports. This can NOT be done in userspace
7683 on Sparc. */
7684diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7685index 370ca1e..d4f4a98 100644
7686--- a/arch/sparc/include/asm/elf_64.h
7687+++ b/arch/sparc/include/asm/elf_64.h
7688@@ -189,6 +189,13 @@ typedef struct {
7689 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7690 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7691
7692+#ifdef CONFIG_PAX_ASLR
7693+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7694+
7695+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7696+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7697+#endif
7698+
7699 extern unsigned long sparc64_elf_hwcap;
7700 #define ELF_HWCAP sparc64_elf_hwcap
7701
7702diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7703index 9b1c36d..209298b 100644
7704--- a/arch/sparc/include/asm/pgalloc_32.h
7705+++ b/arch/sparc/include/asm/pgalloc_32.h
7706@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7707 }
7708
7709 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7710+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7711
7712 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7713 unsigned long address)
7714diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7715index bcfe063..b333142 100644
7716--- a/arch/sparc/include/asm/pgalloc_64.h
7717+++ b/arch/sparc/include/asm/pgalloc_64.h
7718@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7719 }
7720
7721 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7722+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7723
7724 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7725 {
7726diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7727index 6fc1348..390c50a 100644
7728--- a/arch/sparc/include/asm/pgtable_32.h
7729+++ b/arch/sparc/include/asm/pgtable_32.h
7730@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7731 #define PAGE_SHARED SRMMU_PAGE_SHARED
7732 #define PAGE_COPY SRMMU_PAGE_COPY
7733 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7734+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7735+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7736+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7737 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7738
7739 /* Top-level page directory - dummy used by init-mm.
7740@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7741
7742 /* xwr */
7743 #define __P000 PAGE_NONE
7744-#define __P001 PAGE_READONLY
7745-#define __P010 PAGE_COPY
7746-#define __P011 PAGE_COPY
7747+#define __P001 PAGE_READONLY_NOEXEC
7748+#define __P010 PAGE_COPY_NOEXEC
7749+#define __P011 PAGE_COPY_NOEXEC
7750 #define __P100 PAGE_READONLY
7751 #define __P101 PAGE_READONLY
7752 #define __P110 PAGE_COPY
7753 #define __P111 PAGE_COPY
7754
7755 #define __S000 PAGE_NONE
7756-#define __S001 PAGE_READONLY
7757-#define __S010 PAGE_SHARED
7758-#define __S011 PAGE_SHARED
7759+#define __S001 PAGE_READONLY_NOEXEC
7760+#define __S010 PAGE_SHARED_NOEXEC
7761+#define __S011 PAGE_SHARED_NOEXEC
7762 #define __S100 PAGE_READONLY
7763 #define __S101 PAGE_READONLY
7764 #define __S110 PAGE_SHARED
7765diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7766index 79da178..c2eede8 100644
7767--- a/arch/sparc/include/asm/pgtsrmmu.h
7768+++ b/arch/sparc/include/asm/pgtsrmmu.h
7769@@ -115,6 +115,11 @@
7770 SRMMU_EXEC | SRMMU_REF)
7771 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7772 SRMMU_EXEC | SRMMU_REF)
7773+
7774+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7775+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7776+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7777+
7778 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7779 SRMMU_DIRTY | SRMMU_REF)
7780
7781diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7782index 9689176..63c18ea 100644
7783--- a/arch/sparc/include/asm/spinlock_64.h
7784+++ b/arch/sparc/include/asm/spinlock_64.h
7785@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7786
7787 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7788
7789-static void inline arch_read_lock(arch_rwlock_t *lock)
7790+static inline void arch_read_lock(arch_rwlock_t *lock)
7791 {
7792 unsigned long tmp1, tmp2;
7793
7794 __asm__ __volatile__ (
7795 "1: ldsw [%2], %0\n"
7796 " brlz,pn %0, 2f\n"
7797-"4: add %0, 1, %1\n"
7798+"4: addcc %0, 1, %1\n"
7799+
7800+#ifdef CONFIG_PAX_REFCOUNT
7801+" tvs %%icc, 6\n"
7802+#endif
7803+
7804 " cas [%2], %0, %1\n"
7805 " cmp %0, %1\n"
7806 " bne,pn %%icc, 1b\n"
7807@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7808 " .previous"
7809 : "=&r" (tmp1), "=&r" (tmp2)
7810 : "r" (lock)
7811- : "memory");
7812+ : "memory", "cc");
7813 }
7814
7815-static int inline arch_read_trylock(arch_rwlock_t *lock)
7816+static inline int arch_read_trylock(arch_rwlock_t *lock)
7817 {
7818 int tmp1, tmp2;
7819
7820@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7821 "1: ldsw [%2], %0\n"
7822 " brlz,a,pn %0, 2f\n"
7823 " mov 0, %0\n"
7824-" add %0, 1, %1\n"
7825+" addcc %0, 1, %1\n"
7826+
7827+#ifdef CONFIG_PAX_REFCOUNT
7828+" tvs %%icc, 6\n"
7829+#endif
7830+
7831 " cas [%2], %0, %1\n"
7832 " cmp %0, %1\n"
7833 " bne,pn %%icc, 1b\n"
7834@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7835 return tmp1;
7836 }
7837
7838-static void inline arch_read_unlock(arch_rwlock_t *lock)
7839+static inline void arch_read_unlock(arch_rwlock_t *lock)
7840 {
7841 unsigned long tmp1, tmp2;
7842
7843 __asm__ __volatile__(
7844 "1: lduw [%2], %0\n"
7845-" sub %0, 1, %1\n"
7846+" subcc %0, 1, %1\n"
7847+
7848+#ifdef CONFIG_PAX_REFCOUNT
7849+" tvs %%icc, 6\n"
7850+#endif
7851+
7852 " cas [%2], %0, %1\n"
7853 " cmp %0, %1\n"
7854 " bne,pn %%xcc, 1b\n"
7855@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7856 : "memory");
7857 }
7858
7859-static void inline arch_write_lock(arch_rwlock_t *lock)
7860+static inline void arch_write_lock(arch_rwlock_t *lock)
7861 {
7862 unsigned long mask, tmp1, tmp2;
7863
7864@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7865 : "memory");
7866 }
7867
7868-static void inline arch_write_unlock(arch_rwlock_t *lock)
7869+static inline void arch_write_unlock(arch_rwlock_t *lock)
7870 {
7871 __asm__ __volatile__(
7872 " stw %%g0, [%0]"
7873@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7874 : "memory");
7875 }
7876
7877-static int inline arch_write_trylock(arch_rwlock_t *lock)
7878+static inline int arch_write_trylock(arch_rwlock_t *lock)
7879 {
7880 unsigned long mask, tmp1, tmp2, result;
7881
7882diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7883index 25849ae..924c54b 100644
7884--- a/arch/sparc/include/asm/thread_info_32.h
7885+++ b/arch/sparc/include/asm/thread_info_32.h
7886@@ -49,6 +49,8 @@ struct thread_info {
7887 unsigned long w_saved;
7888
7889 struct restart_block restart_block;
7890+
7891+ unsigned long lowest_stack;
7892 };
7893
7894 /*
7895diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7896index 269bd92..e46a9b8 100644
7897--- a/arch/sparc/include/asm/thread_info_64.h
7898+++ b/arch/sparc/include/asm/thread_info_64.h
7899@@ -63,6 +63,8 @@ struct thread_info {
7900 struct pt_regs *kern_una_regs;
7901 unsigned int kern_una_insn;
7902
7903+ unsigned long lowest_stack;
7904+
7905 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7906 };
7907
7908@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7909 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7910 /* flag bit 6 is available */
7911 #define TIF_32BIT 7 /* 32-bit binary */
7912-/* flag bit 8 is available */
7913+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7914 #define TIF_SECCOMP 9 /* secure computing */
7915 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7916 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7917+
7918 /* NOTE: Thread flags >= 12 should be ones we have no interest
7919 * in using in assembly, else we can't use the mask as
7920 * an immediate value in instructions such as andcc.
7921@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7922 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7923 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7924 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7925+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7926
7927 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7928 _TIF_DO_NOTIFY_RESUME_MASK | \
7929 _TIF_NEED_RESCHED)
7930 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7931
7932+#define _TIF_WORK_SYSCALL \
7933+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7934+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7935+
7936+
7937 /*
7938 * Thread-synchronous status.
7939 *
7940diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7941index 0167d26..9acd8ed 100644
7942--- a/arch/sparc/include/asm/uaccess.h
7943+++ b/arch/sparc/include/asm/uaccess.h
7944@@ -1,5 +1,13 @@
7945 #ifndef ___ASM_SPARC_UACCESS_H
7946 #define ___ASM_SPARC_UACCESS_H
7947+
7948+#ifdef __KERNEL__
7949+#ifndef __ASSEMBLY__
7950+#include <linux/types.h>
7951+extern void check_object_size(const void *ptr, unsigned long n, bool to);
7952+#endif
7953+#endif
7954+
7955 #if defined(__sparc__) && defined(__arch64__)
7956 #include <asm/uaccess_64.h>
7957 #else
7958diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7959index 53a28dd..50c38c3 100644
7960--- a/arch/sparc/include/asm/uaccess_32.h
7961+++ b/arch/sparc/include/asm/uaccess_32.h
7962@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7963
7964 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7965 {
7966- if (n && __access_ok((unsigned long) to, n))
7967+ if ((long)n < 0)
7968+ return n;
7969+
7970+ if (n && __access_ok((unsigned long) to, n)) {
7971+ if (!__builtin_constant_p(n))
7972+ check_object_size(from, n, true);
7973 return __copy_user(to, (__force void __user *) from, n);
7974- else
7975+ } else
7976 return n;
7977 }
7978
7979 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7980 {
7981+ if ((long)n < 0)
7982+ return n;
7983+
7984+ if (!__builtin_constant_p(n))
7985+ check_object_size(from, n, true);
7986+
7987 return __copy_user(to, (__force void __user *) from, n);
7988 }
7989
7990 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7991 {
7992- if (n && __access_ok((unsigned long) from, n))
7993+ if ((long)n < 0)
7994+ return n;
7995+
7996+ if (n && __access_ok((unsigned long) from, n)) {
7997+ if (!__builtin_constant_p(n))
7998+ check_object_size(to, n, false);
7999 return __copy_user((__force void __user *) to, from, n);
8000- else
8001+ } else
8002 return n;
8003 }
8004
8005 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8006 {
8007+ if ((long)n < 0)
8008+ return n;
8009+
8010 return __copy_user((__force void __user *) to, from, n);
8011 }
8012
8013diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8014index e562d3c..191f176 100644
8015--- a/arch/sparc/include/asm/uaccess_64.h
8016+++ b/arch/sparc/include/asm/uaccess_64.h
8017@@ -10,6 +10,7 @@
8018 #include <linux/compiler.h>
8019 #include <linux/string.h>
8020 #include <linux/thread_info.h>
8021+#include <linux/kernel.h>
8022 #include <asm/asi.h>
8023 #include <asm/spitfire.h>
8024 #include <asm-generic/uaccess-unaligned.h>
8025@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8026 static inline unsigned long __must_check
8027 copy_from_user(void *to, const void __user *from, unsigned long size)
8028 {
8029- unsigned long ret = ___copy_from_user(to, from, size);
8030+ unsigned long ret;
8031
8032+ if ((long)size < 0 || size > INT_MAX)
8033+ return size;
8034+
8035+ if (!__builtin_constant_p(size))
8036+ check_object_size(to, size, false);
8037+
8038+ ret = ___copy_from_user(to, from, size);
8039 if (unlikely(ret))
8040 ret = copy_from_user_fixup(to, from, size);
8041
8042@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8043 static inline unsigned long __must_check
8044 copy_to_user(void __user *to, const void *from, unsigned long size)
8045 {
8046- unsigned long ret = ___copy_to_user(to, from, size);
8047+ unsigned long ret;
8048
8049+ if ((long)size < 0 || size > INT_MAX)
8050+ return size;
8051+
8052+ if (!__builtin_constant_p(size))
8053+ check_object_size(from, size, true);
8054+
8055+ ret = ___copy_to_user(to, from, size);
8056 if (unlikely(ret))
8057 ret = copy_to_user_fixup(to, from, size);
8058 return ret;
8059diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8060index 6cf591b..b49e65a 100644
8061--- a/arch/sparc/kernel/Makefile
8062+++ b/arch/sparc/kernel/Makefile
8063@@ -3,7 +3,7 @@
8064 #
8065
8066 asflags-y := -ansi
8067-ccflags-y := -Werror
8068+#ccflags-y := -Werror
8069
8070 extra-y := head_$(BITS).o
8071
8072diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8073index be8e862..5b50b12 100644
8074--- a/arch/sparc/kernel/process_32.c
8075+++ b/arch/sparc/kernel/process_32.c
8076@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
8077
8078 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8079 r->psr, r->pc, r->npc, r->y, print_tainted());
8080- printk("PC: <%pS>\n", (void *) r->pc);
8081+ printk("PC: <%pA>\n", (void *) r->pc);
8082 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8083 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8084 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8085 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8086 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8087 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8088- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8089+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8090
8091 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8092 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8093@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8094 rw = (struct reg_window32 *) fp;
8095 pc = rw->ins[7];
8096 printk("[%08lx : ", pc);
8097- printk("%pS ] ", (void *) pc);
8098+ printk("%pA ] ", (void *) pc);
8099 fp = rw->ins[6];
8100 } while (++count < 16);
8101 printk("\n");
8102diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8103index cdb80b2..5ca141d 100644
8104--- a/arch/sparc/kernel/process_64.c
8105+++ b/arch/sparc/kernel/process_64.c
8106@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8107 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8108 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8109 if (regs->tstate & TSTATE_PRIV)
8110- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8111+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8112 }
8113
8114 void show_regs(struct pt_regs *regs)
8115 {
8116 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8117 regs->tpc, regs->tnpc, regs->y, print_tainted());
8118- printk("TPC: <%pS>\n", (void *) regs->tpc);
8119+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8120 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8121 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8122 regs->u_regs[3]);
8123@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8124 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8125 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8126 regs->u_regs[15]);
8127- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8128+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8129 show_regwindow(regs);
8130 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8131 }
8132@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8133 ((tp && tp->task) ? tp->task->pid : -1));
8134
8135 if (gp->tstate & TSTATE_PRIV) {
8136- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8137+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8138 (void *) gp->tpc,
8139 (void *) gp->o7,
8140 (void *) gp->i7,
8141diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8142index 7ff45e4..a58f271 100644
8143--- a/arch/sparc/kernel/ptrace_64.c
8144+++ b/arch/sparc/kernel/ptrace_64.c
8145@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8146 return ret;
8147 }
8148
8149+#ifdef CONFIG_GRKERNSEC_SETXID
8150+extern void gr_delayed_cred_worker(void);
8151+#endif
8152+
8153 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8154 {
8155 int ret = 0;
8156@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8157 /* do the secure computing check first */
8158 secure_computing_strict(regs->u_regs[UREG_G1]);
8159
8160+#ifdef CONFIG_GRKERNSEC_SETXID
8161+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8162+ gr_delayed_cred_worker();
8163+#endif
8164+
8165 if (test_thread_flag(TIF_SYSCALL_TRACE))
8166 ret = tracehook_report_syscall_entry(regs);
8167
8168@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8169
8170 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8171 {
8172+#ifdef CONFIG_GRKERNSEC_SETXID
8173+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8174+ gr_delayed_cred_worker();
8175+#endif
8176+
8177 audit_syscall_exit(regs);
8178
8179 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8180diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8181index 2da0bdc..79128d2 100644
8182--- a/arch/sparc/kernel/sys_sparc_32.c
8183+++ b/arch/sparc/kernel/sys_sparc_32.c
8184@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8185 if (len > TASK_SIZE - PAGE_SIZE)
8186 return -ENOMEM;
8187 if (!addr)
8188- addr = TASK_UNMAPPED_BASE;
8189+ addr = current->mm->mmap_base;
8190
8191 info.flags = 0;
8192 info.length = len;
8193diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8194index 708bc29..f0129cb 100644
8195--- a/arch/sparc/kernel/sys_sparc_64.c
8196+++ b/arch/sparc/kernel/sys_sparc_64.c
8197@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8198 struct vm_area_struct * vma;
8199 unsigned long task_size = TASK_SIZE;
8200 int do_color_align;
8201+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8202 struct vm_unmapped_area_info info;
8203
8204 if (flags & MAP_FIXED) {
8205 /* We do not accept a shared mapping if it would violate
8206 * cache aliasing constraints.
8207 */
8208- if ((flags & MAP_SHARED) &&
8209+ if ((filp || (flags & MAP_SHARED)) &&
8210 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8211 return -EINVAL;
8212 return addr;
8213@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8214 if (filp || (flags & MAP_SHARED))
8215 do_color_align = 1;
8216
8217+#ifdef CONFIG_PAX_RANDMMAP
8218+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8219+#endif
8220+
8221 if (addr) {
8222 if (do_color_align)
8223 addr = COLOR_ALIGN(addr, pgoff);
8224@@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8225 addr = PAGE_ALIGN(addr);
8226
8227 vma = find_vma(mm, addr);
8228- if (task_size - len >= addr &&
8229- (!vma || addr + len <= vma->vm_start))
8230+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8231 return addr;
8232 }
8233
8234 info.flags = 0;
8235 info.length = len;
8236- info.low_limit = TASK_UNMAPPED_BASE;
8237+ info.low_limit = mm->mmap_base;
8238 info.high_limit = min(task_size, VA_EXCLUDE_START);
8239 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8240 info.align_offset = pgoff << PAGE_SHIFT;
8241@@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8242 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8243 VM_BUG_ON(addr != -ENOMEM);
8244 info.low_limit = VA_EXCLUDE_END;
8245+
8246+#ifdef CONFIG_PAX_RANDMMAP
8247+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8248+ info.low_limit += mm->delta_mmap;
8249+#endif
8250+
8251 info.high_limit = task_size;
8252 addr = vm_unmapped_area(&info);
8253 }
8254@@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8255 unsigned long task_size = STACK_TOP32;
8256 unsigned long addr = addr0;
8257 int do_color_align;
8258+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8259 struct vm_unmapped_area_info info;
8260
8261 /* This should only ever run for 32-bit processes. */
8262@@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8263 /* We do not accept a shared mapping if it would violate
8264 * cache aliasing constraints.
8265 */
8266- if ((flags & MAP_SHARED) &&
8267+ if ((filp || (flags & MAP_SHARED)) &&
8268 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8269 return -EINVAL;
8270 return addr;
8271@@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8272 if (filp || (flags & MAP_SHARED))
8273 do_color_align = 1;
8274
8275+#ifdef CONFIG_PAX_RANDMMAP
8276+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8277+#endif
8278+
8279 /* requesting a specific address */
8280 if (addr) {
8281 if (do_color_align)
8282@@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8283 addr = PAGE_ALIGN(addr);
8284
8285 vma = find_vma(mm, addr);
8286- if (task_size - len >= addr &&
8287- (!vma || addr + len <= vma->vm_start))
8288+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8289 return addr;
8290 }
8291
8292@@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8293 VM_BUG_ON(addr != -ENOMEM);
8294 info.flags = 0;
8295 info.low_limit = TASK_UNMAPPED_BASE;
8296+
8297+#ifdef CONFIG_PAX_RANDMMAP
8298+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8299+ info.low_limit += mm->delta_mmap;
8300+#endif
8301+
8302 info.high_limit = STACK_TOP32;
8303 addr = vm_unmapped_area(&info);
8304 }
8305@@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8306 {
8307 unsigned long rnd = 0UL;
8308
8309+#ifdef CONFIG_PAX_RANDMMAP
8310+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8311+#endif
8312+
8313 if (current->flags & PF_RANDOMIZE) {
8314 unsigned long val = get_random_int();
8315 if (test_thread_flag(TIF_32BIT))
8316@@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8317 gap == RLIM_INFINITY ||
8318 sysctl_legacy_va_layout) {
8319 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8320+
8321+#ifdef CONFIG_PAX_RANDMMAP
8322+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8323+ mm->mmap_base += mm->delta_mmap;
8324+#endif
8325+
8326 mm->get_unmapped_area = arch_get_unmapped_area;
8327 mm->unmap_area = arch_unmap_area;
8328 } else {
8329@@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8330 gap = (task_size / 6 * 5);
8331
8332 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8333+
8334+#ifdef CONFIG_PAX_RANDMMAP
8335+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8336+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8337+#endif
8338+
8339 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8340 mm->unmap_area = arch_unmap_area_topdown;
8341 }
8342diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8343index e0fed77..604a7e5 100644
8344--- a/arch/sparc/kernel/syscalls.S
8345+++ b/arch/sparc/kernel/syscalls.S
8346@@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8347 #endif
8348 .align 32
8349 1: ldx [%g6 + TI_FLAGS], %l5
8350- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8351+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8352 be,pt %icc, rtrap
8353 nop
8354 call syscall_trace_leave
8355@@ -190,7 +190,7 @@ linux_sparc_syscall32:
8356
8357 srl %i5, 0, %o5 ! IEU1
8358 srl %i2, 0, %o2 ! IEU0 Group
8359- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8360+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8361 bne,pn %icc, linux_syscall_trace32 ! CTI
8362 mov %i0, %l5 ! IEU1
8363 call %l7 ! CTI Group brk forced
8364@@ -213,7 +213,7 @@ linux_sparc_syscall:
8365
8366 mov %i3, %o3 ! IEU1
8367 mov %i4, %o4 ! IEU0 Group
8368- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8369+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8370 bne,pn %icc, linux_syscall_trace ! CTI Group
8371 mov %i0, %l5 ! IEU0
8372 2: call %l7 ! CTI Group brk forced
8373@@ -229,7 +229,7 @@ ret_sys_call:
8374
8375 cmp %o0, -ERESTART_RESTARTBLOCK
8376 bgeu,pn %xcc, 1f
8377- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8378+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8379 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8380
8381 2:
8382diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8383index 654e8aa..45f431b 100644
8384--- a/arch/sparc/kernel/sysfs.c
8385+++ b/arch/sparc/kernel/sysfs.c
8386@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8387 return NOTIFY_OK;
8388 }
8389
8390-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8391+static struct notifier_block sysfs_cpu_nb = {
8392 .notifier_call = sysfs_cpu_notify,
8393 };
8394
8395diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8396index a5785ea..405c5f7 100644
8397--- a/arch/sparc/kernel/traps_32.c
8398+++ b/arch/sparc/kernel/traps_32.c
8399@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8400 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8401 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8402
8403+extern void gr_handle_kernel_exploit(void);
8404+
8405 void die_if_kernel(char *str, struct pt_regs *regs)
8406 {
8407 static int die_counter;
8408@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8409 count++ < 30 &&
8410 (((unsigned long) rw) >= PAGE_OFFSET) &&
8411 !(((unsigned long) rw) & 0x7)) {
8412- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8413+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8414 (void *) rw->ins[7]);
8415 rw = (struct reg_window32 *)rw->ins[6];
8416 }
8417 }
8418 printk("Instruction DUMP:");
8419 instruction_dump ((unsigned long *) regs->pc);
8420- if(regs->psr & PSR_PS)
8421+ if(regs->psr & PSR_PS) {
8422+ gr_handle_kernel_exploit();
8423 do_exit(SIGKILL);
8424+ }
8425 do_exit(SIGSEGV);
8426 }
8427
8428diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8429index e7ecf15..6520e65 100644
8430--- a/arch/sparc/kernel/traps_64.c
8431+++ b/arch/sparc/kernel/traps_64.c
8432@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8433 i + 1,
8434 p->trapstack[i].tstate, p->trapstack[i].tpc,
8435 p->trapstack[i].tnpc, p->trapstack[i].tt);
8436- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8437+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8438 }
8439 }
8440
8441@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8442
8443 lvl -= 0x100;
8444 if (regs->tstate & TSTATE_PRIV) {
8445+
8446+#ifdef CONFIG_PAX_REFCOUNT
8447+ if (lvl == 6)
8448+ pax_report_refcount_overflow(regs);
8449+#endif
8450+
8451 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8452 die_if_kernel(buffer, regs);
8453 }
8454@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8455 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8456 {
8457 char buffer[32];
8458-
8459+
8460 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8461 0, lvl, SIGTRAP) == NOTIFY_STOP)
8462 return;
8463
8464+#ifdef CONFIG_PAX_REFCOUNT
8465+ if (lvl == 6)
8466+ pax_report_refcount_overflow(regs);
8467+#endif
8468+
8469 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8470
8471 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8472@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8473 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8474 printk("%s" "ERROR(%d): ",
8475 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8476- printk("TPC<%pS>\n", (void *) regs->tpc);
8477+ printk("TPC<%pA>\n", (void *) regs->tpc);
8478 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8479 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8480 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8481@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8482 smp_processor_id(),
8483 (type & 0x1) ? 'I' : 'D',
8484 regs->tpc);
8485- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8486+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8487 panic("Irrecoverable Cheetah+ parity error.");
8488 }
8489
8490@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8491 smp_processor_id(),
8492 (type & 0x1) ? 'I' : 'D',
8493 regs->tpc);
8494- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8495+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8496 }
8497
8498 struct sun4v_error_entry {
8499@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8500
8501 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8502 regs->tpc, tl);
8503- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8504+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8505 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8506- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8507+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8508 (void *) regs->u_regs[UREG_I7]);
8509 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8510 "pte[%lx] error[%lx]\n",
8511@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8512
8513 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8514 regs->tpc, tl);
8515- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8516+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8517 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8518- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8519+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8520 (void *) regs->u_regs[UREG_I7]);
8521 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8522 "pte[%lx] error[%lx]\n",
8523@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8524 fp = (unsigned long)sf->fp + STACK_BIAS;
8525 }
8526
8527- printk(" [%016lx] %pS\n", pc, (void *) pc);
8528+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8529 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8530 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8531 int index = tsk->curr_ret_stack;
8532 if (tsk->ret_stack && index >= graph) {
8533 pc = tsk->ret_stack[index - graph].ret;
8534- printk(" [%016lx] %pS\n", pc, (void *) pc);
8535+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8536 graph++;
8537 }
8538 }
8539@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8540 return (struct reg_window *) (fp + STACK_BIAS);
8541 }
8542
8543+extern void gr_handle_kernel_exploit(void);
8544+
8545 void die_if_kernel(char *str, struct pt_regs *regs)
8546 {
8547 static int die_counter;
8548@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8549 while (rw &&
8550 count++ < 30 &&
8551 kstack_valid(tp, (unsigned long) rw)) {
8552- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8553+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8554 (void *) rw->ins[7]);
8555
8556 rw = kernel_stack_up(rw);
8557@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8558 }
8559 user_instruction_dump ((unsigned int __user *) regs->tpc);
8560 }
8561- if (regs->tstate & TSTATE_PRIV)
8562+ if (regs->tstate & TSTATE_PRIV) {
8563+ gr_handle_kernel_exploit();
8564 do_exit(SIGKILL);
8565+ }
8566 do_exit(SIGSEGV);
8567 }
8568 EXPORT_SYMBOL(die_if_kernel);
8569diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8570index 8201c25e..072a2a7 100644
8571--- a/arch/sparc/kernel/unaligned_64.c
8572+++ b/arch/sparc/kernel/unaligned_64.c
8573@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8574 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8575
8576 if (__ratelimit(&ratelimit)) {
8577- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8578+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8579 regs->tpc, (void *) regs->tpc);
8580 }
8581 }
8582diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8583index 8410065f2..4fd4ca22 100644
8584--- a/arch/sparc/lib/Makefile
8585+++ b/arch/sparc/lib/Makefile
8586@@ -2,7 +2,7 @@
8587 #
8588
8589 asflags-y := -ansi -DST_DIV0=0x02
8590-ccflags-y := -Werror
8591+#ccflags-y := -Werror
8592
8593 lib-$(CONFIG_SPARC32) += ashrdi3.o
8594 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8595diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8596index 85c233d..68500e0 100644
8597--- a/arch/sparc/lib/atomic_64.S
8598+++ b/arch/sparc/lib/atomic_64.S
8599@@ -17,7 +17,12 @@
8600 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8601 BACKOFF_SETUP(%o2)
8602 1: lduw [%o1], %g1
8603- add %g1, %o0, %g7
8604+ addcc %g1, %o0, %g7
8605+
8606+#ifdef CONFIG_PAX_REFCOUNT
8607+ tvs %icc, 6
8608+#endif
8609+
8610 cas [%o1], %g1, %g7
8611 cmp %g1, %g7
8612 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8613@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8614 2: BACKOFF_SPIN(%o2, %o3, 1b)
8615 ENDPROC(atomic_add)
8616
8617+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8618+ BACKOFF_SETUP(%o2)
8619+1: lduw [%o1], %g1
8620+ add %g1, %o0, %g7
8621+ cas [%o1], %g1, %g7
8622+ cmp %g1, %g7
8623+ bne,pn %icc, 2f
8624+ nop
8625+ retl
8626+ nop
8627+2: BACKOFF_SPIN(%o2, %o3, 1b)
8628+ENDPROC(atomic_add_unchecked)
8629+
8630 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8631 BACKOFF_SETUP(%o2)
8632 1: lduw [%o1], %g1
8633- sub %g1, %o0, %g7
8634+ subcc %g1, %o0, %g7
8635+
8636+#ifdef CONFIG_PAX_REFCOUNT
8637+ tvs %icc, 6
8638+#endif
8639+
8640 cas [%o1], %g1, %g7
8641 cmp %g1, %g7
8642 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8643@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8644 2: BACKOFF_SPIN(%o2, %o3, 1b)
8645 ENDPROC(atomic_sub)
8646
8647+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8648+ BACKOFF_SETUP(%o2)
8649+1: lduw [%o1], %g1
8650+ sub %g1, %o0, %g7
8651+ cas [%o1], %g1, %g7
8652+ cmp %g1, %g7
8653+ bne,pn %icc, 2f
8654+ nop
8655+ retl
8656+ nop
8657+2: BACKOFF_SPIN(%o2, %o3, 1b)
8658+ENDPROC(atomic_sub_unchecked)
8659+
8660 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8661 BACKOFF_SETUP(%o2)
8662 1: lduw [%o1], %g1
8663- add %g1, %o0, %g7
8664+ addcc %g1, %o0, %g7
8665+
8666+#ifdef CONFIG_PAX_REFCOUNT
8667+ tvs %icc, 6
8668+#endif
8669+
8670 cas [%o1], %g1, %g7
8671 cmp %g1, %g7
8672 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8673@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8674 2: BACKOFF_SPIN(%o2, %o3, 1b)
8675 ENDPROC(atomic_add_ret)
8676
8677+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8678+ BACKOFF_SETUP(%o2)
8679+1: lduw [%o1], %g1
8680+ addcc %g1, %o0, %g7
8681+ cas [%o1], %g1, %g7
8682+ cmp %g1, %g7
8683+ bne,pn %icc, 2f
8684+ add %g7, %o0, %g7
8685+ sra %g7, 0, %o0
8686+ retl
8687+ nop
8688+2: BACKOFF_SPIN(%o2, %o3, 1b)
8689+ENDPROC(atomic_add_ret_unchecked)
8690+
8691 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8692 BACKOFF_SETUP(%o2)
8693 1: lduw [%o1], %g1
8694- sub %g1, %o0, %g7
8695+ subcc %g1, %o0, %g7
8696+
8697+#ifdef CONFIG_PAX_REFCOUNT
8698+ tvs %icc, 6
8699+#endif
8700+
8701 cas [%o1], %g1, %g7
8702 cmp %g1, %g7
8703 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8704@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8705 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8706 BACKOFF_SETUP(%o2)
8707 1: ldx [%o1], %g1
8708- add %g1, %o0, %g7
8709+ addcc %g1, %o0, %g7
8710+
8711+#ifdef CONFIG_PAX_REFCOUNT
8712+ tvs %xcc, 6
8713+#endif
8714+
8715 casx [%o1], %g1, %g7
8716 cmp %g1, %g7
8717 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8718@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8719 2: BACKOFF_SPIN(%o2, %o3, 1b)
8720 ENDPROC(atomic64_add)
8721
8722+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8723+ BACKOFF_SETUP(%o2)
8724+1: ldx [%o1], %g1
8725+ addcc %g1, %o0, %g7
8726+ casx [%o1], %g1, %g7
8727+ cmp %g1, %g7
8728+ bne,pn %xcc, 2f
8729+ nop
8730+ retl
8731+ nop
8732+2: BACKOFF_SPIN(%o2, %o3, 1b)
8733+ENDPROC(atomic64_add_unchecked)
8734+
8735 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8736 BACKOFF_SETUP(%o2)
8737 1: ldx [%o1], %g1
8738- sub %g1, %o0, %g7
8739+ subcc %g1, %o0, %g7
8740+
8741+#ifdef CONFIG_PAX_REFCOUNT
8742+ tvs %xcc, 6
8743+#endif
8744+
8745 casx [%o1], %g1, %g7
8746 cmp %g1, %g7
8747 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8748@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8749 2: BACKOFF_SPIN(%o2, %o3, 1b)
8750 ENDPROC(atomic64_sub)
8751
8752+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8753+ BACKOFF_SETUP(%o2)
8754+1: ldx [%o1], %g1
8755+ subcc %g1, %o0, %g7
8756+ casx [%o1], %g1, %g7
8757+ cmp %g1, %g7
8758+ bne,pn %xcc, 2f
8759+ nop
8760+ retl
8761+ nop
8762+2: BACKOFF_SPIN(%o2, %o3, 1b)
8763+ENDPROC(atomic64_sub_unchecked)
8764+
8765 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8766 BACKOFF_SETUP(%o2)
8767 1: ldx [%o1], %g1
8768- add %g1, %o0, %g7
8769+ addcc %g1, %o0, %g7
8770+
8771+#ifdef CONFIG_PAX_REFCOUNT
8772+ tvs %xcc, 6
8773+#endif
8774+
8775 casx [%o1], %g1, %g7
8776 cmp %g1, %g7
8777 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8778@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8779 2: BACKOFF_SPIN(%o2, %o3, 1b)
8780 ENDPROC(atomic64_add_ret)
8781
8782+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8783+ BACKOFF_SETUP(%o2)
8784+1: ldx [%o1], %g1
8785+ addcc %g1, %o0, %g7
8786+ casx [%o1], %g1, %g7
8787+ cmp %g1, %g7
8788+ bne,pn %xcc, 2f
8789+ add %g7, %o0, %g7
8790+ mov %g7, %o0
8791+ retl
8792+ nop
8793+2: BACKOFF_SPIN(%o2, %o3, 1b)
8794+ENDPROC(atomic64_add_ret_unchecked)
8795+
8796 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8797 BACKOFF_SETUP(%o2)
8798 1: ldx [%o1], %g1
8799- sub %g1, %o0, %g7
8800+ subcc %g1, %o0, %g7
8801+
8802+#ifdef CONFIG_PAX_REFCOUNT
8803+ tvs %xcc, 6
8804+#endif
8805+
8806 casx [%o1], %g1, %g7
8807 cmp %g1, %g7
8808 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8809diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8810index 0c4e35e..745d3e4 100644
8811--- a/arch/sparc/lib/ksyms.c
8812+++ b/arch/sparc/lib/ksyms.c
8813@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8814
8815 /* Atomic counter implementation. */
8816 EXPORT_SYMBOL(atomic_add);
8817+EXPORT_SYMBOL(atomic_add_unchecked);
8818 EXPORT_SYMBOL(atomic_add_ret);
8819+EXPORT_SYMBOL(atomic_add_ret_unchecked);
8820 EXPORT_SYMBOL(atomic_sub);
8821+EXPORT_SYMBOL(atomic_sub_unchecked);
8822 EXPORT_SYMBOL(atomic_sub_ret);
8823 EXPORT_SYMBOL(atomic64_add);
8824+EXPORT_SYMBOL(atomic64_add_unchecked);
8825 EXPORT_SYMBOL(atomic64_add_ret);
8826+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8827 EXPORT_SYMBOL(atomic64_sub);
8828+EXPORT_SYMBOL(atomic64_sub_unchecked);
8829 EXPORT_SYMBOL(atomic64_sub_ret);
8830 EXPORT_SYMBOL(atomic64_dec_if_positive);
8831
8832diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8833index 30c3ecc..736f015 100644
8834--- a/arch/sparc/mm/Makefile
8835+++ b/arch/sparc/mm/Makefile
8836@@ -2,7 +2,7 @@
8837 #
8838
8839 asflags-y := -ansi
8840-ccflags-y := -Werror
8841+#ccflags-y := -Werror
8842
8843 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8844 obj-y += fault_$(BITS).o
8845diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8846index e98bfda..ea8d221 100644
8847--- a/arch/sparc/mm/fault_32.c
8848+++ b/arch/sparc/mm/fault_32.c
8849@@ -21,6 +21,9 @@
8850 #include <linux/perf_event.h>
8851 #include <linux/interrupt.h>
8852 #include <linux/kdebug.h>
8853+#include <linux/slab.h>
8854+#include <linux/pagemap.h>
8855+#include <linux/compiler.h>
8856
8857 #include <asm/page.h>
8858 #include <asm/pgtable.h>
8859@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8860 return safe_compute_effective_address(regs, insn);
8861 }
8862
8863+#ifdef CONFIG_PAX_PAGEEXEC
8864+#ifdef CONFIG_PAX_DLRESOLVE
8865+static void pax_emuplt_close(struct vm_area_struct *vma)
8866+{
8867+ vma->vm_mm->call_dl_resolve = 0UL;
8868+}
8869+
8870+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8871+{
8872+ unsigned int *kaddr;
8873+
8874+ vmf->page = alloc_page(GFP_HIGHUSER);
8875+ if (!vmf->page)
8876+ return VM_FAULT_OOM;
8877+
8878+ kaddr = kmap(vmf->page);
8879+ memset(kaddr, 0, PAGE_SIZE);
8880+ kaddr[0] = 0x9DE3BFA8U; /* save */
8881+ flush_dcache_page(vmf->page);
8882+ kunmap(vmf->page);
8883+ return VM_FAULT_MAJOR;
8884+}
8885+
8886+static const struct vm_operations_struct pax_vm_ops = {
8887+ .close = pax_emuplt_close,
8888+ .fault = pax_emuplt_fault
8889+};
8890+
8891+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8892+{
8893+ int ret;
8894+
8895+ INIT_LIST_HEAD(&vma->anon_vma_chain);
8896+ vma->vm_mm = current->mm;
8897+ vma->vm_start = addr;
8898+ vma->vm_end = addr + PAGE_SIZE;
8899+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8900+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8901+ vma->vm_ops = &pax_vm_ops;
8902+
8903+ ret = insert_vm_struct(current->mm, vma);
8904+ if (ret)
8905+ return ret;
8906+
8907+ ++current->mm->total_vm;
8908+ return 0;
8909+}
8910+#endif
8911+
8912+/*
8913+ * PaX: decide what to do with offenders (regs->pc = fault address)
8914+ *
8915+ * returns 1 when task should be killed
8916+ * 2 when patched PLT trampoline was detected
8917+ * 3 when unpatched PLT trampoline was detected
8918+ */
8919+static int pax_handle_fetch_fault(struct pt_regs *regs)
8920+{
8921+
8922+#ifdef CONFIG_PAX_EMUPLT
8923+ int err;
8924+
8925+ do { /* PaX: patched PLT emulation #1 */
8926+ unsigned int sethi1, sethi2, jmpl;
8927+
8928+ err = get_user(sethi1, (unsigned int *)regs->pc);
8929+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8930+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8931+
8932+ if (err)
8933+ break;
8934+
8935+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8936+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
8937+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
8938+ {
8939+ unsigned int addr;
8940+
8941+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8942+ addr = regs->u_regs[UREG_G1];
8943+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8944+ regs->pc = addr;
8945+ regs->npc = addr+4;
8946+ return 2;
8947+ }
8948+ } while (0);
8949+
8950+ do { /* PaX: patched PLT emulation #2 */
8951+ unsigned int ba;
8952+
8953+ err = get_user(ba, (unsigned int *)regs->pc);
8954+
8955+ if (err)
8956+ break;
8957+
8958+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8959+ unsigned int addr;
8960+
8961+ if ((ba & 0xFFC00000U) == 0x30800000U)
8962+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8963+ else
8964+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8965+ regs->pc = addr;
8966+ regs->npc = addr+4;
8967+ return 2;
8968+ }
8969+ } while (0);
8970+
8971+ do { /* PaX: patched PLT emulation #3 */
8972+ unsigned int sethi, bajmpl, nop;
8973+
8974+ err = get_user(sethi, (unsigned int *)regs->pc);
8975+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8976+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
8977+
8978+ if (err)
8979+ break;
8980+
8981+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8982+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8983+ nop == 0x01000000U)
8984+ {
8985+ unsigned int addr;
8986+
8987+ addr = (sethi & 0x003FFFFFU) << 10;
8988+ regs->u_regs[UREG_G1] = addr;
8989+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8990+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8991+ else
8992+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8993+ regs->pc = addr;
8994+ regs->npc = addr+4;
8995+ return 2;
8996+ }
8997+ } while (0);
8998+
8999+ do { /* PaX: unpatched PLT emulation step 1 */
9000+ unsigned int sethi, ba, nop;
9001+
9002+ err = get_user(sethi, (unsigned int *)regs->pc);
9003+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9004+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9005+
9006+ if (err)
9007+ break;
9008+
9009+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9010+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9011+ nop == 0x01000000U)
9012+ {
9013+ unsigned int addr, save, call;
9014+
9015+ if ((ba & 0xFFC00000U) == 0x30800000U)
9016+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9017+ else
9018+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9019+
9020+ err = get_user(save, (unsigned int *)addr);
9021+ err |= get_user(call, (unsigned int *)(addr+4));
9022+ err |= get_user(nop, (unsigned int *)(addr+8));
9023+ if (err)
9024+ break;
9025+
9026+#ifdef CONFIG_PAX_DLRESOLVE
9027+ if (save == 0x9DE3BFA8U &&
9028+ (call & 0xC0000000U) == 0x40000000U &&
9029+ nop == 0x01000000U)
9030+ {
9031+ struct vm_area_struct *vma;
9032+ unsigned long call_dl_resolve;
9033+
9034+ down_read(&current->mm->mmap_sem);
9035+ call_dl_resolve = current->mm->call_dl_resolve;
9036+ up_read(&current->mm->mmap_sem);
9037+ if (likely(call_dl_resolve))
9038+ goto emulate;
9039+
9040+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9041+
9042+ down_write(&current->mm->mmap_sem);
9043+ if (current->mm->call_dl_resolve) {
9044+ call_dl_resolve = current->mm->call_dl_resolve;
9045+ up_write(&current->mm->mmap_sem);
9046+ if (vma)
9047+ kmem_cache_free(vm_area_cachep, vma);
9048+ goto emulate;
9049+ }
9050+
9051+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9052+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9053+ up_write(&current->mm->mmap_sem);
9054+ if (vma)
9055+ kmem_cache_free(vm_area_cachep, vma);
9056+ return 1;
9057+ }
9058+
9059+ if (pax_insert_vma(vma, call_dl_resolve)) {
9060+ up_write(&current->mm->mmap_sem);
9061+ kmem_cache_free(vm_area_cachep, vma);
9062+ return 1;
9063+ }
9064+
9065+ current->mm->call_dl_resolve = call_dl_resolve;
9066+ up_write(&current->mm->mmap_sem);
9067+
9068+emulate:
9069+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9070+ regs->pc = call_dl_resolve;
9071+ regs->npc = addr+4;
9072+ return 3;
9073+ }
9074+#endif
9075+
9076+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9077+ if ((save & 0xFFC00000U) == 0x05000000U &&
9078+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9079+ nop == 0x01000000U)
9080+ {
9081+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9082+ regs->u_regs[UREG_G2] = addr + 4;
9083+ addr = (save & 0x003FFFFFU) << 10;
9084+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9085+ regs->pc = addr;
9086+ regs->npc = addr+4;
9087+ return 3;
9088+ }
9089+ }
9090+ } while (0);
9091+
9092+ do { /* PaX: unpatched PLT emulation step 2 */
9093+ unsigned int save, call, nop;
9094+
9095+ err = get_user(save, (unsigned int *)(regs->pc-4));
9096+ err |= get_user(call, (unsigned int *)regs->pc);
9097+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9098+ if (err)
9099+ break;
9100+
9101+ if (save == 0x9DE3BFA8U &&
9102+ (call & 0xC0000000U) == 0x40000000U &&
9103+ nop == 0x01000000U)
9104+ {
9105+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9106+
9107+ regs->u_regs[UREG_RETPC] = regs->pc;
9108+ regs->pc = dl_resolve;
9109+ regs->npc = dl_resolve+4;
9110+ return 3;
9111+ }
9112+ } while (0);
9113+#endif
9114+
9115+ return 1;
9116+}
9117+
9118+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9119+{
9120+ unsigned long i;
9121+
9122+ printk(KERN_ERR "PAX: bytes at PC: ");
9123+ for (i = 0; i < 8; i++) {
9124+ unsigned int c;
9125+ if (get_user(c, (unsigned int *)pc+i))
9126+ printk(KERN_CONT "???????? ");
9127+ else
9128+ printk(KERN_CONT "%08x ", c);
9129+ }
9130+ printk("\n");
9131+}
9132+#endif
9133+
9134 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9135 int text_fault)
9136 {
9137@@ -230,6 +504,24 @@ good_area:
9138 if (!(vma->vm_flags & VM_WRITE))
9139 goto bad_area;
9140 } else {
9141+
9142+#ifdef CONFIG_PAX_PAGEEXEC
9143+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9144+ up_read(&mm->mmap_sem);
9145+ switch (pax_handle_fetch_fault(regs)) {
9146+
9147+#ifdef CONFIG_PAX_EMUPLT
9148+ case 2:
9149+ case 3:
9150+ return;
9151+#endif
9152+
9153+ }
9154+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9155+ do_group_exit(SIGKILL);
9156+ }
9157+#endif
9158+
9159 /* Allow reads even for write-only mappings */
9160 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9161 goto bad_area;
9162diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9163index 5062ff3..e0b75f3 100644
9164--- a/arch/sparc/mm/fault_64.c
9165+++ b/arch/sparc/mm/fault_64.c
9166@@ -21,6 +21,9 @@
9167 #include <linux/kprobes.h>
9168 #include <linux/kdebug.h>
9169 #include <linux/percpu.h>
9170+#include <linux/slab.h>
9171+#include <linux/pagemap.h>
9172+#include <linux/compiler.h>
9173
9174 #include <asm/page.h>
9175 #include <asm/pgtable.h>
9176@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9177 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9178 regs->tpc);
9179 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9180- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9181+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9182 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9183 dump_stack();
9184 unhandled_fault(regs->tpc, current, regs);
9185@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9186 show_regs(regs);
9187 }
9188
9189+#ifdef CONFIG_PAX_PAGEEXEC
9190+#ifdef CONFIG_PAX_DLRESOLVE
9191+static void pax_emuplt_close(struct vm_area_struct *vma)
9192+{
9193+ vma->vm_mm->call_dl_resolve = 0UL;
9194+}
9195+
9196+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9197+{
9198+ unsigned int *kaddr;
9199+
9200+ vmf->page = alloc_page(GFP_HIGHUSER);
9201+ if (!vmf->page)
9202+ return VM_FAULT_OOM;
9203+
9204+ kaddr = kmap(vmf->page);
9205+ memset(kaddr, 0, PAGE_SIZE);
9206+ kaddr[0] = 0x9DE3BFA8U; /* save */
9207+ flush_dcache_page(vmf->page);
9208+ kunmap(vmf->page);
9209+ return VM_FAULT_MAJOR;
9210+}
9211+
9212+static const struct vm_operations_struct pax_vm_ops = {
9213+ .close = pax_emuplt_close,
9214+ .fault = pax_emuplt_fault
9215+};
9216+
9217+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9218+{
9219+ int ret;
9220+
9221+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9222+ vma->vm_mm = current->mm;
9223+ vma->vm_start = addr;
9224+ vma->vm_end = addr + PAGE_SIZE;
9225+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9226+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9227+ vma->vm_ops = &pax_vm_ops;
9228+
9229+ ret = insert_vm_struct(current->mm, vma);
9230+ if (ret)
9231+ return ret;
9232+
9233+ ++current->mm->total_vm;
9234+ return 0;
9235+}
9236+#endif
9237+
9238+/*
9239+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9240+ *
9241+ * returns 1 when task should be killed
9242+ * 2 when patched PLT trampoline was detected
9243+ * 3 when unpatched PLT trampoline was detected
9244+ */
9245+static int pax_handle_fetch_fault(struct pt_regs *regs)
9246+{
9247+
9248+#ifdef CONFIG_PAX_EMUPLT
9249+ int err;
9250+
9251+ do { /* PaX: patched PLT emulation #1 */
9252+ unsigned int sethi1, sethi2, jmpl;
9253+
9254+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9255+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9256+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9257+
9258+ if (err)
9259+ break;
9260+
9261+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9262+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9263+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9264+ {
9265+ unsigned long addr;
9266+
9267+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9268+ addr = regs->u_regs[UREG_G1];
9269+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9270+
9271+ if (test_thread_flag(TIF_32BIT))
9272+ addr &= 0xFFFFFFFFUL;
9273+
9274+ regs->tpc = addr;
9275+ regs->tnpc = addr+4;
9276+ return 2;
9277+ }
9278+ } while (0);
9279+
9280+ do { /* PaX: patched PLT emulation #2 */
9281+ unsigned int ba;
9282+
9283+ err = get_user(ba, (unsigned int *)regs->tpc);
9284+
9285+ if (err)
9286+ break;
9287+
9288+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9289+ unsigned long addr;
9290+
9291+ if ((ba & 0xFFC00000U) == 0x30800000U)
9292+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9293+ else
9294+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9295+
9296+ if (test_thread_flag(TIF_32BIT))
9297+ addr &= 0xFFFFFFFFUL;
9298+
9299+ regs->tpc = addr;
9300+ regs->tnpc = addr+4;
9301+ return 2;
9302+ }
9303+ } while (0);
9304+
9305+ do { /* PaX: patched PLT emulation #3 */
9306+ unsigned int sethi, bajmpl, nop;
9307+
9308+ err = get_user(sethi, (unsigned int *)regs->tpc);
9309+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9310+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9311+
9312+ if (err)
9313+ break;
9314+
9315+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9316+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9317+ nop == 0x01000000U)
9318+ {
9319+ unsigned long addr;
9320+
9321+ addr = (sethi & 0x003FFFFFU) << 10;
9322+ regs->u_regs[UREG_G1] = addr;
9323+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9324+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9325+ else
9326+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9327+
9328+ if (test_thread_flag(TIF_32BIT))
9329+ addr &= 0xFFFFFFFFUL;
9330+
9331+ regs->tpc = addr;
9332+ regs->tnpc = addr+4;
9333+ return 2;
9334+ }
9335+ } while (0);
9336+
9337+ do { /* PaX: patched PLT emulation #4 */
9338+ unsigned int sethi, mov1, call, mov2;
9339+
9340+ err = get_user(sethi, (unsigned int *)regs->tpc);
9341+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9342+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9343+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9344+
9345+ if (err)
9346+ break;
9347+
9348+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9349+ mov1 == 0x8210000FU &&
9350+ (call & 0xC0000000U) == 0x40000000U &&
9351+ mov2 == 0x9E100001U)
9352+ {
9353+ unsigned long addr;
9354+
9355+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9356+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9357+
9358+ if (test_thread_flag(TIF_32BIT))
9359+ addr &= 0xFFFFFFFFUL;
9360+
9361+ regs->tpc = addr;
9362+ regs->tnpc = addr+4;
9363+ return 2;
9364+ }
9365+ } while (0);
9366+
9367+ do { /* PaX: patched PLT emulation #5 */
9368+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9369+
9370+ err = get_user(sethi, (unsigned int *)regs->tpc);
9371+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9372+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9373+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9374+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9375+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9376+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9377+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9378+
9379+ if (err)
9380+ break;
9381+
9382+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9383+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9384+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9385+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9386+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9387+ sllx == 0x83287020U &&
9388+ jmpl == 0x81C04005U &&
9389+ nop == 0x01000000U)
9390+ {
9391+ unsigned long addr;
9392+
9393+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9394+ regs->u_regs[UREG_G1] <<= 32;
9395+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9396+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9397+ regs->tpc = addr;
9398+ regs->tnpc = addr+4;
9399+ return 2;
9400+ }
9401+ } while (0);
9402+
9403+ do { /* PaX: patched PLT emulation #6 */
9404+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9405+
9406+ err = get_user(sethi, (unsigned int *)regs->tpc);
9407+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9408+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9409+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9410+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9411+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9412+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9413+
9414+ if (err)
9415+ break;
9416+
9417+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9418+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9419+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9420+ sllx == 0x83287020U &&
9421+ (or & 0xFFFFE000U) == 0x8A116000U &&
9422+ jmpl == 0x81C04005U &&
9423+ nop == 0x01000000U)
9424+ {
9425+ unsigned long addr;
9426+
9427+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9428+ regs->u_regs[UREG_G1] <<= 32;
9429+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9430+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9431+ regs->tpc = addr;
9432+ regs->tnpc = addr+4;
9433+ return 2;
9434+ }
9435+ } while (0);
9436+
9437+ do { /* PaX: unpatched PLT emulation step 1 */
9438+ unsigned int sethi, ba, nop;
9439+
9440+ err = get_user(sethi, (unsigned int *)regs->tpc);
9441+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9442+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9443+
9444+ if (err)
9445+ break;
9446+
9447+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9448+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9449+ nop == 0x01000000U)
9450+ {
9451+ unsigned long addr;
9452+ unsigned int save, call;
9453+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9454+
9455+ if ((ba & 0xFFC00000U) == 0x30800000U)
9456+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9457+ else
9458+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9459+
9460+ if (test_thread_flag(TIF_32BIT))
9461+ addr &= 0xFFFFFFFFUL;
9462+
9463+ err = get_user(save, (unsigned int *)addr);
9464+ err |= get_user(call, (unsigned int *)(addr+4));
9465+ err |= get_user(nop, (unsigned int *)(addr+8));
9466+ if (err)
9467+ break;
9468+
9469+#ifdef CONFIG_PAX_DLRESOLVE
9470+ if (save == 0x9DE3BFA8U &&
9471+ (call & 0xC0000000U) == 0x40000000U &&
9472+ nop == 0x01000000U)
9473+ {
9474+ struct vm_area_struct *vma;
9475+ unsigned long call_dl_resolve;
9476+
9477+ down_read(&current->mm->mmap_sem);
9478+ call_dl_resolve = current->mm->call_dl_resolve;
9479+ up_read(&current->mm->mmap_sem);
9480+ if (likely(call_dl_resolve))
9481+ goto emulate;
9482+
9483+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9484+
9485+ down_write(&current->mm->mmap_sem);
9486+ if (current->mm->call_dl_resolve) {
9487+ call_dl_resolve = current->mm->call_dl_resolve;
9488+ up_write(&current->mm->mmap_sem);
9489+ if (vma)
9490+ kmem_cache_free(vm_area_cachep, vma);
9491+ goto emulate;
9492+ }
9493+
9494+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9495+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9496+ up_write(&current->mm->mmap_sem);
9497+ if (vma)
9498+ kmem_cache_free(vm_area_cachep, vma);
9499+ return 1;
9500+ }
9501+
9502+ if (pax_insert_vma(vma, call_dl_resolve)) {
9503+ up_write(&current->mm->mmap_sem);
9504+ kmem_cache_free(vm_area_cachep, vma);
9505+ return 1;
9506+ }
9507+
9508+ current->mm->call_dl_resolve = call_dl_resolve;
9509+ up_write(&current->mm->mmap_sem);
9510+
9511+emulate:
9512+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9513+ regs->tpc = call_dl_resolve;
9514+ regs->tnpc = addr+4;
9515+ return 3;
9516+ }
9517+#endif
9518+
9519+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9520+ if ((save & 0xFFC00000U) == 0x05000000U &&
9521+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9522+ nop == 0x01000000U)
9523+ {
9524+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9525+ regs->u_regs[UREG_G2] = addr + 4;
9526+ addr = (save & 0x003FFFFFU) << 10;
9527+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9528+
9529+ if (test_thread_flag(TIF_32BIT))
9530+ addr &= 0xFFFFFFFFUL;
9531+
9532+ regs->tpc = addr;
9533+ regs->tnpc = addr+4;
9534+ return 3;
9535+ }
9536+
9537+ /* PaX: 64-bit PLT stub */
9538+ err = get_user(sethi1, (unsigned int *)addr);
9539+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9540+ err |= get_user(or1, (unsigned int *)(addr+8));
9541+ err |= get_user(or2, (unsigned int *)(addr+12));
9542+ err |= get_user(sllx, (unsigned int *)(addr+16));
9543+ err |= get_user(add, (unsigned int *)(addr+20));
9544+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9545+ err |= get_user(nop, (unsigned int *)(addr+28));
9546+ if (err)
9547+ break;
9548+
9549+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9550+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9551+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9552+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9553+ sllx == 0x89293020U &&
9554+ add == 0x8A010005U &&
9555+ jmpl == 0x89C14000U &&
9556+ nop == 0x01000000U)
9557+ {
9558+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9559+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9560+ regs->u_regs[UREG_G4] <<= 32;
9561+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9562+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9563+ regs->u_regs[UREG_G4] = addr + 24;
9564+ addr = regs->u_regs[UREG_G5];
9565+ regs->tpc = addr;
9566+ regs->tnpc = addr+4;
9567+ return 3;
9568+ }
9569+ }
9570+ } while (0);
9571+
9572+#ifdef CONFIG_PAX_DLRESOLVE
9573+ do { /* PaX: unpatched PLT emulation step 2 */
9574+ unsigned int save, call, nop;
9575+
9576+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9577+ err |= get_user(call, (unsigned int *)regs->tpc);
9578+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9579+ if (err)
9580+ break;
9581+
9582+ if (save == 0x9DE3BFA8U &&
9583+ (call & 0xC0000000U) == 0x40000000U &&
9584+ nop == 0x01000000U)
9585+ {
9586+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9587+
9588+ if (test_thread_flag(TIF_32BIT))
9589+ dl_resolve &= 0xFFFFFFFFUL;
9590+
9591+ regs->u_regs[UREG_RETPC] = regs->tpc;
9592+ regs->tpc = dl_resolve;
9593+ regs->tnpc = dl_resolve+4;
9594+ return 3;
9595+ }
9596+ } while (0);
9597+#endif
9598+
9599+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9600+ unsigned int sethi, ba, nop;
9601+
9602+ err = get_user(sethi, (unsigned int *)regs->tpc);
9603+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9604+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9605+
9606+ if (err)
9607+ break;
9608+
9609+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9610+ (ba & 0xFFF00000U) == 0x30600000U &&
9611+ nop == 0x01000000U)
9612+ {
9613+ unsigned long addr;
9614+
9615+ addr = (sethi & 0x003FFFFFU) << 10;
9616+ regs->u_regs[UREG_G1] = addr;
9617+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9618+
9619+ if (test_thread_flag(TIF_32BIT))
9620+ addr &= 0xFFFFFFFFUL;
9621+
9622+ regs->tpc = addr;
9623+ regs->tnpc = addr+4;
9624+ return 2;
9625+ }
9626+ } while (0);
9627+
9628+#endif
9629+
9630+ return 1;
9631+}
9632+
9633+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9634+{
9635+ unsigned long i;
9636+
9637+ printk(KERN_ERR "PAX: bytes at PC: ");
9638+ for (i = 0; i < 8; i++) {
9639+ unsigned int c;
9640+ if (get_user(c, (unsigned int *)pc+i))
9641+ printk(KERN_CONT "???????? ");
9642+ else
9643+ printk(KERN_CONT "%08x ", c);
9644+ }
9645+ printk("\n");
9646+}
9647+#endif
9648+
9649 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9650 {
9651 struct mm_struct *mm = current->mm;
9652@@ -341,6 +804,29 @@ retry:
9653 if (!vma)
9654 goto bad_area;
9655
9656+#ifdef CONFIG_PAX_PAGEEXEC
9657+ /* PaX: detect ITLB misses on non-exec pages */
9658+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9659+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9660+ {
9661+ if (address != regs->tpc)
9662+ goto good_area;
9663+
9664+ up_read(&mm->mmap_sem);
9665+ switch (pax_handle_fetch_fault(regs)) {
9666+
9667+#ifdef CONFIG_PAX_EMUPLT
9668+ case 2:
9669+ case 3:
9670+ return;
9671+#endif
9672+
9673+ }
9674+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9675+ do_group_exit(SIGKILL);
9676+ }
9677+#endif
9678+
9679 /* Pure DTLB misses do not tell us whether the fault causing
9680 * load/store/atomic was a write or not, it only says that there
9681 * was no match. So in such a case we (carefully) read the
9682diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9683index d2b5944..bd813f2 100644
9684--- a/arch/sparc/mm/hugetlbpage.c
9685+++ b/arch/sparc/mm/hugetlbpage.c
9686@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9687
9688 info.flags = 0;
9689 info.length = len;
9690- info.low_limit = TASK_UNMAPPED_BASE;
9691+ info.low_limit = mm->mmap_base;
9692 info.high_limit = min(task_size, VA_EXCLUDE_START);
9693 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9694 info.align_offset = 0;
9695@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9696 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9697 VM_BUG_ON(addr != -ENOMEM);
9698 info.low_limit = VA_EXCLUDE_END;
9699+
9700+#ifdef CONFIG_PAX_RANDMMAP
9701+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9702+ info.low_limit += mm->delta_mmap;
9703+#endif
9704+
9705 info.high_limit = task_size;
9706 addr = vm_unmapped_area(&info);
9707 }
9708@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9709 VM_BUG_ON(addr != -ENOMEM);
9710 info.flags = 0;
9711 info.low_limit = TASK_UNMAPPED_BASE;
9712+
9713+#ifdef CONFIG_PAX_RANDMMAP
9714+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9715+ info.low_limit += mm->delta_mmap;
9716+#endif
9717+
9718 info.high_limit = STACK_TOP32;
9719 addr = vm_unmapped_area(&info);
9720 }
9721@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9722 struct mm_struct *mm = current->mm;
9723 struct vm_area_struct *vma;
9724 unsigned long task_size = TASK_SIZE;
9725+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9726
9727 if (test_thread_flag(TIF_32BIT))
9728 task_size = STACK_TOP32;
9729@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9730 return addr;
9731 }
9732
9733+#ifdef CONFIG_PAX_RANDMMAP
9734+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9735+#endif
9736+
9737 if (addr) {
9738 addr = ALIGN(addr, HPAGE_SIZE);
9739 vma = find_vma(mm, addr);
9740- if (task_size - len >= addr &&
9741- (!vma || addr + len <= vma->vm_start))
9742+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9743 return addr;
9744 }
9745 if (mm->get_unmapped_area == arch_get_unmapped_area)
9746diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9747index f4500c6..889656c 100644
9748--- a/arch/tile/include/asm/atomic_64.h
9749+++ b/arch/tile/include/asm/atomic_64.h
9750@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9751
9752 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9753
9754+#define atomic64_read_unchecked(v) atomic64_read(v)
9755+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9756+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9757+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9758+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9759+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9760+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9761+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9762+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9763+
9764 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9765 #define smp_mb__before_atomic_dec() smp_mb()
9766 #define smp_mb__after_atomic_dec() smp_mb()
9767diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9768index a9a5299..0fce79e 100644
9769--- a/arch/tile/include/asm/cache.h
9770+++ b/arch/tile/include/asm/cache.h
9771@@ -15,11 +15,12 @@
9772 #ifndef _ASM_TILE_CACHE_H
9773 #define _ASM_TILE_CACHE_H
9774
9775+#include <linux/const.h>
9776 #include <arch/chip.h>
9777
9778 /* bytes per L1 data cache line */
9779 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9780-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9781+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9782
9783 /* bytes per L2 cache line */
9784 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9785diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9786index 9ab078a..d6635c2 100644
9787--- a/arch/tile/include/asm/uaccess.h
9788+++ b/arch/tile/include/asm/uaccess.h
9789@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9790 const void __user *from,
9791 unsigned long n)
9792 {
9793- int sz = __compiletime_object_size(to);
9794+ size_t sz = __compiletime_object_size(to);
9795
9796- if (likely(sz == -1 || sz >= n))
9797+ if (likely(sz == (size_t)-1 || sz >= n))
9798 n = _copy_from_user(to, from, n);
9799 else
9800 copy_from_user_overflow();
9801diff --git a/arch/um/Makefile b/arch/um/Makefile
9802index 133f7de..1d6f2f1 100644
9803--- a/arch/um/Makefile
9804+++ b/arch/um/Makefile
9805@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9806 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9807 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9808
9809+ifdef CONSTIFY_PLUGIN
9810+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9811+endif
9812+
9813 #This will adjust *FLAGS accordingly to the platform.
9814 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9815
9816diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9817index 19e1bdd..3665b77 100644
9818--- a/arch/um/include/asm/cache.h
9819+++ b/arch/um/include/asm/cache.h
9820@@ -1,6 +1,7 @@
9821 #ifndef __UM_CACHE_H
9822 #define __UM_CACHE_H
9823
9824+#include <linux/const.h>
9825
9826 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9827 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9828@@ -12,6 +13,6 @@
9829 # define L1_CACHE_SHIFT 5
9830 #endif
9831
9832-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9833+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9834
9835 #endif
9836diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9837index 2e0a6b1..a64d0f5 100644
9838--- a/arch/um/include/asm/kmap_types.h
9839+++ b/arch/um/include/asm/kmap_types.h
9840@@ -8,6 +8,6 @@
9841
9842 /* No more #include "asm/arch/kmap_types.h" ! */
9843
9844-#define KM_TYPE_NR 14
9845+#define KM_TYPE_NR 15
9846
9847 #endif
9848diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9849index 5ff53d9..5850cdf 100644
9850--- a/arch/um/include/asm/page.h
9851+++ b/arch/um/include/asm/page.h
9852@@ -14,6 +14,9 @@
9853 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9854 #define PAGE_MASK (~(PAGE_SIZE-1))
9855
9856+#define ktla_ktva(addr) (addr)
9857+#define ktva_ktla(addr) (addr)
9858+
9859 #ifndef __ASSEMBLY__
9860
9861 struct page;
9862diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9863index 0032f92..cd151e0 100644
9864--- a/arch/um/include/asm/pgtable-3level.h
9865+++ b/arch/um/include/asm/pgtable-3level.h
9866@@ -58,6 +58,7 @@
9867 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9868 #define pud_populate(mm, pud, pmd) \
9869 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9870+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9871
9872 #ifdef CONFIG_64BIT
9873 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9874diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9875index b462b13..e7a19aa 100644
9876--- a/arch/um/kernel/process.c
9877+++ b/arch/um/kernel/process.c
9878@@ -386,22 +386,6 @@ int singlestepping(void * t)
9879 return 2;
9880 }
9881
9882-/*
9883- * Only x86 and x86_64 have an arch_align_stack().
9884- * All other arches have "#define arch_align_stack(x) (x)"
9885- * in their asm/system.h
9886- * As this is included in UML from asm-um/system-generic.h,
9887- * we can use it to behave as the subarch does.
9888- */
9889-#ifndef arch_align_stack
9890-unsigned long arch_align_stack(unsigned long sp)
9891-{
9892- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9893- sp -= get_random_int() % 8192;
9894- return sp & ~0xf;
9895-}
9896-#endif
9897-
9898 unsigned long get_wchan(struct task_struct *p)
9899 {
9900 unsigned long stack_page, sp, ip;
9901diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9902index ad8f795..2c7eec6 100644
9903--- a/arch/unicore32/include/asm/cache.h
9904+++ b/arch/unicore32/include/asm/cache.h
9905@@ -12,8 +12,10 @@
9906 #ifndef __UNICORE_CACHE_H__
9907 #define __UNICORE_CACHE_H__
9908
9909-#define L1_CACHE_SHIFT (5)
9910-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9911+#include <linux/const.h>
9912+
9913+#define L1_CACHE_SHIFT 5
9914+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9915
9916 /*
9917 * Memory returned by kmalloc() may be used for DMA, so we must make
9918diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9919index 0694d09..b58b3aa 100644
9920--- a/arch/x86/Kconfig
9921+++ b/arch/x86/Kconfig
9922@@ -238,7 +238,7 @@ config X86_HT
9923
9924 config X86_32_LAZY_GS
9925 def_bool y
9926- depends on X86_32 && !CC_STACKPROTECTOR
9927+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9928
9929 config ARCH_HWEIGHT_CFLAGS
9930 string
9931@@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9932
9933 config X86_MSR
9934 tristate "/dev/cpu/*/msr - Model-specific register support"
9935+ depends on !GRKERNSEC_KMEM
9936 ---help---
9937 This device gives privileged processes access to the x86
9938 Model-Specific Registers (MSRs). It is a character device with
9939@@ -1054,7 +1055,7 @@ choice
9940
9941 config NOHIGHMEM
9942 bool "off"
9943- depends on !X86_NUMAQ
9944+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9945 ---help---
9946 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9947 However, the address space of 32-bit x86 processors is only 4
9948@@ -1091,7 +1092,7 @@ config NOHIGHMEM
9949
9950 config HIGHMEM4G
9951 bool "4GB"
9952- depends on !X86_NUMAQ
9953+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9954 ---help---
9955 Select this if you have a 32-bit processor and between 1 and 4
9956 gigabytes of physical RAM.
9957@@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9958 hex
9959 default 0xB0000000 if VMSPLIT_3G_OPT
9960 default 0x80000000 if VMSPLIT_2G
9961- default 0x78000000 if VMSPLIT_2G_OPT
9962+ default 0x70000000 if VMSPLIT_2G_OPT
9963 default 0x40000000 if VMSPLIT_1G
9964 default 0xC0000000
9965 depends on X86_32
9966@@ -1542,6 +1543,7 @@ config SECCOMP
9967
9968 config CC_STACKPROTECTOR
9969 bool "Enable -fstack-protector buffer overflow detection"
9970+ depends on X86_64 || !PAX_MEMORY_UDEREF
9971 ---help---
9972 This option turns on the -fstack-protector GCC feature. This
9973 feature puts, at the beginning of functions, a canary value on
9974@@ -1599,6 +1601,7 @@ config KEXEC_JUMP
9975 config PHYSICAL_START
9976 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9977 default "0x1000000"
9978+ range 0x400000 0x40000000
9979 ---help---
9980 This gives the physical address where the kernel is loaded.
9981
9982@@ -1662,6 +1665,7 @@ config X86_NEED_RELOCS
9983 config PHYSICAL_ALIGN
9984 hex "Alignment value to which kernel should be aligned" if X86_32
9985 default "0x1000000"
9986+ range 0x400000 0x1000000 if PAX_KERNEXEC
9987 range 0x2000 0x1000000
9988 ---help---
9989 This value puts the alignment restrictions on physical address
9990@@ -1737,9 +1741,10 @@ config DEBUG_HOTPLUG_CPU0
9991 If unsure, say N.
9992
9993 config COMPAT_VDSO
9994- def_bool y
9995+ def_bool n
9996 prompt "Compat VDSO support"
9997 depends on X86_32 || IA32_EMULATION
9998+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9999 ---help---
10000 Map the 32-bit VDSO to the predictable old-style address too.
10001
10002diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10003index c026cca..14657ae 100644
10004--- a/arch/x86/Kconfig.cpu
10005+++ b/arch/x86/Kconfig.cpu
10006@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10007
10008 config X86_F00F_BUG
10009 def_bool y
10010- depends on M586MMX || M586TSC || M586 || M486
10011+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10012
10013 config X86_INVD_BUG
10014 def_bool y
10015@@ -327,7 +327,7 @@ config X86_INVD_BUG
10016
10017 config X86_ALIGNMENT_16
10018 def_bool y
10019- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10020+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10021
10022 config X86_INTEL_USERCOPY
10023 def_bool y
10024@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10025 # generates cmov.
10026 config X86_CMOV
10027 def_bool y
10028- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10029+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10030
10031 config X86_MINIMUM_CPU_FAMILY
10032 int
10033diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10034index b322f12..652d0d9 100644
10035--- a/arch/x86/Kconfig.debug
10036+++ b/arch/x86/Kconfig.debug
10037@@ -84,7 +84,7 @@ config X86_PTDUMP
10038 config DEBUG_RODATA
10039 bool "Write protect kernel read-only data structures"
10040 default y
10041- depends on DEBUG_KERNEL
10042+ depends on DEBUG_KERNEL && BROKEN
10043 ---help---
10044 Mark the kernel read-only data as write-protected in the pagetables,
10045 in order to catch accidental (and incorrect) writes to such const
10046@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10047
10048 config DEBUG_SET_MODULE_RONX
10049 bool "Set loadable kernel module data as NX and text as RO"
10050- depends on MODULES
10051+ depends on MODULES && BROKEN
10052 ---help---
10053 This option helps catch unintended modifications to loadable
10054 kernel module's text and read-only data. It also prevents execution
10055@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10056
10057 config DEBUG_STRICT_USER_COPY_CHECKS
10058 bool "Strict copy size checks"
10059- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10060+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10061 ---help---
10062 Enabling this option turns a certain set of sanity checks for user
10063 copy operations into compile time failures.
10064diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10065index e71fc42..7829607 100644
10066--- a/arch/x86/Makefile
10067+++ b/arch/x86/Makefile
10068@@ -50,6 +50,7 @@ else
10069 UTS_MACHINE := x86_64
10070 CHECKFLAGS += -D__x86_64__ -m64
10071
10072+ biarch := $(call cc-option,-m64)
10073 KBUILD_AFLAGS += -m64
10074 KBUILD_CFLAGS += -m64
10075
10076@@ -230,3 +231,12 @@ define archhelp
10077 echo ' FDARGS="..." arguments for the booted kernel'
10078 echo ' FDINITRD=file initrd for the booted kernel'
10079 endef
10080+
10081+define OLD_LD
10082+
10083+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10084+*** Please upgrade your binutils to 2.18 or newer
10085+endef
10086+
10087+archprepare:
10088+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10089diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10090index 379814b..add62ce 100644
10091--- a/arch/x86/boot/Makefile
10092+++ b/arch/x86/boot/Makefile
10093@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10094 $(call cc-option, -fno-stack-protector) \
10095 $(call cc-option, -mpreferred-stack-boundary=2)
10096 KBUILD_CFLAGS += $(call cc-option, -m32)
10097+ifdef CONSTIFY_PLUGIN
10098+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10099+endif
10100 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10101 GCOV_PROFILE := n
10102
10103diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10104index 878e4b9..20537ab 100644
10105--- a/arch/x86/boot/bitops.h
10106+++ b/arch/x86/boot/bitops.h
10107@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10108 u8 v;
10109 const u32 *p = (const u32 *)addr;
10110
10111- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10112+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10113 return v;
10114 }
10115
10116@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10117
10118 static inline void set_bit(int nr, void *addr)
10119 {
10120- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10121+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10122 }
10123
10124 #endif /* BOOT_BITOPS_H */
10125diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10126index 18997e5..83d9c67 100644
10127--- a/arch/x86/boot/boot.h
10128+++ b/arch/x86/boot/boot.h
10129@@ -85,7 +85,7 @@ static inline void io_delay(void)
10130 static inline u16 ds(void)
10131 {
10132 u16 seg;
10133- asm("movw %%ds,%0" : "=rm" (seg));
10134+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10135 return seg;
10136 }
10137
10138@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10139 static inline int memcmp(const void *s1, const void *s2, size_t len)
10140 {
10141 u8 diff;
10142- asm("repe; cmpsb; setnz %0"
10143+ asm volatile("repe; cmpsb; setnz %0"
10144 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10145 return diff;
10146 }
10147diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10148index 8a84501..b2d165f 100644
10149--- a/arch/x86/boot/compressed/Makefile
10150+++ b/arch/x86/boot/compressed/Makefile
10151@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10152 KBUILD_CFLAGS += $(cflags-y)
10153 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10154 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10155+ifdef CONSTIFY_PLUGIN
10156+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10157+endif
10158
10159 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10160 GCOV_PROFILE := n
10161diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10162index c205035..5853587 100644
10163--- a/arch/x86/boot/compressed/eboot.c
10164+++ b/arch/x86/boot/compressed/eboot.c
10165@@ -150,7 +150,6 @@ again:
10166 *addr = max_addr;
10167 }
10168
10169-free_pool:
10170 efi_call_phys1(sys_table->boottime->free_pool, map);
10171
10172 fail:
10173@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10174 if (i == map_size / desc_size)
10175 status = EFI_NOT_FOUND;
10176
10177-free_pool:
10178 efi_call_phys1(sys_table->boottime->free_pool, map);
10179 fail:
10180 return status;
10181diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10182index 1e3184f..0d11e2e 100644
10183--- a/arch/x86/boot/compressed/head_32.S
10184+++ b/arch/x86/boot/compressed/head_32.S
10185@@ -118,7 +118,7 @@ preferred_addr:
10186 notl %eax
10187 andl %eax, %ebx
10188 #else
10189- movl $LOAD_PHYSICAL_ADDR, %ebx
10190+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10191 #endif
10192
10193 /* Target address to relocate to for decompression */
10194@@ -204,7 +204,7 @@ relocated:
10195 * and where it was actually loaded.
10196 */
10197 movl %ebp, %ebx
10198- subl $LOAD_PHYSICAL_ADDR, %ebx
10199+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10200 jz 2f /* Nothing to be done if loaded at compiled addr. */
10201 /*
10202 * Process relocations.
10203@@ -212,8 +212,7 @@ relocated:
10204
10205 1: subl $4, %edi
10206 movl (%edi), %ecx
10207- testl %ecx, %ecx
10208- jz 2f
10209+ jecxz 2f
10210 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10211 jmp 1b
10212 2:
10213diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10214index f5d1aaa..cce11dc 100644
10215--- a/arch/x86/boot/compressed/head_64.S
10216+++ b/arch/x86/boot/compressed/head_64.S
10217@@ -91,7 +91,7 @@ ENTRY(startup_32)
10218 notl %eax
10219 andl %eax, %ebx
10220 #else
10221- movl $LOAD_PHYSICAL_ADDR, %ebx
10222+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10223 #endif
10224
10225 /* Target address to relocate to for decompression */
10226@@ -273,7 +273,7 @@ preferred_addr:
10227 notq %rax
10228 andq %rax, %rbp
10229 #else
10230- movq $LOAD_PHYSICAL_ADDR, %rbp
10231+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10232 #endif
10233
10234 /* Target address to relocate to for decompression */
10235diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10236index 88f7ff6..ed695dd 100644
10237--- a/arch/x86/boot/compressed/misc.c
10238+++ b/arch/x86/boot/compressed/misc.c
10239@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10240 case PT_LOAD:
10241 #ifdef CONFIG_RELOCATABLE
10242 dest = output;
10243- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10244+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10245 #else
10246 dest = (void *)(phdr->p_paddr);
10247 #endif
10248@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10249 error("Destination address too large");
10250 #endif
10251 #ifndef CONFIG_RELOCATABLE
10252- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10253+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10254 error("Wrong destination address");
10255 #endif
10256
10257diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10258index 4d3ff03..e4972ff 100644
10259--- a/arch/x86/boot/cpucheck.c
10260+++ b/arch/x86/boot/cpucheck.c
10261@@ -74,7 +74,7 @@ static int has_fpu(void)
10262 u16 fcw = -1, fsw = -1;
10263 u32 cr0;
10264
10265- asm("movl %%cr0,%0" : "=r" (cr0));
10266+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10267 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10268 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10269 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10270@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10271 {
10272 u32 f0, f1;
10273
10274- asm("pushfl ; "
10275+ asm volatile("pushfl ; "
10276 "pushfl ; "
10277 "popl %0 ; "
10278 "movl %0,%1 ; "
10279@@ -115,7 +115,7 @@ static void get_flags(void)
10280 set_bit(X86_FEATURE_FPU, cpu.flags);
10281
10282 if (has_eflag(X86_EFLAGS_ID)) {
10283- asm("cpuid"
10284+ asm volatile("cpuid"
10285 : "=a" (max_intel_level),
10286 "=b" (cpu_vendor[0]),
10287 "=d" (cpu_vendor[1]),
10288@@ -124,7 +124,7 @@ static void get_flags(void)
10289
10290 if (max_intel_level >= 0x00000001 &&
10291 max_intel_level <= 0x0000ffff) {
10292- asm("cpuid"
10293+ asm volatile("cpuid"
10294 : "=a" (tfms),
10295 "=c" (cpu.flags[4]),
10296 "=d" (cpu.flags[0])
10297@@ -136,7 +136,7 @@ static void get_flags(void)
10298 cpu.model += ((tfms >> 16) & 0xf) << 4;
10299 }
10300
10301- asm("cpuid"
10302+ asm volatile("cpuid"
10303 : "=a" (max_amd_level)
10304 : "a" (0x80000000)
10305 : "ebx", "ecx", "edx");
10306@@ -144,7 +144,7 @@ static void get_flags(void)
10307 if (max_amd_level >= 0x80000001 &&
10308 max_amd_level <= 0x8000ffff) {
10309 u32 eax = 0x80000001;
10310- asm("cpuid"
10311+ asm volatile("cpuid"
10312 : "+a" (eax),
10313 "=c" (cpu.flags[6]),
10314 "=d" (cpu.flags[1])
10315@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10316 u32 ecx = MSR_K7_HWCR;
10317 u32 eax, edx;
10318
10319- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10320+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10321 eax &= ~(1 << 15);
10322- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10323+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10324
10325 get_flags(); /* Make sure it really did something */
10326 err = check_flags();
10327@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10328 u32 ecx = MSR_VIA_FCR;
10329 u32 eax, edx;
10330
10331- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10332+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10333 eax |= (1<<1)|(1<<7);
10334- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10335+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10336
10337 set_bit(X86_FEATURE_CX8, cpu.flags);
10338 err = check_flags();
10339@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10340 u32 eax, edx;
10341 u32 level = 1;
10342
10343- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10344- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10345- asm("cpuid"
10346+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10347+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10348+ asm volatile("cpuid"
10349 : "+a" (level), "=d" (cpu.flags[0])
10350 : : "ecx", "ebx");
10351- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10352+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10353
10354 err = check_flags();
10355 }
10356diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10357index 944ce59..87ee37a 100644
10358--- a/arch/x86/boot/header.S
10359+++ b/arch/x86/boot/header.S
10360@@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10361 # single linked list of
10362 # struct setup_data
10363
10364-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10365+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10366
10367 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10368+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10369+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10370+#else
10371 #define VO_INIT_SIZE (VO__end - VO__text)
10372+#endif
10373 #if ZO_INIT_SIZE > VO_INIT_SIZE
10374 #define INIT_SIZE ZO_INIT_SIZE
10375 #else
10376diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10377index db75d07..8e6d0af 100644
10378--- a/arch/x86/boot/memory.c
10379+++ b/arch/x86/boot/memory.c
10380@@ -19,7 +19,7 @@
10381
10382 static int detect_memory_e820(void)
10383 {
10384- int count = 0;
10385+ unsigned int count = 0;
10386 struct biosregs ireg, oreg;
10387 struct e820entry *desc = boot_params.e820_map;
10388 static struct e820entry buf; /* static so it is zeroed */
10389diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10390index 11e8c6e..fdbb1ed 100644
10391--- a/arch/x86/boot/video-vesa.c
10392+++ b/arch/x86/boot/video-vesa.c
10393@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10394
10395 boot_params.screen_info.vesapm_seg = oreg.es;
10396 boot_params.screen_info.vesapm_off = oreg.di;
10397+ boot_params.screen_info.vesapm_size = oreg.cx;
10398 }
10399
10400 /*
10401diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10402index 43eda28..5ab5fdb 100644
10403--- a/arch/x86/boot/video.c
10404+++ b/arch/x86/boot/video.c
10405@@ -96,7 +96,7 @@ static void store_mode_params(void)
10406 static unsigned int get_entry(void)
10407 {
10408 char entry_buf[4];
10409- int i, len = 0;
10410+ unsigned int i, len = 0;
10411 int key;
10412 unsigned int v;
10413
10414diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10415index 5b577d5..3c1fed4 100644
10416--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10417+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10418@@ -8,6 +8,8 @@
10419 * including this sentence is retained in full.
10420 */
10421
10422+#include <asm/alternative-asm.h>
10423+
10424 .extern crypto_ft_tab
10425 .extern crypto_it_tab
10426 .extern crypto_fl_tab
10427@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10428 je B192; \
10429 leaq 32(r9),r9;
10430
10431+#define ret pax_force_retaddr 0, 1; ret
10432+
10433 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10434 movq r1,r2; \
10435 movq r3,r4; \
10436diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10437index 3470624..201259d 100644
10438--- a/arch/x86/crypto/aesni-intel_asm.S
10439+++ b/arch/x86/crypto/aesni-intel_asm.S
10440@@ -31,6 +31,7 @@
10441
10442 #include <linux/linkage.h>
10443 #include <asm/inst.h>
10444+#include <asm/alternative-asm.h>
10445
10446 #ifdef __x86_64__
10447 .data
10448@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10449 pop %r14
10450 pop %r13
10451 pop %r12
10452+ pax_force_retaddr 0, 1
10453 ret
10454+ENDPROC(aesni_gcm_dec)
10455
10456
10457 /*****************************************************************************
10458@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10459 pop %r14
10460 pop %r13
10461 pop %r12
10462+ pax_force_retaddr 0, 1
10463 ret
10464+ENDPROC(aesni_gcm_enc)
10465
10466 #endif
10467
10468@@ -1714,6 +1719,7 @@ _key_expansion_256a:
10469 pxor %xmm1, %xmm0
10470 movaps %xmm0, (TKEYP)
10471 add $0x10, TKEYP
10472+ pax_force_retaddr_bts
10473 ret
10474
10475 .align 4
10476@@ -1738,6 +1744,7 @@ _key_expansion_192a:
10477 shufps $0b01001110, %xmm2, %xmm1
10478 movaps %xmm1, 0x10(TKEYP)
10479 add $0x20, TKEYP
10480+ pax_force_retaddr_bts
10481 ret
10482
10483 .align 4
10484@@ -1757,6 +1764,7 @@ _key_expansion_192b:
10485
10486 movaps %xmm0, (TKEYP)
10487 add $0x10, TKEYP
10488+ pax_force_retaddr_bts
10489 ret
10490
10491 .align 4
10492@@ -1769,6 +1777,7 @@ _key_expansion_256b:
10493 pxor %xmm1, %xmm2
10494 movaps %xmm2, (TKEYP)
10495 add $0x10, TKEYP
10496+ pax_force_retaddr_bts
10497 ret
10498
10499 /*
10500@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10501 #ifndef __x86_64__
10502 popl KEYP
10503 #endif
10504+ pax_force_retaddr 0, 1
10505 ret
10506+ENDPROC(aesni_set_key)
10507
10508 /*
10509 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10510@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10511 popl KLEN
10512 popl KEYP
10513 #endif
10514+ pax_force_retaddr 0, 1
10515 ret
10516+ENDPROC(aesni_enc)
10517
10518 /*
10519 * _aesni_enc1: internal ABI
10520@@ -1959,6 +1972,7 @@ _aesni_enc1:
10521 AESENC KEY STATE
10522 movaps 0x70(TKEYP), KEY
10523 AESENCLAST KEY STATE
10524+ pax_force_retaddr_bts
10525 ret
10526
10527 /*
10528@@ -2067,6 +2081,7 @@ _aesni_enc4:
10529 AESENCLAST KEY STATE2
10530 AESENCLAST KEY STATE3
10531 AESENCLAST KEY STATE4
10532+ pax_force_retaddr_bts
10533 ret
10534
10535 /*
10536@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10537 popl KLEN
10538 popl KEYP
10539 #endif
10540+ pax_force_retaddr 0, 1
10541 ret
10542+ENDPROC(aesni_dec)
10543
10544 /*
10545 * _aesni_dec1: internal ABI
10546@@ -2146,6 +2163,7 @@ _aesni_dec1:
10547 AESDEC KEY STATE
10548 movaps 0x70(TKEYP), KEY
10549 AESDECLAST KEY STATE
10550+ pax_force_retaddr_bts
10551 ret
10552
10553 /*
10554@@ -2254,6 +2272,7 @@ _aesni_dec4:
10555 AESDECLAST KEY STATE2
10556 AESDECLAST KEY STATE3
10557 AESDECLAST KEY STATE4
10558+ pax_force_retaddr_bts
10559 ret
10560
10561 /*
10562@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10563 popl KEYP
10564 popl LEN
10565 #endif
10566+ pax_force_retaddr 0, 1
10567 ret
10568+ENDPROC(aesni_ecb_enc)
10569
10570 /*
10571 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10572@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10573 popl KEYP
10574 popl LEN
10575 #endif
10576+ pax_force_retaddr 0, 1
10577 ret
10578+ENDPROC(aesni_ecb_dec)
10579
10580 /*
10581 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10582@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10583 popl LEN
10584 popl IVP
10585 #endif
10586+ pax_force_retaddr 0, 1
10587 ret
10588+ENDPROC(aesni_cbc_enc)
10589
10590 /*
10591 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10592@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10593 popl LEN
10594 popl IVP
10595 #endif
10596+ pax_force_retaddr 0, 1
10597 ret
10598+ENDPROC(aesni_cbc_dec)
10599
10600 #ifdef __x86_64__
10601 .align 16
10602@@ -2526,6 +2553,7 @@ _aesni_inc_init:
10603 mov $1, TCTR_LOW
10604 MOVQ_R64_XMM TCTR_LOW INC
10605 MOVQ_R64_XMM CTR TCTR_LOW
10606+ pax_force_retaddr_bts
10607 ret
10608
10609 /*
10610@@ -2554,6 +2582,7 @@ _aesni_inc:
10611 .Linc_low:
10612 movaps CTR, IV
10613 PSHUFB_XMM BSWAP_MASK IV
10614+ pax_force_retaddr_bts
10615 ret
10616
10617 /*
10618@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10619 .Lctr_enc_ret:
10620 movups IV, (IVP)
10621 .Lctr_enc_just_ret:
10622+ pax_force_retaddr 0, 1
10623 ret
10624+ENDPROC(aesni_ctr_enc)
10625 #endif
10626diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10627index 391d245..67f35c2 100644
10628--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10629+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10630@@ -20,6 +20,8 @@
10631 *
10632 */
10633
10634+#include <asm/alternative-asm.h>
10635+
10636 .file "blowfish-x86_64-asm.S"
10637 .text
10638
10639@@ -151,9 +153,11 @@ __blowfish_enc_blk:
10640 jnz __enc_xor;
10641
10642 write_block();
10643+ pax_force_retaddr 0, 1
10644 ret;
10645 __enc_xor:
10646 xor_block();
10647+ pax_force_retaddr 0, 1
10648 ret;
10649
10650 .align 8
10651@@ -188,6 +192,7 @@ blowfish_dec_blk:
10652
10653 movq %r11, %rbp;
10654
10655+ pax_force_retaddr 0, 1
10656 ret;
10657
10658 /**********************************************************************
10659@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10660
10661 popq %rbx;
10662 popq %rbp;
10663+ pax_force_retaddr 0, 1
10664 ret;
10665
10666 __enc_xor4:
10667@@ -349,6 +355,7 @@ __enc_xor4:
10668
10669 popq %rbx;
10670 popq %rbp;
10671+ pax_force_retaddr 0, 1
10672 ret;
10673
10674 .align 8
10675@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10676 popq %rbx;
10677 popq %rbp;
10678
10679+ pax_force_retaddr 0, 1
10680 ret;
10681
10682diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10683index 0b33743..7a56206 100644
10684--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10685+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10686@@ -20,6 +20,8 @@
10687 *
10688 */
10689
10690+#include <asm/alternative-asm.h>
10691+
10692 .file "camellia-x86_64-asm_64.S"
10693 .text
10694
10695@@ -229,12 +231,14 @@ __enc_done:
10696 enc_outunpack(mov, RT1);
10697
10698 movq RRBP, %rbp;
10699+ pax_force_retaddr 0, 1
10700 ret;
10701
10702 __enc_xor:
10703 enc_outunpack(xor, RT1);
10704
10705 movq RRBP, %rbp;
10706+ pax_force_retaddr 0, 1
10707 ret;
10708
10709 .global camellia_dec_blk;
10710@@ -275,6 +279,7 @@ __dec_rounds16:
10711 dec_outunpack();
10712
10713 movq RRBP, %rbp;
10714+ pax_force_retaddr 0, 1
10715 ret;
10716
10717 /**********************************************************************
10718@@ -468,6 +473,7 @@ __enc2_done:
10719
10720 movq RRBP, %rbp;
10721 popq %rbx;
10722+ pax_force_retaddr 0, 1
10723 ret;
10724
10725 __enc2_xor:
10726@@ -475,6 +481,7 @@ __enc2_xor:
10727
10728 movq RRBP, %rbp;
10729 popq %rbx;
10730+ pax_force_retaddr 0, 1
10731 ret;
10732
10733 .global camellia_dec_blk_2way;
10734@@ -517,4 +524,5 @@ __dec2_rounds16:
10735
10736 movq RRBP, %rbp;
10737 movq RXOR, %rbx;
10738+ pax_force_retaddr 0, 1
10739 ret;
10740diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10741index 15b00ac..2071784 100644
10742--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10743+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10744@@ -23,6 +23,8 @@
10745 *
10746 */
10747
10748+#include <asm/alternative-asm.h>
10749+
10750 .file "cast5-avx-x86_64-asm_64.S"
10751
10752 .extern cast_s1
10753@@ -281,6 +283,7 @@ __skip_enc:
10754 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10755 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10756
10757+ pax_force_retaddr 0, 1
10758 ret;
10759
10760 .align 16
10761@@ -353,6 +356,7 @@ __dec_tail:
10762 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10763 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10764
10765+ pax_force_retaddr 0, 1
10766 ret;
10767
10768 __skip_dec:
10769@@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10770 vmovdqu RR4, (6*4*4)(%r11);
10771 vmovdqu RL4, (7*4*4)(%r11);
10772
10773+ pax_force_retaddr
10774 ret;
10775
10776 .align 16
10777@@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10778 vmovdqu RR4, (6*4*4)(%r11);
10779 vmovdqu RL4, (7*4*4)(%r11);
10780
10781+ pax_force_retaddr
10782 ret;
10783
10784 .align 16
10785@@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10786
10787 popq %r12;
10788
10789+ pax_force_retaddr
10790 ret;
10791
10792 .align 16
10793@@ -555,4 +562,5 @@ cast5_ctr_16way:
10794
10795 popq %r12;
10796
10797+ pax_force_retaddr
10798 ret;
10799diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10800index 2569d0d..637c289 100644
10801--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10802+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10803@@ -23,6 +23,8 @@
10804 *
10805 */
10806
10807+#include <asm/alternative-asm.h>
10808+
10809 #include "glue_helper-asm-avx.S"
10810
10811 .file "cast6-avx-x86_64-asm_64.S"
10812@@ -294,6 +296,7 @@ __cast6_enc_blk8:
10813 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10814 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10815
10816+ pax_force_retaddr 0, 1
10817 ret;
10818
10819 .align 8
10820@@ -340,6 +343,7 @@ __cast6_dec_blk8:
10821 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10822 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10823
10824+ pax_force_retaddr 0, 1
10825 ret;
10826
10827 .align 8
10828@@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10829
10830 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10831
10832+ pax_force_retaddr
10833 ret;
10834
10835 .align 8
10836@@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10837
10838 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10839
10840+ pax_force_retaddr
10841 ret;
10842
10843 .align 8
10844@@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10845
10846 popq %r12;
10847
10848+ pax_force_retaddr
10849 ret;
10850
10851 .align 8
10852@@ -436,4 +443,5 @@ cast6_ctr_8way:
10853
10854 popq %r12;
10855
10856+ pax_force_retaddr
10857 ret;
10858diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10859index 6214a9b..1f4fc9a 100644
10860--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10861+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10862@@ -1,3 +1,5 @@
10863+#include <asm/alternative-asm.h>
10864+
10865 # enter ECRYPT_encrypt_bytes
10866 .text
10867 .p2align 5
10868@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10869 add %r11,%rsp
10870 mov %rdi,%rax
10871 mov %rsi,%rdx
10872+ pax_force_retaddr 0, 1
10873 ret
10874 # bytesatleast65:
10875 ._bytesatleast65:
10876@@ -891,6 +894,7 @@ ECRYPT_keysetup:
10877 add %r11,%rsp
10878 mov %rdi,%rax
10879 mov %rsi,%rdx
10880+ pax_force_retaddr
10881 ret
10882 # enter ECRYPT_ivsetup
10883 .text
10884@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10885 add %r11,%rsp
10886 mov %rdi,%rax
10887 mov %rsi,%rdx
10888+ pax_force_retaddr
10889 ret
10890diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10891index 02b0e9f..cf4cf5c 100644
10892--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10893+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10894@@ -24,6 +24,8 @@
10895 *
10896 */
10897
10898+#include <asm/alternative-asm.h>
10899+
10900 #include "glue_helper-asm-avx.S"
10901
10902 .file "serpent-avx-x86_64-asm_64.S"
10903@@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10904 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10905 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10906
10907+ pax_force_retaddr
10908 ret;
10909
10910 .align 8
10911@@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10912 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10913 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10914
10915+ pax_force_retaddr
10916 ret;
10917
10918 .align 8
10919@@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10920
10921 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10922
10923+ pax_force_retaddr
10924 ret;
10925
10926 .align 8
10927@@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10928
10929 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10930
10931+ pax_force_retaddr
10932 ret;
10933
10934 .align 8
10935@@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10936
10937 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10938
10939+ pax_force_retaddr
10940 ret;
10941
10942 .align 8
10943@@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10944
10945 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10946
10947+ pax_force_retaddr
10948 ret;
10949diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10950index 3ee1ff0..cbc568b 100644
10951--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10952+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10953@@ -24,6 +24,8 @@
10954 *
10955 */
10956
10957+#include <asm/alternative-asm.h>
10958+
10959 .file "serpent-sse2-x86_64-asm_64.S"
10960 .text
10961
10962@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10963 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10964 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10965
10966+ pax_force_retaddr
10967 ret;
10968
10969 __enc_xor8:
10970 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10971 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10972
10973+ pax_force_retaddr
10974 ret;
10975
10976 .align 8
10977@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10978 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10979 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10980
10981+ pax_force_retaddr
10982 ret;
10983diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10984index 49d6987..df66bd4 100644
10985--- a/arch/x86/crypto/sha1_ssse3_asm.S
10986+++ b/arch/x86/crypto/sha1_ssse3_asm.S
10987@@ -28,6 +28,8 @@
10988 * (at your option) any later version.
10989 */
10990
10991+#include <asm/alternative-asm.h>
10992+
10993 #define CTX %rdi // arg1
10994 #define BUF %rsi // arg2
10995 #define CNT %rdx // arg3
10996@@ -104,6 +106,7 @@
10997 pop %r12
10998 pop %rbp
10999 pop %rbx
11000+ pax_force_retaddr 0, 1
11001 ret
11002
11003 .size \name, .-\name
11004diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11005index ebac16b..8092eb9 100644
11006--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11007+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11008@@ -23,6 +23,8 @@
11009 *
11010 */
11011
11012+#include <asm/alternative-asm.h>
11013+
11014 #include "glue_helper-asm-avx.S"
11015
11016 .file "twofish-avx-x86_64-asm_64.S"
11017@@ -283,6 +285,7 @@ __twofish_enc_blk8:
11018 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11019 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11020
11021+ pax_force_retaddr 0, 1
11022 ret;
11023
11024 .align 8
11025@@ -324,6 +327,7 @@ __twofish_dec_blk8:
11026 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11027 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11028
11029+ pax_force_retaddr 0, 1
11030 ret;
11031
11032 .align 8
11033@@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
11034
11035 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11036
11037+ pax_force_retaddr 0, 1
11038 ret;
11039
11040 .align 8
11041@@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
11042
11043 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11044
11045+ pax_force_retaddr 0, 1
11046 ret;
11047
11048 .align 8
11049@@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
11050
11051 popq %r12;
11052
11053+ pax_force_retaddr 0, 1
11054 ret;
11055
11056 .align 8
11057@@ -420,4 +427,5 @@ twofish_ctr_8way:
11058
11059 popq %r12;
11060
11061+ pax_force_retaddr 0, 1
11062 ret;
11063diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11064index 5b012a2..36d5364 100644
11065--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11066+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11067@@ -20,6 +20,8 @@
11068 *
11069 */
11070
11071+#include <asm/alternative-asm.h>
11072+
11073 .file "twofish-x86_64-asm-3way.S"
11074 .text
11075
11076@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
11077 popq %r13;
11078 popq %r14;
11079 popq %r15;
11080+ pax_force_retaddr 0, 1
11081 ret;
11082
11083 __enc_xor3:
11084@@ -271,6 +274,7 @@ __enc_xor3:
11085 popq %r13;
11086 popq %r14;
11087 popq %r15;
11088+ pax_force_retaddr 0, 1
11089 ret;
11090
11091 .global twofish_dec_blk_3way
11092@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11093 popq %r13;
11094 popq %r14;
11095 popq %r15;
11096+ pax_force_retaddr 0, 1
11097 ret;
11098
11099diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11100index 7bcf3fc..f53832f 100644
11101--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11102+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11103@@ -21,6 +21,7 @@
11104 .text
11105
11106 #include <asm/asm-offsets.h>
11107+#include <asm/alternative-asm.h>
11108
11109 #define a_offset 0
11110 #define b_offset 4
11111@@ -268,6 +269,7 @@ twofish_enc_blk:
11112
11113 popq R1
11114 movq $1,%rax
11115+ pax_force_retaddr 0, 1
11116 ret
11117
11118 twofish_dec_blk:
11119@@ -319,4 +321,5 @@ twofish_dec_blk:
11120
11121 popq R1
11122 movq $1,%rax
11123+ pax_force_retaddr 0, 1
11124 ret
11125diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11126index a703af1..f5b9c36 100644
11127--- a/arch/x86/ia32/ia32_aout.c
11128+++ b/arch/x86/ia32/ia32_aout.c
11129@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11130 unsigned long dump_start, dump_size;
11131 struct user32 dump;
11132
11133+ memset(&dump, 0, sizeof(dump));
11134+
11135 fs = get_fs();
11136 set_fs(KERNEL_DS);
11137 has_dumped = 1;
11138diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11139index a1daf4a..f8c4537 100644
11140--- a/arch/x86/ia32/ia32_signal.c
11141+++ b/arch/x86/ia32/ia32_signal.c
11142@@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11143 sp -= frame_size;
11144 /* Align the stack pointer according to the i386 ABI,
11145 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11146- sp = ((sp + 4) & -16ul) - 4;
11147+ sp = ((sp - 12) & -16ul) - 4;
11148 return (void __user *) sp;
11149 }
11150
11151@@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11152 * These are actually not used anymore, but left because some
11153 * gdb versions depend on them as a marker.
11154 */
11155- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11156+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11157 } put_user_catch(err);
11158
11159 if (err)
11160@@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11161 0xb8,
11162 __NR_ia32_rt_sigreturn,
11163 0x80cd,
11164- 0,
11165+ 0
11166 };
11167
11168 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11169@@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11170
11171 if (ka->sa.sa_flags & SA_RESTORER)
11172 restorer = ka->sa.sa_restorer;
11173+ else if (current->mm->context.vdso)
11174+ /* Return stub is in 32bit vsyscall page */
11175+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11176 else
11177- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11178- rt_sigreturn);
11179+ restorer = &frame->retcode;
11180 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11181
11182 /*
11183 * Not actually used anymore, but left because some gdb
11184 * versions need it.
11185 */
11186- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11187+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11188 } put_user_catch(err);
11189
11190 err |= copy_siginfo_to_user32(&frame->info, info);
11191diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11192index 142c4ce..19b683f 100644
11193--- a/arch/x86/ia32/ia32entry.S
11194+++ b/arch/x86/ia32/ia32entry.S
11195@@ -15,8 +15,10 @@
11196 #include <asm/irqflags.h>
11197 #include <asm/asm.h>
11198 #include <asm/smap.h>
11199+#include <asm/pgtable.h>
11200 #include <linux/linkage.h>
11201 #include <linux/err.h>
11202+#include <asm/alternative-asm.h>
11203
11204 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11205 #include <linux/elf-em.h>
11206@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11207 ENDPROC(native_irq_enable_sysexit)
11208 #endif
11209
11210+ .macro pax_enter_kernel_user
11211+ pax_set_fptr_mask
11212+#ifdef CONFIG_PAX_MEMORY_UDEREF
11213+ call pax_enter_kernel_user
11214+#endif
11215+ .endm
11216+
11217+ .macro pax_exit_kernel_user
11218+#ifdef CONFIG_PAX_MEMORY_UDEREF
11219+ call pax_exit_kernel_user
11220+#endif
11221+#ifdef CONFIG_PAX_RANDKSTACK
11222+ pushq %rax
11223+ pushq %r11
11224+ call pax_randomize_kstack
11225+ popq %r11
11226+ popq %rax
11227+#endif
11228+ .endm
11229+
11230+.macro pax_erase_kstack
11231+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11232+ call pax_erase_kstack
11233+#endif
11234+.endm
11235+
11236 /*
11237 * 32bit SYSENTER instruction entry.
11238 *
11239@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11240 CFI_REGISTER rsp,rbp
11241 SWAPGS_UNSAFE_STACK
11242 movq PER_CPU_VAR(kernel_stack), %rsp
11243- addq $(KERNEL_STACK_OFFSET),%rsp
11244- /*
11245- * No need to follow this irqs on/off section: the syscall
11246- * disabled irqs, here we enable it straight after entry:
11247- */
11248- ENABLE_INTERRUPTS(CLBR_NONE)
11249 movl %ebp,%ebp /* zero extension */
11250 pushq_cfi $__USER32_DS
11251 /*CFI_REL_OFFSET ss,0*/
11252@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11253 CFI_REL_OFFSET rsp,0
11254 pushfq_cfi
11255 /*CFI_REL_OFFSET rflags,0*/
11256- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11257- CFI_REGISTER rip,r10
11258+ orl $X86_EFLAGS_IF,(%rsp)
11259+ GET_THREAD_INFO(%r11)
11260+ movl TI_sysenter_return(%r11), %r11d
11261+ CFI_REGISTER rip,r11
11262 pushq_cfi $__USER32_CS
11263 /*CFI_REL_OFFSET cs,0*/
11264 movl %eax, %eax
11265- pushq_cfi %r10
11266+ pushq_cfi %r11
11267 CFI_REL_OFFSET rip,0
11268 pushq_cfi %rax
11269 cld
11270 SAVE_ARGS 0,1,0
11271+ pax_enter_kernel_user
11272+
11273+#ifdef CONFIG_PAX_RANDKSTACK
11274+ pax_erase_kstack
11275+#endif
11276+
11277+ /*
11278+ * No need to follow this irqs on/off section: the syscall
11279+ * disabled irqs, here we enable it straight after entry:
11280+ */
11281+ ENABLE_INTERRUPTS(CLBR_NONE)
11282 /* no need to do an access_ok check here because rbp has been
11283 32bit zero extended */
11284+
11285+#ifdef CONFIG_PAX_MEMORY_UDEREF
11286+ mov $PAX_USER_SHADOW_BASE,%r11
11287+ add %r11,%rbp
11288+#endif
11289+
11290 ASM_STAC
11291 1: movl (%rbp),%ebp
11292 _ASM_EXTABLE(1b,ia32_badarg)
11293 ASM_CLAC
11294- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11295- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11296+ GET_THREAD_INFO(%r11)
11297+ orl $TS_COMPAT,TI_status(%r11)
11298+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11299 CFI_REMEMBER_STATE
11300 jnz sysenter_tracesys
11301 cmpq $(IA32_NR_syscalls-1),%rax
11302@@ -162,12 +204,15 @@ sysenter_do_call:
11303 sysenter_dispatch:
11304 call *ia32_sys_call_table(,%rax,8)
11305 movq %rax,RAX-ARGOFFSET(%rsp)
11306+ GET_THREAD_INFO(%r11)
11307 DISABLE_INTERRUPTS(CLBR_NONE)
11308 TRACE_IRQS_OFF
11309- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11310+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11311 jnz sysexit_audit
11312 sysexit_from_sys_call:
11313- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11314+ pax_exit_kernel_user
11315+ pax_erase_kstack
11316+ andl $~TS_COMPAT,TI_status(%r11)
11317 /* clear IF, that popfq doesn't enable interrupts early */
11318 andl $~0x200,EFLAGS-R11(%rsp)
11319 movl RIP-R11(%rsp),%edx /* User %eip */
11320@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11321 movl %eax,%esi /* 2nd arg: syscall number */
11322 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11323 call __audit_syscall_entry
11324+
11325+ pax_erase_kstack
11326+
11327 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11328 cmpq $(IA32_NR_syscalls-1),%rax
11329 ja ia32_badsys
11330@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11331 .endm
11332
11333 .macro auditsys_exit exit
11334- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11335+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11336 jnz ia32_ret_from_sys_call
11337 TRACE_IRQS_ON
11338 ENABLE_INTERRUPTS(CLBR_NONE)
11339@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11340 1: setbe %al /* 1 if error, 0 if not */
11341 movzbl %al,%edi /* zero-extend that into %edi */
11342 call __audit_syscall_exit
11343+ GET_THREAD_INFO(%r11)
11344 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11345 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11346 DISABLE_INTERRUPTS(CLBR_NONE)
11347 TRACE_IRQS_OFF
11348- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11349+ testl %edi,TI_flags(%r11)
11350 jz \exit
11351 CLEAR_RREGS -ARGOFFSET
11352 jmp int_with_check
11353@@ -237,7 +286,7 @@ sysexit_audit:
11354
11355 sysenter_tracesys:
11356 #ifdef CONFIG_AUDITSYSCALL
11357- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11358+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11359 jz sysenter_auditsys
11360 #endif
11361 SAVE_REST
11362@@ -249,6 +298,9 @@ sysenter_tracesys:
11363 RESTORE_REST
11364 cmpq $(IA32_NR_syscalls-1),%rax
11365 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11366+
11367+ pax_erase_kstack
11368+
11369 jmp sysenter_do_call
11370 CFI_ENDPROC
11371 ENDPROC(ia32_sysenter_target)
11372@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11373 ENTRY(ia32_cstar_target)
11374 CFI_STARTPROC32 simple
11375 CFI_SIGNAL_FRAME
11376- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11377+ CFI_DEF_CFA rsp,0
11378 CFI_REGISTER rip,rcx
11379 /*CFI_REGISTER rflags,r11*/
11380 SWAPGS_UNSAFE_STACK
11381 movl %esp,%r8d
11382 CFI_REGISTER rsp,r8
11383 movq PER_CPU_VAR(kernel_stack),%rsp
11384+ SAVE_ARGS 8*6,0,0
11385+ pax_enter_kernel_user
11386+
11387+#ifdef CONFIG_PAX_RANDKSTACK
11388+ pax_erase_kstack
11389+#endif
11390+
11391 /*
11392 * No need to follow this irqs on/off section: the syscall
11393 * disabled irqs and here we enable it straight after entry:
11394 */
11395 ENABLE_INTERRUPTS(CLBR_NONE)
11396- SAVE_ARGS 8,0,0
11397 movl %eax,%eax /* zero extension */
11398 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11399 movq %rcx,RIP-ARGOFFSET(%rsp)
11400@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11401 /* no need to do an access_ok check here because r8 has been
11402 32bit zero extended */
11403 /* hardware stack frame is complete now */
11404+
11405+#ifdef CONFIG_PAX_MEMORY_UDEREF
11406+ mov $PAX_USER_SHADOW_BASE,%r11
11407+ add %r11,%r8
11408+#endif
11409+
11410 ASM_STAC
11411 1: movl (%r8),%r9d
11412 _ASM_EXTABLE(1b,ia32_badarg)
11413 ASM_CLAC
11414- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11415- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11416+ GET_THREAD_INFO(%r11)
11417+ orl $TS_COMPAT,TI_status(%r11)
11418+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11419 CFI_REMEMBER_STATE
11420 jnz cstar_tracesys
11421 cmpq $IA32_NR_syscalls-1,%rax
11422@@ -319,12 +384,15 @@ cstar_do_call:
11423 cstar_dispatch:
11424 call *ia32_sys_call_table(,%rax,8)
11425 movq %rax,RAX-ARGOFFSET(%rsp)
11426+ GET_THREAD_INFO(%r11)
11427 DISABLE_INTERRUPTS(CLBR_NONE)
11428 TRACE_IRQS_OFF
11429- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11430+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11431 jnz sysretl_audit
11432 sysretl_from_sys_call:
11433- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11434+ pax_exit_kernel_user
11435+ pax_erase_kstack
11436+ andl $~TS_COMPAT,TI_status(%r11)
11437 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11438 movl RIP-ARGOFFSET(%rsp),%ecx
11439 CFI_REGISTER rip,rcx
11440@@ -352,7 +420,7 @@ sysretl_audit:
11441
11442 cstar_tracesys:
11443 #ifdef CONFIG_AUDITSYSCALL
11444- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11445+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11446 jz cstar_auditsys
11447 #endif
11448 xchgl %r9d,%ebp
11449@@ -366,6 +434,9 @@ cstar_tracesys:
11450 xchgl %ebp,%r9d
11451 cmpq $(IA32_NR_syscalls-1),%rax
11452 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11453+
11454+ pax_erase_kstack
11455+
11456 jmp cstar_do_call
11457 END(ia32_cstar_target)
11458
11459@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11460 CFI_REL_OFFSET rip,RIP-RIP
11461 PARAVIRT_ADJUST_EXCEPTION_FRAME
11462 SWAPGS
11463- /*
11464- * No need to follow this irqs on/off section: the syscall
11465- * disabled irqs and here we enable it straight after entry:
11466- */
11467- ENABLE_INTERRUPTS(CLBR_NONE)
11468 movl %eax,%eax
11469 pushq_cfi %rax
11470 cld
11471 /* note the registers are not zero extended to the sf.
11472 this could be a problem. */
11473 SAVE_ARGS 0,1,0
11474- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11475- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11476+ pax_enter_kernel_user
11477+
11478+#ifdef CONFIG_PAX_RANDKSTACK
11479+ pax_erase_kstack
11480+#endif
11481+
11482+ /*
11483+ * No need to follow this irqs on/off section: the syscall
11484+ * disabled irqs and here we enable it straight after entry:
11485+ */
11486+ ENABLE_INTERRUPTS(CLBR_NONE)
11487+ GET_THREAD_INFO(%r11)
11488+ orl $TS_COMPAT,TI_status(%r11)
11489+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11490 jnz ia32_tracesys
11491 cmpq $(IA32_NR_syscalls-1),%rax
11492 ja ia32_badsys
11493@@ -442,6 +520,9 @@ ia32_tracesys:
11494 RESTORE_REST
11495 cmpq $(IA32_NR_syscalls-1),%rax
11496 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11497+
11498+ pax_erase_kstack
11499+
11500 jmp ia32_do_call
11501 END(ia32_syscall)
11502
11503diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11504index d0b689b..34be51d 100644
11505--- a/arch/x86/ia32/sys_ia32.c
11506+++ b/arch/x86/ia32/sys_ia32.c
11507@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11508 */
11509 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11510 {
11511- typeof(ubuf->st_uid) uid = 0;
11512- typeof(ubuf->st_gid) gid = 0;
11513+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11514+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11515 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11516 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11517 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11518@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11519 mm_segment_t old_fs = get_fs();
11520
11521 set_fs(KERNEL_DS);
11522- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11523+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11524 set_fs(old_fs);
11525 if (put_compat_timespec(&t, interval))
11526 return -EFAULT;
11527@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11528 mm_segment_t old_fs = get_fs();
11529
11530 set_fs(KERNEL_DS);
11531- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11532+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11533 set_fs(old_fs);
11534 if (!ret) {
11535 switch (_NSIG_WORDS) {
11536@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11537 if (copy_siginfo_from_user32(&info, uinfo))
11538 return -EFAULT;
11539 set_fs(KERNEL_DS);
11540- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11541+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11542 set_fs(old_fs);
11543 return ret;
11544 }
11545@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11546 return -EFAULT;
11547
11548 set_fs(KERNEL_DS);
11549- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11550+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11551 count);
11552 set_fs(old_fs);
11553
11554diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11555index 372231c..a5aa1a1 100644
11556--- a/arch/x86/include/asm/alternative-asm.h
11557+++ b/arch/x86/include/asm/alternative-asm.h
11558@@ -18,6 +18,45 @@
11559 .endm
11560 #endif
11561
11562+#ifdef KERNEXEC_PLUGIN
11563+ .macro pax_force_retaddr_bts rip=0
11564+ btsq $63,\rip(%rsp)
11565+ .endm
11566+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11567+ .macro pax_force_retaddr rip=0, reload=0
11568+ btsq $63,\rip(%rsp)
11569+ .endm
11570+ .macro pax_force_fptr ptr
11571+ btsq $63,\ptr
11572+ .endm
11573+ .macro pax_set_fptr_mask
11574+ .endm
11575+#endif
11576+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11577+ .macro pax_force_retaddr rip=0, reload=0
11578+ .if \reload
11579+ pax_set_fptr_mask
11580+ .endif
11581+ orq %r10,\rip(%rsp)
11582+ .endm
11583+ .macro pax_force_fptr ptr
11584+ orq %r10,\ptr
11585+ .endm
11586+ .macro pax_set_fptr_mask
11587+ movabs $0x8000000000000000,%r10
11588+ .endm
11589+#endif
11590+#else
11591+ .macro pax_force_retaddr rip=0, reload=0
11592+ .endm
11593+ .macro pax_force_fptr ptr
11594+ .endm
11595+ .macro pax_force_retaddr_bts rip=0
11596+ .endm
11597+ .macro pax_set_fptr_mask
11598+ .endm
11599+#endif
11600+
11601 .macro altinstruction_entry orig alt feature orig_len alt_len
11602 .long \orig - .
11603 .long \alt - .
11604diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11605index 58ed6d9..f1cbe58 100644
11606--- a/arch/x86/include/asm/alternative.h
11607+++ b/arch/x86/include/asm/alternative.h
11608@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11609 ".pushsection .discard,\"aw\",@progbits\n" \
11610 DISCARD_ENTRY(1) \
11611 ".popsection\n" \
11612- ".pushsection .altinstr_replacement, \"ax\"\n" \
11613+ ".pushsection .altinstr_replacement, \"a\"\n" \
11614 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11615 ".popsection"
11616
11617@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11618 DISCARD_ENTRY(1) \
11619 DISCARD_ENTRY(2) \
11620 ".popsection\n" \
11621- ".pushsection .altinstr_replacement, \"ax\"\n" \
11622+ ".pushsection .altinstr_replacement, \"a\"\n" \
11623 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11624 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11625 ".popsection"
11626diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11627index 3388034..050f0b9 100644
11628--- a/arch/x86/include/asm/apic.h
11629+++ b/arch/x86/include/asm/apic.h
11630@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11631
11632 #ifdef CONFIG_X86_LOCAL_APIC
11633
11634-extern unsigned int apic_verbosity;
11635+extern int apic_verbosity;
11636 extern int local_apic_timer_c2_ok;
11637
11638 extern int disable_apic;
11639diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11640index 20370c6..a2eb9b0 100644
11641--- a/arch/x86/include/asm/apm.h
11642+++ b/arch/x86/include/asm/apm.h
11643@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11644 __asm__ __volatile__(APM_DO_ZERO_SEGS
11645 "pushl %%edi\n\t"
11646 "pushl %%ebp\n\t"
11647- "lcall *%%cs:apm_bios_entry\n\t"
11648+ "lcall *%%ss:apm_bios_entry\n\t"
11649 "setc %%al\n\t"
11650 "popl %%ebp\n\t"
11651 "popl %%edi\n\t"
11652@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11653 __asm__ __volatile__(APM_DO_ZERO_SEGS
11654 "pushl %%edi\n\t"
11655 "pushl %%ebp\n\t"
11656- "lcall *%%cs:apm_bios_entry\n\t"
11657+ "lcall *%%ss:apm_bios_entry\n\t"
11658 "setc %%bl\n\t"
11659 "popl %%ebp\n\t"
11660 "popl %%edi\n\t"
11661diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11662index 722aa3b..3a0bb27 100644
11663--- a/arch/x86/include/asm/atomic.h
11664+++ b/arch/x86/include/asm/atomic.h
11665@@ -22,7 +22,18 @@
11666 */
11667 static inline int atomic_read(const atomic_t *v)
11668 {
11669- return (*(volatile int *)&(v)->counter);
11670+ return (*(volatile const int *)&(v)->counter);
11671+}
11672+
11673+/**
11674+ * atomic_read_unchecked - read atomic variable
11675+ * @v: pointer of type atomic_unchecked_t
11676+ *
11677+ * Atomically reads the value of @v.
11678+ */
11679+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11680+{
11681+ return (*(volatile const int *)&(v)->counter);
11682 }
11683
11684 /**
11685@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11686 }
11687
11688 /**
11689+ * atomic_set_unchecked - set atomic variable
11690+ * @v: pointer of type atomic_unchecked_t
11691+ * @i: required value
11692+ *
11693+ * Atomically sets the value of @v to @i.
11694+ */
11695+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11696+{
11697+ v->counter = i;
11698+}
11699+
11700+/**
11701 * atomic_add - add integer to atomic variable
11702 * @i: integer value to add
11703 * @v: pointer of type atomic_t
11704@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11705 */
11706 static inline void atomic_add(int i, atomic_t *v)
11707 {
11708- asm volatile(LOCK_PREFIX "addl %1,%0"
11709+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11710+
11711+#ifdef CONFIG_PAX_REFCOUNT
11712+ "jno 0f\n"
11713+ LOCK_PREFIX "subl %1,%0\n"
11714+ "int $4\n0:\n"
11715+ _ASM_EXTABLE(0b, 0b)
11716+#endif
11717+
11718+ : "+m" (v->counter)
11719+ : "ir" (i));
11720+}
11721+
11722+/**
11723+ * atomic_add_unchecked - add integer to atomic variable
11724+ * @i: integer value to add
11725+ * @v: pointer of type atomic_unchecked_t
11726+ *
11727+ * Atomically adds @i to @v.
11728+ */
11729+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11730+{
11731+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
11732 : "+m" (v->counter)
11733 : "ir" (i));
11734 }
11735@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11736 */
11737 static inline void atomic_sub(int i, atomic_t *v)
11738 {
11739- asm volatile(LOCK_PREFIX "subl %1,%0"
11740+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11741+
11742+#ifdef CONFIG_PAX_REFCOUNT
11743+ "jno 0f\n"
11744+ LOCK_PREFIX "addl %1,%0\n"
11745+ "int $4\n0:\n"
11746+ _ASM_EXTABLE(0b, 0b)
11747+#endif
11748+
11749+ : "+m" (v->counter)
11750+ : "ir" (i));
11751+}
11752+
11753+/**
11754+ * atomic_sub_unchecked - subtract integer from atomic variable
11755+ * @i: integer value to subtract
11756+ * @v: pointer of type atomic_unchecked_t
11757+ *
11758+ * Atomically subtracts @i from @v.
11759+ */
11760+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11761+{
11762+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
11763 : "+m" (v->counter)
11764 : "ir" (i));
11765 }
11766@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11767 {
11768 unsigned char c;
11769
11770- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11771+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
11772+
11773+#ifdef CONFIG_PAX_REFCOUNT
11774+ "jno 0f\n"
11775+ LOCK_PREFIX "addl %2,%0\n"
11776+ "int $4\n0:\n"
11777+ _ASM_EXTABLE(0b, 0b)
11778+#endif
11779+
11780+ "sete %1\n"
11781 : "+m" (v->counter), "=qm" (c)
11782 : "ir" (i) : "memory");
11783 return c;
11784@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11785 */
11786 static inline void atomic_inc(atomic_t *v)
11787 {
11788- asm volatile(LOCK_PREFIX "incl %0"
11789+ asm volatile(LOCK_PREFIX "incl %0\n"
11790+
11791+#ifdef CONFIG_PAX_REFCOUNT
11792+ "jno 0f\n"
11793+ LOCK_PREFIX "decl %0\n"
11794+ "int $4\n0:\n"
11795+ _ASM_EXTABLE(0b, 0b)
11796+#endif
11797+
11798+ : "+m" (v->counter));
11799+}
11800+
11801+/**
11802+ * atomic_inc_unchecked - increment atomic variable
11803+ * @v: pointer of type atomic_unchecked_t
11804+ *
11805+ * Atomically increments @v by 1.
11806+ */
11807+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11808+{
11809+ asm volatile(LOCK_PREFIX "incl %0\n"
11810 : "+m" (v->counter));
11811 }
11812
11813@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11814 */
11815 static inline void atomic_dec(atomic_t *v)
11816 {
11817- asm volatile(LOCK_PREFIX "decl %0"
11818+ asm volatile(LOCK_PREFIX "decl %0\n"
11819+
11820+#ifdef CONFIG_PAX_REFCOUNT
11821+ "jno 0f\n"
11822+ LOCK_PREFIX "incl %0\n"
11823+ "int $4\n0:\n"
11824+ _ASM_EXTABLE(0b, 0b)
11825+#endif
11826+
11827+ : "+m" (v->counter));
11828+}
11829+
11830+/**
11831+ * atomic_dec_unchecked - decrement atomic variable
11832+ * @v: pointer of type atomic_unchecked_t
11833+ *
11834+ * Atomically decrements @v by 1.
11835+ */
11836+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11837+{
11838+ asm volatile(LOCK_PREFIX "decl %0\n"
11839 : "+m" (v->counter));
11840 }
11841
11842@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11843 {
11844 unsigned char c;
11845
11846- asm volatile(LOCK_PREFIX "decl %0; sete %1"
11847+ asm volatile(LOCK_PREFIX "decl %0\n"
11848+
11849+#ifdef CONFIG_PAX_REFCOUNT
11850+ "jno 0f\n"
11851+ LOCK_PREFIX "incl %0\n"
11852+ "int $4\n0:\n"
11853+ _ASM_EXTABLE(0b, 0b)
11854+#endif
11855+
11856+ "sete %1\n"
11857 : "+m" (v->counter), "=qm" (c)
11858 : : "memory");
11859 return c != 0;
11860@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11861 {
11862 unsigned char c;
11863
11864- asm volatile(LOCK_PREFIX "incl %0; sete %1"
11865+ asm volatile(LOCK_PREFIX "incl %0\n"
11866+
11867+#ifdef CONFIG_PAX_REFCOUNT
11868+ "jno 0f\n"
11869+ LOCK_PREFIX "decl %0\n"
11870+ "int $4\n0:\n"
11871+ _ASM_EXTABLE(0b, 0b)
11872+#endif
11873+
11874+ "sete %1\n"
11875+ : "+m" (v->counter), "=qm" (c)
11876+ : : "memory");
11877+ return c != 0;
11878+}
11879+
11880+/**
11881+ * atomic_inc_and_test_unchecked - increment and test
11882+ * @v: pointer of type atomic_unchecked_t
11883+ *
11884+ * Atomically increments @v by 1
11885+ * and returns true if the result is zero, or false for all
11886+ * other cases.
11887+ */
11888+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11889+{
11890+ unsigned char c;
11891+
11892+ asm volatile(LOCK_PREFIX "incl %0\n"
11893+ "sete %1\n"
11894 : "+m" (v->counter), "=qm" (c)
11895 : : "memory");
11896 return c != 0;
11897@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11898 {
11899 unsigned char c;
11900
11901- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11902+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
11903+
11904+#ifdef CONFIG_PAX_REFCOUNT
11905+ "jno 0f\n"
11906+ LOCK_PREFIX "subl %2,%0\n"
11907+ "int $4\n0:\n"
11908+ _ASM_EXTABLE(0b, 0b)
11909+#endif
11910+
11911+ "sets %1\n"
11912 : "+m" (v->counter), "=qm" (c)
11913 : "ir" (i) : "memory");
11914 return c;
11915@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11916 */
11917 static inline int atomic_add_return(int i, atomic_t *v)
11918 {
11919+ return i + xadd_check_overflow(&v->counter, i);
11920+}
11921+
11922+/**
11923+ * atomic_add_return_unchecked - add integer and return
11924+ * @i: integer value to add
11925+ * @v: pointer of type atomic_unchecked_t
11926+ *
11927+ * Atomically adds @i to @v and returns @i + @v
11928+ */
11929+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11930+{
11931 return i + xadd(&v->counter, i);
11932 }
11933
11934@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11935 }
11936
11937 #define atomic_inc_return(v) (atomic_add_return(1, v))
11938+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11939+{
11940+ return atomic_add_return_unchecked(1, v);
11941+}
11942 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11943
11944 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11945@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11946 return cmpxchg(&v->counter, old, new);
11947 }
11948
11949+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11950+{
11951+ return cmpxchg(&v->counter, old, new);
11952+}
11953+
11954 static inline int atomic_xchg(atomic_t *v, int new)
11955 {
11956 return xchg(&v->counter, new);
11957 }
11958
11959+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11960+{
11961+ return xchg(&v->counter, new);
11962+}
11963+
11964 /**
11965 * __atomic_add_unless - add unless the number is already a given value
11966 * @v: pointer of type atomic_t
11967@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11968 */
11969 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11970 {
11971- int c, old;
11972+ int c, old, new;
11973 c = atomic_read(v);
11974 for (;;) {
11975- if (unlikely(c == (u)))
11976+ if (unlikely(c == u))
11977 break;
11978- old = atomic_cmpxchg((v), c, c + (a));
11979+
11980+ asm volatile("addl %2,%0\n"
11981+
11982+#ifdef CONFIG_PAX_REFCOUNT
11983+ "jno 0f\n"
11984+ "subl %2,%0\n"
11985+ "int $4\n0:\n"
11986+ _ASM_EXTABLE(0b, 0b)
11987+#endif
11988+
11989+ : "=r" (new)
11990+ : "0" (c), "ir" (a));
11991+
11992+ old = atomic_cmpxchg(v, c, new);
11993 if (likely(old == c))
11994 break;
11995 c = old;
11996@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11997 }
11998
11999 /**
12000+ * atomic_inc_not_zero_hint - increment if not null
12001+ * @v: pointer of type atomic_t
12002+ * @hint: probable value of the atomic before the increment
12003+ *
12004+ * This version of atomic_inc_not_zero() gives a hint of probable
12005+ * value of the atomic. This helps processor to not read the memory
12006+ * before doing the atomic read/modify/write cycle, lowering
12007+ * number of bus transactions on some arches.
12008+ *
12009+ * Returns: 0 if increment was not done, 1 otherwise.
12010+ */
12011+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12012+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12013+{
12014+ int val, c = hint, new;
12015+
12016+ /* sanity test, should be removed by compiler if hint is a constant */
12017+ if (!hint)
12018+ return __atomic_add_unless(v, 1, 0);
12019+
12020+ do {
12021+ asm volatile("incl %0\n"
12022+
12023+#ifdef CONFIG_PAX_REFCOUNT
12024+ "jno 0f\n"
12025+ "decl %0\n"
12026+ "int $4\n0:\n"
12027+ _ASM_EXTABLE(0b, 0b)
12028+#endif
12029+
12030+ : "=r" (new)
12031+ : "0" (c));
12032+
12033+ val = atomic_cmpxchg(v, c, new);
12034+ if (val == c)
12035+ return 1;
12036+ c = val;
12037+ } while (c);
12038+
12039+ return 0;
12040+}
12041+
12042+/**
12043 * atomic_inc_short - increment of a short integer
12044 * @v: pointer to type int
12045 *
12046@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12047 #endif
12048
12049 /* These are x86-specific, used by some header files */
12050-#define atomic_clear_mask(mask, addr) \
12051- asm volatile(LOCK_PREFIX "andl %0,%1" \
12052- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12053+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12054+{
12055+ asm volatile(LOCK_PREFIX "andl %1,%0"
12056+ : "+m" (v->counter)
12057+ : "r" (~(mask))
12058+ : "memory");
12059+}
12060
12061-#define atomic_set_mask(mask, addr) \
12062- asm volatile(LOCK_PREFIX "orl %0,%1" \
12063- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12064- : "memory")
12065+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12066+{
12067+ asm volatile(LOCK_PREFIX "andl %1,%0"
12068+ : "+m" (v->counter)
12069+ : "r" (~(mask))
12070+ : "memory");
12071+}
12072+
12073+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12074+{
12075+ asm volatile(LOCK_PREFIX "orl %1,%0"
12076+ : "+m" (v->counter)
12077+ : "r" (mask)
12078+ : "memory");
12079+}
12080+
12081+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12082+{
12083+ asm volatile(LOCK_PREFIX "orl %1,%0"
12084+ : "+m" (v->counter)
12085+ : "r" (mask)
12086+ : "memory");
12087+}
12088
12089 /* Atomic operations are already serializing on x86 */
12090 #define smp_mb__before_atomic_dec() barrier()
12091diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12092index b154de7..aadebd8 100644
12093--- a/arch/x86/include/asm/atomic64_32.h
12094+++ b/arch/x86/include/asm/atomic64_32.h
12095@@ -12,6 +12,14 @@ typedef struct {
12096 u64 __aligned(8) counter;
12097 } atomic64_t;
12098
12099+#ifdef CONFIG_PAX_REFCOUNT
12100+typedef struct {
12101+ u64 __aligned(8) counter;
12102+} atomic64_unchecked_t;
12103+#else
12104+typedef atomic64_t atomic64_unchecked_t;
12105+#endif
12106+
12107 #define ATOMIC64_INIT(val) { (val) }
12108
12109 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12110@@ -37,21 +45,31 @@ typedef struct {
12111 ATOMIC64_DECL_ONE(sym##_386)
12112
12113 ATOMIC64_DECL_ONE(add_386);
12114+ATOMIC64_DECL_ONE(add_unchecked_386);
12115 ATOMIC64_DECL_ONE(sub_386);
12116+ATOMIC64_DECL_ONE(sub_unchecked_386);
12117 ATOMIC64_DECL_ONE(inc_386);
12118+ATOMIC64_DECL_ONE(inc_unchecked_386);
12119 ATOMIC64_DECL_ONE(dec_386);
12120+ATOMIC64_DECL_ONE(dec_unchecked_386);
12121 #endif
12122
12123 #define alternative_atomic64(f, out, in...) \
12124 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12125
12126 ATOMIC64_DECL(read);
12127+ATOMIC64_DECL(read_unchecked);
12128 ATOMIC64_DECL(set);
12129+ATOMIC64_DECL(set_unchecked);
12130 ATOMIC64_DECL(xchg);
12131 ATOMIC64_DECL(add_return);
12132+ATOMIC64_DECL(add_return_unchecked);
12133 ATOMIC64_DECL(sub_return);
12134+ATOMIC64_DECL(sub_return_unchecked);
12135 ATOMIC64_DECL(inc_return);
12136+ATOMIC64_DECL(inc_return_unchecked);
12137 ATOMIC64_DECL(dec_return);
12138+ATOMIC64_DECL(dec_return_unchecked);
12139 ATOMIC64_DECL(dec_if_positive);
12140 ATOMIC64_DECL(inc_not_zero);
12141 ATOMIC64_DECL(add_unless);
12142@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12143 }
12144
12145 /**
12146+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12147+ * @p: pointer to type atomic64_unchecked_t
12148+ * @o: expected value
12149+ * @n: new value
12150+ *
12151+ * Atomically sets @v to @n if it was equal to @o and returns
12152+ * the old value.
12153+ */
12154+
12155+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12156+{
12157+ return cmpxchg64(&v->counter, o, n);
12158+}
12159+
12160+/**
12161 * atomic64_xchg - xchg atomic64 variable
12162 * @v: pointer to type atomic64_t
12163 * @n: value to assign
12164@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12165 }
12166
12167 /**
12168+ * atomic64_set_unchecked - set atomic64 variable
12169+ * @v: pointer to type atomic64_unchecked_t
12170+ * @n: value to assign
12171+ *
12172+ * Atomically sets the value of @v to @n.
12173+ */
12174+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12175+{
12176+ unsigned high = (unsigned)(i >> 32);
12177+ unsigned low = (unsigned)i;
12178+ alternative_atomic64(set, /* no output */,
12179+ "S" (v), "b" (low), "c" (high)
12180+ : "eax", "edx", "memory");
12181+}
12182+
12183+/**
12184 * atomic64_read - read atomic64 variable
12185 * @v: pointer to type atomic64_t
12186 *
12187@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12188 }
12189
12190 /**
12191+ * atomic64_read_unchecked - read atomic64 variable
12192+ * @v: pointer to type atomic64_unchecked_t
12193+ *
12194+ * Atomically reads the value of @v and returns it.
12195+ */
12196+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12197+{
12198+ long long r;
12199+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12200+ return r;
12201+ }
12202+
12203+/**
12204 * atomic64_add_return - add and return
12205 * @i: integer value to add
12206 * @v: pointer to type atomic64_t
12207@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12208 return i;
12209 }
12210
12211+/**
12212+ * atomic64_add_return_unchecked - add and return
12213+ * @i: integer value to add
12214+ * @v: pointer to type atomic64_unchecked_t
12215+ *
12216+ * Atomically adds @i to @v and returns @i + *@v
12217+ */
12218+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12219+{
12220+ alternative_atomic64(add_return_unchecked,
12221+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12222+ ASM_NO_INPUT_CLOBBER("memory"));
12223+ return i;
12224+}
12225+
12226 /*
12227 * Other variants with different arithmetic operators:
12228 */
12229@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12230 return a;
12231 }
12232
12233+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12234+{
12235+ long long a;
12236+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12237+ "S" (v) : "memory", "ecx");
12238+ return a;
12239+}
12240+
12241 static inline long long atomic64_dec_return(atomic64_t *v)
12242 {
12243 long long a;
12244@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12245 }
12246
12247 /**
12248+ * atomic64_add_unchecked - add integer to atomic64 variable
12249+ * @i: integer value to add
12250+ * @v: pointer to type atomic64_unchecked_t
12251+ *
12252+ * Atomically adds @i to @v.
12253+ */
12254+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12255+{
12256+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12257+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12258+ ASM_NO_INPUT_CLOBBER("memory"));
12259+ return i;
12260+}
12261+
12262+/**
12263 * atomic64_sub - subtract the atomic64 variable
12264 * @i: integer value to subtract
12265 * @v: pointer to type atomic64_t
12266diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12267index 0e1cbfc..5623683 100644
12268--- a/arch/x86/include/asm/atomic64_64.h
12269+++ b/arch/x86/include/asm/atomic64_64.h
12270@@ -18,7 +18,19 @@
12271 */
12272 static inline long atomic64_read(const atomic64_t *v)
12273 {
12274- return (*(volatile long *)&(v)->counter);
12275+ return (*(volatile const long *)&(v)->counter);
12276+}
12277+
12278+/**
12279+ * atomic64_read_unchecked - read atomic64 variable
12280+ * @v: pointer of type atomic64_unchecked_t
12281+ *
12282+ * Atomically reads the value of @v.
12283+ * Doesn't imply a read memory barrier.
12284+ */
12285+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12286+{
12287+ return (*(volatile const long *)&(v)->counter);
12288 }
12289
12290 /**
12291@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12292 }
12293
12294 /**
12295+ * atomic64_set_unchecked - set atomic64 variable
12296+ * @v: pointer to type atomic64_unchecked_t
12297+ * @i: required value
12298+ *
12299+ * Atomically sets the value of @v to @i.
12300+ */
12301+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12302+{
12303+ v->counter = i;
12304+}
12305+
12306+/**
12307 * atomic64_add - add integer to atomic64 variable
12308 * @i: integer value to add
12309 * @v: pointer to type atomic64_t
12310@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12311 */
12312 static inline void atomic64_add(long i, atomic64_t *v)
12313 {
12314+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12315+
12316+#ifdef CONFIG_PAX_REFCOUNT
12317+ "jno 0f\n"
12318+ LOCK_PREFIX "subq %1,%0\n"
12319+ "int $4\n0:\n"
12320+ _ASM_EXTABLE(0b, 0b)
12321+#endif
12322+
12323+ : "=m" (v->counter)
12324+ : "er" (i), "m" (v->counter));
12325+}
12326+
12327+/**
12328+ * atomic64_add_unchecked - add integer to atomic64 variable
12329+ * @i: integer value to add
12330+ * @v: pointer to type atomic64_unchecked_t
12331+ *
12332+ * Atomically adds @i to @v.
12333+ */
12334+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12335+{
12336 asm volatile(LOCK_PREFIX "addq %1,%0"
12337 : "=m" (v->counter)
12338 : "er" (i), "m" (v->counter));
12339@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12340 */
12341 static inline void atomic64_sub(long i, atomic64_t *v)
12342 {
12343- asm volatile(LOCK_PREFIX "subq %1,%0"
12344+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12345+
12346+#ifdef CONFIG_PAX_REFCOUNT
12347+ "jno 0f\n"
12348+ LOCK_PREFIX "addq %1,%0\n"
12349+ "int $4\n0:\n"
12350+ _ASM_EXTABLE(0b, 0b)
12351+#endif
12352+
12353+ : "=m" (v->counter)
12354+ : "er" (i), "m" (v->counter));
12355+}
12356+
12357+/**
12358+ * atomic64_sub_unchecked - subtract the atomic64 variable
12359+ * @i: integer value to subtract
12360+ * @v: pointer to type atomic64_unchecked_t
12361+ *
12362+ * Atomically subtracts @i from @v.
12363+ */
12364+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12365+{
12366+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12367 : "=m" (v->counter)
12368 : "er" (i), "m" (v->counter));
12369 }
12370@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12371 {
12372 unsigned char c;
12373
12374- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12375+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12376+
12377+#ifdef CONFIG_PAX_REFCOUNT
12378+ "jno 0f\n"
12379+ LOCK_PREFIX "addq %2,%0\n"
12380+ "int $4\n0:\n"
12381+ _ASM_EXTABLE(0b, 0b)
12382+#endif
12383+
12384+ "sete %1\n"
12385 : "=m" (v->counter), "=qm" (c)
12386 : "er" (i), "m" (v->counter) : "memory");
12387 return c;
12388@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12389 */
12390 static inline void atomic64_inc(atomic64_t *v)
12391 {
12392+ asm volatile(LOCK_PREFIX "incq %0\n"
12393+
12394+#ifdef CONFIG_PAX_REFCOUNT
12395+ "jno 0f\n"
12396+ LOCK_PREFIX "decq %0\n"
12397+ "int $4\n0:\n"
12398+ _ASM_EXTABLE(0b, 0b)
12399+#endif
12400+
12401+ : "=m" (v->counter)
12402+ : "m" (v->counter));
12403+}
12404+
12405+/**
12406+ * atomic64_inc_unchecked - increment atomic64 variable
12407+ * @v: pointer to type atomic64_unchecked_t
12408+ *
12409+ * Atomically increments @v by 1.
12410+ */
12411+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12412+{
12413 asm volatile(LOCK_PREFIX "incq %0"
12414 : "=m" (v->counter)
12415 : "m" (v->counter));
12416@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12417 */
12418 static inline void atomic64_dec(atomic64_t *v)
12419 {
12420- asm volatile(LOCK_PREFIX "decq %0"
12421+ asm volatile(LOCK_PREFIX "decq %0\n"
12422+
12423+#ifdef CONFIG_PAX_REFCOUNT
12424+ "jno 0f\n"
12425+ LOCK_PREFIX "incq %0\n"
12426+ "int $4\n0:\n"
12427+ _ASM_EXTABLE(0b, 0b)
12428+#endif
12429+
12430+ : "=m" (v->counter)
12431+ : "m" (v->counter));
12432+}
12433+
12434+/**
12435+ * atomic64_dec_unchecked - decrement atomic64 variable
12436+ * @v: pointer to type atomic64_t
12437+ *
12438+ * Atomically decrements @v by 1.
12439+ */
12440+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12441+{
12442+ asm volatile(LOCK_PREFIX "decq %0\n"
12443 : "=m" (v->counter)
12444 : "m" (v->counter));
12445 }
12446@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12447 {
12448 unsigned char c;
12449
12450- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12451+ asm volatile(LOCK_PREFIX "decq %0\n"
12452+
12453+#ifdef CONFIG_PAX_REFCOUNT
12454+ "jno 0f\n"
12455+ LOCK_PREFIX "incq %0\n"
12456+ "int $4\n0:\n"
12457+ _ASM_EXTABLE(0b, 0b)
12458+#endif
12459+
12460+ "sete %1\n"
12461 : "=m" (v->counter), "=qm" (c)
12462 : "m" (v->counter) : "memory");
12463 return c != 0;
12464@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12465 {
12466 unsigned char c;
12467
12468- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12469+ asm volatile(LOCK_PREFIX "incq %0\n"
12470+
12471+#ifdef CONFIG_PAX_REFCOUNT
12472+ "jno 0f\n"
12473+ LOCK_PREFIX "decq %0\n"
12474+ "int $4\n0:\n"
12475+ _ASM_EXTABLE(0b, 0b)
12476+#endif
12477+
12478+ "sete %1\n"
12479 : "=m" (v->counter), "=qm" (c)
12480 : "m" (v->counter) : "memory");
12481 return c != 0;
12482@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12483 {
12484 unsigned char c;
12485
12486- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12487+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12488+
12489+#ifdef CONFIG_PAX_REFCOUNT
12490+ "jno 0f\n"
12491+ LOCK_PREFIX "subq %2,%0\n"
12492+ "int $4\n0:\n"
12493+ _ASM_EXTABLE(0b, 0b)
12494+#endif
12495+
12496+ "sets %1\n"
12497 : "=m" (v->counter), "=qm" (c)
12498 : "er" (i), "m" (v->counter) : "memory");
12499 return c;
12500@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12501 */
12502 static inline long atomic64_add_return(long i, atomic64_t *v)
12503 {
12504+ return i + xadd_check_overflow(&v->counter, i);
12505+}
12506+
12507+/**
12508+ * atomic64_add_return_unchecked - add and return
12509+ * @i: integer value to add
12510+ * @v: pointer to type atomic64_unchecked_t
12511+ *
12512+ * Atomically adds @i to @v and returns @i + @v
12513+ */
12514+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12515+{
12516 return i + xadd(&v->counter, i);
12517 }
12518
12519@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12520 }
12521
12522 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12523+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12524+{
12525+ return atomic64_add_return_unchecked(1, v);
12526+}
12527 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12528
12529 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12530@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12531 return cmpxchg(&v->counter, old, new);
12532 }
12533
12534+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12535+{
12536+ return cmpxchg(&v->counter, old, new);
12537+}
12538+
12539 static inline long atomic64_xchg(atomic64_t *v, long new)
12540 {
12541 return xchg(&v->counter, new);
12542@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12543 */
12544 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12545 {
12546- long c, old;
12547+ long c, old, new;
12548 c = atomic64_read(v);
12549 for (;;) {
12550- if (unlikely(c == (u)))
12551+ if (unlikely(c == u))
12552 break;
12553- old = atomic64_cmpxchg((v), c, c + (a));
12554+
12555+ asm volatile("add %2,%0\n"
12556+
12557+#ifdef CONFIG_PAX_REFCOUNT
12558+ "jno 0f\n"
12559+ "sub %2,%0\n"
12560+ "int $4\n0:\n"
12561+ _ASM_EXTABLE(0b, 0b)
12562+#endif
12563+
12564+ : "=r" (new)
12565+ : "0" (c), "ir" (a));
12566+
12567+ old = atomic64_cmpxchg(v, c, new);
12568 if (likely(old == c))
12569 break;
12570 c = old;
12571 }
12572- return c != (u);
12573+ return c != u;
12574 }
12575
12576 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12577diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12578index 6dfd019..0c6699f 100644
12579--- a/arch/x86/include/asm/bitops.h
12580+++ b/arch/x86/include/asm/bitops.h
12581@@ -40,7 +40,7 @@
12582 * a mask operation on a byte.
12583 */
12584 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12585-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12586+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12587 #define CONST_MASK(nr) (1 << ((nr) & 7))
12588
12589 /**
12590diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12591index 4fa687a..60f2d39 100644
12592--- a/arch/x86/include/asm/boot.h
12593+++ b/arch/x86/include/asm/boot.h
12594@@ -6,10 +6,15 @@
12595 #include <uapi/asm/boot.h>
12596
12597 /* Physical address where kernel should be loaded. */
12598-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12599+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12600 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12601 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12602
12603+#ifndef __ASSEMBLY__
12604+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12605+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12606+#endif
12607+
12608 /* Minimum kernel alignment, as a power of two */
12609 #ifdef CONFIG_X86_64
12610 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12611diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12612index 48f99f1..d78ebf9 100644
12613--- a/arch/x86/include/asm/cache.h
12614+++ b/arch/x86/include/asm/cache.h
12615@@ -5,12 +5,13 @@
12616
12617 /* L1 cache line size */
12618 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12619-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12620+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12621
12622 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12623+#define __read_only __attribute__((__section__(".data..read_only")))
12624
12625 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12626-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12627+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12628
12629 #ifdef CONFIG_X86_VSMP
12630 #ifdef CONFIG_SMP
12631diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12632index 9863ee3..4a1f8e1 100644
12633--- a/arch/x86/include/asm/cacheflush.h
12634+++ b/arch/x86/include/asm/cacheflush.h
12635@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12636 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12637
12638 if (pg_flags == _PGMT_DEFAULT)
12639- return -1;
12640+ return ~0UL;
12641 else if (pg_flags == _PGMT_WC)
12642 return _PAGE_CACHE_WC;
12643 else if (pg_flags == _PGMT_UC_MINUS)
12644diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12645index 46fc474..b02b0f9 100644
12646--- a/arch/x86/include/asm/checksum_32.h
12647+++ b/arch/x86/include/asm/checksum_32.h
12648@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12649 int len, __wsum sum,
12650 int *src_err_ptr, int *dst_err_ptr);
12651
12652+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12653+ int len, __wsum sum,
12654+ int *src_err_ptr, int *dst_err_ptr);
12655+
12656+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12657+ int len, __wsum sum,
12658+ int *src_err_ptr, int *dst_err_ptr);
12659+
12660 /*
12661 * Note: when you get a NULL pointer exception here this means someone
12662 * passed in an incorrect kernel address to one of these functions.
12663@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12664 int *err_ptr)
12665 {
12666 might_sleep();
12667- return csum_partial_copy_generic((__force void *)src, dst,
12668+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
12669 len, sum, err_ptr, NULL);
12670 }
12671
12672@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12673 {
12674 might_sleep();
12675 if (access_ok(VERIFY_WRITE, dst, len))
12676- return csum_partial_copy_generic(src, (__force void *)dst,
12677+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12678 len, sum, NULL, err_ptr);
12679
12680 if (len)
12681diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12682index 8d871ea..c1a0dc9 100644
12683--- a/arch/x86/include/asm/cmpxchg.h
12684+++ b/arch/x86/include/asm/cmpxchg.h
12685@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12686 __compiletime_error("Bad argument size for cmpxchg");
12687 extern void __xadd_wrong_size(void)
12688 __compiletime_error("Bad argument size for xadd");
12689+extern void __xadd_check_overflow_wrong_size(void)
12690+ __compiletime_error("Bad argument size for xadd_check_overflow");
12691 extern void __add_wrong_size(void)
12692 __compiletime_error("Bad argument size for add");
12693+extern void __add_check_overflow_wrong_size(void)
12694+ __compiletime_error("Bad argument size for add_check_overflow");
12695
12696 /*
12697 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12698@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12699 __ret; \
12700 })
12701
12702+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12703+ ({ \
12704+ __typeof__ (*(ptr)) __ret = (arg); \
12705+ switch (sizeof(*(ptr))) { \
12706+ case __X86_CASE_L: \
12707+ asm volatile (lock #op "l %0, %1\n" \
12708+ "jno 0f\n" \
12709+ "mov %0,%1\n" \
12710+ "int $4\n0:\n" \
12711+ _ASM_EXTABLE(0b, 0b) \
12712+ : "+r" (__ret), "+m" (*(ptr)) \
12713+ : : "memory", "cc"); \
12714+ break; \
12715+ case __X86_CASE_Q: \
12716+ asm volatile (lock #op "q %q0, %1\n" \
12717+ "jno 0f\n" \
12718+ "mov %0,%1\n" \
12719+ "int $4\n0:\n" \
12720+ _ASM_EXTABLE(0b, 0b) \
12721+ : "+r" (__ret), "+m" (*(ptr)) \
12722+ : : "memory", "cc"); \
12723+ break; \
12724+ default: \
12725+ __ ## op ## _check_overflow_wrong_size(); \
12726+ } \
12727+ __ret; \
12728+ })
12729+
12730 /*
12731 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12732 * Since this is generally used to protect other memory information, we
12733@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12734 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12735 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12736
12737+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12738+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12739+
12740 #define __add(ptr, inc, lock) \
12741 ({ \
12742 __typeof__ (*(ptr)) __ret = (inc); \
12743diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12744index 2d9075e..b75a844 100644
12745--- a/arch/x86/include/asm/cpufeature.h
12746+++ b/arch/x86/include/asm/cpufeature.h
12747@@ -206,7 +206,7 @@
12748 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12749 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12750 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12751-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12752+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12753 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12754 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12755 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12756@@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12757 ".section .discard,\"aw\",@progbits\n"
12758 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12759 ".previous\n"
12760- ".section .altinstr_replacement,\"ax\"\n"
12761+ ".section .altinstr_replacement,\"a\"\n"
12762 "3: movb $1,%0\n"
12763 "4:\n"
12764 ".previous\n"
12765diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12766index 8bf1c06..f723dfd 100644
12767--- a/arch/x86/include/asm/desc.h
12768+++ b/arch/x86/include/asm/desc.h
12769@@ -4,6 +4,7 @@
12770 #include <asm/desc_defs.h>
12771 #include <asm/ldt.h>
12772 #include <asm/mmu.h>
12773+#include <asm/pgtable.h>
12774
12775 #include <linux/smp.h>
12776 #include <linux/percpu.h>
12777@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12778
12779 desc->type = (info->read_exec_only ^ 1) << 1;
12780 desc->type |= info->contents << 2;
12781+ desc->type |= info->seg_not_present ^ 1;
12782
12783 desc->s = 1;
12784 desc->dpl = 0x3;
12785@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12786 }
12787
12788 extern struct desc_ptr idt_descr;
12789-extern gate_desc idt_table[];
12790 extern struct desc_ptr nmi_idt_descr;
12791-extern gate_desc nmi_idt_table[];
12792-
12793-struct gdt_page {
12794- struct desc_struct gdt[GDT_ENTRIES];
12795-} __attribute__((aligned(PAGE_SIZE)));
12796-
12797-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12798+extern gate_desc idt_table[256];
12799+extern gate_desc nmi_idt_table[256];
12800
12801+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12802 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12803 {
12804- return per_cpu(gdt_page, cpu).gdt;
12805+ return cpu_gdt_table[cpu];
12806 }
12807
12808 #ifdef CONFIG_X86_64
12809@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12810 unsigned long base, unsigned dpl, unsigned flags,
12811 unsigned short seg)
12812 {
12813- gate->a = (seg << 16) | (base & 0xffff);
12814- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12815+ gate->gate.offset_low = base;
12816+ gate->gate.seg = seg;
12817+ gate->gate.reserved = 0;
12818+ gate->gate.type = type;
12819+ gate->gate.s = 0;
12820+ gate->gate.dpl = dpl;
12821+ gate->gate.p = 1;
12822+ gate->gate.offset_high = base >> 16;
12823 }
12824
12825 #endif
12826@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12827
12828 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12829 {
12830+ pax_open_kernel();
12831 memcpy(&idt[entry], gate, sizeof(*gate));
12832+ pax_close_kernel();
12833 }
12834
12835 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12836 {
12837+ pax_open_kernel();
12838 memcpy(&ldt[entry], desc, 8);
12839+ pax_close_kernel();
12840 }
12841
12842 static inline void
12843@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12844 default: size = sizeof(*gdt); break;
12845 }
12846
12847+ pax_open_kernel();
12848 memcpy(&gdt[entry], desc, size);
12849+ pax_close_kernel();
12850 }
12851
12852 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12853@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12854
12855 static inline void native_load_tr_desc(void)
12856 {
12857+ pax_open_kernel();
12858 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12859+ pax_close_kernel();
12860 }
12861
12862 static inline void native_load_gdt(const struct desc_ptr *dtr)
12863@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12864 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12865 unsigned int i;
12866
12867+ pax_open_kernel();
12868 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12869 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12870+ pax_close_kernel();
12871 }
12872
12873 #define _LDT_empty(info) \
12874@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12875 }
12876
12877 #ifdef CONFIG_X86_64
12878-static inline void set_nmi_gate(int gate, void *addr)
12879+static inline void set_nmi_gate(int gate, const void *addr)
12880 {
12881 gate_desc s;
12882
12883@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12884 }
12885 #endif
12886
12887-static inline void _set_gate(int gate, unsigned type, void *addr,
12888+static inline void _set_gate(int gate, unsigned type, const void *addr,
12889 unsigned dpl, unsigned ist, unsigned seg)
12890 {
12891 gate_desc s;
12892@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12893 * Pentium F0 0F bugfix can have resulted in the mapped
12894 * IDT being write-protected.
12895 */
12896-static inline void set_intr_gate(unsigned int n, void *addr)
12897+static inline void set_intr_gate(unsigned int n, const void *addr)
12898 {
12899 BUG_ON((unsigned)n > 0xFF);
12900 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12901@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12902 /*
12903 * This routine sets up an interrupt gate at directory privilege level 3.
12904 */
12905-static inline void set_system_intr_gate(unsigned int n, void *addr)
12906+static inline void set_system_intr_gate(unsigned int n, const void *addr)
12907 {
12908 BUG_ON((unsigned)n > 0xFF);
12909 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12910 }
12911
12912-static inline void set_system_trap_gate(unsigned int n, void *addr)
12913+static inline void set_system_trap_gate(unsigned int n, const void *addr)
12914 {
12915 BUG_ON((unsigned)n > 0xFF);
12916 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12917 }
12918
12919-static inline void set_trap_gate(unsigned int n, void *addr)
12920+static inline void set_trap_gate(unsigned int n, const void *addr)
12921 {
12922 BUG_ON((unsigned)n > 0xFF);
12923 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12924@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12925 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12926 {
12927 BUG_ON((unsigned)n > 0xFF);
12928- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12929+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12930 }
12931
12932-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12933+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12934 {
12935 BUG_ON((unsigned)n > 0xFF);
12936 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12937 }
12938
12939-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12940+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12941 {
12942 BUG_ON((unsigned)n > 0xFF);
12943 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12944 }
12945
12946+#ifdef CONFIG_X86_32
12947+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12948+{
12949+ struct desc_struct d;
12950+
12951+ if (likely(limit))
12952+ limit = (limit - 1UL) >> PAGE_SHIFT;
12953+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
12954+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12955+}
12956+#endif
12957+
12958 #endif /* _ASM_X86_DESC_H */
12959diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12960index 278441f..b95a174 100644
12961--- a/arch/x86/include/asm/desc_defs.h
12962+++ b/arch/x86/include/asm/desc_defs.h
12963@@ -31,6 +31,12 @@ struct desc_struct {
12964 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12965 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12966 };
12967+ struct {
12968+ u16 offset_low;
12969+ u16 seg;
12970+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12971+ unsigned offset_high: 16;
12972+ } gate;
12973 };
12974 } __attribute__((packed));
12975
12976diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12977index 9c999c1..3860cb8 100644
12978--- a/arch/x86/include/asm/elf.h
12979+++ b/arch/x86/include/asm/elf.h
12980@@ -243,7 +243,25 @@ extern int force_personality32;
12981 the loader. We need to make sure that it is out of the way of the program
12982 that it will "exec", and that there is sufficient room for the brk. */
12983
12984+#ifdef CONFIG_PAX_SEGMEXEC
12985+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12986+#else
12987 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12988+#endif
12989+
12990+#ifdef CONFIG_PAX_ASLR
12991+#ifdef CONFIG_X86_32
12992+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12993+
12994+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12995+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12996+#else
12997+#define PAX_ELF_ET_DYN_BASE 0x400000UL
12998+
12999+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13000+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13001+#endif
13002+#endif
13003
13004 /* This yields a mask that user programs can use to figure out what
13005 instruction set this CPU supports. This could be done in user space,
13006@@ -296,16 +314,12 @@ do { \
13007
13008 #define ARCH_DLINFO \
13009 do { \
13010- if (vdso_enabled) \
13011- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13012- (unsigned long)current->mm->context.vdso); \
13013+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13014 } while (0)
13015
13016 #define ARCH_DLINFO_X32 \
13017 do { \
13018- if (vdso_enabled) \
13019- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13020- (unsigned long)current->mm->context.vdso); \
13021+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13022 } while (0)
13023
13024 #define AT_SYSINFO 32
13025@@ -320,7 +334,7 @@ else \
13026
13027 #endif /* !CONFIG_X86_32 */
13028
13029-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13030+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13031
13032 #define VDSO_ENTRY \
13033 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13034@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13035 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13036 #define compat_arch_setup_additional_pages syscall32_setup_pages
13037
13038-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13039-#define arch_randomize_brk arch_randomize_brk
13040-
13041 /*
13042 * True on X86_32 or when emulating IA32 on X86_64
13043 */
13044diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13045index 75ce3f4..882e801 100644
13046--- a/arch/x86/include/asm/emergency-restart.h
13047+++ b/arch/x86/include/asm/emergency-restart.h
13048@@ -13,6 +13,6 @@ enum reboot_type {
13049
13050 extern enum reboot_type reboot_type;
13051
13052-extern void machine_emergency_restart(void);
13053+extern void machine_emergency_restart(void) __noreturn;
13054
13055 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13056diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13057index 41ab26e..a88c9e6 100644
13058--- a/arch/x86/include/asm/fpu-internal.h
13059+++ b/arch/x86/include/asm/fpu-internal.h
13060@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13061 ({ \
13062 int err; \
13063 asm volatile(ASM_STAC "\n" \
13064- "1:" #insn "\n\t" \
13065+ "1:" \
13066+ __copyuser_seg \
13067+ #insn "\n\t" \
13068 "2: " ASM_CLAC "\n" \
13069 ".section .fixup,\"ax\"\n" \
13070 "3: movl $-1,%[err]\n" \
13071@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13072 "emms\n\t" /* clear stack tags */
13073 "fildl %P[addr]", /* set F?P to defined value */
13074 X86_FEATURE_FXSAVE_LEAK,
13075- [addr] "m" (tsk->thread.fpu.has_fpu));
13076+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13077
13078 return fpu_restore_checking(&tsk->thread.fpu);
13079 }
13080diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13081index be27ba1..8f13ff9 100644
13082--- a/arch/x86/include/asm/futex.h
13083+++ b/arch/x86/include/asm/futex.h
13084@@ -12,6 +12,7 @@
13085 #include <asm/smap.h>
13086
13087 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13088+ typecheck(u32 __user *, uaddr); \
13089 asm volatile("\t" ASM_STAC "\n" \
13090 "1:\t" insn "\n" \
13091 "2:\t" ASM_CLAC "\n" \
13092@@ -20,15 +21,16 @@
13093 "\tjmp\t2b\n" \
13094 "\t.previous\n" \
13095 _ASM_EXTABLE(1b, 3b) \
13096- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13097+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13098 : "i" (-EFAULT), "0" (oparg), "1" (0))
13099
13100 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13101+ typecheck(u32 __user *, uaddr); \
13102 asm volatile("\t" ASM_STAC "\n" \
13103 "1:\tmovl %2, %0\n" \
13104 "\tmovl\t%0, %3\n" \
13105 "\t" insn "\n" \
13106- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13107+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13108 "\tjnz\t1b\n" \
13109 "3:\t" ASM_CLAC "\n" \
13110 "\t.section .fixup,\"ax\"\n" \
13111@@ -38,7 +40,7 @@
13112 _ASM_EXTABLE(1b, 4b) \
13113 _ASM_EXTABLE(2b, 4b) \
13114 : "=&a" (oldval), "=&r" (ret), \
13115- "+m" (*uaddr), "=&r" (tem) \
13116+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13117 : "r" (oparg), "i" (-EFAULT), "1" (0))
13118
13119 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13120@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13121
13122 switch (op) {
13123 case FUTEX_OP_SET:
13124- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13125+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13126 break;
13127 case FUTEX_OP_ADD:
13128- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13129+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13130 uaddr, oparg);
13131 break;
13132 case FUTEX_OP_OR:
13133@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13134 return -EFAULT;
13135
13136 asm volatile("\t" ASM_STAC "\n"
13137- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13138+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13139 "2:\t" ASM_CLAC "\n"
13140 "\t.section .fixup, \"ax\"\n"
13141 "3:\tmov %3, %0\n"
13142 "\tjmp 2b\n"
13143 "\t.previous\n"
13144 _ASM_EXTABLE(1b, 3b)
13145- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13146+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13147 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13148 : "memory"
13149 );
13150diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13151index eb92a6e..b98b2f4 100644
13152--- a/arch/x86/include/asm/hw_irq.h
13153+++ b/arch/x86/include/asm/hw_irq.h
13154@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13155 extern void enable_IO_APIC(void);
13156
13157 /* Statistics */
13158-extern atomic_t irq_err_count;
13159-extern atomic_t irq_mis_count;
13160+extern atomic_unchecked_t irq_err_count;
13161+extern atomic_unchecked_t irq_mis_count;
13162
13163 /* EISA */
13164 extern void eisa_set_level_irq(unsigned int irq);
13165diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13166index a203659..9889f1c 100644
13167--- a/arch/x86/include/asm/i8259.h
13168+++ b/arch/x86/include/asm/i8259.h
13169@@ -62,7 +62,7 @@ struct legacy_pic {
13170 void (*init)(int auto_eoi);
13171 int (*irq_pending)(unsigned int irq);
13172 void (*make_irq)(unsigned int irq);
13173-};
13174+} __do_const;
13175
13176 extern struct legacy_pic *legacy_pic;
13177 extern struct legacy_pic null_legacy_pic;
13178diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13179index d8e8eef..15b1179 100644
13180--- a/arch/x86/include/asm/io.h
13181+++ b/arch/x86/include/asm/io.h
13182@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13183 return ioremap_nocache(offset, size);
13184 }
13185
13186-extern void iounmap(volatile void __iomem *addr);
13187+extern void iounmap(const volatile void __iomem *addr);
13188
13189 extern void set_iounmap_nonlazy(void);
13190
13191@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13192
13193 #include <linux/vmalloc.h>
13194
13195+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13196+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13197+{
13198+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13199+}
13200+
13201+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13202+{
13203+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13204+}
13205+
13206 /*
13207 * Convert a virtual cached pointer to an uncached pointer
13208 */
13209diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13210index bba3cf8..06bc8da 100644
13211--- a/arch/x86/include/asm/irqflags.h
13212+++ b/arch/x86/include/asm/irqflags.h
13213@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13214 sti; \
13215 sysexit
13216
13217+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13218+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13219+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13220+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13221+
13222 #else
13223 #define INTERRUPT_RETURN iret
13224 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13225diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13226index d3ddd17..c9fb0cc 100644
13227--- a/arch/x86/include/asm/kprobes.h
13228+++ b/arch/x86/include/asm/kprobes.h
13229@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13230 #define RELATIVEJUMP_SIZE 5
13231 #define RELATIVECALL_OPCODE 0xe8
13232 #define RELATIVE_ADDR_SIZE 4
13233-#define MAX_STACK_SIZE 64
13234-#define MIN_STACK_SIZE(ADDR) \
13235- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13236- THREAD_SIZE - (unsigned long)(ADDR))) \
13237- ? (MAX_STACK_SIZE) \
13238- : (((unsigned long)current_thread_info()) + \
13239- THREAD_SIZE - (unsigned long)(ADDR)))
13240+#define MAX_STACK_SIZE 64UL
13241+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13242
13243 #define flush_insn_slot(p) do { } while (0)
13244
13245diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13246index 2d89e39..baee879 100644
13247--- a/arch/x86/include/asm/local.h
13248+++ b/arch/x86/include/asm/local.h
13249@@ -10,33 +10,97 @@ typedef struct {
13250 atomic_long_t a;
13251 } local_t;
13252
13253+typedef struct {
13254+ atomic_long_unchecked_t a;
13255+} local_unchecked_t;
13256+
13257 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13258
13259 #define local_read(l) atomic_long_read(&(l)->a)
13260+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13261 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13262+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13263
13264 static inline void local_inc(local_t *l)
13265 {
13266- asm volatile(_ASM_INC "%0"
13267+ asm volatile(_ASM_INC "%0\n"
13268+
13269+#ifdef CONFIG_PAX_REFCOUNT
13270+ "jno 0f\n"
13271+ _ASM_DEC "%0\n"
13272+ "int $4\n0:\n"
13273+ _ASM_EXTABLE(0b, 0b)
13274+#endif
13275+
13276+ : "+m" (l->a.counter));
13277+}
13278+
13279+static inline void local_inc_unchecked(local_unchecked_t *l)
13280+{
13281+ asm volatile(_ASM_INC "%0\n"
13282 : "+m" (l->a.counter));
13283 }
13284
13285 static inline void local_dec(local_t *l)
13286 {
13287- asm volatile(_ASM_DEC "%0"
13288+ asm volatile(_ASM_DEC "%0\n"
13289+
13290+#ifdef CONFIG_PAX_REFCOUNT
13291+ "jno 0f\n"
13292+ _ASM_INC "%0\n"
13293+ "int $4\n0:\n"
13294+ _ASM_EXTABLE(0b, 0b)
13295+#endif
13296+
13297+ : "+m" (l->a.counter));
13298+}
13299+
13300+static inline void local_dec_unchecked(local_unchecked_t *l)
13301+{
13302+ asm volatile(_ASM_DEC "%0\n"
13303 : "+m" (l->a.counter));
13304 }
13305
13306 static inline void local_add(long i, local_t *l)
13307 {
13308- asm volatile(_ASM_ADD "%1,%0"
13309+ asm volatile(_ASM_ADD "%1,%0\n"
13310+
13311+#ifdef CONFIG_PAX_REFCOUNT
13312+ "jno 0f\n"
13313+ _ASM_SUB "%1,%0\n"
13314+ "int $4\n0:\n"
13315+ _ASM_EXTABLE(0b, 0b)
13316+#endif
13317+
13318+ : "+m" (l->a.counter)
13319+ : "ir" (i));
13320+}
13321+
13322+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13323+{
13324+ asm volatile(_ASM_ADD "%1,%0\n"
13325 : "+m" (l->a.counter)
13326 : "ir" (i));
13327 }
13328
13329 static inline void local_sub(long i, local_t *l)
13330 {
13331- asm volatile(_ASM_SUB "%1,%0"
13332+ asm volatile(_ASM_SUB "%1,%0\n"
13333+
13334+#ifdef CONFIG_PAX_REFCOUNT
13335+ "jno 0f\n"
13336+ _ASM_ADD "%1,%0\n"
13337+ "int $4\n0:\n"
13338+ _ASM_EXTABLE(0b, 0b)
13339+#endif
13340+
13341+ : "+m" (l->a.counter)
13342+ : "ir" (i));
13343+}
13344+
13345+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13346+{
13347+ asm volatile(_ASM_SUB "%1,%0\n"
13348 : "+m" (l->a.counter)
13349 : "ir" (i));
13350 }
13351@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13352 {
13353 unsigned char c;
13354
13355- asm volatile(_ASM_SUB "%2,%0; sete %1"
13356+ asm volatile(_ASM_SUB "%2,%0\n"
13357+
13358+#ifdef CONFIG_PAX_REFCOUNT
13359+ "jno 0f\n"
13360+ _ASM_ADD "%2,%0\n"
13361+ "int $4\n0:\n"
13362+ _ASM_EXTABLE(0b, 0b)
13363+#endif
13364+
13365+ "sete %1\n"
13366 : "+m" (l->a.counter), "=qm" (c)
13367 : "ir" (i) : "memory");
13368 return c;
13369@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13370 {
13371 unsigned char c;
13372
13373- asm volatile(_ASM_DEC "%0; sete %1"
13374+ asm volatile(_ASM_DEC "%0\n"
13375+
13376+#ifdef CONFIG_PAX_REFCOUNT
13377+ "jno 0f\n"
13378+ _ASM_INC "%0\n"
13379+ "int $4\n0:\n"
13380+ _ASM_EXTABLE(0b, 0b)
13381+#endif
13382+
13383+ "sete %1\n"
13384 : "+m" (l->a.counter), "=qm" (c)
13385 : : "memory");
13386 return c != 0;
13387@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13388 {
13389 unsigned char c;
13390
13391- asm volatile(_ASM_INC "%0; sete %1"
13392+ asm volatile(_ASM_INC "%0\n"
13393+
13394+#ifdef CONFIG_PAX_REFCOUNT
13395+ "jno 0f\n"
13396+ _ASM_DEC "%0\n"
13397+ "int $4\n0:\n"
13398+ _ASM_EXTABLE(0b, 0b)
13399+#endif
13400+
13401+ "sete %1\n"
13402 : "+m" (l->a.counter), "=qm" (c)
13403 : : "memory");
13404 return c != 0;
13405@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13406 {
13407 unsigned char c;
13408
13409- asm volatile(_ASM_ADD "%2,%0; sets %1"
13410+ asm volatile(_ASM_ADD "%2,%0\n"
13411+
13412+#ifdef CONFIG_PAX_REFCOUNT
13413+ "jno 0f\n"
13414+ _ASM_SUB "%2,%0\n"
13415+ "int $4\n0:\n"
13416+ _ASM_EXTABLE(0b, 0b)
13417+#endif
13418+
13419+ "sets %1\n"
13420 : "+m" (l->a.counter), "=qm" (c)
13421 : "ir" (i) : "memory");
13422 return c;
13423@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13424 static inline long local_add_return(long i, local_t *l)
13425 {
13426 long __i = i;
13427+ asm volatile(_ASM_XADD "%0, %1\n"
13428+
13429+#ifdef CONFIG_PAX_REFCOUNT
13430+ "jno 0f\n"
13431+ _ASM_MOV "%0,%1\n"
13432+ "int $4\n0:\n"
13433+ _ASM_EXTABLE(0b, 0b)
13434+#endif
13435+
13436+ : "+r" (i), "+m" (l->a.counter)
13437+ : : "memory");
13438+ return i + __i;
13439+}
13440+
13441+/**
13442+ * local_add_return_unchecked - add and return
13443+ * @i: integer value to add
13444+ * @l: pointer to type local_unchecked_t
13445+ *
13446+ * Atomically adds @i to @l and returns @i + @l
13447+ */
13448+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13449+{
13450+ long __i = i;
13451 asm volatile(_ASM_XADD "%0, %1;"
13452 : "+r" (i), "+m" (l->a.counter)
13453 : : "memory");
13454@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13455
13456 #define local_cmpxchg(l, o, n) \
13457 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13458+#define local_cmpxchg_unchecked(l, o, n) \
13459+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13460 /* Always has a lock prefix */
13461 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13462
13463diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13464new file mode 100644
13465index 0000000..2bfd3ba
13466--- /dev/null
13467+++ b/arch/x86/include/asm/mman.h
13468@@ -0,0 +1,15 @@
13469+#ifndef _X86_MMAN_H
13470+#define _X86_MMAN_H
13471+
13472+#include <uapi/asm/mman.h>
13473+
13474+#ifdef __KERNEL__
13475+#ifndef __ASSEMBLY__
13476+#ifdef CONFIG_X86_32
13477+#define arch_mmap_check i386_mmap_check
13478+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13479+#endif
13480+#endif
13481+#endif
13482+
13483+#endif /* X86_MMAN_H */
13484diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13485index 5f55e69..e20bfb1 100644
13486--- a/arch/x86/include/asm/mmu.h
13487+++ b/arch/x86/include/asm/mmu.h
13488@@ -9,7 +9,7 @@
13489 * we put the segment information here.
13490 */
13491 typedef struct {
13492- void *ldt;
13493+ struct desc_struct *ldt;
13494 int size;
13495
13496 #ifdef CONFIG_X86_64
13497@@ -18,7 +18,19 @@ typedef struct {
13498 #endif
13499
13500 struct mutex lock;
13501- void *vdso;
13502+ unsigned long vdso;
13503+
13504+#ifdef CONFIG_X86_32
13505+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13506+ unsigned long user_cs_base;
13507+ unsigned long user_cs_limit;
13508+
13509+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13510+ cpumask_t cpu_user_cs_mask;
13511+#endif
13512+
13513+#endif
13514+#endif
13515 } mm_context_t;
13516
13517 #ifdef CONFIG_SMP
13518diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13519index cdbf367..adb37ac 100644
13520--- a/arch/x86/include/asm/mmu_context.h
13521+++ b/arch/x86/include/asm/mmu_context.h
13522@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13523
13524 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13525 {
13526+
13527+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13528+ unsigned int i;
13529+ pgd_t *pgd;
13530+
13531+ pax_open_kernel();
13532+ pgd = get_cpu_pgd(smp_processor_id());
13533+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13534+ set_pgd_batched(pgd+i, native_make_pgd(0));
13535+ pax_close_kernel();
13536+#endif
13537+
13538 #ifdef CONFIG_SMP
13539 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13540 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13541@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13542 struct task_struct *tsk)
13543 {
13544 unsigned cpu = smp_processor_id();
13545+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13546+ int tlbstate = TLBSTATE_OK;
13547+#endif
13548
13549 if (likely(prev != next)) {
13550 #ifdef CONFIG_SMP
13551+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13552+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13553+#endif
13554 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13555 this_cpu_write(cpu_tlbstate.active_mm, next);
13556 #endif
13557 cpumask_set_cpu(cpu, mm_cpumask(next));
13558
13559 /* Re-load page tables */
13560+#ifdef CONFIG_PAX_PER_CPU_PGD
13561+ pax_open_kernel();
13562+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13563+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13564+ pax_close_kernel();
13565+ load_cr3(get_cpu_pgd(cpu));
13566+#else
13567 load_cr3(next->pgd);
13568+#endif
13569
13570 /* stop flush ipis for the previous mm */
13571 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13572@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13573 */
13574 if (unlikely(prev->context.ldt != next->context.ldt))
13575 load_LDT_nolock(&next->context);
13576- }
13577+
13578+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13579+ if (!(__supported_pte_mask & _PAGE_NX)) {
13580+ smp_mb__before_clear_bit();
13581+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13582+ smp_mb__after_clear_bit();
13583+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13584+ }
13585+#endif
13586+
13587+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13588+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13589+ prev->context.user_cs_limit != next->context.user_cs_limit))
13590+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13591 #ifdef CONFIG_SMP
13592+ else if (unlikely(tlbstate != TLBSTATE_OK))
13593+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13594+#endif
13595+#endif
13596+
13597+ }
13598 else {
13599+
13600+#ifdef CONFIG_PAX_PER_CPU_PGD
13601+ pax_open_kernel();
13602+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13603+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13604+ pax_close_kernel();
13605+ load_cr3(get_cpu_pgd(cpu));
13606+#endif
13607+
13608+#ifdef CONFIG_SMP
13609 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13610 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13611
13612@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13613 * tlb flush IPI delivery. We must reload CR3
13614 * to make sure to use no freed page tables.
13615 */
13616+
13617+#ifndef CONFIG_PAX_PER_CPU_PGD
13618 load_cr3(next->pgd);
13619+#endif
13620+
13621 load_LDT_nolock(&next->context);
13622+
13623+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13624+ if (!(__supported_pte_mask & _PAGE_NX))
13625+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13626+#endif
13627+
13628+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13629+#ifdef CONFIG_PAX_PAGEEXEC
13630+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13631+#endif
13632+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13633+#endif
13634+
13635 }
13636+#endif
13637 }
13638-#endif
13639 }
13640
13641 #define activate_mm(prev, next) \
13642diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13643index e3b7819..b257c64 100644
13644--- a/arch/x86/include/asm/module.h
13645+++ b/arch/x86/include/asm/module.h
13646@@ -5,6 +5,7 @@
13647
13648 #ifdef CONFIG_X86_64
13649 /* X86_64 does not define MODULE_PROC_FAMILY */
13650+#define MODULE_PROC_FAMILY ""
13651 #elif defined CONFIG_M486
13652 #define MODULE_PROC_FAMILY "486 "
13653 #elif defined CONFIG_M586
13654@@ -57,8 +58,20 @@
13655 #error unknown processor family
13656 #endif
13657
13658-#ifdef CONFIG_X86_32
13659-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13660+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13661+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13662+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13663+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13664+#else
13665+#define MODULE_PAX_KERNEXEC ""
13666 #endif
13667
13668+#ifdef CONFIG_PAX_MEMORY_UDEREF
13669+#define MODULE_PAX_UDEREF "UDEREF "
13670+#else
13671+#define MODULE_PAX_UDEREF ""
13672+#endif
13673+
13674+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13675+
13676 #endif /* _ASM_X86_MODULE_H */
13677diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
13678index c0fa356..07a498a 100644
13679--- a/arch/x86/include/asm/nmi.h
13680+++ b/arch/x86/include/asm/nmi.h
13681@@ -42,11 +42,11 @@ struct nmiaction {
13682 nmi_handler_t handler;
13683 unsigned long flags;
13684 const char *name;
13685-};
13686+} __do_const;
13687
13688 #define register_nmi_handler(t, fn, fg, n, init...) \
13689 ({ \
13690- static struct nmiaction init fn##_na = { \
13691+ static const struct nmiaction init fn##_na = { \
13692 .handler = (fn), \
13693 .name = (n), \
13694 .flags = (fg), \
13695@@ -54,7 +54,7 @@ struct nmiaction {
13696 __register_nmi_handler((t), &fn##_na); \
13697 })
13698
13699-int __register_nmi_handler(unsigned int, struct nmiaction *);
13700+int __register_nmi_handler(unsigned int, const struct nmiaction *);
13701
13702 void unregister_nmi_handler(unsigned int, const char *);
13703
13704diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13705index 320f7bb..e89f8f8 100644
13706--- a/arch/x86/include/asm/page_64_types.h
13707+++ b/arch/x86/include/asm/page_64_types.h
13708@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13709
13710 /* duplicated to the one in bootmem.h */
13711 extern unsigned long max_pfn;
13712-extern unsigned long phys_base;
13713+extern const unsigned long phys_base;
13714
13715 extern unsigned long __phys_addr(unsigned long);
13716 #define __phys_reloc_hide(x) (x)
13717diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13718index 5edd174..9cf5821 100644
13719--- a/arch/x86/include/asm/paravirt.h
13720+++ b/arch/x86/include/asm/paravirt.h
13721@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13722 val);
13723 }
13724
13725+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13726+{
13727+ pgdval_t val = native_pgd_val(pgd);
13728+
13729+ if (sizeof(pgdval_t) > sizeof(long))
13730+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13731+ val, (u64)val >> 32);
13732+ else
13733+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13734+ val);
13735+}
13736+
13737 static inline void pgd_clear(pgd_t *pgdp)
13738 {
13739 set_pgd(pgdp, __pgd(0));
13740@@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13741 pv_mmu_ops.set_fixmap(idx, phys, flags);
13742 }
13743
13744+#ifdef CONFIG_PAX_KERNEXEC
13745+static inline unsigned long pax_open_kernel(void)
13746+{
13747+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13748+}
13749+
13750+static inline unsigned long pax_close_kernel(void)
13751+{
13752+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13753+}
13754+#else
13755+static inline unsigned long pax_open_kernel(void) { return 0; }
13756+static inline unsigned long pax_close_kernel(void) { return 0; }
13757+#endif
13758+
13759 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13760
13761 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13762@@ -927,7 +954,7 @@ extern void default_banner(void);
13763
13764 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13765 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13766-#define PARA_INDIRECT(addr) *%cs:addr
13767+#define PARA_INDIRECT(addr) *%ss:addr
13768 #endif
13769
13770 #define INTERRUPT_RETURN \
13771@@ -1002,6 +1029,21 @@ extern void default_banner(void);
13772 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13773 CLBR_NONE, \
13774 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13775+
13776+#define GET_CR0_INTO_RDI \
13777+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13778+ mov %rax,%rdi
13779+
13780+#define SET_RDI_INTO_CR0 \
13781+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13782+
13783+#define GET_CR3_INTO_RDI \
13784+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13785+ mov %rax,%rdi
13786+
13787+#define SET_RDI_INTO_CR3 \
13788+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13789+
13790 #endif /* CONFIG_X86_32 */
13791
13792 #endif /* __ASSEMBLY__ */
13793diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13794index 142236e..5446ffbc 100644
13795--- a/arch/x86/include/asm/paravirt_types.h
13796+++ b/arch/x86/include/asm/paravirt_types.h
13797@@ -84,7 +84,7 @@ struct pv_init_ops {
13798 */
13799 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13800 unsigned long addr, unsigned len);
13801-};
13802+} __no_const;
13803
13804
13805 struct pv_lazy_ops {
13806@@ -97,7 +97,7 @@ struct pv_time_ops {
13807 unsigned long long (*sched_clock)(void);
13808 unsigned long long (*steal_clock)(int cpu);
13809 unsigned long (*get_tsc_khz)(void);
13810-};
13811+} __no_const;
13812
13813 struct pv_cpu_ops {
13814 /* hooks for various privileged instructions */
13815@@ -191,7 +191,7 @@ struct pv_cpu_ops {
13816
13817 void (*start_context_switch)(struct task_struct *prev);
13818 void (*end_context_switch)(struct task_struct *next);
13819-};
13820+} __no_const;
13821
13822 struct pv_irq_ops {
13823 /*
13824@@ -222,7 +222,7 @@ struct pv_apic_ops {
13825 unsigned long start_eip,
13826 unsigned long start_esp);
13827 #endif
13828-};
13829+} __no_const;
13830
13831 struct pv_mmu_ops {
13832 unsigned long (*read_cr2)(void);
13833@@ -312,6 +312,7 @@ struct pv_mmu_ops {
13834 struct paravirt_callee_save make_pud;
13835
13836 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13837+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13838 #endif /* PAGETABLE_LEVELS == 4 */
13839 #endif /* PAGETABLE_LEVELS >= 3 */
13840
13841@@ -323,6 +324,12 @@ struct pv_mmu_ops {
13842 an mfn. We can tell which is which from the index. */
13843 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13844 phys_addr_t phys, pgprot_t flags);
13845+
13846+#ifdef CONFIG_PAX_KERNEXEC
13847+ unsigned long (*pax_open_kernel)(void);
13848+ unsigned long (*pax_close_kernel)(void);
13849+#endif
13850+
13851 };
13852
13853 struct arch_spinlock;
13854@@ -333,7 +340,7 @@ struct pv_lock_ops {
13855 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13856 int (*spin_trylock)(struct arch_spinlock *lock);
13857 void (*spin_unlock)(struct arch_spinlock *lock);
13858-};
13859+} __no_const;
13860
13861 /* This contains all the paravirt structures: we get a convenient
13862 * number for each function using the offset which we use to indicate
13863diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13864index b4389a4..7024269 100644
13865--- a/arch/x86/include/asm/pgalloc.h
13866+++ b/arch/x86/include/asm/pgalloc.h
13867@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13868 pmd_t *pmd, pte_t *pte)
13869 {
13870 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13871+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13872+}
13873+
13874+static inline void pmd_populate_user(struct mm_struct *mm,
13875+ pmd_t *pmd, pte_t *pte)
13876+{
13877+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13878 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13879 }
13880
13881@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13882
13883 #ifdef CONFIG_X86_PAE
13884 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13885+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13886+{
13887+ pud_populate(mm, pudp, pmd);
13888+}
13889 #else /* !CONFIG_X86_PAE */
13890 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13891 {
13892 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13893 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13894 }
13895+
13896+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13897+{
13898+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13899+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13900+}
13901 #endif /* CONFIG_X86_PAE */
13902
13903 #if PAGETABLE_LEVELS > 3
13904@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13905 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13906 }
13907
13908+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13909+{
13910+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13911+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13912+}
13913+
13914 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13915 {
13916 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13917diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13918index f2b489c..4f7e2e5 100644
13919--- a/arch/x86/include/asm/pgtable-2level.h
13920+++ b/arch/x86/include/asm/pgtable-2level.h
13921@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13922
13923 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13924 {
13925+ pax_open_kernel();
13926 *pmdp = pmd;
13927+ pax_close_kernel();
13928 }
13929
13930 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13931diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13932index 4cc9f2b..5fd9226 100644
13933--- a/arch/x86/include/asm/pgtable-3level.h
13934+++ b/arch/x86/include/asm/pgtable-3level.h
13935@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13936
13937 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13938 {
13939+ pax_open_kernel();
13940 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13941+ pax_close_kernel();
13942 }
13943
13944 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13945 {
13946+ pax_open_kernel();
13947 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13948+ pax_close_kernel();
13949 }
13950
13951 /*
13952diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13953index 1c1a955..50f828c 100644
13954--- a/arch/x86/include/asm/pgtable.h
13955+++ b/arch/x86/include/asm/pgtable.h
13956@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13957
13958 #ifndef __PAGETABLE_PUD_FOLDED
13959 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13960+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13961 #define pgd_clear(pgd) native_pgd_clear(pgd)
13962 #endif
13963
13964@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13965
13966 #define arch_end_context_switch(prev) do {} while(0)
13967
13968+#define pax_open_kernel() native_pax_open_kernel()
13969+#define pax_close_kernel() native_pax_close_kernel()
13970 #endif /* CONFIG_PARAVIRT */
13971
13972+#define __HAVE_ARCH_PAX_OPEN_KERNEL
13973+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13974+
13975+#ifdef CONFIG_PAX_KERNEXEC
13976+static inline unsigned long native_pax_open_kernel(void)
13977+{
13978+ unsigned long cr0;
13979+
13980+ preempt_disable();
13981+ barrier();
13982+ cr0 = read_cr0() ^ X86_CR0_WP;
13983+ BUG_ON(cr0 & X86_CR0_WP);
13984+ write_cr0(cr0);
13985+ return cr0 ^ X86_CR0_WP;
13986+}
13987+
13988+static inline unsigned long native_pax_close_kernel(void)
13989+{
13990+ unsigned long cr0;
13991+
13992+ cr0 = read_cr0() ^ X86_CR0_WP;
13993+ BUG_ON(!(cr0 & X86_CR0_WP));
13994+ write_cr0(cr0);
13995+ barrier();
13996+ preempt_enable_no_resched();
13997+ return cr0 ^ X86_CR0_WP;
13998+}
13999+#else
14000+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14001+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14002+#endif
14003+
14004 /*
14005 * The following only work if pte_present() is true.
14006 * Undefined behaviour if not..
14007 */
14008+static inline int pte_user(pte_t pte)
14009+{
14010+ return pte_val(pte) & _PAGE_USER;
14011+}
14012+
14013 static inline int pte_dirty(pte_t pte)
14014 {
14015 return pte_flags(pte) & _PAGE_DIRTY;
14016@@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14017 return pte_clear_flags(pte, _PAGE_RW);
14018 }
14019
14020+static inline pte_t pte_mkread(pte_t pte)
14021+{
14022+ return __pte(pte_val(pte) | _PAGE_USER);
14023+}
14024+
14025 static inline pte_t pte_mkexec(pte_t pte)
14026 {
14027- return pte_clear_flags(pte, _PAGE_NX);
14028+#ifdef CONFIG_X86_PAE
14029+ if (__supported_pte_mask & _PAGE_NX)
14030+ return pte_clear_flags(pte, _PAGE_NX);
14031+ else
14032+#endif
14033+ return pte_set_flags(pte, _PAGE_USER);
14034+}
14035+
14036+static inline pte_t pte_exprotect(pte_t pte)
14037+{
14038+#ifdef CONFIG_X86_PAE
14039+ if (__supported_pte_mask & _PAGE_NX)
14040+ return pte_set_flags(pte, _PAGE_NX);
14041+ else
14042+#endif
14043+ return pte_clear_flags(pte, _PAGE_USER);
14044 }
14045
14046 static inline pte_t pte_mkdirty(pte_t pte)
14047@@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14048 #endif
14049
14050 #ifndef __ASSEMBLY__
14051+
14052+#ifdef CONFIG_PAX_PER_CPU_PGD
14053+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14054+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14055+{
14056+ return cpu_pgd[cpu];
14057+}
14058+#endif
14059+
14060 #include <linux/mm_types.h>
14061
14062 static inline int pte_none(pte_t pte)
14063@@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14064
14065 static inline int pgd_bad(pgd_t pgd)
14066 {
14067- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14068+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14069 }
14070
14071 static inline int pgd_none(pgd_t pgd)
14072@@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
14073 * pgd_offset() returns a (pgd_t *)
14074 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14075 */
14076-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14077+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14078+
14079+#ifdef CONFIG_PAX_PER_CPU_PGD
14080+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14081+#endif
14082+
14083 /*
14084 * a shortcut which implies the use of the kernel's pgd, instead
14085 * of a process's
14086@@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
14087 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14088 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14089
14090+#ifdef CONFIG_X86_32
14091+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14092+#else
14093+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14094+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14095+
14096+#ifdef CONFIG_PAX_MEMORY_UDEREF
14097+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
14098+#else
14099+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
14100+#endif
14101+
14102+#endif
14103+
14104 #ifndef __ASSEMBLY__
14105
14106 extern int direct_gbpages;
14107@@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14108 * dst and src can be on the same page, but the range must not overlap,
14109 * and must not cross a page boundary.
14110 */
14111-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14112+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14113 {
14114- memcpy(dst, src, count * sizeof(pgd_t));
14115+ pax_open_kernel();
14116+ while (count--)
14117+ *dst++ = *src++;
14118+ pax_close_kernel();
14119 }
14120
14121+#ifdef CONFIG_PAX_PER_CPU_PGD
14122+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14123+#endif
14124+
14125+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14126+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14127+#else
14128+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14129+#endif
14130
14131 #include <asm-generic/pgtable.h>
14132 #endif /* __ASSEMBLY__ */
14133diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14134index 8faa215..a8a17ea 100644
14135--- a/arch/x86/include/asm/pgtable_32.h
14136+++ b/arch/x86/include/asm/pgtable_32.h
14137@@ -25,9 +25,6 @@
14138 struct mm_struct;
14139 struct vm_area_struct;
14140
14141-extern pgd_t swapper_pg_dir[1024];
14142-extern pgd_t initial_page_table[1024];
14143-
14144 static inline void pgtable_cache_init(void) { }
14145 static inline void check_pgt_cache(void) { }
14146 void paging_init(void);
14147@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14148 # include <asm/pgtable-2level.h>
14149 #endif
14150
14151+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14152+extern pgd_t initial_page_table[PTRS_PER_PGD];
14153+#ifdef CONFIG_X86_PAE
14154+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14155+#endif
14156+
14157 #if defined(CONFIG_HIGHPTE)
14158 #define pte_offset_map(dir, address) \
14159 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14160@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14161 /* Clear a kernel PTE and flush it from the TLB */
14162 #define kpte_clear_flush(ptep, vaddr) \
14163 do { \
14164+ pax_open_kernel(); \
14165 pte_clear(&init_mm, (vaddr), (ptep)); \
14166+ pax_close_kernel(); \
14167 __flush_tlb_one((vaddr)); \
14168 } while (0)
14169
14170@@ -75,6 +80,9 @@ do { \
14171
14172 #endif /* !__ASSEMBLY__ */
14173
14174+#define HAVE_ARCH_UNMAPPED_AREA
14175+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14176+
14177 /*
14178 * kern_addr_valid() is (1) for FLATMEM and (0) for
14179 * SPARSEMEM and DISCONTIGMEM
14180diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14181index ed5903b..c7fe163 100644
14182--- a/arch/x86/include/asm/pgtable_32_types.h
14183+++ b/arch/x86/include/asm/pgtable_32_types.h
14184@@ -8,7 +8,7 @@
14185 */
14186 #ifdef CONFIG_X86_PAE
14187 # include <asm/pgtable-3level_types.h>
14188-# define PMD_SIZE (1UL << PMD_SHIFT)
14189+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14190 # define PMD_MASK (~(PMD_SIZE - 1))
14191 #else
14192 # include <asm/pgtable-2level_types.h>
14193@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14194 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14195 #endif
14196
14197+#ifdef CONFIG_PAX_KERNEXEC
14198+#ifndef __ASSEMBLY__
14199+extern unsigned char MODULES_EXEC_VADDR[];
14200+extern unsigned char MODULES_EXEC_END[];
14201+#endif
14202+#include <asm/boot.h>
14203+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14204+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14205+#else
14206+#define ktla_ktva(addr) (addr)
14207+#define ktva_ktla(addr) (addr)
14208+#endif
14209+
14210 #define MODULES_VADDR VMALLOC_START
14211 #define MODULES_END VMALLOC_END
14212 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14213diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14214index 47356f9..deb94a2 100644
14215--- a/arch/x86/include/asm/pgtable_64.h
14216+++ b/arch/x86/include/asm/pgtable_64.h
14217@@ -16,10 +16,14 @@
14218
14219 extern pud_t level3_kernel_pgt[512];
14220 extern pud_t level3_ident_pgt[512];
14221+extern pud_t level3_vmalloc_start_pgt[512];
14222+extern pud_t level3_vmalloc_end_pgt[512];
14223+extern pud_t level3_vmemmap_pgt[512];
14224+extern pud_t level2_vmemmap_pgt[512];
14225 extern pmd_t level2_kernel_pgt[512];
14226 extern pmd_t level2_fixmap_pgt[512];
14227-extern pmd_t level2_ident_pgt[512];
14228-extern pgd_t init_level4_pgt[];
14229+extern pmd_t level2_ident_pgt[512*2];
14230+extern pgd_t init_level4_pgt[512];
14231
14232 #define swapper_pg_dir init_level4_pgt
14233
14234@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14235
14236 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14237 {
14238+ pax_open_kernel();
14239 *pmdp = pmd;
14240+ pax_close_kernel();
14241 }
14242
14243 static inline void native_pmd_clear(pmd_t *pmd)
14244@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14245
14246 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14247 {
14248+ pax_open_kernel();
14249 *pudp = pud;
14250+ pax_close_kernel();
14251 }
14252
14253 static inline void native_pud_clear(pud_t *pud)
14254@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14255
14256 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14257 {
14258+ pax_open_kernel();
14259+ *pgdp = pgd;
14260+ pax_close_kernel();
14261+}
14262+
14263+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14264+{
14265 *pgdp = pgd;
14266 }
14267
14268diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14269index 766ea16..5b96cb3 100644
14270--- a/arch/x86/include/asm/pgtable_64_types.h
14271+++ b/arch/x86/include/asm/pgtable_64_types.h
14272@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14273 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14274 #define MODULES_END _AC(0xffffffffff000000, UL)
14275 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14276+#define MODULES_EXEC_VADDR MODULES_VADDR
14277+#define MODULES_EXEC_END MODULES_END
14278+
14279+#define ktla_ktva(addr) (addr)
14280+#define ktva_ktla(addr) (addr)
14281
14282 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14283diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14284index 3c32db8..1ddccf5 100644
14285--- a/arch/x86/include/asm/pgtable_types.h
14286+++ b/arch/x86/include/asm/pgtable_types.h
14287@@ -16,13 +16,12 @@
14288 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14289 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14290 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14291-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14292+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14293 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14294 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14295 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14296-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14297-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14298-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14299+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14300+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14301 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14302
14303 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14304@@ -40,7 +39,6 @@
14305 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14306 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14307 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14308-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14309 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14310 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14311 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14312@@ -57,8 +55,10 @@
14313
14314 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14315 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14316-#else
14317+#elif defined(CONFIG_KMEMCHECK)
14318 #define _PAGE_NX (_AT(pteval_t, 0))
14319+#else
14320+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14321 #endif
14322
14323 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14324@@ -116,6 +116,9 @@
14325 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14326 _PAGE_ACCESSED)
14327
14328+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14329+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14330+
14331 #define __PAGE_KERNEL_EXEC \
14332 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14333 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14334@@ -126,7 +129,7 @@
14335 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14336 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14337 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14338-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14339+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14340 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14341 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14342 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14343@@ -188,8 +191,8 @@
14344 * bits are combined, this will alow user to access the high address mapped
14345 * VDSO in the presence of CONFIG_COMPAT_VDSO
14346 */
14347-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14348-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14349+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14350+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14351 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14352 #endif
14353
14354@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14355 {
14356 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14357 }
14358+#endif
14359
14360+#if PAGETABLE_LEVELS == 3
14361+#include <asm-generic/pgtable-nopud.h>
14362+#endif
14363+
14364+#if PAGETABLE_LEVELS == 2
14365+#include <asm-generic/pgtable-nopmd.h>
14366+#endif
14367+
14368+#ifndef __ASSEMBLY__
14369 #if PAGETABLE_LEVELS > 3
14370 typedef struct { pudval_t pud; } pud_t;
14371
14372@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14373 return pud.pud;
14374 }
14375 #else
14376-#include <asm-generic/pgtable-nopud.h>
14377-
14378 static inline pudval_t native_pud_val(pud_t pud)
14379 {
14380 return native_pgd_val(pud.pgd);
14381@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14382 return pmd.pmd;
14383 }
14384 #else
14385-#include <asm-generic/pgtable-nopmd.h>
14386-
14387 static inline pmdval_t native_pmd_val(pmd_t pmd)
14388 {
14389 return native_pgd_val(pmd.pud.pgd);
14390@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14391
14392 extern pteval_t __supported_pte_mask;
14393 extern void set_nx(void);
14394-extern int nx_enabled;
14395
14396 #define pgprot_writecombine pgprot_writecombine
14397 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14398diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14399index 888184b..a07ac89 100644
14400--- a/arch/x86/include/asm/processor.h
14401+++ b/arch/x86/include/asm/processor.h
14402@@ -287,7 +287,7 @@ struct tss_struct {
14403
14404 } ____cacheline_aligned;
14405
14406-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14407+extern struct tss_struct init_tss[NR_CPUS];
14408
14409 /*
14410 * Save the original ist values for checking stack pointers during debugging
14411@@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14412 */
14413 #define TASK_SIZE PAGE_OFFSET
14414 #define TASK_SIZE_MAX TASK_SIZE
14415+
14416+#ifdef CONFIG_PAX_SEGMEXEC
14417+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14418+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14419+#else
14420 #define STACK_TOP TASK_SIZE
14421-#define STACK_TOP_MAX STACK_TOP
14422+#endif
14423+
14424+#define STACK_TOP_MAX TASK_SIZE
14425
14426 #define INIT_THREAD { \
14427- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14428+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14429 .vm86_info = NULL, \
14430 .sysenter_cs = __KERNEL_CS, \
14431 .io_bitmap_ptr = NULL, \
14432@@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14433 */
14434 #define INIT_TSS { \
14435 .x86_tss = { \
14436- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14437+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14438 .ss0 = __KERNEL_DS, \
14439 .ss1 = __KERNEL_CS, \
14440 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14441@@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14442 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14443
14444 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14445-#define KSTK_TOP(info) \
14446-({ \
14447- unsigned long *__ptr = (unsigned long *)(info); \
14448- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14449-})
14450+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14451
14452 /*
14453 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14454@@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14455 #define task_pt_regs(task) \
14456 ({ \
14457 struct pt_regs *__regs__; \
14458- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14459+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14460 __regs__ - 1; \
14461 })
14462
14463@@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14464 /*
14465 * User space process size. 47bits minus one guard page.
14466 */
14467-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14468+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14469
14470 /* This decides where the kernel will search for a free chunk of vm
14471 * space during mmap's.
14472 */
14473 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14474- 0xc0000000 : 0xFFFFe000)
14475+ 0xc0000000 : 0xFFFFf000)
14476
14477 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14478 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14479@@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14480 #define STACK_TOP_MAX TASK_SIZE_MAX
14481
14482 #define INIT_THREAD { \
14483- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14484+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14485 }
14486
14487 #define INIT_TSS { \
14488- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14489+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14490 }
14491
14492 /*
14493@@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14494 */
14495 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14496
14497+#ifdef CONFIG_PAX_SEGMEXEC
14498+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14499+#endif
14500+
14501 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14502
14503 /* Get/set a process' ability to use the timestamp counter instruction */
14504@@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14505 #define cpu_has_amd_erratum(x) (false)
14506 #endif /* CONFIG_CPU_SUP_AMD */
14507
14508-extern unsigned long arch_align_stack(unsigned long sp);
14509+#define arch_align_stack(x) ((x) & ~0xfUL)
14510 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14511
14512 void default_idle(void);
14513 bool set_pm_idle_to_default(void);
14514
14515-void stop_this_cpu(void *dummy);
14516+void stop_this_cpu(void *dummy) __noreturn;
14517
14518 #endif /* _ASM_X86_PROCESSOR_H */
14519diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14520index 942a086..6c26446 100644
14521--- a/arch/x86/include/asm/ptrace.h
14522+++ b/arch/x86/include/asm/ptrace.h
14523@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14524 }
14525
14526 /*
14527- * user_mode_vm(regs) determines whether a register set came from user mode.
14528+ * user_mode(regs) determines whether a register set came from user mode.
14529 * This is true if V8086 mode was enabled OR if the register set was from
14530 * protected mode with RPL-3 CS value. This tricky test checks that with
14531 * one comparison. Many places in the kernel can bypass this full check
14532- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14533+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14534+ * be used.
14535 */
14536-static inline int user_mode(struct pt_regs *regs)
14537+static inline int user_mode_novm(struct pt_regs *regs)
14538 {
14539 #ifdef CONFIG_X86_32
14540 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14541 #else
14542- return !!(regs->cs & 3);
14543+ return !!(regs->cs & SEGMENT_RPL_MASK);
14544 #endif
14545 }
14546
14547-static inline int user_mode_vm(struct pt_regs *regs)
14548+static inline int user_mode(struct pt_regs *regs)
14549 {
14550 #ifdef CONFIG_X86_32
14551 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14552 USER_RPL;
14553 #else
14554- return user_mode(regs);
14555+ return user_mode_novm(regs);
14556 #endif
14557 }
14558
14559@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14560 #ifdef CONFIG_X86_64
14561 static inline bool user_64bit_mode(struct pt_regs *regs)
14562 {
14563+ unsigned long cs = regs->cs & 0xffff;
14564 #ifndef CONFIG_PARAVIRT
14565 /*
14566 * On non-paravirt systems, this is the only long mode CPL 3
14567 * selector. We do not allow long mode selectors in the LDT.
14568 */
14569- return regs->cs == __USER_CS;
14570+ return cs == __USER_CS;
14571 #else
14572 /* Headers are too twisted for this to go in paravirt.h. */
14573- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14574+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14575 #endif
14576 }
14577
14578@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14579 * Traps from the kernel do not save sp and ss.
14580 * Use the helper function to retrieve sp.
14581 */
14582- if (offset == offsetof(struct pt_regs, sp) &&
14583- regs->cs == __KERNEL_CS)
14584- return kernel_stack_pointer(regs);
14585+ if (offset == offsetof(struct pt_regs, sp)) {
14586+ unsigned long cs = regs->cs & 0xffff;
14587+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14588+ return kernel_stack_pointer(regs);
14589+ }
14590 #endif
14591 return *(unsigned long *)((unsigned long)regs + offset);
14592 }
14593diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14594index fe1ec5b..dc5c3fe 100644
14595--- a/arch/x86/include/asm/realmode.h
14596+++ b/arch/x86/include/asm/realmode.h
14597@@ -22,16 +22,14 @@ struct real_mode_header {
14598 #endif
14599 /* APM/BIOS reboot */
14600 u32 machine_real_restart_asm;
14601-#ifdef CONFIG_X86_64
14602 u32 machine_real_restart_seg;
14603-#endif
14604 };
14605
14606 /* This must match data at trampoline_32/64.S */
14607 struct trampoline_header {
14608 #ifdef CONFIG_X86_32
14609 u32 start;
14610- u16 gdt_pad;
14611+ u16 boot_cs;
14612 u16 gdt_limit;
14613 u32 gdt_base;
14614 #else
14615diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14616index a82c4f1..ac45053 100644
14617--- a/arch/x86/include/asm/reboot.h
14618+++ b/arch/x86/include/asm/reboot.h
14619@@ -6,13 +6,13 @@
14620 struct pt_regs;
14621
14622 struct machine_ops {
14623- void (*restart)(char *cmd);
14624- void (*halt)(void);
14625- void (*power_off)(void);
14626+ void (* __noreturn restart)(char *cmd);
14627+ void (* __noreturn halt)(void);
14628+ void (* __noreturn power_off)(void);
14629 void (*shutdown)(void);
14630 void (*crash_shutdown)(struct pt_regs *);
14631- void (*emergency_restart)(void);
14632-};
14633+ void (* __noreturn emergency_restart)(void);
14634+} __no_const;
14635
14636 extern struct machine_ops machine_ops;
14637
14638diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14639index 2dbe4a7..ce1db00 100644
14640--- a/arch/x86/include/asm/rwsem.h
14641+++ b/arch/x86/include/asm/rwsem.h
14642@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14643 {
14644 asm volatile("# beginning down_read\n\t"
14645 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14646+
14647+#ifdef CONFIG_PAX_REFCOUNT
14648+ "jno 0f\n"
14649+ LOCK_PREFIX _ASM_DEC "(%1)\n"
14650+ "int $4\n0:\n"
14651+ _ASM_EXTABLE(0b, 0b)
14652+#endif
14653+
14654 /* adds 0x00000001 */
14655 " jns 1f\n"
14656 " call call_rwsem_down_read_failed\n"
14657@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14658 "1:\n\t"
14659 " mov %1,%2\n\t"
14660 " add %3,%2\n\t"
14661+
14662+#ifdef CONFIG_PAX_REFCOUNT
14663+ "jno 0f\n"
14664+ "sub %3,%2\n"
14665+ "int $4\n0:\n"
14666+ _ASM_EXTABLE(0b, 0b)
14667+#endif
14668+
14669 " jle 2f\n\t"
14670 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14671 " jnz 1b\n\t"
14672@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14673 long tmp;
14674 asm volatile("# beginning down_write\n\t"
14675 LOCK_PREFIX " xadd %1,(%2)\n\t"
14676+
14677+#ifdef CONFIG_PAX_REFCOUNT
14678+ "jno 0f\n"
14679+ "mov %1,(%2)\n"
14680+ "int $4\n0:\n"
14681+ _ASM_EXTABLE(0b, 0b)
14682+#endif
14683+
14684 /* adds 0xffff0001, returns the old value */
14685 " test %1,%1\n\t"
14686 /* was the count 0 before? */
14687@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14688 long tmp;
14689 asm volatile("# beginning __up_read\n\t"
14690 LOCK_PREFIX " xadd %1,(%2)\n\t"
14691+
14692+#ifdef CONFIG_PAX_REFCOUNT
14693+ "jno 0f\n"
14694+ "mov %1,(%2)\n"
14695+ "int $4\n0:\n"
14696+ _ASM_EXTABLE(0b, 0b)
14697+#endif
14698+
14699 /* subtracts 1, returns the old value */
14700 " jns 1f\n\t"
14701 " call call_rwsem_wake\n" /* expects old value in %edx */
14702@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14703 long tmp;
14704 asm volatile("# beginning __up_write\n\t"
14705 LOCK_PREFIX " xadd %1,(%2)\n\t"
14706+
14707+#ifdef CONFIG_PAX_REFCOUNT
14708+ "jno 0f\n"
14709+ "mov %1,(%2)\n"
14710+ "int $4\n0:\n"
14711+ _ASM_EXTABLE(0b, 0b)
14712+#endif
14713+
14714 /* subtracts 0xffff0001, returns the old value */
14715 " jns 1f\n\t"
14716 " call call_rwsem_wake\n" /* expects old value in %edx */
14717@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14718 {
14719 asm volatile("# beginning __downgrade_write\n\t"
14720 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14721+
14722+#ifdef CONFIG_PAX_REFCOUNT
14723+ "jno 0f\n"
14724+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14725+ "int $4\n0:\n"
14726+ _ASM_EXTABLE(0b, 0b)
14727+#endif
14728+
14729 /*
14730 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14731 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14732@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14733 */
14734 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14735 {
14736- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14737+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14738+
14739+#ifdef CONFIG_PAX_REFCOUNT
14740+ "jno 0f\n"
14741+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
14742+ "int $4\n0:\n"
14743+ _ASM_EXTABLE(0b, 0b)
14744+#endif
14745+
14746 : "+m" (sem->count)
14747 : "er" (delta));
14748 }
14749@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14750 */
14751 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14752 {
14753- return delta + xadd(&sem->count, delta);
14754+ return delta + xadd_check_overflow(&sem->count, delta);
14755 }
14756
14757 #endif /* __KERNEL__ */
14758diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14759index c48a950..c6d7468 100644
14760--- a/arch/x86/include/asm/segment.h
14761+++ b/arch/x86/include/asm/segment.h
14762@@ -64,10 +64,15 @@
14763 * 26 - ESPFIX small SS
14764 * 27 - per-cpu [ offset to per-cpu data area ]
14765 * 28 - stack_canary-20 [ for stack protector ]
14766- * 29 - unused
14767- * 30 - unused
14768+ * 29 - PCI BIOS CS
14769+ * 30 - PCI BIOS DS
14770 * 31 - TSS for double fault handler
14771 */
14772+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14773+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14774+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14775+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14776+
14777 #define GDT_ENTRY_TLS_MIN 6
14778 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14779
14780@@ -79,6 +84,8 @@
14781
14782 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14783
14784+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14785+
14786 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14787
14788 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14789@@ -104,6 +111,12 @@
14790 #define __KERNEL_STACK_CANARY 0
14791 #endif
14792
14793+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14794+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14795+
14796+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14797+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14798+
14799 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14800
14801 /*
14802@@ -141,7 +154,7 @@
14803 */
14804
14805 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14806-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14807+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14808
14809
14810 #else
14811@@ -165,6 +178,8 @@
14812 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14813 #define __USER32_DS __USER_DS
14814
14815+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14816+
14817 #define GDT_ENTRY_TSS 8 /* needs two entries */
14818 #define GDT_ENTRY_LDT 10 /* needs two entries */
14819 #define GDT_ENTRY_TLS_MIN 12
14820@@ -185,6 +200,7 @@
14821 #endif
14822
14823 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14824+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14825 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14826 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14827 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14828@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14829 {
14830 unsigned long __limit;
14831 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14832- return __limit + 1;
14833+ return __limit;
14834 }
14835
14836 #endif /* !__ASSEMBLY__ */
14837diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14838index b073aae..39f9bdd 100644
14839--- a/arch/x86/include/asm/smp.h
14840+++ b/arch/x86/include/asm/smp.h
14841@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14842 /* cpus sharing the last level cache: */
14843 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14844 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14845-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14846+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14847
14848 static inline struct cpumask *cpu_sibling_mask(int cpu)
14849 {
14850@@ -79,7 +79,7 @@ struct smp_ops {
14851
14852 void (*send_call_func_ipi)(const struct cpumask *mask);
14853 void (*send_call_func_single_ipi)(int cpu);
14854-};
14855+} __no_const;
14856
14857 /* Globals due to paravirt */
14858 extern void set_cpu_sibling_map(int cpu);
14859@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14860 extern int safe_smp_processor_id(void);
14861
14862 #elif defined(CONFIG_X86_64_SMP)
14863-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14864-
14865-#define stack_smp_processor_id() \
14866-({ \
14867- struct thread_info *ti; \
14868- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14869- ti->cpu; \
14870-})
14871+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14872+#define stack_smp_processor_id() raw_smp_processor_id()
14873 #define safe_smp_processor_id() smp_processor_id()
14874
14875 #endif
14876diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14877index 33692ea..350a534 100644
14878--- a/arch/x86/include/asm/spinlock.h
14879+++ b/arch/x86/include/asm/spinlock.h
14880@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14881 static inline void arch_read_lock(arch_rwlock_t *rw)
14882 {
14883 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14884+
14885+#ifdef CONFIG_PAX_REFCOUNT
14886+ "jno 0f\n"
14887+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14888+ "int $4\n0:\n"
14889+ _ASM_EXTABLE(0b, 0b)
14890+#endif
14891+
14892 "jns 1f\n"
14893 "call __read_lock_failed\n\t"
14894 "1:\n"
14895@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14896 static inline void arch_write_lock(arch_rwlock_t *rw)
14897 {
14898 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14899+
14900+#ifdef CONFIG_PAX_REFCOUNT
14901+ "jno 0f\n"
14902+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14903+ "int $4\n0:\n"
14904+ _ASM_EXTABLE(0b, 0b)
14905+#endif
14906+
14907 "jz 1f\n"
14908 "call __write_lock_failed\n\t"
14909 "1:\n"
14910@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14911
14912 static inline void arch_read_unlock(arch_rwlock_t *rw)
14913 {
14914- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14915+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14916+
14917+#ifdef CONFIG_PAX_REFCOUNT
14918+ "jno 0f\n"
14919+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14920+ "int $4\n0:\n"
14921+ _ASM_EXTABLE(0b, 0b)
14922+#endif
14923+
14924 :"+m" (rw->lock) : : "memory");
14925 }
14926
14927 static inline void arch_write_unlock(arch_rwlock_t *rw)
14928 {
14929- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14930+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14931+
14932+#ifdef CONFIG_PAX_REFCOUNT
14933+ "jno 0f\n"
14934+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14935+ "int $4\n0:\n"
14936+ _ASM_EXTABLE(0b, 0b)
14937+#endif
14938+
14939 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14940 }
14941
14942diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14943index 6a99859..03cb807 100644
14944--- a/arch/x86/include/asm/stackprotector.h
14945+++ b/arch/x86/include/asm/stackprotector.h
14946@@ -47,7 +47,7 @@
14947 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14948 */
14949 #define GDT_STACK_CANARY_INIT \
14950- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14951+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14952
14953 /*
14954 * Initialize the stackprotector canary value.
14955@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14956
14957 static inline void load_stack_canary_segment(void)
14958 {
14959-#ifdef CONFIG_X86_32
14960+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14961 asm volatile ("mov %0, %%gs" : : "r" (0));
14962 #endif
14963 }
14964diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14965index 70bbe39..4ae2bd4 100644
14966--- a/arch/x86/include/asm/stacktrace.h
14967+++ b/arch/x86/include/asm/stacktrace.h
14968@@ -11,28 +11,20 @@
14969
14970 extern int kstack_depth_to_print;
14971
14972-struct thread_info;
14973+struct task_struct;
14974 struct stacktrace_ops;
14975
14976-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14977- unsigned long *stack,
14978- unsigned long bp,
14979- const struct stacktrace_ops *ops,
14980- void *data,
14981- unsigned long *end,
14982- int *graph);
14983+typedef unsigned long walk_stack_t(struct task_struct *task,
14984+ void *stack_start,
14985+ unsigned long *stack,
14986+ unsigned long bp,
14987+ const struct stacktrace_ops *ops,
14988+ void *data,
14989+ unsigned long *end,
14990+ int *graph);
14991
14992-extern unsigned long
14993-print_context_stack(struct thread_info *tinfo,
14994- unsigned long *stack, unsigned long bp,
14995- const struct stacktrace_ops *ops, void *data,
14996- unsigned long *end, int *graph);
14997-
14998-extern unsigned long
14999-print_context_stack_bp(struct thread_info *tinfo,
15000- unsigned long *stack, unsigned long bp,
15001- const struct stacktrace_ops *ops, void *data,
15002- unsigned long *end, int *graph);
15003+extern walk_stack_t print_context_stack;
15004+extern walk_stack_t print_context_stack_bp;
15005
15006 /* Generic stack tracer with callbacks */
15007
15008@@ -40,7 +32,7 @@ struct stacktrace_ops {
15009 void (*address)(void *data, unsigned long address, int reliable);
15010 /* On negative return stop dumping */
15011 int (*stack)(void *data, char *name);
15012- walk_stack_t walk_stack;
15013+ walk_stack_t *walk_stack;
15014 };
15015
15016 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15017diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15018index 4ec45b3..a4f0a8a 100644
15019--- a/arch/x86/include/asm/switch_to.h
15020+++ b/arch/x86/include/asm/switch_to.h
15021@@ -108,7 +108,7 @@ do { \
15022 "call __switch_to\n\t" \
15023 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15024 __switch_canary \
15025- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15026+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15027 "movq %%rax,%%rdi\n\t" \
15028 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15029 "jnz ret_from_fork\n\t" \
15030@@ -119,7 +119,7 @@ do { \
15031 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15032 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15033 [_tif_fork] "i" (_TIF_FORK), \
15034- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15035+ [thread_info] "m" (current_tinfo), \
15036 [current_task] "m" (current_task) \
15037 __switch_canary_iparam \
15038 : "memory", "cc" __EXTRA_CLOBBER)
15039diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15040index 2d946e6..e453ec4 100644
15041--- a/arch/x86/include/asm/thread_info.h
15042+++ b/arch/x86/include/asm/thread_info.h
15043@@ -10,6 +10,7 @@
15044 #include <linux/compiler.h>
15045 #include <asm/page.h>
15046 #include <asm/types.h>
15047+#include <asm/percpu.h>
15048
15049 /*
15050 * low level task data that entry.S needs immediate access to
15051@@ -24,7 +25,6 @@ struct exec_domain;
15052 #include <linux/atomic.h>
15053
15054 struct thread_info {
15055- struct task_struct *task; /* main task structure */
15056 struct exec_domain *exec_domain; /* execution domain */
15057 __u32 flags; /* low level flags */
15058 __u32 status; /* thread synchronous flags */
15059@@ -34,19 +34,13 @@ struct thread_info {
15060 mm_segment_t addr_limit;
15061 struct restart_block restart_block;
15062 void __user *sysenter_return;
15063-#ifdef CONFIG_X86_32
15064- unsigned long previous_esp; /* ESP of the previous stack in
15065- case of nested (IRQ) stacks
15066- */
15067- __u8 supervisor_stack[0];
15068-#endif
15069+ unsigned long lowest_stack;
15070 unsigned int sig_on_uaccess_error:1;
15071 unsigned int uaccess_err:1; /* uaccess failed */
15072 };
15073
15074-#define INIT_THREAD_INFO(tsk) \
15075+#define INIT_THREAD_INFO \
15076 { \
15077- .task = &tsk, \
15078 .exec_domain = &default_exec_domain, \
15079 .flags = 0, \
15080 .cpu = 0, \
15081@@ -57,7 +51,7 @@ struct thread_info {
15082 }, \
15083 }
15084
15085-#define init_thread_info (init_thread_union.thread_info)
15086+#define init_thread_info (init_thread_union.stack)
15087 #define init_stack (init_thread_union.stack)
15088
15089 #else /* !__ASSEMBLY__ */
15090@@ -98,6 +92,7 @@ struct thread_info {
15091 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15092 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15093 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15094+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15095
15096 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15097 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15098@@ -122,17 +117,18 @@ struct thread_info {
15099 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15100 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15101 #define _TIF_X32 (1 << TIF_X32)
15102+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15103
15104 /* work to do in syscall_trace_enter() */
15105 #define _TIF_WORK_SYSCALL_ENTRY \
15106 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15107 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15108- _TIF_NOHZ)
15109+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15110
15111 /* work to do in syscall_trace_leave() */
15112 #define _TIF_WORK_SYSCALL_EXIT \
15113 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15114- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15115+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15116
15117 /* work to do on interrupt/exception return */
15118 #define _TIF_WORK_MASK \
15119@@ -143,7 +139,7 @@ struct thread_info {
15120 /* work to do on any return to user space */
15121 #define _TIF_ALLWORK_MASK \
15122 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15123- _TIF_NOHZ)
15124+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15125
15126 /* Only used for 64 bit */
15127 #define _TIF_DO_NOTIFY_MASK \
15128@@ -159,45 +155,40 @@ struct thread_info {
15129
15130 #define PREEMPT_ACTIVE 0x10000000
15131
15132-#ifdef CONFIG_X86_32
15133-
15134-#define STACK_WARN (THREAD_SIZE/8)
15135-/*
15136- * macros/functions for gaining access to the thread information structure
15137- *
15138- * preempt_count needs to be 1 initially, until the scheduler is functional.
15139- */
15140-#ifndef __ASSEMBLY__
15141-
15142-
15143-/* how to get the current stack pointer from C */
15144-register unsigned long current_stack_pointer asm("esp") __used;
15145-
15146-/* how to get the thread information struct from C */
15147-static inline struct thread_info *current_thread_info(void)
15148-{
15149- return (struct thread_info *)
15150- (current_stack_pointer & ~(THREAD_SIZE - 1));
15151-}
15152-
15153-#else /* !__ASSEMBLY__ */
15154-
15155+#ifdef __ASSEMBLY__
15156 /* how to get the thread information struct from ASM */
15157 #define GET_THREAD_INFO(reg) \
15158- movl $-THREAD_SIZE, reg; \
15159- andl %esp, reg
15160+ mov PER_CPU_VAR(current_tinfo), reg
15161
15162 /* use this one if reg already contains %esp */
15163-#define GET_THREAD_INFO_WITH_ESP(reg) \
15164- andl $-THREAD_SIZE, reg
15165+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15166+#else
15167+/* how to get the thread information struct from C */
15168+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15169+
15170+static __always_inline struct thread_info *current_thread_info(void)
15171+{
15172+ return this_cpu_read_stable(current_tinfo);
15173+}
15174+#endif
15175+
15176+#ifdef CONFIG_X86_32
15177+
15178+#define STACK_WARN (THREAD_SIZE/8)
15179+/*
15180+ * macros/functions for gaining access to the thread information structure
15181+ *
15182+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15183+ */
15184+#ifndef __ASSEMBLY__
15185+
15186+/* how to get the current stack pointer from C */
15187+register unsigned long current_stack_pointer asm("esp") __used;
15188
15189 #endif
15190
15191 #else /* X86_32 */
15192
15193-#include <asm/percpu.h>
15194-#define KERNEL_STACK_OFFSET (5*8)
15195-
15196 /*
15197 * macros/functions for gaining access to the thread information structure
15198 * preempt_count needs to be 1 initially, until the scheduler is functional.
15199@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15200 #ifndef __ASSEMBLY__
15201 DECLARE_PER_CPU(unsigned long, kernel_stack);
15202
15203-static inline struct thread_info *current_thread_info(void)
15204-{
15205- struct thread_info *ti;
15206- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15207- KERNEL_STACK_OFFSET - THREAD_SIZE);
15208- return ti;
15209-}
15210-
15211-#else /* !__ASSEMBLY__ */
15212-
15213-/* how to get the thread information struct from ASM */
15214-#define GET_THREAD_INFO(reg) \
15215- movq PER_CPU_VAR(kernel_stack),reg ; \
15216- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15217-
15218-/*
15219- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15220- * a certain register (to be used in assembler memory operands).
15221- */
15222-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15223-
15224+/* how to get the current stack pointer from C */
15225+register unsigned long current_stack_pointer asm("rsp") __used;
15226 #endif
15227
15228 #endif /* !X86_32 */
15229@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15230 extern void arch_task_cache_init(void);
15231 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15232 extern void arch_release_task_struct(struct task_struct *tsk);
15233+
15234+#define __HAVE_THREAD_FUNCTIONS
15235+#define task_thread_info(task) (&(task)->tinfo)
15236+#define task_stack_page(task) ((task)->stack)
15237+#define setup_thread_stack(p, org) do {} while (0)
15238+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15239+
15240 #endif
15241 #endif /* _ASM_X86_THREAD_INFO_H */
15242diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15243index 1709801..0a60f2f 100644
15244--- a/arch/x86/include/asm/uaccess.h
15245+++ b/arch/x86/include/asm/uaccess.h
15246@@ -7,6 +7,7 @@
15247 #include <linux/compiler.h>
15248 #include <linux/thread_info.h>
15249 #include <linux/string.h>
15250+#include <linux/sched.h>
15251 #include <asm/asm.h>
15252 #include <asm/page.h>
15253 #include <asm/smap.h>
15254@@ -29,7 +30,12 @@
15255
15256 #define get_ds() (KERNEL_DS)
15257 #define get_fs() (current_thread_info()->addr_limit)
15258+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15259+void __set_fs(mm_segment_t x);
15260+void set_fs(mm_segment_t x);
15261+#else
15262 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15263+#endif
15264
15265 #define segment_eq(a, b) ((a).seg == (b).seg)
15266
15267@@ -77,8 +83,33 @@
15268 * checks that the pointer is in the user space range - after calling
15269 * this function, memory access functions may still return -EFAULT.
15270 */
15271-#define access_ok(type, addr, size) \
15272- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15273+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15274+#define access_ok(type, addr, size) \
15275+({ \
15276+ long __size = size; \
15277+ unsigned long __addr = (unsigned long)addr; \
15278+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15279+ unsigned long __end_ao = __addr + __size - 1; \
15280+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15281+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15282+ while(__addr_ao <= __end_ao) { \
15283+ char __c_ao; \
15284+ __addr_ao += PAGE_SIZE; \
15285+ if (__size > PAGE_SIZE) \
15286+ cond_resched(); \
15287+ if (__get_user(__c_ao, (char __user *)__addr)) \
15288+ break; \
15289+ if (type != VERIFY_WRITE) { \
15290+ __addr = __addr_ao; \
15291+ continue; \
15292+ } \
15293+ if (__put_user(__c_ao, (char __user *)__addr)) \
15294+ break; \
15295+ __addr = __addr_ao; \
15296+ } \
15297+ } \
15298+ __ret_ao; \
15299+})
15300
15301 /*
15302 * The exception table consists of pairs of addresses relative to the
15303@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15304 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15305 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15306
15307-
15308+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15309+#define __copyuser_seg "gs;"
15310+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15311+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15312+#else
15313+#define __copyuser_seg
15314+#define __COPYUSER_SET_ES
15315+#define __COPYUSER_RESTORE_ES
15316+#endif
15317
15318 #ifdef CONFIG_X86_32
15319 #define __put_user_asm_u64(x, addr, err, errret) \
15320 asm volatile(ASM_STAC "\n" \
15321- "1: movl %%eax,0(%2)\n" \
15322- "2: movl %%edx,4(%2)\n" \
15323+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15324+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15325 "3: " ASM_CLAC "\n" \
15326 ".section .fixup,\"ax\"\n" \
15327 "4: movl %3,%0\n" \
15328@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15329
15330 #define __put_user_asm_ex_u64(x, addr) \
15331 asm volatile(ASM_STAC "\n" \
15332- "1: movl %%eax,0(%1)\n" \
15333- "2: movl %%edx,4(%1)\n" \
15334+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15335+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15336 "3: " ASM_CLAC "\n" \
15337 _ASM_EXTABLE_EX(1b, 2b) \
15338 _ASM_EXTABLE_EX(2b, 3b) \
15339@@ -259,7 +298,7 @@ extern void __put_user_8(void);
15340 __typeof__(*(ptr)) __pu_val; \
15341 __chk_user_ptr(ptr); \
15342 might_fault(); \
15343- __pu_val = x; \
15344+ __pu_val = (x); \
15345 switch (sizeof(*(ptr))) { \
15346 case 1: \
15347 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15348@@ -358,7 +397,7 @@ do { \
15349
15350 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15351 asm volatile(ASM_STAC "\n" \
15352- "1: mov"itype" %2,%"rtype"1\n" \
15353+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15354 "2: " ASM_CLAC "\n" \
15355 ".section .fixup,\"ax\"\n" \
15356 "3: mov %3,%0\n" \
15357@@ -366,7 +405,7 @@ do { \
15358 " jmp 2b\n" \
15359 ".previous\n" \
15360 _ASM_EXTABLE(1b, 3b) \
15361- : "=r" (err), ltype(x) \
15362+ : "=r" (err), ltype (x) \
15363 : "m" (__m(addr)), "i" (errret), "0" (err))
15364
15365 #define __get_user_size_ex(x, ptr, size) \
15366@@ -391,7 +430,7 @@ do { \
15367 } while (0)
15368
15369 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15370- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15371+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15372 "2:\n" \
15373 _ASM_EXTABLE_EX(1b, 2b) \
15374 : ltype(x) : "m" (__m(addr)))
15375@@ -408,13 +447,24 @@ do { \
15376 int __gu_err; \
15377 unsigned long __gu_val; \
15378 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15379- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15380+ (x) = (__typeof__(*(ptr)))__gu_val; \
15381 __gu_err; \
15382 })
15383
15384 /* FIXME: this hack is definitely wrong -AK */
15385 struct __large_struct { unsigned long buf[100]; };
15386-#define __m(x) (*(struct __large_struct __user *)(x))
15387+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15388+#define ____m(x) \
15389+({ \
15390+ unsigned long ____x = (unsigned long)(x); \
15391+ if (____x < PAX_USER_SHADOW_BASE) \
15392+ ____x += PAX_USER_SHADOW_BASE; \
15393+ (void __user *)____x; \
15394+})
15395+#else
15396+#define ____m(x) (x)
15397+#endif
15398+#define __m(x) (*(struct __large_struct __user *)____m(x))
15399
15400 /*
15401 * Tell gcc we read from memory instead of writing: this is because
15402@@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15403 */
15404 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15405 asm volatile(ASM_STAC "\n" \
15406- "1: mov"itype" %"rtype"1,%2\n" \
15407+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15408 "2: " ASM_CLAC "\n" \
15409 ".section .fixup,\"ax\"\n" \
15410 "3: mov %3,%0\n" \
15411@@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15412 ".previous\n" \
15413 _ASM_EXTABLE(1b, 3b) \
15414 : "=r"(err) \
15415- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15416+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15417
15418 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15419- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15420+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15421 "2:\n" \
15422 _ASM_EXTABLE_EX(1b, 2b) \
15423 : : ltype(x), "m" (__m(addr)))
15424@@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15425 * On error, the variable @x is set to zero.
15426 */
15427
15428+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15429+#define __get_user(x, ptr) get_user((x), (ptr))
15430+#else
15431 #define __get_user(x, ptr) \
15432 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15433+#endif
15434
15435 /**
15436 * __put_user: - Write a simple value into user space, with less checking.
15437@@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15438 * Returns zero on success, or -EFAULT on error.
15439 */
15440
15441+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15442+#define __put_user(x, ptr) put_user((x), (ptr))
15443+#else
15444 #define __put_user(x, ptr) \
15445 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15446+#endif
15447
15448 #define __get_user_unaligned __get_user
15449 #define __put_user_unaligned __put_user
15450@@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15451 #define get_user_ex(x, ptr) do { \
15452 unsigned long __gue_val; \
15453 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15454- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15455+ (x) = (__typeof__(*(ptr)))__gue_val; \
15456 } while (0)
15457
15458 #define put_user_try uaccess_try
15459@@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15460 extern __must_check long strlen_user(const char __user *str);
15461 extern __must_check long strnlen_user(const char __user *str, long n);
15462
15463-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15464-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15465+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15466+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15467
15468 /*
15469 * movsl can be slow when source and dest are not both 8-byte aligned
15470diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15471index 7f760a9..04b1c65 100644
15472--- a/arch/x86/include/asm/uaccess_32.h
15473+++ b/arch/x86/include/asm/uaccess_32.h
15474@@ -11,15 +11,15 @@
15475 #include <asm/page.h>
15476
15477 unsigned long __must_check __copy_to_user_ll
15478- (void __user *to, const void *from, unsigned long n);
15479+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15480 unsigned long __must_check __copy_from_user_ll
15481- (void *to, const void __user *from, unsigned long n);
15482+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15483 unsigned long __must_check __copy_from_user_ll_nozero
15484- (void *to, const void __user *from, unsigned long n);
15485+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15486 unsigned long __must_check __copy_from_user_ll_nocache
15487- (void *to, const void __user *from, unsigned long n);
15488+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15489 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15490- (void *to, const void __user *from, unsigned long n);
15491+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15492
15493 /**
15494 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15495@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15496 static __always_inline unsigned long __must_check
15497 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15498 {
15499+ if ((long)n < 0)
15500+ return n;
15501+
15502+ check_object_size(from, n, true);
15503+
15504 if (__builtin_constant_p(n)) {
15505 unsigned long ret;
15506
15507@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15508 __copy_to_user(void __user *to, const void *from, unsigned long n)
15509 {
15510 might_fault();
15511+
15512 return __copy_to_user_inatomic(to, from, n);
15513 }
15514
15515 static __always_inline unsigned long
15516 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15517 {
15518+ if ((long)n < 0)
15519+ return n;
15520+
15521 /* Avoid zeroing the tail if the copy fails..
15522 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15523 * but as the zeroing behaviour is only significant when n is not
15524@@ -137,6 +146,12 @@ static __always_inline unsigned long
15525 __copy_from_user(void *to, const void __user *from, unsigned long n)
15526 {
15527 might_fault();
15528+
15529+ if ((long)n < 0)
15530+ return n;
15531+
15532+ check_object_size(to, n, false);
15533+
15534 if (__builtin_constant_p(n)) {
15535 unsigned long ret;
15536
15537@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15538 const void __user *from, unsigned long n)
15539 {
15540 might_fault();
15541+
15542+ if ((long)n < 0)
15543+ return n;
15544+
15545 if (__builtin_constant_p(n)) {
15546 unsigned long ret;
15547
15548@@ -181,15 +200,19 @@ static __always_inline unsigned long
15549 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15550 unsigned long n)
15551 {
15552- return __copy_from_user_ll_nocache_nozero(to, from, n);
15553+ if ((long)n < 0)
15554+ return n;
15555+
15556+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15557 }
15558
15559-unsigned long __must_check copy_to_user(void __user *to,
15560- const void *from, unsigned long n);
15561-unsigned long __must_check _copy_from_user(void *to,
15562- const void __user *from,
15563- unsigned long n);
15564-
15565+extern void copy_to_user_overflow(void)
15566+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15567+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15568+#else
15569+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15570+#endif
15571+;
15572
15573 extern void copy_from_user_overflow(void)
15574 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15575@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15576 #endif
15577 ;
15578
15579-static inline unsigned long __must_check copy_from_user(void *to,
15580- const void __user *from,
15581- unsigned long n)
15582+/**
15583+ * copy_to_user: - Copy a block of data into user space.
15584+ * @to: Destination address, in user space.
15585+ * @from: Source address, in kernel space.
15586+ * @n: Number of bytes to copy.
15587+ *
15588+ * Context: User context only. This function may sleep.
15589+ *
15590+ * Copy data from kernel space to user space.
15591+ *
15592+ * Returns number of bytes that could not be copied.
15593+ * On success, this will be zero.
15594+ */
15595+static inline unsigned long __must_check
15596+copy_to_user(void __user *to, const void *from, unsigned long n)
15597 {
15598- int sz = __compiletime_object_size(to);
15599+ size_t sz = __compiletime_object_size(from);
15600
15601- if (likely(sz == -1 || sz >= n))
15602- n = _copy_from_user(to, from, n);
15603- else
15604+ if (unlikely(sz != (size_t)-1 && sz < n))
15605+ copy_to_user_overflow();
15606+ else if (access_ok(VERIFY_WRITE, to, n))
15607+ n = __copy_to_user(to, from, n);
15608+ return n;
15609+}
15610+
15611+/**
15612+ * copy_from_user: - Copy a block of data from user space.
15613+ * @to: Destination address, in kernel space.
15614+ * @from: Source address, in user space.
15615+ * @n: Number of bytes to copy.
15616+ *
15617+ * Context: User context only. This function may sleep.
15618+ *
15619+ * Copy data from user space to kernel space.
15620+ *
15621+ * Returns number of bytes that could not be copied.
15622+ * On success, this will be zero.
15623+ *
15624+ * If some data could not be copied, this function will pad the copied
15625+ * data to the requested size using zero bytes.
15626+ */
15627+static inline unsigned long __must_check
15628+copy_from_user(void *to, const void __user *from, unsigned long n)
15629+{
15630+ size_t sz = __compiletime_object_size(to);
15631+
15632+ check_object_size(to, n, false);
15633+
15634+ if (unlikely(sz != (size_t)-1 && sz < n))
15635 copy_from_user_overflow();
15636-
15637+ else if (access_ok(VERIFY_READ, from, n))
15638+ n = __copy_from_user(to, from, n);
15639+ else if ((long)n > 0)
15640+ memset(to, 0, n);
15641 return n;
15642 }
15643
15644diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15645index 142810c..747941a 100644
15646--- a/arch/x86/include/asm/uaccess_64.h
15647+++ b/arch/x86/include/asm/uaccess_64.h
15648@@ -10,6 +10,9 @@
15649 #include <asm/alternative.h>
15650 #include <asm/cpufeature.h>
15651 #include <asm/page.h>
15652+#include <asm/pgtable.h>
15653+
15654+#define set_fs(x) (current_thread_info()->addr_limit = (x))
15655
15656 /*
15657 * Copy To/From Userspace
15658@@ -17,13 +20,13 @@
15659
15660 /* Handles exceptions in both to and from, but doesn't do access_ok */
15661 __must_check unsigned long
15662-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15663+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15664 __must_check unsigned long
15665-copy_user_generic_string(void *to, const void *from, unsigned len);
15666+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15667 __must_check unsigned long
15668-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15669+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15670
15671-static __always_inline __must_check unsigned long
15672+static __always_inline __must_check __size_overflow(3) unsigned long
15673 copy_user_generic(void *to, const void *from, unsigned len)
15674 {
15675 unsigned ret;
15676@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15677 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15678 "=d" (len)),
15679 "1" (to), "2" (from), "3" (len)
15680- : "memory", "rcx", "r8", "r9", "r10", "r11");
15681+ : "memory", "rcx", "r8", "r9", "r11");
15682 return ret;
15683 }
15684
15685+static __always_inline __must_check unsigned long
15686+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15687+static __always_inline __must_check unsigned long
15688+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15689 __must_check unsigned long
15690-_copy_to_user(void __user *to, const void *from, unsigned len);
15691-__must_check unsigned long
15692-_copy_from_user(void *to, const void __user *from, unsigned len);
15693-__must_check unsigned long
15694-copy_in_user(void __user *to, const void __user *from, unsigned len);
15695+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15696+
15697+extern void copy_to_user_overflow(void)
15698+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15699+ __compiletime_error("copy_to_user() buffer size is not provably correct")
15700+#else
15701+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
15702+#endif
15703+;
15704+
15705+extern void copy_from_user_overflow(void)
15706+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15707+ __compiletime_error("copy_from_user() buffer size is not provably correct")
15708+#else
15709+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
15710+#endif
15711+;
15712
15713 static inline unsigned long __must_check copy_from_user(void *to,
15714 const void __user *from,
15715 unsigned long n)
15716 {
15717- int sz = __compiletime_object_size(to);
15718-
15719 might_fault();
15720- if (likely(sz == -1 || sz >= n))
15721- n = _copy_from_user(to, from, n);
15722-#ifdef CONFIG_DEBUG_VM
15723- else
15724- WARN(1, "Buffer overflow detected!\n");
15725-#endif
15726+
15727+ check_object_size(to, n, false);
15728+
15729+ if (access_ok(VERIFY_READ, from, n))
15730+ n = __copy_from_user(to, from, n);
15731+ else if (n < INT_MAX)
15732+ memset(to, 0, n);
15733 return n;
15734 }
15735
15736 static __always_inline __must_check
15737-int copy_to_user(void __user *dst, const void *src, unsigned size)
15738+int copy_to_user(void __user *dst, const void *src, unsigned long size)
15739 {
15740 might_fault();
15741
15742- return _copy_to_user(dst, src, size);
15743+ if (access_ok(VERIFY_WRITE, dst, size))
15744+ size = __copy_to_user(dst, src, size);
15745+ return size;
15746 }
15747
15748 static __always_inline __must_check
15749-int __copy_from_user(void *dst, const void __user *src, unsigned size)
15750+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15751 {
15752- int ret = 0;
15753+ size_t sz = __compiletime_object_size(dst);
15754+ unsigned ret = 0;
15755
15756 might_fault();
15757+
15758+ if (size > INT_MAX)
15759+ return size;
15760+
15761+ check_object_size(dst, size, false);
15762+
15763+#ifdef CONFIG_PAX_MEMORY_UDEREF
15764+ if (!__access_ok(VERIFY_READ, src, size))
15765+ return size;
15766+#endif
15767+
15768+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15769+ copy_from_user_overflow();
15770+ return size;
15771+ }
15772+
15773 if (!__builtin_constant_p(size))
15774- return copy_user_generic(dst, (__force void *)src, size);
15775+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15776 switch (size) {
15777- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15778+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15779 ret, "b", "b", "=q", 1);
15780 return ret;
15781- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15782+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15783 ret, "w", "w", "=r", 2);
15784 return ret;
15785- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15786+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15787 ret, "l", "k", "=r", 4);
15788 return ret;
15789- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15790+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15791 ret, "q", "", "=r", 8);
15792 return ret;
15793 case 10:
15794- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15795+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15796 ret, "q", "", "=r", 10);
15797 if (unlikely(ret))
15798 return ret;
15799 __get_user_asm(*(u16 *)(8 + (char *)dst),
15800- (u16 __user *)(8 + (char __user *)src),
15801+ (const u16 __user *)(8 + (const char __user *)src),
15802 ret, "w", "w", "=r", 2);
15803 return ret;
15804 case 16:
15805- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15806+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15807 ret, "q", "", "=r", 16);
15808 if (unlikely(ret))
15809 return ret;
15810 __get_user_asm(*(u64 *)(8 + (char *)dst),
15811- (u64 __user *)(8 + (char __user *)src),
15812+ (const u64 __user *)(8 + (const char __user *)src),
15813 ret, "q", "", "=r", 8);
15814 return ret;
15815 default:
15816- return copy_user_generic(dst, (__force void *)src, size);
15817+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15818 }
15819 }
15820
15821 static __always_inline __must_check
15822-int __copy_to_user(void __user *dst, const void *src, unsigned size)
15823+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15824 {
15825- int ret = 0;
15826+ size_t sz = __compiletime_object_size(src);
15827+ unsigned ret = 0;
15828
15829 might_fault();
15830+
15831+ if (size > INT_MAX)
15832+ return size;
15833+
15834+ check_object_size(src, size, true);
15835+
15836+#ifdef CONFIG_PAX_MEMORY_UDEREF
15837+ if (!__access_ok(VERIFY_WRITE, dst, size))
15838+ return size;
15839+#endif
15840+
15841+ if (unlikely(sz != (size_t)-1 && sz < size)) {
15842+ copy_to_user_overflow();
15843+ return size;
15844+ }
15845+
15846 if (!__builtin_constant_p(size))
15847- return copy_user_generic((__force void *)dst, src, size);
15848+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15849 switch (size) {
15850- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15851+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15852 ret, "b", "b", "iq", 1);
15853 return ret;
15854- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15855+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15856 ret, "w", "w", "ir", 2);
15857 return ret;
15858- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15859+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15860 ret, "l", "k", "ir", 4);
15861 return ret;
15862- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15863+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15864 ret, "q", "", "er", 8);
15865 return ret;
15866 case 10:
15867- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15868+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15869 ret, "q", "", "er", 10);
15870 if (unlikely(ret))
15871 return ret;
15872 asm("":::"memory");
15873- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15874+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15875 ret, "w", "w", "ir", 2);
15876 return ret;
15877 case 16:
15878- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15879+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15880 ret, "q", "", "er", 16);
15881 if (unlikely(ret))
15882 return ret;
15883 asm("":::"memory");
15884- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15885+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15886 ret, "q", "", "er", 8);
15887 return ret;
15888 default:
15889- return copy_user_generic((__force void *)dst, src, size);
15890+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15891 }
15892 }
15893
15894 static __always_inline __must_check
15895-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15896+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15897 {
15898- int ret = 0;
15899+ unsigned ret = 0;
15900
15901 might_fault();
15902+
15903+ if (size > INT_MAX)
15904+ return size;
15905+
15906+#ifdef CONFIG_PAX_MEMORY_UDEREF
15907+ if (!__access_ok(VERIFY_READ, src, size))
15908+ return size;
15909+ if (!__access_ok(VERIFY_WRITE, dst, size))
15910+ return size;
15911+#endif
15912+
15913 if (!__builtin_constant_p(size))
15914- return copy_user_generic((__force void *)dst,
15915- (__force void *)src, size);
15916+ return copy_user_generic((__force_kernel void *)____m(dst),
15917+ (__force_kernel const void *)____m(src), size);
15918 switch (size) {
15919 case 1: {
15920 u8 tmp;
15921- __get_user_asm(tmp, (u8 __user *)src,
15922+ __get_user_asm(tmp, (const u8 __user *)src,
15923 ret, "b", "b", "=q", 1);
15924 if (likely(!ret))
15925 __put_user_asm(tmp, (u8 __user *)dst,
15926@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15927 }
15928 case 2: {
15929 u16 tmp;
15930- __get_user_asm(tmp, (u16 __user *)src,
15931+ __get_user_asm(tmp, (const u16 __user *)src,
15932 ret, "w", "w", "=r", 2);
15933 if (likely(!ret))
15934 __put_user_asm(tmp, (u16 __user *)dst,
15935@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15936
15937 case 4: {
15938 u32 tmp;
15939- __get_user_asm(tmp, (u32 __user *)src,
15940+ __get_user_asm(tmp, (const u32 __user *)src,
15941 ret, "l", "k", "=r", 4);
15942 if (likely(!ret))
15943 __put_user_asm(tmp, (u32 __user *)dst,
15944@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15945 }
15946 case 8: {
15947 u64 tmp;
15948- __get_user_asm(tmp, (u64 __user *)src,
15949+ __get_user_asm(tmp, (const u64 __user *)src,
15950 ret, "q", "", "=r", 8);
15951 if (likely(!ret))
15952 __put_user_asm(tmp, (u64 __user *)dst,
15953@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15954 return ret;
15955 }
15956 default:
15957- return copy_user_generic((__force void *)dst,
15958- (__force void *)src, size);
15959+ return copy_user_generic((__force_kernel void *)____m(dst),
15960+ (__force_kernel const void *)____m(src), size);
15961 }
15962 }
15963
15964 static __must_check __always_inline int
15965-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15966+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15967 {
15968- return copy_user_generic(dst, (__force const void *)src, size);
15969+ if (size > INT_MAX)
15970+ return size;
15971+
15972+#ifdef CONFIG_PAX_MEMORY_UDEREF
15973+ if (!__access_ok(VERIFY_READ, src, size))
15974+ return size;
15975+#endif
15976+
15977+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15978 }
15979
15980-static __must_check __always_inline int
15981-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15982+static __must_check __always_inline unsigned long
15983+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15984 {
15985- return copy_user_generic((__force void *)dst, src, size);
15986+ if (size > INT_MAX)
15987+ return size;
15988+
15989+#ifdef CONFIG_PAX_MEMORY_UDEREF
15990+ if (!__access_ok(VERIFY_WRITE, dst, size))
15991+ return size;
15992+#endif
15993+
15994+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15995 }
15996
15997-extern long __copy_user_nocache(void *dst, const void __user *src,
15998- unsigned size, int zerorest);
15999+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16000+ unsigned long size, int zerorest) __size_overflow(3);
16001
16002-static inline int
16003-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16004+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16005 {
16006 might_sleep();
16007+
16008+ if (size > INT_MAX)
16009+ return size;
16010+
16011+#ifdef CONFIG_PAX_MEMORY_UDEREF
16012+ if (!__access_ok(VERIFY_READ, src, size))
16013+ return size;
16014+#endif
16015+
16016 return __copy_user_nocache(dst, src, size, 1);
16017 }
16018
16019-static inline int
16020-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16021- unsigned size)
16022+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16023+ unsigned long size)
16024 {
16025+ if (size > INT_MAX)
16026+ return size;
16027+
16028+#ifdef CONFIG_PAX_MEMORY_UDEREF
16029+ if (!__access_ok(VERIFY_READ, src, size))
16030+ return size;
16031+#endif
16032+
16033 return __copy_user_nocache(dst, src, size, 0);
16034 }
16035
16036-unsigned long
16037-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16038+extern unsigned long
16039+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16040
16041 #endif /* _ASM_X86_UACCESS_64_H */
16042diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16043index 5b238981..77fdd78 100644
16044--- a/arch/x86/include/asm/word-at-a-time.h
16045+++ b/arch/x86/include/asm/word-at-a-time.h
16046@@ -11,7 +11,7 @@
16047 * and shift, for example.
16048 */
16049 struct word_at_a_time {
16050- const unsigned long one_bits, high_bits;
16051+ unsigned long one_bits, high_bits;
16052 };
16053
16054 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16055diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16056index 5769349..a3d3e2a 100644
16057--- a/arch/x86/include/asm/x86_init.h
16058+++ b/arch/x86/include/asm/x86_init.h
16059@@ -141,7 +141,7 @@ struct x86_init_ops {
16060 struct x86_init_timers timers;
16061 struct x86_init_iommu iommu;
16062 struct x86_init_pci pci;
16063-};
16064+} __no_const;
16065
16066 /**
16067 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16068@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
16069 void (*setup_percpu_clockev)(void);
16070 void (*early_percpu_clock_init)(void);
16071 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16072-};
16073+} __no_const;
16074
16075 /**
16076 * struct x86_platform_ops - platform specific runtime functions
16077@@ -178,7 +178,7 @@ struct x86_platform_ops {
16078 void (*save_sched_clock_state)(void);
16079 void (*restore_sched_clock_state)(void);
16080 void (*apic_post_init)(void);
16081-};
16082+} __no_const;
16083
16084 struct pci_dev;
16085
16086@@ -187,14 +187,14 @@ struct x86_msi_ops {
16087 void (*teardown_msi_irq)(unsigned int irq);
16088 void (*teardown_msi_irqs)(struct pci_dev *dev);
16089 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16090-};
16091+} __no_const;
16092
16093 struct x86_io_apic_ops {
16094 void (*init) (void);
16095 unsigned int (*read) (unsigned int apic, unsigned int reg);
16096 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
16097 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
16098-};
16099+} __no_const;
16100
16101 extern struct x86_init_ops x86_init;
16102 extern struct x86_cpuinit_ops x86_cpuinit;
16103diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16104index 0415cda..b43d877 100644
16105--- a/arch/x86/include/asm/xsave.h
16106+++ b/arch/x86/include/asm/xsave.h
16107@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16108 return -EFAULT;
16109
16110 __asm__ __volatile__(ASM_STAC "\n"
16111- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16112+ "1:"
16113+ __copyuser_seg
16114+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16115 "2: " ASM_CLAC "\n"
16116 ".section .fixup,\"ax\"\n"
16117 "3: movl $-1,%[err]\n"
16118@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16119 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16120 {
16121 int err;
16122- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16123+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16124 u32 lmask = mask;
16125 u32 hmask = mask >> 32;
16126
16127 __asm__ __volatile__(ASM_STAC "\n"
16128- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16129+ "1:"
16130+ __copyuser_seg
16131+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16132 "2: " ASM_CLAC "\n"
16133 ".section .fixup,\"ax\"\n"
16134 "3: movl $-1,%[err]\n"
16135diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16136index bbae024..e1528f9 100644
16137--- a/arch/x86/include/uapi/asm/e820.h
16138+++ b/arch/x86/include/uapi/asm/e820.h
16139@@ -63,7 +63,7 @@ struct e820map {
16140 #define ISA_START_ADDRESS 0xa0000
16141 #define ISA_END_ADDRESS 0x100000
16142
16143-#define BIOS_BEGIN 0x000a0000
16144+#define BIOS_BEGIN 0x000c0000
16145 #define BIOS_END 0x00100000
16146
16147 #define BIOS_ROM_BASE 0xffe00000
16148diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16149index 34e923a..0c6bb6e 100644
16150--- a/arch/x86/kernel/Makefile
16151+++ b/arch/x86/kernel/Makefile
16152@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16153 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16154 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16155 obj-y += probe_roms.o
16156-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16157+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16158 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16159 obj-y += syscall_$(BITS).o
16160 obj-$(CONFIG_X86_64) += vsyscall_64.o
16161diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16162index bacf4b0..4ede72e 100644
16163--- a/arch/x86/kernel/acpi/boot.c
16164+++ b/arch/x86/kernel/acpi/boot.c
16165@@ -1358,7 +1358,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16166 * If your system is blacklisted here, but you find that acpi=force
16167 * works for you, please contact linux-acpi@vger.kernel.org
16168 */
16169-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16170+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16171 /*
16172 * Boxes that need ACPI disabled
16173 */
16174@@ -1433,7 +1433,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16175 };
16176
16177 /* second table for DMI checks that should run after early-quirks */
16178-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16179+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16180 /*
16181 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16182 * which includes some code which overrides all temperature
16183diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16184index d5e0d71..6533e08 100644
16185--- a/arch/x86/kernel/acpi/sleep.c
16186+++ b/arch/x86/kernel/acpi/sleep.c
16187@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16188 #else /* CONFIG_64BIT */
16189 #ifdef CONFIG_SMP
16190 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16191+
16192+ pax_open_kernel();
16193 early_gdt_descr.address =
16194 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16195+ pax_close_kernel();
16196+
16197 initial_gs = per_cpu_offset(smp_processor_id());
16198 #endif
16199 initial_code = (unsigned long)wakeup_long64;
16200diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16201index 13ab720..95d5442 100644
16202--- a/arch/x86/kernel/acpi/wakeup_32.S
16203+++ b/arch/x86/kernel/acpi/wakeup_32.S
16204@@ -30,13 +30,11 @@ wakeup_pmode_return:
16205 # and restore the stack ... but you need gdt for this to work
16206 movl saved_context_esp, %esp
16207
16208- movl %cs:saved_magic, %eax
16209- cmpl $0x12345678, %eax
16210+ cmpl $0x12345678, saved_magic
16211 jne bogus_magic
16212
16213 # jump to place where we left off
16214- movl saved_eip, %eax
16215- jmp *%eax
16216+ jmp *(saved_eip)
16217
16218 bogus_magic:
16219 jmp bogus_magic
16220diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16221index ef5ccca..bd83949 100644
16222--- a/arch/x86/kernel/alternative.c
16223+++ b/arch/x86/kernel/alternative.c
16224@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16225 */
16226 for (a = start; a < end; a++) {
16227 instr = (u8 *)&a->instr_offset + a->instr_offset;
16228+
16229+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16230+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16231+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16232+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16233+#endif
16234+
16235 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16236 BUG_ON(a->replacementlen > a->instrlen);
16237 BUG_ON(a->instrlen > sizeof(insnbuf));
16238@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16239 for (poff = start; poff < end; poff++) {
16240 u8 *ptr = (u8 *)poff + *poff;
16241
16242+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16243+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16244+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16245+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16246+#endif
16247+
16248 if (!*poff || ptr < text || ptr >= text_end)
16249 continue;
16250 /* turn DS segment override prefix into lock prefix */
16251- if (*ptr == 0x3e)
16252+ if (*ktla_ktva(ptr) == 0x3e)
16253 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16254 }
16255 mutex_unlock(&text_mutex);
16256@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16257 for (poff = start; poff < end; poff++) {
16258 u8 *ptr = (u8 *)poff + *poff;
16259
16260+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16261+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16262+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16263+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16264+#endif
16265+
16266 if (!*poff || ptr < text || ptr >= text_end)
16267 continue;
16268 /* turn lock prefix into DS segment override prefix */
16269- if (*ptr == 0xf0)
16270+ if (*ktla_ktva(ptr) == 0xf0)
16271 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16272 }
16273 mutex_unlock(&text_mutex);
16274@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16275
16276 BUG_ON(p->len > MAX_PATCH_LEN);
16277 /* prep the buffer with the original instructions */
16278- memcpy(insnbuf, p->instr, p->len);
16279+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16280 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16281 (unsigned long)p->instr, p->len);
16282
16283@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16284 if (!uniproc_patched || num_possible_cpus() == 1)
16285 free_init_pages("SMP alternatives",
16286 (unsigned long)__smp_locks,
16287- (unsigned long)__smp_locks_end);
16288+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16289 #endif
16290
16291 apply_paravirt(__parainstructions, __parainstructions_end);
16292@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16293 * instructions. And on the local CPU you need to be protected again NMI or MCE
16294 * handlers seeing an inconsistent instruction while you patch.
16295 */
16296-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16297+void *__kprobes text_poke_early(void *addr, const void *opcode,
16298 size_t len)
16299 {
16300 unsigned long flags;
16301 local_irq_save(flags);
16302- memcpy(addr, opcode, len);
16303+
16304+ pax_open_kernel();
16305+ memcpy(ktla_ktva(addr), opcode, len);
16306 sync_core();
16307+ pax_close_kernel();
16308+
16309 local_irq_restore(flags);
16310 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16311 that causes hangs on some VIA CPUs. */
16312@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16313 */
16314 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16315 {
16316- unsigned long flags;
16317- char *vaddr;
16318+ unsigned char *vaddr = ktla_ktva(addr);
16319 struct page *pages[2];
16320- int i;
16321+ size_t i;
16322
16323 if (!core_kernel_text((unsigned long)addr)) {
16324- pages[0] = vmalloc_to_page(addr);
16325- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16326+ pages[0] = vmalloc_to_page(vaddr);
16327+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16328 } else {
16329- pages[0] = virt_to_page(addr);
16330+ pages[0] = virt_to_page(vaddr);
16331 WARN_ON(!PageReserved(pages[0]));
16332- pages[1] = virt_to_page(addr + PAGE_SIZE);
16333+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16334 }
16335 BUG_ON(!pages[0]);
16336- local_irq_save(flags);
16337- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16338- if (pages[1])
16339- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16340- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16341- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16342- clear_fixmap(FIX_TEXT_POKE0);
16343- if (pages[1])
16344- clear_fixmap(FIX_TEXT_POKE1);
16345- local_flush_tlb();
16346- sync_core();
16347- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16348- that causes hangs on some VIA CPUs. */
16349+ text_poke_early(addr, opcode, len);
16350 for (i = 0; i < len; i++)
16351- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16352- local_irq_restore(flags);
16353+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16354 return addr;
16355 }
16356
16357diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16358index cbf5121..812b537 100644
16359--- a/arch/x86/kernel/apic/apic.c
16360+++ b/arch/x86/kernel/apic/apic.c
16361@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16362 /*
16363 * Debug level, exported for io_apic.c
16364 */
16365-unsigned int apic_verbosity;
16366+int apic_verbosity;
16367
16368 int pic_mode;
16369
16370@@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16371 apic_write(APIC_ESR, 0);
16372 v1 = apic_read(APIC_ESR);
16373 ack_APIC_irq();
16374- atomic_inc(&irq_err_count);
16375+ atomic_inc_unchecked(&irq_err_count);
16376
16377 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16378 smp_processor_id(), v0 , v1);
16379diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16380index 00c77cf..2dc6a2d 100644
16381--- a/arch/x86/kernel/apic/apic_flat_64.c
16382+++ b/arch/x86/kernel/apic/apic_flat_64.c
16383@@ -157,7 +157,7 @@ static int flat_probe(void)
16384 return 1;
16385 }
16386
16387-static struct apic apic_flat = {
16388+static struct apic apic_flat __read_only = {
16389 .name = "flat",
16390 .probe = flat_probe,
16391 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16392@@ -271,7 +271,7 @@ static int physflat_probe(void)
16393 return 0;
16394 }
16395
16396-static struct apic apic_physflat = {
16397+static struct apic apic_physflat __read_only = {
16398
16399 .name = "physical flat",
16400 .probe = physflat_probe,
16401diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16402index e145f28..2752888 100644
16403--- a/arch/x86/kernel/apic/apic_noop.c
16404+++ b/arch/x86/kernel/apic/apic_noop.c
16405@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16406 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16407 }
16408
16409-struct apic apic_noop = {
16410+struct apic apic_noop __read_only = {
16411 .name = "noop",
16412 .probe = noop_probe,
16413 .acpi_madt_oem_check = NULL,
16414diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16415index d50e364..543bee3 100644
16416--- a/arch/x86/kernel/apic/bigsmp_32.c
16417+++ b/arch/x86/kernel/apic/bigsmp_32.c
16418@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16419 return dmi_bigsmp;
16420 }
16421
16422-static struct apic apic_bigsmp = {
16423+static struct apic apic_bigsmp __read_only = {
16424
16425 .name = "bigsmp",
16426 .probe = probe_bigsmp,
16427diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16428index 0874799..a7a7892 100644
16429--- a/arch/x86/kernel/apic/es7000_32.c
16430+++ b/arch/x86/kernel/apic/es7000_32.c
16431@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16432 return ret && es7000_apic_is_cluster();
16433 }
16434
16435-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16436-static struct apic __refdata apic_es7000_cluster = {
16437+static struct apic apic_es7000_cluster __read_only = {
16438
16439 .name = "es7000",
16440 .probe = probe_es7000,
16441@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16442 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16443 };
16444
16445-static struct apic __refdata apic_es7000 = {
16446+static struct apic apic_es7000 __read_only = {
16447
16448 .name = "es7000",
16449 .probe = probe_es7000,
16450diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16451index b739d39..aebc14c 100644
16452--- a/arch/x86/kernel/apic/io_apic.c
16453+++ b/arch/x86/kernel/apic/io_apic.c
16454@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16455 }
16456 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16457
16458-void lock_vector_lock(void)
16459+void lock_vector_lock(void) __acquires(vector_lock)
16460 {
16461 /* Used to the online set of cpus does not change
16462 * during assign_irq_vector.
16463@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16464 raw_spin_lock(&vector_lock);
16465 }
16466
16467-void unlock_vector_lock(void)
16468+void unlock_vector_lock(void) __releases(vector_lock)
16469 {
16470 raw_spin_unlock(&vector_lock);
16471 }
16472@@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16473 ack_APIC_irq();
16474 }
16475
16476-atomic_t irq_mis_count;
16477+atomic_unchecked_t irq_mis_count;
16478
16479 #ifdef CONFIG_GENERIC_PENDING_IRQ
16480 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16481@@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16482 * at the cpu.
16483 */
16484 if (!(v & (1 << (i & 0x1f)))) {
16485- atomic_inc(&irq_mis_count);
16486+ atomic_inc_unchecked(&irq_mis_count);
16487
16488 eoi_ioapic_irq(irq, cfg);
16489 }
16490@@ -2567,11 +2567,13 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
16491
16492 static void irq_remap_modify_chip_defaults(struct irq_chip *chip)
16493 {
16494- chip->irq_print_chip = ir_print_prefix;
16495- chip->irq_ack = ir_ack_apic_edge;
16496- chip->irq_eoi = ir_ack_apic_level;
16497+ pax_open_kernel();
16498+ *(void **)&chip->irq_print_chip = ir_print_prefix;
16499+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
16500+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
16501
16502- chip->irq_set_affinity = set_remapped_irq_affinity;
16503+ *(void **)&chip->irq_set_affinity = set_remapped_irq_affinity;
16504+ pax_close_kernel();
16505 }
16506 #endif /* CONFIG_IRQ_REMAP */
16507
16508diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16509index d661ee9..791fd33 100644
16510--- a/arch/x86/kernel/apic/numaq_32.c
16511+++ b/arch/x86/kernel/apic/numaq_32.c
16512@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16513 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16514 }
16515
16516-/* Use __refdata to keep false positive warning calm. */
16517-static struct apic __refdata apic_numaq = {
16518+static struct apic apic_numaq __read_only = {
16519
16520 .name = "NUMAQ",
16521 .probe = probe_numaq,
16522diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16523index eb35ef9..f184a21 100644
16524--- a/arch/x86/kernel/apic/probe_32.c
16525+++ b/arch/x86/kernel/apic/probe_32.c
16526@@ -72,7 +72,7 @@ static int probe_default(void)
16527 return 1;
16528 }
16529
16530-static struct apic apic_default = {
16531+static struct apic apic_default __read_only = {
16532
16533 .name = "default",
16534 .probe = probe_default,
16535diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16536index 77c95c0..434f8a4 100644
16537--- a/arch/x86/kernel/apic/summit_32.c
16538+++ b/arch/x86/kernel/apic/summit_32.c
16539@@ -486,7 +486,7 @@ void setup_summit(void)
16540 }
16541 #endif
16542
16543-static struct apic apic_summit = {
16544+static struct apic apic_summit __read_only = {
16545
16546 .name = "summit",
16547 .probe = probe_summit,
16548diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16549index c88baa4..757aee1 100644
16550--- a/arch/x86/kernel/apic/x2apic_cluster.c
16551+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16552@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16553 return notifier_from_errno(err);
16554 }
16555
16556-static struct notifier_block __refdata x2apic_cpu_notifier = {
16557+static struct notifier_block x2apic_cpu_notifier = {
16558 .notifier_call = update_clusterinfo,
16559 };
16560
16561@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16562 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16563 }
16564
16565-static struct apic apic_x2apic_cluster = {
16566+static struct apic apic_x2apic_cluster __read_only = {
16567
16568 .name = "cluster x2apic",
16569 .probe = x2apic_cluster_probe,
16570diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16571index 562a76d..a003c0f 100644
16572--- a/arch/x86/kernel/apic/x2apic_phys.c
16573+++ b/arch/x86/kernel/apic/x2apic_phys.c
16574@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16575 return apic == &apic_x2apic_phys;
16576 }
16577
16578-static struct apic apic_x2apic_phys = {
16579+static struct apic apic_x2apic_phys __read_only = {
16580
16581 .name = "physical x2apic",
16582 .probe = x2apic_phys_probe,
16583diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16584index 8cfade9..b9d04fc 100644
16585--- a/arch/x86/kernel/apic/x2apic_uv_x.c
16586+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16587@@ -333,7 +333,7 @@ static int uv_probe(void)
16588 return apic == &apic_x2apic_uv_x;
16589 }
16590
16591-static struct apic __refdata apic_x2apic_uv_x = {
16592+static struct apic apic_x2apic_uv_x __read_only = {
16593
16594 .name = "UV large system",
16595 .probe = uv_probe,
16596diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16597index d65464e..1035d31 100644
16598--- a/arch/x86/kernel/apm_32.c
16599+++ b/arch/x86/kernel/apm_32.c
16600@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16601 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16602 * even though they are called in protected mode.
16603 */
16604-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16605+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16606 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16607
16608 static const char driver_version[] = "1.16ac"; /* no spaces */
16609@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16610 BUG_ON(cpu != 0);
16611 gdt = get_cpu_gdt_table(cpu);
16612 save_desc_40 = gdt[0x40 / 8];
16613+
16614+ pax_open_kernel();
16615 gdt[0x40 / 8] = bad_bios_desc;
16616+ pax_close_kernel();
16617
16618 apm_irq_save(flags);
16619 APM_DO_SAVE_SEGS;
16620@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16621 &call->esi);
16622 APM_DO_RESTORE_SEGS;
16623 apm_irq_restore(flags);
16624+
16625+ pax_open_kernel();
16626 gdt[0x40 / 8] = save_desc_40;
16627+ pax_close_kernel();
16628+
16629 put_cpu();
16630
16631 return call->eax & 0xff;
16632@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16633 BUG_ON(cpu != 0);
16634 gdt = get_cpu_gdt_table(cpu);
16635 save_desc_40 = gdt[0x40 / 8];
16636+
16637+ pax_open_kernel();
16638 gdt[0x40 / 8] = bad_bios_desc;
16639+ pax_close_kernel();
16640
16641 apm_irq_save(flags);
16642 APM_DO_SAVE_SEGS;
16643@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16644 &call->eax);
16645 APM_DO_RESTORE_SEGS;
16646 apm_irq_restore(flags);
16647+
16648+ pax_open_kernel();
16649 gdt[0x40 / 8] = save_desc_40;
16650+ pax_close_kernel();
16651+
16652 put_cpu();
16653 return error;
16654 }
16655@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16656 * code to that CPU.
16657 */
16658 gdt = get_cpu_gdt_table(0);
16659+
16660+ pax_open_kernel();
16661 set_desc_base(&gdt[APM_CS >> 3],
16662 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16663 set_desc_base(&gdt[APM_CS_16 >> 3],
16664 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16665 set_desc_base(&gdt[APM_DS >> 3],
16666 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16667+ pax_close_kernel();
16668
16669 proc_create("apm", 0, NULL, &apm_file_ops);
16670
16671diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16672index 2861082..6d4718e 100644
16673--- a/arch/x86/kernel/asm-offsets.c
16674+++ b/arch/x86/kernel/asm-offsets.c
16675@@ -33,6 +33,8 @@ void common(void) {
16676 OFFSET(TI_status, thread_info, status);
16677 OFFSET(TI_addr_limit, thread_info, addr_limit);
16678 OFFSET(TI_preempt_count, thread_info, preempt_count);
16679+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16680+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16681
16682 BLANK();
16683 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16684@@ -53,8 +55,26 @@ void common(void) {
16685 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16686 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16687 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16688+
16689+#ifdef CONFIG_PAX_KERNEXEC
16690+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16691 #endif
16692
16693+#ifdef CONFIG_PAX_MEMORY_UDEREF
16694+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16695+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16696+#ifdef CONFIG_X86_64
16697+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16698+#endif
16699+#endif
16700+
16701+#endif
16702+
16703+ BLANK();
16704+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16705+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16706+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16707+
16708 #ifdef CONFIG_XEN
16709 BLANK();
16710 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16711diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16712index 1b4754f..fbb4227 100644
16713--- a/arch/x86/kernel/asm-offsets_64.c
16714+++ b/arch/x86/kernel/asm-offsets_64.c
16715@@ -76,6 +76,7 @@ int main(void)
16716 BLANK();
16717 #undef ENTRY
16718
16719+ DEFINE(TSS_size, sizeof(struct tss_struct));
16720 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16721 BLANK();
16722
16723diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16724index a0e067d..9c7db16 100644
16725--- a/arch/x86/kernel/cpu/Makefile
16726+++ b/arch/x86/kernel/cpu/Makefile
16727@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16728 CFLAGS_REMOVE_perf_event.o = -pg
16729 endif
16730
16731-# Make sure load_percpu_segment has no stackprotector
16732-nostackp := $(call cc-option, -fno-stack-protector)
16733-CFLAGS_common.o := $(nostackp)
16734-
16735 obj-y := intel_cacheinfo.o scattered.o topology.o
16736 obj-y += proc.o capflags.o powerflags.o common.o
16737 obj-y += vmware.o hypervisor.o mshyperv.o
16738diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16739index 15239ff..e23e04e 100644
16740--- a/arch/x86/kernel/cpu/amd.c
16741+++ b/arch/x86/kernel/cpu/amd.c
16742@@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16743 unsigned int size)
16744 {
16745 /* AMD errata T13 (order #21922) */
16746- if ((c->x86 == 6)) {
16747+ if (c->x86 == 6) {
16748 /* Duron Rev A0 */
16749 if (c->x86_model == 3 && c->x86_mask == 0)
16750 size = 64;
16751diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16752index 9c3ab43..51e6366 100644
16753--- a/arch/x86/kernel/cpu/common.c
16754+++ b/arch/x86/kernel/cpu/common.c
16755@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16756
16757 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16758
16759-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16760-#ifdef CONFIG_X86_64
16761- /*
16762- * We need valid kernel segments for data and code in long mode too
16763- * IRET will check the segment types kkeil 2000/10/28
16764- * Also sysret mandates a special GDT layout
16765- *
16766- * TLS descriptors are currently at a different place compared to i386.
16767- * Hopefully nobody expects them at a fixed place (Wine?)
16768- */
16769- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16770- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16771- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16772- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16773- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16774- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16775-#else
16776- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16777- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16778- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16779- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16780- /*
16781- * Segments used for calling PnP BIOS have byte granularity.
16782- * They code segments and data segments have fixed 64k limits,
16783- * the transfer segment sizes are set at run time.
16784- */
16785- /* 32-bit code */
16786- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16787- /* 16-bit code */
16788- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16789- /* 16-bit data */
16790- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16791- /* 16-bit data */
16792- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16793- /* 16-bit data */
16794- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16795- /*
16796- * The APM segments have byte granularity and their bases
16797- * are set at run time. All have 64k limits.
16798- */
16799- /* 32-bit code */
16800- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16801- /* 16-bit code */
16802- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16803- /* data */
16804- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16805-
16806- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16807- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16808- GDT_STACK_CANARY_INIT
16809-#endif
16810-} };
16811-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16812-
16813 static int __init x86_xsave_setup(char *s)
16814 {
16815 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16816@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16817 {
16818 struct desc_ptr gdt_descr;
16819
16820- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16821+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16822 gdt_descr.size = GDT_SIZE - 1;
16823 load_gdt(&gdt_descr);
16824 /* Reload the per-cpu base */
16825@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16826 /* Filter out anything that depends on CPUID levels we don't have */
16827 filter_cpuid_features(c, true);
16828
16829+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16830+ setup_clear_cpu_cap(X86_FEATURE_SEP);
16831+#endif
16832+
16833 /* If the model name is still unset, do table lookup. */
16834 if (!c->x86_model_id[0]) {
16835 const char *p;
16836@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16837 }
16838 __setup("clearcpuid=", setup_disablecpuid);
16839
16840+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16841+EXPORT_PER_CPU_SYMBOL(current_tinfo);
16842+
16843 #ifdef CONFIG_X86_64
16844 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16845-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16846- (unsigned long) nmi_idt_table };
16847+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16848
16849 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16850 irq_stack_union) __aligned(PAGE_SIZE);
16851@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16852 EXPORT_PER_CPU_SYMBOL(current_task);
16853
16854 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16855- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16856+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16857 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16858
16859 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16860@@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16861 int i;
16862
16863 cpu = stack_smp_processor_id();
16864- t = &per_cpu(init_tss, cpu);
16865+ t = init_tss + cpu;
16866 oist = &per_cpu(orig_ist, cpu);
16867
16868 #ifdef CONFIG_NUMA
16869@@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16870 switch_to_new_gdt(cpu);
16871 loadsegment(fs, 0);
16872
16873- load_idt((const struct desc_ptr *)&idt_descr);
16874+ load_idt(&idt_descr);
16875
16876 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16877 syscall_init();
16878@@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16879 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16880 barrier();
16881
16882- x86_configure_nx();
16883 enable_x2apic();
16884
16885 /*
16886@@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16887 {
16888 int cpu = smp_processor_id();
16889 struct task_struct *curr = current;
16890- struct tss_struct *t = &per_cpu(init_tss, cpu);
16891+ struct tss_struct *t = init_tss + cpu;
16892 struct thread_struct *thread = &curr->thread;
16893
16894 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16895diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16896index fcaabd0..7b55a26 100644
16897--- a/arch/x86/kernel/cpu/intel.c
16898+++ b/arch/x86/kernel/cpu/intel.c
16899@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16900 * Update the IDT descriptor and reload the IDT so that
16901 * it uses the read-only mapped virtual address.
16902 */
16903- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16904+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16905 load_idt(&idt_descr);
16906 }
16907 #endif
16908diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16909index 84c1309..39b7224 100644
16910--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16911+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16912@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16913 };
16914
16915 #ifdef CONFIG_AMD_NB
16916+static struct attribute *default_attrs_amd_nb[] = {
16917+ &type.attr,
16918+ &level.attr,
16919+ &coherency_line_size.attr,
16920+ &physical_line_partition.attr,
16921+ &ways_of_associativity.attr,
16922+ &number_of_sets.attr,
16923+ &size.attr,
16924+ &shared_cpu_map.attr,
16925+ &shared_cpu_list.attr,
16926+ NULL,
16927+ NULL,
16928+ NULL,
16929+ NULL
16930+};
16931+
16932 static struct attribute ** __cpuinit amd_l3_attrs(void)
16933 {
16934 static struct attribute **attrs;
16935@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16936
16937 n = ARRAY_SIZE(default_attrs);
16938
16939- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16940- n += 2;
16941-
16942- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16943- n += 1;
16944-
16945- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16946- if (attrs == NULL)
16947- return attrs = default_attrs;
16948-
16949- for (n = 0; default_attrs[n]; n++)
16950- attrs[n] = default_attrs[n];
16951+ attrs = default_attrs_amd_nb;
16952
16953 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16954 attrs[n++] = &cache_disable_0.attr;
16955@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16956 .default_attrs = default_attrs,
16957 };
16958
16959+#ifdef CONFIG_AMD_NB
16960+static struct kobj_type ktype_cache_amd_nb = {
16961+ .sysfs_ops = &sysfs_ops,
16962+ .default_attrs = default_attrs_amd_nb,
16963+};
16964+#endif
16965+
16966 static struct kobj_type ktype_percpu_entry = {
16967 .sysfs_ops = &sysfs_ops,
16968 };
16969@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16970 return retval;
16971 }
16972
16973+#ifdef CONFIG_AMD_NB
16974+ amd_l3_attrs();
16975+#endif
16976+
16977 for (i = 0; i < num_cache_leaves; i++) {
16978+ struct kobj_type *ktype;
16979+
16980 this_object = INDEX_KOBJECT_PTR(cpu, i);
16981 this_object->cpu = cpu;
16982 this_object->index = i;
16983
16984 this_leaf = CPUID4_INFO_IDX(cpu, i);
16985
16986- ktype_cache.default_attrs = default_attrs;
16987+ ktype = &ktype_cache;
16988 #ifdef CONFIG_AMD_NB
16989 if (this_leaf->base.nb)
16990- ktype_cache.default_attrs = amd_l3_attrs();
16991+ ktype = &ktype_cache_amd_nb;
16992 #endif
16993 retval = kobject_init_and_add(&(this_object->kobj),
16994- &ktype_cache,
16995+ ktype,
16996 per_cpu(ici_cache_kobject, cpu),
16997 "index%1lu", i);
16998 if (unlikely(retval)) {
16999@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17000 return NOTIFY_OK;
17001 }
17002
17003-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17004+static struct notifier_block cacheinfo_cpu_notifier = {
17005 .notifier_call = cacheinfo_cpu_callback,
17006 };
17007
17008diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17009index 80dbda8..be16652 100644
17010--- a/arch/x86/kernel/cpu/mcheck/mce.c
17011+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17012@@ -45,6 +45,7 @@
17013 #include <asm/processor.h>
17014 #include <asm/mce.h>
17015 #include <asm/msr.h>
17016+#include <asm/local.h>
17017
17018 #include "mce-internal.h"
17019
17020@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17021 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17022 m->cs, m->ip);
17023
17024- if (m->cs == __KERNEL_CS)
17025+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17026 print_symbol("{%s}", m->ip);
17027 pr_cont("\n");
17028 }
17029@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17030
17031 #define PANIC_TIMEOUT 5 /* 5 seconds */
17032
17033-static atomic_t mce_paniced;
17034+static atomic_unchecked_t mce_paniced;
17035
17036 static int fake_panic;
17037-static atomic_t mce_fake_paniced;
17038+static atomic_unchecked_t mce_fake_paniced;
17039
17040 /* Panic in progress. Enable interrupts and wait for final IPI */
17041 static void wait_for_panic(void)
17042@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17043 /*
17044 * Make sure only one CPU runs in machine check panic
17045 */
17046- if (atomic_inc_return(&mce_paniced) > 1)
17047+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17048 wait_for_panic();
17049 barrier();
17050
17051@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17052 console_verbose();
17053 } else {
17054 /* Don't log too much for fake panic */
17055- if (atomic_inc_return(&mce_fake_paniced) > 1)
17056+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17057 return;
17058 }
17059 /* First print corrected ones that are still unlogged */
17060@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
17061 * might have been modified by someone else.
17062 */
17063 rmb();
17064- if (atomic_read(&mce_paniced))
17065+ if (atomic_read_unchecked(&mce_paniced))
17066 wait_for_panic();
17067 if (!mca_cfg.monarch_timeout)
17068 goto out;
17069@@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17070 }
17071
17072 /* Call the installed machine check handler for this CPU setup. */
17073-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17074+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17075 unexpected_machine_check;
17076
17077 /*
17078@@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17079 return;
17080 }
17081
17082+ pax_open_kernel();
17083 machine_check_vector = do_machine_check;
17084+ pax_close_kernel();
17085
17086 __mcheck_cpu_init_generic();
17087 __mcheck_cpu_init_vendor(c);
17088@@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17089 */
17090
17091 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17092-static int mce_chrdev_open_count; /* #times opened */
17093+static local_t mce_chrdev_open_count; /* #times opened */
17094 static int mce_chrdev_open_exclu; /* already open exclusive? */
17095
17096 static int mce_chrdev_open(struct inode *inode, struct file *file)
17097@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17098 spin_lock(&mce_chrdev_state_lock);
17099
17100 if (mce_chrdev_open_exclu ||
17101- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17102+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17103 spin_unlock(&mce_chrdev_state_lock);
17104
17105 return -EBUSY;
17106@@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17107
17108 if (file->f_flags & O_EXCL)
17109 mce_chrdev_open_exclu = 1;
17110- mce_chrdev_open_count++;
17111+ local_inc(&mce_chrdev_open_count);
17112
17113 spin_unlock(&mce_chrdev_state_lock);
17114
17115@@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17116 {
17117 spin_lock(&mce_chrdev_state_lock);
17118
17119- mce_chrdev_open_count--;
17120+ local_dec(&mce_chrdev_open_count);
17121 mce_chrdev_open_exclu = 0;
17122
17123 spin_unlock(&mce_chrdev_state_lock);
17124@@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17125 return NOTIFY_OK;
17126 }
17127
17128-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17129+static struct notifier_block mce_cpu_notifier = {
17130 .notifier_call = mce_cpu_callback,
17131 };
17132
17133@@ -2382,7 +2385,7 @@ static __init void mce_init_banks(void)
17134
17135 for (i = 0; i < mca_cfg.banks; i++) {
17136 struct mce_bank *b = &mce_banks[i];
17137- struct device_attribute *a = &b->attr;
17138+ device_attribute_no_const *a = &b->attr;
17139
17140 sysfs_attr_init(&a->attr);
17141 a->attr.name = b->attrname;
17142@@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
17143 static void mce_reset(void)
17144 {
17145 cpu_missing = 0;
17146- atomic_set(&mce_fake_paniced, 0);
17147+ atomic_set_unchecked(&mce_fake_paniced, 0);
17148 atomic_set(&mce_executing, 0);
17149 atomic_set(&mce_callin, 0);
17150 atomic_set(&global_nwo, 0);
17151diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17152index 2d5454c..51987eb 100644
17153--- a/arch/x86/kernel/cpu/mcheck/p5.c
17154+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17155@@ -11,6 +11,7 @@
17156 #include <asm/processor.h>
17157 #include <asm/mce.h>
17158 #include <asm/msr.h>
17159+#include <asm/pgtable.h>
17160
17161 /* By default disabled */
17162 int mce_p5_enabled __read_mostly;
17163@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17164 if (!cpu_has(c, X86_FEATURE_MCE))
17165 return;
17166
17167+ pax_open_kernel();
17168 machine_check_vector = pentium_machine_check;
17169+ pax_close_kernel();
17170 /* Make sure the vector pointer is visible before we enable MCEs: */
17171 wmb();
17172
17173diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17174index 47a1870..8c019a7 100644
17175--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17176+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17177@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17178 return notifier_from_errno(err);
17179 }
17180
17181-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17182+static struct notifier_block thermal_throttle_cpu_notifier =
17183 {
17184 .notifier_call = thermal_throttle_cpu_callback,
17185 };
17186diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17187index 2d7998f..17c9de1 100644
17188--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17189+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17190@@ -10,6 +10,7 @@
17191 #include <asm/processor.h>
17192 #include <asm/mce.h>
17193 #include <asm/msr.h>
17194+#include <asm/pgtable.h>
17195
17196 /* Machine check handler for WinChip C6: */
17197 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17198@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17199 {
17200 u32 lo, hi;
17201
17202+ pax_open_kernel();
17203 machine_check_vector = winchip_machine_check;
17204+ pax_close_kernel();
17205 /* Make sure the vector pointer is visible before we enable MCEs: */
17206 wmb();
17207
17208diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17209index 726bf96..81f0526 100644
17210--- a/arch/x86/kernel/cpu/mtrr/main.c
17211+++ b/arch/x86/kernel/cpu/mtrr/main.c
17212@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17213 u64 size_or_mask, size_and_mask;
17214 static bool mtrr_aps_delayed_init;
17215
17216-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17217+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17218
17219 const struct mtrr_ops *mtrr_if;
17220
17221diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17222index df5e41f..816c719 100644
17223--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17224+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17225@@ -25,7 +25,7 @@ struct mtrr_ops {
17226 int (*validate_add_page)(unsigned long base, unsigned long size,
17227 unsigned int type);
17228 int (*have_wrcomb)(void);
17229-};
17230+} __do_const;
17231
17232 extern int generic_get_free_region(unsigned long base, unsigned long size,
17233 int replace_reg);
17234diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17235index 6774c17..72c1b22 100644
17236--- a/arch/x86/kernel/cpu/perf_event.c
17237+++ b/arch/x86/kernel/cpu/perf_event.c
17238@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17239 pr_info("no hardware sampling interrupt available.\n");
17240 }
17241
17242-static struct attribute_group x86_pmu_format_group = {
17243+static attribute_group_no_const x86_pmu_format_group = {
17244 .name = "format",
17245 .attrs = NULL,
17246 };
17247@@ -1313,7 +1313,7 @@ static struct attribute_group x86_pmu_format_group = {
17248 struct perf_pmu_events_attr {
17249 struct device_attribute attr;
17250 u64 id;
17251-};
17252+} __do_const;
17253
17254 /*
17255 * Remove all undefined events (x86_pmu.event_map(id) == 0)
17256@@ -1381,7 +1381,7 @@ static struct attribute *events_attr[] = {
17257 NULL,
17258 };
17259
17260-static struct attribute_group x86_pmu_events_group = {
17261+static attribute_group_no_const x86_pmu_events_group = {
17262 .name = "events",
17263 .attrs = events_attr,
17264 };
17265@@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17266 if (idx > GDT_ENTRIES)
17267 return 0;
17268
17269- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17270+ desc = get_cpu_gdt_table(smp_processor_id());
17271 }
17272
17273 return get_desc_base(desc + idx);
17274@@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17275 break;
17276
17277 perf_callchain_store(entry, frame.return_address);
17278- fp = frame.next_frame;
17279+ fp = (const void __force_user *)frame.next_frame;
17280 }
17281 }
17282
17283diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17284index 4914e94..60b06e3 100644
17285--- a/arch/x86/kernel/cpu/perf_event_intel.c
17286+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17287@@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17288 * v2 and above have a perf capabilities MSR
17289 */
17290 if (version > 1) {
17291- u64 capabilities;
17292+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17293
17294- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17295- x86_pmu.intel_cap.capabilities = capabilities;
17296+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17297+ x86_pmu.intel_cap.capabilities = capabilities;
17298 }
17299
17300 intel_ds_init();
17301diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17302index b43200d..7fdcdbb 100644
17303--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17304+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17305@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17306 static int __init uncore_type_init(struct intel_uncore_type *type)
17307 {
17308 struct intel_uncore_pmu *pmus;
17309- struct attribute_group *events_group;
17310+ attribute_group_no_const *events_group;
17311 struct attribute **attrs;
17312 int i, j;
17313
17314@@ -2826,7 +2826,7 @@ static int
17315 return NOTIFY_OK;
17316 }
17317
17318-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17319+static struct notifier_block uncore_cpu_nb = {
17320 .notifier_call = uncore_cpu_notifier,
17321 /*
17322 * to migrate uncore events, our notifier should be executed
17323diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17324index e68a455..975a932 100644
17325--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17326+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17327@@ -428,7 +428,7 @@ struct intel_uncore_box {
17328 struct uncore_event_desc {
17329 struct kobj_attribute attr;
17330 const char *config;
17331-};
17332+} __do_const;
17333
17334 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17335 { \
17336diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17337index 60c7891..9e911d3 100644
17338--- a/arch/x86/kernel/cpuid.c
17339+++ b/arch/x86/kernel/cpuid.c
17340@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17341 return notifier_from_errno(err);
17342 }
17343
17344-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17345+static struct notifier_block cpuid_class_cpu_notifier =
17346 {
17347 .notifier_call = cpuid_class_cpu_callback,
17348 };
17349diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17350index 74467fe..18793d5 100644
17351--- a/arch/x86/kernel/crash.c
17352+++ b/arch/x86/kernel/crash.c
17353@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17354 {
17355 #ifdef CONFIG_X86_32
17356 struct pt_regs fixed_regs;
17357-#endif
17358
17359-#ifdef CONFIG_X86_32
17360- if (!user_mode_vm(regs)) {
17361+ if (!user_mode(regs)) {
17362 crash_fixup_ss_esp(&fixed_regs, regs);
17363 regs = &fixed_regs;
17364 }
17365diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17366index 37250fe..bf2ec74 100644
17367--- a/arch/x86/kernel/doublefault_32.c
17368+++ b/arch/x86/kernel/doublefault_32.c
17369@@ -11,7 +11,7 @@
17370
17371 #define DOUBLEFAULT_STACKSIZE (1024)
17372 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17373-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17374+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17375
17376 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17377
17378@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17379 unsigned long gdt, tss;
17380
17381 store_gdt(&gdt_desc);
17382- gdt = gdt_desc.address;
17383+ gdt = (unsigned long)gdt_desc.address;
17384
17385 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17386
17387@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17388 /* 0x2 bit is always set */
17389 .flags = X86_EFLAGS_SF | 0x2,
17390 .sp = STACK_START,
17391- .es = __USER_DS,
17392+ .es = __KERNEL_DS,
17393 .cs = __KERNEL_CS,
17394 .ss = __KERNEL_DS,
17395- .ds = __USER_DS,
17396+ .ds = __KERNEL_DS,
17397 .fs = __KERNEL_PERCPU,
17398
17399 .__cr3 = __pa_nodebug(swapper_pg_dir),
17400diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17401index ae42418b..787c16b 100644
17402--- a/arch/x86/kernel/dumpstack.c
17403+++ b/arch/x86/kernel/dumpstack.c
17404@@ -2,6 +2,9 @@
17405 * Copyright (C) 1991, 1992 Linus Torvalds
17406 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17407 */
17408+#ifdef CONFIG_GRKERNSEC_HIDESYM
17409+#define __INCLUDED_BY_HIDESYM 1
17410+#endif
17411 #include <linux/kallsyms.h>
17412 #include <linux/kprobes.h>
17413 #include <linux/uaccess.h>
17414@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17415 static void
17416 print_ftrace_graph_addr(unsigned long addr, void *data,
17417 const struct stacktrace_ops *ops,
17418- struct thread_info *tinfo, int *graph)
17419+ struct task_struct *task, int *graph)
17420 {
17421- struct task_struct *task;
17422 unsigned long ret_addr;
17423 int index;
17424
17425 if (addr != (unsigned long)return_to_handler)
17426 return;
17427
17428- task = tinfo->task;
17429 index = task->curr_ret_stack;
17430
17431 if (!task->ret_stack || index < *graph)
17432@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17433 static inline void
17434 print_ftrace_graph_addr(unsigned long addr, void *data,
17435 const struct stacktrace_ops *ops,
17436- struct thread_info *tinfo, int *graph)
17437+ struct task_struct *task, int *graph)
17438 { }
17439 #endif
17440
17441@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17442 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17443 */
17444
17445-static inline int valid_stack_ptr(struct thread_info *tinfo,
17446- void *p, unsigned int size, void *end)
17447+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17448 {
17449- void *t = tinfo;
17450 if (end) {
17451 if (p < end && p >= (end-THREAD_SIZE))
17452 return 1;
17453@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17454 }
17455
17456 unsigned long
17457-print_context_stack(struct thread_info *tinfo,
17458+print_context_stack(struct task_struct *task, void *stack_start,
17459 unsigned long *stack, unsigned long bp,
17460 const struct stacktrace_ops *ops, void *data,
17461 unsigned long *end, int *graph)
17462 {
17463 struct stack_frame *frame = (struct stack_frame *)bp;
17464
17465- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17466+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17467 unsigned long addr;
17468
17469 addr = *stack;
17470@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17471 } else {
17472 ops->address(data, addr, 0);
17473 }
17474- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17475+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17476 }
17477 stack++;
17478 }
17479@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17480 EXPORT_SYMBOL_GPL(print_context_stack);
17481
17482 unsigned long
17483-print_context_stack_bp(struct thread_info *tinfo,
17484+print_context_stack_bp(struct task_struct *task, void *stack_start,
17485 unsigned long *stack, unsigned long bp,
17486 const struct stacktrace_ops *ops, void *data,
17487 unsigned long *end, int *graph)
17488@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17489 struct stack_frame *frame = (struct stack_frame *)bp;
17490 unsigned long *ret_addr = &frame->return_address;
17491
17492- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17493+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17494 unsigned long addr = *ret_addr;
17495
17496 if (!__kernel_text_address(addr))
17497@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17498 ops->address(data, addr, 1);
17499 frame = frame->next_frame;
17500 ret_addr = &frame->return_address;
17501- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17502+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17503 }
17504
17505 return (unsigned long)frame;
17506@@ -189,7 +188,7 @@ void dump_stack(void)
17507
17508 bp = stack_frame(current, NULL);
17509 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17510- current->pid, current->comm, print_tainted(),
17511+ task_pid_nr(current), current->comm, print_tainted(),
17512 init_utsname()->release,
17513 (int)strcspn(init_utsname()->version, " "),
17514 init_utsname()->version);
17515@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17516 }
17517 EXPORT_SYMBOL_GPL(oops_begin);
17518
17519+extern void gr_handle_kernel_exploit(void);
17520+
17521 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17522 {
17523 if (regs && kexec_should_crash(current))
17524@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17525 panic("Fatal exception in interrupt");
17526 if (panic_on_oops)
17527 panic("Fatal exception");
17528- do_exit(signr);
17529+
17530+ gr_handle_kernel_exploit();
17531+
17532+ do_group_exit(signr);
17533 }
17534
17535 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17536@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17537 print_modules();
17538 show_regs(regs);
17539 #ifdef CONFIG_X86_32
17540- if (user_mode_vm(regs)) {
17541+ if (user_mode(regs)) {
17542 sp = regs->sp;
17543 ss = regs->ss & 0xffff;
17544 } else {
17545@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17546 unsigned long flags = oops_begin();
17547 int sig = SIGSEGV;
17548
17549- if (!user_mode_vm(regs))
17550+ if (!user_mode(regs))
17551 report_bug(regs->ip, regs);
17552
17553 if (__die(str, regs, err))
17554diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17555index 1038a41..db2c12b 100644
17556--- a/arch/x86/kernel/dumpstack_32.c
17557+++ b/arch/x86/kernel/dumpstack_32.c
17558@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17559 bp = stack_frame(task, regs);
17560
17561 for (;;) {
17562- struct thread_info *context;
17563+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17564
17565- context = (struct thread_info *)
17566- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17567- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17568+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17569
17570- stack = (unsigned long *)context->previous_esp;
17571- if (!stack)
17572+ if (stack_start == task_stack_page(task))
17573 break;
17574+ stack = *(unsigned long **)stack_start;
17575 if (ops->stack(data, "IRQ") < 0)
17576 break;
17577 touch_nmi_watchdog();
17578@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17579 {
17580 int i;
17581
17582- __show_regs(regs, !user_mode_vm(regs));
17583+ __show_regs(regs, !user_mode(regs));
17584
17585 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17586 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17587@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17588 * When in-kernel, we also print out the stack and code at the
17589 * time of the fault..
17590 */
17591- if (!user_mode_vm(regs)) {
17592+ if (!user_mode(regs)) {
17593 unsigned int code_prologue = code_bytes * 43 / 64;
17594 unsigned int code_len = code_bytes;
17595 unsigned char c;
17596 u8 *ip;
17597+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17598
17599 pr_emerg("Stack:\n");
17600 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17601
17602 pr_emerg("Code:");
17603
17604- ip = (u8 *)regs->ip - code_prologue;
17605+ ip = (u8 *)regs->ip - code_prologue + cs_base;
17606 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17607 /* try starting at IP */
17608- ip = (u8 *)regs->ip;
17609+ ip = (u8 *)regs->ip + cs_base;
17610 code_len = code_len - code_prologue + 1;
17611 }
17612 for (i = 0; i < code_len; i++, ip++) {
17613@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17614 pr_cont(" Bad EIP value.");
17615 break;
17616 }
17617- if (ip == (u8 *)regs->ip)
17618+ if (ip == (u8 *)regs->ip + cs_base)
17619 pr_cont(" <%02x>", c);
17620 else
17621 pr_cont(" %02x", c);
17622@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17623 {
17624 unsigned short ud2;
17625
17626+ ip = ktla_ktva(ip);
17627 if (ip < PAGE_OFFSET)
17628 return 0;
17629 if (probe_kernel_address((unsigned short *)ip, ud2))
17630@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17631
17632 return ud2 == 0x0b0f;
17633 }
17634+
17635+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17636+void pax_check_alloca(unsigned long size)
17637+{
17638+ unsigned long sp = (unsigned long)&sp, stack_left;
17639+
17640+ /* all kernel stacks are of the same size */
17641+ stack_left = sp & (THREAD_SIZE - 1);
17642+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17643+}
17644+EXPORT_SYMBOL(pax_check_alloca);
17645+#endif
17646diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17647index b653675..51cc8c0 100644
17648--- a/arch/x86/kernel/dumpstack_64.c
17649+++ b/arch/x86/kernel/dumpstack_64.c
17650@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17651 unsigned long *irq_stack_end =
17652 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17653 unsigned used = 0;
17654- struct thread_info *tinfo;
17655 int graph = 0;
17656 unsigned long dummy;
17657+ void *stack_start;
17658
17659 if (!task)
17660 task = current;
17661@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17662 * current stack address. If the stacks consist of nested
17663 * exceptions
17664 */
17665- tinfo = task_thread_info(task);
17666 for (;;) {
17667 char *id;
17668 unsigned long *estack_end;
17669+
17670 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17671 &used, &id);
17672
17673@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17674 if (ops->stack(data, id) < 0)
17675 break;
17676
17677- bp = ops->walk_stack(tinfo, stack, bp, ops,
17678+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17679 data, estack_end, &graph);
17680 ops->stack(data, "<EOE>");
17681 /*
17682@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17683 * second-to-last pointer (index -2 to end) in the
17684 * exception stack:
17685 */
17686+ if ((u16)estack_end[-1] != __KERNEL_DS)
17687+ goto out;
17688 stack = (unsigned long *) estack_end[-2];
17689 continue;
17690 }
17691@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17692 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17693 if (ops->stack(data, "IRQ") < 0)
17694 break;
17695- bp = ops->walk_stack(tinfo, stack, bp,
17696+ bp = ops->walk_stack(task, irq_stack, stack, bp,
17697 ops, data, irq_stack_end, &graph);
17698 /*
17699 * We link to the next stack (which would be
17700@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17701 /*
17702 * This handles the process stack:
17703 */
17704- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17705+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17706+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17707+out:
17708 put_cpu();
17709 }
17710 EXPORT_SYMBOL(dump_trace);
17711@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17712 {
17713 int i;
17714 unsigned long sp;
17715- const int cpu = smp_processor_id();
17716+ const int cpu = raw_smp_processor_id();
17717 struct task_struct *cur = current;
17718
17719 sp = regs->sp;
17720@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17721
17722 return ud2 == 0x0b0f;
17723 }
17724+
17725+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17726+void pax_check_alloca(unsigned long size)
17727+{
17728+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17729+ unsigned cpu, used;
17730+ char *id;
17731+
17732+ /* check the process stack first */
17733+ stack_start = (unsigned long)task_stack_page(current);
17734+ stack_end = stack_start + THREAD_SIZE;
17735+ if (likely(stack_start <= sp && sp < stack_end)) {
17736+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
17737+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17738+ return;
17739+ }
17740+
17741+ cpu = get_cpu();
17742+
17743+ /* check the irq stacks */
17744+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17745+ stack_start = stack_end - IRQ_STACK_SIZE;
17746+ if (stack_start <= sp && sp < stack_end) {
17747+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17748+ put_cpu();
17749+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17750+ return;
17751+ }
17752+
17753+ /* check the exception stacks */
17754+ used = 0;
17755+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17756+ stack_start = stack_end - EXCEPTION_STKSZ;
17757+ if (stack_end && stack_start <= sp && sp < stack_end) {
17758+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17759+ put_cpu();
17760+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
17761+ return;
17762+ }
17763+
17764+ put_cpu();
17765+
17766+ /* unknown stack */
17767+ BUG();
17768+}
17769+EXPORT_SYMBOL(pax_check_alloca);
17770+#endif
17771diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17772index 9b9f18b..9fcaa04 100644
17773--- a/arch/x86/kernel/early_printk.c
17774+++ b/arch/x86/kernel/early_printk.c
17775@@ -7,6 +7,7 @@
17776 #include <linux/pci_regs.h>
17777 #include <linux/pci_ids.h>
17778 #include <linux/errno.h>
17779+#include <linux/sched.h>
17780 #include <asm/io.h>
17781 #include <asm/processor.h>
17782 #include <asm/fcntl.h>
17783diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17784index 6ed91d9..6cc365b 100644
17785--- a/arch/x86/kernel/entry_32.S
17786+++ b/arch/x86/kernel/entry_32.S
17787@@ -177,13 +177,153 @@
17788 /*CFI_REL_OFFSET gs, PT_GS*/
17789 .endm
17790 .macro SET_KERNEL_GS reg
17791+
17792+#ifdef CONFIG_CC_STACKPROTECTOR
17793 movl $(__KERNEL_STACK_CANARY), \reg
17794+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17795+ movl $(__USER_DS), \reg
17796+#else
17797+ xorl \reg, \reg
17798+#endif
17799+
17800 movl \reg, %gs
17801 .endm
17802
17803 #endif /* CONFIG_X86_32_LAZY_GS */
17804
17805-.macro SAVE_ALL
17806+.macro pax_enter_kernel
17807+#ifdef CONFIG_PAX_KERNEXEC
17808+ call pax_enter_kernel
17809+#endif
17810+.endm
17811+
17812+.macro pax_exit_kernel
17813+#ifdef CONFIG_PAX_KERNEXEC
17814+ call pax_exit_kernel
17815+#endif
17816+.endm
17817+
17818+#ifdef CONFIG_PAX_KERNEXEC
17819+ENTRY(pax_enter_kernel)
17820+#ifdef CONFIG_PARAVIRT
17821+ pushl %eax
17822+ pushl %ecx
17823+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17824+ mov %eax, %esi
17825+#else
17826+ mov %cr0, %esi
17827+#endif
17828+ bts $16, %esi
17829+ jnc 1f
17830+ mov %cs, %esi
17831+ cmp $__KERNEL_CS, %esi
17832+ jz 3f
17833+ ljmp $__KERNEL_CS, $3f
17834+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17835+2:
17836+#ifdef CONFIG_PARAVIRT
17837+ mov %esi, %eax
17838+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17839+#else
17840+ mov %esi, %cr0
17841+#endif
17842+3:
17843+#ifdef CONFIG_PARAVIRT
17844+ popl %ecx
17845+ popl %eax
17846+#endif
17847+ ret
17848+ENDPROC(pax_enter_kernel)
17849+
17850+ENTRY(pax_exit_kernel)
17851+#ifdef CONFIG_PARAVIRT
17852+ pushl %eax
17853+ pushl %ecx
17854+#endif
17855+ mov %cs, %esi
17856+ cmp $__KERNEXEC_KERNEL_CS, %esi
17857+ jnz 2f
17858+#ifdef CONFIG_PARAVIRT
17859+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17860+ mov %eax, %esi
17861+#else
17862+ mov %cr0, %esi
17863+#endif
17864+ btr $16, %esi
17865+ ljmp $__KERNEL_CS, $1f
17866+1:
17867+#ifdef CONFIG_PARAVIRT
17868+ mov %esi, %eax
17869+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17870+#else
17871+ mov %esi, %cr0
17872+#endif
17873+2:
17874+#ifdef CONFIG_PARAVIRT
17875+ popl %ecx
17876+ popl %eax
17877+#endif
17878+ ret
17879+ENDPROC(pax_exit_kernel)
17880+#endif
17881+
17882+.macro pax_erase_kstack
17883+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17884+ call pax_erase_kstack
17885+#endif
17886+.endm
17887+
17888+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17889+/*
17890+ * ebp: thread_info
17891+ */
17892+ENTRY(pax_erase_kstack)
17893+ pushl %edi
17894+ pushl %ecx
17895+ pushl %eax
17896+
17897+ mov TI_lowest_stack(%ebp), %edi
17898+ mov $-0xBEEF, %eax
17899+ std
17900+
17901+1: mov %edi, %ecx
17902+ and $THREAD_SIZE_asm - 1, %ecx
17903+ shr $2, %ecx
17904+ repne scasl
17905+ jecxz 2f
17906+
17907+ cmp $2*16, %ecx
17908+ jc 2f
17909+
17910+ mov $2*16, %ecx
17911+ repe scasl
17912+ jecxz 2f
17913+ jne 1b
17914+
17915+2: cld
17916+ mov %esp, %ecx
17917+ sub %edi, %ecx
17918+
17919+ cmp $THREAD_SIZE_asm, %ecx
17920+ jb 3f
17921+ ud2
17922+3:
17923+
17924+ shr $2, %ecx
17925+ rep stosl
17926+
17927+ mov TI_task_thread_sp0(%ebp), %edi
17928+ sub $128, %edi
17929+ mov %edi, TI_lowest_stack(%ebp)
17930+
17931+ popl %eax
17932+ popl %ecx
17933+ popl %edi
17934+ ret
17935+ENDPROC(pax_erase_kstack)
17936+#endif
17937+
17938+.macro __SAVE_ALL _DS
17939 cld
17940 PUSH_GS
17941 pushl_cfi %fs
17942@@ -206,7 +346,7 @@
17943 CFI_REL_OFFSET ecx, 0
17944 pushl_cfi %ebx
17945 CFI_REL_OFFSET ebx, 0
17946- movl $(__USER_DS), %edx
17947+ movl $\_DS, %edx
17948 movl %edx, %ds
17949 movl %edx, %es
17950 movl $(__KERNEL_PERCPU), %edx
17951@@ -214,6 +354,15 @@
17952 SET_KERNEL_GS %edx
17953 .endm
17954
17955+.macro SAVE_ALL
17956+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17957+ __SAVE_ALL __KERNEL_DS
17958+ pax_enter_kernel
17959+#else
17960+ __SAVE_ALL __USER_DS
17961+#endif
17962+.endm
17963+
17964 .macro RESTORE_INT_REGS
17965 popl_cfi %ebx
17966 CFI_RESTORE ebx
17967@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17968 popfl_cfi
17969 jmp syscall_exit
17970 CFI_ENDPROC
17971-END(ret_from_fork)
17972+ENDPROC(ret_from_fork)
17973
17974 ENTRY(ret_from_kernel_thread)
17975 CFI_STARTPROC
17976@@ -344,7 +493,15 @@ ret_from_intr:
17977 andl $SEGMENT_RPL_MASK, %eax
17978 #endif
17979 cmpl $USER_RPL, %eax
17980+
17981+#ifdef CONFIG_PAX_KERNEXEC
17982+ jae resume_userspace
17983+
17984+ pax_exit_kernel
17985+ jmp resume_kernel
17986+#else
17987 jb resume_kernel # not returning to v8086 or userspace
17988+#endif
17989
17990 ENTRY(resume_userspace)
17991 LOCKDEP_SYS_EXIT
17992@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17993 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17994 # int/exception return?
17995 jne work_pending
17996- jmp restore_all
17997-END(ret_from_exception)
17998+ jmp restore_all_pax
17999+ENDPROC(ret_from_exception)
18000
18001 #ifdef CONFIG_PREEMPT
18002 ENTRY(resume_kernel)
18003@@ -372,7 +529,7 @@ need_resched:
18004 jz restore_all
18005 call preempt_schedule_irq
18006 jmp need_resched
18007-END(resume_kernel)
18008+ENDPROC(resume_kernel)
18009 #endif
18010 CFI_ENDPROC
18011 /*
18012@@ -406,30 +563,45 @@ sysenter_past_esp:
18013 /*CFI_REL_OFFSET cs, 0*/
18014 /*
18015 * Push current_thread_info()->sysenter_return to the stack.
18016- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18017- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18018 */
18019- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18020+ pushl_cfi $0
18021 CFI_REL_OFFSET eip, 0
18022
18023 pushl_cfi %eax
18024 SAVE_ALL
18025+ GET_THREAD_INFO(%ebp)
18026+ movl TI_sysenter_return(%ebp),%ebp
18027+ movl %ebp,PT_EIP(%esp)
18028 ENABLE_INTERRUPTS(CLBR_NONE)
18029
18030 /*
18031 * Load the potential sixth argument from user stack.
18032 * Careful about security.
18033 */
18034+ movl PT_OLDESP(%esp),%ebp
18035+
18036+#ifdef CONFIG_PAX_MEMORY_UDEREF
18037+ mov PT_OLDSS(%esp),%ds
18038+1: movl %ds:(%ebp),%ebp
18039+ push %ss
18040+ pop %ds
18041+#else
18042 cmpl $__PAGE_OFFSET-3,%ebp
18043 jae syscall_fault
18044 ASM_STAC
18045 1: movl (%ebp),%ebp
18046 ASM_CLAC
18047+#endif
18048+
18049 movl %ebp,PT_EBP(%esp)
18050 _ASM_EXTABLE(1b,syscall_fault)
18051
18052 GET_THREAD_INFO(%ebp)
18053
18054+#ifdef CONFIG_PAX_RANDKSTACK
18055+ pax_erase_kstack
18056+#endif
18057+
18058 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18059 jnz sysenter_audit
18060 sysenter_do_call:
18061@@ -444,12 +616,24 @@ sysenter_do_call:
18062 testl $_TIF_ALLWORK_MASK, %ecx
18063 jne sysexit_audit
18064 sysenter_exit:
18065+
18066+#ifdef CONFIG_PAX_RANDKSTACK
18067+ pushl_cfi %eax
18068+ movl %esp, %eax
18069+ call pax_randomize_kstack
18070+ popl_cfi %eax
18071+#endif
18072+
18073+ pax_erase_kstack
18074+
18075 /* if something modifies registers it must also disable sysexit */
18076 movl PT_EIP(%esp), %edx
18077 movl PT_OLDESP(%esp), %ecx
18078 xorl %ebp,%ebp
18079 TRACE_IRQS_ON
18080 1: mov PT_FS(%esp), %fs
18081+2: mov PT_DS(%esp), %ds
18082+3: mov PT_ES(%esp), %es
18083 PTGS_TO_GS
18084 ENABLE_INTERRUPTS_SYSEXIT
18085
18086@@ -466,6 +650,9 @@ sysenter_audit:
18087 movl %eax,%edx /* 2nd arg: syscall number */
18088 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18089 call __audit_syscall_entry
18090+
18091+ pax_erase_kstack
18092+
18093 pushl_cfi %ebx
18094 movl PT_EAX(%esp),%eax /* reload syscall number */
18095 jmp sysenter_do_call
18096@@ -491,10 +678,16 @@ sysexit_audit:
18097
18098 CFI_ENDPROC
18099 .pushsection .fixup,"ax"
18100-2: movl $0,PT_FS(%esp)
18101+4: movl $0,PT_FS(%esp)
18102+ jmp 1b
18103+5: movl $0,PT_DS(%esp)
18104+ jmp 1b
18105+6: movl $0,PT_ES(%esp)
18106 jmp 1b
18107 .popsection
18108- _ASM_EXTABLE(1b,2b)
18109+ _ASM_EXTABLE(1b,4b)
18110+ _ASM_EXTABLE(2b,5b)
18111+ _ASM_EXTABLE(3b,6b)
18112 PTGS_TO_GS_EX
18113 ENDPROC(ia32_sysenter_target)
18114
18115@@ -509,6 +702,11 @@ ENTRY(system_call)
18116 pushl_cfi %eax # save orig_eax
18117 SAVE_ALL
18118 GET_THREAD_INFO(%ebp)
18119+
18120+#ifdef CONFIG_PAX_RANDKSTACK
18121+ pax_erase_kstack
18122+#endif
18123+
18124 # system call tracing in operation / emulation
18125 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18126 jnz syscall_trace_entry
18127@@ -527,6 +725,15 @@ syscall_exit:
18128 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18129 jne syscall_exit_work
18130
18131+restore_all_pax:
18132+
18133+#ifdef CONFIG_PAX_RANDKSTACK
18134+ movl %esp, %eax
18135+ call pax_randomize_kstack
18136+#endif
18137+
18138+ pax_erase_kstack
18139+
18140 restore_all:
18141 TRACE_IRQS_IRET
18142 restore_all_notrace:
18143@@ -583,14 +790,34 @@ ldt_ss:
18144 * compensating for the offset by changing to the ESPFIX segment with
18145 * a base address that matches for the difference.
18146 */
18147-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18148+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18149 mov %esp, %edx /* load kernel esp */
18150 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18151 mov %dx, %ax /* eax: new kernel esp */
18152 sub %eax, %edx /* offset (low word is 0) */
18153+#ifdef CONFIG_SMP
18154+ movl PER_CPU_VAR(cpu_number), %ebx
18155+ shll $PAGE_SHIFT_asm, %ebx
18156+ addl $cpu_gdt_table, %ebx
18157+#else
18158+ movl $cpu_gdt_table, %ebx
18159+#endif
18160 shr $16, %edx
18161- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18162- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18163+
18164+#ifdef CONFIG_PAX_KERNEXEC
18165+ mov %cr0, %esi
18166+ btr $16, %esi
18167+ mov %esi, %cr0
18168+#endif
18169+
18170+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18171+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18172+
18173+#ifdef CONFIG_PAX_KERNEXEC
18174+ bts $16, %esi
18175+ mov %esi, %cr0
18176+#endif
18177+
18178 pushl_cfi $__ESPFIX_SS
18179 pushl_cfi %eax /* new kernel esp */
18180 /* Disable interrupts, but do not irqtrace this section: we
18181@@ -619,20 +846,18 @@ work_resched:
18182 movl TI_flags(%ebp), %ecx
18183 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18184 # than syscall tracing?
18185- jz restore_all
18186+ jz restore_all_pax
18187 testb $_TIF_NEED_RESCHED, %cl
18188 jnz work_resched
18189
18190 work_notifysig: # deal with pending signals and
18191 # notify-resume requests
18192+ movl %esp, %eax
18193 #ifdef CONFIG_VM86
18194 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18195- movl %esp, %eax
18196 jne work_notifysig_v86 # returning to kernel-space or
18197 # vm86-space
18198 1:
18199-#else
18200- movl %esp, %eax
18201 #endif
18202 TRACE_IRQS_ON
18203 ENABLE_INTERRUPTS(CLBR_NONE)
18204@@ -653,7 +878,7 @@ work_notifysig_v86:
18205 movl %eax, %esp
18206 jmp 1b
18207 #endif
18208-END(work_pending)
18209+ENDPROC(work_pending)
18210
18211 # perform syscall exit tracing
18212 ALIGN
18213@@ -661,11 +886,14 @@ syscall_trace_entry:
18214 movl $-ENOSYS,PT_EAX(%esp)
18215 movl %esp, %eax
18216 call syscall_trace_enter
18217+
18218+ pax_erase_kstack
18219+
18220 /* What it returned is what we'll actually use. */
18221 cmpl $(NR_syscalls), %eax
18222 jnae syscall_call
18223 jmp syscall_exit
18224-END(syscall_trace_entry)
18225+ENDPROC(syscall_trace_entry)
18226
18227 # perform syscall exit tracing
18228 ALIGN
18229@@ -678,21 +906,25 @@ syscall_exit_work:
18230 movl %esp, %eax
18231 call syscall_trace_leave
18232 jmp resume_userspace
18233-END(syscall_exit_work)
18234+ENDPROC(syscall_exit_work)
18235 CFI_ENDPROC
18236
18237 RING0_INT_FRAME # can't unwind into user space anyway
18238 syscall_fault:
18239+#ifdef CONFIG_PAX_MEMORY_UDEREF
18240+ push %ss
18241+ pop %ds
18242+#endif
18243 ASM_CLAC
18244 GET_THREAD_INFO(%ebp)
18245 movl $-EFAULT,PT_EAX(%esp)
18246 jmp resume_userspace
18247-END(syscall_fault)
18248+ENDPROC(syscall_fault)
18249
18250 syscall_badsys:
18251 movl $-ENOSYS,PT_EAX(%esp)
18252 jmp resume_userspace
18253-END(syscall_badsys)
18254+ENDPROC(syscall_badsys)
18255 CFI_ENDPROC
18256 /*
18257 * End of kprobes section
18258@@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18259 * normal stack and adjusts ESP with the matching offset.
18260 */
18261 /* fixup the stack */
18262- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18263- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18264+#ifdef CONFIG_SMP
18265+ movl PER_CPU_VAR(cpu_number), %ebx
18266+ shll $PAGE_SHIFT_asm, %ebx
18267+ addl $cpu_gdt_table, %ebx
18268+#else
18269+ movl $cpu_gdt_table, %ebx
18270+#endif
18271+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18272+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18273 shl $16, %eax
18274 addl %esp, %eax /* the adjusted stack pointer */
18275 pushl_cfi $__KERNEL_DS
18276@@ -807,7 +1046,7 @@ vector=vector+1
18277 .endr
18278 2: jmp common_interrupt
18279 .endr
18280-END(irq_entries_start)
18281+ENDPROC(irq_entries_start)
18282
18283 .previous
18284 END(interrupt)
18285@@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18286 pushl_cfi $do_coprocessor_error
18287 jmp error_code
18288 CFI_ENDPROC
18289-END(coprocessor_error)
18290+ENDPROC(coprocessor_error)
18291
18292 ENTRY(simd_coprocessor_error)
18293 RING0_INT_FRAME
18294@@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18295 #endif
18296 jmp error_code
18297 CFI_ENDPROC
18298-END(simd_coprocessor_error)
18299+ENDPROC(simd_coprocessor_error)
18300
18301 ENTRY(device_not_available)
18302 RING0_INT_FRAME
18303@@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18304 pushl_cfi $do_device_not_available
18305 jmp error_code
18306 CFI_ENDPROC
18307-END(device_not_available)
18308+ENDPROC(device_not_available)
18309
18310 #ifdef CONFIG_PARAVIRT
18311 ENTRY(native_iret)
18312 iret
18313 _ASM_EXTABLE(native_iret, iret_exc)
18314-END(native_iret)
18315+ENDPROC(native_iret)
18316
18317 ENTRY(native_irq_enable_sysexit)
18318 sti
18319 sysexit
18320-END(native_irq_enable_sysexit)
18321+ENDPROC(native_irq_enable_sysexit)
18322 #endif
18323
18324 ENTRY(overflow)
18325@@ -910,7 +1149,7 @@ ENTRY(overflow)
18326 pushl_cfi $do_overflow
18327 jmp error_code
18328 CFI_ENDPROC
18329-END(overflow)
18330+ENDPROC(overflow)
18331
18332 ENTRY(bounds)
18333 RING0_INT_FRAME
18334@@ -919,7 +1158,7 @@ ENTRY(bounds)
18335 pushl_cfi $do_bounds
18336 jmp error_code
18337 CFI_ENDPROC
18338-END(bounds)
18339+ENDPROC(bounds)
18340
18341 ENTRY(invalid_op)
18342 RING0_INT_FRAME
18343@@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18344 pushl_cfi $do_invalid_op
18345 jmp error_code
18346 CFI_ENDPROC
18347-END(invalid_op)
18348+ENDPROC(invalid_op)
18349
18350 ENTRY(coprocessor_segment_overrun)
18351 RING0_INT_FRAME
18352@@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18353 pushl_cfi $do_coprocessor_segment_overrun
18354 jmp error_code
18355 CFI_ENDPROC
18356-END(coprocessor_segment_overrun)
18357+ENDPROC(coprocessor_segment_overrun)
18358
18359 ENTRY(invalid_TSS)
18360 RING0_EC_FRAME
18361@@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18362 pushl_cfi $do_invalid_TSS
18363 jmp error_code
18364 CFI_ENDPROC
18365-END(invalid_TSS)
18366+ENDPROC(invalid_TSS)
18367
18368 ENTRY(segment_not_present)
18369 RING0_EC_FRAME
18370@@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18371 pushl_cfi $do_segment_not_present
18372 jmp error_code
18373 CFI_ENDPROC
18374-END(segment_not_present)
18375+ENDPROC(segment_not_present)
18376
18377 ENTRY(stack_segment)
18378 RING0_EC_FRAME
18379@@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18380 pushl_cfi $do_stack_segment
18381 jmp error_code
18382 CFI_ENDPROC
18383-END(stack_segment)
18384+ENDPROC(stack_segment)
18385
18386 ENTRY(alignment_check)
18387 RING0_EC_FRAME
18388@@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18389 pushl_cfi $do_alignment_check
18390 jmp error_code
18391 CFI_ENDPROC
18392-END(alignment_check)
18393+ENDPROC(alignment_check)
18394
18395 ENTRY(divide_error)
18396 RING0_INT_FRAME
18397@@ -978,7 +1217,7 @@ ENTRY(divide_error)
18398 pushl_cfi $do_divide_error
18399 jmp error_code
18400 CFI_ENDPROC
18401-END(divide_error)
18402+ENDPROC(divide_error)
18403
18404 #ifdef CONFIG_X86_MCE
18405 ENTRY(machine_check)
18406@@ -988,7 +1227,7 @@ ENTRY(machine_check)
18407 pushl_cfi machine_check_vector
18408 jmp error_code
18409 CFI_ENDPROC
18410-END(machine_check)
18411+ENDPROC(machine_check)
18412 #endif
18413
18414 ENTRY(spurious_interrupt_bug)
18415@@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18416 pushl_cfi $do_spurious_interrupt_bug
18417 jmp error_code
18418 CFI_ENDPROC
18419-END(spurious_interrupt_bug)
18420+ENDPROC(spurious_interrupt_bug)
18421 /*
18422 * End of kprobes section
18423 */
18424@@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18425
18426 ENTRY(mcount)
18427 ret
18428-END(mcount)
18429+ENDPROC(mcount)
18430
18431 ENTRY(ftrace_caller)
18432 cmpl $0, function_trace_stop
18433@@ -1134,7 +1373,7 @@ ftrace_graph_call:
18434 .globl ftrace_stub
18435 ftrace_stub:
18436 ret
18437-END(ftrace_caller)
18438+ENDPROC(ftrace_caller)
18439
18440 ENTRY(ftrace_regs_caller)
18441 pushf /* push flags before compare (in cs location) */
18442@@ -1235,7 +1474,7 @@ trace:
18443 popl %ecx
18444 popl %eax
18445 jmp ftrace_stub
18446-END(mcount)
18447+ENDPROC(mcount)
18448 #endif /* CONFIG_DYNAMIC_FTRACE */
18449 #endif /* CONFIG_FUNCTION_TRACER */
18450
18451@@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18452 popl %ecx
18453 popl %eax
18454 ret
18455-END(ftrace_graph_caller)
18456+ENDPROC(ftrace_graph_caller)
18457
18458 .globl return_to_handler
18459 return_to_handler:
18460@@ -1309,15 +1548,18 @@ error_code:
18461 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18462 REG_TO_PTGS %ecx
18463 SET_KERNEL_GS %ecx
18464- movl $(__USER_DS), %ecx
18465+ movl $(__KERNEL_DS), %ecx
18466 movl %ecx, %ds
18467 movl %ecx, %es
18468+
18469+ pax_enter_kernel
18470+
18471 TRACE_IRQS_OFF
18472 movl %esp,%eax # pt_regs pointer
18473 call *%edi
18474 jmp ret_from_exception
18475 CFI_ENDPROC
18476-END(page_fault)
18477+ENDPROC(page_fault)
18478
18479 /*
18480 * Debug traps and NMI can happen at the one SYSENTER instruction
18481@@ -1360,7 +1602,7 @@ debug_stack_correct:
18482 call do_debug
18483 jmp ret_from_exception
18484 CFI_ENDPROC
18485-END(debug)
18486+ENDPROC(debug)
18487
18488 /*
18489 * NMI is doubly nasty. It can happen _while_ we're handling
18490@@ -1398,6 +1640,9 @@ nmi_stack_correct:
18491 xorl %edx,%edx # zero error code
18492 movl %esp,%eax # pt_regs pointer
18493 call do_nmi
18494+
18495+ pax_exit_kernel
18496+
18497 jmp restore_all_notrace
18498 CFI_ENDPROC
18499
18500@@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18501 FIXUP_ESPFIX_STACK # %eax == %esp
18502 xorl %edx,%edx # zero error code
18503 call do_nmi
18504+
18505+ pax_exit_kernel
18506+
18507 RESTORE_REGS
18508 lss 12+4(%esp), %esp # back to espfix stack
18509 CFI_ADJUST_CFA_OFFSET -24
18510 jmp irq_return
18511 CFI_ENDPROC
18512-END(nmi)
18513+ENDPROC(nmi)
18514
18515 ENTRY(int3)
18516 RING0_INT_FRAME
18517@@ -1452,14 +1700,14 @@ ENTRY(int3)
18518 call do_int3
18519 jmp ret_from_exception
18520 CFI_ENDPROC
18521-END(int3)
18522+ENDPROC(int3)
18523
18524 ENTRY(general_protection)
18525 RING0_EC_FRAME
18526 pushl_cfi $do_general_protection
18527 jmp error_code
18528 CFI_ENDPROC
18529-END(general_protection)
18530+ENDPROC(general_protection)
18531
18532 #ifdef CONFIG_KVM_GUEST
18533 ENTRY(async_page_fault)
18534@@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18535 pushl_cfi $do_async_page_fault
18536 jmp error_code
18537 CFI_ENDPROC
18538-END(async_page_fault)
18539+ENDPROC(async_page_fault)
18540 #endif
18541
18542 /*
18543diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18544index cb3c591..bc63707 100644
18545--- a/arch/x86/kernel/entry_64.S
18546+++ b/arch/x86/kernel/entry_64.S
18547@@ -59,6 +59,8 @@
18548 #include <asm/context_tracking.h>
18549 #include <asm/smap.h>
18550 #include <linux/err.h>
18551+#include <asm/pgtable.h>
18552+#include <asm/alternative-asm.h>
18553
18554 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18555 #include <linux/elf-em.h>
18556@@ -80,8 +82,9 @@
18557 #ifdef CONFIG_DYNAMIC_FTRACE
18558
18559 ENTRY(function_hook)
18560+ pax_force_retaddr
18561 retq
18562-END(function_hook)
18563+ENDPROC(function_hook)
18564
18565 /* skip is set if stack has been adjusted */
18566 .macro ftrace_caller_setup skip=0
18567@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18568 #endif
18569
18570 GLOBAL(ftrace_stub)
18571+ pax_force_retaddr
18572 retq
18573-END(ftrace_caller)
18574+ENDPROC(ftrace_caller)
18575
18576 ENTRY(ftrace_regs_caller)
18577 /* Save the current flags before compare (in SS location)*/
18578@@ -191,7 +195,7 @@ ftrace_restore_flags:
18579 popfq
18580 jmp ftrace_stub
18581
18582-END(ftrace_regs_caller)
18583+ENDPROC(ftrace_regs_caller)
18584
18585
18586 #else /* ! CONFIG_DYNAMIC_FTRACE */
18587@@ -212,6 +216,7 @@ ENTRY(function_hook)
18588 #endif
18589
18590 GLOBAL(ftrace_stub)
18591+ pax_force_retaddr
18592 retq
18593
18594 trace:
18595@@ -225,12 +230,13 @@ trace:
18596 #endif
18597 subq $MCOUNT_INSN_SIZE, %rdi
18598
18599+ pax_force_fptr ftrace_trace_function
18600 call *ftrace_trace_function
18601
18602 MCOUNT_RESTORE_FRAME
18603
18604 jmp ftrace_stub
18605-END(function_hook)
18606+ENDPROC(function_hook)
18607 #endif /* CONFIG_DYNAMIC_FTRACE */
18608 #endif /* CONFIG_FUNCTION_TRACER */
18609
18610@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18611
18612 MCOUNT_RESTORE_FRAME
18613
18614+ pax_force_retaddr
18615 retq
18616-END(ftrace_graph_caller)
18617+ENDPROC(ftrace_graph_caller)
18618
18619 GLOBAL(return_to_handler)
18620 subq $24, %rsp
18621@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18622 movq 8(%rsp), %rdx
18623 movq (%rsp), %rax
18624 addq $24, %rsp
18625+ pax_force_fptr %rdi
18626 jmp *%rdi
18627+ENDPROC(return_to_handler)
18628 #endif
18629
18630
18631@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18632 ENDPROC(native_usergs_sysret64)
18633 #endif /* CONFIG_PARAVIRT */
18634
18635+ .macro ljmpq sel, off
18636+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18637+ .byte 0x48; ljmp *1234f(%rip)
18638+ .pushsection .rodata
18639+ .align 16
18640+ 1234: .quad \off; .word \sel
18641+ .popsection
18642+#else
18643+ pushq $\sel
18644+ pushq $\off
18645+ lretq
18646+#endif
18647+ .endm
18648+
18649+ .macro pax_enter_kernel
18650+ pax_set_fptr_mask
18651+#ifdef CONFIG_PAX_KERNEXEC
18652+ call pax_enter_kernel
18653+#endif
18654+ .endm
18655+
18656+ .macro pax_exit_kernel
18657+#ifdef CONFIG_PAX_KERNEXEC
18658+ call pax_exit_kernel
18659+#endif
18660+ .endm
18661+
18662+#ifdef CONFIG_PAX_KERNEXEC
18663+ENTRY(pax_enter_kernel)
18664+ pushq %rdi
18665+
18666+#ifdef CONFIG_PARAVIRT
18667+ PV_SAVE_REGS(CLBR_RDI)
18668+#endif
18669+
18670+ GET_CR0_INTO_RDI
18671+ bts $16,%rdi
18672+ jnc 3f
18673+ mov %cs,%edi
18674+ cmp $__KERNEL_CS,%edi
18675+ jnz 2f
18676+1:
18677+
18678+#ifdef CONFIG_PARAVIRT
18679+ PV_RESTORE_REGS(CLBR_RDI)
18680+#endif
18681+
18682+ popq %rdi
18683+ pax_force_retaddr
18684+ retq
18685+
18686+2: ljmpq __KERNEL_CS,1f
18687+3: ljmpq __KERNEXEC_KERNEL_CS,4f
18688+4: SET_RDI_INTO_CR0
18689+ jmp 1b
18690+ENDPROC(pax_enter_kernel)
18691+
18692+ENTRY(pax_exit_kernel)
18693+ pushq %rdi
18694+
18695+#ifdef CONFIG_PARAVIRT
18696+ PV_SAVE_REGS(CLBR_RDI)
18697+#endif
18698+
18699+ mov %cs,%rdi
18700+ cmp $__KERNEXEC_KERNEL_CS,%edi
18701+ jz 2f
18702+1:
18703+
18704+#ifdef CONFIG_PARAVIRT
18705+ PV_RESTORE_REGS(CLBR_RDI);
18706+#endif
18707+
18708+ popq %rdi
18709+ pax_force_retaddr
18710+ retq
18711+
18712+2: GET_CR0_INTO_RDI
18713+ btr $16,%rdi
18714+ ljmpq __KERNEL_CS,3f
18715+3: SET_RDI_INTO_CR0
18716+ jmp 1b
18717+ENDPROC(pax_exit_kernel)
18718+#endif
18719+
18720+ .macro pax_enter_kernel_user
18721+ pax_set_fptr_mask
18722+#ifdef CONFIG_PAX_MEMORY_UDEREF
18723+ call pax_enter_kernel_user
18724+#endif
18725+ .endm
18726+
18727+ .macro pax_exit_kernel_user
18728+#ifdef CONFIG_PAX_MEMORY_UDEREF
18729+ call pax_exit_kernel_user
18730+#endif
18731+#ifdef CONFIG_PAX_RANDKSTACK
18732+ pushq %rax
18733+ call pax_randomize_kstack
18734+ popq %rax
18735+#endif
18736+ .endm
18737+
18738+#ifdef CONFIG_PAX_MEMORY_UDEREF
18739+ENTRY(pax_enter_kernel_user)
18740+ pushq %rdi
18741+ pushq %rbx
18742+
18743+#ifdef CONFIG_PARAVIRT
18744+ PV_SAVE_REGS(CLBR_RDI)
18745+#endif
18746+
18747+ GET_CR3_INTO_RDI
18748+ mov %rdi,%rbx
18749+ add $__START_KERNEL_map,%rbx
18750+ sub phys_base(%rip),%rbx
18751+
18752+#ifdef CONFIG_PARAVIRT
18753+ pushq %rdi
18754+ cmpl $0, pv_info+PARAVIRT_enabled
18755+ jz 1f
18756+ i = 0
18757+ .rept USER_PGD_PTRS
18758+ mov i*8(%rbx),%rsi
18759+ mov $0,%sil
18760+ lea i*8(%rbx),%rdi
18761+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18762+ i = i + 1
18763+ .endr
18764+ jmp 2f
18765+1:
18766+#endif
18767+
18768+ i = 0
18769+ .rept USER_PGD_PTRS
18770+ movb $0,i*8(%rbx)
18771+ i = i + 1
18772+ .endr
18773+
18774+#ifdef CONFIG_PARAVIRT
18775+2: popq %rdi
18776+#endif
18777+ SET_RDI_INTO_CR3
18778+
18779+#ifdef CONFIG_PAX_KERNEXEC
18780+ GET_CR0_INTO_RDI
18781+ bts $16,%rdi
18782+ SET_RDI_INTO_CR0
18783+#endif
18784+
18785+#ifdef CONFIG_PARAVIRT
18786+ PV_RESTORE_REGS(CLBR_RDI)
18787+#endif
18788+
18789+ popq %rbx
18790+ popq %rdi
18791+ pax_force_retaddr
18792+ retq
18793+ENDPROC(pax_enter_kernel_user)
18794+
18795+ENTRY(pax_exit_kernel_user)
18796+ push %rdi
18797+
18798+#ifdef CONFIG_PARAVIRT
18799+ pushq %rbx
18800+ PV_SAVE_REGS(CLBR_RDI)
18801+#endif
18802+
18803+#ifdef CONFIG_PAX_KERNEXEC
18804+ GET_CR0_INTO_RDI
18805+ btr $16,%rdi
18806+ SET_RDI_INTO_CR0
18807+#endif
18808+
18809+ GET_CR3_INTO_RDI
18810+ add $__START_KERNEL_map,%rdi
18811+ sub phys_base(%rip),%rdi
18812+
18813+#ifdef CONFIG_PARAVIRT
18814+ cmpl $0, pv_info+PARAVIRT_enabled
18815+ jz 1f
18816+ mov %rdi,%rbx
18817+ i = 0
18818+ .rept USER_PGD_PTRS
18819+ mov i*8(%rbx),%rsi
18820+ mov $0x67,%sil
18821+ lea i*8(%rbx),%rdi
18822+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18823+ i = i + 1
18824+ .endr
18825+ jmp 2f
18826+1:
18827+#endif
18828+
18829+ i = 0
18830+ .rept USER_PGD_PTRS
18831+ movb $0x67,i*8(%rdi)
18832+ i = i + 1
18833+ .endr
18834+
18835+#ifdef CONFIG_PARAVIRT
18836+2: PV_RESTORE_REGS(CLBR_RDI)
18837+ popq %rbx
18838+#endif
18839+
18840+ popq %rdi
18841+ pax_force_retaddr
18842+ retq
18843+ENDPROC(pax_exit_kernel_user)
18844+#endif
18845+
18846+.macro pax_erase_kstack
18847+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18848+ call pax_erase_kstack
18849+#endif
18850+.endm
18851+
18852+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18853+ENTRY(pax_erase_kstack)
18854+ pushq %rdi
18855+ pushq %rcx
18856+ pushq %rax
18857+ pushq %r11
18858+
18859+ GET_THREAD_INFO(%r11)
18860+ mov TI_lowest_stack(%r11), %rdi
18861+ mov $-0xBEEF, %rax
18862+ std
18863+
18864+1: mov %edi, %ecx
18865+ and $THREAD_SIZE_asm - 1, %ecx
18866+ shr $3, %ecx
18867+ repne scasq
18868+ jecxz 2f
18869+
18870+ cmp $2*8, %ecx
18871+ jc 2f
18872+
18873+ mov $2*8, %ecx
18874+ repe scasq
18875+ jecxz 2f
18876+ jne 1b
18877+
18878+2: cld
18879+ mov %esp, %ecx
18880+ sub %edi, %ecx
18881+
18882+ cmp $THREAD_SIZE_asm, %rcx
18883+ jb 3f
18884+ ud2
18885+3:
18886+
18887+ shr $3, %ecx
18888+ rep stosq
18889+
18890+ mov TI_task_thread_sp0(%r11), %rdi
18891+ sub $256, %rdi
18892+ mov %rdi, TI_lowest_stack(%r11)
18893+
18894+ popq %r11
18895+ popq %rax
18896+ popq %rcx
18897+ popq %rdi
18898+ pax_force_retaddr
18899+ ret
18900+ENDPROC(pax_erase_kstack)
18901+#endif
18902
18903 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18904 #ifdef CONFIG_TRACE_IRQFLAGS
18905@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18906 .endm
18907
18908 .macro UNFAKE_STACK_FRAME
18909- addq $8*6, %rsp
18910- CFI_ADJUST_CFA_OFFSET -(6*8)
18911+ addq $8*6 + ARG_SKIP, %rsp
18912+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18913 .endm
18914
18915 /*
18916@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18917 movq %rsp, %rsi
18918
18919 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18920- testl $3, CS-RBP(%rsi)
18921+ testb $3, CS-RBP(%rsi)
18922 je 1f
18923 SWAPGS
18924 /*
18925@@ -498,9 +774,10 @@ ENTRY(save_rest)
18926 movq_cfi r15, R15+16
18927 movq %r11, 8(%rsp) /* return address */
18928 FIXUP_TOP_OF_STACK %r11, 16
18929+ pax_force_retaddr
18930 ret
18931 CFI_ENDPROC
18932-END(save_rest)
18933+ENDPROC(save_rest)
18934
18935 /* save complete stack frame */
18936 .pushsection .kprobes.text, "ax"
18937@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18938 js 1f /* negative -> in kernel */
18939 SWAPGS
18940 xorl %ebx,%ebx
18941-1: ret
18942+1: pax_force_retaddr_bts
18943+ ret
18944 CFI_ENDPROC
18945-END(save_paranoid)
18946+ENDPROC(save_paranoid)
18947 .popsection
18948
18949 /*
18950@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18951
18952 RESTORE_REST
18953
18954- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18955+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18956 jz 1f
18957
18958 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18959@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18960 RESTORE_REST
18961 jmp int_ret_from_sys_call
18962 CFI_ENDPROC
18963-END(ret_from_fork)
18964+ENDPROC(ret_from_fork)
18965
18966 /*
18967 * System call entry. Up to 6 arguments in registers are supported.
18968@@ -608,7 +886,7 @@ END(ret_from_fork)
18969 ENTRY(system_call)
18970 CFI_STARTPROC simple
18971 CFI_SIGNAL_FRAME
18972- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18973+ CFI_DEF_CFA rsp,0
18974 CFI_REGISTER rip,rcx
18975 /*CFI_REGISTER rflags,r11*/
18976 SWAPGS_UNSAFE_STACK
18977@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18978
18979 movq %rsp,PER_CPU_VAR(old_rsp)
18980 movq PER_CPU_VAR(kernel_stack),%rsp
18981+ SAVE_ARGS 8*6,0
18982+ pax_enter_kernel_user
18983+
18984+#ifdef CONFIG_PAX_RANDKSTACK
18985+ pax_erase_kstack
18986+#endif
18987+
18988 /*
18989 * No need to follow this irqs off/on section - it's straight
18990 * and short:
18991 */
18992 ENABLE_INTERRUPTS(CLBR_NONE)
18993- SAVE_ARGS 8,0
18994 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18995 movq %rcx,RIP-ARGOFFSET(%rsp)
18996 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18997- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18998+ GET_THREAD_INFO(%rcx)
18999+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19000 jnz tracesys
19001 system_call_fastpath:
19002 #if __SYSCALL_MASK == ~0
19003@@ -640,7 +925,7 @@ system_call_fastpath:
19004 cmpl $__NR_syscall_max,%eax
19005 #endif
19006 ja badsys
19007- movq %r10,%rcx
19008+ movq R10-ARGOFFSET(%rsp),%rcx
19009 call *sys_call_table(,%rax,8) # XXX: rip relative
19010 movq %rax,RAX-ARGOFFSET(%rsp)
19011 /*
19012@@ -654,10 +939,13 @@ sysret_check:
19013 LOCKDEP_SYS_EXIT
19014 DISABLE_INTERRUPTS(CLBR_NONE)
19015 TRACE_IRQS_OFF
19016- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19017+ GET_THREAD_INFO(%rcx)
19018+ movl TI_flags(%rcx),%edx
19019 andl %edi,%edx
19020 jnz sysret_careful
19021 CFI_REMEMBER_STATE
19022+ pax_exit_kernel_user
19023+ pax_erase_kstack
19024 /*
19025 * sysretq will re-enable interrupts:
19026 */
19027@@ -709,14 +997,18 @@ badsys:
19028 * jump back to the normal fast path.
19029 */
19030 auditsys:
19031- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19032+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19033 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19034 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19035 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19036 movq %rax,%rsi /* 2nd arg: syscall number */
19037 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19038 call __audit_syscall_entry
19039+
19040+ pax_erase_kstack
19041+
19042 LOAD_ARGS 0 /* reload call-clobbered registers */
19043+ pax_set_fptr_mask
19044 jmp system_call_fastpath
19045
19046 /*
19047@@ -737,7 +1029,7 @@ sysret_audit:
19048 /* Do syscall tracing */
19049 tracesys:
19050 #ifdef CONFIG_AUDITSYSCALL
19051- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19052+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19053 jz auditsys
19054 #endif
19055 SAVE_REST
19056@@ -745,12 +1037,16 @@ tracesys:
19057 FIXUP_TOP_OF_STACK %rdi
19058 movq %rsp,%rdi
19059 call syscall_trace_enter
19060+
19061+ pax_erase_kstack
19062+
19063 /*
19064 * Reload arg registers from stack in case ptrace changed them.
19065 * We don't reload %rax because syscall_trace_enter() returned
19066 * the value it wants us to use in the table lookup.
19067 */
19068 LOAD_ARGS ARGOFFSET, 1
19069+ pax_set_fptr_mask
19070 RESTORE_REST
19071 #if __SYSCALL_MASK == ~0
19072 cmpq $__NR_syscall_max,%rax
19073@@ -759,7 +1055,7 @@ tracesys:
19074 cmpl $__NR_syscall_max,%eax
19075 #endif
19076 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19077- movq %r10,%rcx /* fixup for C */
19078+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19079 call *sys_call_table(,%rax,8)
19080 movq %rax,RAX-ARGOFFSET(%rsp)
19081 /* Use IRET because user could have changed frame */
19082@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
19083 andl %edi,%edx
19084 jnz int_careful
19085 andl $~TS_COMPAT,TI_status(%rcx)
19086- jmp retint_swapgs
19087+ pax_exit_kernel_user
19088+ pax_erase_kstack
19089+ jmp retint_swapgs_pax
19090
19091 /* Either reschedule or signal or syscall exit tracking needed. */
19092 /* First do a reschedule test. */
19093@@ -826,7 +1124,7 @@ int_restore_rest:
19094 TRACE_IRQS_OFF
19095 jmp int_with_check
19096 CFI_ENDPROC
19097-END(system_call)
19098+ENDPROC(system_call)
19099
19100 /*
19101 * Certain special system calls that need to save a complete full stack frame.
19102@@ -842,7 +1140,7 @@ ENTRY(\label)
19103 call \func
19104 jmp ptregscall_common
19105 CFI_ENDPROC
19106-END(\label)
19107+ENDPROC(\label)
19108 .endm
19109
19110 .macro FORK_LIKE func
19111@@ -856,9 +1154,10 @@ ENTRY(stub_\func)
19112 DEFAULT_FRAME 0 8 /* offset 8: return address */
19113 call sys_\func
19114 RESTORE_TOP_OF_STACK %r11, 8
19115+ pax_force_retaddr
19116 ret $REST_SKIP /* pop extended registers */
19117 CFI_ENDPROC
19118-END(stub_\func)
19119+ENDPROC(stub_\func)
19120 .endm
19121
19122 FORK_LIKE clone
19123@@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
19124 movq_cfi_restore R12+8, r12
19125 movq_cfi_restore RBP+8, rbp
19126 movq_cfi_restore RBX+8, rbx
19127+ pax_force_retaddr
19128 ret $REST_SKIP /* pop extended registers */
19129 CFI_ENDPROC
19130-END(ptregscall_common)
19131+ENDPROC(ptregscall_common)
19132
19133 ENTRY(stub_execve)
19134 CFI_STARTPROC
19135@@ -891,7 +1191,7 @@ ENTRY(stub_execve)
19136 RESTORE_REST
19137 jmp int_ret_from_sys_call
19138 CFI_ENDPROC
19139-END(stub_execve)
19140+ENDPROC(stub_execve)
19141
19142 /*
19143 * sigreturn is special because it needs to restore all registers on return.
19144@@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
19145 RESTORE_REST
19146 jmp int_ret_from_sys_call
19147 CFI_ENDPROC
19148-END(stub_rt_sigreturn)
19149+ENDPROC(stub_rt_sigreturn)
19150
19151 #ifdef CONFIG_X86_X32_ABI
19152 ENTRY(stub_x32_rt_sigreturn)
19153@@ -975,7 +1275,7 @@ vector=vector+1
19154 2: jmp common_interrupt
19155 .endr
19156 CFI_ENDPROC
19157-END(irq_entries_start)
19158+ENDPROC(irq_entries_start)
19159
19160 .previous
19161 END(interrupt)
19162@@ -995,6 +1295,16 @@ END(interrupt)
19163 subq $ORIG_RAX-RBP, %rsp
19164 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19165 SAVE_ARGS_IRQ
19166+#ifdef CONFIG_PAX_MEMORY_UDEREF
19167+ testb $3, CS(%rdi)
19168+ jnz 1f
19169+ pax_enter_kernel
19170+ jmp 2f
19171+1: pax_enter_kernel_user
19172+2:
19173+#else
19174+ pax_enter_kernel
19175+#endif
19176 call \func
19177 .endm
19178
19179@@ -1027,7 +1337,7 @@ ret_from_intr:
19180
19181 exit_intr:
19182 GET_THREAD_INFO(%rcx)
19183- testl $3,CS-ARGOFFSET(%rsp)
19184+ testb $3,CS-ARGOFFSET(%rsp)
19185 je retint_kernel
19186
19187 /* Interrupt came from user space */
19188@@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
19189 * The iretq could re-enable interrupts:
19190 */
19191 DISABLE_INTERRUPTS(CLBR_ANY)
19192+ pax_exit_kernel_user
19193+retint_swapgs_pax:
19194 TRACE_IRQS_IRETQ
19195 SWAPGS
19196 jmp restore_args
19197
19198 retint_restore_args: /* return to kernel space */
19199 DISABLE_INTERRUPTS(CLBR_ANY)
19200+ pax_exit_kernel
19201+ pax_force_retaddr (RIP-ARGOFFSET)
19202 /*
19203 * The iretq could re-enable interrupts:
19204 */
19205@@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
19206 #endif
19207
19208 CFI_ENDPROC
19209-END(common_interrupt)
19210+ENDPROC(common_interrupt)
19211 /*
19212 * End of kprobes section
19213 */
19214@@ -1155,7 +1469,7 @@ ENTRY(\sym)
19215 interrupt \do_sym
19216 jmp ret_from_intr
19217 CFI_ENDPROC
19218-END(\sym)
19219+ENDPROC(\sym)
19220 .endm
19221
19222 #ifdef CONFIG_SMP
19223@@ -1211,12 +1525,22 @@ ENTRY(\sym)
19224 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19225 call error_entry
19226 DEFAULT_FRAME 0
19227+#ifdef CONFIG_PAX_MEMORY_UDEREF
19228+ testb $3, CS(%rsp)
19229+ jnz 1f
19230+ pax_enter_kernel
19231+ jmp 2f
19232+1: pax_enter_kernel_user
19233+2:
19234+#else
19235+ pax_enter_kernel
19236+#endif
19237 movq %rsp,%rdi /* pt_regs pointer */
19238 xorl %esi,%esi /* no error code */
19239 call \do_sym
19240 jmp error_exit /* %ebx: no swapgs flag */
19241 CFI_ENDPROC
19242-END(\sym)
19243+ENDPROC(\sym)
19244 .endm
19245
19246 .macro paranoidzeroentry sym do_sym
19247@@ -1229,15 +1553,25 @@ ENTRY(\sym)
19248 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19249 call save_paranoid
19250 TRACE_IRQS_OFF
19251+#ifdef CONFIG_PAX_MEMORY_UDEREF
19252+ testb $3, CS(%rsp)
19253+ jnz 1f
19254+ pax_enter_kernel
19255+ jmp 2f
19256+1: pax_enter_kernel_user
19257+2:
19258+#else
19259+ pax_enter_kernel
19260+#endif
19261 movq %rsp,%rdi /* pt_regs pointer */
19262 xorl %esi,%esi /* no error code */
19263 call \do_sym
19264 jmp paranoid_exit /* %ebx: no swapgs flag */
19265 CFI_ENDPROC
19266-END(\sym)
19267+ENDPROC(\sym)
19268 .endm
19269
19270-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19271+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19272 .macro paranoidzeroentry_ist sym do_sym ist
19273 ENTRY(\sym)
19274 INTR_FRAME
19275@@ -1248,14 +1582,30 @@ ENTRY(\sym)
19276 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19277 call save_paranoid
19278 TRACE_IRQS_OFF_DEBUG
19279+#ifdef CONFIG_PAX_MEMORY_UDEREF
19280+ testb $3, CS(%rsp)
19281+ jnz 1f
19282+ pax_enter_kernel
19283+ jmp 2f
19284+1: pax_enter_kernel_user
19285+2:
19286+#else
19287+ pax_enter_kernel
19288+#endif
19289 movq %rsp,%rdi /* pt_regs pointer */
19290 xorl %esi,%esi /* no error code */
19291+#ifdef CONFIG_SMP
19292+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19293+ lea init_tss(%r12), %r12
19294+#else
19295+ lea init_tss(%rip), %r12
19296+#endif
19297 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19298 call \do_sym
19299 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19300 jmp paranoid_exit /* %ebx: no swapgs flag */
19301 CFI_ENDPROC
19302-END(\sym)
19303+ENDPROC(\sym)
19304 .endm
19305
19306 .macro errorentry sym do_sym
19307@@ -1267,13 +1617,23 @@ ENTRY(\sym)
19308 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19309 call error_entry
19310 DEFAULT_FRAME 0
19311+#ifdef CONFIG_PAX_MEMORY_UDEREF
19312+ testb $3, CS(%rsp)
19313+ jnz 1f
19314+ pax_enter_kernel
19315+ jmp 2f
19316+1: pax_enter_kernel_user
19317+2:
19318+#else
19319+ pax_enter_kernel
19320+#endif
19321 movq %rsp,%rdi /* pt_regs pointer */
19322 movq ORIG_RAX(%rsp),%rsi /* get error code */
19323 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19324 call \do_sym
19325 jmp error_exit /* %ebx: no swapgs flag */
19326 CFI_ENDPROC
19327-END(\sym)
19328+ENDPROC(\sym)
19329 .endm
19330
19331 /* error code is on the stack already */
19332@@ -1287,13 +1647,23 @@ ENTRY(\sym)
19333 call save_paranoid
19334 DEFAULT_FRAME 0
19335 TRACE_IRQS_OFF
19336+#ifdef CONFIG_PAX_MEMORY_UDEREF
19337+ testb $3, CS(%rsp)
19338+ jnz 1f
19339+ pax_enter_kernel
19340+ jmp 2f
19341+1: pax_enter_kernel_user
19342+2:
19343+#else
19344+ pax_enter_kernel
19345+#endif
19346 movq %rsp,%rdi /* pt_regs pointer */
19347 movq ORIG_RAX(%rsp),%rsi /* get error code */
19348 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19349 call \do_sym
19350 jmp paranoid_exit /* %ebx: no swapgs flag */
19351 CFI_ENDPROC
19352-END(\sym)
19353+ENDPROC(\sym)
19354 .endm
19355
19356 zeroentry divide_error do_divide_error
19357@@ -1323,9 +1693,10 @@ gs_change:
19358 2: mfence /* workaround */
19359 SWAPGS
19360 popfq_cfi
19361+ pax_force_retaddr
19362 ret
19363 CFI_ENDPROC
19364-END(native_load_gs_index)
19365+ENDPROC(native_load_gs_index)
19366
19367 _ASM_EXTABLE(gs_change,bad_gs)
19368 .section .fixup,"ax"
19369@@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19370 CFI_DEF_CFA_REGISTER rsp
19371 CFI_ADJUST_CFA_OFFSET -8
19372 decl PER_CPU_VAR(irq_count)
19373+ pax_force_retaddr
19374 ret
19375 CFI_ENDPROC
19376-END(call_softirq)
19377+ENDPROC(call_softirq)
19378
19379 #ifdef CONFIG_XEN
19380 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19381@@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19382 decl PER_CPU_VAR(irq_count)
19383 jmp error_exit
19384 CFI_ENDPROC
19385-END(xen_do_hypervisor_callback)
19386+ENDPROC(xen_do_hypervisor_callback)
19387
19388 /*
19389 * Hypervisor uses this for application faults while it executes.
19390@@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19391 SAVE_ALL
19392 jmp error_exit
19393 CFI_ENDPROC
19394-END(xen_failsafe_callback)
19395+ENDPROC(xen_failsafe_callback)
19396
19397 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19398 xen_hvm_callback_vector xen_evtchn_do_upcall
19399@@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19400 TRACE_IRQS_OFF_DEBUG
19401 testl %ebx,%ebx /* swapgs needed? */
19402 jnz paranoid_restore
19403- testl $3,CS(%rsp)
19404+ testb $3,CS(%rsp)
19405 jnz paranoid_userspace
19406+#ifdef CONFIG_PAX_MEMORY_UDEREF
19407+ pax_exit_kernel
19408+ TRACE_IRQS_IRETQ 0
19409+ SWAPGS_UNSAFE_STACK
19410+ RESTORE_ALL 8
19411+ pax_force_retaddr_bts
19412+ jmp irq_return
19413+#endif
19414 paranoid_swapgs:
19415+#ifdef CONFIG_PAX_MEMORY_UDEREF
19416+ pax_exit_kernel_user
19417+#else
19418+ pax_exit_kernel
19419+#endif
19420 TRACE_IRQS_IRETQ 0
19421 SWAPGS_UNSAFE_STACK
19422 RESTORE_ALL 8
19423 jmp irq_return
19424 paranoid_restore:
19425+ pax_exit_kernel
19426 TRACE_IRQS_IRETQ_DEBUG 0
19427 RESTORE_ALL 8
19428+ pax_force_retaddr_bts
19429 jmp irq_return
19430 paranoid_userspace:
19431 GET_THREAD_INFO(%rcx)
19432@@ -1539,7 +1926,7 @@ paranoid_schedule:
19433 TRACE_IRQS_OFF
19434 jmp paranoid_userspace
19435 CFI_ENDPROC
19436-END(paranoid_exit)
19437+ENDPROC(paranoid_exit)
19438
19439 /*
19440 * Exception entry point. This expects an error code/orig_rax on the stack.
19441@@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19442 movq_cfi r14, R14+8
19443 movq_cfi r15, R15+8
19444 xorl %ebx,%ebx
19445- testl $3,CS+8(%rsp)
19446+ testb $3,CS+8(%rsp)
19447 je error_kernelspace
19448 error_swapgs:
19449 SWAPGS
19450 error_sti:
19451 TRACE_IRQS_OFF
19452+ pax_force_retaddr_bts
19453 ret
19454
19455 /*
19456@@ -1598,7 +1986,7 @@ bstep_iret:
19457 movq %rcx,RIP+8(%rsp)
19458 jmp error_swapgs
19459 CFI_ENDPROC
19460-END(error_entry)
19461+ENDPROC(error_entry)
19462
19463
19464 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19465@@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19466 jnz retint_careful
19467 jmp retint_swapgs
19468 CFI_ENDPROC
19469-END(error_exit)
19470+ENDPROC(error_exit)
19471
19472 /*
19473 * Test if a given stack is an NMI stack or not.
19474@@ -1676,9 +2064,11 @@ ENTRY(nmi)
19475 * If %cs was not the kernel segment, then the NMI triggered in user
19476 * space, which means it is definitely not nested.
19477 */
19478+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19479+ je 1f
19480 cmpl $__KERNEL_CS, 16(%rsp)
19481 jne first_nmi
19482-
19483+1:
19484 /*
19485 * Check the special variable on the stack to see if NMIs are
19486 * executing.
19487@@ -1847,6 +2237,17 @@ end_repeat_nmi:
19488 */
19489 movq %cr2, %r12
19490
19491+#ifdef CONFIG_PAX_MEMORY_UDEREF
19492+ testb $3, CS(%rsp)
19493+ jnz 1f
19494+ pax_enter_kernel
19495+ jmp 2f
19496+1: pax_enter_kernel_user
19497+2:
19498+#else
19499+ pax_enter_kernel
19500+#endif
19501+
19502 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19503 movq %rsp,%rdi
19504 movq $-1,%rsi
19505@@ -1862,23 +2263,34 @@ end_repeat_nmi:
19506 testl %ebx,%ebx /* swapgs needed? */
19507 jnz nmi_restore
19508 nmi_swapgs:
19509+#ifdef CONFIG_PAX_MEMORY_UDEREF
19510+ pax_exit_kernel_user
19511+#else
19512+ pax_exit_kernel
19513+#endif
19514 SWAPGS_UNSAFE_STACK
19515+ RESTORE_ALL 6*8
19516+ /* Clear the NMI executing stack variable */
19517+ movq $0, 5*8(%rsp)
19518+ jmp irq_return
19519 nmi_restore:
19520+ pax_exit_kernel
19521 /* Pop the extra iret frame at once */
19522 RESTORE_ALL 6*8
19523+ pax_force_retaddr_bts
19524
19525 /* Clear the NMI executing stack variable */
19526 movq $0, 5*8(%rsp)
19527 jmp irq_return
19528 CFI_ENDPROC
19529-END(nmi)
19530+ENDPROC(nmi)
19531
19532 ENTRY(ignore_sysret)
19533 CFI_STARTPROC
19534 mov $-ENOSYS,%eax
19535 sysret
19536 CFI_ENDPROC
19537-END(ignore_sysret)
19538+ENDPROC(ignore_sysret)
19539
19540 /*
19541 * End of kprobes section
19542diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19543index 1d41402..af9a46a 100644
19544--- a/arch/x86/kernel/ftrace.c
19545+++ b/arch/x86/kernel/ftrace.c
19546@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19547 {
19548 unsigned char replaced[MCOUNT_INSN_SIZE];
19549
19550+ ip = ktla_ktva(ip);
19551+
19552 /*
19553 * Note: Due to modules and __init, code can
19554 * disappear and change, we need to protect against faulting
19555@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19556 unsigned char old[MCOUNT_INSN_SIZE], *new;
19557 int ret;
19558
19559- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19560+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19561 new = ftrace_call_replace(ip, (unsigned long)func);
19562
19563 /* See comment above by declaration of modifying_ftrace_code */
19564@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19565 /* Also update the regs callback function */
19566 if (!ret) {
19567 ip = (unsigned long)(&ftrace_regs_call);
19568- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19569+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19570 new = ftrace_call_replace(ip, (unsigned long)func);
19571 ret = ftrace_modify_code(ip, old, new);
19572 }
19573@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19574 * kernel identity mapping to modify code.
19575 */
19576 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19577- ip = (unsigned long)__va(__pa(ip));
19578+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19579
19580 return probe_kernel_write((void *)ip, val, size);
19581 }
19582@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19583 unsigned char replaced[MCOUNT_INSN_SIZE];
19584 unsigned char brk = BREAKPOINT_INSTRUCTION;
19585
19586- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19587+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19588 return -EFAULT;
19589
19590 /* Make sure it is what we expect it to be */
19591@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19592 return ret;
19593
19594 fail_update:
19595- probe_kernel_write((void *)ip, &old_code[0], 1);
19596+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19597 goto out;
19598 }
19599
19600@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19601 {
19602 unsigned char code[MCOUNT_INSN_SIZE];
19603
19604+ ip = ktla_ktva(ip);
19605+
19606 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19607 return -EFAULT;
19608
19609diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19610index c18f59d..9c0c9f6 100644
19611--- a/arch/x86/kernel/head32.c
19612+++ b/arch/x86/kernel/head32.c
19613@@ -18,6 +18,7 @@
19614 #include <asm/io_apic.h>
19615 #include <asm/bios_ebda.h>
19616 #include <asm/tlbflush.h>
19617+#include <asm/boot.h>
19618
19619 static void __init i386_default_early_setup(void)
19620 {
19621@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19622
19623 void __init i386_start_kernel(void)
19624 {
19625- memblock_reserve(__pa_symbol(&_text),
19626- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19627+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19628
19629 #ifdef CONFIG_BLK_DEV_INITRD
19630 /* Reserve INITRD */
19631diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19632index c8932c7..d56b622 100644
19633--- a/arch/x86/kernel/head_32.S
19634+++ b/arch/x86/kernel/head_32.S
19635@@ -26,6 +26,12 @@
19636 /* Physical address */
19637 #define pa(X) ((X) - __PAGE_OFFSET)
19638
19639+#ifdef CONFIG_PAX_KERNEXEC
19640+#define ta(X) (X)
19641+#else
19642+#define ta(X) ((X) - __PAGE_OFFSET)
19643+#endif
19644+
19645 /*
19646 * References to members of the new_cpu_data structure.
19647 */
19648@@ -55,11 +61,7 @@
19649 * and small than max_low_pfn, otherwise will waste some page table entries
19650 */
19651
19652-#if PTRS_PER_PMD > 1
19653-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19654-#else
19655-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19656-#endif
19657+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19658
19659 /* Number of possible pages in the lowmem region */
19660 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19661@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19662 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19663
19664 /*
19665+ * Real beginning of normal "text" segment
19666+ */
19667+ENTRY(stext)
19668+ENTRY(_stext)
19669+
19670+/*
19671 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19672 * %esi points to the real-mode code as a 32-bit pointer.
19673 * CS and DS must be 4 GB flat segments, but we don't depend on
19674@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19675 * can.
19676 */
19677 __HEAD
19678+
19679+#ifdef CONFIG_PAX_KERNEXEC
19680+ jmp startup_32
19681+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19682+.fill PAGE_SIZE-5,1,0xcc
19683+#endif
19684+
19685 ENTRY(startup_32)
19686 movl pa(stack_start),%ecx
19687
19688@@ -106,6 +121,59 @@ ENTRY(startup_32)
19689 2:
19690 leal -__PAGE_OFFSET(%ecx),%esp
19691
19692+#ifdef CONFIG_SMP
19693+ movl $pa(cpu_gdt_table),%edi
19694+ movl $__per_cpu_load,%eax
19695+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19696+ rorl $16,%eax
19697+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19698+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19699+ movl $__per_cpu_end - 1,%eax
19700+ subl $__per_cpu_start,%eax
19701+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19702+#endif
19703+
19704+#ifdef CONFIG_PAX_MEMORY_UDEREF
19705+ movl $NR_CPUS,%ecx
19706+ movl $pa(cpu_gdt_table),%edi
19707+1:
19708+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19709+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19710+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19711+ addl $PAGE_SIZE_asm,%edi
19712+ loop 1b
19713+#endif
19714+
19715+#ifdef CONFIG_PAX_KERNEXEC
19716+ movl $pa(boot_gdt),%edi
19717+ movl $__LOAD_PHYSICAL_ADDR,%eax
19718+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19719+ rorl $16,%eax
19720+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19721+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19722+ rorl $16,%eax
19723+
19724+ ljmp $(__BOOT_CS),$1f
19725+1:
19726+
19727+ movl $NR_CPUS,%ecx
19728+ movl $pa(cpu_gdt_table),%edi
19729+ addl $__PAGE_OFFSET,%eax
19730+1:
19731+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19732+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19733+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19734+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19735+ rorl $16,%eax
19736+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19737+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19738+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19739+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19740+ rorl $16,%eax
19741+ addl $PAGE_SIZE_asm,%edi
19742+ loop 1b
19743+#endif
19744+
19745 /*
19746 * Clear BSS first so that there are no surprises...
19747 */
19748@@ -196,8 +264,11 @@ ENTRY(startup_32)
19749 movl %eax, pa(max_pfn_mapped)
19750
19751 /* Do early initialization of the fixmap area */
19752- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19753- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19754+#ifdef CONFIG_COMPAT_VDSO
19755+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19756+#else
19757+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19758+#endif
19759 #else /* Not PAE */
19760
19761 page_pde_offset = (__PAGE_OFFSET >> 20);
19762@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19763 movl %eax, pa(max_pfn_mapped)
19764
19765 /* Do early initialization of the fixmap area */
19766- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19767- movl %eax,pa(initial_page_table+0xffc)
19768+#ifdef CONFIG_COMPAT_VDSO
19769+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19770+#else
19771+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19772+#endif
19773 #endif
19774
19775 #ifdef CONFIG_PARAVIRT
19776@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19777 cmpl $num_subarch_entries, %eax
19778 jae bad_subarch
19779
19780- movl pa(subarch_entries)(,%eax,4), %eax
19781- subl $__PAGE_OFFSET, %eax
19782- jmp *%eax
19783+ jmp *pa(subarch_entries)(,%eax,4)
19784
19785 bad_subarch:
19786 WEAK(lguest_entry)
19787@@ -256,10 +328,10 @@ WEAK(xen_entry)
19788 __INITDATA
19789
19790 subarch_entries:
19791- .long default_entry /* normal x86/PC */
19792- .long lguest_entry /* lguest hypervisor */
19793- .long xen_entry /* Xen hypervisor */
19794- .long default_entry /* Moorestown MID */
19795+ .long ta(default_entry) /* normal x86/PC */
19796+ .long ta(lguest_entry) /* lguest hypervisor */
19797+ .long ta(xen_entry) /* Xen hypervisor */
19798+ .long ta(default_entry) /* Moorestown MID */
19799 num_subarch_entries = (. - subarch_entries) / 4
19800 .previous
19801 #else
19802@@ -335,6 +407,7 @@ default_entry:
19803 movl pa(mmu_cr4_features),%eax
19804 movl %eax,%cr4
19805
19806+#ifdef CONFIG_X86_PAE
19807 testb $X86_CR4_PAE, %al # check if PAE is enabled
19808 jz 6f
19809
19810@@ -363,6 +436,9 @@ default_entry:
19811 /* Make changes effective */
19812 wrmsr
19813
19814+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19815+#endif
19816+
19817 6:
19818
19819 /*
19820@@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19821 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19822 movl %eax,%ss # after changing gdt.
19823
19824- movl $(__USER_DS),%eax # DS/ES contains default USER segment
19825+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19826 movl %eax,%ds
19827 movl %eax,%es
19828
19829 movl $(__KERNEL_PERCPU), %eax
19830 movl %eax,%fs # set this cpu's percpu
19831
19832+#ifdef CONFIG_CC_STACKPROTECTOR
19833 movl $(__KERNEL_STACK_CANARY),%eax
19834+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19835+ movl $(__USER_DS),%eax
19836+#else
19837+ xorl %eax,%eax
19838+#endif
19839 movl %eax,%gs
19840
19841 xorl %eax,%eax # Clear LDT
19842@@ -544,8 +626,11 @@ setup_once:
19843 * relocation. Manually set base address in stack canary
19844 * segment descriptor.
19845 */
19846- movl $gdt_page,%eax
19847+ movl $cpu_gdt_table,%eax
19848 movl $stack_canary,%ecx
19849+#ifdef CONFIG_SMP
19850+ addl $__per_cpu_load,%ecx
19851+#endif
19852 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19853 shrl $16, %ecx
19854 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19855@@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19856 /* This is global to keep gas from relaxing the jumps */
19857 ENTRY(early_idt_handler)
19858 cld
19859- cmpl $2,%ss:early_recursion_flag
19860+ cmpl $1,%ss:early_recursion_flag
19861 je hlt_loop
19862 incl %ss:early_recursion_flag
19863
19864@@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19865 pushl (20+6*4)(%esp) /* trapno */
19866 pushl $fault_msg
19867 call printk
19868-#endif
19869 call dump_stack
19870+#endif
19871 hlt_loop:
19872 hlt
19873 jmp hlt_loop
19874@@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19875 /* This is the default interrupt "handler" :-) */
19876 ALIGN
19877 ignore_int:
19878- cld
19879 #ifdef CONFIG_PRINTK
19880+ cmpl $2,%ss:early_recursion_flag
19881+ je hlt_loop
19882+ incl %ss:early_recursion_flag
19883+ cld
19884 pushl %eax
19885 pushl %ecx
19886 pushl %edx
19887@@ -644,9 +732,6 @@ ignore_int:
19888 movl $(__KERNEL_DS),%eax
19889 movl %eax,%ds
19890 movl %eax,%es
19891- cmpl $2,early_recursion_flag
19892- je hlt_loop
19893- incl early_recursion_flag
19894 pushl 16(%esp)
19895 pushl 24(%esp)
19896 pushl 32(%esp)
19897@@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19898 /*
19899 * BSS section
19900 */
19901-__PAGE_ALIGNED_BSS
19902- .align PAGE_SIZE
19903 #ifdef CONFIG_X86_PAE
19904+.section .initial_pg_pmd,"a",@progbits
19905 initial_pg_pmd:
19906 .fill 1024*KPMDS,4,0
19907 #else
19908+.section .initial_page_table,"a",@progbits
19909 ENTRY(initial_page_table)
19910 .fill 1024,4,0
19911 #endif
19912+.section .initial_pg_fixmap,"a",@progbits
19913 initial_pg_fixmap:
19914 .fill 1024,4,0
19915+.section .empty_zero_page,"a",@progbits
19916 ENTRY(empty_zero_page)
19917 .fill 4096,1,0
19918+.section .swapper_pg_dir,"a",@progbits
19919 ENTRY(swapper_pg_dir)
19920+#ifdef CONFIG_X86_PAE
19921+ .fill 4,8,0
19922+#else
19923 .fill 1024,4,0
19924+#endif
19925+
19926+/*
19927+ * The IDT has to be page-aligned to simplify the Pentium
19928+ * F0 0F bug workaround.. We have a special link segment
19929+ * for this.
19930+ */
19931+.section .idt,"a",@progbits
19932+ENTRY(idt_table)
19933+ .fill 256,8,0
19934
19935 /*
19936 * This starts the data section.
19937 */
19938 #ifdef CONFIG_X86_PAE
19939-__PAGE_ALIGNED_DATA
19940- /* Page-aligned for the benefit of paravirt? */
19941- .align PAGE_SIZE
19942+.section .initial_page_table,"a",@progbits
19943 ENTRY(initial_page_table)
19944 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19945 # if KPMDS == 3
19946@@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19947 # error "Kernel PMDs should be 1, 2 or 3"
19948 # endif
19949 .align PAGE_SIZE /* needs to be page-sized too */
19950+
19951+#ifdef CONFIG_PAX_PER_CPU_PGD
19952+ENTRY(cpu_pgd)
19953+ .rept NR_CPUS
19954+ .fill 4,8,0
19955+ .endr
19956+#endif
19957+
19958 #endif
19959
19960 .data
19961 .balign 4
19962 ENTRY(stack_start)
19963- .long init_thread_union+THREAD_SIZE
19964+ .long init_thread_union+THREAD_SIZE-8
19965
19966 __INITRODATA
19967 int_msg:
19968@@ -754,7 +861,7 @@ fault_msg:
19969 * segment size, and 32-bit linear address value:
19970 */
19971
19972- .data
19973+.section .rodata,"a",@progbits
19974 .globl boot_gdt_descr
19975 .globl idt_descr
19976
19977@@ -763,7 +870,7 @@ fault_msg:
19978 .word 0 # 32 bit align gdt_desc.address
19979 boot_gdt_descr:
19980 .word __BOOT_DS+7
19981- .long boot_gdt - __PAGE_OFFSET
19982+ .long pa(boot_gdt)
19983
19984 .word 0 # 32-bit align idt_desc.address
19985 idt_descr:
19986@@ -774,7 +881,7 @@ idt_descr:
19987 .word 0 # 32 bit align gdt_desc.address
19988 ENTRY(early_gdt_descr)
19989 .word GDT_ENTRIES*8-1
19990- .long gdt_page /* Overwritten for secondary CPUs */
19991+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
19992
19993 /*
19994 * The boot_gdt must mirror the equivalent in setup.S and is
19995@@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19996 .align L1_CACHE_BYTES
19997 ENTRY(boot_gdt)
19998 .fill GDT_ENTRY_BOOT_CS,8,0
19999- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20000- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20001+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20002+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20003+
20004+ .align PAGE_SIZE_asm
20005+ENTRY(cpu_gdt_table)
20006+ .rept NR_CPUS
20007+ .quad 0x0000000000000000 /* NULL descriptor */
20008+ .quad 0x0000000000000000 /* 0x0b reserved */
20009+ .quad 0x0000000000000000 /* 0x13 reserved */
20010+ .quad 0x0000000000000000 /* 0x1b reserved */
20011+
20012+#ifdef CONFIG_PAX_KERNEXEC
20013+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20014+#else
20015+ .quad 0x0000000000000000 /* 0x20 unused */
20016+#endif
20017+
20018+ .quad 0x0000000000000000 /* 0x28 unused */
20019+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20020+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20021+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20022+ .quad 0x0000000000000000 /* 0x4b reserved */
20023+ .quad 0x0000000000000000 /* 0x53 reserved */
20024+ .quad 0x0000000000000000 /* 0x5b reserved */
20025+
20026+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20027+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20028+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20029+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20030+
20031+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20032+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20033+
20034+ /*
20035+ * Segments used for calling PnP BIOS have byte granularity.
20036+ * The code segments and data segments have fixed 64k limits,
20037+ * the transfer segment sizes are set at run time.
20038+ */
20039+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20040+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20041+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20042+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20043+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20044+
20045+ /*
20046+ * The APM segments have byte granularity and their bases
20047+ * are set at run time. All have 64k limits.
20048+ */
20049+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20050+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20051+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20052+
20053+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20054+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20055+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20056+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20057+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20058+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20059+
20060+ /* Be sure this is zeroed to avoid false validations in Xen */
20061+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20062+ .endr
20063diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20064index 980053c..74d3b44 100644
20065--- a/arch/x86/kernel/head_64.S
20066+++ b/arch/x86/kernel/head_64.S
20067@@ -20,6 +20,8 @@
20068 #include <asm/processor-flags.h>
20069 #include <asm/percpu.h>
20070 #include <asm/nops.h>
20071+#include <asm/cpufeature.h>
20072+#include <asm/alternative-asm.h>
20073
20074 #ifdef CONFIG_PARAVIRT
20075 #include <asm/asm-offsets.h>
20076@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20077 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20078 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20079 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20080+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20081+L3_VMALLOC_START = pud_index(VMALLOC_START)
20082+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20083+L3_VMALLOC_END = pud_index(VMALLOC_END)
20084+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20085+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20086
20087 .text
20088 __HEAD
20089@@ -88,35 +96,23 @@ startup_64:
20090 */
20091 addq %rbp, init_level4_pgt + 0(%rip)
20092 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
20093+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20094+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20095+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20096 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
20097
20098 addq %rbp, level3_ident_pgt + 0(%rip)
20099+#ifndef CONFIG_XEN
20100+ addq %rbp, level3_ident_pgt + 8(%rip)
20101+#endif
20102
20103- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20104- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20105+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
20106+
20107+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
20108+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
20109
20110 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20111-
20112- /* Add an Identity mapping if I am above 1G */
20113- leaq _text(%rip), %rdi
20114- andq $PMD_PAGE_MASK, %rdi
20115-
20116- movq %rdi, %rax
20117- shrq $PUD_SHIFT, %rax
20118- andq $(PTRS_PER_PUD - 1), %rax
20119- jz ident_complete
20120-
20121- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
20122- leaq level3_ident_pgt(%rip), %rbx
20123- movq %rdx, 0(%rbx, %rax, 8)
20124-
20125- movq %rdi, %rax
20126- shrq $PMD_SHIFT, %rax
20127- andq $(PTRS_PER_PMD - 1), %rax
20128- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
20129- leaq level2_spare_pgt(%rip), %rbx
20130- movq %rdx, 0(%rbx, %rax, 8)
20131-ident_complete:
20132+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20133
20134 /*
20135 * Fixup the kernel text+data virtual addresses. Note that
20136@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
20137 * after the boot processor executes this code.
20138 */
20139
20140- /* Enable PAE mode and PGE */
20141- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
20142+ /* Enable PAE mode and PSE/PGE */
20143+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
20144 movq %rax, %cr4
20145
20146 /* Setup early boot stage 4 level pagetables. */
20147@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
20148 movl $MSR_EFER, %ecx
20149 rdmsr
20150 btsl $_EFER_SCE, %eax /* Enable System Call */
20151- btl $20,%edi /* No Execute supported? */
20152+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20153 jnc 1f
20154 btsl $_EFER_NX, %eax
20155+ leaq init_level4_pgt(%rip), %rdi
20156+#ifndef CONFIG_EFI
20157+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20158+#endif
20159+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20160+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20161+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20162+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20163 1: wrmsr /* Make changes effective */
20164
20165 /* Setup cr0 */
20166@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
20167 * jump. In addition we need to ensure %cs is set so we make this
20168 * a far return.
20169 */
20170+ pax_set_fptr_mask
20171 movq initial_code(%rip),%rax
20172 pushq $0 # fake return address to stop unwinder
20173 pushq $__KERNEL_CS # set correct cs
20174@@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
20175 bad_address:
20176 jmp bad_address
20177
20178- .section ".init.text","ax"
20179+ __INIT
20180 .globl early_idt_handlers
20181 early_idt_handlers:
20182 # 104(%rsp) %rflags
20183@@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
20184 call dump_stack
20185 #ifdef CONFIG_KALLSYMS
20186 leaq early_idt_ripmsg(%rip),%rdi
20187- movq 40(%rsp),%rsi # %rip again
20188+ movq 88(%rsp),%rsi # %rip again
20189 call __print_symbol
20190 #endif
20191 #endif /* EARLY_PRINTK */
20192@@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
20193 addq $16,%rsp # drop vector number and error code
20194 decl early_recursion_flag(%rip)
20195 INTERRUPT_RETURN
20196+ .previous
20197
20198+ __INITDATA
20199 .balign 4
20200 early_recursion_flag:
20201 .long 0
20202+ .previous
20203
20204+ .section .rodata,"a",@progbits
20205 #ifdef CONFIG_EARLY_PRINTK
20206 early_idt_msg:
20207 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20208@@ -376,6 +385,7 @@ early_idt_ripmsg:
20209 #endif /* CONFIG_EARLY_PRINTK */
20210 .previous
20211
20212+ .section .rodata,"a",@progbits
20213 #define NEXT_PAGE(name) \
20214 .balign PAGE_SIZE; \
20215 ENTRY(name)
20216@@ -388,7 +398,6 @@ ENTRY(name)
20217 i = i + 1 ; \
20218 .endr
20219
20220- .data
20221 /*
20222 * This default setting generates an ident mapping at address 0x100000
20223 * and a mapping for the kernel that precisely maps virtual address
20224@@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
20225 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20226 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20227 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20228+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20229+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20230+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20231+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20232+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20233+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20234 .org init_level4_pgt + L4_START_KERNEL*8, 0
20235 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20236 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20237
20238+#ifdef CONFIG_PAX_PER_CPU_PGD
20239+NEXT_PAGE(cpu_pgd)
20240+ .rept NR_CPUS
20241+ .fill 512,8,0
20242+ .endr
20243+#endif
20244+
20245 NEXT_PAGE(level3_ident_pgt)
20246 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20247+#ifdef CONFIG_XEN
20248 .fill 511,8,0
20249+#else
20250+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20251+ .fill 510,8,0
20252+#endif
20253+
20254+NEXT_PAGE(level3_vmalloc_start_pgt)
20255+ .fill 512,8,0
20256+
20257+NEXT_PAGE(level3_vmalloc_end_pgt)
20258+ .fill 512,8,0
20259+
20260+NEXT_PAGE(level3_vmemmap_pgt)
20261+ .fill L3_VMEMMAP_START,8,0
20262+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20263
20264 NEXT_PAGE(level3_kernel_pgt)
20265 .fill L3_START_KERNEL,8,0
20266@@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20267 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20268 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20269
20270+NEXT_PAGE(level2_vmemmap_pgt)
20271+ .fill 512,8,0
20272+
20273 NEXT_PAGE(level2_fixmap_pgt)
20274- .fill 506,8,0
20275- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20276- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20277- .fill 5,8,0
20278+ .fill 507,8,0
20279+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20280+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20281+ .fill 4,8,0
20282
20283-NEXT_PAGE(level1_fixmap_pgt)
20284+NEXT_PAGE(level1_vsyscall_pgt)
20285 .fill 512,8,0
20286
20287-NEXT_PAGE(level2_ident_pgt)
20288- /* Since I easily can, map the first 1G.
20289+ /* Since I easily can, map the first 2G.
20290 * Don't set NX because code runs from these pages.
20291 */
20292- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20293+NEXT_PAGE(level2_ident_pgt)
20294+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20295
20296 NEXT_PAGE(level2_kernel_pgt)
20297 /*
20298@@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20299 * If you want to increase this then increase MODULES_VADDR
20300 * too.)
20301 */
20302- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20303- KERNEL_IMAGE_SIZE/PMD_SIZE)
20304-
20305-NEXT_PAGE(level2_spare_pgt)
20306- .fill 512, 8, 0
20307+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20308
20309 #undef PMDS
20310 #undef NEXT_PAGE
20311
20312- .data
20313+ .align PAGE_SIZE
20314+ENTRY(cpu_gdt_table)
20315+ .rept NR_CPUS
20316+ .quad 0x0000000000000000 /* NULL descriptor */
20317+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20318+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20319+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20320+ .quad 0x00cffb000000ffff /* __USER32_CS */
20321+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20322+ .quad 0x00affb000000ffff /* __USER_CS */
20323+
20324+#ifdef CONFIG_PAX_KERNEXEC
20325+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20326+#else
20327+ .quad 0x0 /* unused */
20328+#endif
20329+
20330+ .quad 0,0 /* TSS */
20331+ .quad 0,0 /* LDT */
20332+ .quad 0,0,0 /* three TLS descriptors */
20333+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20334+ /* asm/segment.h:GDT_ENTRIES must match this */
20335+
20336+ /* zero the remaining page */
20337+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20338+ .endr
20339+
20340 .align 16
20341 .globl early_gdt_descr
20342 early_gdt_descr:
20343 .word GDT_ENTRIES*8-1
20344 early_gdt_descr_base:
20345- .quad INIT_PER_CPU_VAR(gdt_page)
20346+ .quad cpu_gdt_table
20347
20348 ENTRY(phys_base)
20349 /* This must match the first entry in level2_kernel_pgt */
20350 .quad 0x0000000000000000
20351
20352 #include "../../x86/xen/xen-head.S"
20353-
20354- .section .bss, "aw", @nobits
20355+
20356+ .section .rodata,"a",@progbits
20357 .align L1_CACHE_BYTES
20358 ENTRY(idt_table)
20359- .skip IDT_ENTRIES * 16
20360+ .fill 512,8,0
20361
20362 .align L1_CACHE_BYTES
20363 ENTRY(nmi_idt_table)
20364- .skip IDT_ENTRIES * 16
20365+ .fill 512,8,0
20366
20367 __PAGE_ALIGNED_BSS
20368 .align PAGE_SIZE
20369diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20370index 9c3bd4a..e1d9b35 100644
20371--- a/arch/x86/kernel/i386_ksyms_32.c
20372+++ b/arch/x86/kernel/i386_ksyms_32.c
20373@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20374 EXPORT_SYMBOL(cmpxchg8b_emu);
20375 #endif
20376
20377+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20378+
20379 /* Networking helper routines. */
20380 EXPORT_SYMBOL(csum_partial_copy_generic);
20381+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20382+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20383
20384 EXPORT_SYMBOL(__get_user_1);
20385 EXPORT_SYMBOL(__get_user_2);
20386@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20387
20388 EXPORT_SYMBOL(csum_partial);
20389 EXPORT_SYMBOL(empty_zero_page);
20390+
20391+#ifdef CONFIG_PAX_KERNEXEC
20392+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20393+#endif
20394diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20395index 245a71d..89d9ce4 100644
20396--- a/arch/x86/kernel/i387.c
20397+++ b/arch/x86/kernel/i387.c
20398@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20399 static inline bool interrupted_user_mode(void)
20400 {
20401 struct pt_regs *regs = get_irq_regs();
20402- return regs && user_mode_vm(regs);
20403+ return regs && user_mode(regs);
20404 }
20405
20406 /*
20407diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20408index 9a5c460..b332a4b 100644
20409--- a/arch/x86/kernel/i8259.c
20410+++ b/arch/x86/kernel/i8259.c
20411@@ -209,7 +209,7 @@ spurious_8259A_irq:
20412 "spurious 8259A interrupt: IRQ%d.\n", irq);
20413 spurious_irq_mask |= irqmask;
20414 }
20415- atomic_inc(&irq_err_count);
20416+ atomic_inc_unchecked(&irq_err_count);
20417 /*
20418 * Theoretically we do not have to handle this IRQ,
20419 * but in Linux this does not cause problems and is
20420@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20421 /* (slave's support for AEOI in flat mode is to be investigated) */
20422 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20423
20424+ pax_open_kernel();
20425 if (auto_eoi)
20426 /*
20427 * In AEOI mode we just have to mask the interrupt
20428 * when acking.
20429 */
20430- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20431+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20432 else
20433- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20434+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20435+ pax_close_kernel();
20436
20437 udelay(100); /* wait for 8259A to initialize */
20438
20439diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20440index a979b5b..1d6db75 100644
20441--- a/arch/x86/kernel/io_delay.c
20442+++ b/arch/x86/kernel/io_delay.c
20443@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20444 * Quirk table for systems that misbehave (lock up, etc.) if port
20445 * 0x80 is used:
20446 */
20447-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20448+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20449 {
20450 .callback = dmi_io_delay_0xed_port,
20451 .ident = "Compaq Presario V6000",
20452diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20453index 8c96897..be66bfa 100644
20454--- a/arch/x86/kernel/ioport.c
20455+++ b/arch/x86/kernel/ioport.c
20456@@ -6,6 +6,7 @@
20457 #include <linux/sched.h>
20458 #include <linux/kernel.h>
20459 #include <linux/capability.h>
20460+#include <linux/security.h>
20461 #include <linux/errno.h>
20462 #include <linux/types.h>
20463 #include <linux/ioport.h>
20464@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20465
20466 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20467 return -EINVAL;
20468+#ifdef CONFIG_GRKERNSEC_IO
20469+ if (turn_on && grsec_disable_privio) {
20470+ gr_handle_ioperm();
20471+ return -EPERM;
20472+ }
20473+#endif
20474 if (turn_on && !capable(CAP_SYS_RAWIO))
20475 return -EPERM;
20476
20477@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20478 * because the ->io_bitmap_max value must match the bitmap
20479 * contents:
20480 */
20481- tss = &per_cpu(init_tss, get_cpu());
20482+ tss = init_tss + get_cpu();
20483
20484 if (turn_on)
20485 bitmap_clear(t->io_bitmap_ptr, from, num);
20486@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20487 return -EINVAL;
20488 /* Trying to gain more privileges? */
20489 if (level > old) {
20490+#ifdef CONFIG_GRKERNSEC_IO
20491+ if (grsec_disable_privio) {
20492+ gr_handle_iopl();
20493+ return -EPERM;
20494+ }
20495+#endif
20496 if (!capable(CAP_SYS_RAWIO))
20497 return -EPERM;
20498 }
20499diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20500index e4595f1..ee3bfb8 100644
20501--- a/arch/x86/kernel/irq.c
20502+++ b/arch/x86/kernel/irq.c
20503@@ -18,7 +18,7 @@
20504 #include <asm/mce.h>
20505 #include <asm/hw_irq.h>
20506
20507-atomic_t irq_err_count;
20508+atomic_unchecked_t irq_err_count;
20509
20510 /* Function pointer for generic interrupt vector handling */
20511 void (*x86_platform_ipi_callback)(void) = NULL;
20512@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20513 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20514 seq_printf(p, " Machine check polls\n");
20515 #endif
20516- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20517+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20518 #if defined(CONFIG_X86_IO_APIC)
20519- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20520+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20521 #endif
20522 return 0;
20523 }
20524@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20525
20526 u64 arch_irq_stat(void)
20527 {
20528- u64 sum = atomic_read(&irq_err_count);
20529+ u64 sum = atomic_read_unchecked(&irq_err_count);
20530
20531 #ifdef CONFIG_X86_IO_APIC
20532- sum += atomic_read(&irq_mis_count);
20533+ sum += atomic_read_unchecked(&irq_mis_count);
20534 #endif
20535 return sum;
20536 }
20537diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20538index 344faf8..355f60d 100644
20539--- a/arch/x86/kernel/irq_32.c
20540+++ b/arch/x86/kernel/irq_32.c
20541@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20542 __asm__ __volatile__("andl %%esp,%0" :
20543 "=r" (sp) : "0" (THREAD_SIZE - 1));
20544
20545- return sp < (sizeof(struct thread_info) + STACK_WARN);
20546+ return sp < STACK_WARN;
20547 }
20548
20549 static void print_stack_overflow(void)
20550@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20551 * per-CPU IRQ handling contexts (thread information and stack)
20552 */
20553 union irq_ctx {
20554- struct thread_info tinfo;
20555- u32 stack[THREAD_SIZE/sizeof(u32)];
20556+ unsigned long previous_esp;
20557+ u32 stack[THREAD_SIZE/sizeof(u32)];
20558 } __attribute__((aligned(THREAD_SIZE)));
20559
20560 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20561@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20562 static inline int
20563 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20564 {
20565- union irq_ctx *curctx, *irqctx;
20566+ union irq_ctx *irqctx;
20567 u32 *isp, arg1, arg2;
20568
20569- curctx = (union irq_ctx *) current_thread_info();
20570 irqctx = __this_cpu_read(hardirq_ctx);
20571
20572 /*
20573@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20574 * handler) we can't do that and just have to keep using the
20575 * current stack (which is the irq stack already after all)
20576 */
20577- if (unlikely(curctx == irqctx))
20578+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20579 return 0;
20580
20581 /* build the stack frame on the IRQ stack */
20582- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20583- irqctx->tinfo.task = curctx->tinfo.task;
20584- irqctx->tinfo.previous_esp = current_stack_pointer;
20585+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20586+ irqctx->previous_esp = current_stack_pointer;
20587
20588- /* Copy the preempt_count so that the [soft]irq checks work. */
20589- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20590+#ifdef CONFIG_PAX_MEMORY_UDEREF
20591+ __set_fs(MAKE_MM_SEG(0));
20592+#endif
20593
20594 if (unlikely(overflow))
20595 call_on_stack(print_stack_overflow, isp);
20596@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20597 : "0" (irq), "1" (desc), "2" (isp),
20598 "D" (desc->handle_irq)
20599 : "memory", "cc", "ecx");
20600+
20601+#ifdef CONFIG_PAX_MEMORY_UDEREF
20602+ __set_fs(current_thread_info()->addr_limit);
20603+#endif
20604+
20605 return 1;
20606 }
20607
20608@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20609 */
20610 void __cpuinit irq_ctx_init(int cpu)
20611 {
20612- union irq_ctx *irqctx;
20613-
20614 if (per_cpu(hardirq_ctx, cpu))
20615 return;
20616
20617- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20618- THREADINFO_GFP,
20619- THREAD_SIZE_ORDER));
20620- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20621- irqctx->tinfo.cpu = cpu;
20622- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20623- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20624-
20625- per_cpu(hardirq_ctx, cpu) = irqctx;
20626-
20627- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20628- THREADINFO_GFP,
20629- THREAD_SIZE_ORDER));
20630- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20631- irqctx->tinfo.cpu = cpu;
20632- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20633-
20634- per_cpu(softirq_ctx, cpu) = irqctx;
20635+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20636+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20637+
20638+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20639+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20640
20641 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20642 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20643@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20644 asmlinkage void do_softirq(void)
20645 {
20646 unsigned long flags;
20647- struct thread_info *curctx;
20648 union irq_ctx *irqctx;
20649 u32 *isp;
20650
20651@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20652 local_irq_save(flags);
20653
20654 if (local_softirq_pending()) {
20655- curctx = current_thread_info();
20656 irqctx = __this_cpu_read(softirq_ctx);
20657- irqctx->tinfo.task = curctx->task;
20658- irqctx->tinfo.previous_esp = current_stack_pointer;
20659+ irqctx->previous_esp = current_stack_pointer;
20660
20661 /* build the stack frame on the softirq stack */
20662- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20663+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20664+
20665+#ifdef CONFIG_PAX_MEMORY_UDEREF
20666+ __set_fs(MAKE_MM_SEG(0));
20667+#endif
20668
20669 call_on_stack(__do_softirq, isp);
20670+
20671+#ifdef CONFIG_PAX_MEMORY_UDEREF
20672+ __set_fs(current_thread_info()->addr_limit);
20673+#endif
20674+
20675 /*
20676 * Shouldn't happen, we returned above if in_interrupt():
20677 */
20678@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20679 if (unlikely(!desc))
20680 return false;
20681
20682- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20683+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20684 if (unlikely(overflow))
20685 print_stack_overflow();
20686 desc->handle_irq(irq, desc);
20687diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20688index d04d3ec..ea4b374 100644
20689--- a/arch/x86/kernel/irq_64.c
20690+++ b/arch/x86/kernel/irq_64.c
20691@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20692 u64 estack_top, estack_bottom;
20693 u64 curbase = (u64)task_stack_page(current);
20694
20695- if (user_mode_vm(regs))
20696+ if (user_mode(regs))
20697 return;
20698
20699 if (regs->sp >= curbase + sizeof(struct thread_info) +
20700diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20701index dc1404b..bbc43e7 100644
20702--- a/arch/x86/kernel/kdebugfs.c
20703+++ b/arch/x86/kernel/kdebugfs.c
20704@@ -27,7 +27,7 @@ struct setup_data_node {
20705 u32 len;
20706 };
20707
20708-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20709+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20710 size_t count, loff_t *ppos)
20711 {
20712 struct setup_data_node *node = file->private_data;
20713diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20714index 836f832..a8bda67 100644
20715--- a/arch/x86/kernel/kgdb.c
20716+++ b/arch/x86/kernel/kgdb.c
20717@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20718 #ifdef CONFIG_X86_32
20719 switch (regno) {
20720 case GDB_SS:
20721- if (!user_mode_vm(regs))
20722+ if (!user_mode(regs))
20723 *(unsigned long *)mem = __KERNEL_DS;
20724 break;
20725 case GDB_SP:
20726- if (!user_mode_vm(regs))
20727+ if (!user_mode(regs))
20728 *(unsigned long *)mem = kernel_stack_pointer(regs);
20729 break;
20730 case GDB_GS:
20731@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20732 bp->attr.bp_addr = breakinfo[breakno].addr;
20733 bp->attr.bp_len = breakinfo[breakno].len;
20734 bp->attr.bp_type = breakinfo[breakno].type;
20735- info->address = breakinfo[breakno].addr;
20736+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20737+ info->address = ktla_ktva(breakinfo[breakno].addr);
20738+ else
20739+ info->address = breakinfo[breakno].addr;
20740 info->len = breakinfo[breakno].len;
20741 info->type = breakinfo[breakno].type;
20742 val = arch_install_hw_breakpoint(bp);
20743@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20744 case 'k':
20745 /* clear the trace bit */
20746 linux_regs->flags &= ~X86_EFLAGS_TF;
20747- atomic_set(&kgdb_cpu_doing_single_step, -1);
20748+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20749
20750 /* set the trace bit if we're stepping */
20751 if (remcomInBuffer[0] == 's') {
20752 linux_regs->flags |= X86_EFLAGS_TF;
20753- atomic_set(&kgdb_cpu_doing_single_step,
20754+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20755 raw_smp_processor_id());
20756 }
20757
20758@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20759
20760 switch (cmd) {
20761 case DIE_DEBUG:
20762- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20763+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20764 if (user_mode(regs))
20765 return single_step_cont(regs, args);
20766 break;
20767@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20768 #endif /* CONFIG_DEBUG_RODATA */
20769
20770 bpt->type = BP_BREAKPOINT;
20771- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20772+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20773 BREAK_INSTR_SIZE);
20774 if (err)
20775 return err;
20776- err = probe_kernel_write((char *)bpt->bpt_addr,
20777+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20778 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20779 #ifdef CONFIG_DEBUG_RODATA
20780 if (!err)
20781@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20782 return -EBUSY;
20783 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20784 BREAK_INSTR_SIZE);
20785- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20786+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20787 if (err)
20788 return err;
20789 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20790@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20791 if (mutex_is_locked(&text_mutex))
20792 goto knl_write;
20793 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20794- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20795+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20796 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20797 goto knl_write;
20798 return err;
20799 knl_write:
20800 #endif /* CONFIG_DEBUG_RODATA */
20801- return probe_kernel_write((char *)bpt->bpt_addr,
20802+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20803 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20804 }
20805
20806diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20807index c5e410e..ed5a7f0 100644
20808--- a/arch/x86/kernel/kprobes-opt.c
20809+++ b/arch/x86/kernel/kprobes-opt.c
20810@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20811 * Verify if the address gap is in 2GB range, because this uses
20812 * a relative jump.
20813 */
20814- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20815+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20816 if (abs(rel) > 0x7fffffff)
20817 return -ERANGE;
20818
20819@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20820 op->optinsn.size = ret;
20821
20822 /* Copy arch-dep-instance from template */
20823- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20824+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20825
20826 /* Set probe information */
20827 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20828
20829 /* Set probe function call */
20830- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20831+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20832
20833 /* Set returning jmp instruction at the tail of out-of-line buffer */
20834- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20835+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20836 (u8 *)op->kp.addr + op->optinsn.size);
20837
20838 flush_icache_range((unsigned long) buf,
20839@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20840 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20841
20842 /* Backup instructions which will be replaced by jump address */
20843- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20844+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20845 RELATIVE_ADDR_SIZE);
20846
20847 insn_buf[0] = RELATIVEJUMP_OPCODE;
20848@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20849 /* This kprobe is really able to run optimized path. */
20850 op = container_of(p, struct optimized_kprobe, kp);
20851 /* Detour through copied instructions */
20852- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20853+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20854 if (!reenter)
20855 reset_current_kprobe();
20856 preempt_enable_no_resched();
20857diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20858index 57916c0..9e0b9d0 100644
20859--- a/arch/x86/kernel/kprobes.c
20860+++ b/arch/x86/kernel/kprobes.c
20861@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20862 s32 raddr;
20863 } __attribute__((packed)) *insn;
20864
20865- insn = (struct __arch_relative_insn *)from;
20866+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
20867+
20868+ pax_open_kernel();
20869 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20870 insn->op = op;
20871+ pax_close_kernel();
20872 }
20873
20874 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20875@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20876 kprobe_opcode_t opcode;
20877 kprobe_opcode_t *orig_opcodes = opcodes;
20878
20879- if (search_exception_tables((unsigned long)opcodes))
20880+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20881 return 0; /* Page fault may occur on this address. */
20882
20883 retry:
20884@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20885 * for the first byte, we can recover the original instruction
20886 * from it and kp->opcode.
20887 */
20888- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20889+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20890 buf[0] = kp->opcode;
20891- return (unsigned long)buf;
20892+ return ktva_ktla((unsigned long)buf);
20893 }
20894
20895 /*
20896@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20897 /* Another subsystem puts a breakpoint, failed to recover */
20898 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20899 return 0;
20900+ pax_open_kernel();
20901 memcpy(dest, insn.kaddr, insn.length);
20902+ pax_close_kernel();
20903
20904 #ifdef CONFIG_X86_64
20905 if (insn_rip_relative(&insn)) {
20906@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20907 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20908 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20909 disp = (u8 *) dest + insn_offset_displacement(&insn);
20910+ pax_open_kernel();
20911 *(s32 *) disp = (s32) newdisp;
20912+ pax_close_kernel();
20913 }
20914 #endif
20915 return insn.length;
20916@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20917 * nor set current_kprobe, because it doesn't use single
20918 * stepping.
20919 */
20920- regs->ip = (unsigned long)p->ainsn.insn;
20921+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20922 preempt_enable_no_resched();
20923 return;
20924 }
20925@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20926 regs->flags &= ~X86_EFLAGS_IF;
20927 /* single step inline if the instruction is an int3 */
20928 if (p->opcode == BREAKPOINT_INSTRUCTION)
20929- regs->ip = (unsigned long)p->addr;
20930+ regs->ip = ktla_ktva((unsigned long)p->addr);
20931 else
20932- regs->ip = (unsigned long)p->ainsn.insn;
20933+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20934 }
20935
20936 /*
20937@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20938 setup_singlestep(p, regs, kcb, 0);
20939 return 1;
20940 }
20941- } else if (*addr != BREAKPOINT_INSTRUCTION) {
20942+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20943 /*
20944 * The breakpoint instruction was removed right
20945 * after we hit it. Another cpu has removed
20946@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20947 " movq %rax, 152(%rsp)\n"
20948 RESTORE_REGS_STRING
20949 " popfq\n"
20950+#ifdef KERNEXEC_PLUGIN
20951+ " btsq $63,(%rsp)\n"
20952+#endif
20953 #else
20954 " pushf\n"
20955 SAVE_REGS_STRING
20956@@ -788,7 +798,7 @@ static void __kprobes
20957 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20958 {
20959 unsigned long *tos = stack_addr(regs);
20960- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20961+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20962 unsigned long orig_ip = (unsigned long)p->addr;
20963 kprobe_opcode_t *insn = p->ainsn.insn;
20964
20965@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20966 struct die_args *args = data;
20967 int ret = NOTIFY_DONE;
20968
20969- if (args->regs && user_mode_vm(args->regs))
20970+ if (args->regs && user_mode(args->regs))
20971 return ret;
20972
20973 switch (val) {
20974diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20975index 9c2bd8b..bb1131c 100644
20976--- a/arch/x86/kernel/kvm.c
20977+++ b/arch/x86/kernel/kvm.c
20978@@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20979 return NOTIFY_OK;
20980 }
20981
20982-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20983+static struct notifier_block kvm_cpu_notifier = {
20984 .notifier_call = kvm_cpu_notify,
20985 };
20986 #endif
20987diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20988index ebc9873..1b9724b 100644
20989--- a/arch/x86/kernel/ldt.c
20990+++ b/arch/x86/kernel/ldt.c
20991@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20992 if (reload) {
20993 #ifdef CONFIG_SMP
20994 preempt_disable();
20995- load_LDT(pc);
20996+ load_LDT_nolock(pc);
20997 if (!cpumask_equal(mm_cpumask(current->mm),
20998 cpumask_of(smp_processor_id())))
20999 smp_call_function(flush_ldt, current->mm, 1);
21000 preempt_enable();
21001 #else
21002- load_LDT(pc);
21003+ load_LDT_nolock(pc);
21004 #endif
21005 }
21006 if (oldsize) {
21007@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21008 return err;
21009
21010 for (i = 0; i < old->size; i++)
21011- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21012+ write_ldt_entry(new->ldt, i, old->ldt + i);
21013 return 0;
21014 }
21015
21016@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21017 retval = copy_ldt(&mm->context, &old_mm->context);
21018 mutex_unlock(&old_mm->context.lock);
21019 }
21020+
21021+ if (tsk == current) {
21022+ mm->context.vdso = 0;
21023+
21024+#ifdef CONFIG_X86_32
21025+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21026+ mm->context.user_cs_base = 0UL;
21027+ mm->context.user_cs_limit = ~0UL;
21028+
21029+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21030+ cpus_clear(mm->context.cpu_user_cs_mask);
21031+#endif
21032+
21033+#endif
21034+#endif
21035+
21036+ }
21037+
21038 return retval;
21039 }
21040
21041@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21042 }
21043 }
21044
21045+#ifdef CONFIG_PAX_SEGMEXEC
21046+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21047+ error = -EINVAL;
21048+ goto out_unlock;
21049+ }
21050+#endif
21051+
21052 fill_ldt(&ldt, &ldt_info);
21053 if (oldmode)
21054 ldt.avl = 0;
21055diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21056index 5b19e4d..6476a76 100644
21057--- a/arch/x86/kernel/machine_kexec_32.c
21058+++ b/arch/x86/kernel/machine_kexec_32.c
21059@@ -26,7 +26,7 @@
21060 #include <asm/cacheflush.h>
21061 #include <asm/debugreg.h>
21062
21063-static void set_idt(void *newidt, __u16 limit)
21064+static void set_idt(struct desc_struct *newidt, __u16 limit)
21065 {
21066 struct desc_ptr curidt;
21067
21068@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21069 }
21070
21071
21072-static void set_gdt(void *newgdt, __u16 limit)
21073+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21074 {
21075 struct desc_ptr curgdt;
21076
21077@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21078 }
21079
21080 control_page = page_address(image->control_code_page);
21081- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21082+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21083
21084 relocate_kernel_ptr = control_page;
21085 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21086diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21087index 3a04b22..1d2eb09 100644
21088--- a/arch/x86/kernel/microcode_core.c
21089+++ b/arch/x86/kernel/microcode_core.c
21090@@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21091 return NOTIFY_OK;
21092 }
21093
21094-static struct notifier_block __refdata mc_cpu_notifier = {
21095+static struct notifier_block mc_cpu_notifier = {
21096 .notifier_call = mc_cpu_callback,
21097 };
21098
21099diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21100index 3544aed..01ddc1c 100644
21101--- a/arch/x86/kernel/microcode_intel.c
21102+++ b/arch/x86/kernel/microcode_intel.c
21103@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21104
21105 static int get_ucode_user(void *to, const void *from, size_t n)
21106 {
21107- return copy_from_user(to, from, n);
21108+ return copy_from_user(to, (const void __force_user *)from, n);
21109 }
21110
21111 static enum ucode_state
21112 request_microcode_user(int cpu, const void __user *buf, size_t size)
21113 {
21114- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21115+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21116 }
21117
21118 static void microcode_fini_cpu(int cpu)
21119diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21120index 216a4d7..228255a 100644
21121--- a/arch/x86/kernel/module.c
21122+++ b/arch/x86/kernel/module.c
21123@@ -43,15 +43,60 @@ do { \
21124 } while (0)
21125 #endif
21126
21127-void *module_alloc(unsigned long size)
21128+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21129 {
21130- if (PAGE_ALIGN(size) > MODULES_LEN)
21131+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21132 return NULL;
21133 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21134- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21135+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21136 -1, __builtin_return_address(0));
21137 }
21138
21139+void *module_alloc(unsigned long size)
21140+{
21141+
21142+#ifdef CONFIG_PAX_KERNEXEC
21143+ return __module_alloc(size, PAGE_KERNEL);
21144+#else
21145+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21146+#endif
21147+
21148+}
21149+
21150+#ifdef CONFIG_PAX_KERNEXEC
21151+#ifdef CONFIG_X86_32
21152+void *module_alloc_exec(unsigned long size)
21153+{
21154+ struct vm_struct *area;
21155+
21156+ if (size == 0)
21157+ return NULL;
21158+
21159+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21160+ return area ? area->addr : NULL;
21161+}
21162+EXPORT_SYMBOL(module_alloc_exec);
21163+
21164+void module_free_exec(struct module *mod, void *module_region)
21165+{
21166+ vunmap(module_region);
21167+}
21168+EXPORT_SYMBOL(module_free_exec);
21169+#else
21170+void module_free_exec(struct module *mod, void *module_region)
21171+{
21172+ module_free(mod, module_region);
21173+}
21174+EXPORT_SYMBOL(module_free_exec);
21175+
21176+void *module_alloc_exec(unsigned long size)
21177+{
21178+ return __module_alloc(size, PAGE_KERNEL_RX);
21179+}
21180+EXPORT_SYMBOL(module_alloc_exec);
21181+#endif
21182+#endif
21183+
21184 #ifdef CONFIG_X86_32
21185 int apply_relocate(Elf32_Shdr *sechdrs,
21186 const char *strtab,
21187@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21188 unsigned int i;
21189 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21190 Elf32_Sym *sym;
21191- uint32_t *location;
21192+ uint32_t *plocation, location;
21193
21194 DEBUGP("Applying relocate section %u to %u\n",
21195 relsec, sechdrs[relsec].sh_info);
21196 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21197 /* This is where to make the change */
21198- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21199- + rel[i].r_offset;
21200+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21201+ location = (uint32_t)plocation;
21202+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21203+ plocation = ktla_ktva((void *)plocation);
21204 /* This is the symbol it is referring to. Note that all
21205 undefined symbols have been resolved. */
21206 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21207@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21208 switch (ELF32_R_TYPE(rel[i].r_info)) {
21209 case R_386_32:
21210 /* We add the value into the location given */
21211- *location += sym->st_value;
21212+ pax_open_kernel();
21213+ *plocation += sym->st_value;
21214+ pax_close_kernel();
21215 break;
21216 case R_386_PC32:
21217 /* Add the value, subtract its position */
21218- *location += sym->st_value - (uint32_t)location;
21219+ pax_open_kernel();
21220+ *plocation += sym->st_value - location;
21221+ pax_close_kernel();
21222 break;
21223 default:
21224 pr_err("%s: Unknown relocation: %u\n",
21225@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21226 case R_X86_64_NONE:
21227 break;
21228 case R_X86_64_64:
21229+ pax_open_kernel();
21230 *(u64 *)loc = val;
21231+ pax_close_kernel();
21232 break;
21233 case R_X86_64_32:
21234+ pax_open_kernel();
21235 *(u32 *)loc = val;
21236+ pax_close_kernel();
21237 if (val != *(u32 *)loc)
21238 goto overflow;
21239 break;
21240 case R_X86_64_32S:
21241+ pax_open_kernel();
21242 *(s32 *)loc = val;
21243+ pax_close_kernel();
21244 if ((s64)val != *(s32 *)loc)
21245 goto overflow;
21246 break;
21247 case R_X86_64_PC32:
21248 val -= (u64)loc;
21249+ pax_open_kernel();
21250 *(u32 *)loc = val;
21251+ pax_close_kernel();
21252+
21253 #if 0
21254 if ((s64)val != *(s32 *)loc)
21255 goto overflow;
21256diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21257index 4929502..686c291 100644
21258--- a/arch/x86/kernel/msr.c
21259+++ b/arch/x86/kernel/msr.c
21260@@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21261 return notifier_from_errno(err);
21262 }
21263
21264-static struct notifier_block __refdata msr_class_cpu_notifier = {
21265+static struct notifier_block msr_class_cpu_notifier = {
21266 .notifier_call = msr_class_cpu_callback,
21267 };
21268
21269diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21270index f84f5c5..f404e81 100644
21271--- a/arch/x86/kernel/nmi.c
21272+++ b/arch/x86/kernel/nmi.c
21273@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21274 return handled;
21275 }
21276
21277-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21278+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21279 {
21280 struct nmi_desc *desc = nmi_to_desc(type);
21281 unsigned long flags;
21282@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21283 * event confuses some handlers (kdump uses this flag)
21284 */
21285 if (action->flags & NMI_FLAG_FIRST)
21286- list_add_rcu(&action->list, &desc->head);
21287+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21288 else
21289- list_add_tail_rcu(&action->list, &desc->head);
21290+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21291
21292 spin_unlock_irqrestore(&desc->lock, flags);
21293 return 0;
21294@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21295 if (!strcmp(n->name, name)) {
21296 WARN(in_nmi(),
21297 "Trying to free NMI (%s) from NMI context!\n", n->name);
21298- list_del_rcu(&n->list);
21299+ pax_list_del_rcu((struct list_head *)&n->list);
21300 break;
21301 }
21302 }
21303@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21304 dotraplinkage notrace __kprobes void
21305 do_nmi(struct pt_regs *regs, long error_code)
21306 {
21307+
21308+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21309+ if (!user_mode(regs)) {
21310+ unsigned long cs = regs->cs & 0xFFFF;
21311+ unsigned long ip = ktva_ktla(regs->ip);
21312+
21313+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21314+ regs->ip = ip;
21315+ }
21316+#endif
21317+
21318 nmi_nesting_preprocess(regs);
21319
21320 nmi_enter();
21321diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21322index 6d9582e..f746287 100644
21323--- a/arch/x86/kernel/nmi_selftest.c
21324+++ b/arch/x86/kernel/nmi_selftest.c
21325@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21326 {
21327 /* trap all the unknown NMIs we may generate */
21328 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21329- __initdata);
21330+ __initconst);
21331 }
21332
21333 static void __init cleanup_nmi_testsuite(void)
21334@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21335 unsigned long timeout;
21336
21337 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21338- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21339+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21340 nmi_fail = FAILURE;
21341 return;
21342 }
21343diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21344index 676b8c7..870ba04 100644
21345--- a/arch/x86/kernel/paravirt-spinlocks.c
21346+++ b/arch/x86/kernel/paravirt-spinlocks.c
21347@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21348 arch_spin_lock(lock);
21349 }
21350
21351-struct pv_lock_ops pv_lock_ops = {
21352+struct pv_lock_ops pv_lock_ops __read_only = {
21353 #ifdef CONFIG_SMP
21354 .spin_is_locked = __ticket_spin_is_locked,
21355 .spin_is_contended = __ticket_spin_is_contended,
21356diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21357index 17fff18..5cfa0f4 100644
21358--- a/arch/x86/kernel/paravirt.c
21359+++ b/arch/x86/kernel/paravirt.c
21360@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21361 {
21362 return x;
21363 }
21364+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21365+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21366+#endif
21367
21368 void __init default_banner(void)
21369 {
21370@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21371 if (opfunc == NULL)
21372 /* If there's no function, patch it with a ud2a (BUG) */
21373 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21374- else if (opfunc == _paravirt_nop)
21375+ else if (opfunc == (void *)_paravirt_nop)
21376 /* If the operation is a nop, then nop the callsite */
21377 ret = paravirt_patch_nop();
21378
21379 /* identity functions just return their single argument */
21380- else if (opfunc == _paravirt_ident_32)
21381+ else if (opfunc == (void *)_paravirt_ident_32)
21382 ret = paravirt_patch_ident_32(insnbuf, len);
21383- else if (opfunc == _paravirt_ident_64)
21384+ else if (opfunc == (void *)_paravirt_ident_64)
21385 ret = paravirt_patch_ident_64(insnbuf, len);
21386+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21387+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21388+ ret = paravirt_patch_ident_64(insnbuf, len);
21389+#endif
21390
21391 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21392 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21393@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21394 if (insn_len > len || start == NULL)
21395 insn_len = len;
21396 else
21397- memcpy(insnbuf, start, insn_len);
21398+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21399
21400 return insn_len;
21401 }
21402@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21403 preempt_enable();
21404 }
21405
21406-struct pv_info pv_info = {
21407+struct pv_info pv_info __read_only = {
21408 .name = "bare hardware",
21409 .paravirt_enabled = 0,
21410 .kernel_rpl = 0,
21411@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21412 #endif
21413 };
21414
21415-struct pv_init_ops pv_init_ops = {
21416+struct pv_init_ops pv_init_ops __read_only = {
21417 .patch = native_patch,
21418 };
21419
21420-struct pv_time_ops pv_time_ops = {
21421+struct pv_time_ops pv_time_ops __read_only = {
21422 .sched_clock = native_sched_clock,
21423 .steal_clock = native_steal_clock,
21424 };
21425
21426-struct pv_irq_ops pv_irq_ops = {
21427+struct pv_irq_ops pv_irq_ops __read_only = {
21428 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21429 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21430 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21431@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21432 #endif
21433 };
21434
21435-struct pv_cpu_ops pv_cpu_ops = {
21436+struct pv_cpu_ops pv_cpu_ops __read_only = {
21437 .cpuid = native_cpuid,
21438 .get_debugreg = native_get_debugreg,
21439 .set_debugreg = native_set_debugreg,
21440@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21441 .end_context_switch = paravirt_nop,
21442 };
21443
21444-struct pv_apic_ops pv_apic_ops = {
21445+struct pv_apic_ops pv_apic_ops __read_only= {
21446 #ifdef CONFIG_X86_LOCAL_APIC
21447 .startup_ipi_hook = paravirt_nop,
21448 #endif
21449 };
21450
21451-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21452+#ifdef CONFIG_X86_32
21453+#ifdef CONFIG_X86_PAE
21454+/* 64-bit pagetable entries */
21455+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21456+#else
21457 /* 32-bit pagetable entries */
21458 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21459+#endif
21460 #else
21461 /* 64-bit pagetable entries */
21462 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21463 #endif
21464
21465-struct pv_mmu_ops pv_mmu_ops = {
21466+struct pv_mmu_ops pv_mmu_ops __read_only = {
21467
21468 .read_cr2 = native_read_cr2,
21469 .write_cr2 = native_write_cr2,
21470@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21471 .make_pud = PTE_IDENT,
21472
21473 .set_pgd = native_set_pgd,
21474+ .set_pgd_batched = native_set_pgd_batched,
21475 #endif
21476 #endif /* PAGETABLE_LEVELS >= 3 */
21477
21478@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21479 },
21480
21481 .set_fixmap = native_set_fixmap,
21482+
21483+#ifdef CONFIG_PAX_KERNEXEC
21484+ .pax_open_kernel = native_pax_open_kernel,
21485+ .pax_close_kernel = native_pax_close_kernel,
21486+#endif
21487+
21488 };
21489
21490 EXPORT_SYMBOL_GPL(pv_time_ops);
21491diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21492index 35ccf75..7a15747 100644
21493--- a/arch/x86/kernel/pci-iommu_table.c
21494+++ b/arch/x86/kernel/pci-iommu_table.c
21495@@ -2,7 +2,7 @@
21496 #include <asm/iommu_table.h>
21497 #include <linux/string.h>
21498 #include <linux/kallsyms.h>
21499-
21500+#include <linux/sched.h>
21501
21502 #define DEBUG 1
21503
21504diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21505index 6c483ba..d10ce2f 100644
21506--- a/arch/x86/kernel/pci-swiotlb.c
21507+++ b/arch/x86/kernel/pci-swiotlb.c
21508@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21509 void *vaddr, dma_addr_t dma_addr,
21510 struct dma_attrs *attrs)
21511 {
21512- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21513+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21514 }
21515
21516 static struct dma_map_ops swiotlb_dma_ops = {
21517diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21518index 2ed787f..f70c9f6 100644
21519--- a/arch/x86/kernel/process.c
21520+++ b/arch/x86/kernel/process.c
21521@@ -36,7 +36,8 @@
21522 * section. Since TSS's are completely CPU-local, we want them
21523 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21524 */
21525-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21526+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21527+EXPORT_SYMBOL(init_tss);
21528
21529 #ifdef CONFIG_X86_64
21530 static DEFINE_PER_CPU(unsigned char, is_idle);
21531@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21532 task_xstate_cachep =
21533 kmem_cache_create("task_xstate", xstate_size,
21534 __alignof__(union thread_xstate),
21535- SLAB_PANIC | SLAB_NOTRACK, NULL);
21536+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21537 }
21538
21539 /*
21540@@ -105,7 +106,7 @@ void exit_thread(void)
21541 unsigned long *bp = t->io_bitmap_ptr;
21542
21543 if (bp) {
21544- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21545+ struct tss_struct *tss = init_tss + get_cpu();
21546
21547 t->io_bitmap_ptr = NULL;
21548 clear_thread_flag(TIF_IO_BITMAP);
21549@@ -136,7 +137,7 @@ void show_regs_common(void)
21550 board = dmi_get_system_info(DMI_BOARD_NAME);
21551
21552 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21553- current->pid, current->comm, print_tainted(),
21554+ task_pid_nr(current), current->comm, print_tainted(),
21555 init_utsname()->release,
21556 (int)strcspn(init_utsname()->version, " "),
21557 init_utsname()->version,
21558@@ -149,6 +150,9 @@ void flush_thread(void)
21559 {
21560 struct task_struct *tsk = current;
21561
21562+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21563+ loadsegment(gs, 0);
21564+#endif
21565 flush_ptrace_hw_breakpoint(tsk);
21566 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21567 drop_init_fpu(tsk);
21568@@ -301,7 +305,7 @@ static void __exit_idle(void)
21569 void exit_idle(void)
21570 {
21571 /* idle loop has pid 0 */
21572- if (current->pid)
21573+ if (task_pid_nr(current))
21574 return;
21575 __exit_idle();
21576 }
21577@@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21578
21579 return ret;
21580 }
21581-void stop_this_cpu(void *dummy)
21582+__noreturn void stop_this_cpu(void *dummy)
21583 {
21584 local_irq_disable();
21585 /*
21586@@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21587 }
21588 early_param("idle", idle_setup);
21589
21590-unsigned long arch_align_stack(unsigned long sp)
21591+#ifdef CONFIG_PAX_RANDKSTACK
21592+void pax_randomize_kstack(struct pt_regs *regs)
21593 {
21594- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21595- sp -= get_random_int() % 8192;
21596- return sp & ~0xf;
21597-}
21598+ struct thread_struct *thread = &current->thread;
21599+ unsigned long time;
21600
21601-unsigned long arch_randomize_brk(struct mm_struct *mm)
21602-{
21603- unsigned long range_end = mm->brk + 0x02000000;
21604- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21605-}
21606+ if (!randomize_va_space)
21607+ return;
21608+
21609+ if (v8086_mode(regs))
21610+ return;
21611
21612+ rdtscl(time);
21613+
21614+ /* P4 seems to return a 0 LSB, ignore it */
21615+#ifdef CONFIG_MPENTIUM4
21616+ time &= 0x3EUL;
21617+ time <<= 2;
21618+#elif defined(CONFIG_X86_64)
21619+ time &= 0xFUL;
21620+ time <<= 4;
21621+#else
21622+ time &= 0x1FUL;
21623+ time <<= 3;
21624+#endif
21625+
21626+ thread->sp0 ^= time;
21627+ load_sp0(init_tss + smp_processor_id(), thread);
21628+
21629+#ifdef CONFIG_X86_64
21630+ this_cpu_write(kernel_stack, thread->sp0);
21631+#endif
21632+}
21633+#endif
21634diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21635index b5a8905..d9cacac 100644
21636--- a/arch/x86/kernel/process_32.c
21637+++ b/arch/x86/kernel/process_32.c
21638@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21639 unsigned long thread_saved_pc(struct task_struct *tsk)
21640 {
21641 return ((unsigned long *)tsk->thread.sp)[3];
21642+//XXX return tsk->thread.eip;
21643 }
21644
21645 void __show_regs(struct pt_regs *regs, int all)
21646@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21647 unsigned long sp;
21648 unsigned short ss, gs;
21649
21650- if (user_mode_vm(regs)) {
21651+ if (user_mode(regs)) {
21652 sp = regs->sp;
21653 ss = regs->ss & 0xffff;
21654- gs = get_user_gs(regs);
21655 } else {
21656 sp = kernel_stack_pointer(regs);
21657 savesegment(ss, ss);
21658- savesegment(gs, gs);
21659 }
21660+ gs = get_user_gs(regs);
21661
21662 show_regs_common();
21663
21664 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21665 (u16)regs->cs, regs->ip, regs->flags,
21666- smp_processor_id());
21667+ raw_smp_processor_id());
21668 print_symbol("EIP is at %s\n", regs->ip);
21669
21670 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21671@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21672 int copy_thread(unsigned long clone_flags, unsigned long sp,
21673 unsigned long arg, struct task_struct *p)
21674 {
21675- struct pt_regs *childregs = task_pt_regs(p);
21676+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21677 struct task_struct *tsk;
21678 int err;
21679
21680 p->thread.sp = (unsigned long) childregs;
21681 p->thread.sp0 = (unsigned long) (childregs+1);
21682+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21683
21684 if (unlikely(p->flags & PF_KTHREAD)) {
21685 /* kernel thread */
21686 memset(childregs, 0, sizeof(struct pt_regs));
21687 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21688- task_user_gs(p) = __KERNEL_STACK_CANARY;
21689- childregs->ds = __USER_DS;
21690- childregs->es = __USER_DS;
21691+ savesegment(gs, childregs->gs);
21692+ childregs->ds = __KERNEL_DS;
21693+ childregs->es = __KERNEL_DS;
21694 childregs->fs = __KERNEL_PERCPU;
21695 childregs->bx = sp; /* function */
21696 childregs->bp = arg;
21697@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21698 struct thread_struct *prev = &prev_p->thread,
21699 *next = &next_p->thread;
21700 int cpu = smp_processor_id();
21701- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21702+ struct tss_struct *tss = init_tss + cpu;
21703 fpu_switch_t fpu;
21704
21705 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21706@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21707 */
21708 lazy_save_gs(prev->gs);
21709
21710+#ifdef CONFIG_PAX_MEMORY_UDEREF
21711+ __set_fs(task_thread_info(next_p)->addr_limit);
21712+#endif
21713+
21714 /*
21715 * Load the per-thread Thread-Local Storage descriptor.
21716 */
21717@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21718 */
21719 arch_end_context_switch(next_p);
21720
21721+ this_cpu_write(current_task, next_p);
21722+ this_cpu_write(current_tinfo, &next_p->tinfo);
21723+
21724 /*
21725 * Restore %gs if needed (which is common)
21726 */
21727@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21728
21729 switch_fpu_finish(next_p, fpu);
21730
21731- this_cpu_write(current_task, next_p);
21732-
21733 return prev_p;
21734 }
21735
21736@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21737 } while (count++ < 16);
21738 return 0;
21739 }
21740-
21741diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21742index 6e68a61..955a9a5 100644
21743--- a/arch/x86/kernel/process_64.c
21744+++ b/arch/x86/kernel/process_64.c
21745@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21746 struct pt_regs *childregs;
21747 struct task_struct *me = current;
21748
21749- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21750+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21751 childregs = task_pt_regs(p);
21752 p->thread.sp = (unsigned long) childregs;
21753 p->thread.usersp = me->thread.usersp;
21754+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21755 set_tsk_thread_flag(p, TIF_FORK);
21756 p->fpu_counter = 0;
21757 p->thread.io_bitmap_ptr = NULL;
21758@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21759 struct thread_struct *prev = &prev_p->thread;
21760 struct thread_struct *next = &next_p->thread;
21761 int cpu = smp_processor_id();
21762- struct tss_struct *tss = &per_cpu(init_tss, cpu);
21763+ struct tss_struct *tss = init_tss + cpu;
21764 unsigned fsindex, gsindex;
21765 fpu_switch_t fpu;
21766
21767@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21768 prev->usersp = this_cpu_read(old_rsp);
21769 this_cpu_write(old_rsp, next->usersp);
21770 this_cpu_write(current_task, next_p);
21771+ this_cpu_write(current_tinfo, &next_p->tinfo);
21772
21773- this_cpu_write(kernel_stack,
21774- (unsigned long)task_stack_page(next_p) +
21775- THREAD_SIZE - KERNEL_STACK_OFFSET);
21776+ this_cpu_write(kernel_stack, next->sp0);
21777
21778 /*
21779 * Now maybe reload the debug registers and handle I/O bitmaps
21780@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21781 if (!p || p == current || p->state == TASK_RUNNING)
21782 return 0;
21783 stack = (unsigned long)task_stack_page(p);
21784- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21785+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21786 return 0;
21787 fp = *(u64 *)(p->thread.sp);
21788 do {
21789- if (fp < (unsigned long)stack ||
21790- fp >= (unsigned long)stack+THREAD_SIZE)
21791+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21792 return 0;
21793 ip = *(u64 *)(fp+8);
21794 if (!in_sched_functions(ip))
21795diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21796index b629bbe..0fa615a 100644
21797--- a/arch/x86/kernel/ptrace.c
21798+++ b/arch/x86/kernel/ptrace.c
21799@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21800 {
21801 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21802 unsigned long sp = (unsigned long)&regs->sp;
21803- struct thread_info *tinfo;
21804
21805- if (context == (sp & ~(THREAD_SIZE - 1)))
21806+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21807 return sp;
21808
21809- tinfo = (struct thread_info *)context;
21810- if (tinfo->previous_esp)
21811- return tinfo->previous_esp;
21812+ sp = *(unsigned long *)context;
21813+ if (sp)
21814+ return sp;
21815
21816 return (unsigned long)regs;
21817 }
21818@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21819 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21820 {
21821 int i;
21822- int dr7 = 0;
21823+ unsigned long dr7 = 0;
21824 struct arch_hw_breakpoint *info;
21825
21826 for (i = 0; i < HBP_NUM; i++) {
21827@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21828 unsigned long addr, unsigned long data)
21829 {
21830 int ret;
21831- unsigned long __user *datap = (unsigned long __user *)data;
21832+ unsigned long __user *datap = (__force unsigned long __user *)data;
21833
21834 switch (request) {
21835 /* read the word at location addr in the USER area. */
21836@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21837 if ((int) addr < 0)
21838 return -EIO;
21839 ret = do_get_thread_area(child, addr,
21840- (struct user_desc __user *)data);
21841+ (__force struct user_desc __user *) data);
21842 break;
21843
21844 case PTRACE_SET_THREAD_AREA:
21845 if ((int) addr < 0)
21846 return -EIO;
21847 ret = do_set_thread_area(child, addr,
21848- (struct user_desc __user *)data, 0);
21849+ (__force struct user_desc __user *) data, 0);
21850 break;
21851 #endif
21852
21853@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21854
21855 #ifdef CONFIG_X86_64
21856
21857-static struct user_regset x86_64_regsets[] __read_mostly = {
21858+static user_regset_no_const x86_64_regsets[] __read_only = {
21859 [REGSET_GENERAL] = {
21860 .core_note_type = NT_PRSTATUS,
21861 .n = sizeof(struct user_regs_struct) / sizeof(long),
21862@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21863 #endif /* CONFIG_X86_64 */
21864
21865 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21866-static struct user_regset x86_32_regsets[] __read_mostly = {
21867+static user_regset_no_const x86_32_regsets[] __read_only = {
21868 [REGSET_GENERAL] = {
21869 .core_note_type = NT_PRSTATUS,
21870 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21871@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21872 */
21873 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21874
21875-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21876+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21877 {
21878 #ifdef CONFIG_X86_64
21879 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21880@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21881 memset(info, 0, sizeof(*info));
21882 info->si_signo = SIGTRAP;
21883 info->si_code = si_code;
21884- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21885+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21886 }
21887
21888 void user_single_step_siginfo(struct task_struct *tsk,
21889@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21890 # define IS_IA32 0
21891 #endif
21892
21893+#ifdef CONFIG_GRKERNSEC_SETXID
21894+extern void gr_delayed_cred_worker(void);
21895+#endif
21896+
21897 /*
21898 * We must return the syscall number to actually look up in the table.
21899 * This can be -1L to skip running any syscall at all.
21900@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21901
21902 user_exit();
21903
21904+#ifdef CONFIG_GRKERNSEC_SETXID
21905+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21906+ gr_delayed_cred_worker();
21907+#endif
21908+
21909 /*
21910 * If we stepped into a sysenter/syscall insn, it trapped in
21911 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21912@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21913 */
21914 user_exit();
21915
21916+#ifdef CONFIG_GRKERNSEC_SETXID
21917+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21918+ gr_delayed_cred_worker();
21919+#endif
21920+
21921 audit_syscall_exit(regs);
21922
21923 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21924diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21925index 85c3959..76b89f9 100644
21926--- a/arch/x86/kernel/pvclock.c
21927+++ b/arch/x86/kernel/pvclock.c
21928@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21929 return pv_tsc_khz;
21930 }
21931
21932-static atomic64_t last_value = ATOMIC64_INIT(0);
21933+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21934
21935 void pvclock_resume(void)
21936 {
21937- atomic64_set(&last_value, 0);
21938+ atomic64_set_unchecked(&last_value, 0);
21939 }
21940
21941 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21942@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21943 * updating at the same time, and one of them could be slightly behind,
21944 * making the assumption that last_value always go forward fail to hold.
21945 */
21946- last = atomic64_read(&last_value);
21947+ last = atomic64_read_unchecked(&last_value);
21948 do {
21949 if (ret < last)
21950 return last;
21951- last = atomic64_cmpxchg(&last_value, last, ret);
21952+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21953 } while (unlikely(last != ret));
21954
21955 return ret;
21956diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21957index 76fa1e9..abf09ea 100644
21958--- a/arch/x86/kernel/reboot.c
21959+++ b/arch/x86/kernel/reboot.c
21960@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21961 EXPORT_SYMBOL(pm_power_off);
21962
21963 static const struct desc_ptr no_idt = {};
21964-static int reboot_mode;
21965+static unsigned short reboot_mode;
21966 enum reboot_type reboot_type = BOOT_ACPI;
21967 int reboot_force;
21968
21969@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21970
21971 void __noreturn machine_real_restart(unsigned int type)
21972 {
21973+
21974+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21975+ struct desc_struct *gdt;
21976+#endif
21977+
21978 local_irq_disable();
21979
21980 /*
21981@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21982
21983 /* Jump to the identity-mapped low memory code */
21984 #ifdef CONFIG_X86_32
21985- asm volatile("jmpl *%0" : :
21986+
21987+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21988+ gdt = get_cpu_gdt_table(smp_processor_id());
21989+ pax_open_kernel();
21990+#ifdef CONFIG_PAX_MEMORY_UDEREF
21991+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21992+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21993+ loadsegment(ds, __KERNEL_DS);
21994+ loadsegment(es, __KERNEL_DS);
21995+ loadsegment(ss, __KERNEL_DS);
21996+#endif
21997+#ifdef CONFIG_PAX_KERNEXEC
21998+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21999+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22000+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22001+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22002+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22003+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22004+#endif
22005+ pax_close_kernel();
22006+#endif
22007+
22008+ asm volatile("ljmpl *%0" : :
22009 "rm" (real_mode_header->machine_real_restart_asm),
22010 "a" (type));
22011 #else
22012@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22013 * try to force a triple fault and then cycle between hitting the keyboard
22014 * controller and doing that
22015 */
22016-static void native_machine_emergency_restart(void)
22017+static void __noreturn native_machine_emergency_restart(void)
22018 {
22019 int i;
22020 int attempt = 0;
22021@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22022 #endif
22023 }
22024
22025-static void __machine_emergency_restart(int emergency)
22026+static void __noreturn __machine_emergency_restart(int emergency)
22027 {
22028 reboot_emergency = emergency;
22029 machine_ops.emergency_restart();
22030 }
22031
22032-static void native_machine_restart(char *__unused)
22033+static void __noreturn native_machine_restart(char *__unused)
22034 {
22035 pr_notice("machine restart\n");
22036
22037@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22038 __machine_emergency_restart(0);
22039 }
22040
22041-static void native_machine_halt(void)
22042+static void __noreturn native_machine_halt(void)
22043 {
22044 /* Stop other cpus and apics */
22045 machine_shutdown();
22046@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22047 stop_this_cpu(NULL);
22048 }
22049
22050-static void native_machine_power_off(void)
22051+static void __noreturn native_machine_power_off(void)
22052 {
22053 if (pm_power_off) {
22054 if (!reboot_force)
22055@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22056 }
22057 /* A fallback in case there is no PM info available */
22058 tboot_shutdown(TB_SHUTDOWN_HALT);
22059+ unreachable();
22060 }
22061
22062-struct machine_ops machine_ops = {
22063+struct machine_ops machine_ops __read_only = {
22064 .power_off = native_machine_power_off,
22065 .shutdown = native_machine_shutdown,
22066 .emergency_restart = native_machine_emergency_restart,
22067diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22068index 7a6f3b3..bed145d7 100644
22069--- a/arch/x86/kernel/relocate_kernel_64.S
22070+++ b/arch/x86/kernel/relocate_kernel_64.S
22071@@ -11,6 +11,7 @@
22072 #include <asm/kexec.h>
22073 #include <asm/processor-flags.h>
22074 #include <asm/pgtable_types.h>
22075+#include <asm/alternative-asm.h>
22076
22077 /*
22078 * Must be relocatable PIC code callable as a C function
22079@@ -160,13 +161,14 @@ identity_mapped:
22080 xorq %rbp, %rbp
22081 xorq %r8, %r8
22082 xorq %r9, %r9
22083- xorq %r10, %r9
22084+ xorq %r10, %r10
22085 xorq %r11, %r11
22086 xorq %r12, %r12
22087 xorq %r13, %r13
22088 xorq %r14, %r14
22089 xorq %r15, %r15
22090
22091+ pax_force_retaddr 0, 1
22092 ret
22093
22094 1:
22095diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22096index 8b24289..d37b58b 100644
22097--- a/arch/x86/kernel/setup.c
22098+++ b/arch/x86/kernel/setup.c
22099@@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
22100
22101 switch (data->type) {
22102 case SETUP_E820_EXT:
22103- parse_e820_ext(data);
22104+ parse_e820_ext((struct setup_data __force_kernel *)data);
22105 break;
22106 case SETUP_DTB:
22107 add_dtb(pa_data);
22108@@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
22109 * area (640->1Mb) as ram even though it is not.
22110 * take them out.
22111 */
22112- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22113+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22114
22115 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22116 }
22117@@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
22118
22119 if (!boot_params.hdr.root_flags)
22120 root_mountflags &= ~MS_RDONLY;
22121- init_mm.start_code = (unsigned long) _text;
22122- init_mm.end_code = (unsigned long) _etext;
22123+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22124+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22125 init_mm.end_data = (unsigned long) _edata;
22126 init_mm.brk = _brk_end;
22127
22128- code_resource.start = virt_to_phys(_text);
22129- code_resource.end = virt_to_phys(_etext)-1;
22130- data_resource.start = virt_to_phys(_etext);
22131+ code_resource.start = virt_to_phys(ktla_ktva(_text));
22132+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
22133+ data_resource.start = virt_to_phys(_sdata);
22134 data_resource.end = virt_to_phys(_edata)-1;
22135 bss_resource.start = virt_to_phys(&__bss_start);
22136 bss_resource.end = virt_to_phys(&__bss_stop)-1;
22137diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22138index 5cdff03..5810740 100644
22139--- a/arch/x86/kernel/setup_percpu.c
22140+++ b/arch/x86/kernel/setup_percpu.c
22141@@ -21,19 +21,17 @@
22142 #include <asm/cpu.h>
22143 #include <asm/stackprotector.h>
22144
22145-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22146+#ifdef CONFIG_SMP
22147+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22148 EXPORT_PER_CPU_SYMBOL(cpu_number);
22149+#endif
22150
22151-#ifdef CONFIG_X86_64
22152 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22153-#else
22154-#define BOOT_PERCPU_OFFSET 0
22155-#endif
22156
22157 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22158 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22159
22160-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22161+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22162 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22163 };
22164 EXPORT_SYMBOL(__per_cpu_offset);
22165@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22166 {
22167 #ifdef CONFIG_X86_32
22168 struct desc_struct gdt;
22169+ unsigned long base = per_cpu_offset(cpu);
22170
22171- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22172- 0x2 | DESCTYPE_S, 0x8);
22173- gdt.s = 1;
22174+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22175+ 0x83 | DESCTYPE_S, 0xC);
22176 write_gdt_entry(get_cpu_gdt_table(cpu),
22177 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22178 #endif
22179@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22180 /* alrighty, percpu areas up and running */
22181 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22182 for_each_possible_cpu(cpu) {
22183+#ifdef CONFIG_CC_STACKPROTECTOR
22184+#ifdef CONFIG_X86_32
22185+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22186+#endif
22187+#endif
22188 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22189 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22190 per_cpu(cpu_number, cpu) = cpu;
22191@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22192 */
22193 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22194 #endif
22195+#ifdef CONFIG_CC_STACKPROTECTOR
22196+#ifdef CONFIG_X86_32
22197+ if (!cpu)
22198+ per_cpu(stack_canary.canary, cpu) = canary;
22199+#endif
22200+#endif
22201 /*
22202 * Up to this point, the boot CPU has been using .init.data
22203 * area. Reload any changed state for the boot CPU.
22204diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22205index d6bf1f3..3ffce5a 100644
22206--- a/arch/x86/kernel/signal.c
22207+++ b/arch/x86/kernel/signal.c
22208@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22209 * Align the stack pointer according to the i386 ABI,
22210 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22211 */
22212- sp = ((sp + 4) & -16ul) - 4;
22213+ sp = ((sp - 12) & -16ul) - 4;
22214 #else /* !CONFIG_X86_32 */
22215 sp = round_down(sp, 16) - 8;
22216 #endif
22217@@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22218 }
22219
22220 if (current->mm->context.vdso)
22221- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22222+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22223 else
22224- restorer = &frame->retcode;
22225+ restorer = (void __user *)&frame->retcode;
22226 if (ka->sa.sa_flags & SA_RESTORER)
22227 restorer = ka->sa.sa_restorer;
22228
22229@@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
22230 * reasons and because gdb uses it as a signature to notice
22231 * signal handler stack frames.
22232 */
22233- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22234+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22235
22236 if (err)
22237 return -EFAULT;
22238@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22239 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22240
22241 /* Set up to return from userspace. */
22242- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22243+ if (current->mm->context.vdso)
22244+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22245+ else
22246+ restorer = (void __user *)&frame->retcode;
22247 if (ka->sa.sa_flags & SA_RESTORER)
22248 restorer = ka->sa.sa_restorer;
22249 put_user_ex(restorer, &frame->pretcode);
22250@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
22251 * reasons and because gdb uses it as a signature to notice
22252 * signal handler stack frames.
22253 */
22254- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22255+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22256 } put_user_catch(err);
22257
22258 err |= copy_siginfo_to_user(&frame->info, info);
22259diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22260index 48d2b7d..90d328a 100644
22261--- a/arch/x86/kernel/smp.c
22262+++ b/arch/x86/kernel/smp.c
22263@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22264
22265 __setup("nonmi_ipi", nonmi_ipi_setup);
22266
22267-struct smp_ops smp_ops = {
22268+struct smp_ops smp_ops __read_only = {
22269 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22270 .smp_prepare_cpus = native_smp_prepare_cpus,
22271 .smp_cpus_done = native_smp_cpus_done,
22272diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22273index ed0fe38..87fc692 100644
22274--- a/arch/x86/kernel/smpboot.c
22275+++ b/arch/x86/kernel/smpboot.c
22276@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22277 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22278 (THREAD_SIZE + task_stack_page(idle))) - 1);
22279 per_cpu(current_task, cpu) = idle;
22280+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22281
22282 #ifdef CONFIG_X86_32
22283 /* Stack for startup_32 can be just as for start_secondary onwards */
22284@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22285 #else
22286 clear_tsk_thread_flag(idle, TIF_FORK);
22287 initial_gs = per_cpu_offset(cpu);
22288- per_cpu(kernel_stack, cpu) =
22289- (unsigned long)task_stack_page(idle) -
22290- KERNEL_STACK_OFFSET + THREAD_SIZE;
22291+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22292 #endif
22293+
22294+ pax_open_kernel();
22295 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22296+ pax_close_kernel();
22297+
22298 initial_code = (unsigned long)start_secondary;
22299 stack_start = idle->thread.sp;
22300
22301@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22302 /* the FPU context is blank, nobody can own it */
22303 __cpu_disable_lazy_restore(cpu);
22304
22305+#ifdef CONFIG_PAX_PER_CPU_PGD
22306+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22307+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22308+ KERNEL_PGD_PTRS);
22309+#endif
22310+
22311+ /* the FPU context is blank, nobody can own it */
22312+ __cpu_disable_lazy_restore(cpu);
22313+
22314 err = do_boot_cpu(apicid, cpu, tidle);
22315 if (err) {
22316 pr_debug("do_boot_cpu failed %d\n", err);
22317diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22318index 9b4d51d..5d28b58 100644
22319--- a/arch/x86/kernel/step.c
22320+++ b/arch/x86/kernel/step.c
22321@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22322 struct desc_struct *desc;
22323 unsigned long base;
22324
22325- seg &= ~7UL;
22326+ seg >>= 3;
22327
22328 mutex_lock(&child->mm->context.lock);
22329- if (unlikely((seg >> 3) >= child->mm->context.size))
22330+ if (unlikely(seg >= child->mm->context.size))
22331 addr = -1L; /* bogus selector, access would fault */
22332 else {
22333 desc = child->mm->context.ldt + seg;
22334@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22335 addr += base;
22336 }
22337 mutex_unlock(&child->mm->context.lock);
22338- }
22339+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22340+ addr = ktla_ktva(addr);
22341
22342 return addr;
22343 }
22344@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22345 unsigned char opcode[15];
22346 unsigned long addr = convert_ip_to_linear(child, regs);
22347
22348+ if (addr == -EINVAL)
22349+ return 0;
22350+
22351 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22352 for (i = 0; i < copied; i++) {
22353 switch (opcode[i]) {
22354diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22355new file mode 100644
22356index 0000000..207bec6
22357--- /dev/null
22358+++ b/arch/x86/kernel/sys_i386_32.c
22359@@ -0,0 +1,250 @@
22360+/*
22361+ * This file contains various random system calls that
22362+ * have a non-standard calling sequence on the Linux/i386
22363+ * platform.
22364+ */
22365+
22366+#include <linux/errno.h>
22367+#include <linux/sched.h>
22368+#include <linux/mm.h>
22369+#include <linux/fs.h>
22370+#include <linux/smp.h>
22371+#include <linux/sem.h>
22372+#include <linux/msg.h>
22373+#include <linux/shm.h>
22374+#include <linux/stat.h>
22375+#include <linux/syscalls.h>
22376+#include <linux/mman.h>
22377+#include <linux/file.h>
22378+#include <linux/utsname.h>
22379+#include <linux/ipc.h>
22380+
22381+#include <linux/uaccess.h>
22382+#include <linux/unistd.h>
22383+
22384+#include <asm/syscalls.h>
22385+
22386+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22387+{
22388+ unsigned long pax_task_size = TASK_SIZE;
22389+
22390+#ifdef CONFIG_PAX_SEGMEXEC
22391+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22392+ pax_task_size = SEGMEXEC_TASK_SIZE;
22393+#endif
22394+
22395+ if (flags & MAP_FIXED)
22396+ if (len > pax_task_size || addr > pax_task_size - len)
22397+ return -EINVAL;
22398+
22399+ return 0;
22400+}
22401+
22402+unsigned long
22403+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22404+ unsigned long len, unsigned long pgoff, unsigned long flags)
22405+{
22406+ struct mm_struct *mm = current->mm;
22407+ struct vm_area_struct *vma;
22408+ unsigned long start_addr, pax_task_size = TASK_SIZE;
22409+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22410+
22411+#ifdef CONFIG_PAX_SEGMEXEC
22412+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22413+ pax_task_size = SEGMEXEC_TASK_SIZE;
22414+#endif
22415+
22416+ pax_task_size -= PAGE_SIZE;
22417+
22418+ if (len > pax_task_size)
22419+ return -ENOMEM;
22420+
22421+ if (flags & MAP_FIXED)
22422+ return addr;
22423+
22424+#ifdef CONFIG_PAX_RANDMMAP
22425+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22426+#endif
22427+
22428+ if (addr) {
22429+ addr = PAGE_ALIGN(addr);
22430+ if (pax_task_size - len >= addr) {
22431+ vma = find_vma(mm, addr);
22432+ if (check_heap_stack_gap(vma, addr, len, offset))
22433+ return addr;
22434+ }
22435+ }
22436+ if (len > mm->cached_hole_size) {
22437+ start_addr = addr = mm->free_area_cache;
22438+ } else {
22439+ start_addr = addr = mm->mmap_base;
22440+ mm->cached_hole_size = 0;
22441+ }
22442+
22443+#ifdef CONFIG_PAX_PAGEEXEC
22444+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22445+ start_addr = 0x00110000UL;
22446+
22447+#ifdef CONFIG_PAX_RANDMMAP
22448+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22449+ start_addr += mm->delta_mmap & 0x03FFF000UL;
22450+#endif
22451+
22452+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22453+ start_addr = addr = mm->mmap_base;
22454+ else
22455+ addr = start_addr;
22456+ }
22457+#endif
22458+
22459+full_search:
22460+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22461+ /* At this point: (!vma || addr < vma->vm_end). */
22462+ if (pax_task_size - len < addr) {
22463+ /*
22464+ * Start a new search - just in case we missed
22465+ * some holes.
22466+ */
22467+ if (start_addr != mm->mmap_base) {
22468+ start_addr = addr = mm->mmap_base;
22469+ mm->cached_hole_size = 0;
22470+ goto full_search;
22471+ }
22472+ return -ENOMEM;
22473+ }
22474+ if (check_heap_stack_gap(vma, addr, len, offset))
22475+ break;
22476+ if (addr + mm->cached_hole_size < vma->vm_start)
22477+ mm->cached_hole_size = vma->vm_start - addr;
22478+ addr = vma->vm_end;
22479+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
22480+ start_addr = addr = mm->mmap_base;
22481+ mm->cached_hole_size = 0;
22482+ goto full_search;
22483+ }
22484+ }
22485+
22486+ /*
22487+ * Remember the place where we stopped the search:
22488+ */
22489+ mm->free_area_cache = addr + len;
22490+ return addr;
22491+}
22492+
22493+unsigned long
22494+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22495+ const unsigned long len, const unsigned long pgoff,
22496+ const unsigned long flags)
22497+{
22498+ struct vm_area_struct *vma;
22499+ struct mm_struct *mm = current->mm;
22500+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22501+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22502+
22503+#ifdef CONFIG_PAX_SEGMEXEC
22504+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22505+ pax_task_size = SEGMEXEC_TASK_SIZE;
22506+#endif
22507+
22508+ pax_task_size -= PAGE_SIZE;
22509+
22510+ /* requested length too big for entire address space */
22511+ if (len > pax_task_size)
22512+ return -ENOMEM;
22513+
22514+ if (flags & MAP_FIXED)
22515+ return addr;
22516+
22517+#ifdef CONFIG_PAX_PAGEEXEC
22518+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22519+ goto bottomup;
22520+#endif
22521+
22522+#ifdef CONFIG_PAX_RANDMMAP
22523+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22524+#endif
22525+
22526+ /* requesting a specific address */
22527+ if (addr) {
22528+ addr = PAGE_ALIGN(addr);
22529+ if (pax_task_size - len >= addr) {
22530+ vma = find_vma(mm, addr);
22531+ if (check_heap_stack_gap(vma, addr, len, offset))
22532+ return addr;
22533+ }
22534+ }
22535+
22536+ /* check if free_area_cache is useful for us */
22537+ if (len <= mm->cached_hole_size) {
22538+ mm->cached_hole_size = 0;
22539+ mm->free_area_cache = mm->mmap_base;
22540+ }
22541+
22542+ /* either no address requested or can't fit in requested address hole */
22543+ addr = mm->free_area_cache;
22544+
22545+ /* make sure it can fit in the remaining address space */
22546+ if (addr > len) {
22547+ vma = find_vma(mm, addr-len);
22548+ if (check_heap_stack_gap(vma, addr - len, len, offset))
22549+ /* remember the address as a hint for next time */
22550+ return (mm->free_area_cache = addr-len);
22551+ }
22552+
22553+ if (mm->mmap_base < len)
22554+ goto bottomup;
22555+
22556+ addr = mm->mmap_base-len;
22557+
22558+ do {
22559+ /*
22560+ * Lookup failure means no vma is above this address,
22561+ * else if new region fits below vma->vm_start,
22562+ * return with success:
22563+ */
22564+ vma = find_vma(mm, addr);
22565+ if (check_heap_stack_gap(vma, addr, len, offset))
22566+ /* remember the address as a hint for next time */
22567+ return (mm->free_area_cache = addr);
22568+
22569+ /* remember the largest hole we saw so far */
22570+ if (addr + mm->cached_hole_size < vma->vm_start)
22571+ mm->cached_hole_size = vma->vm_start - addr;
22572+
22573+ /* try just below the current vma->vm_start */
22574+ addr = skip_heap_stack_gap(vma, len, offset);
22575+ } while (!IS_ERR_VALUE(addr));
22576+
22577+bottomup:
22578+ /*
22579+ * A failed mmap() very likely causes application failure,
22580+ * so fall back to the bottom-up function here. This scenario
22581+ * can happen with large stack limits and large mmap()
22582+ * allocations.
22583+ */
22584+
22585+#ifdef CONFIG_PAX_SEGMEXEC
22586+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22587+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22588+ else
22589+#endif
22590+
22591+ mm->mmap_base = TASK_UNMAPPED_BASE;
22592+
22593+#ifdef CONFIG_PAX_RANDMMAP
22594+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22595+ mm->mmap_base += mm->delta_mmap;
22596+#endif
22597+
22598+ mm->free_area_cache = mm->mmap_base;
22599+ mm->cached_hole_size = ~0UL;
22600+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22601+ /*
22602+ * Restore the topdown base:
22603+ */
22604+ mm->mmap_base = base;
22605+ mm->free_area_cache = base;
22606+ mm->cached_hole_size = ~0UL;
22607+
22608+ return addr;
22609+}
22610diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22611index 97ef74b..57a1882 100644
22612--- a/arch/x86/kernel/sys_x86_64.c
22613+++ b/arch/x86/kernel/sys_x86_64.c
22614@@ -81,8 +81,8 @@ out:
22615 return error;
22616 }
22617
22618-static void find_start_end(unsigned long flags, unsigned long *begin,
22619- unsigned long *end)
22620+static void find_start_end(struct mm_struct *mm, unsigned long flags,
22621+ unsigned long *begin, unsigned long *end)
22622 {
22623 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22624 unsigned long new_begin;
22625@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22626 *begin = new_begin;
22627 }
22628 } else {
22629- *begin = TASK_UNMAPPED_BASE;
22630+ *begin = mm->mmap_base;
22631 *end = TASK_SIZE;
22632 }
22633 }
22634@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22635 struct vm_area_struct *vma;
22636 struct vm_unmapped_area_info info;
22637 unsigned long begin, end;
22638+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22639
22640 if (flags & MAP_FIXED)
22641 return addr;
22642
22643- find_start_end(flags, &begin, &end);
22644+ find_start_end(mm, flags, &begin, &end);
22645
22646 if (len > end)
22647 return -ENOMEM;
22648
22649+#ifdef CONFIG_PAX_RANDMMAP
22650+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22651+#endif
22652+
22653 if (addr) {
22654 addr = PAGE_ALIGN(addr);
22655 vma = find_vma(mm, addr);
22656- if (end - len >= addr &&
22657- (!vma || addr + len <= vma->vm_start))
22658+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22659 return addr;
22660 }
22661
22662@@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22663 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22664 goto bottomup;
22665
22666+#ifdef CONFIG_PAX_RANDMMAP
22667+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22668+#endif
22669+
22670 /* requesting a specific address */
22671 if (addr) {
22672 addr = PAGE_ALIGN(addr);
22673diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22674index f84fe00..f41d9f1 100644
22675--- a/arch/x86/kernel/tboot.c
22676+++ b/arch/x86/kernel/tboot.c
22677@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22678
22679 void tboot_shutdown(u32 shutdown_type)
22680 {
22681- void (*shutdown)(void);
22682+ void (* __noreturn shutdown)(void);
22683
22684 if (!tboot_enabled())
22685 return;
22686@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22687
22688 switch_to_tboot_pt();
22689
22690- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22691+ shutdown = (void *)tboot->shutdown_entry;
22692 shutdown();
22693
22694 /* should not reach here */
22695@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22696 return 0;
22697 }
22698
22699-static atomic_t ap_wfs_count;
22700+static atomic_unchecked_t ap_wfs_count;
22701
22702 static int tboot_wait_for_aps(int num_aps)
22703 {
22704@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22705 {
22706 switch (action) {
22707 case CPU_DYING:
22708- atomic_inc(&ap_wfs_count);
22709+ atomic_inc_unchecked(&ap_wfs_count);
22710 if (num_online_cpus() == 1)
22711- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22712+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22713 return NOTIFY_BAD;
22714 break;
22715 }
22716 return NOTIFY_OK;
22717 }
22718
22719-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22720+static struct notifier_block tboot_cpu_notifier =
22721 {
22722 .notifier_call = tboot_cpu_callback,
22723 };
22724@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22725
22726 tboot_create_trampoline();
22727
22728- atomic_set(&ap_wfs_count, 0);
22729+ atomic_set_unchecked(&ap_wfs_count, 0);
22730 register_hotcpu_notifier(&tboot_cpu_notifier);
22731
22732 acpi_os_set_prepare_sleep(&tboot_sleep);
22733diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22734index 24d3c91..d06b473 100644
22735--- a/arch/x86/kernel/time.c
22736+++ b/arch/x86/kernel/time.c
22737@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22738 {
22739 unsigned long pc = instruction_pointer(regs);
22740
22741- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22742+ if (!user_mode(regs) && in_lock_functions(pc)) {
22743 #ifdef CONFIG_FRAME_POINTER
22744- return *(unsigned long *)(regs->bp + sizeof(long));
22745+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22746 #else
22747 unsigned long *sp =
22748 (unsigned long *)kernel_stack_pointer(regs);
22749@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22750 * or above a saved flags. Eflags has bits 22-31 zero,
22751 * kernel addresses don't.
22752 */
22753+
22754+#ifdef CONFIG_PAX_KERNEXEC
22755+ return ktla_ktva(sp[0]);
22756+#else
22757 if (sp[0] >> 22)
22758 return sp[0];
22759 if (sp[1] >> 22)
22760 return sp[1];
22761 #endif
22762+
22763+#endif
22764 }
22765 return pc;
22766 }
22767diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22768index 9d9d2f9..cad418a 100644
22769--- a/arch/x86/kernel/tls.c
22770+++ b/arch/x86/kernel/tls.c
22771@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22772 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22773 return -EINVAL;
22774
22775+#ifdef CONFIG_PAX_SEGMEXEC
22776+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22777+ return -EINVAL;
22778+#endif
22779+
22780 set_tls_desc(p, idx, &info, 1);
22781
22782 return 0;
22783@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22784
22785 if (kbuf)
22786 info = kbuf;
22787- else if (__copy_from_user(infobuf, ubuf, count))
22788+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22789 return -EFAULT;
22790 else
22791 info = infobuf;
22792diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22793index ecffca1..95c4d13 100644
22794--- a/arch/x86/kernel/traps.c
22795+++ b/arch/x86/kernel/traps.c
22796@@ -68,12 +68,6 @@
22797 #include <asm/setup.h>
22798
22799 asmlinkage int system_call(void);
22800-
22801-/*
22802- * The IDT has to be page-aligned to simplify the Pentium
22803- * F0 0F bug workaround.
22804- */
22805-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22806 #endif
22807
22808 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22809@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22810 }
22811
22812 static int __kprobes
22813-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22814+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22815 struct pt_regs *regs, long error_code)
22816 {
22817 #ifdef CONFIG_X86_32
22818- if (regs->flags & X86_VM_MASK) {
22819+ if (v8086_mode(regs)) {
22820 /*
22821 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22822 * On nmi (interrupt 2), do_trap should not be called.
22823@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22824 return -1;
22825 }
22826 #endif
22827- if (!user_mode(regs)) {
22828+ if (!user_mode_novm(regs)) {
22829 if (!fixup_exception(regs)) {
22830 tsk->thread.error_code = error_code;
22831 tsk->thread.trap_nr = trapnr;
22832+
22833+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22834+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22835+ str = "PAX: suspicious stack segment fault";
22836+#endif
22837+
22838 die(str, regs, error_code);
22839 }
22840+
22841+#ifdef CONFIG_PAX_REFCOUNT
22842+ if (trapnr == 4)
22843+ pax_report_refcount_overflow(regs);
22844+#endif
22845+
22846 return 0;
22847 }
22848
22849@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22850 }
22851
22852 static void __kprobes
22853-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22854+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22855 long error_code, siginfo_t *info)
22856 {
22857 struct task_struct *tsk = current;
22858@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22859 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22860 printk_ratelimit()) {
22861 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22862- tsk->comm, tsk->pid, str,
22863+ tsk->comm, task_pid_nr(tsk), str,
22864 regs->ip, regs->sp, error_code);
22865 print_vma_addr(" in ", regs->ip);
22866 pr_cont("\n");
22867@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22868 conditional_sti(regs);
22869
22870 #ifdef CONFIG_X86_32
22871- if (regs->flags & X86_VM_MASK) {
22872+ if (v8086_mode(regs)) {
22873 local_irq_enable();
22874 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22875 goto exit;
22876@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22877 #endif
22878
22879 tsk = current;
22880- if (!user_mode(regs)) {
22881+ if (!user_mode_novm(regs)) {
22882 if (fixup_exception(regs))
22883 goto exit;
22884
22885 tsk->thread.error_code = error_code;
22886 tsk->thread.trap_nr = X86_TRAP_GP;
22887 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22888- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22889+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22890+
22891+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22892+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22893+ die("PAX: suspicious general protection fault", regs, error_code);
22894+ else
22895+#endif
22896+
22897 die("general protection fault", regs, error_code);
22898+ }
22899 goto exit;
22900 }
22901
22902+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22903+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22904+ struct mm_struct *mm = tsk->mm;
22905+ unsigned long limit;
22906+
22907+ down_write(&mm->mmap_sem);
22908+ limit = mm->context.user_cs_limit;
22909+ if (limit < TASK_SIZE) {
22910+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22911+ up_write(&mm->mmap_sem);
22912+ return;
22913+ }
22914+ up_write(&mm->mmap_sem);
22915+ }
22916+#endif
22917+
22918 tsk->thread.error_code = error_code;
22919 tsk->thread.trap_nr = X86_TRAP_GP;
22920
22921@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22922 /* It's safe to allow irq's after DR6 has been saved */
22923 preempt_conditional_sti(regs);
22924
22925- if (regs->flags & X86_VM_MASK) {
22926+ if (v8086_mode(regs)) {
22927 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22928 X86_TRAP_DB);
22929 preempt_conditional_cli(regs);
22930@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22931 * We already checked v86 mode above, so we can check for kernel mode
22932 * by just checking the CPL of CS.
22933 */
22934- if ((dr6 & DR_STEP) && !user_mode(regs)) {
22935+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22936 tsk->thread.debugreg6 &= ~DR_STEP;
22937 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22938 regs->flags &= ~X86_EFLAGS_TF;
22939@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22940 return;
22941 conditional_sti(regs);
22942
22943- if (!user_mode_vm(regs))
22944+ if (!user_mode(regs))
22945 {
22946 if (!fixup_exception(regs)) {
22947 task->thread.error_code = error_code;
22948diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22949index c71025b..b117501 100644
22950--- a/arch/x86/kernel/uprobes.c
22951+++ b/arch/x86/kernel/uprobes.c
22952@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22953 int ret = NOTIFY_DONE;
22954
22955 /* We are only interested in userspace traps */
22956- if (regs && !user_mode_vm(regs))
22957+ if (regs && !user_mode(regs))
22958 return NOTIFY_DONE;
22959
22960 switch (val) {
22961diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22962index b9242ba..50c5edd 100644
22963--- a/arch/x86/kernel/verify_cpu.S
22964+++ b/arch/x86/kernel/verify_cpu.S
22965@@ -20,6 +20,7 @@
22966 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22967 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22968 * arch/x86/kernel/head_32.S: processor startup
22969+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22970 *
22971 * verify_cpu, returns the status of longmode and SSE in register %eax.
22972 * 0: Success 1: Failure
22973diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22974index 1dfe69c..a3df6f6 100644
22975--- a/arch/x86/kernel/vm86_32.c
22976+++ b/arch/x86/kernel/vm86_32.c
22977@@ -43,6 +43,7 @@
22978 #include <linux/ptrace.h>
22979 #include <linux/audit.h>
22980 #include <linux/stddef.h>
22981+#include <linux/grsecurity.h>
22982
22983 #include <asm/uaccess.h>
22984 #include <asm/io.h>
22985@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22986 do_exit(SIGSEGV);
22987 }
22988
22989- tss = &per_cpu(init_tss, get_cpu());
22990+ tss = init_tss + get_cpu();
22991 current->thread.sp0 = current->thread.saved_sp0;
22992 current->thread.sysenter_cs = __KERNEL_CS;
22993 load_sp0(tss, &current->thread);
22994@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22995 struct task_struct *tsk;
22996 int tmp, ret = -EPERM;
22997
22998+#ifdef CONFIG_GRKERNSEC_VM86
22999+ if (!capable(CAP_SYS_RAWIO)) {
23000+ gr_handle_vm86();
23001+ goto out;
23002+ }
23003+#endif
23004+
23005 tsk = current;
23006 if (tsk->thread.saved_sp0)
23007 goto out;
23008@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
23009 int tmp, ret;
23010 struct vm86plus_struct __user *v86;
23011
23012+#ifdef CONFIG_GRKERNSEC_VM86
23013+ if (!capable(CAP_SYS_RAWIO)) {
23014+ gr_handle_vm86();
23015+ ret = -EPERM;
23016+ goto out;
23017+ }
23018+#endif
23019+
23020 tsk = current;
23021 switch (cmd) {
23022 case VM86_REQUEST_IRQ:
23023@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23024 tsk->thread.saved_fs = info->regs32->fs;
23025 tsk->thread.saved_gs = get_user_gs(info->regs32);
23026
23027- tss = &per_cpu(init_tss, get_cpu());
23028+ tss = init_tss + get_cpu();
23029 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23030 if (cpu_has_sep)
23031 tsk->thread.sysenter_cs = 0;
23032@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23033 goto cannot_handle;
23034 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23035 goto cannot_handle;
23036- intr_ptr = (unsigned long __user *) (i << 2);
23037+ intr_ptr = (__force unsigned long __user *) (i << 2);
23038 if (get_user(segoffs, intr_ptr))
23039 goto cannot_handle;
23040 if ((segoffs >> 16) == BIOSSEG)
23041diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23042index 22a1530..8fbaaad 100644
23043--- a/arch/x86/kernel/vmlinux.lds.S
23044+++ b/arch/x86/kernel/vmlinux.lds.S
23045@@ -26,6 +26,13 @@
23046 #include <asm/page_types.h>
23047 #include <asm/cache.h>
23048 #include <asm/boot.h>
23049+#include <asm/segment.h>
23050+
23051+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23052+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23053+#else
23054+#define __KERNEL_TEXT_OFFSET 0
23055+#endif
23056
23057 #undef i386 /* in case the preprocessor is a 32bit one */
23058
23059@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23060
23061 PHDRS {
23062 text PT_LOAD FLAGS(5); /* R_E */
23063+#ifdef CONFIG_X86_32
23064+ module PT_LOAD FLAGS(5); /* R_E */
23065+#endif
23066+#ifdef CONFIG_XEN
23067+ rodata PT_LOAD FLAGS(5); /* R_E */
23068+#else
23069+ rodata PT_LOAD FLAGS(4); /* R__ */
23070+#endif
23071 data PT_LOAD FLAGS(6); /* RW_ */
23072-#ifdef CONFIG_X86_64
23073+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23074 #ifdef CONFIG_SMP
23075 percpu PT_LOAD FLAGS(6); /* RW_ */
23076 #endif
23077+ text.init PT_LOAD FLAGS(5); /* R_E */
23078+ text.exit PT_LOAD FLAGS(5); /* R_E */
23079 init PT_LOAD FLAGS(7); /* RWE */
23080-#endif
23081 note PT_NOTE FLAGS(0); /* ___ */
23082 }
23083
23084 SECTIONS
23085 {
23086 #ifdef CONFIG_X86_32
23087- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23088- phys_startup_32 = startup_32 - LOAD_OFFSET;
23089+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23090 #else
23091- . = __START_KERNEL;
23092- phys_startup_64 = startup_64 - LOAD_OFFSET;
23093+ . = __START_KERNEL;
23094 #endif
23095
23096 /* Text and read-only data */
23097- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23098- _text = .;
23099+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23100 /* bootstrapping code */
23101+#ifdef CONFIG_X86_32
23102+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23103+#else
23104+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23105+#endif
23106+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23107+ _text = .;
23108 HEAD_TEXT
23109 #ifdef CONFIG_X86_32
23110 . = ALIGN(PAGE_SIZE);
23111@@ -108,13 +128,48 @@ SECTIONS
23112 IRQENTRY_TEXT
23113 *(.fixup)
23114 *(.gnu.warning)
23115- /* End of text section */
23116- _etext = .;
23117 } :text = 0x9090
23118
23119- NOTES :text :note
23120+ . += __KERNEL_TEXT_OFFSET;
23121
23122- EXCEPTION_TABLE(16) :text = 0x9090
23123+#ifdef CONFIG_X86_32
23124+ . = ALIGN(PAGE_SIZE);
23125+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23126+
23127+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
23128+ MODULES_EXEC_VADDR = .;
23129+ BYTE(0)
23130+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23131+ . = ALIGN(HPAGE_SIZE) - 1;
23132+ MODULES_EXEC_END = .;
23133+#endif
23134+
23135+ } :module
23136+#endif
23137+
23138+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23139+ /* End of text section */
23140+ BYTE(0)
23141+ _etext = . - __KERNEL_TEXT_OFFSET;
23142+ }
23143+
23144+#ifdef CONFIG_X86_32
23145+ . = ALIGN(PAGE_SIZE);
23146+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23147+ *(.idt)
23148+ . = ALIGN(PAGE_SIZE);
23149+ *(.empty_zero_page)
23150+ *(.initial_pg_fixmap)
23151+ *(.initial_pg_pmd)
23152+ *(.initial_page_table)
23153+ *(.swapper_pg_dir)
23154+ } :rodata
23155+#endif
23156+
23157+ . = ALIGN(PAGE_SIZE);
23158+ NOTES :rodata :note
23159+
23160+ EXCEPTION_TABLE(16) :rodata
23161
23162 #if defined(CONFIG_DEBUG_RODATA)
23163 /* .text should occupy whole number of pages */
23164@@ -126,16 +181,20 @@ SECTIONS
23165
23166 /* Data */
23167 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23168+
23169+#ifdef CONFIG_PAX_KERNEXEC
23170+ . = ALIGN(HPAGE_SIZE);
23171+#else
23172+ . = ALIGN(PAGE_SIZE);
23173+#endif
23174+
23175 /* Start of data section */
23176 _sdata = .;
23177
23178 /* init_task */
23179 INIT_TASK_DATA(THREAD_SIZE)
23180
23181-#ifdef CONFIG_X86_32
23182- /* 32 bit has nosave before _edata */
23183 NOSAVE_DATA
23184-#endif
23185
23186 PAGE_ALIGNED_DATA(PAGE_SIZE)
23187
23188@@ -176,12 +235,19 @@ SECTIONS
23189 #endif /* CONFIG_X86_64 */
23190
23191 /* Init code and data - will be freed after init */
23192- . = ALIGN(PAGE_SIZE);
23193 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23194+ BYTE(0)
23195+
23196+#ifdef CONFIG_PAX_KERNEXEC
23197+ . = ALIGN(HPAGE_SIZE);
23198+#else
23199+ . = ALIGN(PAGE_SIZE);
23200+#endif
23201+
23202 __init_begin = .; /* paired with __init_end */
23203- }
23204+ } :init.begin
23205
23206-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23207+#ifdef CONFIG_SMP
23208 /*
23209 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23210 * output PHDR, so the next output section - .init.text - should
23211@@ -190,12 +256,27 @@ SECTIONS
23212 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23213 #endif
23214
23215- INIT_TEXT_SECTION(PAGE_SIZE)
23216-#ifdef CONFIG_X86_64
23217- :init
23218-#endif
23219+ . = ALIGN(PAGE_SIZE);
23220+ init_begin = .;
23221+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23222+ VMLINUX_SYMBOL(_sinittext) = .;
23223+ INIT_TEXT
23224+ VMLINUX_SYMBOL(_einittext) = .;
23225+ . = ALIGN(PAGE_SIZE);
23226+ } :text.init
23227
23228- INIT_DATA_SECTION(16)
23229+ /*
23230+ * .exit.text is discard at runtime, not link time, to deal with
23231+ * references from .altinstructions and .eh_frame
23232+ */
23233+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23234+ EXIT_TEXT
23235+ . = ALIGN(16);
23236+ } :text.exit
23237+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23238+
23239+ . = ALIGN(PAGE_SIZE);
23240+ INIT_DATA_SECTION(16) :init
23241
23242 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23243 __x86_cpu_dev_start = .;
23244@@ -257,19 +338,12 @@ SECTIONS
23245 }
23246
23247 . = ALIGN(8);
23248- /*
23249- * .exit.text is discard at runtime, not link time, to deal with
23250- * references from .altinstructions and .eh_frame
23251- */
23252- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23253- EXIT_TEXT
23254- }
23255
23256 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23257 EXIT_DATA
23258 }
23259
23260-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23261+#ifndef CONFIG_SMP
23262 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23263 #endif
23264
23265@@ -288,16 +362,10 @@ SECTIONS
23266 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23267 __smp_locks = .;
23268 *(.smp_locks)
23269- . = ALIGN(PAGE_SIZE);
23270 __smp_locks_end = .;
23271+ . = ALIGN(PAGE_SIZE);
23272 }
23273
23274-#ifdef CONFIG_X86_64
23275- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23276- NOSAVE_DATA
23277- }
23278-#endif
23279-
23280 /* BSS */
23281 . = ALIGN(PAGE_SIZE);
23282 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23283@@ -313,6 +381,7 @@ SECTIONS
23284 __brk_base = .;
23285 . += 64 * 1024; /* 64k alignment slop space */
23286 *(.brk_reservation) /* areas brk users have reserved */
23287+ . = ALIGN(HPAGE_SIZE);
23288 __brk_limit = .;
23289 }
23290
23291@@ -339,13 +408,12 @@ SECTIONS
23292 * for the boot processor.
23293 */
23294 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23295-INIT_PER_CPU(gdt_page);
23296 INIT_PER_CPU(irq_stack_union);
23297
23298 /*
23299 * Build-time check on the image size:
23300 */
23301-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23302+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23303 "kernel image bigger than KERNEL_IMAGE_SIZE");
23304
23305 #ifdef CONFIG_SMP
23306diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23307index 9a907a6..f83f921 100644
23308--- a/arch/x86/kernel/vsyscall_64.c
23309+++ b/arch/x86/kernel/vsyscall_64.c
23310@@ -56,15 +56,13 @@
23311 DEFINE_VVAR(int, vgetcpu_mode);
23312 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23313
23314-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23315+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23316
23317 static int __init vsyscall_setup(char *str)
23318 {
23319 if (str) {
23320 if (!strcmp("emulate", str))
23321 vsyscall_mode = EMULATE;
23322- else if (!strcmp("native", str))
23323- vsyscall_mode = NATIVE;
23324 else if (!strcmp("none", str))
23325 vsyscall_mode = NONE;
23326 else
23327@@ -323,8 +321,7 @@ do_ret:
23328 return true;
23329
23330 sigsegv:
23331- force_sig(SIGSEGV, current);
23332- return true;
23333+ do_group_exit(SIGKILL);
23334 }
23335
23336 /*
23337@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23338 extern char __vvar_page;
23339 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23340
23341- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23342- vsyscall_mode == NATIVE
23343- ? PAGE_KERNEL_VSYSCALL
23344- : PAGE_KERNEL_VVAR);
23345+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23346 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23347 (unsigned long)VSYSCALL_START);
23348
23349diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23350index 1330dd1..d220b99 100644
23351--- a/arch/x86/kernel/x8664_ksyms_64.c
23352+++ b/arch/x86/kernel/x8664_ksyms_64.c
23353@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23354 EXPORT_SYMBOL(copy_user_generic_unrolled);
23355 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23356 EXPORT_SYMBOL(__copy_user_nocache);
23357-EXPORT_SYMBOL(_copy_from_user);
23358-EXPORT_SYMBOL(_copy_to_user);
23359
23360 EXPORT_SYMBOL(copy_page);
23361 EXPORT_SYMBOL(clear_page);
23362diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23363index 7a3d075..6cb373d 100644
23364--- a/arch/x86/kernel/x86_init.c
23365+++ b/arch/x86/kernel/x86_init.c
23366@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23367 },
23368 };
23369
23370-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23371+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23372 .early_percpu_clock_init = x86_init_noop,
23373 .setup_percpu_clockev = setup_secondary_APIC_clock,
23374 };
23375@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23376 static void default_nmi_init(void) { };
23377 static int default_i8042_detect(void) { return 1; };
23378
23379-struct x86_platform_ops x86_platform = {
23380+struct x86_platform_ops x86_platform __read_only = {
23381 .calibrate_tsc = native_calibrate_tsc,
23382 .get_wallclock = mach_get_cmos_time,
23383 .set_wallclock = mach_set_rtc_mmss,
23384@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23385 };
23386
23387 EXPORT_SYMBOL_GPL(x86_platform);
23388-struct x86_msi_ops x86_msi = {
23389+struct x86_msi_ops x86_msi __read_only = {
23390 .setup_msi_irqs = native_setup_msi_irqs,
23391 .teardown_msi_irq = native_teardown_msi_irq,
23392 .teardown_msi_irqs = default_teardown_msi_irqs,
23393 .restore_msi_irqs = default_restore_msi_irqs,
23394 };
23395
23396-struct x86_io_apic_ops x86_io_apic_ops = {
23397+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23398 .init = native_io_apic_init_mappings,
23399 .read = native_io_apic_read,
23400 .write = native_io_apic_write,
23401diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23402index ada87a3..afea76d 100644
23403--- a/arch/x86/kernel/xsave.c
23404+++ b/arch/x86/kernel/xsave.c
23405@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23406 {
23407 int err;
23408
23409+ buf = (struct xsave_struct __user *)____m(buf);
23410 if (use_xsave())
23411 err = xsave_user(buf);
23412 else if (use_fxsr())
23413@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23414 */
23415 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23416 {
23417+ buf = (void __user *)____m(buf);
23418 if (use_xsave()) {
23419 if ((unsigned long)buf % 64 || fx_only) {
23420 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23421diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23422index a20ecb5..d0e2194 100644
23423--- a/arch/x86/kvm/cpuid.c
23424+++ b/arch/x86/kvm/cpuid.c
23425@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23426 struct kvm_cpuid2 *cpuid,
23427 struct kvm_cpuid_entry2 __user *entries)
23428 {
23429- int r;
23430+ int r, i;
23431
23432 r = -E2BIG;
23433 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23434 goto out;
23435 r = -EFAULT;
23436- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23437- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23438+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23439 goto out;
23440+ for (i = 0; i < cpuid->nent; ++i) {
23441+ struct kvm_cpuid_entry2 cpuid_entry;
23442+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23443+ goto out;
23444+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23445+ }
23446 vcpu->arch.cpuid_nent = cpuid->nent;
23447 kvm_apic_set_version(vcpu);
23448 kvm_x86_ops->cpuid_update(vcpu);
23449@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23450 struct kvm_cpuid2 *cpuid,
23451 struct kvm_cpuid_entry2 __user *entries)
23452 {
23453- int r;
23454+ int r, i;
23455
23456 r = -E2BIG;
23457 if (cpuid->nent < vcpu->arch.cpuid_nent)
23458 goto out;
23459 r = -EFAULT;
23460- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23461- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23462+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23463 goto out;
23464+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23465+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23466+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23467+ goto out;
23468+ }
23469 return 0;
23470
23471 out:
23472diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23473index a27e763..54bfe43 100644
23474--- a/arch/x86/kvm/emulate.c
23475+++ b/arch/x86/kvm/emulate.c
23476@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23477
23478 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23479 do { \
23480+ unsigned long _tmp; \
23481 __asm__ __volatile__ ( \
23482 _PRE_EFLAGS("0", "4", "2") \
23483 _op _suffix " %"_x"3,%1; " \
23484@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23485 /* Raw emulation: instruction has two explicit operands. */
23486 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23487 do { \
23488- unsigned long _tmp; \
23489- \
23490 switch ((ctxt)->dst.bytes) { \
23491 case 2: \
23492 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23493@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23494
23495 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23496 do { \
23497- unsigned long _tmp; \
23498 switch ((ctxt)->dst.bytes) { \
23499 case 1: \
23500 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23501diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23502index 9392f52..0e56d77 100644
23503--- a/arch/x86/kvm/lapic.c
23504+++ b/arch/x86/kvm/lapic.c
23505@@ -55,7 +55,7 @@
23506 #define APIC_BUS_CYCLE_NS 1
23507
23508 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23509-#define apic_debug(fmt, arg...)
23510+#define apic_debug(fmt, arg...) do {} while (0)
23511
23512 #define APIC_LVT_NUM 6
23513 /* 14 is the version for Xeon and Pentium 8.4.8*/
23514diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23515index 891eb6d..e027900 100644
23516--- a/arch/x86/kvm/paging_tmpl.h
23517+++ b/arch/x86/kvm/paging_tmpl.h
23518@@ -208,7 +208,7 @@ retry_walk:
23519 if (unlikely(kvm_is_error_hva(host_addr)))
23520 goto error;
23521
23522- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23523+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23524 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23525 goto error;
23526 walker->ptep_user[walker->level - 1] = ptep_user;
23527diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23528index d29d3cd..ec9d522 100644
23529--- a/arch/x86/kvm/svm.c
23530+++ b/arch/x86/kvm/svm.c
23531@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23532 int cpu = raw_smp_processor_id();
23533
23534 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23535+
23536+ pax_open_kernel();
23537 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23538+ pax_close_kernel();
23539+
23540 load_TR_desc();
23541 }
23542
23543@@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23544 #endif
23545 #endif
23546
23547+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23548+ __set_fs(current_thread_info()->addr_limit);
23549+#endif
23550+
23551 reload_tss(vcpu);
23552
23553 local_irq_disable();
23554diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23555index 9120ae1..238abc0 100644
23556--- a/arch/x86/kvm/vmx.c
23557+++ b/arch/x86/kvm/vmx.c
23558@@ -1370,7 +1370,11 @@ static void reload_tss(void)
23559 struct desc_struct *descs;
23560
23561 descs = (void *)gdt->address;
23562+
23563+ pax_open_kernel();
23564 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23565+ pax_close_kernel();
23566+
23567 load_TR_desc();
23568 }
23569
23570@@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23571 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23572 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23573
23574+#ifdef CONFIG_PAX_PER_CPU_PGD
23575+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23576+#endif
23577+
23578 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23579 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23580 vmx->loaded_vmcs->cpu = cpu;
23581@@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23582 if (!cpu_has_vmx_flexpriority())
23583 flexpriority_enabled = 0;
23584
23585- if (!cpu_has_vmx_tpr_shadow())
23586- kvm_x86_ops->update_cr8_intercept = NULL;
23587+ if (!cpu_has_vmx_tpr_shadow()) {
23588+ pax_open_kernel();
23589+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23590+ pax_close_kernel();
23591+ }
23592
23593 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23594 kvm_disable_largepages();
23595@@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23596
23597 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23598 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23599+
23600+#ifndef CONFIG_PAX_PER_CPU_PGD
23601 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23602+#endif
23603
23604 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23605 #ifdef CONFIG_X86_64
23606@@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23607 native_store_idt(&dt);
23608 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23609
23610- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23611+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23612
23613 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23614 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23615@@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23616 "jmp 2f \n\t"
23617 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23618 "2: "
23619+
23620+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23621+ "ljmp %[cs],$3f\n\t"
23622+ "3: "
23623+#endif
23624+
23625 /* Save guest registers, load host registers, keep flags */
23626 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23627 "pop %0 \n\t"
23628@@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23629 #endif
23630 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23631 [wordsize]"i"(sizeof(ulong))
23632+
23633+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23634+ ,[cs]"i"(__KERNEL_CS)
23635+#endif
23636+
23637 : "cc", "memory"
23638 #ifdef CONFIG_X86_64
23639 , "rax", "rbx", "rdi", "rsi"
23640@@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23641 if (debugctlmsr)
23642 update_debugctlmsr(debugctlmsr);
23643
23644-#ifndef CONFIG_X86_64
23645+#ifdef CONFIG_X86_32
23646 /*
23647 * The sysexit path does not restore ds/es, so we must set them to
23648 * a reasonable value ourselves.
23649@@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23650 * may be executed in interrupt context, which saves and restore segments
23651 * around it, nullifying its effect.
23652 */
23653- loadsegment(ds, __USER_DS);
23654- loadsegment(es, __USER_DS);
23655+ loadsegment(ds, __KERNEL_DS);
23656+ loadsegment(es, __KERNEL_DS);
23657+ loadsegment(ss, __KERNEL_DS);
23658+
23659+#ifdef CONFIG_PAX_KERNEXEC
23660+ loadsegment(fs, __KERNEL_PERCPU);
23661+#endif
23662+
23663+#ifdef CONFIG_PAX_MEMORY_UDEREF
23664+ __set_fs(current_thread_info()->addr_limit);
23665+#endif
23666+
23667 #endif
23668
23669 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23670diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23671index c243b81..9eb193f 100644
23672--- a/arch/x86/kvm/x86.c
23673+++ b/arch/x86/kvm/x86.c
23674@@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23675 {
23676 struct kvm *kvm = vcpu->kvm;
23677 int lm = is_long_mode(vcpu);
23678- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23679- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23680+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23681+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23682 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23683 : kvm->arch.xen_hvm_config.blob_size_32;
23684 u32 page_num = data & ~PAGE_MASK;
23685@@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23686 if (n < msr_list.nmsrs)
23687 goto out;
23688 r = -EFAULT;
23689+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23690+ goto out;
23691 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23692 num_msrs_to_save * sizeof(u32)))
23693 goto out;
23694@@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23695 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23696 struct kvm_interrupt *irq)
23697 {
23698- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23699+ if (irq->irq >= KVM_NR_INTERRUPTS)
23700 return -EINVAL;
23701 if (irqchip_in_kernel(vcpu->kvm))
23702 return -ENXIO;
23703@@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23704 };
23705 #endif
23706
23707-int kvm_arch_init(void *opaque)
23708+int kvm_arch_init(const void *opaque)
23709 {
23710 int r;
23711 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23712diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23713index df4176c..23ce092 100644
23714--- a/arch/x86/lguest/boot.c
23715+++ b/arch/x86/lguest/boot.c
23716@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23717 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23718 * Launcher to reboot us.
23719 */
23720-static void lguest_restart(char *reason)
23721+static __noreturn void lguest_restart(char *reason)
23722 {
23723 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23724+ BUG();
23725 }
23726
23727 /*G:050
23728diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23729index 00933d5..3a64af9 100644
23730--- a/arch/x86/lib/atomic64_386_32.S
23731+++ b/arch/x86/lib/atomic64_386_32.S
23732@@ -48,6 +48,10 @@ BEGIN(read)
23733 movl (v), %eax
23734 movl 4(v), %edx
23735 RET_ENDP
23736+BEGIN(read_unchecked)
23737+ movl (v), %eax
23738+ movl 4(v), %edx
23739+RET_ENDP
23740 #undef v
23741
23742 #define v %esi
23743@@ -55,6 +59,10 @@ BEGIN(set)
23744 movl %ebx, (v)
23745 movl %ecx, 4(v)
23746 RET_ENDP
23747+BEGIN(set_unchecked)
23748+ movl %ebx, (v)
23749+ movl %ecx, 4(v)
23750+RET_ENDP
23751 #undef v
23752
23753 #define v %esi
23754@@ -70,6 +78,20 @@ RET_ENDP
23755 BEGIN(add)
23756 addl %eax, (v)
23757 adcl %edx, 4(v)
23758+
23759+#ifdef CONFIG_PAX_REFCOUNT
23760+ jno 0f
23761+ subl %eax, (v)
23762+ sbbl %edx, 4(v)
23763+ int $4
23764+0:
23765+ _ASM_EXTABLE(0b, 0b)
23766+#endif
23767+
23768+RET_ENDP
23769+BEGIN(add_unchecked)
23770+ addl %eax, (v)
23771+ adcl %edx, 4(v)
23772 RET_ENDP
23773 #undef v
23774
23775@@ -77,6 +99,24 @@ RET_ENDP
23776 BEGIN(add_return)
23777 addl (v), %eax
23778 adcl 4(v), %edx
23779+
23780+#ifdef CONFIG_PAX_REFCOUNT
23781+ into
23782+1234:
23783+ _ASM_EXTABLE(1234b, 2f)
23784+#endif
23785+
23786+ movl %eax, (v)
23787+ movl %edx, 4(v)
23788+
23789+#ifdef CONFIG_PAX_REFCOUNT
23790+2:
23791+#endif
23792+
23793+RET_ENDP
23794+BEGIN(add_return_unchecked)
23795+ addl (v), %eax
23796+ adcl 4(v), %edx
23797 movl %eax, (v)
23798 movl %edx, 4(v)
23799 RET_ENDP
23800@@ -86,6 +126,20 @@ RET_ENDP
23801 BEGIN(sub)
23802 subl %eax, (v)
23803 sbbl %edx, 4(v)
23804+
23805+#ifdef CONFIG_PAX_REFCOUNT
23806+ jno 0f
23807+ addl %eax, (v)
23808+ adcl %edx, 4(v)
23809+ int $4
23810+0:
23811+ _ASM_EXTABLE(0b, 0b)
23812+#endif
23813+
23814+RET_ENDP
23815+BEGIN(sub_unchecked)
23816+ subl %eax, (v)
23817+ sbbl %edx, 4(v)
23818 RET_ENDP
23819 #undef v
23820
23821@@ -96,6 +150,27 @@ BEGIN(sub_return)
23822 sbbl $0, %edx
23823 addl (v), %eax
23824 adcl 4(v), %edx
23825+
23826+#ifdef CONFIG_PAX_REFCOUNT
23827+ into
23828+1234:
23829+ _ASM_EXTABLE(1234b, 2f)
23830+#endif
23831+
23832+ movl %eax, (v)
23833+ movl %edx, 4(v)
23834+
23835+#ifdef CONFIG_PAX_REFCOUNT
23836+2:
23837+#endif
23838+
23839+RET_ENDP
23840+BEGIN(sub_return_unchecked)
23841+ negl %edx
23842+ negl %eax
23843+ sbbl $0, %edx
23844+ addl (v), %eax
23845+ adcl 4(v), %edx
23846 movl %eax, (v)
23847 movl %edx, 4(v)
23848 RET_ENDP
23849@@ -105,6 +180,20 @@ RET_ENDP
23850 BEGIN(inc)
23851 addl $1, (v)
23852 adcl $0, 4(v)
23853+
23854+#ifdef CONFIG_PAX_REFCOUNT
23855+ jno 0f
23856+ subl $1, (v)
23857+ sbbl $0, 4(v)
23858+ int $4
23859+0:
23860+ _ASM_EXTABLE(0b, 0b)
23861+#endif
23862+
23863+RET_ENDP
23864+BEGIN(inc_unchecked)
23865+ addl $1, (v)
23866+ adcl $0, 4(v)
23867 RET_ENDP
23868 #undef v
23869
23870@@ -114,6 +203,26 @@ BEGIN(inc_return)
23871 movl 4(v), %edx
23872 addl $1, %eax
23873 adcl $0, %edx
23874+
23875+#ifdef CONFIG_PAX_REFCOUNT
23876+ into
23877+1234:
23878+ _ASM_EXTABLE(1234b, 2f)
23879+#endif
23880+
23881+ movl %eax, (v)
23882+ movl %edx, 4(v)
23883+
23884+#ifdef CONFIG_PAX_REFCOUNT
23885+2:
23886+#endif
23887+
23888+RET_ENDP
23889+BEGIN(inc_return_unchecked)
23890+ movl (v), %eax
23891+ movl 4(v), %edx
23892+ addl $1, %eax
23893+ adcl $0, %edx
23894 movl %eax, (v)
23895 movl %edx, 4(v)
23896 RET_ENDP
23897@@ -123,6 +232,20 @@ RET_ENDP
23898 BEGIN(dec)
23899 subl $1, (v)
23900 sbbl $0, 4(v)
23901+
23902+#ifdef CONFIG_PAX_REFCOUNT
23903+ jno 0f
23904+ addl $1, (v)
23905+ adcl $0, 4(v)
23906+ int $4
23907+0:
23908+ _ASM_EXTABLE(0b, 0b)
23909+#endif
23910+
23911+RET_ENDP
23912+BEGIN(dec_unchecked)
23913+ subl $1, (v)
23914+ sbbl $0, 4(v)
23915 RET_ENDP
23916 #undef v
23917
23918@@ -132,6 +255,26 @@ BEGIN(dec_return)
23919 movl 4(v), %edx
23920 subl $1, %eax
23921 sbbl $0, %edx
23922+
23923+#ifdef CONFIG_PAX_REFCOUNT
23924+ into
23925+1234:
23926+ _ASM_EXTABLE(1234b, 2f)
23927+#endif
23928+
23929+ movl %eax, (v)
23930+ movl %edx, 4(v)
23931+
23932+#ifdef CONFIG_PAX_REFCOUNT
23933+2:
23934+#endif
23935+
23936+RET_ENDP
23937+BEGIN(dec_return_unchecked)
23938+ movl (v), %eax
23939+ movl 4(v), %edx
23940+ subl $1, %eax
23941+ sbbl $0, %edx
23942 movl %eax, (v)
23943 movl %edx, 4(v)
23944 RET_ENDP
23945@@ -143,6 +286,13 @@ BEGIN(add_unless)
23946 adcl %edx, %edi
23947 addl (v), %eax
23948 adcl 4(v), %edx
23949+
23950+#ifdef CONFIG_PAX_REFCOUNT
23951+ into
23952+1234:
23953+ _ASM_EXTABLE(1234b, 2f)
23954+#endif
23955+
23956 cmpl %eax, %ecx
23957 je 3f
23958 1:
23959@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23960 1:
23961 addl $1, %eax
23962 adcl $0, %edx
23963+
23964+#ifdef CONFIG_PAX_REFCOUNT
23965+ into
23966+1234:
23967+ _ASM_EXTABLE(1234b, 2f)
23968+#endif
23969+
23970 movl %eax, (v)
23971 movl %edx, 4(v)
23972 movl $1, %eax
23973@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23974 movl 4(v), %edx
23975 subl $1, %eax
23976 sbbl $0, %edx
23977+
23978+#ifdef CONFIG_PAX_REFCOUNT
23979+ into
23980+1234:
23981+ _ASM_EXTABLE(1234b, 1f)
23982+#endif
23983+
23984 js 1f
23985 movl %eax, (v)
23986 movl %edx, 4(v)
23987diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23988index f5cc9eb..51fa319 100644
23989--- a/arch/x86/lib/atomic64_cx8_32.S
23990+++ b/arch/x86/lib/atomic64_cx8_32.S
23991@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23992 CFI_STARTPROC
23993
23994 read64 %ecx
23995+ pax_force_retaddr
23996 ret
23997 CFI_ENDPROC
23998 ENDPROC(atomic64_read_cx8)
23999
24000+ENTRY(atomic64_read_unchecked_cx8)
24001+ CFI_STARTPROC
24002+
24003+ read64 %ecx
24004+ pax_force_retaddr
24005+ ret
24006+ CFI_ENDPROC
24007+ENDPROC(atomic64_read_unchecked_cx8)
24008+
24009 ENTRY(atomic64_set_cx8)
24010 CFI_STARTPROC
24011
24012@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24013 cmpxchg8b (%esi)
24014 jne 1b
24015
24016+ pax_force_retaddr
24017 ret
24018 CFI_ENDPROC
24019 ENDPROC(atomic64_set_cx8)
24020
24021+ENTRY(atomic64_set_unchecked_cx8)
24022+ CFI_STARTPROC
24023+
24024+1:
24025+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24026+ * are atomic on 586 and newer */
24027+ cmpxchg8b (%esi)
24028+ jne 1b
24029+
24030+ pax_force_retaddr
24031+ ret
24032+ CFI_ENDPROC
24033+ENDPROC(atomic64_set_unchecked_cx8)
24034+
24035 ENTRY(atomic64_xchg_cx8)
24036 CFI_STARTPROC
24037
24038@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24039 cmpxchg8b (%esi)
24040 jne 1b
24041
24042+ pax_force_retaddr
24043 ret
24044 CFI_ENDPROC
24045 ENDPROC(atomic64_xchg_cx8)
24046
24047-.macro addsub_return func ins insc
24048-ENTRY(atomic64_\func\()_return_cx8)
24049+.macro addsub_return func ins insc unchecked=""
24050+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24051 CFI_STARTPROC
24052 SAVE ebp
24053 SAVE ebx
24054@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24055 movl %edx, %ecx
24056 \ins\()l %esi, %ebx
24057 \insc\()l %edi, %ecx
24058+
24059+.ifb \unchecked
24060+#ifdef CONFIG_PAX_REFCOUNT
24061+ into
24062+2:
24063+ _ASM_EXTABLE(2b, 3f)
24064+#endif
24065+.endif
24066+
24067 LOCK_PREFIX
24068 cmpxchg8b (%ebp)
24069 jne 1b
24070-
24071-10:
24072 movl %ebx, %eax
24073 movl %ecx, %edx
24074+
24075+.ifb \unchecked
24076+#ifdef CONFIG_PAX_REFCOUNT
24077+3:
24078+#endif
24079+.endif
24080+
24081 RESTORE edi
24082 RESTORE esi
24083 RESTORE ebx
24084 RESTORE ebp
24085+ pax_force_retaddr
24086 ret
24087 CFI_ENDPROC
24088-ENDPROC(atomic64_\func\()_return_cx8)
24089+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24090 .endm
24091
24092 addsub_return add add adc
24093 addsub_return sub sub sbb
24094+addsub_return add add adc _unchecked
24095+addsub_return sub sub sbb _unchecked
24096
24097-.macro incdec_return func ins insc
24098-ENTRY(atomic64_\func\()_return_cx8)
24099+.macro incdec_return func ins insc unchecked=""
24100+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24101 CFI_STARTPROC
24102 SAVE ebx
24103
24104@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24105 movl %edx, %ecx
24106 \ins\()l $1, %ebx
24107 \insc\()l $0, %ecx
24108+
24109+.ifb \unchecked
24110+#ifdef CONFIG_PAX_REFCOUNT
24111+ into
24112+2:
24113+ _ASM_EXTABLE(2b, 3f)
24114+#endif
24115+.endif
24116+
24117 LOCK_PREFIX
24118 cmpxchg8b (%esi)
24119 jne 1b
24120
24121-10:
24122 movl %ebx, %eax
24123 movl %ecx, %edx
24124+
24125+.ifb \unchecked
24126+#ifdef CONFIG_PAX_REFCOUNT
24127+3:
24128+#endif
24129+.endif
24130+
24131 RESTORE ebx
24132+ pax_force_retaddr
24133 ret
24134 CFI_ENDPROC
24135-ENDPROC(atomic64_\func\()_return_cx8)
24136+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24137 .endm
24138
24139 incdec_return inc add adc
24140 incdec_return dec sub sbb
24141+incdec_return inc add adc _unchecked
24142+incdec_return dec sub sbb _unchecked
24143
24144 ENTRY(atomic64_dec_if_positive_cx8)
24145 CFI_STARTPROC
24146@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24147 movl %edx, %ecx
24148 subl $1, %ebx
24149 sbb $0, %ecx
24150+
24151+#ifdef CONFIG_PAX_REFCOUNT
24152+ into
24153+1234:
24154+ _ASM_EXTABLE(1234b, 2f)
24155+#endif
24156+
24157 js 2f
24158 LOCK_PREFIX
24159 cmpxchg8b (%esi)
24160@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24161 movl %ebx, %eax
24162 movl %ecx, %edx
24163 RESTORE ebx
24164+ pax_force_retaddr
24165 ret
24166 CFI_ENDPROC
24167 ENDPROC(atomic64_dec_if_positive_cx8)
24168@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24169 movl %edx, %ecx
24170 addl %ebp, %ebx
24171 adcl %edi, %ecx
24172+
24173+#ifdef CONFIG_PAX_REFCOUNT
24174+ into
24175+1234:
24176+ _ASM_EXTABLE(1234b, 3f)
24177+#endif
24178+
24179 LOCK_PREFIX
24180 cmpxchg8b (%esi)
24181 jne 1b
24182@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24183 CFI_ADJUST_CFA_OFFSET -8
24184 RESTORE ebx
24185 RESTORE ebp
24186+ pax_force_retaddr
24187 ret
24188 4:
24189 cmpl %edx, 4(%esp)
24190@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24191 xorl %ecx, %ecx
24192 addl $1, %ebx
24193 adcl %edx, %ecx
24194+
24195+#ifdef CONFIG_PAX_REFCOUNT
24196+ into
24197+1234:
24198+ _ASM_EXTABLE(1234b, 3f)
24199+#endif
24200+
24201 LOCK_PREFIX
24202 cmpxchg8b (%esi)
24203 jne 1b
24204@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24205 movl $1, %eax
24206 3:
24207 RESTORE ebx
24208+ pax_force_retaddr
24209 ret
24210 CFI_ENDPROC
24211 ENDPROC(atomic64_inc_not_zero_cx8)
24212diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24213index 2af5df3..62b1a5a 100644
24214--- a/arch/x86/lib/checksum_32.S
24215+++ b/arch/x86/lib/checksum_32.S
24216@@ -29,7 +29,8 @@
24217 #include <asm/dwarf2.h>
24218 #include <asm/errno.h>
24219 #include <asm/asm.h>
24220-
24221+#include <asm/segment.h>
24222+
24223 /*
24224 * computes a partial checksum, e.g. for TCP/UDP fragments
24225 */
24226@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24227
24228 #define ARGBASE 16
24229 #define FP 12
24230-
24231-ENTRY(csum_partial_copy_generic)
24232+
24233+ENTRY(csum_partial_copy_generic_to_user)
24234 CFI_STARTPROC
24235+
24236+#ifdef CONFIG_PAX_MEMORY_UDEREF
24237+ pushl_cfi %gs
24238+ popl_cfi %es
24239+ jmp csum_partial_copy_generic
24240+#endif
24241+
24242+ENTRY(csum_partial_copy_generic_from_user)
24243+
24244+#ifdef CONFIG_PAX_MEMORY_UDEREF
24245+ pushl_cfi %gs
24246+ popl_cfi %ds
24247+#endif
24248+
24249+ENTRY(csum_partial_copy_generic)
24250 subl $4,%esp
24251 CFI_ADJUST_CFA_OFFSET 4
24252 pushl_cfi %edi
24253@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24254 jmp 4f
24255 SRC(1: movw (%esi), %bx )
24256 addl $2, %esi
24257-DST( movw %bx, (%edi) )
24258+DST( movw %bx, %es:(%edi) )
24259 addl $2, %edi
24260 addw %bx, %ax
24261 adcl $0, %eax
24262@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24263 SRC(1: movl (%esi), %ebx )
24264 SRC( movl 4(%esi), %edx )
24265 adcl %ebx, %eax
24266-DST( movl %ebx, (%edi) )
24267+DST( movl %ebx, %es:(%edi) )
24268 adcl %edx, %eax
24269-DST( movl %edx, 4(%edi) )
24270+DST( movl %edx, %es:4(%edi) )
24271
24272 SRC( movl 8(%esi), %ebx )
24273 SRC( movl 12(%esi), %edx )
24274 adcl %ebx, %eax
24275-DST( movl %ebx, 8(%edi) )
24276+DST( movl %ebx, %es:8(%edi) )
24277 adcl %edx, %eax
24278-DST( movl %edx, 12(%edi) )
24279+DST( movl %edx, %es:12(%edi) )
24280
24281 SRC( movl 16(%esi), %ebx )
24282 SRC( movl 20(%esi), %edx )
24283 adcl %ebx, %eax
24284-DST( movl %ebx, 16(%edi) )
24285+DST( movl %ebx, %es:16(%edi) )
24286 adcl %edx, %eax
24287-DST( movl %edx, 20(%edi) )
24288+DST( movl %edx, %es:20(%edi) )
24289
24290 SRC( movl 24(%esi), %ebx )
24291 SRC( movl 28(%esi), %edx )
24292 adcl %ebx, %eax
24293-DST( movl %ebx, 24(%edi) )
24294+DST( movl %ebx, %es:24(%edi) )
24295 adcl %edx, %eax
24296-DST( movl %edx, 28(%edi) )
24297+DST( movl %edx, %es:28(%edi) )
24298
24299 lea 32(%esi), %esi
24300 lea 32(%edi), %edi
24301@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24302 shrl $2, %edx # This clears CF
24303 SRC(3: movl (%esi), %ebx )
24304 adcl %ebx, %eax
24305-DST( movl %ebx, (%edi) )
24306+DST( movl %ebx, %es:(%edi) )
24307 lea 4(%esi), %esi
24308 lea 4(%edi), %edi
24309 dec %edx
24310@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24311 jb 5f
24312 SRC( movw (%esi), %cx )
24313 leal 2(%esi), %esi
24314-DST( movw %cx, (%edi) )
24315+DST( movw %cx, %es:(%edi) )
24316 leal 2(%edi), %edi
24317 je 6f
24318 shll $16,%ecx
24319 SRC(5: movb (%esi), %cl )
24320-DST( movb %cl, (%edi) )
24321+DST( movb %cl, %es:(%edi) )
24322 6: addl %ecx, %eax
24323 adcl $0, %eax
24324 7:
24325@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24326
24327 6001:
24328 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24329- movl $-EFAULT, (%ebx)
24330+ movl $-EFAULT, %ss:(%ebx)
24331
24332 # zero the complete destination - computing the rest
24333 # is too much work
24334@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24335
24336 6002:
24337 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24338- movl $-EFAULT,(%ebx)
24339+ movl $-EFAULT,%ss:(%ebx)
24340 jmp 5000b
24341
24342 .previous
24343
24344+ pushl_cfi %ss
24345+ popl_cfi %ds
24346+ pushl_cfi %ss
24347+ popl_cfi %es
24348 popl_cfi %ebx
24349 CFI_RESTORE ebx
24350 popl_cfi %esi
24351@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24352 popl_cfi %ecx # equivalent to addl $4,%esp
24353 ret
24354 CFI_ENDPROC
24355-ENDPROC(csum_partial_copy_generic)
24356+ENDPROC(csum_partial_copy_generic_to_user)
24357
24358 #else
24359
24360 /* Version for PentiumII/PPro */
24361
24362 #define ROUND1(x) \
24363+ nop; nop; nop; \
24364 SRC(movl x(%esi), %ebx ) ; \
24365 addl %ebx, %eax ; \
24366- DST(movl %ebx, x(%edi) ) ;
24367+ DST(movl %ebx, %es:x(%edi)) ;
24368
24369 #define ROUND(x) \
24370+ nop; nop; nop; \
24371 SRC(movl x(%esi), %ebx ) ; \
24372 adcl %ebx, %eax ; \
24373- DST(movl %ebx, x(%edi) ) ;
24374+ DST(movl %ebx, %es:x(%edi)) ;
24375
24376 #define ARGBASE 12
24377-
24378-ENTRY(csum_partial_copy_generic)
24379+
24380+ENTRY(csum_partial_copy_generic_to_user)
24381 CFI_STARTPROC
24382+
24383+#ifdef CONFIG_PAX_MEMORY_UDEREF
24384+ pushl_cfi %gs
24385+ popl_cfi %es
24386+ jmp csum_partial_copy_generic
24387+#endif
24388+
24389+ENTRY(csum_partial_copy_generic_from_user)
24390+
24391+#ifdef CONFIG_PAX_MEMORY_UDEREF
24392+ pushl_cfi %gs
24393+ popl_cfi %ds
24394+#endif
24395+
24396+ENTRY(csum_partial_copy_generic)
24397 pushl_cfi %ebx
24398 CFI_REL_OFFSET ebx, 0
24399 pushl_cfi %edi
24400@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24401 subl %ebx, %edi
24402 lea -1(%esi),%edx
24403 andl $-32,%edx
24404- lea 3f(%ebx,%ebx), %ebx
24405+ lea 3f(%ebx,%ebx,2), %ebx
24406 testl %esi, %esi
24407 jmp *%ebx
24408 1: addl $64,%esi
24409@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24410 jb 5f
24411 SRC( movw (%esi), %dx )
24412 leal 2(%esi), %esi
24413-DST( movw %dx, (%edi) )
24414+DST( movw %dx, %es:(%edi) )
24415 leal 2(%edi), %edi
24416 je 6f
24417 shll $16,%edx
24418 5:
24419 SRC( movb (%esi), %dl )
24420-DST( movb %dl, (%edi) )
24421+DST( movb %dl, %es:(%edi) )
24422 6: addl %edx, %eax
24423 adcl $0, %eax
24424 7:
24425 .section .fixup, "ax"
24426 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24427- movl $-EFAULT, (%ebx)
24428+ movl $-EFAULT, %ss:(%ebx)
24429 # zero the complete destination (computing the rest is too much work)
24430 movl ARGBASE+8(%esp),%edi # dst
24431 movl ARGBASE+12(%esp),%ecx # len
24432@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24433 rep; stosb
24434 jmp 7b
24435 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24436- movl $-EFAULT, (%ebx)
24437+ movl $-EFAULT, %ss:(%ebx)
24438 jmp 7b
24439 .previous
24440
24441+#ifdef CONFIG_PAX_MEMORY_UDEREF
24442+ pushl_cfi %ss
24443+ popl_cfi %ds
24444+ pushl_cfi %ss
24445+ popl_cfi %es
24446+#endif
24447+
24448 popl_cfi %esi
24449 CFI_RESTORE esi
24450 popl_cfi %edi
24451@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24452 CFI_RESTORE ebx
24453 ret
24454 CFI_ENDPROC
24455-ENDPROC(csum_partial_copy_generic)
24456+ENDPROC(csum_partial_copy_generic_to_user)
24457
24458 #undef ROUND
24459 #undef ROUND1
24460diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24461index f2145cf..cea889d 100644
24462--- a/arch/x86/lib/clear_page_64.S
24463+++ b/arch/x86/lib/clear_page_64.S
24464@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24465 movl $4096/8,%ecx
24466 xorl %eax,%eax
24467 rep stosq
24468+ pax_force_retaddr
24469 ret
24470 CFI_ENDPROC
24471 ENDPROC(clear_page_c)
24472@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24473 movl $4096,%ecx
24474 xorl %eax,%eax
24475 rep stosb
24476+ pax_force_retaddr
24477 ret
24478 CFI_ENDPROC
24479 ENDPROC(clear_page_c_e)
24480@@ -43,6 +45,7 @@ ENTRY(clear_page)
24481 leaq 64(%rdi),%rdi
24482 jnz .Lloop
24483 nop
24484+ pax_force_retaddr
24485 ret
24486 CFI_ENDPROC
24487 .Lclear_page_end:
24488@@ -58,7 +61,7 @@ ENDPROC(clear_page)
24489
24490 #include <asm/cpufeature.h>
24491
24492- .section .altinstr_replacement,"ax"
24493+ .section .altinstr_replacement,"a"
24494 1: .byte 0xeb /* jmp <disp8> */
24495 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24496 2: .byte 0xeb /* jmp <disp8> */
24497diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24498index 1e572c5..2a162cd 100644
24499--- a/arch/x86/lib/cmpxchg16b_emu.S
24500+++ b/arch/x86/lib/cmpxchg16b_emu.S
24501@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24502
24503 popf
24504 mov $1, %al
24505+ pax_force_retaddr
24506 ret
24507
24508 not_same:
24509 popf
24510 xor %al,%al
24511+ pax_force_retaddr
24512 ret
24513
24514 CFI_ENDPROC
24515diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24516index 176cca6..1166c50 100644
24517--- a/arch/x86/lib/copy_page_64.S
24518+++ b/arch/x86/lib/copy_page_64.S
24519@@ -9,6 +9,7 @@ copy_page_rep:
24520 CFI_STARTPROC
24521 movl $4096/8, %ecx
24522 rep movsq
24523+ pax_force_retaddr
24524 ret
24525 CFI_ENDPROC
24526 ENDPROC(copy_page_rep)
24527@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24528
24529 ENTRY(copy_page)
24530 CFI_STARTPROC
24531- subq $2*8, %rsp
24532- CFI_ADJUST_CFA_OFFSET 2*8
24533+ subq $3*8, %rsp
24534+ CFI_ADJUST_CFA_OFFSET 3*8
24535 movq %rbx, (%rsp)
24536 CFI_REL_OFFSET rbx, 0
24537 movq %r12, 1*8(%rsp)
24538 CFI_REL_OFFSET r12, 1*8
24539+ movq %r13, 2*8(%rsp)
24540+ CFI_REL_OFFSET r13, 2*8
24541
24542 movl $(4096/64)-5, %ecx
24543 .p2align 4
24544@@ -36,7 +39,7 @@ ENTRY(copy_page)
24545 movq 0x8*2(%rsi), %rdx
24546 movq 0x8*3(%rsi), %r8
24547 movq 0x8*4(%rsi), %r9
24548- movq 0x8*5(%rsi), %r10
24549+ movq 0x8*5(%rsi), %r13
24550 movq 0x8*6(%rsi), %r11
24551 movq 0x8*7(%rsi), %r12
24552
24553@@ -47,7 +50,7 @@ ENTRY(copy_page)
24554 movq %rdx, 0x8*2(%rdi)
24555 movq %r8, 0x8*3(%rdi)
24556 movq %r9, 0x8*4(%rdi)
24557- movq %r10, 0x8*5(%rdi)
24558+ movq %r13, 0x8*5(%rdi)
24559 movq %r11, 0x8*6(%rdi)
24560 movq %r12, 0x8*7(%rdi)
24561
24562@@ -66,7 +69,7 @@ ENTRY(copy_page)
24563 movq 0x8*2(%rsi), %rdx
24564 movq 0x8*3(%rsi), %r8
24565 movq 0x8*4(%rsi), %r9
24566- movq 0x8*5(%rsi), %r10
24567+ movq 0x8*5(%rsi), %r13
24568 movq 0x8*6(%rsi), %r11
24569 movq 0x8*7(%rsi), %r12
24570
24571@@ -75,7 +78,7 @@ ENTRY(copy_page)
24572 movq %rdx, 0x8*2(%rdi)
24573 movq %r8, 0x8*3(%rdi)
24574 movq %r9, 0x8*4(%rdi)
24575- movq %r10, 0x8*5(%rdi)
24576+ movq %r13, 0x8*5(%rdi)
24577 movq %r11, 0x8*6(%rdi)
24578 movq %r12, 0x8*7(%rdi)
24579
24580@@ -87,8 +90,11 @@ ENTRY(copy_page)
24581 CFI_RESTORE rbx
24582 movq 1*8(%rsp), %r12
24583 CFI_RESTORE r12
24584- addq $2*8, %rsp
24585- CFI_ADJUST_CFA_OFFSET -2*8
24586+ movq 2*8(%rsp), %r13
24587+ CFI_RESTORE r13
24588+ addq $3*8, %rsp
24589+ CFI_ADJUST_CFA_OFFSET -3*8
24590+ pax_force_retaddr
24591 ret
24592 .Lcopy_page_end:
24593 CFI_ENDPROC
24594@@ -99,7 +105,7 @@ ENDPROC(copy_page)
24595
24596 #include <asm/cpufeature.h>
24597
24598- .section .altinstr_replacement,"ax"
24599+ .section .altinstr_replacement,"a"
24600 1: .byte 0xeb /* jmp <disp8> */
24601 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24602 2:
24603diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24604index a30ca15..d25fab6 100644
24605--- a/arch/x86/lib/copy_user_64.S
24606+++ b/arch/x86/lib/copy_user_64.S
24607@@ -18,6 +18,7 @@
24608 #include <asm/alternative-asm.h>
24609 #include <asm/asm.h>
24610 #include <asm/smap.h>
24611+#include <asm/pgtable.h>
24612
24613 /*
24614 * By placing feature2 after feature1 in altinstructions section, we logically
24615@@ -31,7 +32,7 @@
24616 .byte 0xe9 /* 32bit jump */
24617 .long \orig-1f /* by default jump to orig */
24618 1:
24619- .section .altinstr_replacement,"ax"
24620+ .section .altinstr_replacement,"a"
24621 2: .byte 0xe9 /* near jump with 32bit immediate */
24622 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24623 3: .byte 0xe9 /* near jump with 32bit immediate */
24624@@ -70,47 +71,20 @@
24625 #endif
24626 .endm
24627
24628-/* Standard copy_to_user with segment limit checking */
24629-ENTRY(_copy_to_user)
24630- CFI_STARTPROC
24631- GET_THREAD_INFO(%rax)
24632- movq %rdi,%rcx
24633- addq %rdx,%rcx
24634- jc bad_to_user
24635- cmpq TI_addr_limit(%rax),%rcx
24636- ja bad_to_user
24637- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24638- copy_user_generic_unrolled,copy_user_generic_string, \
24639- copy_user_enhanced_fast_string
24640- CFI_ENDPROC
24641-ENDPROC(_copy_to_user)
24642-
24643-/* Standard copy_from_user with segment limit checking */
24644-ENTRY(_copy_from_user)
24645- CFI_STARTPROC
24646- GET_THREAD_INFO(%rax)
24647- movq %rsi,%rcx
24648- addq %rdx,%rcx
24649- jc bad_from_user
24650- cmpq TI_addr_limit(%rax),%rcx
24651- ja bad_from_user
24652- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24653- copy_user_generic_unrolled,copy_user_generic_string, \
24654- copy_user_enhanced_fast_string
24655- CFI_ENDPROC
24656-ENDPROC(_copy_from_user)
24657-
24658 .section .fixup,"ax"
24659 /* must zero dest */
24660 ENTRY(bad_from_user)
24661 bad_from_user:
24662 CFI_STARTPROC
24663+ testl %edx,%edx
24664+ js bad_to_user
24665 movl %edx,%ecx
24666 xorl %eax,%eax
24667 rep
24668 stosb
24669 bad_to_user:
24670 movl %edx,%eax
24671+ pax_force_retaddr
24672 ret
24673 CFI_ENDPROC
24674 ENDPROC(bad_from_user)
24675@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24676 jz 17f
24677 1: movq (%rsi),%r8
24678 2: movq 1*8(%rsi),%r9
24679-3: movq 2*8(%rsi),%r10
24680+3: movq 2*8(%rsi),%rax
24681 4: movq 3*8(%rsi),%r11
24682 5: movq %r8,(%rdi)
24683 6: movq %r9,1*8(%rdi)
24684-7: movq %r10,2*8(%rdi)
24685+7: movq %rax,2*8(%rdi)
24686 8: movq %r11,3*8(%rdi)
24687 9: movq 4*8(%rsi),%r8
24688 10: movq 5*8(%rsi),%r9
24689-11: movq 6*8(%rsi),%r10
24690+11: movq 6*8(%rsi),%rax
24691 12: movq 7*8(%rsi),%r11
24692 13: movq %r8,4*8(%rdi)
24693 14: movq %r9,5*8(%rdi)
24694-15: movq %r10,6*8(%rdi)
24695+15: movq %rax,6*8(%rdi)
24696 16: movq %r11,7*8(%rdi)
24697 leaq 64(%rsi),%rsi
24698 leaq 64(%rdi),%rdi
24699@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24700 jnz 21b
24701 23: xor %eax,%eax
24702 ASM_CLAC
24703+ pax_force_retaddr
24704 ret
24705
24706 .section .fixup,"ax"
24707@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24708 movsb
24709 4: xorl %eax,%eax
24710 ASM_CLAC
24711+ pax_force_retaddr
24712 ret
24713
24714 .section .fixup,"ax"
24715@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24716 movsb
24717 2: xorl %eax,%eax
24718 ASM_CLAC
24719+ pax_force_retaddr
24720 ret
24721
24722 .section .fixup,"ax"
24723diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24724index 6a4f43c..f5f9e26 100644
24725--- a/arch/x86/lib/copy_user_nocache_64.S
24726+++ b/arch/x86/lib/copy_user_nocache_64.S
24727@@ -8,6 +8,7 @@
24728
24729 #include <linux/linkage.h>
24730 #include <asm/dwarf2.h>
24731+#include <asm/alternative-asm.h>
24732
24733 #define FIX_ALIGNMENT 1
24734
24735@@ -16,6 +17,7 @@
24736 #include <asm/thread_info.h>
24737 #include <asm/asm.h>
24738 #include <asm/smap.h>
24739+#include <asm/pgtable.h>
24740
24741 .macro ALIGN_DESTINATION
24742 #ifdef FIX_ALIGNMENT
24743@@ -49,6 +51,15 @@
24744 */
24745 ENTRY(__copy_user_nocache)
24746 CFI_STARTPROC
24747+
24748+#ifdef CONFIG_PAX_MEMORY_UDEREF
24749+ mov $PAX_USER_SHADOW_BASE,%rcx
24750+ cmp %rcx,%rsi
24751+ jae 1f
24752+ add %rcx,%rsi
24753+1:
24754+#endif
24755+
24756 ASM_STAC
24757 cmpl $8,%edx
24758 jb 20f /* less then 8 bytes, go to byte copy loop */
24759@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24760 jz 17f
24761 1: movq (%rsi),%r8
24762 2: movq 1*8(%rsi),%r9
24763-3: movq 2*8(%rsi),%r10
24764+3: movq 2*8(%rsi),%rax
24765 4: movq 3*8(%rsi),%r11
24766 5: movnti %r8,(%rdi)
24767 6: movnti %r9,1*8(%rdi)
24768-7: movnti %r10,2*8(%rdi)
24769+7: movnti %rax,2*8(%rdi)
24770 8: movnti %r11,3*8(%rdi)
24771 9: movq 4*8(%rsi),%r8
24772 10: movq 5*8(%rsi),%r9
24773-11: movq 6*8(%rsi),%r10
24774+11: movq 6*8(%rsi),%rax
24775 12: movq 7*8(%rsi),%r11
24776 13: movnti %r8,4*8(%rdi)
24777 14: movnti %r9,5*8(%rdi)
24778-15: movnti %r10,6*8(%rdi)
24779+15: movnti %rax,6*8(%rdi)
24780 16: movnti %r11,7*8(%rdi)
24781 leaq 64(%rsi),%rsi
24782 leaq 64(%rdi),%rdi
24783@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24784 23: xorl %eax,%eax
24785 ASM_CLAC
24786 sfence
24787+ pax_force_retaddr
24788 ret
24789
24790 .section .fixup,"ax"
24791diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24792index 2419d5f..953ee51 100644
24793--- a/arch/x86/lib/csum-copy_64.S
24794+++ b/arch/x86/lib/csum-copy_64.S
24795@@ -9,6 +9,7 @@
24796 #include <asm/dwarf2.h>
24797 #include <asm/errno.h>
24798 #include <asm/asm.h>
24799+#include <asm/alternative-asm.h>
24800
24801 /*
24802 * Checksum copy with exception handling.
24803@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24804 CFI_RESTORE rbp
24805 addq $7*8, %rsp
24806 CFI_ADJUST_CFA_OFFSET -7*8
24807+ pax_force_retaddr 0, 1
24808 ret
24809 CFI_RESTORE_STATE
24810
24811diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24812index 25b7ae8..169fafc 100644
24813--- a/arch/x86/lib/csum-wrappers_64.c
24814+++ b/arch/x86/lib/csum-wrappers_64.c
24815@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24816 len -= 2;
24817 }
24818 }
24819- isum = csum_partial_copy_generic((__force const void *)src,
24820+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24821 dst, len, isum, errp, NULL);
24822 if (unlikely(*errp))
24823 goto out_err;
24824@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24825 }
24826
24827 *errp = 0;
24828- return csum_partial_copy_generic(src, (void __force *)dst,
24829+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24830 len, isum, NULL, errp);
24831 }
24832 EXPORT_SYMBOL(csum_partial_copy_to_user);
24833diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24834index 156b9c8..b144132 100644
24835--- a/arch/x86/lib/getuser.S
24836+++ b/arch/x86/lib/getuser.S
24837@@ -34,17 +34,40 @@
24838 #include <asm/thread_info.h>
24839 #include <asm/asm.h>
24840 #include <asm/smap.h>
24841+#include <asm/segment.h>
24842+#include <asm/pgtable.h>
24843+#include <asm/alternative-asm.h>
24844+
24845+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24846+#define __copyuser_seg gs;
24847+#else
24848+#define __copyuser_seg
24849+#endif
24850
24851 .text
24852 ENTRY(__get_user_1)
24853 CFI_STARTPROC
24854+
24855+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24856 GET_THREAD_INFO(%_ASM_DX)
24857 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24858 jae bad_get_user
24859 ASM_STAC
24860-1: movzb (%_ASM_AX),%edx
24861+
24862+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24863+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24864+ cmp %_ASM_DX,%_ASM_AX
24865+ jae 1234f
24866+ add %_ASM_DX,%_ASM_AX
24867+1234:
24868+#endif
24869+
24870+#endif
24871+
24872+1: __copyuser_seg movzb (%_ASM_AX),%edx
24873 xor %eax,%eax
24874 ASM_CLAC
24875+ pax_force_retaddr
24876 ret
24877 CFI_ENDPROC
24878 ENDPROC(__get_user_1)
24879@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24880 ENTRY(__get_user_2)
24881 CFI_STARTPROC
24882 add $1,%_ASM_AX
24883+
24884+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24885 jc bad_get_user
24886 GET_THREAD_INFO(%_ASM_DX)
24887 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24888 jae bad_get_user
24889 ASM_STAC
24890-2: movzwl -1(%_ASM_AX),%edx
24891+
24892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24893+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24894+ cmp %_ASM_DX,%_ASM_AX
24895+ jae 1234f
24896+ add %_ASM_DX,%_ASM_AX
24897+1234:
24898+#endif
24899+
24900+#endif
24901+
24902+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24903 xor %eax,%eax
24904 ASM_CLAC
24905+ pax_force_retaddr
24906 ret
24907 CFI_ENDPROC
24908 ENDPROC(__get_user_2)
24909@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24910 ENTRY(__get_user_4)
24911 CFI_STARTPROC
24912 add $3,%_ASM_AX
24913+
24914+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24915 jc bad_get_user
24916 GET_THREAD_INFO(%_ASM_DX)
24917 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24918 jae bad_get_user
24919 ASM_STAC
24920-3: mov -3(%_ASM_AX),%edx
24921+
24922+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24923+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24924+ cmp %_ASM_DX,%_ASM_AX
24925+ jae 1234f
24926+ add %_ASM_DX,%_ASM_AX
24927+1234:
24928+#endif
24929+
24930+#endif
24931+
24932+3: __copyuser_seg mov -3(%_ASM_AX),%edx
24933 xor %eax,%eax
24934 ASM_CLAC
24935+ pax_force_retaddr
24936 ret
24937 CFI_ENDPROC
24938 ENDPROC(__get_user_4)
24939@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24940 GET_THREAD_INFO(%_ASM_DX)
24941 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24942 jae bad_get_user
24943+
24944+#ifdef CONFIG_PAX_MEMORY_UDEREF
24945+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24946+ cmp %_ASM_DX,%_ASM_AX
24947+ jae 1234f
24948+ add %_ASM_DX,%_ASM_AX
24949+1234:
24950+#endif
24951+
24952 ASM_STAC
24953 4: movq -7(%_ASM_AX),%_ASM_DX
24954 xor %eax,%eax
24955 ASM_CLAC
24956+ pax_force_retaddr
24957 ret
24958 CFI_ENDPROC
24959 ENDPROC(__get_user_8)
24960@@ -101,6 +162,7 @@ bad_get_user:
24961 xor %edx,%edx
24962 mov $(-EFAULT),%_ASM_AX
24963 ASM_CLAC
24964+ pax_force_retaddr
24965 ret
24966 CFI_ENDPROC
24967 END(bad_get_user)
24968diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24969index 54fcffe..7be149e 100644
24970--- a/arch/x86/lib/insn.c
24971+++ b/arch/x86/lib/insn.c
24972@@ -20,8 +20,10 @@
24973
24974 #ifdef __KERNEL__
24975 #include <linux/string.h>
24976+#include <asm/pgtable_types.h>
24977 #else
24978 #include <string.h>
24979+#define ktla_ktva(addr) addr
24980 #endif
24981 #include <asm/inat.h>
24982 #include <asm/insn.h>
24983@@ -53,8 +55,8 @@
24984 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24985 {
24986 memset(insn, 0, sizeof(*insn));
24987- insn->kaddr = kaddr;
24988- insn->next_byte = kaddr;
24989+ insn->kaddr = ktla_ktva(kaddr);
24990+ insn->next_byte = ktla_ktva(kaddr);
24991 insn->x86_64 = x86_64 ? 1 : 0;
24992 insn->opnd_bytes = 4;
24993 if (x86_64)
24994diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24995index 05a95e7..326f2fa 100644
24996--- a/arch/x86/lib/iomap_copy_64.S
24997+++ b/arch/x86/lib/iomap_copy_64.S
24998@@ -17,6 +17,7 @@
24999
25000 #include <linux/linkage.h>
25001 #include <asm/dwarf2.h>
25002+#include <asm/alternative-asm.h>
25003
25004 /*
25005 * override generic version in lib/iomap_copy.c
25006@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25007 CFI_STARTPROC
25008 movl %edx,%ecx
25009 rep movsd
25010+ pax_force_retaddr
25011 ret
25012 CFI_ENDPROC
25013 ENDPROC(__iowrite32_copy)
25014diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25015index 1c273be..da9cc0e 100644
25016--- a/arch/x86/lib/memcpy_64.S
25017+++ b/arch/x86/lib/memcpy_64.S
25018@@ -33,6 +33,7 @@
25019 rep movsq
25020 movl %edx, %ecx
25021 rep movsb
25022+ pax_force_retaddr
25023 ret
25024 .Lmemcpy_e:
25025 .previous
25026@@ -49,6 +50,7 @@
25027 movq %rdi, %rax
25028 movq %rdx, %rcx
25029 rep movsb
25030+ pax_force_retaddr
25031 ret
25032 .Lmemcpy_e_e:
25033 .previous
25034@@ -76,13 +78,13 @@ ENTRY(memcpy)
25035 */
25036 movq 0*8(%rsi), %r8
25037 movq 1*8(%rsi), %r9
25038- movq 2*8(%rsi), %r10
25039+ movq 2*8(%rsi), %rcx
25040 movq 3*8(%rsi), %r11
25041 leaq 4*8(%rsi), %rsi
25042
25043 movq %r8, 0*8(%rdi)
25044 movq %r9, 1*8(%rdi)
25045- movq %r10, 2*8(%rdi)
25046+ movq %rcx, 2*8(%rdi)
25047 movq %r11, 3*8(%rdi)
25048 leaq 4*8(%rdi), %rdi
25049 jae .Lcopy_forward_loop
25050@@ -105,12 +107,12 @@ ENTRY(memcpy)
25051 subq $0x20, %rdx
25052 movq -1*8(%rsi), %r8
25053 movq -2*8(%rsi), %r9
25054- movq -3*8(%rsi), %r10
25055+ movq -3*8(%rsi), %rcx
25056 movq -4*8(%rsi), %r11
25057 leaq -4*8(%rsi), %rsi
25058 movq %r8, -1*8(%rdi)
25059 movq %r9, -2*8(%rdi)
25060- movq %r10, -3*8(%rdi)
25061+ movq %rcx, -3*8(%rdi)
25062 movq %r11, -4*8(%rdi)
25063 leaq -4*8(%rdi), %rdi
25064 jae .Lcopy_backward_loop
25065@@ -130,12 +132,13 @@ ENTRY(memcpy)
25066 */
25067 movq 0*8(%rsi), %r8
25068 movq 1*8(%rsi), %r9
25069- movq -2*8(%rsi, %rdx), %r10
25070+ movq -2*8(%rsi, %rdx), %rcx
25071 movq -1*8(%rsi, %rdx), %r11
25072 movq %r8, 0*8(%rdi)
25073 movq %r9, 1*8(%rdi)
25074- movq %r10, -2*8(%rdi, %rdx)
25075+ movq %rcx, -2*8(%rdi, %rdx)
25076 movq %r11, -1*8(%rdi, %rdx)
25077+ pax_force_retaddr
25078 retq
25079 .p2align 4
25080 .Lless_16bytes:
25081@@ -148,6 +151,7 @@ ENTRY(memcpy)
25082 movq -1*8(%rsi, %rdx), %r9
25083 movq %r8, 0*8(%rdi)
25084 movq %r9, -1*8(%rdi, %rdx)
25085+ pax_force_retaddr
25086 retq
25087 .p2align 4
25088 .Lless_8bytes:
25089@@ -161,6 +165,7 @@ ENTRY(memcpy)
25090 movl -4(%rsi, %rdx), %r8d
25091 movl %ecx, (%rdi)
25092 movl %r8d, -4(%rdi, %rdx)
25093+ pax_force_retaddr
25094 retq
25095 .p2align 4
25096 .Lless_3bytes:
25097@@ -179,6 +184,7 @@ ENTRY(memcpy)
25098 movb %cl, (%rdi)
25099
25100 .Lend:
25101+ pax_force_retaddr
25102 retq
25103 CFI_ENDPROC
25104 ENDPROC(memcpy)
25105diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25106index ee16461..c39c199 100644
25107--- a/arch/x86/lib/memmove_64.S
25108+++ b/arch/x86/lib/memmove_64.S
25109@@ -61,13 +61,13 @@ ENTRY(memmove)
25110 5:
25111 sub $0x20, %rdx
25112 movq 0*8(%rsi), %r11
25113- movq 1*8(%rsi), %r10
25114+ movq 1*8(%rsi), %rcx
25115 movq 2*8(%rsi), %r9
25116 movq 3*8(%rsi), %r8
25117 leaq 4*8(%rsi), %rsi
25118
25119 movq %r11, 0*8(%rdi)
25120- movq %r10, 1*8(%rdi)
25121+ movq %rcx, 1*8(%rdi)
25122 movq %r9, 2*8(%rdi)
25123 movq %r8, 3*8(%rdi)
25124 leaq 4*8(%rdi), %rdi
25125@@ -81,10 +81,10 @@ ENTRY(memmove)
25126 4:
25127 movq %rdx, %rcx
25128 movq -8(%rsi, %rdx), %r11
25129- lea -8(%rdi, %rdx), %r10
25130+ lea -8(%rdi, %rdx), %r9
25131 shrq $3, %rcx
25132 rep movsq
25133- movq %r11, (%r10)
25134+ movq %r11, (%r9)
25135 jmp 13f
25136 .Lmemmove_end_forward:
25137
25138@@ -95,14 +95,14 @@ ENTRY(memmove)
25139 7:
25140 movq %rdx, %rcx
25141 movq (%rsi), %r11
25142- movq %rdi, %r10
25143+ movq %rdi, %r9
25144 leaq -8(%rsi, %rdx), %rsi
25145 leaq -8(%rdi, %rdx), %rdi
25146 shrq $3, %rcx
25147 std
25148 rep movsq
25149 cld
25150- movq %r11, (%r10)
25151+ movq %r11, (%r9)
25152 jmp 13f
25153
25154 /*
25155@@ -127,13 +127,13 @@ ENTRY(memmove)
25156 8:
25157 subq $0x20, %rdx
25158 movq -1*8(%rsi), %r11
25159- movq -2*8(%rsi), %r10
25160+ movq -2*8(%rsi), %rcx
25161 movq -3*8(%rsi), %r9
25162 movq -4*8(%rsi), %r8
25163 leaq -4*8(%rsi), %rsi
25164
25165 movq %r11, -1*8(%rdi)
25166- movq %r10, -2*8(%rdi)
25167+ movq %rcx, -2*8(%rdi)
25168 movq %r9, -3*8(%rdi)
25169 movq %r8, -4*8(%rdi)
25170 leaq -4*8(%rdi), %rdi
25171@@ -151,11 +151,11 @@ ENTRY(memmove)
25172 * Move data from 16 bytes to 31 bytes.
25173 */
25174 movq 0*8(%rsi), %r11
25175- movq 1*8(%rsi), %r10
25176+ movq 1*8(%rsi), %rcx
25177 movq -2*8(%rsi, %rdx), %r9
25178 movq -1*8(%rsi, %rdx), %r8
25179 movq %r11, 0*8(%rdi)
25180- movq %r10, 1*8(%rdi)
25181+ movq %rcx, 1*8(%rdi)
25182 movq %r9, -2*8(%rdi, %rdx)
25183 movq %r8, -1*8(%rdi, %rdx)
25184 jmp 13f
25185@@ -167,9 +167,9 @@ ENTRY(memmove)
25186 * Move data from 8 bytes to 15 bytes.
25187 */
25188 movq 0*8(%rsi), %r11
25189- movq -1*8(%rsi, %rdx), %r10
25190+ movq -1*8(%rsi, %rdx), %r9
25191 movq %r11, 0*8(%rdi)
25192- movq %r10, -1*8(%rdi, %rdx)
25193+ movq %r9, -1*8(%rdi, %rdx)
25194 jmp 13f
25195 10:
25196 cmpq $4, %rdx
25197@@ -178,9 +178,9 @@ ENTRY(memmove)
25198 * Move data from 4 bytes to 7 bytes.
25199 */
25200 movl (%rsi), %r11d
25201- movl -4(%rsi, %rdx), %r10d
25202+ movl -4(%rsi, %rdx), %r9d
25203 movl %r11d, (%rdi)
25204- movl %r10d, -4(%rdi, %rdx)
25205+ movl %r9d, -4(%rdi, %rdx)
25206 jmp 13f
25207 11:
25208 cmp $2, %rdx
25209@@ -189,9 +189,9 @@ ENTRY(memmove)
25210 * Move data from 2 bytes to 3 bytes.
25211 */
25212 movw (%rsi), %r11w
25213- movw -2(%rsi, %rdx), %r10w
25214+ movw -2(%rsi, %rdx), %r9w
25215 movw %r11w, (%rdi)
25216- movw %r10w, -2(%rdi, %rdx)
25217+ movw %r9w, -2(%rdi, %rdx)
25218 jmp 13f
25219 12:
25220 cmp $1, %rdx
25221@@ -202,6 +202,7 @@ ENTRY(memmove)
25222 movb (%rsi), %r11b
25223 movb %r11b, (%rdi)
25224 13:
25225+ pax_force_retaddr
25226 retq
25227 CFI_ENDPROC
25228
25229@@ -210,6 +211,7 @@ ENTRY(memmove)
25230 /* Forward moving data. */
25231 movq %rdx, %rcx
25232 rep movsb
25233+ pax_force_retaddr
25234 retq
25235 .Lmemmove_end_forward_efs:
25236 .previous
25237diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25238index 2dcb380..963660a 100644
25239--- a/arch/x86/lib/memset_64.S
25240+++ b/arch/x86/lib/memset_64.S
25241@@ -30,6 +30,7 @@
25242 movl %edx,%ecx
25243 rep stosb
25244 movq %r9,%rax
25245+ pax_force_retaddr
25246 ret
25247 .Lmemset_e:
25248 .previous
25249@@ -52,6 +53,7 @@
25250 movq %rdx,%rcx
25251 rep stosb
25252 movq %r9,%rax
25253+ pax_force_retaddr
25254 ret
25255 .Lmemset_e_e:
25256 .previous
25257@@ -59,7 +61,7 @@
25258 ENTRY(memset)
25259 ENTRY(__memset)
25260 CFI_STARTPROC
25261- movq %rdi,%r10
25262+ movq %rdi,%r11
25263
25264 /* expand byte value */
25265 movzbl %sil,%ecx
25266@@ -117,7 +119,8 @@ ENTRY(__memset)
25267 jnz .Lloop_1
25268
25269 .Lende:
25270- movq %r10,%rax
25271+ movq %r11,%rax
25272+ pax_force_retaddr
25273 ret
25274
25275 CFI_RESTORE_STATE
25276diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25277index c9f2d9b..e7fd2c0 100644
25278--- a/arch/x86/lib/mmx_32.c
25279+++ b/arch/x86/lib/mmx_32.c
25280@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25281 {
25282 void *p;
25283 int i;
25284+ unsigned long cr0;
25285
25286 if (unlikely(in_interrupt()))
25287 return __memcpy(to, from, len);
25288@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25289 kernel_fpu_begin();
25290
25291 __asm__ __volatile__ (
25292- "1: prefetch (%0)\n" /* This set is 28 bytes */
25293- " prefetch 64(%0)\n"
25294- " prefetch 128(%0)\n"
25295- " prefetch 192(%0)\n"
25296- " prefetch 256(%0)\n"
25297+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25298+ " prefetch 64(%1)\n"
25299+ " prefetch 128(%1)\n"
25300+ " prefetch 192(%1)\n"
25301+ " prefetch 256(%1)\n"
25302 "2: \n"
25303 ".section .fixup, \"ax\"\n"
25304- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25305+ "3: \n"
25306+
25307+#ifdef CONFIG_PAX_KERNEXEC
25308+ " movl %%cr0, %0\n"
25309+ " movl %0, %%eax\n"
25310+ " andl $0xFFFEFFFF, %%eax\n"
25311+ " movl %%eax, %%cr0\n"
25312+#endif
25313+
25314+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25315+
25316+#ifdef CONFIG_PAX_KERNEXEC
25317+ " movl %0, %%cr0\n"
25318+#endif
25319+
25320 " jmp 2b\n"
25321 ".previous\n"
25322 _ASM_EXTABLE(1b, 3b)
25323- : : "r" (from));
25324+ : "=&r" (cr0) : "r" (from) : "ax");
25325
25326 for ( ; i > 5; i--) {
25327 __asm__ __volatile__ (
25328- "1: prefetch 320(%0)\n"
25329- "2: movq (%0), %%mm0\n"
25330- " movq 8(%0), %%mm1\n"
25331- " movq 16(%0), %%mm2\n"
25332- " movq 24(%0), %%mm3\n"
25333- " movq %%mm0, (%1)\n"
25334- " movq %%mm1, 8(%1)\n"
25335- " movq %%mm2, 16(%1)\n"
25336- " movq %%mm3, 24(%1)\n"
25337- " movq 32(%0), %%mm0\n"
25338- " movq 40(%0), %%mm1\n"
25339- " movq 48(%0), %%mm2\n"
25340- " movq 56(%0), %%mm3\n"
25341- " movq %%mm0, 32(%1)\n"
25342- " movq %%mm1, 40(%1)\n"
25343- " movq %%mm2, 48(%1)\n"
25344- " movq %%mm3, 56(%1)\n"
25345+ "1: prefetch 320(%1)\n"
25346+ "2: movq (%1), %%mm0\n"
25347+ " movq 8(%1), %%mm1\n"
25348+ " movq 16(%1), %%mm2\n"
25349+ " movq 24(%1), %%mm3\n"
25350+ " movq %%mm0, (%2)\n"
25351+ " movq %%mm1, 8(%2)\n"
25352+ " movq %%mm2, 16(%2)\n"
25353+ " movq %%mm3, 24(%2)\n"
25354+ " movq 32(%1), %%mm0\n"
25355+ " movq 40(%1), %%mm1\n"
25356+ " movq 48(%1), %%mm2\n"
25357+ " movq 56(%1), %%mm3\n"
25358+ " movq %%mm0, 32(%2)\n"
25359+ " movq %%mm1, 40(%2)\n"
25360+ " movq %%mm2, 48(%2)\n"
25361+ " movq %%mm3, 56(%2)\n"
25362 ".section .fixup, \"ax\"\n"
25363- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25364+ "3:\n"
25365+
25366+#ifdef CONFIG_PAX_KERNEXEC
25367+ " movl %%cr0, %0\n"
25368+ " movl %0, %%eax\n"
25369+ " andl $0xFFFEFFFF, %%eax\n"
25370+ " movl %%eax, %%cr0\n"
25371+#endif
25372+
25373+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25374+
25375+#ifdef CONFIG_PAX_KERNEXEC
25376+ " movl %0, %%cr0\n"
25377+#endif
25378+
25379 " jmp 2b\n"
25380 ".previous\n"
25381 _ASM_EXTABLE(1b, 3b)
25382- : : "r" (from), "r" (to) : "memory");
25383+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25384
25385 from += 64;
25386 to += 64;
25387@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25388 static void fast_copy_page(void *to, void *from)
25389 {
25390 int i;
25391+ unsigned long cr0;
25392
25393 kernel_fpu_begin();
25394
25395@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25396 * but that is for later. -AV
25397 */
25398 __asm__ __volatile__(
25399- "1: prefetch (%0)\n"
25400- " prefetch 64(%0)\n"
25401- " prefetch 128(%0)\n"
25402- " prefetch 192(%0)\n"
25403- " prefetch 256(%0)\n"
25404+ "1: prefetch (%1)\n"
25405+ " prefetch 64(%1)\n"
25406+ " prefetch 128(%1)\n"
25407+ " prefetch 192(%1)\n"
25408+ " prefetch 256(%1)\n"
25409 "2: \n"
25410 ".section .fixup, \"ax\"\n"
25411- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25412+ "3: \n"
25413+
25414+#ifdef CONFIG_PAX_KERNEXEC
25415+ " movl %%cr0, %0\n"
25416+ " movl %0, %%eax\n"
25417+ " andl $0xFFFEFFFF, %%eax\n"
25418+ " movl %%eax, %%cr0\n"
25419+#endif
25420+
25421+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25422+
25423+#ifdef CONFIG_PAX_KERNEXEC
25424+ " movl %0, %%cr0\n"
25425+#endif
25426+
25427 " jmp 2b\n"
25428 ".previous\n"
25429- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25430+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25431
25432 for (i = 0; i < (4096-320)/64; i++) {
25433 __asm__ __volatile__ (
25434- "1: prefetch 320(%0)\n"
25435- "2: movq (%0), %%mm0\n"
25436- " movntq %%mm0, (%1)\n"
25437- " movq 8(%0), %%mm1\n"
25438- " movntq %%mm1, 8(%1)\n"
25439- " movq 16(%0), %%mm2\n"
25440- " movntq %%mm2, 16(%1)\n"
25441- " movq 24(%0), %%mm3\n"
25442- " movntq %%mm3, 24(%1)\n"
25443- " movq 32(%0), %%mm4\n"
25444- " movntq %%mm4, 32(%1)\n"
25445- " movq 40(%0), %%mm5\n"
25446- " movntq %%mm5, 40(%1)\n"
25447- " movq 48(%0), %%mm6\n"
25448- " movntq %%mm6, 48(%1)\n"
25449- " movq 56(%0), %%mm7\n"
25450- " movntq %%mm7, 56(%1)\n"
25451+ "1: prefetch 320(%1)\n"
25452+ "2: movq (%1), %%mm0\n"
25453+ " movntq %%mm0, (%2)\n"
25454+ " movq 8(%1), %%mm1\n"
25455+ " movntq %%mm1, 8(%2)\n"
25456+ " movq 16(%1), %%mm2\n"
25457+ " movntq %%mm2, 16(%2)\n"
25458+ " movq 24(%1), %%mm3\n"
25459+ " movntq %%mm3, 24(%2)\n"
25460+ " movq 32(%1), %%mm4\n"
25461+ " movntq %%mm4, 32(%2)\n"
25462+ " movq 40(%1), %%mm5\n"
25463+ " movntq %%mm5, 40(%2)\n"
25464+ " movq 48(%1), %%mm6\n"
25465+ " movntq %%mm6, 48(%2)\n"
25466+ " movq 56(%1), %%mm7\n"
25467+ " movntq %%mm7, 56(%2)\n"
25468 ".section .fixup, \"ax\"\n"
25469- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25470+ "3:\n"
25471+
25472+#ifdef CONFIG_PAX_KERNEXEC
25473+ " movl %%cr0, %0\n"
25474+ " movl %0, %%eax\n"
25475+ " andl $0xFFFEFFFF, %%eax\n"
25476+ " movl %%eax, %%cr0\n"
25477+#endif
25478+
25479+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25480+
25481+#ifdef CONFIG_PAX_KERNEXEC
25482+ " movl %0, %%cr0\n"
25483+#endif
25484+
25485 " jmp 2b\n"
25486 ".previous\n"
25487- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25488+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25489
25490 from += 64;
25491 to += 64;
25492@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25493 static void fast_copy_page(void *to, void *from)
25494 {
25495 int i;
25496+ unsigned long cr0;
25497
25498 kernel_fpu_begin();
25499
25500 __asm__ __volatile__ (
25501- "1: prefetch (%0)\n"
25502- " prefetch 64(%0)\n"
25503- " prefetch 128(%0)\n"
25504- " prefetch 192(%0)\n"
25505- " prefetch 256(%0)\n"
25506+ "1: prefetch (%1)\n"
25507+ " prefetch 64(%1)\n"
25508+ " prefetch 128(%1)\n"
25509+ " prefetch 192(%1)\n"
25510+ " prefetch 256(%1)\n"
25511 "2: \n"
25512 ".section .fixup, \"ax\"\n"
25513- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25514+ "3: \n"
25515+
25516+#ifdef CONFIG_PAX_KERNEXEC
25517+ " movl %%cr0, %0\n"
25518+ " movl %0, %%eax\n"
25519+ " andl $0xFFFEFFFF, %%eax\n"
25520+ " movl %%eax, %%cr0\n"
25521+#endif
25522+
25523+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25524+
25525+#ifdef CONFIG_PAX_KERNEXEC
25526+ " movl %0, %%cr0\n"
25527+#endif
25528+
25529 " jmp 2b\n"
25530 ".previous\n"
25531- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25532+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25533
25534 for (i = 0; i < 4096/64; i++) {
25535 __asm__ __volatile__ (
25536- "1: prefetch 320(%0)\n"
25537- "2: movq (%0), %%mm0\n"
25538- " movq 8(%0), %%mm1\n"
25539- " movq 16(%0), %%mm2\n"
25540- " movq 24(%0), %%mm3\n"
25541- " movq %%mm0, (%1)\n"
25542- " movq %%mm1, 8(%1)\n"
25543- " movq %%mm2, 16(%1)\n"
25544- " movq %%mm3, 24(%1)\n"
25545- " movq 32(%0), %%mm0\n"
25546- " movq 40(%0), %%mm1\n"
25547- " movq 48(%0), %%mm2\n"
25548- " movq 56(%0), %%mm3\n"
25549- " movq %%mm0, 32(%1)\n"
25550- " movq %%mm1, 40(%1)\n"
25551- " movq %%mm2, 48(%1)\n"
25552- " movq %%mm3, 56(%1)\n"
25553+ "1: prefetch 320(%1)\n"
25554+ "2: movq (%1), %%mm0\n"
25555+ " movq 8(%1), %%mm1\n"
25556+ " movq 16(%1), %%mm2\n"
25557+ " movq 24(%1), %%mm3\n"
25558+ " movq %%mm0, (%2)\n"
25559+ " movq %%mm1, 8(%2)\n"
25560+ " movq %%mm2, 16(%2)\n"
25561+ " movq %%mm3, 24(%2)\n"
25562+ " movq 32(%1), %%mm0\n"
25563+ " movq 40(%1), %%mm1\n"
25564+ " movq 48(%1), %%mm2\n"
25565+ " movq 56(%1), %%mm3\n"
25566+ " movq %%mm0, 32(%2)\n"
25567+ " movq %%mm1, 40(%2)\n"
25568+ " movq %%mm2, 48(%2)\n"
25569+ " movq %%mm3, 56(%2)\n"
25570 ".section .fixup, \"ax\"\n"
25571- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25572+ "3:\n"
25573+
25574+#ifdef CONFIG_PAX_KERNEXEC
25575+ " movl %%cr0, %0\n"
25576+ " movl %0, %%eax\n"
25577+ " andl $0xFFFEFFFF, %%eax\n"
25578+ " movl %%eax, %%cr0\n"
25579+#endif
25580+
25581+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25582+
25583+#ifdef CONFIG_PAX_KERNEXEC
25584+ " movl %0, %%cr0\n"
25585+#endif
25586+
25587 " jmp 2b\n"
25588 ".previous\n"
25589 _ASM_EXTABLE(1b, 3b)
25590- : : "r" (from), "r" (to) : "memory");
25591+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25592
25593 from += 64;
25594 to += 64;
25595diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25596index f6d13ee..aca5f0b 100644
25597--- a/arch/x86/lib/msr-reg.S
25598+++ b/arch/x86/lib/msr-reg.S
25599@@ -3,6 +3,7 @@
25600 #include <asm/dwarf2.h>
25601 #include <asm/asm.h>
25602 #include <asm/msr.h>
25603+#include <asm/alternative-asm.h>
25604
25605 #ifdef CONFIG_X86_64
25606 /*
25607@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25608 CFI_STARTPROC
25609 pushq_cfi %rbx
25610 pushq_cfi %rbp
25611- movq %rdi, %r10 /* Save pointer */
25612+ movq %rdi, %r9 /* Save pointer */
25613 xorl %r11d, %r11d /* Return value */
25614 movl (%rdi), %eax
25615 movl 4(%rdi), %ecx
25616@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25617 movl 28(%rdi), %edi
25618 CFI_REMEMBER_STATE
25619 1: \op
25620-2: movl %eax, (%r10)
25621+2: movl %eax, (%r9)
25622 movl %r11d, %eax /* Return value */
25623- movl %ecx, 4(%r10)
25624- movl %edx, 8(%r10)
25625- movl %ebx, 12(%r10)
25626- movl %ebp, 20(%r10)
25627- movl %esi, 24(%r10)
25628- movl %edi, 28(%r10)
25629+ movl %ecx, 4(%r9)
25630+ movl %edx, 8(%r9)
25631+ movl %ebx, 12(%r9)
25632+ movl %ebp, 20(%r9)
25633+ movl %esi, 24(%r9)
25634+ movl %edi, 28(%r9)
25635 popq_cfi %rbp
25636 popq_cfi %rbx
25637+ pax_force_retaddr
25638 ret
25639 3:
25640 CFI_RESTORE_STATE
25641diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25642index fc6ba17..04471c5 100644
25643--- a/arch/x86/lib/putuser.S
25644+++ b/arch/x86/lib/putuser.S
25645@@ -16,7 +16,9 @@
25646 #include <asm/errno.h>
25647 #include <asm/asm.h>
25648 #include <asm/smap.h>
25649-
25650+#include <asm/segment.h>
25651+#include <asm/pgtable.h>
25652+#include <asm/alternative-asm.h>
25653
25654 /*
25655 * __put_user_X
25656@@ -30,57 +32,125 @@
25657 * as they get called from within inline assembly.
25658 */
25659
25660-#define ENTER CFI_STARTPROC ; \
25661- GET_THREAD_INFO(%_ASM_BX)
25662-#define EXIT ASM_CLAC ; \
25663- ret ; \
25664+#define ENTER CFI_STARTPROC
25665+#define EXIT ASM_CLAC ; \
25666+ pax_force_retaddr ; \
25667+ ret ; \
25668 CFI_ENDPROC
25669
25670+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25671+#define _DEST %_ASM_CX,%_ASM_BX
25672+#else
25673+#define _DEST %_ASM_CX
25674+#endif
25675+
25676+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25677+#define __copyuser_seg gs;
25678+#else
25679+#define __copyuser_seg
25680+#endif
25681+
25682 .text
25683 ENTRY(__put_user_1)
25684 ENTER
25685+
25686+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25687+ GET_THREAD_INFO(%_ASM_BX)
25688 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25689 jae bad_put_user
25690 ASM_STAC
25691-1: movb %al,(%_ASM_CX)
25692+
25693+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25694+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25695+ cmp %_ASM_BX,%_ASM_CX
25696+ jb 1234f
25697+ xor %ebx,%ebx
25698+1234:
25699+#endif
25700+
25701+#endif
25702+
25703+1: __copyuser_seg movb %al,(_DEST)
25704 xor %eax,%eax
25705 EXIT
25706 ENDPROC(__put_user_1)
25707
25708 ENTRY(__put_user_2)
25709 ENTER
25710+
25711+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25712+ GET_THREAD_INFO(%_ASM_BX)
25713 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25714 sub $1,%_ASM_BX
25715 cmp %_ASM_BX,%_ASM_CX
25716 jae bad_put_user
25717 ASM_STAC
25718-2: movw %ax,(%_ASM_CX)
25719+
25720+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25721+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25722+ cmp %_ASM_BX,%_ASM_CX
25723+ jb 1234f
25724+ xor %ebx,%ebx
25725+1234:
25726+#endif
25727+
25728+#endif
25729+
25730+2: __copyuser_seg movw %ax,(_DEST)
25731 xor %eax,%eax
25732 EXIT
25733 ENDPROC(__put_user_2)
25734
25735 ENTRY(__put_user_4)
25736 ENTER
25737+
25738+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25739+ GET_THREAD_INFO(%_ASM_BX)
25740 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25741 sub $3,%_ASM_BX
25742 cmp %_ASM_BX,%_ASM_CX
25743 jae bad_put_user
25744 ASM_STAC
25745-3: movl %eax,(%_ASM_CX)
25746+
25747+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25748+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25749+ cmp %_ASM_BX,%_ASM_CX
25750+ jb 1234f
25751+ xor %ebx,%ebx
25752+1234:
25753+#endif
25754+
25755+#endif
25756+
25757+3: __copyuser_seg movl %eax,(_DEST)
25758 xor %eax,%eax
25759 EXIT
25760 ENDPROC(__put_user_4)
25761
25762 ENTRY(__put_user_8)
25763 ENTER
25764+
25765+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25766+ GET_THREAD_INFO(%_ASM_BX)
25767 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25768 sub $7,%_ASM_BX
25769 cmp %_ASM_BX,%_ASM_CX
25770 jae bad_put_user
25771 ASM_STAC
25772-4: mov %_ASM_AX,(%_ASM_CX)
25773+
25774+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25775+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25776+ cmp %_ASM_BX,%_ASM_CX
25777+ jb 1234f
25778+ xor %ebx,%ebx
25779+1234:
25780+#endif
25781+
25782+#endif
25783+
25784+4: __copyuser_seg mov %_ASM_AX,(_DEST)
25785 #ifdef CONFIG_X86_32
25786-5: movl %edx,4(%_ASM_CX)
25787+5: __copyuser_seg movl %edx,4(_DEST)
25788 #endif
25789 xor %eax,%eax
25790 EXIT
25791diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25792index 1cad221..de671ee 100644
25793--- a/arch/x86/lib/rwlock.S
25794+++ b/arch/x86/lib/rwlock.S
25795@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25796 FRAME
25797 0: LOCK_PREFIX
25798 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25799+
25800+#ifdef CONFIG_PAX_REFCOUNT
25801+ jno 1234f
25802+ LOCK_PREFIX
25803+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25804+ int $4
25805+1234:
25806+ _ASM_EXTABLE(1234b, 1234b)
25807+#endif
25808+
25809 1: rep; nop
25810 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25811 jne 1b
25812 LOCK_PREFIX
25813 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25814+
25815+#ifdef CONFIG_PAX_REFCOUNT
25816+ jno 1234f
25817+ LOCK_PREFIX
25818+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25819+ int $4
25820+1234:
25821+ _ASM_EXTABLE(1234b, 1234b)
25822+#endif
25823+
25824 jnz 0b
25825 ENDFRAME
25826+ pax_force_retaddr
25827 ret
25828 CFI_ENDPROC
25829 END(__write_lock_failed)
25830@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25831 FRAME
25832 0: LOCK_PREFIX
25833 READ_LOCK_SIZE(inc) (%__lock_ptr)
25834+
25835+#ifdef CONFIG_PAX_REFCOUNT
25836+ jno 1234f
25837+ LOCK_PREFIX
25838+ READ_LOCK_SIZE(dec) (%__lock_ptr)
25839+ int $4
25840+1234:
25841+ _ASM_EXTABLE(1234b, 1234b)
25842+#endif
25843+
25844 1: rep; nop
25845 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25846 js 1b
25847 LOCK_PREFIX
25848 READ_LOCK_SIZE(dec) (%__lock_ptr)
25849+
25850+#ifdef CONFIG_PAX_REFCOUNT
25851+ jno 1234f
25852+ LOCK_PREFIX
25853+ READ_LOCK_SIZE(inc) (%__lock_ptr)
25854+ int $4
25855+1234:
25856+ _ASM_EXTABLE(1234b, 1234b)
25857+#endif
25858+
25859 js 0b
25860 ENDFRAME
25861+ pax_force_retaddr
25862 ret
25863 CFI_ENDPROC
25864 END(__read_lock_failed)
25865diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25866index 5dff5f0..cadebf4 100644
25867--- a/arch/x86/lib/rwsem.S
25868+++ b/arch/x86/lib/rwsem.S
25869@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25870 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25871 CFI_RESTORE __ASM_REG(dx)
25872 restore_common_regs
25873+ pax_force_retaddr
25874 ret
25875 CFI_ENDPROC
25876 ENDPROC(call_rwsem_down_read_failed)
25877@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25878 movq %rax,%rdi
25879 call rwsem_down_write_failed
25880 restore_common_regs
25881+ pax_force_retaddr
25882 ret
25883 CFI_ENDPROC
25884 ENDPROC(call_rwsem_down_write_failed)
25885@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25886 movq %rax,%rdi
25887 call rwsem_wake
25888 restore_common_regs
25889-1: ret
25890+1: pax_force_retaddr
25891+ ret
25892 CFI_ENDPROC
25893 ENDPROC(call_rwsem_wake)
25894
25895@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25896 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25897 CFI_RESTORE __ASM_REG(dx)
25898 restore_common_regs
25899+ pax_force_retaddr
25900 ret
25901 CFI_ENDPROC
25902 ENDPROC(call_rwsem_downgrade_wake)
25903diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25904index a63efd6..ccecad8 100644
25905--- a/arch/x86/lib/thunk_64.S
25906+++ b/arch/x86/lib/thunk_64.S
25907@@ -8,6 +8,7 @@
25908 #include <linux/linkage.h>
25909 #include <asm/dwarf2.h>
25910 #include <asm/calling.h>
25911+#include <asm/alternative-asm.h>
25912
25913 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25914 .macro THUNK name, func, put_ret_addr_in_rdi=0
25915@@ -41,5 +42,6 @@
25916 SAVE_ARGS
25917 restore:
25918 RESTORE_ARGS
25919+ pax_force_retaddr
25920 ret
25921 CFI_ENDPROC
25922diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25923index f0312d7..9c39d63 100644
25924--- a/arch/x86/lib/usercopy_32.c
25925+++ b/arch/x86/lib/usercopy_32.c
25926@@ -42,11 +42,13 @@ do { \
25927 int __d0; \
25928 might_fault(); \
25929 __asm__ __volatile__( \
25930+ __COPYUSER_SET_ES \
25931 ASM_STAC "\n" \
25932 "0: rep; stosl\n" \
25933 " movl %2,%0\n" \
25934 "1: rep; stosb\n" \
25935 "2: " ASM_CLAC "\n" \
25936+ __COPYUSER_RESTORE_ES \
25937 ".section .fixup,\"ax\"\n" \
25938 "3: lea 0(%2,%0,4),%0\n" \
25939 " jmp 2b\n" \
25940@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25941
25942 #ifdef CONFIG_X86_INTEL_USERCOPY
25943 static unsigned long
25944-__copy_user_intel(void __user *to, const void *from, unsigned long size)
25945+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25946 {
25947 int d0, d1;
25948 __asm__ __volatile__(
25949@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25950 " .align 2,0x90\n"
25951 "3: movl 0(%4), %%eax\n"
25952 "4: movl 4(%4), %%edx\n"
25953- "5: movl %%eax, 0(%3)\n"
25954- "6: movl %%edx, 4(%3)\n"
25955+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25956+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25957 "7: movl 8(%4), %%eax\n"
25958 "8: movl 12(%4),%%edx\n"
25959- "9: movl %%eax, 8(%3)\n"
25960- "10: movl %%edx, 12(%3)\n"
25961+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25962+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25963 "11: movl 16(%4), %%eax\n"
25964 "12: movl 20(%4), %%edx\n"
25965- "13: movl %%eax, 16(%3)\n"
25966- "14: movl %%edx, 20(%3)\n"
25967+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25968+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25969 "15: movl 24(%4), %%eax\n"
25970 "16: movl 28(%4), %%edx\n"
25971- "17: movl %%eax, 24(%3)\n"
25972- "18: movl %%edx, 28(%3)\n"
25973+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25974+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25975 "19: movl 32(%4), %%eax\n"
25976 "20: movl 36(%4), %%edx\n"
25977- "21: movl %%eax, 32(%3)\n"
25978- "22: movl %%edx, 36(%3)\n"
25979+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25980+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25981 "23: movl 40(%4), %%eax\n"
25982 "24: movl 44(%4), %%edx\n"
25983- "25: movl %%eax, 40(%3)\n"
25984- "26: movl %%edx, 44(%3)\n"
25985+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25986+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25987 "27: movl 48(%4), %%eax\n"
25988 "28: movl 52(%4), %%edx\n"
25989- "29: movl %%eax, 48(%3)\n"
25990- "30: movl %%edx, 52(%3)\n"
25991+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25992+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25993 "31: movl 56(%4), %%eax\n"
25994 "32: movl 60(%4), %%edx\n"
25995- "33: movl %%eax, 56(%3)\n"
25996- "34: movl %%edx, 60(%3)\n"
25997+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25998+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25999 " addl $-64, %0\n"
26000 " addl $64, %4\n"
26001 " addl $64, %3\n"
26002@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26003 " shrl $2, %0\n"
26004 " andl $3, %%eax\n"
26005 " cld\n"
26006+ __COPYUSER_SET_ES
26007 "99: rep; movsl\n"
26008 "36: movl %%eax, %0\n"
26009 "37: rep; movsb\n"
26010 "100:\n"
26011+ __COPYUSER_RESTORE_ES
26012 ".section .fixup,\"ax\"\n"
26013 "101: lea 0(%%eax,%0,4),%0\n"
26014 " jmp 100b\n"
26015@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26016 }
26017
26018 static unsigned long
26019+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26020+{
26021+ int d0, d1;
26022+ __asm__ __volatile__(
26023+ " .align 2,0x90\n"
26024+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26025+ " cmpl $67, %0\n"
26026+ " jbe 3f\n"
26027+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26028+ " .align 2,0x90\n"
26029+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26030+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26031+ "5: movl %%eax, 0(%3)\n"
26032+ "6: movl %%edx, 4(%3)\n"
26033+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26034+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26035+ "9: movl %%eax, 8(%3)\n"
26036+ "10: movl %%edx, 12(%3)\n"
26037+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26038+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26039+ "13: movl %%eax, 16(%3)\n"
26040+ "14: movl %%edx, 20(%3)\n"
26041+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26042+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26043+ "17: movl %%eax, 24(%3)\n"
26044+ "18: movl %%edx, 28(%3)\n"
26045+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26046+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26047+ "21: movl %%eax, 32(%3)\n"
26048+ "22: movl %%edx, 36(%3)\n"
26049+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26050+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26051+ "25: movl %%eax, 40(%3)\n"
26052+ "26: movl %%edx, 44(%3)\n"
26053+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26054+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26055+ "29: movl %%eax, 48(%3)\n"
26056+ "30: movl %%edx, 52(%3)\n"
26057+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26058+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26059+ "33: movl %%eax, 56(%3)\n"
26060+ "34: movl %%edx, 60(%3)\n"
26061+ " addl $-64, %0\n"
26062+ " addl $64, %4\n"
26063+ " addl $64, %3\n"
26064+ " cmpl $63, %0\n"
26065+ " ja 1b\n"
26066+ "35: movl %0, %%eax\n"
26067+ " shrl $2, %0\n"
26068+ " andl $3, %%eax\n"
26069+ " cld\n"
26070+ "99: rep; "__copyuser_seg" movsl\n"
26071+ "36: movl %%eax, %0\n"
26072+ "37: rep; "__copyuser_seg" movsb\n"
26073+ "100:\n"
26074+ ".section .fixup,\"ax\"\n"
26075+ "101: lea 0(%%eax,%0,4),%0\n"
26076+ " jmp 100b\n"
26077+ ".previous\n"
26078+ _ASM_EXTABLE(1b,100b)
26079+ _ASM_EXTABLE(2b,100b)
26080+ _ASM_EXTABLE(3b,100b)
26081+ _ASM_EXTABLE(4b,100b)
26082+ _ASM_EXTABLE(5b,100b)
26083+ _ASM_EXTABLE(6b,100b)
26084+ _ASM_EXTABLE(7b,100b)
26085+ _ASM_EXTABLE(8b,100b)
26086+ _ASM_EXTABLE(9b,100b)
26087+ _ASM_EXTABLE(10b,100b)
26088+ _ASM_EXTABLE(11b,100b)
26089+ _ASM_EXTABLE(12b,100b)
26090+ _ASM_EXTABLE(13b,100b)
26091+ _ASM_EXTABLE(14b,100b)
26092+ _ASM_EXTABLE(15b,100b)
26093+ _ASM_EXTABLE(16b,100b)
26094+ _ASM_EXTABLE(17b,100b)
26095+ _ASM_EXTABLE(18b,100b)
26096+ _ASM_EXTABLE(19b,100b)
26097+ _ASM_EXTABLE(20b,100b)
26098+ _ASM_EXTABLE(21b,100b)
26099+ _ASM_EXTABLE(22b,100b)
26100+ _ASM_EXTABLE(23b,100b)
26101+ _ASM_EXTABLE(24b,100b)
26102+ _ASM_EXTABLE(25b,100b)
26103+ _ASM_EXTABLE(26b,100b)
26104+ _ASM_EXTABLE(27b,100b)
26105+ _ASM_EXTABLE(28b,100b)
26106+ _ASM_EXTABLE(29b,100b)
26107+ _ASM_EXTABLE(30b,100b)
26108+ _ASM_EXTABLE(31b,100b)
26109+ _ASM_EXTABLE(32b,100b)
26110+ _ASM_EXTABLE(33b,100b)
26111+ _ASM_EXTABLE(34b,100b)
26112+ _ASM_EXTABLE(35b,100b)
26113+ _ASM_EXTABLE(36b,100b)
26114+ _ASM_EXTABLE(37b,100b)
26115+ _ASM_EXTABLE(99b,101b)
26116+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26117+ : "1"(to), "2"(from), "0"(size)
26118+ : "eax", "edx", "memory");
26119+ return size;
26120+}
26121+
26122+static unsigned long __size_overflow(3)
26123 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26124 {
26125 int d0, d1;
26126 __asm__ __volatile__(
26127 " .align 2,0x90\n"
26128- "0: movl 32(%4), %%eax\n"
26129+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26130 " cmpl $67, %0\n"
26131 " jbe 2f\n"
26132- "1: movl 64(%4), %%eax\n"
26133+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26134 " .align 2,0x90\n"
26135- "2: movl 0(%4), %%eax\n"
26136- "21: movl 4(%4), %%edx\n"
26137+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26138+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26139 " movl %%eax, 0(%3)\n"
26140 " movl %%edx, 4(%3)\n"
26141- "3: movl 8(%4), %%eax\n"
26142- "31: movl 12(%4),%%edx\n"
26143+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26144+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26145 " movl %%eax, 8(%3)\n"
26146 " movl %%edx, 12(%3)\n"
26147- "4: movl 16(%4), %%eax\n"
26148- "41: movl 20(%4), %%edx\n"
26149+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26150+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26151 " movl %%eax, 16(%3)\n"
26152 " movl %%edx, 20(%3)\n"
26153- "10: movl 24(%4), %%eax\n"
26154- "51: movl 28(%4), %%edx\n"
26155+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26156+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26157 " movl %%eax, 24(%3)\n"
26158 " movl %%edx, 28(%3)\n"
26159- "11: movl 32(%4), %%eax\n"
26160- "61: movl 36(%4), %%edx\n"
26161+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26162+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26163 " movl %%eax, 32(%3)\n"
26164 " movl %%edx, 36(%3)\n"
26165- "12: movl 40(%4), %%eax\n"
26166- "71: movl 44(%4), %%edx\n"
26167+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26168+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26169 " movl %%eax, 40(%3)\n"
26170 " movl %%edx, 44(%3)\n"
26171- "13: movl 48(%4), %%eax\n"
26172- "81: movl 52(%4), %%edx\n"
26173+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26174+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26175 " movl %%eax, 48(%3)\n"
26176 " movl %%edx, 52(%3)\n"
26177- "14: movl 56(%4), %%eax\n"
26178- "91: movl 60(%4), %%edx\n"
26179+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26180+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26181 " movl %%eax, 56(%3)\n"
26182 " movl %%edx, 60(%3)\n"
26183 " addl $-64, %0\n"
26184@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26185 " shrl $2, %0\n"
26186 " andl $3, %%eax\n"
26187 " cld\n"
26188- "6: rep; movsl\n"
26189+ "6: rep; "__copyuser_seg" movsl\n"
26190 " movl %%eax,%0\n"
26191- "7: rep; movsb\n"
26192+ "7: rep; "__copyuser_seg" movsb\n"
26193 "8:\n"
26194 ".section .fixup,\"ax\"\n"
26195 "9: lea 0(%%eax,%0,4),%0\n"
26196@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26197 * hyoshiok@miraclelinux.com
26198 */
26199
26200-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26201+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26202 const void __user *from, unsigned long size)
26203 {
26204 int d0, d1;
26205
26206 __asm__ __volatile__(
26207 " .align 2,0x90\n"
26208- "0: movl 32(%4), %%eax\n"
26209+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26210 " cmpl $67, %0\n"
26211 " jbe 2f\n"
26212- "1: movl 64(%4), %%eax\n"
26213+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26214 " .align 2,0x90\n"
26215- "2: movl 0(%4), %%eax\n"
26216- "21: movl 4(%4), %%edx\n"
26217+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26218+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26219 " movnti %%eax, 0(%3)\n"
26220 " movnti %%edx, 4(%3)\n"
26221- "3: movl 8(%4), %%eax\n"
26222- "31: movl 12(%4),%%edx\n"
26223+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26224+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26225 " movnti %%eax, 8(%3)\n"
26226 " movnti %%edx, 12(%3)\n"
26227- "4: movl 16(%4), %%eax\n"
26228- "41: movl 20(%4), %%edx\n"
26229+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26230+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26231 " movnti %%eax, 16(%3)\n"
26232 " movnti %%edx, 20(%3)\n"
26233- "10: movl 24(%4), %%eax\n"
26234- "51: movl 28(%4), %%edx\n"
26235+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26236+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26237 " movnti %%eax, 24(%3)\n"
26238 " movnti %%edx, 28(%3)\n"
26239- "11: movl 32(%4), %%eax\n"
26240- "61: movl 36(%4), %%edx\n"
26241+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26242+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26243 " movnti %%eax, 32(%3)\n"
26244 " movnti %%edx, 36(%3)\n"
26245- "12: movl 40(%4), %%eax\n"
26246- "71: movl 44(%4), %%edx\n"
26247+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26248+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26249 " movnti %%eax, 40(%3)\n"
26250 " movnti %%edx, 44(%3)\n"
26251- "13: movl 48(%4), %%eax\n"
26252- "81: movl 52(%4), %%edx\n"
26253+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26254+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26255 " movnti %%eax, 48(%3)\n"
26256 " movnti %%edx, 52(%3)\n"
26257- "14: movl 56(%4), %%eax\n"
26258- "91: movl 60(%4), %%edx\n"
26259+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26260+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26261 " movnti %%eax, 56(%3)\n"
26262 " movnti %%edx, 60(%3)\n"
26263 " addl $-64, %0\n"
26264@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26265 " shrl $2, %0\n"
26266 " andl $3, %%eax\n"
26267 " cld\n"
26268- "6: rep; movsl\n"
26269+ "6: rep; "__copyuser_seg" movsl\n"
26270 " movl %%eax,%0\n"
26271- "7: rep; movsb\n"
26272+ "7: rep; "__copyuser_seg" movsb\n"
26273 "8:\n"
26274 ".section .fixup,\"ax\"\n"
26275 "9: lea 0(%%eax,%0,4),%0\n"
26276@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26277 return size;
26278 }
26279
26280-static unsigned long __copy_user_intel_nocache(void *to,
26281+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26282 const void __user *from, unsigned long size)
26283 {
26284 int d0, d1;
26285
26286 __asm__ __volatile__(
26287 " .align 2,0x90\n"
26288- "0: movl 32(%4), %%eax\n"
26289+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26290 " cmpl $67, %0\n"
26291 " jbe 2f\n"
26292- "1: movl 64(%4), %%eax\n"
26293+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26294 " .align 2,0x90\n"
26295- "2: movl 0(%4), %%eax\n"
26296- "21: movl 4(%4), %%edx\n"
26297+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26298+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26299 " movnti %%eax, 0(%3)\n"
26300 " movnti %%edx, 4(%3)\n"
26301- "3: movl 8(%4), %%eax\n"
26302- "31: movl 12(%4),%%edx\n"
26303+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26304+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26305 " movnti %%eax, 8(%3)\n"
26306 " movnti %%edx, 12(%3)\n"
26307- "4: movl 16(%4), %%eax\n"
26308- "41: movl 20(%4), %%edx\n"
26309+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26310+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26311 " movnti %%eax, 16(%3)\n"
26312 " movnti %%edx, 20(%3)\n"
26313- "10: movl 24(%4), %%eax\n"
26314- "51: movl 28(%4), %%edx\n"
26315+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26316+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26317 " movnti %%eax, 24(%3)\n"
26318 " movnti %%edx, 28(%3)\n"
26319- "11: movl 32(%4), %%eax\n"
26320- "61: movl 36(%4), %%edx\n"
26321+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26322+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26323 " movnti %%eax, 32(%3)\n"
26324 " movnti %%edx, 36(%3)\n"
26325- "12: movl 40(%4), %%eax\n"
26326- "71: movl 44(%4), %%edx\n"
26327+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26328+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26329 " movnti %%eax, 40(%3)\n"
26330 " movnti %%edx, 44(%3)\n"
26331- "13: movl 48(%4), %%eax\n"
26332- "81: movl 52(%4), %%edx\n"
26333+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26334+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26335 " movnti %%eax, 48(%3)\n"
26336 " movnti %%edx, 52(%3)\n"
26337- "14: movl 56(%4), %%eax\n"
26338- "91: movl 60(%4), %%edx\n"
26339+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26340+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26341 " movnti %%eax, 56(%3)\n"
26342 " movnti %%edx, 60(%3)\n"
26343 " addl $-64, %0\n"
26344@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26345 " shrl $2, %0\n"
26346 " andl $3, %%eax\n"
26347 " cld\n"
26348- "6: rep; movsl\n"
26349+ "6: rep; "__copyuser_seg" movsl\n"
26350 " movl %%eax,%0\n"
26351- "7: rep; movsb\n"
26352+ "7: rep; "__copyuser_seg" movsb\n"
26353 "8:\n"
26354 ".section .fixup,\"ax\"\n"
26355 "9: lea 0(%%eax,%0,4),%0\n"
26356@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26357 */
26358 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26359 unsigned long size);
26360-unsigned long __copy_user_intel(void __user *to, const void *from,
26361+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26362+ unsigned long size);
26363+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26364 unsigned long size);
26365 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26366 const void __user *from, unsigned long size);
26367 #endif /* CONFIG_X86_INTEL_USERCOPY */
26368
26369 /* Generic arbitrary sized copy. */
26370-#define __copy_user(to, from, size) \
26371+#define __copy_user(to, from, size, prefix, set, restore) \
26372 do { \
26373 int __d0, __d1, __d2; \
26374 __asm__ __volatile__( \
26375+ set \
26376 " cmp $7,%0\n" \
26377 " jbe 1f\n" \
26378 " movl %1,%0\n" \
26379 " negl %0\n" \
26380 " andl $7,%0\n" \
26381 " subl %0,%3\n" \
26382- "4: rep; movsb\n" \
26383+ "4: rep; "prefix"movsb\n" \
26384 " movl %3,%0\n" \
26385 " shrl $2,%0\n" \
26386 " andl $3,%3\n" \
26387 " .align 2,0x90\n" \
26388- "0: rep; movsl\n" \
26389+ "0: rep; "prefix"movsl\n" \
26390 " movl %3,%0\n" \
26391- "1: rep; movsb\n" \
26392+ "1: rep; "prefix"movsb\n" \
26393 "2:\n" \
26394+ restore \
26395 ".section .fixup,\"ax\"\n" \
26396 "5: addl %3,%0\n" \
26397 " jmp 2b\n" \
26398@@ -538,14 +650,14 @@ do { \
26399 " negl %0\n" \
26400 " andl $7,%0\n" \
26401 " subl %0,%3\n" \
26402- "4: rep; movsb\n" \
26403+ "4: rep; "__copyuser_seg"movsb\n" \
26404 " movl %3,%0\n" \
26405 " shrl $2,%0\n" \
26406 " andl $3,%3\n" \
26407 " .align 2,0x90\n" \
26408- "0: rep; movsl\n" \
26409+ "0: rep; "__copyuser_seg"movsl\n" \
26410 " movl %3,%0\n" \
26411- "1: rep; movsb\n" \
26412+ "1: rep; "__copyuser_seg"movsb\n" \
26413 "2:\n" \
26414 ".section .fixup,\"ax\"\n" \
26415 "5: addl %3,%0\n" \
26416@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26417 {
26418 stac();
26419 if (movsl_is_ok(to, from, n))
26420- __copy_user(to, from, n);
26421+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26422 else
26423- n = __copy_user_intel(to, from, n);
26424+ n = __generic_copy_to_user_intel(to, from, n);
26425 clac();
26426 return n;
26427 }
26428@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26429 {
26430 stac();
26431 if (movsl_is_ok(to, from, n))
26432- __copy_user(to, from, n);
26433+ __copy_user(to, from, n, __copyuser_seg, "", "");
26434 else
26435- n = __copy_user_intel((void __user *)to,
26436- (const void *)from, n);
26437+ n = __generic_copy_from_user_intel(to, from, n);
26438 clac();
26439 return n;
26440 }
26441@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26442 if (n > 64 && cpu_has_xmm2)
26443 n = __copy_user_intel_nocache(to, from, n);
26444 else
26445- __copy_user(to, from, n);
26446+ __copy_user(to, from, n, __copyuser_seg, "", "");
26447 #else
26448- __copy_user(to, from, n);
26449+ __copy_user(to, from, n, __copyuser_seg, "", "");
26450 #endif
26451 clac();
26452 return n;
26453 }
26454 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26455
26456-/**
26457- * copy_to_user: - Copy a block of data into user space.
26458- * @to: Destination address, in user space.
26459- * @from: Source address, in kernel space.
26460- * @n: Number of bytes to copy.
26461- *
26462- * Context: User context only. This function may sleep.
26463- *
26464- * Copy data from kernel space to user space.
26465- *
26466- * Returns number of bytes that could not be copied.
26467- * On success, this will be zero.
26468- */
26469-unsigned long
26470-copy_to_user(void __user *to, const void *from, unsigned long n)
26471-{
26472- if (access_ok(VERIFY_WRITE, to, n))
26473- n = __copy_to_user(to, from, n);
26474- return n;
26475-}
26476-EXPORT_SYMBOL(copy_to_user);
26477-
26478-/**
26479- * copy_from_user: - Copy a block of data from user space.
26480- * @to: Destination address, in kernel space.
26481- * @from: Source address, in user space.
26482- * @n: Number of bytes to copy.
26483- *
26484- * Context: User context only. This function may sleep.
26485- *
26486- * Copy data from user space to kernel space.
26487- *
26488- * Returns number of bytes that could not be copied.
26489- * On success, this will be zero.
26490- *
26491- * If some data could not be copied, this function will pad the copied
26492- * data to the requested size using zero bytes.
26493- */
26494-unsigned long
26495-_copy_from_user(void *to, const void __user *from, unsigned long n)
26496-{
26497- if (access_ok(VERIFY_READ, from, n))
26498- n = __copy_from_user(to, from, n);
26499- else
26500- memset(to, 0, n);
26501- return n;
26502-}
26503-EXPORT_SYMBOL(_copy_from_user);
26504-
26505 void copy_from_user_overflow(void)
26506 {
26507 WARN(1, "Buffer overflow detected!\n");
26508 }
26509 EXPORT_SYMBOL(copy_from_user_overflow);
26510+
26511+void copy_to_user_overflow(void)
26512+{
26513+ WARN(1, "Buffer overflow detected!\n");
26514+}
26515+EXPORT_SYMBOL(copy_to_user_overflow);
26516+
26517+#ifdef CONFIG_PAX_MEMORY_UDEREF
26518+void __set_fs(mm_segment_t x)
26519+{
26520+ switch (x.seg) {
26521+ case 0:
26522+ loadsegment(gs, 0);
26523+ break;
26524+ case TASK_SIZE_MAX:
26525+ loadsegment(gs, __USER_DS);
26526+ break;
26527+ case -1UL:
26528+ loadsegment(gs, __KERNEL_DS);
26529+ break;
26530+ default:
26531+ BUG();
26532+ }
26533+ return;
26534+}
26535+EXPORT_SYMBOL(__set_fs);
26536+
26537+void set_fs(mm_segment_t x)
26538+{
26539+ current_thread_info()->addr_limit = x;
26540+ __set_fs(x);
26541+}
26542+EXPORT_SYMBOL(set_fs);
26543+#endif
26544diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26545index 05928aa..b33dea1 100644
26546--- a/arch/x86/lib/usercopy_64.c
26547+++ b/arch/x86/lib/usercopy_64.c
26548@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26549 _ASM_EXTABLE(0b,3b)
26550 _ASM_EXTABLE(1b,2b)
26551 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26552- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26553+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26554 [zero] "r" (0UL), [eight] "r" (8UL));
26555 clac();
26556 return size;
26557@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26558 }
26559 EXPORT_SYMBOL(clear_user);
26560
26561-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26562+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26563 {
26564- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26565- return copy_user_generic((__force void *)to, (__force void *)from, len);
26566- }
26567- return len;
26568+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26569+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26570+ return len;
26571 }
26572 EXPORT_SYMBOL(copy_in_user);
26573
26574@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26575 * it is not necessary to optimize tail handling.
26576 */
26577 unsigned long
26578-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26579+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26580 {
26581 char c;
26582 unsigned zero_len;
26583@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26584 clac();
26585 return len;
26586 }
26587+
26588+void copy_from_user_overflow(void)
26589+{
26590+ WARN(1, "Buffer overflow detected!\n");
26591+}
26592+EXPORT_SYMBOL(copy_from_user_overflow);
26593+
26594+void copy_to_user_overflow(void)
26595+{
26596+ WARN(1, "Buffer overflow detected!\n");
26597+}
26598+EXPORT_SYMBOL(copy_to_user_overflow);
26599diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26600index 903ec1e..c4166b2 100644
26601--- a/arch/x86/mm/extable.c
26602+++ b/arch/x86/mm/extable.c
26603@@ -6,12 +6,24 @@
26604 static inline unsigned long
26605 ex_insn_addr(const struct exception_table_entry *x)
26606 {
26607- return (unsigned long)&x->insn + x->insn;
26608+ unsigned long reloc = 0;
26609+
26610+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26611+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26612+#endif
26613+
26614+ return (unsigned long)&x->insn + x->insn + reloc;
26615 }
26616 static inline unsigned long
26617 ex_fixup_addr(const struct exception_table_entry *x)
26618 {
26619- return (unsigned long)&x->fixup + x->fixup;
26620+ unsigned long reloc = 0;
26621+
26622+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26623+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26624+#endif
26625+
26626+ return (unsigned long)&x->fixup + x->fixup + reloc;
26627 }
26628
26629 int fixup_exception(struct pt_regs *regs)
26630@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26631 unsigned long new_ip;
26632
26633 #ifdef CONFIG_PNPBIOS
26634- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26635+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26636 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26637 extern u32 pnp_bios_is_utter_crap;
26638 pnp_bios_is_utter_crap = 1;
26639@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26640 i += 4;
26641 p->fixup -= i;
26642 i += 4;
26643+
26644+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26645+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26646+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26647+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26648+#endif
26649+
26650 }
26651 }
26652
26653diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26654index fb674fd..272f369 100644
26655--- a/arch/x86/mm/fault.c
26656+++ b/arch/x86/mm/fault.c
26657@@ -13,12 +13,19 @@
26658 #include <linux/perf_event.h> /* perf_sw_event */
26659 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26660 #include <linux/prefetch.h> /* prefetchw */
26661+#include <linux/unistd.h>
26662+#include <linux/compiler.h>
26663
26664 #include <asm/traps.h> /* dotraplinkage, ... */
26665 #include <asm/pgalloc.h> /* pgd_*(), ... */
26666 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26667 #include <asm/fixmap.h> /* VSYSCALL_START */
26668 #include <asm/context_tracking.h> /* exception_enter(), ... */
26669+#include <asm/tlbflush.h>
26670+
26671+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26672+#include <asm/stacktrace.h>
26673+#endif
26674
26675 /*
26676 * Page fault error code bits:
26677@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26678 int ret = 0;
26679
26680 /* kprobe_running() needs smp_processor_id() */
26681- if (kprobes_built_in() && !user_mode_vm(regs)) {
26682+ if (kprobes_built_in() && !user_mode(regs)) {
26683 preempt_disable();
26684 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26685 ret = 1;
26686@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26687 return !instr_lo || (instr_lo>>1) == 1;
26688 case 0x00:
26689 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26690- if (probe_kernel_address(instr, opcode))
26691+ if (user_mode(regs)) {
26692+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26693+ return 0;
26694+ } else if (probe_kernel_address(instr, opcode))
26695 return 0;
26696
26697 *prefetch = (instr_lo == 0xF) &&
26698@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26699 while (instr < max_instr) {
26700 unsigned char opcode;
26701
26702- if (probe_kernel_address(instr, opcode))
26703+ if (user_mode(regs)) {
26704+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26705+ break;
26706+ } else if (probe_kernel_address(instr, opcode))
26707 break;
26708
26709 instr++;
26710@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26711 force_sig_info(si_signo, &info, tsk);
26712 }
26713
26714+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26715+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26716+#endif
26717+
26718+#ifdef CONFIG_PAX_EMUTRAMP
26719+static int pax_handle_fetch_fault(struct pt_regs *regs);
26720+#endif
26721+
26722+#ifdef CONFIG_PAX_PAGEEXEC
26723+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26724+{
26725+ pgd_t *pgd;
26726+ pud_t *pud;
26727+ pmd_t *pmd;
26728+
26729+ pgd = pgd_offset(mm, address);
26730+ if (!pgd_present(*pgd))
26731+ return NULL;
26732+ pud = pud_offset(pgd, address);
26733+ if (!pud_present(*pud))
26734+ return NULL;
26735+ pmd = pmd_offset(pud, address);
26736+ if (!pmd_present(*pmd))
26737+ return NULL;
26738+ return pmd;
26739+}
26740+#endif
26741+
26742 DEFINE_SPINLOCK(pgd_lock);
26743 LIST_HEAD(pgd_list);
26744
26745@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26746 for (address = VMALLOC_START & PMD_MASK;
26747 address >= TASK_SIZE && address < FIXADDR_TOP;
26748 address += PMD_SIZE) {
26749+
26750+#ifdef CONFIG_PAX_PER_CPU_PGD
26751+ unsigned long cpu;
26752+#else
26753 struct page *page;
26754+#endif
26755
26756 spin_lock(&pgd_lock);
26757+
26758+#ifdef CONFIG_PAX_PER_CPU_PGD
26759+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26760+ pgd_t *pgd = get_cpu_pgd(cpu);
26761+ pmd_t *ret;
26762+#else
26763 list_for_each_entry(page, &pgd_list, lru) {
26764+ pgd_t *pgd = page_address(page);
26765 spinlock_t *pgt_lock;
26766 pmd_t *ret;
26767
26768@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26769 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26770
26771 spin_lock(pgt_lock);
26772- ret = vmalloc_sync_one(page_address(page), address);
26773+#endif
26774+
26775+ ret = vmalloc_sync_one(pgd, address);
26776+
26777+#ifndef CONFIG_PAX_PER_CPU_PGD
26778 spin_unlock(pgt_lock);
26779+#endif
26780
26781 if (!ret)
26782 break;
26783@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26784 * an interrupt in the middle of a task switch..
26785 */
26786 pgd_paddr = read_cr3();
26787+
26788+#ifdef CONFIG_PAX_PER_CPU_PGD
26789+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26790+#endif
26791+
26792 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26793 if (!pmd_k)
26794 return -1;
26795@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26796 * happen within a race in page table update. In the later
26797 * case just flush:
26798 */
26799+
26800+#ifdef CONFIG_PAX_PER_CPU_PGD
26801+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26802+ pgd = pgd_offset_cpu(smp_processor_id(), address);
26803+#else
26804 pgd = pgd_offset(current->active_mm, address);
26805+#endif
26806+
26807 pgd_ref = pgd_offset_k(address);
26808 if (pgd_none(*pgd_ref))
26809 return -1;
26810@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26811 static int is_errata100(struct pt_regs *regs, unsigned long address)
26812 {
26813 #ifdef CONFIG_X86_64
26814- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26815+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26816 return 1;
26817 #endif
26818 return 0;
26819@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26820 }
26821
26822 static const char nx_warning[] = KERN_CRIT
26823-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26824+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26825
26826 static void
26827 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26828@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26829 if (!oops_may_print())
26830 return;
26831
26832- if (error_code & PF_INSTR) {
26833+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26834 unsigned int level;
26835
26836 pte_t *pte = lookup_address(address, &level);
26837
26838 if (pte && pte_present(*pte) && !pte_exec(*pte))
26839- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26840+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26841 }
26842
26843+#ifdef CONFIG_PAX_KERNEXEC
26844+ if (init_mm.start_code <= address && address < init_mm.end_code) {
26845+ if (current->signal->curr_ip)
26846+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26847+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
26848+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26849+ else
26850+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26851+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26852+ }
26853+#endif
26854+
26855 printk(KERN_ALERT "BUG: unable to handle kernel ");
26856 if (address < PAGE_SIZE)
26857 printk(KERN_CONT "NULL pointer dereference");
26858@@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26859 return;
26860 }
26861 #endif
26862+
26863+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26864+ if (pax_is_fetch_fault(regs, error_code, address)) {
26865+
26866+#ifdef CONFIG_PAX_EMUTRAMP
26867+ switch (pax_handle_fetch_fault(regs)) {
26868+ case 2:
26869+ return;
26870+ }
26871+#endif
26872+
26873+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26874+ do_group_exit(SIGKILL);
26875+ }
26876+#endif
26877+
26878 /* Kernel addresses are always protection faults: */
26879 if (address >= TASK_SIZE)
26880 error_code |= PF_PROT;
26881@@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26882 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26883 printk(KERN_ERR
26884 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26885- tsk->comm, tsk->pid, address);
26886+ tsk->comm, task_pid_nr(tsk), address);
26887 code = BUS_MCEERR_AR;
26888 }
26889 #endif
26890@@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26891 return 1;
26892 }
26893
26894+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26895+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26896+{
26897+ pte_t *pte;
26898+ pmd_t *pmd;
26899+ spinlock_t *ptl;
26900+ unsigned char pte_mask;
26901+
26902+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26903+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
26904+ return 0;
26905+
26906+ /* PaX: it's our fault, let's handle it if we can */
26907+
26908+ /* PaX: take a look at read faults before acquiring any locks */
26909+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26910+ /* instruction fetch attempt from a protected page in user mode */
26911+ up_read(&mm->mmap_sem);
26912+
26913+#ifdef CONFIG_PAX_EMUTRAMP
26914+ switch (pax_handle_fetch_fault(regs)) {
26915+ case 2:
26916+ return 1;
26917+ }
26918+#endif
26919+
26920+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26921+ do_group_exit(SIGKILL);
26922+ }
26923+
26924+ pmd = pax_get_pmd(mm, address);
26925+ if (unlikely(!pmd))
26926+ return 0;
26927+
26928+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26929+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26930+ pte_unmap_unlock(pte, ptl);
26931+ return 0;
26932+ }
26933+
26934+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26935+ /* write attempt to a protected page in user mode */
26936+ pte_unmap_unlock(pte, ptl);
26937+ return 0;
26938+ }
26939+
26940+#ifdef CONFIG_SMP
26941+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26942+#else
26943+ if (likely(address > get_limit(regs->cs)))
26944+#endif
26945+ {
26946+ set_pte(pte, pte_mkread(*pte));
26947+ __flush_tlb_one(address);
26948+ pte_unmap_unlock(pte, ptl);
26949+ up_read(&mm->mmap_sem);
26950+ return 1;
26951+ }
26952+
26953+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26954+
26955+ /*
26956+ * PaX: fill DTLB with user rights and retry
26957+ */
26958+ __asm__ __volatile__ (
26959+ "orb %2,(%1)\n"
26960+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26961+/*
26962+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26963+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26964+ * page fault when examined during a TLB load attempt. this is true not only
26965+ * for PTEs holding a non-present entry but also present entries that will
26966+ * raise a page fault (such as those set up by PaX, or the copy-on-write
26967+ * mechanism). in effect it means that we do *not* need to flush the TLBs
26968+ * for our target pages since their PTEs are simply not in the TLBs at all.
26969+
26970+ * the best thing in omitting it is that we gain around 15-20% speed in the
26971+ * fast path of the page fault handler and can get rid of tracing since we
26972+ * can no longer flush unintended entries.
26973+ */
26974+ "invlpg (%0)\n"
26975+#endif
26976+ __copyuser_seg"testb $0,(%0)\n"
26977+ "xorb %3,(%1)\n"
26978+ :
26979+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26980+ : "memory", "cc");
26981+ pte_unmap_unlock(pte, ptl);
26982+ up_read(&mm->mmap_sem);
26983+ return 1;
26984+}
26985+#endif
26986+
26987 /*
26988 * Handle a spurious fault caused by a stale TLB entry.
26989 *
26990@@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26991 static inline int
26992 access_error(unsigned long error_code, struct vm_area_struct *vma)
26993 {
26994+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26995+ return 1;
26996+
26997 if (error_code & PF_WRITE) {
26998 /* write, present and write, not present: */
26999 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27000@@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27001 if (error_code & PF_USER)
27002 return false;
27003
27004- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27005+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27006 return false;
27007
27008 return true;
27009@@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27010 {
27011 struct vm_area_struct *vma;
27012 struct task_struct *tsk;
27013- unsigned long address;
27014 struct mm_struct *mm;
27015 int fault;
27016 int write = error_code & PF_WRITE;
27017 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27018 (write ? FAULT_FLAG_WRITE : 0);
27019
27020- tsk = current;
27021- mm = tsk->mm;
27022-
27023 /* Get the faulting address: */
27024- address = read_cr2();
27025+ unsigned long address = read_cr2();
27026+
27027+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27028+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
27029+ if (!search_exception_tables(regs->ip)) {
27030+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27031+ bad_area_nosemaphore(regs, error_code, address);
27032+ return;
27033+ }
27034+ if (address < PAX_USER_SHADOW_BASE) {
27035+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27036+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27037+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27038+ } else
27039+ address -= PAX_USER_SHADOW_BASE;
27040+ }
27041+#endif
27042+
27043+ tsk = current;
27044+ mm = tsk->mm;
27045
27046 /*
27047 * Detect and handle instructions that would cause a page fault for
27048@@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27049 * User-mode registers count as a user access even for any
27050 * potential system fault or CPU buglet:
27051 */
27052- if (user_mode_vm(regs)) {
27053+ if (user_mode(regs)) {
27054 local_irq_enable();
27055 error_code |= PF_USER;
27056 } else {
27057@@ -1146,6 +1355,11 @@ retry:
27058 might_sleep();
27059 }
27060
27061+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27062+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27063+ return;
27064+#endif
27065+
27066 vma = find_vma(mm, address);
27067 if (unlikely(!vma)) {
27068 bad_area(regs, error_code, address);
27069@@ -1157,18 +1371,24 @@ retry:
27070 bad_area(regs, error_code, address);
27071 return;
27072 }
27073- if (error_code & PF_USER) {
27074- /*
27075- * Accessing the stack below %sp is always a bug.
27076- * The large cushion allows instructions like enter
27077- * and pusha to work. ("enter $65535, $31" pushes
27078- * 32 pointers and then decrements %sp by 65535.)
27079- */
27080- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27081- bad_area(regs, error_code, address);
27082- return;
27083- }
27084+ /*
27085+ * Accessing the stack below %sp is always a bug.
27086+ * The large cushion allows instructions like enter
27087+ * and pusha to work. ("enter $65535, $31" pushes
27088+ * 32 pointers and then decrements %sp by 65535.)
27089+ */
27090+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27091+ bad_area(regs, error_code, address);
27092+ return;
27093 }
27094+
27095+#ifdef CONFIG_PAX_SEGMEXEC
27096+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27097+ bad_area(regs, error_code, address);
27098+ return;
27099+ }
27100+#endif
27101+
27102 if (unlikely(expand_stack(vma, address))) {
27103 bad_area(regs, error_code, address);
27104 return;
27105@@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27106 __do_page_fault(regs, error_code);
27107 exception_exit(regs);
27108 }
27109+
27110+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27111+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27112+{
27113+ struct mm_struct *mm = current->mm;
27114+ unsigned long ip = regs->ip;
27115+
27116+ if (v8086_mode(regs))
27117+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27118+
27119+#ifdef CONFIG_PAX_PAGEEXEC
27120+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27121+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27122+ return true;
27123+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27124+ return true;
27125+ return false;
27126+ }
27127+#endif
27128+
27129+#ifdef CONFIG_PAX_SEGMEXEC
27130+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27131+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27132+ return true;
27133+ return false;
27134+ }
27135+#endif
27136+
27137+ return false;
27138+}
27139+#endif
27140+
27141+#ifdef CONFIG_PAX_EMUTRAMP
27142+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27143+{
27144+ int err;
27145+
27146+ do { /* PaX: libffi trampoline emulation */
27147+ unsigned char mov, jmp;
27148+ unsigned int addr1, addr2;
27149+
27150+#ifdef CONFIG_X86_64
27151+ if ((regs->ip + 9) >> 32)
27152+ break;
27153+#endif
27154+
27155+ err = get_user(mov, (unsigned char __user *)regs->ip);
27156+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27157+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27158+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27159+
27160+ if (err)
27161+ break;
27162+
27163+ if (mov == 0xB8 && jmp == 0xE9) {
27164+ regs->ax = addr1;
27165+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27166+ return 2;
27167+ }
27168+ } while (0);
27169+
27170+ do { /* PaX: gcc trampoline emulation #1 */
27171+ unsigned char mov1, mov2;
27172+ unsigned short jmp;
27173+ unsigned int addr1, addr2;
27174+
27175+#ifdef CONFIG_X86_64
27176+ if ((regs->ip + 11) >> 32)
27177+ break;
27178+#endif
27179+
27180+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27181+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27182+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27183+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27184+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27185+
27186+ if (err)
27187+ break;
27188+
27189+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27190+ regs->cx = addr1;
27191+ regs->ax = addr2;
27192+ regs->ip = addr2;
27193+ return 2;
27194+ }
27195+ } while (0);
27196+
27197+ do { /* PaX: gcc trampoline emulation #2 */
27198+ unsigned char mov, jmp;
27199+ unsigned int addr1, addr2;
27200+
27201+#ifdef CONFIG_X86_64
27202+ if ((regs->ip + 9) >> 32)
27203+ break;
27204+#endif
27205+
27206+ err = get_user(mov, (unsigned char __user *)regs->ip);
27207+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27208+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27209+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27210+
27211+ if (err)
27212+ break;
27213+
27214+ if (mov == 0xB9 && jmp == 0xE9) {
27215+ regs->cx = addr1;
27216+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27217+ return 2;
27218+ }
27219+ } while (0);
27220+
27221+ return 1; /* PaX in action */
27222+}
27223+
27224+#ifdef CONFIG_X86_64
27225+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27226+{
27227+ int err;
27228+
27229+ do { /* PaX: libffi trampoline emulation */
27230+ unsigned short mov1, mov2, jmp1;
27231+ unsigned char stcclc, jmp2;
27232+ unsigned long addr1, addr2;
27233+
27234+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27235+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27236+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27237+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27238+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27239+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27240+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27241+
27242+ if (err)
27243+ break;
27244+
27245+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27246+ regs->r11 = addr1;
27247+ regs->r10 = addr2;
27248+ if (stcclc == 0xF8)
27249+ regs->flags &= ~X86_EFLAGS_CF;
27250+ else
27251+ regs->flags |= X86_EFLAGS_CF;
27252+ regs->ip = addr1;
27253+ return 2;
27254+ }
27255+ } while (0);
27256+
27257+ do { /* PaX: gcc trampoline emulation #1 */
27258+ unsigned short mov1, mov2, jmp1;
27259+ unsigned char jmp2;
27260+ unsigned int addr1;
27261+ unsigned long addr2;
27262+
27263+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27264+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27265+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27266+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27267+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27268+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27269+
27270+ if (err)
27271+ break;
27272+
27273+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27274+ regs->r11 = addr1;
27275+ regs->r10 = addr2;
27276+ regs->ip = addr1;
27277+ return 2;
27278+ }
27279+ } while (0);
27280+
27281+ do { /* PaX: gcc trampoline emulation #2 */
27282+ unsigned short mov1, mov2, jmp1;
27283+ unsigned char jmp2;
27284+ unsigned long addr1, addr2;
27285+
27286+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27287+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27288+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27289+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27290+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27291+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27292+
27293+ if (err)
27294+ break;
27295+
27296+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27297+ regs->r11 = addr1;
27298+ regs->r10 = addr2;
27299+ regs->ip = addr1;
27300+ return 2;
27301+ }
27302+ } while (0);
27303+
27304+ return 1; /* PaX in action */
27305+}
27306+#endif
27307+
27308+/*
27309+ * PaX: decide what to do with offenders (regs->ip = fault address)
27310+ *
27311+ * returns 1 when task should be killed
27312+ * 2 when gcc trampoline was detected
27313+ */
27314+static int pax_handle_fetch_fault(struct pt_regs *regs)
27315+{
27316+ if (v8086_mode(regs))
27317+ return 1;
27318+
27319+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27320+ return 1;
27321+
27322+#ifdef CONFIG_X86_32
27323+ return pax_handle_fetch_fault_32(regs);
27324+#else
27325+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27326+ return pax_handle_fetch_fault_32(regs);
27327+ else
27328+ return pax_handle_fetch_fault_64(regs);
27329+#endif
27330+}
27331+#endif
27332+
27333+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27334+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27335+{
27336+ long i;
27337+
27338+ printk(KERN_ERR "PAX: bytes at PC: ");
27339+ for (i = 0; i < 20; i++) {
27340+ unsigned char c;
27341+ if (get_user(c, (unsigned char __force_user *)pc+i))
27342+ printk(KERN_CONT "?? ");
27343+ else
27344+ printk(KERN_CONT "%02x ", c);
27345+ }
27346+ printk("\n");
27347+
27348+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27349+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27350+ unsigned long c;
27351+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27352+#ifdef CONFIG_X86_32
27353+ printk(KERN_CONT "???????? ");
27354+#else
27355+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27356+ printk(KERN_CONT "???????? ???????? ");
27357+ else
27358+ printk(KERN_CONT "???????????????? ");
27359+#endif
27360+ } else {
27361+#ifdef CONFIG_X86_64
27362+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27363+ printk(KERN_CONT "%08x ", (unsigned int)c);
27364+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27365+ } else
27366+#endif
27367+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27368+ }
27369+ }
27370+ printk("\n");
27371+}
27372+#endif
27373+
27374+/**
27375+ * probe_kernel_write(): safely attempt to write to a location
27376+ * @dst: address to write to
27377+ * @src: pointer to the data that shall be written
27378+ * @size: size of the data chunk
27379+ *
27380+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27381+ * happens, handle that and return -EFAULT.
27382+ */
27383+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27384+{
27385+ long ret;
27386+ mm_segment_t old_fs = get_fs();
27387+
27388+ set_fs(KERNEL_DS);
27389+ pagefault_disable();
27390+ pax_open_kernel();
27391+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27392+ pax_close_kernel();
27393+ pagefault_enable();
27394+ set_fs(old_fs);
27395+
27396+ return ret ? -EFAULT : 0;
27397+}
27398diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27399index dd74e46..7d26398 100644
27400--- a/arch/x86/mm/gup.c
27401+++ b/arch/x86/mm/gup.c
27402@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27403 addr = start;
27404 len = (unsigned long) nr_pages << PAGE_SHIFT;
27405 end = start + len;
27406- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27407+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27408 (void __user *)start, len)))
27409 return 0;
27410
27411diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27412index 6f31ee5..8ee4164 100644
27413--- a/arch/x86/mm/highmem_32.c
27414+++ b/arch/x86/mm/highmem_32.c
27415@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27416 idx = type + KM_TYPE_NR*smp_processor_id();
27417 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27418 BUG_ON(!pte_none(*(kmap_pte-idx)));
27419+
27420+ pax_open_kernel();
27421 set_pte(kmap_pte-idx, mk_pte(page, prot));
27422+ pax_close_kernel();
27423+
27424 arch_flush_lazy_mmu_mode();
27425
27426 return (void *)vaddr;
27427diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27428index ae1aa71..56316db 100644
27429--- a/arch/x86/mm/hugetlbpage.c
27430+++ b/arch/x86/mm/hugetlbpage.c
27431@@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27432 info.flags = 0;
27433 info.length = len;
27434 info.low_limit = TASK_UNMAPPED_BASE;
27435+
27436+#ifdef CONFIG_PAX_RANDMMAP
27437+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27438+ info.low_limit += current->mm->delta_mmap;
27439+#endif
27440+
27441 info.high_limit = TASK_SIZE;
27442 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27443 info.align_offset = 0;
27444@@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27445 VM_BUG_ON(addr != -ENOMEM);
27446 info.flags = 0;
27447 info.low_limit = TASK_UNMAPPED_BASE;
27448+
27449+#ifdef CONFIG_PAX_RANDMMAP
27450+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27451+ info.low_limit += current->mm->delta_mmap;
27452+#endif
27453+
27454 info.high_limit = TASK_SIZE;
27455 addr = vm_unmapped_area(&info);
27456 }
27457@@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27458 struct hstate *h = hstate_file(file);
27459 struct mm_struct *mm = current->mm;
27460 struct vm_area_struct *vma;
27461+ unsigned long pax_task_size = TASK_SIZE;
27462+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27463
27464 if (len & ~huge_page_mask(h))
27465 return -EINVAL;
27466- if (len > TASK_SIZE)
27467+
27468+#ifdef CONFIG_PAX_SEGMEXEC
27469+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27470+ pax_task_size = SEGMEXEC_TASK_SIZE;
27471+#endif
27472+
27473+ pax_task_size -= PAGE_SIZE;
27474+
27475+ if (len > pax_task_size)
27476 return -ENOMEM;
27477
27478 if (flags & MAP_FIXED) {
27479@@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27480 return addr;
27481 }
27482
27483+#ifdef CONFIG_PAX_RANDMMAP
27484+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27485+#endif
27486+
27487 if (addr) {
27488 addr = ALIGN(addr, huge_page_size(h));
27489 vma = find_vma(mm, addr);
27490- if (TASK_SIZE - len >= addr &&
27491- (!vma || addr + len <= vma->vm_start))
27492+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27493 return addr;
27494 }
27495 if (mm->get_unmapped_area == arch_get_unmapped_area)
27496diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27497index d7aea41..0fc945b 100644
27498--- a/arch/x86/mm/init.c
27499+++ b/arch/x86/mm/init.c
27500@@ -4,6 +4,7 @@
27501 #include <linux/swap.h>
27502 #include <linux/memblock.h>
27503 #include <linux/bootmem.h> /* for max_low_pfn */
27504+#include <linux/tboot.h>
27505
27506 #include <asm/cacheflush.h>
27507 #include <asm/e820.h>
27508@@ -16,6 +17,8 @@
27509 #include <asm/tlb.h>
27510 #include <asm/proto.h>
27511 #include <asm/dma.h> /* for MAX_DMA_PFN */
27512+#include <asm/desc.h>
27513+#include <asm/bios_ebda.h>
27514
27515 unsigned long __initdata pgt_buf_start;
27516 unsigned long __meminitdata pgt_buf_end;
27517@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27518 {
27519 int i;
27520 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27521- unsigned long start = 0, good_end;
27522+ unsigned long start = 0x100000, good_end;
27523 phys_addr_t base;
27524
27525 for (i = 0; i < nr_range; i++) {
27526@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27527 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27528 * mmio resources as well as potential bios/acpi data regions.
27529 */
27530+
27531+#ifdef CONFIG_GRKERNSEC_KMEM
27532+static unsigned int ebda_start __read_only;
27533+static unsigned int ebda_end __read_only;
27534+#endif
27535+
27536 int devmem_is_allowed(unsigned long pagenr)
27537 {
27538- if (pagenr < 256)
27539+#ifdef CONFIG_GRKERNSEC_KMEM
27540+ /* allow BDA */
27541+ if (!pagenr)
27542 return 1;
27543+ /* allow EBDA */
27544+ if (pagenr >= ebda_start && pagenr < ebda_end)
27545+ return 1;
27546+ /* if tboot is in use, allow access to its hardcoded serial log range */
27547+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27548+ return 1;
27549+#else
27550+ if (!pagenr)
27551+ return 1;
27552+#ifdef CONFIG_VM86
27553+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27554+ return 1;
27555+#endif
27556+#endif
27557+
27558+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27559+ return 1;
27560+#ifdef CONFIG_GRKERNSEC_KMEM
27561+ /* throw out everything else below 1MB */
27562+ if (pagenr <= 256)
27563+ return 0;
27564+#endif
27565 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27566 return 0;
27567 if (!page_is_ram(pagenr))
27568@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27569 #endif
27570 }
27571
27572+#ifdef CONFIG_GRKERNSEC_KMEM
27573+static inline void gr_init_ebda(void)
27574+{
27575+ unsigned int ebda_addr;
27576+ unsigned int ebda_size = 0;
27577+
27578+ ebda_addr = get_bios_ebda();
27579+ if (ebda_addr) {
27580+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27581+ ebda_size <<= 10;
27582+ }
27583+ if (ebda_addr && ebda_size) {
27584+ ebda_start = ebda_addr >> PAGE_SHIFT;
27585+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27586+ } else {
27587+ ebda_start = 0x9f000 >> PAGE_SHIFT;
27588+ ebda_end = 0xa0000 >> PAGE_SHIFT;
27589+ }
27590+}
27591+#else
27592+static inline void gr_init_ebda(void) { }
27593+#endif
27594+
27595 void free_initmem(void)
27596 {
27597+#ifdef CONFIG_PAX_KERNEXEC
27598+#ifdef CONFIG_X86_32
27599+ /* PaX: limit KERNEL_CS to actual size */
27600+ unsigned long addr, limit;
27601+ struct desc_struct d;
27602+ int cpu;
27603+#else
27604+ pgd_t *pgd;
27605+ pud_t *pud;
27606+ pmd_t *pmd;
27607+ unsigned long addr, end;
27608+#endif
27609+#endif
27610+
27611+ gr_init_ebda();
27612+
27613+#ifdef CONFIG_PAX_KERNEXEC
27614+#ifdef CONFIG_X86_32
27615+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27616+ limit = (limit - 1UL) >> PAGE_SHIFT;
27617+
27618+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27619+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27620+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27621+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27622+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27623+ }
27624+
27625+ /* PaX: make KERNEL_CS read-only */
27626+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27627+ if (!paravirt_enabled())
27628+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27629+/*
27630+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27631+ pgd = pgd_offset_k(addr);
27632+ pud = pud_offset(pgd, addr);
27633+ pmd = pmd_offset(pud, addr);
27634+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27635+ }
27636+*/
27637+#ifdef CONFIG_X86_PAE
27638+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27639+/*
27640+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27641+ pgd = pgd_offset_k(addr);
27642+ pud = pud_offset(pgd, addr);
27643+ pmd = pmd_offset(pud, addr);
27644+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27645+ }
27646+*/
27647+#endif
27648+
27649+#ifdef CONFIG_MODULES
27650+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27651+#endif
27652+
27653+#else
27654+ /* PaX: make kernel code/rodata read-only, rest non-executable */
27655+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27656+ pgd = pgd_offset_k(addr);
27657+ pud = pud_offset(pgd, addr);
27658+ pmd = pmd_offset(pud, addr);
27659+ if (!pmd_present(*pmd))
27660+ continue;
27661+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27662+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27663+ else
27664+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27665+ }
27666+
27667+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27668+ end = addr + KERNEL_IMAGE_SIZE;
27669+ for (; addr < end; addr += PMD_SIZE) {
27670+ pgd = pgd_offset_k(addr);
27671+ pud = pud_offset(pgd, addr);
27672+ pmd = pmd_offset(pud, addr);
27673+ if (!pmd_present(*pmd))
27674+ continue;
27675+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27676+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27677+ }
27678+#endif
27679+
27680+ flush_tlb_all();
27681+#endif
27682+
27683 free_init_pages("unused kernel memory",
27684 (unsigned long)(&__init_begin),
27685 (unsigned long)(&__init_end));
27686diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27687index 745d66b..56bf568 100644
27688--- a/arch/x86/mm/init_32.c
27689+++ b/arch/x86/mm/init_32.c
27690@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27691 }
27692
27693 /*
27694- * Creates a middle page table and puts a pointer to it in the
27695- * given global directory entry. This only returns the gd entry
27696- * in non-PAE compilation mode, since the middle layer is folded.
27697- */
27698-static pmd_t * __init one_md_table_init(pgd_t *pgd)
27699-{
27700- pud_t *pud;
27701- pmd_t *pmd_table;
27702-
27703-#ifdef CONFIG_X86_PAE
27704- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27705- if (after_bootmem)
27706- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27707- else
27708- pmd_table = (pmd_t *)alloc_low_page();
27709- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27710- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27711- pud = pud_offset(pgd, 0);
27712- BUG_ON(pmd_table != pmd_offset(pud, 0));
27713-
27714- return pmd_table;
27715- }
27716-#endif
27717- pud = pud_offset(pgd, 0);
27718- pmd_table = pmd_offset(pud, 0);
27719-
27720- return pmd_table;
27721-}
27722-
27723-/*
27724 * Create a page table and place a pointer to it in a middle page
27725 * directory entry:
27726 */
27727@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27728 page_table = (pte_t *)alloc_low_page();
27729
27730 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27731+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27732+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27733+#else
27734 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27735+#endif
27736 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27737 }
27738
27739 return pte_offset_kernel(pmd, 0);
27740 }
27741
27742+static pmd_t * __init one_md_table_init(pgd_t *pgd)
27743+{
27744+ pud_t *pud;
27745+ pmd_t *pmd_table;
27746+
27747+ pud = pud_offset(pgd, 0);
27748+ pmd_table = pmd_offset(pud, 0);
27749+
27750+ return pmd_table;
27751+}
27752+
27753 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27754 {
27755 int pgd_idx = pgd_index(vaddr);
27756@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27757 int pgd_idx, pmd_idx;
27758 unsigned long vaddr;
27759 pgd_t *pgd;
27760+ pud_t *pud;
27761 pmd_t *pmd;
27762 pte_t *pte = NULL;
27763
27764@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27765 pgd = pgd_base + pgd_idx;
27766
27767 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27768- pmd = one_md_table_init(pgd);
27769- pmd = pmd + pmd_index(vaddr);
27770+ pud = pud_offset(pgd, vaddr);
27771+ pmd = pmd_offset(pud, vaddr);
27772+
27773+#ifdef CONFIG_X86_PAE
27774+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27775+#endif
27776+
27777 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27778 pmd++, pmd_idx++) {
27779 pte = page_table_kmap_check(one_page_table_init(pmd),
27780@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27781 }
27782 }
27783
27784-static inline int is_kernel_text(unsigned long addr)
27785+static inline int is_kernel_text(unsigned long start, unsigned long end)
27786 {
27787- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27788- return 1;
27789- return 0;
27790+ if ((start > ktla_ktva((unsigned long)_etext) ||
27791+ end <= ktla_ktva((unsigned long)_stext)) &&
27792+ (start > ktla_ktva((unsigned long)_einittext) ||
27793+ end <= ktla_ktva((unsigned long)_sinittext)) &&
27794+
27795+#ifdef CONFIG_ACPI_SLEEP
27796+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27797+#endif
27798+
27799+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27800+ return 0;
27801+ return 1;
27802 }
27803
27804 /*
27805@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27806 unsigned long last_map_addr = end;
27807 unsigned long start_pfn, end_pfn;
27808 pgd_t *pgd_base = swapper_pg_dir;
27809- int pgd_idx, pmd_idx, pte_ofs;
27810+ unsigned int pgd_idx, pmd_idx, pte_ofs;
27811 unsigned long pfn;
27812 pgd_t *pgd;
27813+ pud_t *pud;
27814 pmd_t *pmd;
27815 pte_t *pte;
27816 unsigned pages_2m, pages_4k;
27817@@ -280,8 +281,13 @@ repeat:
27818 pfn = start_pfn;
27819 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27820 pgd = pgd_base + pgd_idx;
27821- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27822- pmd = one_md_table_init(pgd);
27823+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27824+ pud = pud_offset(pgd, 0);
27825+ pmd = pmd_offset(pud, 0);
27826+
27827+#ifdef CONFIG_X86_PAE
27828+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27829+#endif
27830
27831 if (pfn >= end_pfn)
27832 continue;
27833@@ -293,14 +299,13 @@ repeat:
27834 #endif
27835 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27836 pmd++, pmd_idx++) {
27837- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27838+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27839
27840 /*
27841 * Map with big pages if possible, otherwise
27842 * create normal page tables:
27843 */
27844 if (use_pse) {
27845- unsigned int addr2;
27846 pgprot_t prot = PAGE_KERNEL_LARGE;
27847 /*
27848 * first pass will use the same initial
27849@@ -310,11 +315,7 @@ repeat:
27850 __pgprot(PTE_IDENT_ATTR |
27851 _PAGE_PSE);
27852
27853- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27854- PAGE_OFFSET + PAGE_SIZE-1;
27855-
27856- if (is_kernel_text(addr) ||
27857- is_kernel_text(addr2))
27858+ if (is_kernel_text(address, address + PMD_SIZE))
27859 prot = PAGE_KERNEL_LARGE_EXEC;
27860
27861 pages_2m++;
27862@@ -331,7 +332,7 @@ repeat:
27863 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27864 pte += pte_ofs;
27865 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27866- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27867+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27868 pgprot_t prot = PAGE_KERNEL;
27869 /*
27870 * first pass will use the same initial
27871@@ -339,7 +340,7 @@ repeat:
27872 */
27873 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27874
27875- if (is_kernel_text(addr))
27876+ if (is_kernel_text(address, address + PAGE_SIZE))
27877 prot = PAGE_KERNEL_EXEC;
27878
27879 pages_4k++;
27880@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27881
27882 pud = pud_offset(pgd, va);
27883 pmd = pmd_offset(pud, va);
27884- if (!pmd_present(*pmd))
27885+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
27886 break;
27887
27888 pte = pte_offset_kernel(pmd, va);
27889@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27890
27891 static void __init pagetable_init(void)
27892 {
27893- pgd_t *pgd_base = swapper_pg_dir;
27894-
27895- permanent_kmaps_init(pgd_base);
27896+ permanent_kmaps_init(swapper_pg_dir);
27897 }
27898
27899-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27900+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27901 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27902
27903 /* user-defined highmem size */
27904@@ -728,6 +727,12 @@ void __init mem_init(void)
27905
27906 pci_iommu_alloc();
27907
27908+#ifdef CONFIG_PAX_PER_CPU_PGD
27909+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27910+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27911+ KERNEL_PGD_PTRS);
27912+#endif
27913+
27914 #ifdef CONFIG_FLATMEM
27915 BUG_ON(!mem_map);
27916 #endif
27917@@ -754,7 +759,7 @@ void __init mem_init(void)
27918 reservedpages++;
27919
27920 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27921- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27922+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27923 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27924
27925 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27926@@ -795,10 +800,10 @@ void __init mem_init(void)
27927 ((unsigned long)&__init_end -
27928 (unsigned long)&__init_begin) >> 10,
27929
27930- (unsigned long)&_etext, (unsigned long)&_edata,
27931- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27932+ (unsigned long)&_sdata, (unsigned long)&_edata,
27933+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27934
27935- (unsigned long)&_text, (unsigned long)&_etext,
27936+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27937 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27938
27939 /*
27940@@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27941 if (!kernel_set_to_readonly)
27942 return;
27943
27944+ start = ktla_ktva(start);
27945 pr_debug("Set kernel text: %lx - %lx for read write\n",
27946 start, start+size);
27947
27948@@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27949 if (!kernel_set_to_readonly)
27950 return;
27951
27952+ start = ktla_ktva(start);
27953 pr_debug("Set kernel text: %lx - %lx for read only\n",
27954 start, start+size);
27955
27956@@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27957 unsigned long start = PFN_ALIGN(_text);
27958 unsigned long size = PFN_ALIGN(_etext) - start;
27959
27960+ start = ktla_ktva(start);
27961 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27962 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27963 size >> 10);
27964diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27965index 75c9a6a..498d677 100644
27966--- a/arch/x86/mm/init_64.c
27967+++ b/arch/x86/mm/init_64.c
27968@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27969 * around without checking the pgd every time.
27970 */
27971
27972-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27973+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27974 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27975
27976 int force_personality32;
27977@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27978
27979 for (address = start; address <= end; address += PGDIR_SIZE) {
27980 const pgd_t *pgd_ref = pgd_offset_k(address);
27981+
27982+#ifdef CONFIG_PAX_PER_CPU_PGD
27983+ unsigned long cpu;
27984+#else
27985 struct page *page;
27986+#endif
27987
27988 if (pgd_none(*pgd_ref))
27989 continue;
27990
27991 spin_lock(&pgd_lock);
27992+
27993+#ifdef CONFIG_PAX_PER_CPU_PGD
27994+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27995+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
27996+#else
27997 list_for_each_entry(page, &pgd_list, lru) {
27998 pgd_t *pgd;
27999 spinlock_t *pgt_lock;
28000@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28001 /* the pgt_lock only for Xen */
28002 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28003 spin_lock(pgt_lock);
28004+#endif
28005
28006 if (pgd_none(*pgd))
28007 set_pgd(pgd, *pgd_ref);
28008@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28009 BUG_ON(pgd_page_vaddr(*pgd)
28010 != pgd_page_vaddr(*pgd_ref));
28011
28012+#ifndef CONFIG_PAX_PER_CPU_PGD
28013 spin_unlock(pgt_lock);
28014+#endif
28015+
28016 }
28017 spin_unlock(&pgd_lock);
28018 }
28019@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28020 {
28021 if (pgd_none(*pgd)) {
28022 pud_t *pud = (pud_t *)spp_getpage();
28023- pgd_populate(&init_mm, pgd, pud);
28024+ pgd_populate_kernel(&init_mm, pgd, pud);
28025 if (pud != pud_offset(pgd, 0))
28026 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28027 pud, pud_offset(pgd, 0));
28028@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28029 {
28030 if (pud_none(*pud)) {
28031 pmd_t *pmd = (pmd_t *) spp_getpage();
28032- pud_populate(&init_mm, pud, pmd);
28033+ pud_populate_kernel(&init_mm, pud, pmd);
28034 if (pmd != pmd_offset(pud, 0))
28035 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28036 pmd, pmd_offset(pud, 0));
28037@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28038 pmd = fill_pmd(pud, vaddr);
28039 pte = fill_pte(pmd, vaddr);
28040
28041+ pax_open_kernel();
28042 set_pte(pte, new_pte);
28043+ pax_close_kernel();
28044
28045 /*
28046 * It's enough to flush this one mapping.
28047@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28048 pgd = pgd_offset_k((unsigned long)__va(phys));
28049 if (pgd_none(*pgd)) {
28050 pud = (pud_t *) spp_getpage();
28051- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28052- _PAGE_USER));
28053+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28054 }
28055 pud = pud_offset(pgd, (unsigned long)__va(phys));
28056 if (pud_none(*pud)) {
28057 pmd = (pmd_t *) spp_getpage();
28058- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28059- _PAGE_USER));
28060+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28061 }
28062 pmd = pmd_offset(pud, phys);
28063 BUG_ON(!pmd_none(*pmd));
28064@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
28065 if (pfn >= pgt_buf_top)
28066 panic("alloc_low_page: ran out of memory");
28067
28068- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28069+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
28070 clear_page(adr);
28071 *phys = pfn * PAGE_SIZE;
28072 return adr;
28073@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
28074
28075 phys = __pa(virt);
28076 left = phys & (PAGE_SIZE - 1);
28077- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28078+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
28079 adr = (void *)(((unsigned long)adr) | left);
28080
28081 return adr;
28082@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28083 unmap_low_page(pmd);
28084
28085 spin_lock(&init_mm.page_table_lock);
28086- pud_populate(&init_mm, pud, __va(pmd_phys));
28087+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
28088 spin_unlock(&init_mm.page_table_lock);
28089 }
28090 __flush_tlb_all();
28091@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
28092 unmap_low_page(pud);
28093
28094 spin_lock(&init_mm.page_table_lock);
28095- pgd_populate(&init_mm, pgd, __va(pud_phys));
28096+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
28097 spin_unlock(&init_mm.page_table_lock);
28098 pgd_changed = true;
28099 }
28100@@ -693,6 +707,12 @@ void __init mem_init(void)
28101
28102 pci_iommu_alloc();
28103
28104+#ifdef CONFIG_PAX_PER_CPU_PGD
28105+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28106+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28107+ KERNEL_PGD_PTRS);
28108+#endif
28109+
28110 /* clear_bss() already clear the empty_zero_page */
28111
28112 reservedpages = 0;
28113@@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
28114 static struct vm_area_struct gate_vma = {
28115 .vm_start = VSYSCALL_START,
28116 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28117- .vm_page_prot = PAGE_READONLY_EXEC,
28118- .vm_flags = VM_READ | VM_EXEC
28119+ .vm_page_prot = PAGE_READONLY,
28120+ .vm_flags = VM_READ
28121 };
28122
28123 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28124@@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
28125
28126 const char *arch_vma_name(struct vm_area_struct *vma)
28127 {
28128- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28129+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28130 return "[vdso]";
28131 if (vma == &gate_vma)
28132 return "[vsyscall]";
28133diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28134index 7b179b4..6bd1777 100644
28135--- a/arch/x86/mm/iomap_32.c
28136+++ b/arch/x86/mm/iomap_32.c
28137@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28138 type = kmap_atomic_idx_push();
28139 idx = type + KM_TYPE_NR * smp_processor_id();
28140 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28141+
28142+ pax_open_kernel();
28143 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28144+ pax_close_kernel();
28145+
28146 arch_flush_lazy_mmu_mode();
28147
28148 return (void *)vaddr;
28149diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28150index 78fe3f1..2f9433c 100644
28151--- a/arch/x86/mm/ioremap.c
28152+++ b/arch/x86/mm/ioremap.c
28153@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28154 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28155 int is_ram = page_is_ram(pfn);
28156
28157- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28158+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28159 return NULL;
28160 WARN_ON_ONCE(is_ram);
28161 }
28162@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28163 *
28164 * Caller must ensure there is only one unmapping for the same pointer.
28165 */
28166-void iounmap(volatile void __iomem *addr)
28167+void iounmap(const volatile void __iomem *addr)
28168 {
28169 struct vm_struct *p, *o;
28170
28171@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28172
28173 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28174 if (page_is_ram(start >> PAGE_SHIFT))
28175+#ifdef CONFIG_HIGHMEM
28176+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28177+#endif
28178 return __va(phys);
28179
28180 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28181@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
28182 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28183
28184 static __initdata int after_paging_init;
28185-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28186+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28187
28188 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28189 {
28190@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
28191 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28192
28193 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28194- memset(bm_pte, 0, sizeof(bm_pte));
28195- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28196+ pmd_populate_user(&init_mm, pmd, bm_pte);
28197
28198 /*
28199 * The boot-ioremap range spans multiple pmds, for which
28200diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28201index d87dd6d..bf3fa66 100644
28202--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28203+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28204@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28205 * memory (e.g. tracked pages)? For now, we need this to avoid
28206 * invoking kmemcheck for PnP BIOS calls.
28207 */
28208- if (regs->flags & X86_VM_MASK)
28209+ if (v8086_mode(regs))
28210 return false;
28211- if (regs->cs != __KERNEL_CS)
28212+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28213 return false;
28214
28215 pte = kmemcheck_pte_lookup(address);
28216diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28217index 845df68..1d8d29f 100644
28218--- a/arch/x86/mm/mmap.c
28219+++ b/arch/x86/mm/mmap.c
28220@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28221 * Leave an at least ~128 MB hole with possible stack randomization.
28222 */
28223 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28224-#define MAX_GAP (TASK_SIZE/6*5)
28225+#define MAX_GAP (pax_task_size/6*5)
28226
28227 static int mmap_is_legacy(void)
28228 {
28229@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28230 return rnd << PAGE_SHIFT;
28231 }
28232
28233-static unsigned long mmap_base(void)
28234+static unsigned long mmap_base(struct mm_struct *mm)
28235 {
28236 unsigned long gap = rlimit(RLIMIT_STACK);
28237+ unsigned long pax_task_size = TASK_SIZE;
28238+
28239+#ifdef CONFIG_PAX_SEGMEXEC
28240+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28241+ pax_task_size = SEGMEXEC_TASK_SIZE;
28242+#endif
28243
28244 if (gap < MIN_GAP)
28245 gap = MIN_GAP;
28246 else if (gap > MAX_GAP)
28247 gap = MAX_GAP;
28248
28249- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28250+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28251 }
28252
28253 /*
28254 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28255 * does, but not when emulating X86_32
28256 */
28257-static unsigned long mmap_legacy_base(void)
28258+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28259 {
28260- if (mmap_is_ia32())
28261+ if (mmap_is_ia32()) {
28262+
28263+#ifdef CONFIG_PAX_SEGMEXEC
28264+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28265+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28266+ else
28267+#endif
28268+
28269 return TASK_UNMAPPED_BASE;
28270- else
28271+ } else
28272 return TASK_UNMAPPED_BASE + mmap_rnd();
28273 }
28274
28275@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28276 void arch_pick_mmap_layout(struct mm_struct *mm)
28277 {
28278 if (mmap_is_legacy()) {
28279- mm->mmap_base = mmap_legacy_base();
28280+ mm->mmap_base = mmap_legacy_base(mm);
28281+
28282+#ifdef CONFIG_PAX_RANDMMAP
28283+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28284+ mm->mmap_base += mm->delta_mmap;
28285+#endif
28286+
28287 mm->get_unmapped_area = arch_get_unmapped_area;
28288 mm->unmap_area = arch_unmap_area;
28289 } else {
28290- mm->mmap_base = mmap_base();
28291+ mm->mmap_base = mmap_base(mm);
28292+
28293+#ifdef CONFIG_PAX_RANDMMAP
28294+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28295+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28296+#endif
28297+
28298 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28299 mm->unmap_area = arch_unmap_area_topdown;
28300 }
28301diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28302index dc0b727..f612039 100644
28303--- a/arch/x86/mm/mmio-mod.c
28304+++ b/arch/x86/mm/mmio-mod.c
28305@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28306 break;
28307 default:
28308 {
28309- unsigned char *ip = (unsigned char *)instptr;
28310+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28311 my_trace->opcode = MMIO_UNKNOWN_OP;
28312 my_trace->width = 0;
28313 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28314@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28315 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28316 void __iomem *addr)
28317 {
28318- static atomic_t next_id;
28319+ static atomic_unchecked_t next_id;
28320 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28321 /* These are page-unaligned. */
28322 struct mmiotrace_map map = {
28323@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28324 .private = trace
28325 },
28326 .phys = offset,
28327- .id = atomic_inc_return(&next_id)
28328+ .id = atomic_inc_return_unchecked(&next_id)
28329 };
28330 map.map_id = trace->id;
28331
28332@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28333 ioremap_trace_core(offset, size, addr);
28334 }
28335
28336-static void iounmap_trace_core(volatile void __iomem *addr)
28337+static void iounmap_trace_core(const volatile void __iomem *addr)
28338 {
28339 struct mmiotrace_map map = {
28340 .phys = 0,
28341@@ -328,7 +328,7 @@ not_enabled:
28342 }
28343 }
28344
28345-void mmiotrace_iounmap(volatile void __iomem *addr)
28346+void mmiotrace_iounmap(const volatile void __iomem *addr)
28347 {
28348 might_sleep();
28349 if (is_enabled()) /* recheck and proper locking in *_core() */
28350diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28351index b008656..773eac2 100644
28352--- a/arch/x86/mm/pageattr-test.c
28353+++ b/arch/x86/mm/pageattr-test.c
28354@@ -36,7 +36,7 @@ enum {
28355
28356 static int pte_testbit(pte_t pte)
28357 {
28358- return pte_flags(pte) & _PAGE_UNUSED1;
28359+ return pte_flags(pte) & _PAGE_CPA_TEST;
28360 }
28361
28362 struct split_state {
28363diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28364index a718e0d..77419bc 100644
28365--- a/arch/x86/mm/pageattr.c
28366+++ b/arch/x86/mm/pageattr.c
28367@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28368 */
28369 #ifdef CONFIG_PCI_BIOS
28370 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28371- pgprot_val(forbidden) |= _PAGE_NX;
28372+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28373 #endif
28374
28375 /*
28376@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28377 * Does not cover __inittext since that is gone later on. On
28378 * 64bit we do not enforce !NX on the low mapping
28379 */
28380- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28381- pgprot_val(forbidden) |= _PAGE_NX;
28382+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28383+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28384
28385+#ifdef CONFIG_DEBUG_RODATA
28386 /*
28387 * The .rodata section needs to be read-only. Using the pfn
28388 * catches all aliases.
28389@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28390 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28391 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28392 pgprot_val(forbidden) |= _PAGE_RW;
28393+#endif
28394
28395 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28396 /*
28397@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28398 }
28399 #endif
28400
28401+#ifdef CONFIG_PAX_KERNEXEC
28402+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28403+ pgprot_val(forbidden) |= _PAGE_RW;
28404+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28405+ }
28406+#endif
28407+
28408 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28409
28410 return prot;
28411@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28412 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28413 {
28414 /* change init_mm */
28415+ pax_open_kernel();
28416 set_pte_atomic(kpte, pte);
28417+
28418 #ifdef CONFIG_X86_32
28419 if (!SHARED_KERNEL_PMD) {
28420+
28421+#ifdef CONFIG_PAX_PER_CPU_PGD
28422+ unsigned long cpu;
28423+#else
28424 struct page *page;
28425+#endif
28426
28427+#ifdef CONFIG_PAX_PER_CPU_PGD
28428+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28429+ pgd_t *pgd = get_cpu_pgd(cpu);
28430+#else
28431 list_for_each_entry(page, &pgd_list, lru) {
28432- pgd_t *pgd;
28433+ pgd_t *pgd = (pgd_t *)page_address(page);
28434+#endif
28435+
28436 pud_t *pud;
28437 pmd_t *pmd;
28438
28439- pgd = (pgd_t *)page_address(page) + pgd_index(address);
28440+ pgd += pgd_index(address);
28441 pud = pud_offset(pgd, address);
28442 pmd = pmd_offset(pud, address);
28443 set_pte_atomic((pte_t *)pmd, pte);
28444 }
28445 }
28446 #endif
28447+ pax_close_kernel();
28448 }
28449
28450 static int
28451diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28452index 0eb572e..92f5c1e 100644
28453--- a/arch/x86/mm/pat.c
28454+++ b/arch/x86/mm/pat.c
28455@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28456
28457 if (!entry) {
28458 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28459- current->comm, current->pid, start, end - 1);
28460+ current->comm, task_pid_nr(current), start, end - 1);
28461 return -EINVAL;
28462 }
28463
28464@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28465
28466 while (cursor < to) {
28467 if (!devmem_is_allowed(pfn)) {
28468- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28469- current->comm, from, to - 1);
28470+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28471+ current->comm, from, to - 1, cursor);
28472 return 0;
28473 }
28474 cursor += PAGE_SIZE;
28475@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28476 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28477 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28478 "for [mem %#010Lx-%#010Lx]\n",
28479- current->comm, current->pid,
28480+ current->comm, task_pid_nr(current),
28481 cattr_name(flags),
28482 base, (unsigned long long)(base + size-1));
28483 return -EINVAL;
28484@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28485 flags = lookup_memtype(paddr);
28486 if (want_flags != flags) {
28487 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28488- current->comm, current->pid,
28489+ current->comm, task_pid_nr(current),
28490 cattr_name(want_flags),
28491 (unsigned long long)paddr,
28492 (unsigned long long)(paddr + size - 1),
28493@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28494 free_memtype(paddr, paddr + size);
28495 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28496 " for [mem %#010Lx-%#010Lx], got %s\n",
28497- current->comm, current->pid,
28498+ current->comm, task_pid_nr(current),
28499 cattr_name(want_flags),
28500 (unsigned long long)paddr,
28501 (unsigned long long)(paddr + size - 1),
28502diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28503index 9f0614d..92ae64a 100644
28504--- a/arch/x86/mm/pf_in.c
28505+++ b/arch/x86/mm/pf_in.c
28506@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28507 int i;
28508 enum reason_type rv = OTHERS;
28509
28510- p = (unsigned char *)ins_addr;
28511+ p = (unsigned char *)ktla_ktva(ins_addr);
28512 p += skip_prefix(p, &prf);
28513 p += get_opcode(p, &opcode);
28514
28515@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28516 struct prefix_bits prf;
28517 int i;
28518
28519- p = (unsigned char *)ins_addr;
28520+ p = (unsigned char *)ktla_ktva(ins_addr);
28521 p += skip_prefix(p, &prf);
28522 p += get_opcode(p, &opcode);
28523
28524@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28525 struct prefix_bits prf;
28526 int i;
28527
28528- p = (unsigned char *)ins_addr;
28529+ p = (unsigned char *)ktla_ktva(ins_addr);
28530 p += skip_prefix(p, &prf);
28531 p += get_opcode(p, &opcode);
28532
28533@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28534 struct prefix_bits prf;
28535 int i;
28536
28537- p = (unsigned char *)ins_addr;
28538+ p = (unsigned char *)ktla_ktva(ins_addr);
28539 p += skip_prefix(p, &prf);
28540 p += get_opcode(p, &opcode);
28541 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28542@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28543 struct prefix_bits prf;
28544 int i;
28545
28546- p = (unsigned char *)ins_addr;
28547+ p = (unsigned char *)ktla_ktva(ins_addr);
28548 p += skip_prefix(p, &prf);
28549 p += get_opcode(p, &opcode);
28550 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28551diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28552index e27fbf8..8b56dc9 100644
28553--- a/arch/x86/mm/pgtable.c
28554+++ b/arch/x86/mm/pgtable.c
28555@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28556 list_del(&page->lru);
28557 }
28558
28559-#define UNSHARED_PTRS_PER_PGD \
28560- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28561+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28562+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28563
28564+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28565+{
28566+ unsigned int count = USER_PGD_PTRS;
28567
28568+ while (count--)
28569+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28570+}
28571+#endif
28572+
28573+#ifdef CONFIG_PAX_PER_CPU_PGD
28574+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28575+{
28576+ unsigned int count = USER_PGD_PTRS;
28577+
28578+ while (count--) {
28579+ pgd_t pgd;
28580+
28581+#ifdef CONFIG_X86_64
28582+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28583+#else
28584+ pgd = *src++;
28585+#endif
28586+
28587+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28588+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28589+#endif
28590+
28591+ *dst++ = pgd;
28592+ }
28593+
28594+}
28595+#endif
28596+
28597+#ifdef CONFIG_X86_64
28598+#define pxd_t pud_t
28599+#define pyd_t pgd_t
28600+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28601+#define pxd_free(mm, pud) pud_free((mm), (pud))
28602+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28603+#define pyd_offset(mm, address) pgd_offset((mm), (address))
28604+#define PYD_SIZE PGDIR_SIZE
28605+#else
28606+#define pxd_t pmd_t
28607+#define pyd_t pud_t
28608+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28609+#define pxd_free(mm, pud) pmd_free((mm), (pud))
28610+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28611+#define pyd_offset(mm, address) pud_offset((mm), (address))
28612+#define PYD_SIZE PUD_SIZE
28613+#endif
28614+
28615+#ifdef CONFIG_PAX_PER_CPU_PGD
28616+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28617+static inline void pgd_dtor(pgd_t *pgd) {}
28618+#else
28619 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28620 {
28621 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28622@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28623 pgd_list_del(pgd);
28624 spin_unlock(&pgd_lock);
28625 }
28626+#endif
28627
28628 /*
28629 * List of all pgd's needed for non-PAE so it can invalidate entries
28630@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28631 * -- nyc
28632 */
28633
28634-#ifdef CONFIG_X86_PAE
28635+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28636 /*
28637 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28638 * updating the top-level pagetable entries to guarantee the
28639@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28640 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28641 * and initialize the kernel pmds here.
28642 */
28643-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28644+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28645
28646 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28647 {
28648@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28649 */
28650 flush_tlb_mm(mm);
28651 }
28652+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28653+#define PREALLOCATED_PXDS USER_PGD_PTRS
28654 #else /* !CONFIG_X86_PAE */
28655
28656 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28657-#define PREALLOCATED_PMDS 0
28658+#define PREALLOCATED_PXDS 0
28659
28660 #endif /* CONFIG_X86_PAE */
28661
28662-static void free_pmds(pmd_t *pmds[])
28663+static void free_pxds(pxd_t *pxds[])
28664 {
28665 int i;
28666
28667- for(i = 0; i < PREALLOCATED_PMDS; i++)
28668- if (pmds[i])
28669- free_page((unsigned long)pmds[i]);
28670+ for(i = 0; i < PREALLOCATED_PXDS; i++)
28671+ if (pxds[i])
28672+ free_page((unsigned long)pxds[i]);
28673 }
28674
28675-static int preallocate_pmds(pmd_t *pmds[])
28676+static int preallocate_pxds(pxd_t *pxds[])
28677 {
28678 int i;
28679 bool failed = false;
28680
28681- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28682- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28683- if (pmd == NULL)
28684+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28685+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28686+ if (pxd == NULL)
28687 failed = true;
28688- pmds[i] = pmd;
28689+ pxds[i] = pxd;
28690 }
28691
28692 if (failed) {
28693- free_pmds(pmds);
28694+ free_pxds(pxds);
28695 return -ENOMEM;
28696 }
28697
28698@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28699 * preallocate which never got a corresponding vma will need to be
28700 * freed manually.
28701 */
28702-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28703+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28704 {
28705 int i;
28706
28707- for(i = 0; i < PREALLOCATED_PMDS; i++) {
28708+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
28709 pgd_t pgd = pgdp[i];
28710
28711 if (pgd_val(pgd) != 0) {
28712- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28713+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28714
28715- pgdp[i] = native_make_pgd(0);
28716+ set_pgd(pgdp + i, native_make_pgd(0));
28717
28718- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28719- pmd_free(mm, pmd);
28720+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28721+ pxd_free(mm, pxd);
28722 }
28723 }
28724 }
28725
28726-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28727+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28728 {
28729- pud_t *pud;
28730+ pyd_t *pyd;
28731 unsigned long addr;
28732 int i;
28733
28734- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28735+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28736 return;
28737
28738- pud = pud_offset(pgd, 0);
28739+#ifdef CONFIG_X86_64
28740+ pyd = pyd_offset(mm, 0L);
28741+#else
28742+ pyd = pyd_offset(pgd, 0L);
28743+#endif
28744
28745- for (addr = i = 0; i < PREALLOCATED_PMDS;
28746- i++, pud++, addr += PUD_SIZE) {
28747- pmd_t *pmd = pmds[i];
28748+ for (addr = i = 0; i < PREALLOCATED_PXDS;
28749+ i++, pyd++, addr += PYD_SIZE) {
28750+ pxd_t *pxd = pxds[i];
28751
28752 if (i >= KERNEL_PGD_BOUNDARY)
28753- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28754- sizeof(pmd_t) * PTRS_PER_PMD);
28755+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28756+ sizeof(pxd_t) * PTRS_PER_PMD);
28757
28758- pud_populate(mm, pud, pmd);
28759+ pyd_populate(mm, pyd, pxd);
28760 }
28761 }
28762
28763 pgd_t *pgd_alloc(struct mm_struct *mm)
28764 {
28765 pgd_t *pgd;
28766- pmd_t *pmds[PREALLOCATED_PMDS];
28767+ pxd_t *pxds[PREALLOCATED_PXDS];
28768
28769 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28770
28771@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28772
28773 mm->pgd = pgd;
28774
28775- if (preallocate_pmds(pmds) != 0)
28776+ if (preallocate_pxds(pxds) != 0)
28777 goto out_free_pgd;
28778
28779 if (paravirt_pgd_alloc(mm) != 0)
28780- goto out_free_pmds;
28781+ goto out_free_pxds;
28782
28783 /*
28784 * Make sure that pre-populating the pmds is atomic with
28785@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28786 spin_lock(&pgd_lock);
28787
28788 pgd_ctor(mm, pgd);
28789- pgd_prepopulate_pmd(mm, pgd, pmds);
28790+ pgd_prepopulate_pxd(mm, pgd, pxds);
28791
28792 spin_unlock(&pgd_lock);
28793
28794 return pgd;
28795
28796-out_free_pmds:
28797- free_pmds(pmds);
28798+out_free_pxds:
28799+ free_pxds(pxds);
28800 out_free_pgd:
28801 free_page((unsigned long)pgd);
28802 out:
28803@@ -295,7 +356,7 @@ out:
28804
28805 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28806 {
28807- pgd_mop_up_pmds(mm, pgd);
28808+ pgd_mop_up_pxds(mm, pgd);
28809 pgd_dtor(pgd);
28810 paravirt_pgd_free(mm, pgd);
28811 free_page((unsigned long)pgd);
28812diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28813index a69bcb8..19068ab 100644
28814--- a/arch/x86/mm/pgtable_32.c
28815+++ b/arch/x86/mm/pgtable_32.c
28816@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28817 return;
28818 }
28819 pte = pte_offset_kernel(pmd, vaddr);
28820+
28821+ pax_open_kernel();
28822 if (pte_val(pteval))
28823 set_pte_at(&init_mm, vaddr, pte, pteval);
28824 else
28825 pte_clear(&init_mm, vaddr, pte);
28826+ pax_close_kernel();
28827
28828 /*
28829 * It's enough to flush this one mapping.
28830diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28831index 410531d..0f16030 100644
28832--- a/arch/x86/mm/setup_nx.c
28833+++ b/arch/x86/mm/setup_nx.c
28834@@ -5,8 +5,10 @@
28835 #include <asm/pgtable.h>
28836 #include <asm/proto.h>
28837
28838+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28839 static int disable_nx __cpuinitdata;
28840
28841+#ifndef CONFIG_PAX_PAGEEXEC
28842 /*
28843 * noexec = on|off
28844 *
28845@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28846 return 0;
28847 }
28848 early_param("noexec", noexec_setup);
28849+#endif
28850+
28851+#endif
28852
28853 void __cpuinit x86_configure_nx(void)
28854 {
28855+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28856 if (cpu_has_nx && !disable_nx)
28857 __supported_pte_mask |= _PAGE_NX;
28858 else
28859+#endif
28860 __supported_pte_mask &= ~_PAGE_NX;
28861 }
28862
28863diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28864index 13a6b29..c2fff23 100644
28865--- a/arch/x86/mm/tlb.c
28866+++ b/arch/x86/mm/tlb.c
28867@@ -48,7 +48,11 @@ void leave_mm(int cpu)
28868 BUG();
28869 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28870 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28871+
28872+#ifndef CONFIG_PAX_PER_CPU_PGD
28873 load_cr3(swapper_pg_dir);
28874+#endif
28875+
28876 }
28877 }
28878 EXPORT_SYMBOL_GPL(leave_mm);
28879diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28880index 877b9a1..a8ecf42 100644
28881--- a/arch/x86/net/bpf_jit.S
28882+++ b/arch/x86/net/bpf_jit.S
28883@@ -9,6 +9,7 @@
28884 */
28885 #include <linux/linkage.h>
28886 #include <asm/dwarf2.h>
28887+#include <asm/alternative-asm.h>
28888
28889 /*
28890 * Calling convention :
28891@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28892 jle bpf_slow_path_word
28893 mov (SKBDATA,%rsi),%eax
28894 bswap %eax /* ntohl() */
28895+ pax_force_retaddr
28896 ret
28897
28898 sk_load_half:
28899@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28900 jle bpf_slow_path_half
28901 movzwl (SKBDATA,%rsi),%eax
28902 rol $8,%ax # ntohs()
28903+ pax_force_retaddr
28904 ret
28905
28906 sk_load_byte:
28907@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28908 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28909 jle bpf_slow_path_byte
28910 movzbl (SKBDATA,%rsi),%eax
28911+ pax_force_retaddr
28912 ret
28913
28914 /**
28915@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28916 movzbl (SKBDATA,%rsi),%ebx
28917 and $15,%bl
28918 shl $2,%bl
28919+ pax_force_retaddr
28920 ret
28921
28922 /* rsi contains offset and can be scratched */
28923@@ -109,6 +114,7 @@ bpf_slow_path_word:
28924 js bpf_error
28925 mov -12(%rbp),%eax
28926 bswap %eax
28927+ pax_force_retaddr
28928 ret
28929
28930 bpf_slow_path_half:
28931@@ -117,12 +123,14 @@ bpf_slow_path_half:
28932 mov -12(%rbp),%ax
28933 rol $8,%ax
28934 movzwl %ax,%eax
28935+ pax_force_retaddr
28936 ret
28937
28938 bpf_slow_path_byte:
28939 bpf_slow_path_common(1)
28940 js bpf_error
28941 movzbl -12(%rbp),%eax
28942+ pax_force_retaddr
28943 ret
28944
28945 bpf_slow_path_byte_msh:
28946@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28947 and $15,%al
28948 shl $2,%al
28949 xchg %eax,%ebx
28950+ pax_force_retaddr
28951 ret
28952
28953 #define sk_negative_common(SIZE) \
28954@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28955 sk_negative_common(4)
28956 mov (%rax), %eax
28957 bswap %eax
28958+ pax_force_retaddr
28959 ret
28960
28961 bpf_slow_path_half_neg:
28962@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28963 mov (%rax),%ax
28964 rol $8,%ax
28965 movzwl %ax,%eax
28966+ pax_force_retaddr
28967 ret
28968
28969 bpf_slow_path_byte_neg:
28970@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28971 .globl sk_load_byte_negative_offset
28972 sk_negative_common(1)
28973 movzbl (%rax), %eax
28974+ pax_force_retaddr
28975 ret
28976
28977 bpf_slow_path_byte_msh_neg:
28978@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28979 and $15,%al
28980 shl $2,%al
28981 xchg %eax,%ebx
28982+ pax_force_retaddr
28983 ret
28984
28985 bpf_error:
28986@@ -197,4 +210,5 @@ bpf_error:
28987 xor %eax,%eax
28988 mov -8(%rbp),%rbx
28989 leaveq
28990+ pax_force_retaddr
28991 ret
28992diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28993index d11a470..3f9adff3 100644
28994--- a/arch/x86/net/bpf_jit_comp.c
28995+++ b/arch/x86/net/bpf_jit_comp.c
28996@@ -12,6 +12,7 @@
28997 #include <linux/netdevice.h>
28998 #include <linux/filter.h>
28999 #include <linux/if_vlan.h>
29000+#include <linux/random.h>
29001
29002 /*
29003 * Conventions :
29004@@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29005 return ptr + len;
29006 }
29007
29008+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29009+#define MAX_INSTR_CODE_SIZE 96
29010+#else
29011+#define MAX_INSTR_CODE_SIZE 64
29012+#endif
29013+
29014 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29015
29016 #define EMIT1(b1) EMIT(b1, 1)
29017 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29018 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29019 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29020+
29021+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29022+/* original constant will appear in ecx */
29023+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29024+do { \
29025+ /* mov ecx, randkey */ \
29026+ EMIT1(0xb9); \
29027+ EMIT(_key, 4); \
29028+ /* xor ecx, randkey ^ off */ \
29029+ EMIT2(0x81, 0xf1); \
29030+ EMIT((_key) ^ (_off), 4); \
29031+} while (0)
29032+
29033+#define EMIT1_off32(b1, _off) \
29034+do { \
29035+ switch (b1) { \
29036+ case 0x05: /* add eax, imm32 */ \
29037+ case 0x2d: /* sub eax, imm32 */ \
29038+ case 0x25: /* and eax, imm32 */ \
29039+ case 0x0d: /* or eax, imm32 */ \
29040+ case 0xb8: /* mov eax, imm32 */ \
29041+ case 0x3d: /* cmp eax, imm32 */ \
29042+ case 0xa9: /* test eax, imm32 */ \
29043+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29044+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29045+ break; \
29046+ case 0xbb: /* mov ebx, imm32 */ \
29047+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29048+ /* mov ebx, ecx */ \
29049+ EMIT2(0x89, 0xcb); \
29050+ break; \
29051+ case 0xbe: /* mov esi, imm32 */ \
29052+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29053+ /* mov esi, ecx */ \
29054+ EMIT2(0x89, 0xce); \
29055+ break; \
29056+ case 0xe9: /* jmp rel imm32 */ \
29057+ EMIT1(b1); \
29058+ EMIT(_off, 4); \
29059+ /* prevent fall-through, we're not called if off = 0 */ \
29060+ EMIT(0xcccccccc, 4); \
29061+ EMIT(0xcccccccc, 4); \
29062+ break; \
29063+ default: \
29064+ EMIT1(b1); \
29065+ EMIT(_off, 4); \
29066+ } \
29067+} while (0)
29068+
29069+#define EMIT2_off32(b1, b2, _off) \
29070+do { \
29071+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29072+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29073+ EMIT(randkey, 4); \
29074+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29075+ EMIT((_off) - randkey, 4); \
29076+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29077+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29078+ /* imul eax, ecx */ \
29079+ EMIT3(0x0f, 0xaf, 0xc1); \
29080+ } else { \
29081+ EMIT2(b1, b2); \
29082+ EMIT(_off, 4); \
29083+ } \
29084+} while (0)
29085+#else
29086 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29087+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29088+#endif
29089
29090 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29091 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29092@@ -90,6 +165,24 @@ do { \
29093 #define X86_JBE 0x76
29094 #define X86_JA 0x77
29095
29096+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29097+#define APPEND_FLOW_VERIFY() \
29098+do { \
29099+ /* mov ecx, randkey */ \
29100+ EMIT1(0xb9); \
29101+ EMIT(randkey, 4); \
29102+ /* cmp ecx, randkey */ \
29103+ EMIT2(0x81, 0xf9); \
29104+ EMIT(randkey, 4); \
29105+ /* jz after 8 int 3s */ \
29106+ EMIT2(0x74, 0x08); \
29107+ EMIT(0xcccccccc, 4); \
29108+ EMIT(0xcccccccc, 4); \
29109+} while (0)
29110+#else
29111+#define APPEND_FLOW_VERIFY() do { } while (0)
29112+#endif
29113+
29114 #define EMIT_COND_JMP(op, offset) \
29115 do { \
29116 if (is_near(offset)) \
29117@@ -97,6 +190,7 @@ do { \
29118 else { \
29119 EMIT2(0x0f, op + 0x10); \
29120 EMIT(offset, 4); /* jxx .+off32 */ \
29121+ APPEND_FLOW_VERIFY(); \
29122 } \
29123 } while (0)
29124
29125@@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
29126 set_fs(old_fs);
29127 }
29128
29129+struct bpf_jit_work {
29130+ struct work_struct work;
29131+ void *image;
29132+};
29133+
29134 #define CHOOSE_LOAD_FUNC(K, func) \
29135 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29136
29137 void bpf_jit_compile(struct sk_filter *fp)
29138 {
29139- u8 temp[64];
29140+ u8 temp[MAX_INSTR_CODE_SIZE];
29141 u8 *prog;
29142 unsigned int proglen, oldproglen = 0;
29143 int ilen, i;
29144@@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29145 unsigned int *addrs;
29146 const struct sock_filter *filter = fp->insns;
29147 int flen = fp->len;
29148+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29149+ unsigned int randkey;
29150+#endif
29151
29152 if (!bpf_jit_enable)
29153 return;
29154@@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29155 if (addrs == NULL)
29156 return;
29157
29158+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29159+ if (!fp->work)
29160+ goto out;
29161+
29162+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29163+ randkey = get_random_int();
29164+#endif
29165+
29166 /* Before first pass, make a rough estimation of addrs[]
29167- * each bpf instruction is translated to less than 64 bytes
29168+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29169 */
29170 for (proglen = 0, i = 0; i < flen; i++) {
29171- proglen += 64;
29172+ proglen += MAX_INSTR_CODE_SIZE;
29173 addrs[i] = proglen;
29174 }
29175 cleanup_addr = proglen; /* epilogue address */
29176@@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29177 case BPF_S_ALU_MUL_K: /* A *= K */
29178 if (is_imm8(K))
29179 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29180- else {
29181- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29182- EMIT(K, 4);
29183- }
29184+ else
29185+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29186 break;
29187 case BPF_S_ALU_DIV_X: /* A /= X; */
29188 seen |= SEEN_XREG;
29189@@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29190 break;
29191 case BPF_S_ALU_MOD_K: /* A %= K; */
29192 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29193+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29194+ DILUTE_CONST_SEQUENCE(K, randkey);
29195+#else
29196 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29197+#endif
29198 EMIT2(0xf7, 0xf1); /* div %ecx */
29199 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29200 break;
29201 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29202+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29203+ DILUTE_CONST_SEQUENCE(K, randkey);
29204+ // imul rax, rcx
29205+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29206+#else
29207 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29208 EMIT(K, 4);
29209+#endif
29210 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29211 break;
29212 case BPF_S_ALU_AND_X:
29213@@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29214 if (is_imm8(K)) {
29215 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29216 } else {
29217- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29218- EMIT(K, 4);
29219+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29220 }
29221 } else {
29222 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29223@@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29224 break;
29225 default:
29226 /* hmm, too complex filter, give up with jit compiler */
29227- goto out;
29228+ goto error;
29229 }
29230 ilen = prog - temp;
29231 if (image) {
29232 if (unlikely(proglen + ilen > oldproglen)) {
29233 pr_err("bpb_jit_compile fatal error\n");
29234- kfree(addrs);
29235- module_free(NULL, image);
29236- return;
29237+ module_free_exec(NULL, image);
29238+ goto error;
29239 }
29240+ pax_open_kernel();
29241 memcpy(image + proglen, temp, ilen);
29242+ pax_close_kernel();
29243 }
29244 proglen += ilen;
29245 addrs[i] = proglen;
29246@@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29247 break;
29248 }
29249 if (proglen == oldproglen) {
29250- image = module_alloc(max_t(unsigned int,
29251- proglen,
29252- sizeof(struct work_struct)));
29253+ image = module_alloc_exec(proglen);
29254 if (!image)
29255- goto out;
29256+ goto error;
29257 }
29258 oldproglen = proglen;
29259 }
29260@@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29261 bpf_flush_icache(image, image + proglen);
29262
29263 fp->bpf_func = (void *)image;
29264- }
29265+ } else
29266+error:
29267+ kfree(fp->work);
29268+
29269 out:
29270 kfree(addrs);
29271 return;
29272@@ -707,18 +826,20 @@ out:
29273
29274 static void jit_free_defer(struct work_struct *arg)
29275 {
29276- module_free(NULL, arg);
29277+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29278+ kfree(arg);
29279 }
29280
29281 /* run from softirq, we must use a work_struct to call
29282- * module_free() from process context
29283+ * module_free_exec() from process context
29284 */
29285 void bpf_jit_free(struct sk_filter *fp)
29286 {
29287 if (fp->bpf_func != sk_run_filter) {
29288- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29289+ struct work_struct *work = &fp->work->work;
29290
29291 INIT_WORK(work, jit_free_defer);
29292+ fp->work->image = fp->bpf_func;
29293 schedule_work(work);
29294 }
29295 }
29296diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29297index d6aa6e8..266395a 100644
29298--- a/arch/x86/oprofile/backtrace.c
29299+++ b/arch/x86/oprofile/backtrace.c
29300@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29301 struct stack_frame_ia32 *fp;
29302 unsigned long bytes;
29303
29304- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29305+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29306 if (bytes != sizeof(bufhead))
29307 return NULL;
29308
29309- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29310+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29311
29312 oprofile_add_trace(bufhead[0].return_address);
29313
29314@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29315 struct stack_frame bufhead[2];
29316 unsigned long bytes;
29317
29318- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29319+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29320 if (bytes != sizeof(bufhead))
29321 return NULL;
29322
29323@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29324 {
29325 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29326
29327- if (!user_mode_vm(regs)) {
29328+ if (!user_mode(regs)) {
29329 unsigned long stack = kernel_stack_pointer(regs);
29330 if (depth)
29331 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29332diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29333index 48768df..ba9143c 100644
29334--- a/arch/x86/oprofile/nmi_int.c
29335+++ b/arch/x86/oprofile/nmi_int.c
29336@@ -23,6 +23,7 @@
29337 #include <asm/nmi.h>
29338 #include <asm/msr.h>
29339 #include <asm/apic.h>
29340+#include <asm/pgtable.h>
29341
29342 #include "op_counter.h"
29343 #include "op_x86_model.h"
29344@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29345 if (ret)
29346 return ret;
29347
29348- if (!model->num_virt_counters)
29349- model->num_virt_counters = model->num_counters;
29350+ if (!model->num_virt_counters) {
29351+ pax_open_kernel();
29352+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29353+ pax_close_kernel();
29354+ }
29355
29356 mux_init(ops);
29357
29358diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29359index b2b9443..be58856 100644
29360--- a/arch/x86/oprofile/op_model_amd.c
29361+++ b/arch/x86/oprofile/op_model_amd.c
29362@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29363 num_counters = AMD64_NUM_COUNTERS;
29364 }
29365
29366- op_amd_spec.num_counters = num_counters;
29367- op_amd_spec.num_controls = num_counters;
29368- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29369+ pax_open_kernel();
29370+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29371+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29372+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29373+ pax_close_kernel();
29374
29375 return 0;
29376 }
29377diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29378index d90528e..0127e2b 100644
29379--- a/arch/x86/oprofile/op_model_ppro.c
29380+++ b/arch/x86/oprofile/op_model_ppro.c
29381@@ -19,6 +19,7 @@
29382 #include <asm/msr.h>
29383 #include <asm/apic.h>
29384 #include <asm/nmi.h>
29385+#include <asm/pgtable.h>
29386
29387 #include "op_x86_model.h"
29388 #include "op_counter.h"
29389@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29390
29391 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29392
29393- op_arch_perfmon_spec.num_counters = num_counters;
29394- op_arch_perfmon_spec.num_controls = num_counters;
29395+ pax_open_kernel();
29396+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
29397+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
29398+ pax_close_kernel();
29399 }
29400
29401 static int arch_perfmon_init(struct oprofile_operations *ignore)
29402diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
29403index 71e8a67..6a313bb 100644
29404--- a/arch/x86/oprofile/op_x86_model.h
29405+++ b/arch/x86/oprofile/op_x86_model.h
29406@@ -52,7 +52,7 @@ struct op_x86_model_spec {
29407 void (*switch_ctrl)(struct op_x86_model_spec const *model,
29408 struct op_msrs const * const msrs);
29409 #endif
29410-};
29411+} __do_const;
29412
29413 struct op_counter_config;
29414
29415diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29416index e9e6ed5..e47ae67 100644
29417--- a/arch/x86/pci/amd_bus.c
29418+++ b/arch/x86/pci/amd_bus.c
29419@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29420 return NOTIFY_OK;
29421 }
29422
29423-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29424+static struct notifier_block amd_cpu_notifier = {
29425 .notifier_call = amd_cpu_notify,
29426 };
29427
29428diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
29429index 372e9b8..e775a6c 100644
29430--- a/arch/x86/pci/irq.c
29431+++ b/arch/x86/pci/irq.c
29432@@ -50,7 +50,7 @@ struct irq_router {
29433 struct irq_router_handler {
29434 u16 vendor;
29435 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
29436-};
29437+} __do_const;
29438
29439 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
29440 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
29441@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
29442 return 0;
29443 }
29444
29445-static __initdata struct irq_router_handler pirq_routers[] = {
29446+static __initconst const struct irq_router_handler pirq_routers[] = {
29447 { PCI_VENDOR_ID_INTEL, intel_router_probe },
29448 { PCI_VENDOR_ID_AL, ali_router_probe },
29449 { PCI_VENDOR_ID_ITE, ite_router_probe },
29450@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
29451 static void __init pirq_find_router(struct irq_router *r)
29452 {
29453 struct irq_routing_table *rt = pirq_table;
29454- struct irq_router_handler *h;
29455+ const struct irq_router_handler *h;
29456
29457 #ifdef CONFIG_PCI_BIOS
29458 if (!rt->signature) {
29459@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
29460 return 0;
29461 }
29462
29463-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
29464+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
29465 {
29466 .callback = fix_broken_hp_bios_irq9,
29467 .ident = "HP Pavilion N5400 Series Laptop",
29468diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29469index 6eb18c4..20d83de 100644
29470--- a/arch/x86/pci/mrst.c
29471+++ b/arch/x86/pci/mrst.c
29472@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29473 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29474 pci_mmcfg_late_init();
29475 pcibios_enable_irq = mrst_pci_irq_enable;
29476- pci_root_ops = pci_mrst_ops;
29477+ pax_open_kernel();
29478+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29479+ pax_close_kernel();
29480 pci_soc_mode = 1;
29481 /* Continue with standard init */
29482 return 1;
29483diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29484index c77b24a..c979855 100644
29485--- a/arch/x86/pci/pcbios.c
29486+++ b/arch/x86/pci/pcbios.c
29487@@ -79,7 +79,7 @@ union bios32 {
29488 static struct {
29489 unsigned long address;
29490 unsigned short segment;
29491-} bios32_indirect = { 0, __KERNEL_CS };
29492+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29493
29494 /*
29495 * Returns the entry point for the given service, NULL on error
29496@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29497 unsigned long length; /* %ecx */
29498 unsigned long entry; /* %edx */
29499 unsigned long flags;
29500+ struct desc_struct d, *gdt;
29501
29502 local_irq_save(flags);
29503- __asm__("lcall *(%%edi); cld"
29504+
29505+ gdt = get_cpu_gdt_table(smp_processor_id());
29506+
29507+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29508+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29509+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29510+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29511+
29512+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29513 : "=a" (return_code),
29514 "=b" (address),
29515 "=c" (length),
29516 "=d" (entry)
29517 : "0" (service),
29518 "1" (0),
29519- "D" (&bios32_indirect));
29520+ "D" (&bios32_indirect),
29521+ "r"(__PCIBIOS_DS)
29522+ : "memory");
29523+
29524+ pax_open_kernel();
29525+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29526+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29527+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29528+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29529+ pax_close_kernel();
29530+
29531 local_irq_restore(flags);
29532
29533 switch (return_code) {
29534- case 0:
29535- return address + entry;
29536- case 0x80: /* Not present */
29537- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29538- return 0;
29539- default: /* Shouldn't happen */
29540- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29541- service, return_code);
29542+ case 0: {
29543+ int cpu;
29544+ unsigned char flags;
29545+
29546+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29547+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29548+ printk(KERN_WARNING "bios32_service: not valid\n");
29549 return 0;
29550+ }
29551+ address = address + PAGE_OFFSET;
29552+ length += 16UL; /* some BIOSs underreport this... */
29553+ flags = 4;
29554+ if (length >= 64*1024*1024) {
29555+ length >>= PAGE_SHIFT;
29556+ flags |= 8;
29557+ }
29558+
29559+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29560+ gdt = get_cpu_gdt_table(cpu);
29561+ pack_descriptor(&d, address, length, 0x9b, flags);
29562+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29563+ pack_descriptor(&d, address, length, 0x93, flags);
29564+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29565+ }
29566+ return entry;
29567+ }
29568+ case 0x80: /* Not present */
29569+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29570+ return 0;
29571+ default: /* Shouldn't happen */
29572+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29573+ service, return_code);
29574+ return 0;
29575 }
29576 }
29577
29578 static struct {
29579 unsigned long address;
29580 unsigned short segment;
29581-} pci_indirect = { 0, __KERNEL_CS };
29582+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29583
29584-static int pci_bios_present;
29585+static int pci_bios_present __read_only;
29586
29587 static int check_pcibios(void)
29588 {
29589@@ -131,11 +174,13 @@ static int check_pcibios(void)
29590 unsigned long flags, pcibios_entry;
29591
29592 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29593- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29594+ pci_indirect.address = pcibios_entry;
29595
29596 local_irq_save(flags);
29597- __asm__(
29598- "lcall *(%%edi); cld\n\t"
29599+ __asm__("movw %w6, %%ds\n\t"
29600+ "lcall *%%ss:(%%edi); cld\n\t"
29601+ "push %%ss\n\t"
29602+ "pop %%ds\n\t"
29603 "jc 1f\n\t"
29604 "xor %%ah, %%ah\n"
29605 "1:"
29606@@ -144,7 +189,8 @@ static int check_pcibios(void)
29607 "=b" (ebx),
29608 "=c" (ecx)
29609 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29610- "D" (&pci_indirect)
29611+ "D" (&pci_indirect),
29612+ "r" (__PCIBIOS_DS)
29613 : "memory");
29614 local_irq_restore(flags);
29615
29616@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29617
29618 switch (len) {
29619 case 1:
29620- __asm__("lcall *(%%esi); cld\n\t"
29621+ __asm__("movw %w6, %%ds\n\t"
29622+ "lcall *%%ss:(%%esi); cld\n\t"
29623+ "push %%ss\n\t"
29624+ "pop %%ds\n\t"
29625 "jc 1f\n\t"
29626 "xor %%ah, %%ah\n"
29627 "1:"
29628@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29629 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29630 "b" (bx),
29631 "D" ((long)reg),
29632- "S" (&pci_indirect));
29633+ "S" (&pci_indirect),
29634+ "r" (__PCIBIOS_DS));
29635 /*
29636 * Zero-extend the result beyond 8 bits, do not trust the
29637 * BIOS having done it:
29638@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29639 *value &= 0xff;
29640 break;
29641 case 2:
29642- __asm__("lcall *(%%esi); cld\n\t"
29643+ __asm__("movw %w6, %%ds\n\t"
29644+ "lcall *%%ss:(%%esi); cld\n\t"
29645+ "push %%ss\n\t"
29646+ "pop %%ds\n\t"
29647 "jc 1f\n\t"
29648 "xor %%ah, %%ah\n"
29649 "1:"
29650@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29651 : "1" (PCIBIOS_READ_CONFIG_WORD),
29652 "b" (bx),
29653 "D" ((long)reg),
29654- "S" (&pci_indirect));
29655+ "S" (&pci_indirect),
29656+ "r" (__PCIBIOS_DS));
29657 /*
29658 * Zero-extend the result beyond 16 bits, do not trust the
29659 * BIOS having done it:
29660@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29661 *value &= 0xffff;
29662 break;
29663 case 4:
29664- __asm__("lcall *(%%esi); cld\n\t"
29665+ __asm__("movw %w6, %%ds\n\t"
29666+ "lcall *%%ss:(%%esi); cld\n\t"
29667+ "push %%ss\n\t"
29668+ "pop %%ds\n\t"
29669 "jc 1f\n\t"
29670 "xor %%ah, %%ah\n"
29671 "1:"
29672@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29673 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29674 "b" (bx),
29675 "D" ((long)reg),
29676- "S" (&pci_indirect));
29677+ "S" (&pci_indirect),
29678+ "r" (__PCIBIOS_DS));
29679 break;
29680 }
29681
29682@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29683
29684 switch (len) {
29685 case 1:
29686- __asm__("lcall *(%%esi); cld\n\t"
29687+ __asm__("movw %w6, %%ds\n\t"
29688+ "lcall *%%ss:(%%esi); cld\n\t"
29689+ "push %%ss\n\t"
29690+ "pop %%ds\n\t"
29691 "jc 1f\n\t"
29692 "xor %%ah, %%ah\n"
29693 "1:"
29694@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29695 "c" (value),
29696 "b" (bx),
29697 "D" ((long)reg),
29698- "S" (&pci_indirect));
29699+ "S" (&pci_indirect),
29700+ "r" (__PCIBIOS_DS));
29701 break;
29702 case 2:
29703- __asm__("lcall *(%%esi); cld\n\t"
29704+ __asm__("movw %w6, %%ds\n\t"
29705+ "lcall *%%ss:(%%esi); cld\n\t"
29706+ "push %%ss\n\t"
29707+ "pop %%ds\n\t"
29708 "jc 1f\n\t"
29709 "xor %%ah, %%ah\n"
29710 "1:"
29711@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29712 "c" (value),
29713 "b" (bx),
29714 "D" ((long)reg),
29715- "S" (&pci_indirect));
29716+ "S" (&pci_indirect),
29717+ "r" (__PCIBIOS_DS));
29718 break;
29719 case 4:
29720- __asm__("lcall *(%%esi); cld\n\t"
29721+ __asm__("movw %w6, %%ds\n\t"
29722+ "lcall *%%ss:(%%esi); cld\n\t"
29723+ "push %%ss\n\t"
29724+ "pop %%ds\n\t"
29725 "jc 1f\n\t"
29726 "xor %%ah, %%ah\n"
29727 "1:"
29728@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29729 "c" (value),
29730 "b" (bx),
29731 "D" ((long)reg),
29732- "S" (&pci_indirect));
29733+ "S" (&pci_indirect),
29734+ "r" (__PCIBIOS_DS));
29735 break;
29736 }
29737
29738@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29739
29740 DBG("PCI: Fetching IRQ routing table... ");
29741 __asm__("push %%es\n\t"
29742+ "movw %w8, %%ds\n\t"
29743 "push %%ds\n\t"
29744 "pop %%es\n\t"
29745- "lcall *(%%esi); cld\n\t"
29746+ "lcall *%%ss:(%%esi); cld\n\t"
29747 "pop %%es\n\t"
29748+ "push %%ss\n\t"
29749+ "pop %%ds\n"
29750 "jc 1f\n\t"
29751 "xor %%ah, %%ah\n"
29752 "1:"
29753@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29754 "1" (0),
29755 "D" ((long) &opt),
29756 "S" (&pci_indirect),
29757- "m" (opt)
29758+ "m" (opt),
29759+ "r" (__PCIBIOS_DS)
29760 : "memory");
29761 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29762 if (ret & 0xff00)
29763@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29764 {
29765 int ret;
29766
29767- __asm__("lcall *(%%esi); cld\n\t"
29768+ __asm__("movw %w5, %%ds\n\t"
29769+ "lcall *%%ss:(%%esi); cld\n\t"
29770+ "push %%ss\n\t"
29771+ "pop %%ds\n"
29772 "jc 1f\n\t"
29773 "xor %%ah, %%ah\n"
29774 "1:"
29775@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29776 : "0" (PCIBIOS_SET_PCI_HW_INT),
29777 "b" ((dev->bus->number << 8) | dev->devfn),
29778 "c" ((irq << 8) | (pin + 10)),
29779- "S" (&pci_indirect));
29780+ "S" (&pci_indirect),
29781+ "r" (__PCIBIOS_DS));
29782 return !(ret & 0xff00);
29783 }
29784 EXPORT_SYMBOL(pcibios_set_irq_routing);
29785diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29786index 40e4469..1ab536e 100644
29787--- a/arch/x86/platform/efi/efi_32.c
29788+++ b/arch/x86/platform/efi/efi_32.c
29789@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29790 {
29791 struct desc_ptr gdt_descr;
29792
29793+#ifdef CONFIG_PAX_KERNEXEC
29794+ struct desc_struct d;
29795+#endif
29796+
29797 local_irq_save(efi_rt_eflags);
29798
29799 load_cr3(initial_page_table);
29800 __flush_tlb_all();
29801
29802+#ifdef CONFIG_PAX_KERNEXEC
29803+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29804+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29805+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29806+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29807+#endif
29808+
29809 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29810 gdt_descr.size = GDT_SIZE - 1;
29811 load_gdt(&gdt_descr);
29812@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29813 {
29814 struct desc_ptr gdt_descr;
29815
29816+#ifdef CONFIG_PAX_KERNEXEC
29817+ struct desc_struct d;
29818+
29819+ memset(&d, 0, sizeof d);
29820+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29821+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29822+#endif
29823+
29824 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29825 gdt_descr.size = GDT_SIZE - 1;
29826 load_gdt(&gdt_descr);
29827diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29828index fbe66e6..eae5e38 100644
29829--- a/arch/x86/platform/efi/efi_stub_32.S
29830+++ b/arch/x86/platform/efi/efi_stub_32.S
29831@@ -6,7 +6,9 @@
29832 */
29833
29834 #include <linux/linkage.h>
29835+#include <linux/init.h>
29836 #include <asm/page_types.h>
29837+#include <asm/segment.h>
29838
29839 /*
29840 * efi_call_phys(void *, ...) is a function with variable parameters.
29841@@ -20,7 +22,7 @@
29842 * service functions will comply with gcc calling convention, too.
29843 */
29844
29845-.text
29846+__INIT
29847 ENTRY(efi_call_phys)
29848 /*
29849 * 0. The function can only be called in Linux kernel. So CS has been
29850@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29851 * The mapping of lower virtual memory has been created in prelog and
29852 * epilog.
29853 */
29854- movl $1f, %edx
29855- subl $__PAGE_OFFSET, %edx
29856- jmp *%edx
29857+#ifdef CONFIG_PAX_KERNEXEC
29858+ movl $(__KERNEXEC_EFI_DS), %edx
29859+ mov %edx, %ds
29860+ mov %edx, %es
29861+ mov %edx, %ss
29862+ addl $2f,(1f)
29863+ ljmp *(1f)
29864+
29865+__INITDATA
29866+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29867+.previous
29868+
29869+2:
29870+ subl $2b,(1b)
29871+#else
29872+ jmp 1f-__PAGE_OFFSET
29873 1:
29874+#endif
29875
29876 /*
29877 * 2. Now on the top of stack is the return
29878@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29879 * parameter 2, ..., param n. To make things easy, we save the return
29880 * address of efi_call_phys in a global variable.
29881 */
29882- popl %edx
29883- movl %edx, saved_return_addr
29884- /* get the function pointer into ECX*/
29885- popl %ecx
29886- movl %ecx, efi_rt_function_ptr
29887- movl $2f, %edx
29888- subl $__PAGE_OFFSET, %edx
29889- pushl %edx
29890+ popl (saved_return_addr)
29891+ popl (efi_rt_function_ptr)
29892
29893 /*
29894 * 3. Clear PG bit in %CR0.
29895@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29896 /*
29897 * 5. Call the physical function.
29898 */
29899- jmp *%ecx
29900+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
29901
29902-2:
29903 /*
29904 * 6. After EFI runtime service returns, control will return to
29905 * following instruction. We'd better readjust stack pointer first.
29906@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29907 movl %cr0, %edx
29908 orl $0x80000000, %edx
29909 movl %edx, %cr0
29910- jmp 1f
29911-1:
29912+
29913 /*
29914 * 8. Now restore the virtual mode from flat mode by
29915 * adding EIP with PAGE_OFFSET.
29916 */
29917- movl $1f, %edx
29918- jmp *%edx
29919+#ifdef CONFIG_PAX_KERNEXEC
29920+ movl $(__KERNEL_DS), %edx
29921+ mov %edx, %ds
29922+ mov %edx, %es
29923+ mov %edx, %ss
29924+ ljmp $(__KERNEL_CS),$1f
29925+#else
29926+ jmp 1f+__PAGE_OFFSET
29927+#endif
29928 1:
29929
29930 /*
29931 * 9. Balance the stack. And because EAX contain the return value,
29932 * we'd better not clobber it.
29933 */
29934- leal efi_rt_function_ptr, %edx
29935- movl (%edx), %ecx
29936- pushl %ecx
29937+ pushl (efi_rt_function_ptr)
29938
29939 /*
29940- * 10. Push the saved return address onto the stack and return.
29941+ * 10. Return to the saved return address.
29942 */
29943- leal saved_return_addr, %edx
29944- movl (%edx), %ecx
29945- pushl %ecx
29946- ret
29947+ jmpl *(saved_return_addr)
29948 ENDPROC(efi_call_phys)
29949 .previous
29950
29951-.data
29952+__INITDATA
29953 saved_return_addr:
29954 .long 0
29955 efi_rt_function_ptr:
29956diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29957index 4c07cca..2c8427d 100644
29958--- a/arch/x86/platform/efi/efi_stub_64.S
29959+++ b/arch/x86/platform/efi/efi_stub_64.S
29960@@ -7,6 +7,7 @@
29961 */
29962
29963 #include <linux/linkage.h>
29964+#include <asm/alternative-asm.h>
29965
29966 #define SAVE_XMM \
29967 mov %rsp, %rax; \
29968@@ -40,6 +41,7 @@ ENTRY(efi_call0)
29969 call *%rdi
29970 addq $32, %rsp
29971 RESTORE_XMM
29972+ pax_force_retaddr 0, 1
29973 ret
29974 ENDPROC(efi_call0)
29975
29976@@ -50,6 +52,7 @@ ENTRY(efi_call1)
29977 call *%rdi
29978 addq $32, %rsp
29979 RESTORE_XMM
29980+ pax_force_retaddr 0, 1
29981 ret
29982 ENDPROC(efi_call1)
29983
29984@@ -60,6 +63,7 @@ ENTRY(efi_call2)
29985 call *%rdi
29986 addq $32, %rsp
29987 RESTORE_XMM
29988+ pax_force_retaddr 0, 1
29989 ret
29990 ENDPROC(efi_call2)
29991
29992@@ -71,6 +75,7 @@ ENTRY(efi_call3)
29993 call *%rdi
29994 addq $32, %rsp
29995 RESTORE_XMM
29996+ pax_force_retaddr 0, 1
29997 ret
29998 ENDPROC(efi_call3)
29999
30000@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30001 call *%rdi
30002 addq $32, %rsp
30003 RESTORE_XMM
30004+ pax_force_retaddr 0, 1
30005 ret
30006 ENDPROC(efi_call4)
30007
30008@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30009 call *%rdi
30010 addq $48, %rsp
30011 RESTORE_XMM
30012+ pax_force_retaddr 0, 1
30013 ret
30014 ENDPROC(efi_call5)
30015
30016@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30017 call *%rdi
30018 addq $48, %rsp
30019 RESTORE_XMM
30020+ pax_force_retaddr 0, 1
30021 ret
30022 ENDPROC(efi_call6)
30023diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30024index e31bcd8..f12dc46 100644
30025--- a/arch/x86/platform/mrst/mrst.c
30026+++ b/arch/x86/platform/mrst/mrst.c
30027@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30028 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30029 int sfi_mrtc_num;
30030
30031-static void mrst_power_off(void)
30032+static __noreturn void mrst_power_off(void)
30033 {
30034+ BUG();
30035 }
30036
30037-static void mrst_reboot(void)
30038+static __noreturn void mrst_reboot(void)
30039 {
30040 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30041+ BUG();
30042 }
30043
30044 /* parse all the mtimer info to a static mtimer array */
30045diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30046index d6ee929..3637cb5 100644
30047--- a/arch/x86/platform/olpc/olpc_dt.c
30048+++ b/arch/x86/platform/olpc/olpc_dt.c
30049@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30050 return res;
30051 }
30052
30053-static struct of_pdt_ops prom_olpc_ops __initdata = {
30054+static struct of_pdt_ops prom_olpc_ops __initconst = {
30055 .nextprop = olpc_dt_nextprop,
30056 .getproplen = olpc_dt_getproplen,
30057 .getproperty = olpc_dt_getproperty,
30058diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30059index 120cee1..b2db75a 100644
30060--- a/arch/x86/power/cpu.c
30061+++ b/arch/x86/power/cpu.c
30062@@ -133,7 +133,7 @@ static void do_fpu_end(void)
30063 static void fix_processor_context(void)
30064 {
30065 int cpu = smp_processor_id();
30066- struct tss_struct *t = &per_cpu(init_tss, cpu);
30067+ struct tss_struct *t = init_tss + cpu;
30068
30069 set_tss_desc(cpu, t); /*
30070 * This just modifies memory; should not be
30071@@ -143,8 +143,6 @@ static void fix_processor_context(void)
30072 */
30073
30074 #ifdef CONFIG_X86_64
30075- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30076-
30077 syscall_init(); /* This sets MSR_*STAR and related */
30078 #endif
30079 load_TR_desc(); /* This does ltr */
30080diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30081index cbca565..bae7133 100644
30082--- a/arch/x86/realmode/init.c
30083+++ b/arch/x86/realmode/init.c
30084@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
30085 __va(real_mode_header->trampoline_header);
30086
30087 #ifdef CONFIG_X86_32
30088- trampoline_header->start = __pa(startup_32_smp);
30089+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
30090+
30091+#ifdef CONFIG_PAX_KERNEXEC
30092+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30093+#endif
30094+
30095+ trampoline_header->boot_cs = __BOOT_CS;
30096 trampoline_header->gdt_limit = __BOOT_DS + 7;
30097 trampoline_header->gdt_base = __pa(boot_gdt);
30098 #else
30099diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30100index 8869287..d577672 100644
30101--- a/arch/x86/realmode/rm/Makefile
30102+++ b/arch/x86/realmode/rm/Makefile
30103@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30104 $(call cc-option, -fno-unit-at-a-time)) \
30105 $(call cc-option, -fno-stack-protector) \
30106 $(call cc-option, -mpreferred-stack-boundary=2)
30107+ifdef CONSTIFY_PLUGIN
30108+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30109+endif
30110 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30111 GCOV_PROFILE := n
30112diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30113index a28221d..93c40f1 100644
30114--- a/arch/x86/realmode/rm/header.S
30115+++ b/arch/x86/realmode/rm/header.S
30116@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30117 #endif
30118 /* APM/BIOS reboot */
30119 .long pa_machine_real_restart_asm
30120-#ifdef CONFIG_X86_64
30121+#ifdef CONFIG_X86_32
30122+ .long __KERNEL_CS
30123+#else
30124 .long __KERNEL32_CS
30125 #endif
30126 END(real_mode_header)
30127diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30128index c1b2791..f9e31c7 100644
30129--- a/arch/x86/realmode/rm/trampoline_32.S
30130+++ b/arch/x86/realmode/rm/trampoline_32.S
30131@@ -25,6 +25,12 @@
30132 #include <asm/page_types.h>
30133 #include "realmode.h"
30134
30135+#ifdef CONFIG_PAX_KERNEXEC
30136+#define ta(X) (X)
30137+#else
30138+#define ta(X) (pa_ ## X)
30139+#endif
30140+
30141 .text
30142 .code16
30143
30144@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30145
30146 cli # We should be safe anyway
30147
30148- movl tr_start, %eax # where we need to go
30149-
30150 movl $0xA5A5A5A5, trampoline_status
30151 # write marker for master knows we're running
30152
30153@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30154 movw $1, %dx # protected mode (PE) bit
30155 lmsw %dx # into protected mode
30156
30157- ljmpl $__BOOT_CS, $pa_startup_32
30158+ ljmpl *(trampoline_header)
30159
30160 .section ".text32","ax"
30161 .code32
30162@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30163 .balign 8
30164 GLOBAL(trampoline_header)
30165 tr_start: .space 4
30166- tr_gdt_pad: .space 2
30167+ tr_boot_cs: .space 2
30168 tr_gdt: .space 6
30169 END(trampoline_header)
30170
30171diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30172index bb360dc..3e5945f 100644
30173--- a/arch/x86/realmode/rm/trampoline_64.S
30174+++ b/arch/x86/realmode/rm/trampoline_64.S
30175@@ -107,7 +107,7 @@ ENTRY(startup_32)
30176 wrmsr
30177
30178 # Enable paging and in turn activate Long Mode
30179- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30180+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30181 movl %eax, %cr0
30182
30183 /*
30184diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30185index 79d67bd..c7e1b90 100644
30186--- a/arch/x86/tools/relocs.c
30187+++ b/arch/x86/tools/relocs.c
30188@@ -12,10 +12,13 @@
30189 #include <regex.h>
30190 #include <tools/le_byteshift.h>
30191
30192+#include "../../../include/generated/autoconf.h"
30193+
30194 static void die(char *fmt, ...);
30195
30196 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30197 static Elf32_Ehdr ehdr;
30198+static Elf32_Phdr *phdr;
30199 static unsigned long reloc_count, reloc_idx;
30200 static unsigned long *relocs;
30201 static unsigned long reloc16_count, reloc16_idx;
30202@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30203 }
30204 }
30205
30206+static void read_phdrs(FILE *fp)
30207+{
30208+ unsigned int i;
30209+
30210+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30211+ if (!phdr) {
30212+ die("Unable to allocate %d program headers\n",
30213+ ehdr.e_phnum);
30214+ }
30215+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30216+ die("Seek to %d failed: %s\n",
30217+ ehdr.e_phoff, strerror(errno));
30218+ }
30219+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30220+ die("Cannot read ELF program headers: %s\n",
30221+ strerror(errno));
30222+ }
30223+ for(i = 0; i < ehdr.e_phnum; i++) {
30224+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30225+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30226+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30227+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30228+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30229+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30230+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30231+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30232+ }
30233+
30234+}
30235+
30236 static void read_shdrs(FILE *fp)
30237 {
30238- int i;
30239+ unsigned int i;
30240 Elf32_Shdr shdr;
30241
30242 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30243@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30244
30245 static void read_strtabs(FILE *fp)
30246 {
30247- int i;
30248+ unsigned int i;
30249 for (i = 0; i < ehdr.e_shnum; i++) {
30250 struct section *sec = &secs[i];
30251 if (sec->shdr.sh_type != SHT_STRTAB) {
30252@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30253
30254 static void read_symtabs(FILE *fp)
30255 {
30256- int i,j;
30257+ unsigned int i,j;
30258 for (i = 0; i < ehdr.e_shnum; i++) {
30259 struct section *sec = &secs[i];
30260 if (sec->shdr.sh_type != SHT_SYMTAB) {
30261@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30262 }
30263
30264
30265-static void read_relocs(FILE *fp)
30266+static void read_relocs(FILE *fp, int use_real_mode)
30267 {
30268- int i,j;
30269+ unsigned int i,j;
30270+ uint32_t base;
30271+
30272 for (i = 0; i < ehdr.e_shnum; i++) {
30273 struct section *sec = &secs[i];
30274 if (sec->shdr.sh_type != SHT_REL) {
30275@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30276 die("Cannot read symbol table: %s\n",
30277 strerror(errno));
30278 }
30279+ base = 0;
30280+
30281+#ifdef CONFIG_X86_32
30282+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30283+ if (phdr[j].p_type != PT_LOAD )
30284+ continue;
30285+ 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)
30286+ continue;
30287+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30288+ break;
30289+ }
30290+#endif
30291+
30292 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30293 Elf32_Rel *rel = &sec->reltab[j];
30294- rel->r_offset = elf32_to_cpu(rel->r_offset);
30295+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30296 rel->r_info = elf32_to_cpu(rel->r_info);
30297 }
30298 }
30299@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30300
30301 static void print_absolute_symbols(void)
30302 {
30303- int i;
30304+ unsigned int i;
30305 printf("Absolute symbols\n");
30306 printf(" Num: Value Size Type Bind Visibility Name\n");
30307 for (i = 0; i < ehdr.e_shnum; i++) {
30308 struct section *sec = &secs[i];
30309 char *sym_strtab;
30310- int j;
30311+ unsigned int j;
30312
30313 if (sec->shdr.sh_type != SHT_SYMTAB) {
30314 continue;
30315@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30316
30317 static void print_absolute_relocs(void)
30318 {
30319- int i, printed = 0;
30320+ unsigned int i, printed = 0;
30321
30322 for (i = 0; i < ehdr.e_shnum; i++) {
30323 struct section *sec = &secs[i];
30324 struct section *sec_applies, *sec_symtab;
30325 char *sym_strtab;
30326 Elf32_Sym *sh_symtab;
30327- int j;
30328+ unsigned int j;
30329 if (sec->shdr.sh_type != SHT_REL) {
30330 continue;
30331 }
30332@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30333 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30334 int use_real_mode)
30335 {
30336- int i;
30337+ unsigned int i;
30338 /* Walk through the relocations */
30339 for (i = 0; i < ehdr.e_shnum; i++) {
30340 char *sym_strtab;
30341 Elf32_Sym *sh_symtab;
30342 struct section *sec_applies, *sec_symtab;
30343- int j;
30344+ unsigned int j;
30345 struct section *sec = &secs[i];
30346
30347 if (sec->shdr.sh_type != SHT_REL) {
30348@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30349 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30350 r_type = ELF32_R_TYPE(rel->r_info);
30351
30352+ if (!use_real_mode) {
30353+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30354+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30355+ continue;
30356+
30357+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30358+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30359+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30360+ continue;
30361+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30362+ continue;
30363+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30364+ continue;
30365+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30366+ continue;
30367+#endif
30368+ }
30369+
30370 shn_abs = sym->st_shndx == SHN_ABS;
30371
30372 switch (r_type) {
30373@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30374
30375 static void emit_relocs(int as_text, int use_real_mode)
30376 {
30377- int i;
30378+ unsigned int i;
30379 /* Count how many relocations I have and allocate space for them. */
30380 reloc_count = 0;
30381 walk_relocs(count_reloc, use_real_mode);
30382@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30383 fname, strerror(errno));
30384 }
30385 read_ehdr(fp);
30386+ read_phdrs(fp);
30387 read_shdrs(fp);
30388 read_strtabs(fp);
30389 read_symtabs(fp);
30390- read_relocs(fp);
30391+ read_relocs(fp, use_real_mode);
30392 if (show_absolute_syms) {
30393 print_absolute_symbols();
30394 goto out;
30395diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
30396index fd14be1..e3c79c0 100644
30397--- a/arch/x86/vdso/Makefile
30398+++ b/arch/x86/vdso/Makefile
30399@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
30400 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
30401 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
30402
30403-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30404+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
30405 GCOV_PROFILE := n
30406
30407 #
30408diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
30409index 0faad64..39ef157 100644
30410--- a/arch/x86/vdso/vdso32-setup.c
30411+++ b/arch/x86/vdso/vdso32-setup.c
30412@@ -25,6 +25,7 @@
30413 #include <asm/tlbflush.h>
30414 #include <asm/vdso.h>
30415 #include <asm/proto.h>
30416+#include <asm/mman.h>
30417
30418 enum {
30419 VDSO_DISABLED = 0,
30420@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
30421 void enable_sep_cpu(void)
30422 {
30423 int cpu = get_cpu();
30424- struct tss_struct *tss = &per_cpu(init_tss, cpu);
30425+ struct tss_struct *tss = init_tss + cpu;
30426
30427 if (!boot_cpu_has(X86_FEATURE_SEP)) {
30428 put_cpu();
30429@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
30430 gate_vma.vm_start = FIXADDR_USER_START;
30431 gate_vma.vm_end = FIXADDR_USER_END;
30432 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
30433- gate_vma.vm_page_prot = __P101;
30434+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
30435
30436 return 0;
30437 }
30438@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30439 if (compat)
30440 addr = VDSO_HIGH_BASE;
30441 else {
30442- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
30443+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
30444 if (IS_ERR_VALUE(addr)) {
30445 ret = addr;
30446 goto up_fail;
30447 }
30448 }
30449
30450- current->mm->context.vdso = (void *)addr;
30451+ current->mm->context.vdso = addr;
30452
30453 if (compat_uses_vma || !compat) {
30454 /*
30455@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30456 }
30457
30458 current_thread_info()->sysenter_return =
30459- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30460+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30461
30462 up_fail:
30463 if (ret)
30464- current->mm->context.vdso = NULL;
30465+ current->mm->context.vdso = 0;
30466
30467 up_write(&mm->mmap_sem);
30468
30469@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30470
30471 const char *arch_vma_name(struct vm_area_struct *vma)
30472 {
30473- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30474+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30475 return "[vdso]";
30476+
30477+#ifdef CONFIG_PAX_SEGMEXEC
30478+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30479+ return "[vdso]";
30480+#endif
30481+
30482 return NULL;
30483 }
30484
30485@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30486 * Check to see if the corresponding task was created in compat vdso
30487 * mode.
30488 */
30489- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30490+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30491 return &gate_vma;
30492 return NULL;
30493 }
30494diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30495index 431e875..cbb23f3 100644
30496--- a/arch/x86/vdso/vma.c
30497+++ b/arch/x86/vdso/vma.c
30498@@ -16,8 +16,6 @@
30499 #include <asm/vdso.h>
30500 #include <asm/page.h>
30501
30502-unsigned int __read_mostly vdso_enabled = 1;
30503-
30504 extern char vdso_start[], vdso_end[];
30505 extern unsigned short vdso_sync_cpuid;
30506
30507@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30508 * unaligned here as a result of stack start randomization.
30509 */
30510 addr = PAGE_ALIGN(addr);
30511- addr = align_vdso_addr(addr);
30512
30513 return addr;
30514 }
30515@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30516 unsigned size)
30517 {
30518 struct mm_struct *mm = current->mm;
30519- unsigned long addr;
30520+ unsigned long addr = 0;
30521 int ret;
30522
30523- if (!vdso_enabled)
30524- return 0;
30525-
30526 down_write(&mm->mmap_sem);
30527+
30528+#ifdef CONFIG_PAX_RANDMMAP
30529+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30530+#endif
30531+
30532 addr = vdso_addr(mm->start_stack, size);
30533+ addr = align_vdso_addr(addr);
30534 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30535 if (IS_ERR_VALUE(addr)) {
30536 ret = addr;
30537 goto up_fail;
30538 }
30539
30540- current->mm->context.vdso = (void *)addr;
30541+ mm->context.vdso = addr;
30542
30543 ret = install_special_mapping(mm, addr, size,
30544 VM_READ|VM_EXEC|
30545 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30546 pages);
30547- if (ret) {
30548- current->mm->context.vdso = NULL;
30549- goto up_fail;
30550- }
30551+ if (ret)
30552+ mm->context.vdso = 0;
30553
30554 up_fail:
30555 up_write(&mm->mmap_sem);
30556@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30557 vdsox32_size);
30558 }
30559 #endif
30560-
30561-static __init int vdso_setup(char *s)
30562-{
30563- vdso_enabled = simple_strtoul(s, NULL, 0);
30564- return 0;
30565-}
30566-__setup("vdso=", vdso_setup);
30567diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30568index e014092..c76ab69 100644
30569--- a/arch/x86/xen/enlighten.c
30570+++ b/arch/x86/xen/enlighten.c
30571@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30572
30573 struct shared_info xen_dummy_shared_info;
30574
30575-void *xen_initial_gdt;
30576-
30577 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30578 __read_mostly int xen_have_vector_callback;
30579 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30580@@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30581 {
30582 unsigned long va = dtr->address;
30583 unsigned int size = dtr->size + 1;
30584- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30585- unsigned long frames[pages];
30586+ unsigned long frames[65536 / PAGE_SIZE];
30587 int f;
30588
30589 /*
30590@@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30591 {
30592 unsigned long va = dtr->address;
30593 unsigned int size = dtr->size + 1;
30594- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30595- unsigned long frames[pages];
30596+ unsigned long frames[65536 / PAGE_SIZE];
30597 int f;
30598
30599 /*
30600@@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30601 return 0;
30602 }
30603
30604-static void set_xen_basic_apic_ops(void)
30605+static void __init set_xen_basic_apic_ops(void)
30606 {
30607 apic->read = xen_apic_read;
30608 apic->write = xen_apic_write;
30609@@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30610 #endif
30611 };
30612
30613-static void xen_reboot(int reason)
30614+static __noreturn void xen_reboot(int reason)
30615 {
30616 struct sched_shutdown r = { .reason = reason };
30617
30618- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30619- BUG();
30620+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30621+ BUG();
30622 }
30623
30624-static void xen_restart(char *msg)
30625+static __noreturn void xen_restart(char *msg)
30626 {
30627 xen_reboot(SHUTDOWN_reboot);
30628 }
30629
30630-static void xen_emergency_restart(void)
30631+static __noreturn void xen_emergency_restart(void)
30632 {
30633 xen_reboot(SHUTDOWN_reboot);
30634 }
30635
30636-static void xen_machine_halt(void)
30637+static __noreturn void xen_machine_halt(void)
30638 {
30639 xen_reboot(SHUTDOWN_poweroff);
30640 }
30641
30642-static void xen_machine_power_off(void)
30643+static __noreturn void xen_machine_power_off(void)
30644 {
30645 if (pm_power_off)
30646 pm_power_off();
30647@@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30648 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30649
30650 /* Work out if we support NX */
30651- x86_configure_nx();
30652+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30653+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30654+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30655+ unsigned l, h;
30656+
30657+ __supported_pte_mask |= _PAGE_NX;
30658+ rdmsr(MSR_EFER, l, h);
30659+ l |= EFER_NX;
30660+ wrmsr(MSR_EFER, l, h);
30661+ }
30662+#endif
30663
30664 xen_setup_features();
30665
30666@@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30667 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30668 }
30669
30670- machine_ops = xen_machine_ops;
30671-
30672- /*
30673- * The only reliable way to retain the initial address of the
30674- * percpu gdt_page is to remember it here, so we can go and
30675- * mark it RW later, when the initial percpu area is freed.
30676- */
30677- xen_initial_gdt = &per_cpu(gdt_page, 0);
30678+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30679
30680 xen_smp_init();
30681
30682@@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30683 return NOTIFY_OK;
30684 }
30685
30686-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30687+static struct notifier_block xen_hvm_cpu_notifier = {
30688 .notifier_call = xen_hvm_cpu_notify,
30689 };
30690
30691diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30692index 01de35c..0bda07b 100644
30693--- a/arch/x86/xen/mmu.c
30694+++ b/arch/x86/xen/mmu.c
30695@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30696 /* L3_k[510] -> level2_kernel_pgt
30697 * L3_i[511] -> level2_fixmap_pgt */
30698 convert_pfn_mfn(level3_kernel_pgt);
30699+ convert_pfn_mfn(level3_vmalloc_start_pgt);
30700+ convert_pfn_mfn(level3_vmalloc_end_pgt);
30701+ convert_pfn_mfn(level3_vmemmap_pgt);
30702
30703 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30704 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30705@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30706 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30707 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30708 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30709+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30710+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30711+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30712 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30713 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30714+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30715 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30716 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30717
30718@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30719 pv_mmu_ops.set_pud = xen_set_pud;
30720 #if PAGETABLE_LEVELS == 4
30721 pv_mmu_ops.set_pgd = xen_set_pgd;
30722+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30723 #endif
30724
30725 /* This will work as long as patching hasn't happened yet
30726@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30727 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30728 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30729 .set_pgd = xen_set_pgd_hyper,
30730+ .set_pgd_batched = xen_set_pgd_hyper,
30731
30732 .alloc_pud = xen_alloc_pmd_init,
30733 .release_pud = xen_release_pmd_init,
30734diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30735index 34bc4ce..c34aa24 100644
30736--- a/arch/x86/xen/smp.c
30737+++ b/arch/x86/xen/smp.c
30738@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30739 {
30740 BUG_ON(smp_processor_id() != 0);
30741 native_smp_prepare_boot_cpu();
30742-
30743- /* We've switched to the "real" per-cpu gdt, so make sure the
30744- old memory can be recycled */
30745- make_lowmem_page_readwrite(xen_initial_gdt);
30746-
30747 xen_filter_cpu_maps();
30748 xen_setup_vcpu_info_placement();
30749 }
30750@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30751 gdt = get_cpu_gdt_table(cpu);
30752
30753 ctxt->flags = VGCF_IN_KERNEL;
30754- ctxt->user_regs.ds = __USER_DS;
30755- ctxt->user_regs.es = __USER_DS;
30756+ ctxt->user_regs.ds = __KERNEL_DS;
30757+ ctxt->user_regs.es = __KERNEL_DS;
30758 ctxt->user_regs.ss = __KERNEL_DS;
30759 #ifdef CONFIG_X86_32
30760 ctxt->user_regs.fs = __KERNEL_PERCPU;
30761- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30762+ savesegment(gs, ctxt->user_regs.gs);
30763 #else
30764 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30765 #endif
30766@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30767 int rc;
30768
30769 per_cpu(current_task, cpu) = idle;
30770+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
30771 #ifdef CONFIG_X86_32
30772 irq_ctx_init(cpu);
30773 #else
30774 clear_tsk_thread_flag(idle, TIF_FORK);
30775- per_cpu(kernel_stack, cpu) =
30776- (unsigned long)task_stack_page(idle) -
30777- KERNEL_STACK_OFFSET + THREAD_SIZE;
30778+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30779 #endif
30780 xen_setup_runstate_info(cpu);
30781 xen_setup_timer(cpu);
30782@@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30783
30784 void __init xen_smp_init(void)
30785 {
30786- smp_ops = xen_smp_ops;
30787+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30788 xen_fill_possible_map();
30789 xen_init_spinlocks();
30790 }
30791diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30792index 33ca6e4..0ded929 100644
30793--- a/arch/x86/xen/xen-asm_32.S
30794+++ b/arch/x86/xen/xen-asm_32.S
30795@@ -84,14 +84,14 @@ ENTRY(xen_iret)
30796 ESP_OFFSET=4 # bytes pushed onto stack
30797
30798 /*
30799- * Store vcpu_info pointer for easy access. Do it this way to
30800- * avoid having to reload %fs
30801+ * Store vcpu_info pointer for easy access.
30802 */
30803 #ifdef CONFIG_SMP
30804- GET_THREAD_INFO(%eax)
30805- movl %ss:TI_cpu(%eax), %eax
30806- movl %ss:__per_cpu_offset(,%eax,4), %eax
30807- mov %ss:xen_vcpu(%eax), %eax
30808+ push %fs
30809+ mov $(__KERNEL_PERCPU), %eax
30810+ mov %eax, %fs
30811+ mov PER_CPU_VAR(xen_vcpu), %eax
30812+ pop %fs
30813 #else
30814 movl %ss:xen_vcpu, %eax
30815 #endif
30816diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30817index 7faed58..ba4427c 100644
30818--- a/arch/x86/xen/xen-head.S
30819+++ b/arch/x86/xen/xen-head.S
30820@@ -19,6 +19,17 @@ ENTRY(startup_xen)
30821 #ifdef CONFIG_X86_32
30822 mov %esi,xen_start_info
30823 mov $init_thread_union+THREAD_SIZE,%esp
30824+#ifdef CONFIG_SMP
30825+ movl $cpu_gdt_table,%edi
30826+ movl $__per_cpu_load,%eax
30827+ movw %ax,__KERNEL_PERCPU + 2(%edi)
30828+ rorl $16,%eax
30829+ movb %al,__KERNEL_PERCPU + 4(%edi)
30830+ movb %ah,__KERNEL_PERCPU + 7(%edi)
30831+ movl $__per_cpu_end - 1,%eax
30832+ subl $__per_cpu_start,%eax
30833+ movw %ax,__KERNEL_PERCPU + 0(%edi)
30834+#endif
30835 #else
30836 mov %rsi,xen_start_info
30837 mov $init_thread_union+THREAD_SIZE,%rsp
30838diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30839index a95b417..b6dbd0b 100644
30840--- a/arch/x86/xen/xen-ops.h
30841+++ b/arch/x86/xen/xen-ops.h
30842@@ -10,8 +10,6 @@
30843 extern const char xen_hypervisor_callback[];
30844 extern const char xen_failsafe_callback[];
30845
30846-extern void *xen_initial_gdt;
30847-
30848 struct trap_info;
30849 void xen_copy_trap_info(struct trap_info *traps);
30850
30851diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30852index 525bd3d..ef888b1 100644
30853--- a/arch/xtensa/variants/dc232b/include/variant/core.h
30854+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30855@@ -119,9 +119,9 @@
30856 ----------------------------------------------------------------------*/
30857
30858 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30859-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30860 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30861 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30862+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30863
30864 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30865 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30866diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30867index 2f33760..835e50a 100644
30868--- a/arch/xtensa/variants/fsf/include/variant/core.h
30869+++ b/arch/xtensa/variants/fsf/include/variant/core.h
30870@@ -11,6 +11,7 @@
30871 #ifndef _XTENSA_CORE_H
30872 #define _XTENSA_CORE_H
30873
30874+#include <linux/const.h>
30875
30876 /****************************************************************************
30877 Parameters Useful for Any Code, USER or PRIVILEGED
30878@@ -112,9 +113,9 @@
30879 ----------------------------------------------------------------------*/
30880
30881 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30882-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30883 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30884 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30885+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30886
30887 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30888 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30889diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30890index af00795..2bb8105 100644
30891--- a/arch/xtensa/variants/s6000/include/variant/core.h
30892+++ b/arch/xtensa/variants/s6000/include/variant/core.h
30893@@ -11,6 +11,7 @@
30894 #ifndef _XTENSA_CORE_CONFIGURATION_H
30895 #define _XTENSA_CORE_CONFIGURATION_H
30896
30897+#include <linux/const.h>
30898
30899 /****************************************************************************
30900 Parameters Useful for Any Code, USER or PRIVILEGED
30901@@ -118,9 +119,9 @@
30902 ----------------------------------------------------------------------*/
30903
30904 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30905-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30906 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30907 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30908+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30909
30910 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30911 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30912diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30913index 58916af..eb9dbcf6 100644
30914--- a/block/blk-iopoll.c
30915+++ b/block/blk-iopoll.c
30916@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30917 }
30918 EXPORT_SYMBOL(blk_iopoll_complete);
30919
30920-static void blk_iopoll_softirq(struct softirq_action *h)
30921+static void blk_iopoll_softirq(void)
30922 {
30923 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30924 int rearm = 0, budget = blk_iopoll_budget;
30925@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30926 return NOTIFY_OK;
30927 }
30928
30929-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30930+static struct notifier_block blk_iopoll_cpu_notifier = {
30931 .notifier_call = blk_iopoll_cpu_notify,
30932 };
30933
30934diff --git a/block/blk-map.c b/block/blk-map.c
30935index 623e1cd..ca1e109 100644
30936--- a/block/blk-map.c
30937+++ b/block/blk-map.c
30938@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30939 if (!len || !kbuf)
30940 return -EINVAL;
30941
30942- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30943+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30944 if (do_copy)
30945 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30946 else
30947diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30948index 467c8de..f3628c5 100644
30949--- a/block/blk-softirq.c
30950+++ b/block/blk-softirq.c
30951@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30952 * Softirq action handler - move entries to local list and loop over them
30953 * while passing them to the queue registered handler.
30954 */
30955-static void blk_done_softirq(struct softirq_action *h)
30956+static void blk_done_softirq(void)
30957 {
30958 struct list_head *cpu_list, local_list;
30959
30960@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30961 return NOTIFY_OK;
30962 }
30963
30964-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30965+static struct notifier_block blk_cpu_notifier = {
30966 .notifier_call = blk_cpu_notify,
30967 };
30968
30969diff --git a/block/bsg.c b/block/bsg.c
30970index ff64ae3..593560c 100644
30971--- a/block/bsg.c
30972+++ b/block/bsg.c
30973@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30974 struct sg_io_v4 *hdr, struct bsg_device *bd,
30975 fmode_t has_write_perm)
30976 {
30977+ unsigned char tmpcmd[sizeof(rq->__cmd)];
30978+ unsigned char *cmdptr;
30979+
30980 if (hdr->request_len > BLK_MAX_CDB) {
30981 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30982 if (!rq->cmd)
30983 return -ENOMEM;
30984- }
30985+ cmdptr = rq->cmd;
30986+ } else
30987+ cmdptr = tmpcmd;
30988
30989- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30990+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30991 hdr->request_len))
30992 return -EFAULT;
30993
30994+ if (cmdptr != rq->cmd)
30995+ memcpy(rq->cmd, cmdptr, hdr->request_len);
30996+
30997 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30998 if (blk_verify_command(rq->cmd, has_write_perm))
30999 return -EPERM;
31000diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31001index 7c668c8..db3521c 100644
31002--- a/block/compat_ioctl.c
31003+++ b/block/compat_ioctl.c
31004@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31005 err |= __get_user(f->spec1, &uf->spec1);
31006 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31007 err |= __get_user(name, &uf->name);
31008- f->name = compat_ptr(name);
31009+ f->name = (void __force_kernel *)compat_ptr(name);
31010 if (err) {
31011 err = -EFAULT;
31012 goto out;
31013diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31014index b62fb88..bdab4c4 100644
31015--- a/block/partitions/efi.c
31016+++ b/block/partitions/efi.c
31017@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31018 if (!gpt)
31019 return NULL;
31020
31021+ if (!le32_to_cpu(gpt->num_partition_entries))
31022+ return NULL;
31023+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31024+ if (!pte)
31025+ return NULL;
31026+
31027 count = le32_to_cpu(gpt->num_partition_entries) *
31028 le32_to_cpu(gpt->sizeof_partition_entry);
31029- if (!count)
31030- return NULL;
31031- pte = kzalloc(count, GFP_KERNEL);
31032- if (!pte)
31033- return NULL;
31034-
31035 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31036 (u8 *) pte,
31037 count) < count) {
31038diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31039index 9a87daa..fb17486 100644
31040--- a/block/scsi_ioctl.c
31041+++ b/block/scsi_ioctl.c
31042@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31043 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31044 struct sg_io_hdr *hdr, fmode_t mode)
31045 {
31046- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31047+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31048+ unsigned char *cmdptr;
31049+
31050+ if (rq->cmd != rq->__cmd)
31051+ cmdptr = rq->cmd;
31052+ else
31053+ cmdptr = tmpcmd;
31054+
31055+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31056 return -EFAULT;
31057+
31058+ if (cmdptr != rq->cmd)
31059+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31060+
31061 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31062 return -EPERM;
31063
31064@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31065 int err;
31066 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31067 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31068+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31069+ unsigned char *cmdptr;
31070
31071 if (!sic)
31072 return -EINVAL;
31073@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31074 */
31075 err = -EFAULT;
31076 rq->cmd_len = cmdlen;
31077- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31078+
31079+ if (rq->cmd != rq->__cmd)
31080+ cmdptr = rq->cmd;
31081+ else
31082+ cmdptr = tmpcmd;
31083+
31084+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31085 goto error;
31086
31087+ if (rq->cmd != cmdptr)
31088+ memcpy(rq->cmd, cmdptr, cmdlen);
31089+
31090 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31091 goto error;
31092
31093diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
31094index 533de95..7d4a8d2 100644
31095--- a/crypto/ablkcipher.c
31096+++ b/crypto/ablkcipher.c
31097@@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31098 {
31099 struct crypto_report_blkcipher rblkcipher;
31100
31101- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
31102- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31103- alg->cra_ablkcipher.geniv ?: "<default>");
31104+ strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
31105+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
31106+ sizeof(rblkcipher.geniv));
31107
31108 rblkcipher.blocksize = alg->cra_blocksize;
31109 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
31110@@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31111 {
31112 struct crypto_report_blkcipher rblkcipher;
31113
31114- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
31115- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31116- alg->cra_ablkcipher.geniv ?: "<built-in>");
31117+ strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
31118+ strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
31119+ sizeof(rblkcipher.geniv));
31120
31121 rblkcipher.blocksize = alg->cra_blocksize;
31122 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
31123diff --git a/crypto/aead.c b/crypto/aead.c
31124index 0b8121e..27bc487 100644
31125--- a/crypto/aead.c
31126+++ b/crypto/aead.c
31127@@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
31128 struct crypto_report_aead raead;
31129 struct aead_alg *aead = &alg->cra_aead;
31130
31131- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
31132- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31133- aead->geniv ?: "<built-in>");
31134+ strncpy(raead.type, "aead", sizeof(raead.type));
31135+ strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
31136
31137 raead.blocksize = alg->cra_blocksize;
31138 raead.maxauthsize = aead->maxauthsize;
31139@@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
31140 struct crypto_report_aead raead;
31141 struct aead_alg *aead = &alg->cra_aead;
31142
31143- snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
31144- snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
31145+ strncpy(raead.type, "nivaead", sizeof(raead.type));
31146+ strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
31147
31148 raead.blocksize = alg->cra_blocksize;
31149 raead.maxauthsize = aead->maxauthsize;
31150diff --git a/crypto/ahash.c b/crypto/ahash.c
31151index 3887856..793a27f 100644
31152--- a/crypto/ahash.c
31153+++ b/crypto/ahash.c
31154@@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
31155 {
31156 struct crypto_report_hash rhash;
31157
31158- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
31159+ strncpy(rhash.type, "ahash", sizeof(rhash.type));
31160
31161 rhash.blocksize = alg->cra_blocksize;
31162 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
31163diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
31164index a8d85a1..c44e014 100644
31165--- a/crypto/blkcipher.c
31166+++ b/crypto/blkcipher.c
31167@@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
31168 {
31169 struct crypto_report_blkcipher rblkcipher;
31170
31171- snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
31172- snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
31173- alg->cra_blkcipher.geniv ?: "<default>");
31174+ strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
31175+ strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
31176+ sizeof(rblkcipher.geniv));
31177
31178 rblkcipher.blocksize = alg->cra_blocksize;
31179 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
31180diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31181index 7bdd61b..afec999 100644
31182--- a/crypto/cryptd.c
31183+++ b/crypto/cryptd.c
31184@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31185
31186 struct cryptd_blkcipher_request_ctx {
31187 crypto_completion_t complete;
31188-};
31189+} __no_const;
31190
31191 struct cryptd_hash_ctx {
31192 struct crypto_shash *child;
31193@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31194
31195 struct cryptd_aead_request_ctx {
31196 crypto_completion_t complete;
31197-};
31198+} __no_const;
31199
31200 static void cryptd_queue_worker(struct work_struct *work);
31201
31202diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
31203index 35d700a..dfd511f 100644
31204--- a/crypto/crypto_user.c
31205+++ b/crypto/crypto_user.c
31206@@ -30,6 +30,8 @@
31207
31208 #include "internal.h"
31209
31210+#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
31211+
31212 static DEFINE_MUTEX(crypto_cfg_mutex);
31213
31214 /* The crypto netlink socket */
31215@@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
31216 {
31217 struct crypto_report_cipher rcipher;
31218
31219- snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
31220+ strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
31221
31222 rcipher.blocksize = alg->cra_blocksize;
31223 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
31224@@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
31225 {
31226 struct crypto_report_comp rcomp;
31227
31228- snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
31229-
31230+ strncpy(rcomp.type, "compression", sizeof(rcomp.type));
31231 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
31232 sizeof(struct crypto_report_comp), &rcomp))
31233 goto nla_put_failure;
31234@@ -108,12 +109,14 @@ nla_put_failure:
31235 static int crypto_report_one(struct crypto_alg *alg,
31236 struct crypto_user_alg *ualg, struct sk_buff *skb)
31237 {
31238- memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
31239- memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
31240- sizeof(ualg->cru_driver_name));
31241- memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
31242- CRYPTO_MAX_ALG_NAME);
31243+ strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
31244+ strncpy(ualg->cru_driver_name, alg->cra_driver_name,
31245+ sizeof(ualg->cru_driver_name));
31246+ strncpy(ualg->cru_module_name, module_name(alg->cra_module),
31247+ sizeof(ualg->cru_module_name));
31248
31249+ ualg->cru_type = 0;
31250+ ualg->cru_mask = 0;
31251 ualg->cru_flags = alg->cra_flags;
31252 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
31253
31254@@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
31255 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
31256 struct crypto_report_larval rl;
31257
31258- snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
31259-
31260+ strncpy(rl.type, "larval", sizeof(rl.type));
31261 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
31262 sizeof(struct crypto_report_larval), &rl))
31263 goto nla_put_failure;
31264@@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
31265 struct crypto_dump_info info;
31266 int err;
31267
31268- if (!p->cru_driver_name)
31269+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31270+ return -EINVAL;
31271+
31272+ if (!p->cru_driver_name[0])
31273 return -EINVAL;
31274
31275 alg = crypto_alg_match(p, 1);
31276@@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31277 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31278 LIST_HEAD(list);
31279
31280+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31281+ return -EINVAL;
31282+
31283 if (priority && !strlen(p->cru_driver_name))
31284 return -EINVAL;
31285
31286@@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31287 struct crypto_alg *alg;
31288 struct crypto_user_alg *p = nlmsg_data(nlh);
31289
31290+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31291+ return -EINVAL;
31292+
31293 alg = crypto_alg_match(p, 1);
31294 if (!alg)
31295 return -ENOENT;
31296@@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
31297 struct crypto_user_alg *p = nlmsg_data(nlh);
31298 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
31299
31300+ if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
31301+ return -EINVAL;
31302+
31303 if (strlen(p->cru_driver_name))
31304 exact = 1;
31305
31306diff --git a/crypto/pcompress.c b/crypto/pcompress.c
31307index 04e083f..7140fe7 100644
31308--- a/crypto/pcompress.c
31309+++ b/crypto/pcompress.c
31310@@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
31311 {
31312 struct crypto_report_comp rpcomp;
31313
31314- snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
31315-
31316+ strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
31317 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
31318 sizeof(struct crypto_report_comp), &rpcomp))
31319 goto nla_put_failure;
31320diff --git a/crypto/rng.c b/crypto/rng.c
31321index f3b7894..e0a25c2 100644
31322--- a/crypto/rng.c
31323+++ b/crypto/rng.c
31324@@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
31325 {
31326 struct crypto_report_rng rrng;
31327
31328- snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
31329+ strncpy(rrng.type, "rng", sizeof(rrng.type));
31330
31331 rrng.seedsize = alg->cra_rng.seedsize;
31332
31333diff --git a/crypto/shash.c b/crypto/shash.c
31334index f426330f..929058a 100644
31335--- a/crypto/shash.c
31336+++ b/crypto/shash.c
31337@@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
31338 struct crypto_report_hash rhash;
31339 struct shash_alg *salg = __crypto_shash_alg(alg);
31340
31341- snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
31342+ strncpy(rhash.type, "shash", sizeof(rhash.type));
31343+
31344 rhash.blocksize = alg->cra_blocksize;
31345 rhash.digestsize = salg->digestsize;
31346
31347diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31348index f220d64..d359ad6 100644
31349--- a/drivers/acpi/apei/apei-internal.h
31350+++ b/drivers/acpi/apei/apei-internal.h
31351@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31352 struct apei_exec_ins_type {
31353 u32 flags;
31354 apei_exec_ins_func_t run;
31355-};
31356+} __do_const;
31357
31358 struct apei_exec_context {
31359 u32 ip;
31360diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31361index e6defd8..c26a225 100644
31362--- a/drivers/acpi/apei/cper.c
31363+++ b/drivers/acpi/apei/cper.c
31364@@ -38,12 +38,12 @@
31365 */
31366 u64 cper_next_record_id(void)
31367 {
31368- static atomic64_t seq;
31369+ static atomic64_unchecked_t seq;
31370
31371- if (!atomic64_read(&seq))
31372- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31373+ if (!atomic64_read_unchecked(&seq))
31374+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31375
31376- return atomic64_inc_return(&seq);
31377+ return atomic64_inc_return_unchecked(&seq);
31378 }
31379 EXPORT_SYMBOL_GPL(cper_next_record_id);
31380
31381diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31382index be60399..778b33e8 100644
31383--- a/drivers/acpi/bgrt.c
31384+++ b/drivers/acpi/bgrt.c
31385@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31386 return -ENODEV;
31387
31388 sysfs_bin_attr_init(&image_attr);
31389- image_attr.private = bgrt_image;
31390- image_attr.size = bgrt_image_size;
31391+ pax_open_kernel();
31392+ *(void **)&image_attr.private = bgrt_image;
31393+ *(size_t *)&image_attr.size = bgrt_image_size;
31394+ pax_close_kernel();
31395
31396 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31397 if (!bgrt_kobj)
31398diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31399index cb96296..b81293b 100644
31400--- a/drivers/acpi/blacklist.c
31401+++ b/drivers/acpi/blacklist.c
31402@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31403 u32 is_critical_error;
31404 };
31405
31406-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31407+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31408
31409 /*
31410 * POLICY: If *anything* doesn't work, put it on the blacklist.
31411@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31412 return 0;
31413 }
31414
31415-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31416+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31417 {
31418 .callback = dmi_disable_osi_vista,
31419 .ident = "Fujitsu Siemens",
31420diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31421index 7586544..636a2f0 100644
31422--- a/drivers/acpi/ec_sys.c
31423+++ b/drivers/acpi/ec_sys.c
31424@@ -12,6 +12,7 @@
31425 #include <linux/acpi.h>
31426 #include <linux/debugfs.h>
31427 #include <linux/module.h>
31428+#include <linux/uaccess.h>
31429 #include "internal.h"
31430
31431 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31432@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31433 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31434 */
31435 unsigned int size = EC_SPACE_SIZE;
31436- u8 *data = (u8 *) buf;
31437+ u8 data;
31438 loff_t init_off = *off;
31439 int err = 0;
31440
31441@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31442 size = count;
31443
31444 while (size) {
31445- err = ec_read(*off, &data[*off - init_off]);
31446+ err = ec_read(*off, &data);
31447 if (err)
31448 return err;
31449+ if (put_user(data, &buf[*off - init_off]))
31450+ return -EFAULT;
31451 *off += 1;
31452 size--;
31453 }
31454@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31455
31456 unsigned int size = count;
31457 loff_t init_off = *off;
31458- u8 *data = (u8 *) buf;
31459 int err = 0;
31460
31461 if (*off >= EC_SPACE_SIZE)
31462@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31463 }
31464
31465 while (size) {
31466- u8 byte_write = data[*off - init_off];
31467+ u8 byte_write;
31468+ if (get_user(byte_write, &buf[*off - init_off]))
31469+ return -EFAULT;
31470 err = ec_write(*off, byte_write);
31471 if (err)
31472 return err;
31473diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
31474index e83311b..142b5cc 100644
31475--- a/drivers/acpi/processor_driver.c
31476+++ b/drivers/acpi/processor_driver.c
31477@@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
31478 return 0;
31479 #endif
31480
31481- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
31482+ BUG_ON(pr->id >= nr_cpu_ids);
31483
31484 /*
31485 * Buggy BIOS check
31486diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31487index ed9a1cc..f4a354c 100644
31488--- a/drivers/acpi/processor_idle.c
31489+++ b/drivers/acpi/processor_idle.c
31490@@ -1005,7 +1005,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31491 {
31492 int i, count = CPUIDLE_DRIVER_STATE_START;
31493 struct acpi_processor_cx *cx;
31494- struct cpuidle_state *state;
31495+ cpuidle_state_no_const *state;
31496 struct cpuidle_driver *drv = &acpi_idle_driver;
31497
31498 if (!pr->flags.power_setup_done)
31499diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31500index ea61ca9..3fdd70d 100644
31501--- a/drivers/acpi/sysfs.c
31502+++ b/drivers/acpi/sysfs.c
31503@@ -420,11 +420,11 @@ static u32 num_counters;
31504 static struct attribute **all_attrs;
31505 static u32 acpi_gpe_count;
31506
31507-static struct attribute_group interrupt_stats_attr_group = {
31508+static attribute_group_no_const interrupt_stats_attr_group = {
31509 .name = "interrupts",
31510 };
31511
31512-static struct kobj_attribute *counter_attrs;
31513+static kobj_attribute_no_const *counter_attrs;
31514
31515 static void delete_gpe_attr_array(void)
31516 {
31517diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31518index 46cd3f4..0871ad0 100644
31519--- a/drivers/ata/libata-core.c
31520+++ b/drivers/ata/libata-core.c
31521@@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31522 struct ata_port *ap;
31523 unsigned int tag;
31524
31525- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31526+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31527 ap = qc->ap;
31528
31529 qc->flags = 0;
31530@@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
31531 struct ata_port *ap;
31532 struct ata_link *link;
31533
31534- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31535+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31536 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31537 ap = qc->ap;
31538 link = qc->dev->link;
31539@@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31540 return;
31541
31542 spin_lock(&lock);
31543+ pax_open_kernel();
31544
31545 for (cur = ops->inherits; cur; cur = cur->inherits) {
31546 void **inherit = (void **)cur;
31547@@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31548 if (IS_ERR(*pp))
31549 *pp = NULL;
31550
31551- ops->inherits = NULL;
31552+ *(struct ata_port_operations **)&ops->inherits = NULL;
31553
31554+ pax_close_kernel();
31555 spin_unlock(&lock);
31556 }
31557
31558diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31559index 405022d..fb70e53 100644
31560--- a/drivers/ata/pata_arasan_cf.c
31561+++ b/drivers/ata/pata_arasan_cf.c
31562@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31563 /* Handle platform specific quirks */
31564 if (pdata->quirk) {
31565 if (pdata->quirk & CF_BROKEN_PIO) {
31566- ap->ops->set_piomode = NULL;
31567+ pax_open_kernel();
31568+ *(void **)&ap->ops->set_piomode = NULL;
31569+ pax_close_kernel();
31570 ap->pio_mask = 0;
31571 }
31572 if (pdata->quirk & CF_BROKEN_MWDMA)
31573diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31574index f9b983a..887b9d8 100644
31575--- a/drivers/atm/adummy.c
31576+++ b/drivers/atm/adummy.c
31577@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31578 vcc->pop(vcc, skb);
31579 else
31580 dev_kfree_skb_any(skb);
31581- atomic_inc(&vcc->stats->tx);
31582+ atomic_inc_unchecked(&vcc->stats->tx);
31583
31584 return 0;
31585 }
31586diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31587index 77a7480..05cde58 100644
31588--- a/drivers/atm/ambassador.c
31589+++ b/drivers/atm/ambassador.c
31590@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31591 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31592
31593 // VC layer stats
31594- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31595+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31596
31597 // free the descriptor
31598 kfree (tx_descr);
31599@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31600 dump_skb ("<<<", vc, skb);
31601
31602 // VC layer stats
31603- atomic_inc(&atm_vcc->stats->rx);
31604+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31605 __net_timestamp(skb);
31606 // end of our responsibility
31607 atm_vcc->push (atm_vcc, skb);
31608@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31609 } else {
31610 PRINTK (KERN_INFO, "dropped over-size frame");
31611 // should we count this?
31612- atomic_inc(&atm_vcc->stats->rx_drop);
31613+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31614 }
31615
31616 } else {
31617@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31618 }
31619
31620 if (check_area (skb->data, skb->len)) {
31621- atomic_inc(&atm_vcc->stats->tx_err);
31622+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31623 return -ENOMEM; // ?
31624 }
31625
31626diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31627index b22d71c..d6e1049 100644
31628--- a/drivers/atm/atmtcp.c
31629+++ b/drivers/atm/atmtcp.c
31630@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31631 if (vcc->pop) vcc->pop(vcc,skb);
31632 else dev_kfree_skb(skb);
31633 if (dev_data) return 0;
31634- atomic_inc(&vcc->stats->tx_err);
31635+ atomic_inc_unchecked(&vcc->stats->tx_err);
31636 return -ENOLINK;
31637 }
31638 size = skb->len+sizeof(struct atmtcp_hdr);
31639@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31640 if (!new_skb) {
31641 if (vcc->pop) vcc->pop(vcc,skb);
31642 else dev_kfree_skb(skb);
31643- atomic_inc(&vcc->stats->tx_err);
31644+ atomic_inc_unchecked(&vcc->stats->tx_err);
31645 return -ENOBUFS;
31646 }
31647 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31648@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31649 if (vcc->pop) vcc->pop(vcc,skb);
31650 else dev_kfree_skb(skb);
31651 out_vcc->push(out_vcc,new_skb);
31652- atomic_inc(&vcc->stats->tx);
31653- atomic_inc(&out_vcc->stats->rx);
31654+ atomic_inc_unchecked(&vcc->stats->tx);
31655+ atomic_inc_unchecked(&out_vcc->stats->rx);
31656 return 0;
31657 }
31658
31659@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31660 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31661 read_unlock(&vcc_sklist_lock);
31662 if (!out_vcc) {
31663- atomic_inc(&vcc->stats->tx_err);
31664+ atomic_inc_unchecked(&vcc->stats->tx_err);
31665 goto done;
31666 }
31667 skb_pull(skb,sizeof(struct atmtcp_hdr));
31668@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31669 __net_timestamp(new_skb);
31670 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31671 out_vcc->push(out_vcc,new_skb);
31672- atomic_inc(&vcc->stats->tx);
31673- atomic_inc(&out_vcc->stats->rx);
31674+ atomic_inc_unchecked(&vcc->stats->tx);
31675+ atomic_inc_unchecked(&out_vcc->stats->rx);
31676 done:
31677 if (vcc->pop) vcc->pop(vcc,skb);
31678 else dev_kfree_skb(skb);
31679diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31680index c1eb6fa..4c71be9 100644
31681--- a/drivers/atm/eni.c
31682+++ b/drivers/atm/eni.c
31683@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31684 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31685 vcc->dev->number);
31686 length = 0;
31687- atomic_inc(&vcc->stats->rx_err);
31688+ atomic_inc_unchecked(&vcc->stats->rx_err);
31689 }
31690 else {
31691 length = ATM_CELL_SIZE-1; /* no HEC */
31692@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31693 size);
31694 }
31695 eff = length = 0;
31696- atomic_inc(&vcc->stats->rx_err);
31697+ atomic_inc_unchecked(&vcc->stats->rx_err);
31698 }
31699 else {
31700 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31701@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31702 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31703 vcc->dev->number,vcc->vci,length,size << 2,descr);
31704 length = eff = 0;
31705- atomic_inc(&vcc->stats->rx_err);
31706+ atomic_inc_unchecked(&vcc->stats->rx_err);
31707 }
31708 }
31709 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31710@@ -767,7 +767,7 @@ rx_dequeued++;
31711 vcc->push(vcc,skb);
31712 pushed++;
31713 }
31714- atomic_inc(&vcc->stats->rx);
31715+ atomic_inc_unchecked(&vcc->stats->rx);
31716 }
31717 wake_up(&eni_dev->rx_wait);
31718 }
31719@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31720 PCI_DMA_TODEVICE);
31721 if (vcc->pop) vcc->pop(vcc,skb);
31722 else dev_kfree_skb_irq(skb);
31723- atomic_inc(&vcc->stats->tx);
31724+ atomic_inc_unchecked(&vcc->stats->tx);
31725 wake_up(&eni_dev->tx_wait);
31726 dma_complete++;
31727 }
31728diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31729index b41c948..a002b17 100644
31730--- a/drivers/atm/firestream.c
31731+++ b/drivers/atm/firestream.c
31732@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31733 }
31734 }
31735
31736- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31737+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31738
31739 fs_dprintk (FS_DEBUG_TXMEM, "i");
31740 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31741@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31742 #endif
31743 skb_put (skb, qe->p1 & 0xffff);
31744 ATM_SKB(skb)->vcc = atm_vcc;
31745- atomic_inc(&atm_vcc->stats->rx);
31746+ atomic_inc_unchecked(&atm_vcc->stats->rx);
31747 __net_timestamp(skb);
31748 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31749 atm_vcc->push (atm_vcc, skb);
31750@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31751 kfree (pe);
31752 }
31753 if (atm_vcc)
31754- atomic_inc(&atm_vcc->stats->rx_drop);
31755+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31756 break;
31757 case 0x1f: /* Reassembly abort: no buffers. */
31758 /* Silently increment error counter. */
31759 if (atm_vcc)
31760- atomic_inc(&atm_vcc->stats->rx_drop);
31761+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31762 break;
31763 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31764 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31765diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31766index 204814e..cede831 100644
31767--- a/drivers/atm/fore200e.c
31768+++ b/drivers/atm/fore200e.c
31769@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31770 #endif
31771 /* check error condition */
31772 if (*entry->status & STATUS_ERROR)
31773- atomic_inc(&vcc->stats->tx_err);
31774+ atomic_inc_unchecked(&vcc->stats->tx_err);
31775 else
31776- atomic_inc(&vcc->stats->tx);
31777+ atomic_inc_unchecked(&vcc->stats->tx);
31778 }
31779 }
31780
31781@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31782 if (skb == NULL) {
31783 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31784
31785- atomic_inc(&vcc->stats->rx_drop);
31786+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31787 return -ENOMEM;
31788 }
31789
31790@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31791
31792 dev_kfree_skb_any(skb);
31793
31794- atomic_inc(&vcc->stats->rx_drop);
31795+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31796 return -ENOMEM;
31797 }
31798
31799 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31800
31801 vcc->push(vcc, skb);
31802- atomic_inc(&vcc->stats->rx);
31803+ atomic_inc_unchecked(&vcc->stats->rx);
31804
31805 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31806
31807@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31808 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31809 fore200e->atm_dev->number,
31810 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31811- atomic_inc(&vcc->stats->rx_err);
31812+ atomic_inc_unchecked(&vcc->stats->rx_err);
31813 }
31814 }
31815
31816@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31817 goto retry_here;
31818 }
31819
31820- atomic_inc(&vcc->stats->tx_err);
31821+ atomic_inc_unchecked(&vcc->stats->tx_err);
31822
31823 fore200e->tx_sat++;
31824 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31825diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31826index 72b6960..cf9167a 100644
31827--- a/drivers/atm/he.c
31828+++ b/drivers/atm/he.c
31829@@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31830
31831 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31832 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31833- atomic_inc(&vcc->stats->rx_drop);
31834+ atomic_inc_unchecked(&vcc->stats->rx_drop);
31835 goto return_host_buffers;
31836 }
31837
31838@@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31839 RBRQ_LEN_ERR(he_dev->rbrq_head)
31840 ? "LEN_ERR" : "",
31841 vcc->vpi, vcc->vci);
31842- atomic_inc(&vcc->stats->rx_err);
31843+ atomic_inc_unchecked(&vcc->stats->rx_err);
31844 goto return_host_buffers;
31845 }
31846
31847@@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31848 vcc->push(vcc, skb);
31849 spin_lock(&he_dev->global_lock);
31850
31851- atomic_inc(&vcc->stats->rx);
31852+ atomic_inc_unchecked(&vcc->stats->rx);
31853
31854 return_host_buffers:
31855 ++pdus_assembled;
31856@@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31857 tpd->vcc->pop(tpd->vcc, tpd->skb);
31858 else
31859 dev_kfree_skb_any(tpd->skb);
31860- atomic_inc(&tpd->vcc->stats->tx_err);
31861+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31862 }
31863 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31864 return;
31865@@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31866 vcc->pop(vcc, skb);
31867 else
31868 dev_kfree_skb_any(skb);
31869- atomic_inc(&vcc->stats->tx_err);
31870+ atomic_inc_unchecked(&vcc->stats->tx_err);
31871 return -EINVAL;
31872 }
31873
31874@@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31875 vcc->pop(vcc, skb);
31876 else
31877 dev_kfree_skb_any(skb);
31878- atomic_inc(&vcc->stats->tx_err);
31879+ atomic_inc_unchecked(&vcc->stats->tx_err);
31880 return -EINVAL;
31881 }
31882 #endif
31883@@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31884 vcc->pop(vcc, skb);
31885 else
31886 dev_kfree_skb_any(skb);
31887- atomic_inc(&vcc->stats->tx_err);
31888+ atomic_inc_unchecked(&vcc->stats->tx_err);
31889 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31890 return -ENOMEM;
31891 }
31892@@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31893 vcc->pop(vcc, skb);
31894 else
31895 dev_kfree_skb_any(skb);
31896- atomic_inc(&vcc->stats->tx_err);
31897+ atomic_inc_unchecked(&vcc->stats->tx_err);
31898 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31899 return -ENOMEM;
31900 }
31901@@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31902 __enqueue_tpd(he_dev, tpd, cid);
31903 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31904
31905- atomic_inc(&vcc->stats->tx);
31906+ atomic_inc_unchecked(&vcc->stats->tx);
31907
31908 return 0;
31909 }
31910diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31911index 1dc0519..1aadaf7 100644
31912--- a/drivers/atm/horizon.c
31913+++ b/drivers/atm/horizon.c
31914@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31915 {
31916 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31917 // VC layer stats
31918- atomic_inc(&vcc->stats->rx);
31919+ atomic_inc_unchecked(&vcc->stats->rx);
31920 __net_timestamp(skb);
31921 // end of our responsibility
31922 vcc->push (vcc, skb);
31923@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31924 dev->tx_iovec = NULL;
31925
31926 // VC layer stats
31927- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31928+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31929
31930 // free the skb
31931 hrz_kfree_skb (skb);
31932diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31933index 272f009..a18ba55 100644
31934--- a/drivers/atm/idt77252.c
31935+++ b/drivers/atm/idt77252.c
31936@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31937 else
31938 dev_kfree_skb(skb);
31939
31940- atomic_inc(&vcc->stats->tx);
31941+ atomic_inc_unchecked(&vcc->stats->tx);
31942 }
31943
31944 atomic_dec(&scq->used);
31945@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31946 if ((sb = dev_alloc_skb(64)) == NULL) {
31947 printk("%s: Can't allocate buffers for aal0.\n",
31948 card->name);
31949- atomic_add(i, &vcc->stats->rx_drop);
31950+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
31951 break;
31952 }
31953 if (!atm_charge(vcc, sb->truesize)) {
31954 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31955 card->name);
31956- atomic_add(i - 1, &vcc->stats->rx_drop);
31957+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31958 dev_kfree_skb(sb);
31959 break;
31960 }
31961@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31962 ATM_SKB(sb)->vcc = vcc;
31963 __net_timestamp(sb);
31964 vcc->push(vcc, sb);
31965- atomic_inc(&vcc->stats->rx);
31966+ atomic_inc_unchecked(&vcc->stats->rx);
31967
31968 cell += ATM_CELL_PAYLOAD;
31969 }
31970@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31971 "(CDC: %08x)\n",
31972 card->name, len, rpp->len, readl(SAR_REG_CDC));
31973 recycle_rx_pool_skb(card, rpp);
31974- atomic_inc(&vcc->stats->rx_err);
31975+ atomic_inc_unchecked(&vcc->stats->rx_err);
31976 return;
31977 }
31978 if (stat & SAR_RSQE_CRC) {
31979 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31980 recycle_rx_pool_skb(card, rpp);
31981- atomic_inc(&vcc->stats->rx_err);
31982+ atomic_inc_unchecked(&vcc->stats->rx_err);
31983 return;
31984 }
31985 if (skb_queue_len(&rpp->queue) > 1) {
31986@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31987 RXPRINTK("%s: Can't alloc RX skb.\n",
31988 card->name);
31989 recycle_rx_pool_skb(card, rpp);
31990- atomic_inc(&vcc->stats->rx_err);
31991+ atomic_inc_unchecked(&vcc->stats->rx_err);
31992 return;
31993 }
31994 if (!atm_charge(vcc, skb->truesize)) {
31995@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31996 __net_timestamp(skb);
31997
31998 vcc->push(vcc, skb);
31999- atomic_inc(&vcc->stats->rx);
32000+ atomic_inc_unchecked(&vcc->stats->rx);
32001
32002 return;
32003 }
32004@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32005 __net_timestamp(skb);
32006
32007 vcc->push(vcc, skb);
32008- atomic_inc(&vcc->stats->rx);
32009+ atomic_inc_unchecked(&vcc->stats->rx);
32010
32011 if (skb->truesize > SAR_FB_SIZE_3)
32012 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32013@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32014 if (vcc->qos.aal != ATM_AAL0) {
32015 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32016 card->name, vpi, vci);
32017- atomic_inc(&vcc->stats->rx_drop);
32018+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32019 goto drop;
32020 }
32021
32022 if ((sb = dev_alloc_skb(64)) == NULL) {
32023 printk("%s: Can't allocate buffers for AAL0.\n",
32024 card->name);
32025- atomic_inc(&vcc->stats->rx_err);
32026+ atomic_inc_unchecked(&vcc->stats->rx_err);
32027 goto drop;
32028 }
32029
32030@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32031 ATM_SKB(sb)->vcc = vcc;
32032 __net_timestamp(sb);
32033 vcc->push(vcc, sb);
32034- atomic_inc(&vcc->stats->rx);
32035+ atomic_inc_unchecked(&vcc->stats->rx);
32036
32037 drop:
32038 skb_pull(queue, 64);
32039@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32040
32041 if (vc == NULL) {
32042 printk("%s: NULL connection in send().\n", card->name);
32043- atomic_inc(&vcc->stats->tx_err);
32044+ atomic_inc_unchecked(&vcc->stats->tx_err);
32045 dev_kfree_skb(skb);
32046 return -EINVAL;
32047 }
32048 if (!test_bit(VCF_TX, &vc->flags)) {
32049 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32050- atomic_inc(&vcc->stats->tx_err);
32051+ atomic_inc_unchecked(&vcc->stats->tx_err);
32052 dev_kfree_skb(skb);
32053 return -EINVAL;
32054 }
32055@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32056 break;
32057 default:
32058 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32059- atomic_inc(&vcc->stats->tx_err);
32060+ atomic_inc_unchecked(&vcc->stats->tx_err);
32061 dev_kfree_skb(skb);
32062 return -EINVAL;
32063 }
32064
32065 if (skb_shinfo(skb)->nr_frags != 0) {
32066 printk("%s: No scatter-gather yet.\n", card->name);
32067- atomic_inc(&vcc->stats->tx_err);
32068+ atomic_inc_unchecked(&vcc->stats->tx_err);
32069 dev_kfree_skb(skb);
32070 return -EINVAL;
32071 }
32072@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32073
32074 err = queue_skb(card, vc, skb, oam);
32075 if (err) {
32076- atomic_inc(&vcc->stats->tx_err);
32077+ atomic_inc_unchecked(&vcc->stats->tx_err);
32078 dev_kfree_skb(skb);
32079 return err;
32080 }
32081@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32082 skb = dev_alloc_skb(64);
32083 if (!skb) {
32084 printk("%s: Out of memory in send_oam().\n", card->name);
32085- atomic_inc(&vcc->stats->tx_err);
32086+ atomic_inc_unchecked(&vcc->stats->tx_err);
32087 return -ENOMEM;
32088 }
32089 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32090diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32091index 4217f29..88f547a 100644
32092--- a/drivers/atm/iphase.c
32093+++ b/drivers/atm/iphase.c
32094@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32095 status = (u_short) (buf_desc_ptr->desc_mode);
32096 if (status & (RX_CER | RX_PTE | RX_OFL))
32097 {
32098- atomic_inc(&vcc->stats->rx_err);
32099+ atomic_inc_unchecked(&vcc->stats->rx_err);
32100 IF_ERR(printk("IA: bad packet, dropping it");)
32101 if (status & RX_CER) {
32102 IF_ERR(printk(" cause: packet CRC error\n");)
32103@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32104 len = dma_addr - buf_addr;
32105 if (len > iadev->rx_buf_sz) {
32106 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32107- atomic_inc(&vcc->stats->rx_err);
32108+ atomic_inc_unchecked(&vcc->stats->rx_err);
32109 goto out_free_desc;
32110 }
32111
32112@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32113 ia_vcc = INPH_IA_VCC(vcc);
32114 if (ia_vcc == NULL)
32115 {
32116- atomic_inc(&vcc->stats->rx_err);
32117+ atomic_inc_unchecked(&vcc->stats->rx_err);
32118 atm_return(vcc, skb->truesize);
32119 dev_kfree_skb_any(skb);
32120 goto INCR_DLE;
32121@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32122 if ((length > iadev->rx_buf_sz) || (length >
32123 (skb->len - sizeof(struct cpcs_trailer))))
32124 {
32125- atomic_inc(&vcc->stats->rx_err);
32126+ atomic_inc_unchecked(&vcc->stats->rx_err);
32127 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32128 length, skb->len);)
32129 atm_return(vcc, skb->truesize);
32130@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32131
32132 IF_RX(printk("rx_dle_intr: skb push");)
32133 vcc->push(vcc,skb);
32134- atomic_inc(&vcc->stats->rx);
32135+ atomic_inc_unchecked(&vcc->stats->rx);
32136 iadev->rx_pkt_cnt++;
32137 }
32138 INCR_DLE:
32139@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32140 {
32141 struct k_sonet_stats *stats;
32142 stats = &PRIV(_ia_dev[board])->sonet_stats;
32143- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32144- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32145- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32146- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32147- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32148- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32149- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32150- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32151- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32152+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32153+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32154+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32155+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32156+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32157+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32158+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32159+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32160+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32161 }
32162 ia_cmds.status = 0;
32163 break;
32164@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32165 if ((desc == 0) || (desc > iadev->num_tx_desc))
32166 {
32167 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32168- atomic_inc(&vcc->stats->tx);
32169+ atomic_inc_unchecked(&vcc->stats->tx);
32170 if (vcc->pop)
32171 vcc->pop(vcc, skb);
32172 else
32173@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32174 ATM_DESC(skb) = vcc->vci;
32175 skb_queue_tail(&iadev->tx_dma_q, skb);
32176
32177- atomic_inc(&vcc->stats->tx);
32178+ atomic_inc_unchecked(&vcc->stats->tx);
32179 iadev->tx_pkt_cnt++;
32180 /* Increment transaction counter */
32181 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32182
32183 #if 0
32184 /* add flow control logic */
32185- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32186+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32187 if (iavcc->vc_desc_cnt > 10) {
32188 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32189 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32190diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32191index fa7d701..1e404c7 100644
32192--- a/drivers/atm/lanai.c
32193+++ b/drivers/atm/lanai.c
32194@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32195 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32196 lanai_endtx(lanai, lvcc);
32197 lanai_free_skb(lvcc->tx.atmvcc, skb);
32198- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32199+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32200 }
32201
32202 /* Try to fill the buffer - don't call unless there is backlog */
32203@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32204 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32205 __net_timestamp(skb);
32206 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32207- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32208+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32209 out:
32210 lvcc->rx.buf.ptr = end;
32211 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32212@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32213 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32214 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32215 lanai->stats.service_rxnotaal5++;
32216- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32217+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32218 return 0;
32219 }
32220 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32221@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32222 int bytes;
32223 read_unlock(&vcc_sklist_lock);
32224 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32225- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32226+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32227 lvcc->stats.x.aal5.service_trash++;
32228 bytes = (SERVICE_GET_END(s) * 16) -
32229 (((unsigned long) lvcc->rx.buf.ptr) -
32230@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32231 }
32232 if (s & SERVICE_STREAM) {
32233 read_unlock(&vcc_sklist_lock);
32234- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32235+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32236 lvcc->stats.x.aal5.service_stream++;
32237 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32238 "PDU on VCI %d!\n", lanai->number, vci);
32239@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32240 return 0;
32241 }
32242 DPRINTK("got rx crc error on vci %d\n", vci);
32243- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32244+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32245 lvcc->stats.x.aal5.service_rxcrc++;
32246 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32247 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32248diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32249index ed1d2b7..8cffc1f 100644
32250--- a/drivers/atm/nicstar.c
32251+++ b/drivers/atm/nicstar.c
32252@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32253 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32254 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32255 card->index);
32256- atomic_inc(&vcc->stats->tx_err);
32257+ atomic_inc_unchecked(&vcc->stats->tx_err);
32258 dev_kfree_skb_any(skb);
32259 return -EINVAL;
32260 }
32261@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32262 if (!vc->tx) {
32263 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32264 card->index);
32265- atomic_inc(&vcc->stats->tx_err);
32266+ atomic_inc_unchecked(&vcc->stats->tx_err);
32267 dev_kfree_skb_any(skb);
32268 return -EINVAL;
32269 }
32270@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32271 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32272 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32273 card->index);
32274- atomic_inc(&vcc->stats->tx_err);
32275+ atomic_inc_unchecked(&vcc->stats->tx_err);
32276 dev_kfree_skb_any(skb);
32277 return -EINVAL;
32278 }
32279
32280 if (skb_shinfo(skb)->nr_frags != 0) {
32281 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32282- atomic_inc(&vcc->stats->tx_err);
32283+ atomic_inc_unchecked(&vcc->stats->tx_err);
32284 dev_kfree_skb_any(skb);
32285 return -EINVAL;
32286 }
32287@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32288 }
32289
32290 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32291- atomic_inc(&vcc->stats->tx_err);
32292+ atomic_inc_unchecked(&vcc->stats->tx_err);
32293 dev_kfree_skb_any(skb);
32294 return -EIO;
32295 }
32296- atomic_inc(&vcc->stats->tx);
32297+ atomic_inc_unchecked(&vcc->stats->tx);
32298
32299 return 0;
32300 }
32301@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32302 printk
32303 ("nicstar%d: Can't allocate buffers for aal0.\n",
32304 card->index);
32305- atomic_add(i, &vcc->stats->rx_drop);
32306+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32307 break;
32308 }
32309 if (!atm_charge(vcc, sb->truesize)) {
32310 RXPRINTK
32311 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32312 card->index);
32313- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32314+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32315 dev_kfree_skb_any(sb);
32316 break;
32317 }
32318@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32319 ATM_SKB(sb)->vcc = vcc;
32320 __net_timestamp(sb);
32321 vcc->push(vcc, sb);
32322- atomic_inc(&vcc->stats->rx);
32323+ atomic_inc_unchecked(&vcc->stats->rx);
32324 cell += ATM_CELL_PAYLOAD;
32325 }
32326
32327@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32328 if (iovb == NULL) {
32329 printk("nicstar%d: Out of iovec buffers.\n",
32330 card->index);
32331- atomic_inc(&vcc->stats->rx_drop);
32332+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32333 recycle_rx_buf(card, skb);
32334 return;
32335 }
32336@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32337 small or large buffer itself. */
32338 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32339 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32340- atomic_inc(&vcc->stats->rx_err);
32341+ atomic_inc_unchecked(&vcc->stats->rx_err);
32342 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32343 NS_MAX_IOVECS);
32344 NS_PRV_IOVCNT(iovb) = 0;
32345@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32346 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32347 card->index);
32348 which_list(card, skb);
32349- atomic_inc(&vcc->stats->rx_err);
32350+ atomic_inc_unchecked(&vcc->stats->rx_err);
32351 recycle_rx_buf(card, skb);
32352 vc->rx_iov = NULL;
32353 recycle_iov_buf(card, iovb);
32354@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32355 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32356 card->index);
32357 which_list(card, skb);
32358- atomic_inc(&vcc->stats->rx_err);
32359+ atomic_inc_unchecked(&vcc->stats->rx_err);
32360 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32361 NS_PRV_IOVCNT(iovb));
32362 vc->rx_iov = NULL;
32363@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32364 printk(" - PDU size mismatch.\n");
32365 else
32366 printk(".\n");
32367- atomic_inc(&vcc->stats->rx_err);
32368+ atomic_inc_unchecked(&vcc->stats->rx_err);
32369 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32370 NS_PRV_IOVCNT(iovb));
32371 vc->rx_iov = NULL;
32372@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32373 /* skb points to a small buffer */
32374 if (!atm_charge(vcc, skb->truesize)) {
32375 push_rxbufs(card, skb);
32376- atomic_inc(&vcc->stats->rx_drop);
32377+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32378 } else {
32379 skb_put(skb, len);
32380 dequeue_sm_buf(card, skb);
32381@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32382 ATM_SKB(skb)->vcc = vcc;
32383 __net_timestamp(skb);
32384 vcc->push(vcc, skb);
32385- atomic_inc(&vcc->stats->rx);
32386+ atomic_inc_unchecked(&vcc->stats->rx);
32387 }
32388 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32389 struct sk_buff *sb;
32390@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32391 if (len <= NS_SMBUFSIZE) {
32392 if (!atm_charge(vcc, sb->truesize)) {
32393 push_rxbufs(card, sb);
32394- atomic_inc(&vcc->stats->rx_drop);
32395+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32396 } else {
32397 skb_put(sb, len);
32398 dequeue_sm_buf(card, sb);
32399@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32400 ATM_SKB(sb)->vcc = vcc;
32401 __net_timestamp(sb);
32402 vcc->push(vcc, sb);
32403- atomic_inc(&vcc->stats->rx);
32404+ atomic_inc_unchecked(&vcc->stats->rx);
32405 }
32406
32407 push_rxbufs(card, skb);
32408@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32409
32410 if (!atm_charge(vcc, skb->truesize)) {
32411 push_rxbufs(card, skb);
32412- atomic_inc(&vcc->stats->rx_drop);
32413+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32414 } else {
32415 dequeue_lg_buf(card, skb);
32416 #ifdef NS_USE_DESTRUCTORS
32417@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32418 ATM_SKB(skb)->vcc = vcc;
32419 __net_timestamp(skb);
32420 vcc->push(vcc, skb);
32421- atomic_inc(&vcc->stats->rx);
32422+ atomic_inc_unchecked(&vcc->stats->rx);
32423 }
32424
32425 push_rxbufs(card, sb);
32426@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32427 printk
32428 ("nicstar%d: Out of huge buffers.\n",
32429 card->index);
32430- atomic_inc(&vcc->stats->rx_drop);
32431+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32432 recycle_iovec_rx_bufs(card,
32433 (struct iovec *)
32434 iovb->data,
32435@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32436 card->hbpool.count++;
32437 } else
32438 dev_kfree_skb_any(hb);
32439- atomic_inc(&vcc->stats->rx_drop);
32440+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32441 } else {
32442 /* Copy the small buffer to the huge buffer */
32443 sb = (struct sk_buff *)iov->iov_base;
32444@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32445 #endif /* NS_USE_DESTRUCTORS */
32446 __net_timestamp(hb);
32447 vcc->push(vcc, hb);
32448- atomic_inc(&vcc->stats->rx);
32449+ atomic_inc_unchecked(&vcc->stats->rx);
32450 }
32451 }
32452
32453diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32454index 0474a89..06ea4a1 100644
32455--- a/drivers/atm/solos-pci.c
32456+++ b/drivers/atm/solos-pci.c
32457@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32458 }
32459 atm_charge(vcc, skb->truesize);
32460 vcc->push(vcc, skb);
32461- atomic_inc(&vcc->stats->rx);
32462+ atomic_inc_unchecked(&vcc->stats->rx);
32463 break;
32464
32465 case PKT_STATUS:
32466@@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32467 vcc = SKB_CB(oldskb)->vcc;
32468
32469 if (vcc) {
32470- atomic_inc(&vcc->stats->tx);
32471+ atomic_inc_unchecked(&vcc->stats->tx);
32472 solos_pop(vcc, oldskb);
32473 } else {
32474 dev_kfree_skb_irq(oldskb);
32475diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32476index 0215934..ce9f5b1 100644
32477--- a/drivers/atm/suni.c
32478+++ b/drivers/atm/suni.c
32479@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32480
32481
32482 #define ADD_LIMITED(s,v) \
32483- atomic_add((v),&stats->s); \
32484- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32485+ atomic_add_unchecked((v),&stats->s); \
32486+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32487
32488
32489 static void suni_hz(unsigned long from_timer)
32490diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32491index 5120a96..e2572bd 100644
32492--- a/drivers/atm/uPD98402.c
32493+++ b/drivers/atm/uPD98402.c
32494@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32495 struct sonet_stats tmp;
32496 int error = 0;
32497
32498- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32499+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32500 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32501 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32502 if (zero && !error) {
32503@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32504
32505
32506 #define ADD_LIMITED(s,v) \
32507- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32508- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32509- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32510+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32511+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32512+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32513
32514
32515 static void stat_event(struct atm_dev *dev)
32516@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32517 if (reason & uPD98402_INT_PFM) stat_event(dev);
32518 if (reason & uPD98402_INT_PCO) {
32519 (void) GET(PCOCR); /* clear interrupt cause */
32520- atomic_add(GET(HECCT),
32521+ atomic_add_unchecked(GET(HECCT),
32522 &PRIV(dev)->sonet_stats.uncorr_hcs);
32523 }
32524 if ((reason & uPD98402_INT_RFO) &&
32525@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32526 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
32527 uPD98402_INT_LOS),PIMR); /* enable them */
32528 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
32529- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32530- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
32531- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
32532+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
32533+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
32534+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32535 return 0;
32536 }
32537
32538diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32539index 969c3c2..9b72956 100644
32540--- a/drivers/atm/zatm.c
32541+++ b/drivers/atm/zatm.c
32542@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32543 }
32544 if (!size) {
32545 dev_kfree_skb_irq(skb);
32546- if (vcc) atomic_inc(&vcc->stats->rx_err);
32547+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32548 continue;
32549 }
32550 if (!atm_charge(vcc,skb->truesize)) {
32551@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32552 skb->len = size;
32553 ATM_SKB(skb)->vcc = vcc;
32554 vcc->push(vcc,skb);
32555- atomic_inc(&vcc->stats->rx);
32556+ atomic_inc_unchecked(&vcc->stats->rx);
32557 }
32558 zout(pos & 0xffff,MTA(mbx));
32559 #if 0 /* probably a stupid idea */
32560@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32561 skb_queue_head(&zatm_vcc->backlog,skb);
32562 break;
32563 }
32564- atomic_inc(&vcc->stats->tx);
32565+ atomic_inc_unchecked(&vcc->stats->tx);
32566 wake_up(&zatm_vcc->tx_wait);
32567 }
32568
32569diff --git a/drivers/base/bus.c b/drivers/base/bus.c
32570index 6856303..0602d70 100644
32571--- a/drivers/base/bus.c
32572+++ b/drivers/base/bus.c
32573@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
32574 return -EINVAL;
32575
32576 mutex_lock(&subsys->p->mutex);
32577- list_add_tail(&sif->node, &subsys->p->interfaces);
32578+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
32579 if (sif->add_dev) {
32580 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32581 while ((dev = subsys_dev_iter_next(&iter)))
32582@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
32583 subsys = sif->subsys;
32584
32585 mutex_lock(&subsys->p->mutex);
32586- list_del_init(&sif->node);
32587+ pax_list_del_init((struct list_head *)&sif->node);
32588 if (sif->remove_dev) {
32589 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
32590 while ((dev = subsys_dev_iter_next(&iter)))
32591diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32592index 17cf7ca..7e553e1 100644
32593--- a/drivers/base/devtmpfs.c
32594+++ b/drivers/base/devtmpfs.c
32595@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32596 if (!thread)
32597 return 0;
32598
32599- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32600+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32601 if (err)
32602 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32603 else
32604diff --git a/drivers/base/node.c b/drivers/base/node.c
32605index fac124a..66bd4ab 100644
32606--- a/drivers/base/node.c
32607+++ b/drivers/base/node.c
32608@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
32609 struct node_attr {
32610 struct device_attribute attr;
32611 enum node_states state;
32612-};
32613+} __do_const;
32614
32615 static ssize_t show_node_state(struct device *dev,
32616 struct device_attribute *attr, char *buf)
32617diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
32618index acc3a8d..981c236 100644
32619--- a/drivers/base/power/domain.c
32620+++ b/drivers/base/power/domain.c
32621@@ -1851,7 +1851,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
32622 {
32623 struct cpuidle_driver *cpuidle_drv;
32624 struct gpd_cpu_data *cpu_data;
32625- struct cpuidle_state *idle_state;
32626+ cpuidle_state_no_const *idle_state;
32627 int ret = 0;
32628
32629 if (IS_ERR_OR_NULL(genpd) || state < 0)
32630@@ -1919,7 +1919,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
32631 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
32632 {
32633 struct gpd_cpu_data *cpu_data;
32634- struct cpuidle_state *idle_state;
32635+ cpuidle_state_no_const *idle_state;
32636 int ret = 0;
32637
32638 if (IS_ERR_OR_NULL(genpd))
32639diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32640index e6ee5e8..98ad7fc 100644
32641--- a/drivers/base/power/wakeup.c
32642+++ b/drivers/base/power/wakeup.c
32643@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32644 * They need to be modified together atomically, so it's better to use one
32645 * atomic variable to hold them both.
32646 */
32647-static atomic_t combined_event_count = ATOMIC_INIT(0);
32648+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32649
32650 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32651 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32652
32653 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32654 {
32655- unsigned int comb = atomic_read(&combined_event_count);
32656+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
32657
32658 *cnt = (comb >> IN_PROGRESS_BITS);
32659 *inpr = comb & MAX_IN_PROGRESS;
32660@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32661 ws->start_prevent_time = ws->last_time;
32662
32663 /* Increment the counter of events in progress. */
32664- cec = atomic_inc_return(&combined_event_count);
32665+ cec = atomic_inc_return_unchecked(&combined_event_count);
32666
32667 trace_wakeup_source_activate(ws->name, cec);
32668 }
32669@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32670 * Increment the counter of registered wakeup events and decrement the
32671 * couter of wakeup events in progress simultaneously.
32672 */
32673- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32674+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32675 trace_wakeup_source_deactivate(ws->name, cec);
32676
32677 split_counters(&cnt, &inpr);
32678diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
32679index e8d11b6..7b1b36f 100644
32680--- a/drivers/base/syscore.c
32681+++ b/drivers/base/syscore.c
32682@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
32683 void register_syscore_ops(struct syscore_ops *ops)
32684 {
32685 mutex_lock(&syscore_ops_lock);
32686- list_add_tail(&ops->node, &syscore_ops_list);
32687+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
32688 mutex_unlock(&syscore_ops_lock);
32689 }
32690 EXPORT_SYMBOL_GPL(register_syscore_ops);
32691@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
32692 void unregister_syscore_ops(struct syscore_ops *ops)
32693 {
32694 mutex_lock(&syscore_ops_lock);
32695- list_del(&ops->node);
32696+ pax_list_del((struct list_head *)&ops->node);
32697 mutex_unlock(&syscore_ops_lock);
32698 }
32699 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
32700diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32701index ade58bc..867143d 100644
32702--- a/drivers/block/cciss.c
32703+++ b/drivers/block/cciss.c
32704@@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32705 int err;
32706 u32 cp;
32707
32708+ memset(&arg64, 0, sizeof(arg64));
32709+
32710 err = 0;
32711 err |=
32712 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32713@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32714 while (!list_empty(&h->reqQ)) {
32715 c = list_entry(h->reqQ.next, CommandList_struct, list);
32716 /* can't do anything if fifo is full */
32717- if ((h->access.fifo_full(h))) {
32718+ if ((h->access->fifo_full(h))) {
32719 dev_warn(&h->pdev->dev, "fifo full\n");
32720 break;
32721 }
32722@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32723 h->Qdepth--;
32724
32725 /* Tell the controller execute command */
32726- h->access.submit_command(h, c);
32727+ h->access->submit_command(h, c);
32728
32729 /* Put job onto the completed Q */
32730 addQ(&h->cmpQ, c);
32731@@ -3441,17 +3443,17 @@ startio:
32732
32733 static inline unsigned long get_next_completion(ctlr_info_t *h)
32734 {
32735- return h->access.command_completed(h);
32736+ return h->access->command_completed(h);
32737 }
32738
32739 static inline int interrupt_pending(ctlr_info_t *h)
32740 {
32741- return h->access.intr_pending(h);
32742+ return h->access->intr_pending(h);
32743 }
32744
32745 static inline long interrupt_not_for_us(ctlr_info_t *h)
32746 {
32747- return ((h->access.intr_pending(h) == 0) ||
32748+ return ((h->access->intr_pending(h) == 0) ||
32749 (h->interrupts_enabled == 0));
32750 }
32751
32752@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32753 u32 a;
32754
32755 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32756- return h->access.command_completed(h);
32757+ return h->access->command_completed(h);
32758
32759 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32760 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32761@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32762 trans_support & CFGTBL_Trans_use_short_tags);
32763
32764 /* Change the access methods to the performant access methods */
32765- h->access = SA5_performant_access;
32766+ h->access = &SA5_performant_access;
32767 h->transMethod = CFGTBL_Trans_Performant;
32768
32769 return;
32770@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32771 if (prod_index < 0)
32772 return -ENODEV;
32773 h->product_name = products[prod_index].product_name;
32774- h->access = *(products[prod_index].access);
32775+ h->access = products[prod_index].access;
32776
32777 if (cciss_board_disabled(h)) {
32778 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32779@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32780 }
32781
32782 /* make sure the board interrupts are off */
32783- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32784+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32785 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32786 if (rc)
32787 goto clean2;
32788@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32789 * fake ones to scoop up any residual completions.
32790 */
32791 spin_lock_irqsave(&h->lock, flags);
32792- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32793+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32794 spin_unlock_irqrestore(&h->lock, flags);
32795 free_irq(h->intr[h->intr_mode], h);
32796 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32797@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32798 dev_info(&h->pdev->dev, "Board READY.\n");
32799 dev_info(&h->pdev->dev,
32800 "Waiting for stale completions to drain.\n");
32801- h->access.set_intr_mask(h, CCISS_INTR_ON);
32802+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32803 msleep(10000);
32804- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32805+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32806
32807 rc = controller_reset_failed(h->cfgtable);
32808 if (rc)
32809@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32810 cciss_scsi_setup(h);
32811
32812 /* Turn the interrupts on so we can service requests */
32813- h->access.set_intr_mask(h, CCISS_INTR_ON);
32814+ h->access->set_intr_mask(h, CCISS_INTR_ON);
32815
32816 /* Get the firmware version */
32817 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32818@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32819 kfree(flush_buf);
32820 if (return_code != IO_OK)
32821 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32822- h->access.set_intr_mask(h, CCISS_INTR_OFF);
32823+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
32824 free_irq(h->intr[h->intr_mode], h);
32825 }
32826
32827diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32828index 7fda30e..eb5dfe0 100644
32829--- a/drivers/block/cciss.h
32830+++ b/drivers/block/cciss.h
32831@@ -101,7 +101,7 @@ struct ctlr_info
32832 /* information about each logical volume */
32833 drive_info_struct *drv[CISS_MAX_LUN];
32834
32835- struct access_method access;
32836+ struct access_method *access;
32837
32838 /* queue and queue Info */
32839 struct list_head reqQ;
32840diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32841index 3f08713..56a586a 100644
32842--- a/drivers/block/cpqarray.c
32843+++ b/drivers/block/cpqarray.c
32844@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32845 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32846 goto Enomem4;
32847 }
32848- hba[i]->access.set_intr_mask(hba[i], 0);
32849+ hba[i]->access->set_intr_mask(hba[i], 0);
32850 if (request_irq(hba[i]->intr, do_ida_intr,
32851 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32852 {
32853@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32854 add_timer(&hba[i]->timer);
32855
32856 /* Enable IRQ now that spinlock and rate limit timer are set up */
32857- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32858+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32859
32860 for(j=0; j<NWD; j++) {
32861 struct gendisk *disk = ida_gendisk[i][j];
32862@@ -694,7 +694,7 @@ DBGINFO(
32863 for(i=0; i<NR_PRODUCTS; i++) {
32864 if (board_id == products[i].board_id) {
32865 c->product_name = products[i].product_name;
32866- c->access = *(products[i].access);
32867+ c->access = products[i].access;
32868 break;
32869 }
32870 }
32871@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32872 hba[ctlr]->intr = intr;
32873 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32874 hba[ctlr]->product_name = products[j].product_name;
32875- hba[ctlr]->access = *(products[j].access);
32876+ hba[ctlr]->access = products[j].access;
32877 hba[ctlr]->ctlr = ctlr;
32878 hba[ctlr]->board_id = board_id;
32879 hba[ctlr]->pci_dev = NULL; /* not PCI */
32880@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32881
32882 while((c = h->reqQ) != NULL) {
32883 /* Can't do anything if we're busy */
32884- if (h->access.fifo_full(h) == 0)
32885+ if (h->access->fifo_full(h) == 0)
32886 return;
32887
32888 /* Get the first entry from the request Q */
32889@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32890 h->Qdepth--;
32891
32892 /* Tell the controller to do our bidding */
32893- h->access.submit_command(h, c);
32894+ h->access->submit_command(h, c);
32895
32896 /* Get onto the completion Q */
32897 addQ(&h->cmpQ, c);
32898@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32899 unsigned long flags;
32900 __u32 a,a1;
32901
32902- istat = h->access.intr_pending(h);
32903+ istat = h->access->intr_pending(h);
32904 /* Is this interrupt for us? */
32905 if (istat == 0)
32906 return IRQ_NONE;
32907@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32908 */
32909 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32910 if (istat & FIFO_NOT_EMPTY) {
32911- while((a = h->access.command_completed(h))) {
32912+ while((a = h->access->command_completed(h))) {
32913 a1 = a; a &= ~3;
32914 if ((c = h->cmpQ) == NULL)
32915 {
32916@@ -1449,11 +1449,11 @@ static int sendcmd(
32917 /*
32918 * Disable interrupt
32919 */
32920- info_p->access.set_intr_mask(info_p, 0);
32921+ info_p->access->set_intr_mask(info_p, 0);
32922 /* Make sure there is room in the command FIFO */
32923 /* Actually it should be completely empty at this time. */
32924 for (i = 200000; i > 0; i--) {
32925- temp = info_p->access.fifo_full(info_p);
32926+ temp = info_p->access->fifo_full(info_p);
32927 if (temp != 0) {
32928 break;
32929 }
32930@@ -1466,7 +1466,7 @@ DBG(
32931 /*
32932 * Send the cmd
32933 */
32934- info_p->access.submit_command(info_p, c);
32935+ info_p->access->submit_command(info_p, c);
32936 complete = pollcomplete(ctlr);
32937
32938 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32939@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32940 * we check the new geometry. Then turn interrupts back on when
32941 * we're done.
32942 */
32943- host->access.set_intr_mask(host, 0);
32944+ host->access->set_intr_mask(host, 0);
32945 getgeometry(ctlr);
32946- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32947+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32948
32949 for(i=0; i<NWD; i++) {
32950 struct gendisk *disk = ida_gendisk[ctlr][i];
32951@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32952 /* Wait (up to 2 seconds) for a command to complete */
32953
32954 for (i = 200000; i > 0; i--) {
32955- done = hba[ctlr]->access.command_completed(hba[ctlr]);
32956+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
32957 if (done == 0) {
32958 udelay(10); /* a short fixed delay */
32959 } else
32960diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32961index be73e9d..7fbf140 100644
32962--- a/drivers/block/cpqarray.h
32963+++ b/drivers/block/cpqarray.h
32964@@ -99,7 +99,7 @@ struct ctlr_info {
32965 drv_info_t drv[NWD];
32966 struct proc_dir_entry *proc;
32967
32968- struct access_method access;
32969+ struct access_method *access;
32970
32971 cmdlist_t *reqQ;
32972 cmdlist_t *cmpQ;
32973diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32974index 6b51afa..17e1191 100644
32975--- a/drivers/block/drbd/drbd_int.h
32976+++ b/drivers/block/drbd/drbd_int.h
32977@@ -582,7 +582,7 @@ struct drbd_epoch {
32978 struct drbd_tconn *tconn;
32979 struct list_head list;
32980 unsigned int barrier_nr;
32981- atomic_t epoch_size; /* increased on every request added. */
32982+ atomic_unchecked_t epoch_size; /* increased on every request added. */
32983 atomic_t active; /* increased on every req. added, and dec on every finished. */
32984 unsigned long flags;
32985 };
32986@@ -1011,7 +1011,7 @@ struct drbd_conf {
32987 int al_tr_cycle;
32988 int al_tr_pos; /* position of the next transaction in the journal */
32989 wait_queue_head_t seq_wait;
32990- atomic_t packet_seq;
32991+ atomic_unchecked_t packet_seq;
32992 unsigned int peer_seq;
32993 spinlock_t peer_seq_lock;
32994 unsigned int minor;
32995@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32996 char __user *uoptval;
32997 int err;
32998
32999- uoptval = (char __user __force *)optval;
33000+ uoptval = (char __force_user *)optval;
33001
33002 set_fs(KERNEL_DS);
33003 if (level == SOL_SOCKET)
33004diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33005index 8c13eeb..217adee 100644
33006--- a/drivers/block/drbd/drbd_main.c
33007+++ b/drivers/block/drbd/drbd_main.c
33008@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33009 p->sector = sector;
33010 p->block_id = block_id;
33011 p->blksize = blksize;
33012- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33013+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33014 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33015 }
33016
33017@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33018 return -EIO;
33019 p->sector = cpu_to_be64(req->i.sector);
33020 p->block_id = (unsigned long)req;
33021- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33022+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33023 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33024 if (mdev->state.conn >= C_SYNC_SOURCE &&
33025 mdev->state.conn <= C_PAUSED_SYNC_T)
33026@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33027 {
33028 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33029
33030- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33031- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33032+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33033+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33034 kfree(tconn->current_epoch);
33035
33036 idr_destroy(&tconn->volumes);
33037diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33038index a9eccfc..f5efe87 100644
33039--- a/drivers/block/drbd/drbd_receiver.c
33040+++ b/drivers/block/drbd/drbd_receiver.c
33041@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33042 {
33043 int err;
33044
33045- atomic_set(&mdev->packet_seq, 0);
33046+ atomic_set_unchecked(&mdev->packet_seq, 0);
33047 mdev->peer_seq = 0;
33048
33049 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33050@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33051 do {
33052 next_epoch = NULL;
33053
33054- epoch_size = atomic_read(&epoch->epoch_size);
33055+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33056
33057 switch (ev & ~EV_CLEANUP) {
33058 case EV_PUT:
33059@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33060 rv = FE_DESTROYED;
33061 } else {
33062 epoch->flags = 0;
33063- atomic_set(&epoch->epoch_size, 0);
33064+ atomic_set_unchecked(&epoch->epoch_size, 0);
33065 /* atomic_set(&epoch->active, 0); is already zero */
33066 if (rv == FE_STILL_LIVE)
33067 rv = FE_RECYCLED;
33068@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33069 conn_wait_active_ee_empty(tconn);
33070 drbd_flush(tconn);
33071
33072- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33073+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33074 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33075 if (epoch)
33076 break;
33077@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33078 }
33079
33080 epoch->flags = 0;
33081- atomic_set(&epoch->epoch_size, 0);
33082+ atomic_set_unchecked(&epoch->epoch_size, 0);
33083 atomic_set(&epoch->active, 0);
33084
33085 spin_lock(&tconn->epoch_lock);
33086- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33087+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33088 list_add(&epoch->list, &tconn->current_epoch->list);
33089 tconn->current_epoch = epoch;
33090 tconn->epochs++;
33091@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33092
33093 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33094 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33095- atomic_inc(&tconn->current_epoch->epoch_size);
33096+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33097 err2 = drbd_drain_block(mdev, pi->size);
33098 if (!err)
33099 err = err2;
33100@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33101
33102 spin_lock(&tconn->epoch_lock);
33103 peer_req->epoch = tconn->current_epoch;
33104- atomic_inc(&peer_req->epoch->epoch_size);
33105+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33106 atomic_inc(&peer_req->epoch->active);
33107 spin_unlock(&tconn->epoch_lock);
33108
33109@@ -4346,7 +4346,7 @@ struct data_cmd {
33110 int expect_payload;
33111 size_t pkt_size;
33112 int (*fn)(struct drbd_tconn *, struct packet_info *);
33113-};
33114+} __do_const;
33115
33116 static struct data_cmd drbd_cmd_handler[] = {
33117 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33118@@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33119 if (!list_empty(&tconn->current_epoch->list))
33120 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33121 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33122- atomic_set(&tconn->current_epoch->epoch_size, 0);
33123+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33124 tconn->send.seen_any_write_yet = false;
33125
33126 conn_info(tconn, "Connection closed\n");
33127@@ -5222,7 +5222,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33128 struct asender_cmd {
33129 size_t pkt_size;
33130 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33131-};
33132+} __do_const;
33133
33134 static struct asender_cmd asender_tbl[] = {
33135 [P_PING] = { 0, got_Ping },
33136diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33137index ae12512..37fa397 100644
33138--- a/drivers/block/loop.c
33139+++ b/drivers/block/loop.c
33140@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
33141 mm_segment_t old_fs = get_fs();
33142
33143 set_fs(get_ds());
33144- bw = file->f_op->write(file, buf, len, &pos);
33145+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33146 set_fs(old_fs);
33147 if (likely(bw == len))
33148 return 0;
33149diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33150index d620b44..587561e 100644
33151--- a/drivers/cdrom/cdrom.c
33152+++ b/drivers/cdrom/cdrom.c
33153@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33154 ENSURE(reset, CDC_RESET);
33155 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33156 cdi->mc_flags = 0;
33157- cdo->n_minors = 0;
33158 cdi->options = CDO_USE_FFLAGS;
33159
33160 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33161@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33162 else
33163 cdi->cdda_method = CDDA_OLD;
33164
33165- if (!cdo->generic_packet)
33166- cdo->generic_packet = cdrom_dummy_generic_packet;
33167+ if (!cdo->generic_packet) {
33168+ pax_open_kernel();
33169+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33170+ pax_close_kernel();
33171+ }
33172
33173 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33174 mutex_lock(&cdrom_mutex);
33175@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33176 if (cdi->exit)
33177 cdi->exit(cdi);
33178
33179- cdi->ops->n_minors--;
33180 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33181 }
33182
33183diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33184index d59cdcb..11afddf 100644
33185--- a/drivers/cdrom/gdrom.c
33186+++ b/drivers/cdrom/gdrom.c
33187@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33188 .audio_ioctl = gdrom_audio_ioctl,
33189 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33190 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33191- .n_minors = 1,
33192 };
33193
33194 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33195diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33196index 72bedad..8181ce1 100644
33197--- a/drivers/char/Kconfig
33198+++ b/drivers/char/Kconfig
33199@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33200
33201 config DEVKMEM
33202 bool "/dev/kmem virtual device support"
33203- default y
33204+ default n
33205+ depends on !GRKERNSEC_KMEM
33206 help
33207 Say Y here if you want to support the /dev/kmem device. The
33208 /dev/kmem device is rarely used, but can be used for certain
33209@@ -581,6 +582,7 @@ config DEVPORT
33210 bool
33211 depends on !M68K
33212 depends on ISA || PCI
33213+ depends on !GRKERNSEC_KMEM
33214 default y
33215
33216 source "drivers/s390/char/Kconfig"
33217diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33218index 2e04433..22afc64 100644
33219--- a/drivers/char/agp/frontend.c
33220+++ b/drivers/char/agp/frontend.c
33221@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33222 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33223 return -EFAULT;
33224
33225- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33226+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33227 return -EFAULT;
33228
33229 client = agp_find_client_by_pid(reserve.pid);
33230diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33231index 21cb980..f15107c 100644
33232--- a/drivers/char/genrtc.c
33233+++ b/drivers/char/genrtc.c
33234@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33235 switch (cmd) {
33236
33237 case RTC_PLL_GET:
33238+ memset(&pll, 0, sizeof(pll));
33239 if (get_rtc_pll(&pll))
33240 return -EINVAL;
33241 else
33242diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33243index fe6d4be..89f32100 100644
33244--- a/drivers/char/hpet.c
33245+++ b/drivers/char/hpet.c
33246@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33247 }
33248
33249 static int
33250-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33251+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33252 struct hpet_info *info)
33253 {
33254 struct hpet_timer __iomem *timer;
33255diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33256index 053201b0..8335cce 100644
33257--- a/drivers/char/ipmi/ipmi_msghandler.c
33258+++ b/drivers/char/ipmi/ipmi_msghandler.c
33259@@ -420,7 +420,7 @@ struct ipmi_smi {
33260 struct proc_dir_entry *proc_dir;
33261 char proc_dir_name[10];
33262
33263- atomic_t stats[IPMI_NUM_STATS];
33264+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33265
33266 /*
33267 * run_to_completion duplicate of smb_info, smi_info
33268@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33269
33270
33271 #define ipmi_inc_stat(intf, stat) \
33272- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33273+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33274 #define ipmi_get_stat(intf, stat) \
33275- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33276+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33277
33278 static int is_lan_addr(struct ipmi_addr *addr)
33279 {
33280@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33281 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33282 init_waitqueue_head(&intf->waitq);
33283 for (i = 0; i < IPMI_NUM_STATS; i++)
33284- atomic_set(&intf->stats[i], 0);
33285+ atomic_set_unchecked(&intf->stats[i], 0);
33286
33287 intf->proc_dir = NULL;
33288
33289diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33290index 1c7fdcd..4899100 100644
33291--- a/drivers/char/ipmi/ipmi_si_intf.c
33292+++ b/drivers/char/ipmi/ipmi_si_intf.c
33293@@ -275,7 +275,7 @@ struct smi_info {
33294 unsigned char slave_addr;
33295
33296 /* Counters and things for the proc filesystem. */
33297- atomic_t stats[SI_NUM_STATS];
33298+ atomic_unchecked_t stats[SI_NUM_STATS];
33299
33300 struct task_struct *thread;
33301
33302@@ -284,9 +284,9 @@ struct smi_info {
33303 };
33304
33305 #define smi_inc_stat(smi, stat) \
33306- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33307+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33308 #define smi_get_stat(smi, stat) \
33309- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33310+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33311
33312 #define SI_MAX_PARMS 4
33313
33314@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
33315 atomic_set(&new_smi->req_events, 0);
33316 new_smi->run_to_completion = 0;
33317 for (i = 0; i < SI_NUM_STATS; i++)
33318- atomic_set(&new_smi->stats[i], 0);
33319+ atomic_set_unchecked(&new_smi->stats[i], 0);
33320
33321 new_smi->interrupt_disabled = 1;
33322 atomic_set(&new_smi->stop_operation, 0);
33323diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33324index c6fa3bc..4ca3e42 100644
33325--- a/drivers/char/mem.c
33326+++ b/drivers/char/mem.c
33327@@ -18,6 +18,7 @@
33328 #include <linux/raw.h>
33329 #include <linux/tty.h>
33330 #include <linux/capability.h>
33331+#include <linux/security.h>
33332 #include <linux/ptrace.h>
33333 #include <linux/device.h>
33334 #include <linux/highmem.h>
33335@@ -37,6 +38,10 @@
33336
33337 #define DEVPORT_MINOR 4
33338
33339+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33340+extern const struct file_operations grsec_fops;
33341+#endif
33342+
33343 static inline unsigned long size_inside_page(unsigned long start,
33344 unsigned long size)
33345 {
33346@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33347
33348 while (cursor < to) {
33349 if (!devmem_is_allowed(pfn)) {
33350+#ifdef CONFIG_GRKERNSEC_KMEM
33351+ gr_handle_mem_readwrite(from, to);
33352+#else
33353 printk(KERN_INFO
33354 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33355 current->comm, from, to);
33356+#endif
33357 return 0;
33358 }
33359 cursor += PAGE_SIZE;
33360@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33361 }
33362 return 1;
33363 }
33364+#elif defined(CONFIG_GRKERNSEC_KMEM)
33365+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33366+{
33367+ return 0;
33368+}
33369 #else
33370 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33371 {
33372@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33373
33374 while (count > 0) {
33375 unsigned long remaining;
33376+ char *temp;
33377
33378 sz = size_inside_page(p, count);
33379
33380@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33381 if (!ptr)
33382 return -EFAULT;
33383
33384- remaining = copy_to_user(buf, ptr, sz);
33385+#ifdef CONFIG_PAX_USERCOPY
33386+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33387+ if (!temp) {
33388+ unxlate_dev_mem_ptr(p, ptr);
33389+ return -ENOMEM;
33390+ }
33391+ memcpy(temp, ptr, sz);
33392+#else
33393+ temp = ptr;
33394+#endif
33395+
33396+ remaining = copy_to_user(buf, temp, sz);
33397+
33398+#ifdef CONFIG_PAX_USERCOPY
33399+ kfree(temp);
33400+#endif
33401+
33402 unxlate_dev_mem_ptr(p, ptr);
33403 if (remaining)
33404 return -EFAULT;
33405@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33406 size_t count, loff_t *ppos)
33407 {
33408 unsigned long p = *ppos;
33409- ssize_t low_count, read, sz;
33410+ ssize_t low_count, read, sz, err = 0;
33411 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
33412- int err = 0;
33413
33414 read = 0;
33415 if (p < (unsigned long) high_memory) {
33416@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33417 }
33418 #endif
33419 while (low_count > 0) {
33420+ char *temp;
33421+
33422 sz = size_inside_page(p, low_count);
33423
33424 /*
33425@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
33426 */
33427 kbuf = xlate_dev_kmem_ptr((char *)p);
33428
33429- if (copy_to_user(buf, kbuf, sz))
33430+#ifdef CONFIG_PAX_USERCOPY
33431+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33432+ if (!temp)
33433+ return -ENOMEM;
33434+ memcpy(temp, kbuf, sz);
33435+#else
33436+ temp = kbuf;
33437+#endif
33438+
33439+ err = copy_to_user(buf, temp, sz);
33440+
33441+#ifdef CONFIG_PAX_USERCOPY
33442+ kfree(temp);
33443+#endif
33444+
33445+ if (err)
33446 return -EFAULT;
33447 buf += sz;
33448 p += sz;
33449@@ -833,6 +880,9 @@ static const struct memdev {
33450 #ifdef CONFIG_CRASH_DUMP
33451 [12] = { "oldmem", 0, &oldmem_fops, NULL },
33452 #endif
33453+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33454+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
33455+#endif
33456 };
33457
33458 static int memory_open(struct inode *inode, struct file *filp)
33459diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
33460index 9df78e2..01ba9ae 100644
33461--- a/drivers/char/nvram.c
33462+++ b/drivers/char/nvram.c
33463@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
33464
33465 spin_unlock_irq(&rtc_lock);
33466
33467- if (copy_to_user(buf, contents, tmp - contents))
33468+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
33469 return -EFAULT;
33470
33471 *ppos = i;
33472diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
33473index b66eaa0..2619d1b 100644
33474--- a/drivers/char/pcmcia/synclink_cs.c
33475+++ b/drivers/char/pcmcia/synclink_cs.c
33476@@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33477
33478 if (debug_level >= DEBUG_LEVEL_INFO)
33479 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
33480- __FILE__,__LINE__, info->device_name, port->count);
33481+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
33482
33483- WARN_ON(!port->count);
33484+ WARN_ON(!atomic_read(&port->count));
33485
33486 if (tty_port_close_start(port, tty, filp) == 0)
33487 goto cleanup;
33488@@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
33489 cleanup:
33490 if (debug_level >= DEBUG_LEVEL_INFO)
33491 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
33492- tty->driver->name, port->count);
33493+ tty->driver->name, atomic_read(&port->count));
33494 }
33495
33496 /* Wait until the transmitter is empty.
33497@@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33498
33499 if (debug_level >= DEBUG_LEVEL_INFO)
33500 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
33501- __FILE__,__LINE__,tty->driver->name, port->count);
33502+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
33503
33504 /* If port is closing, signal caller to try again */
33505 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
33506@@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
33507 goto cleanup;
33508 }
33509 spin_lock(&port->lock);
33510- port->count++;
33511+ atomic_inc(&port->count);
33512 spin_unlock(&port->lock);
33513 spin_unlock_irqrestore(&info->netlock, flags);
33514
33515- if (port->count == 1) {
33516+ if (atomic_read(&port->count) == 1) {
33517 /* 1st open on this device, init hardware */
33518 retval = startup(info, tty);
33519 if (retval < 0)
33520@@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
33521 unsigned short new_crctype;
33522
33523 /* return error if TTY interface open */
33524- if (info->port.count)
33525+ if (atomic_read(&info->port.count))
33526 return -EBUSY;
33527
33528 switch (encoding)
33529@@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
33530
33531 /* arbitrate between network and tty opens */
33532 spin_lock_irqsave(&info->netlock, flags);
33533- if (info->port.count != 0 || info->netcount != 0) {
33534+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
33535 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
33536 spin_unlock_irqrestore(&info->netlock, flags);
33537 return -EBUSY;
33538@@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
33539 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
33540
33541 /* return error if TTY interface open */
33542- if (info->port.count)
33543+ if (atomic_read(&info->port.count))
33544 return -EBUSY;
33545
33546 if (cmd != SIOCWANDEV)
33547diff --git a/drivers/char/random.c b/drivers/char/random.c
33548index 85e81ec..a129a39 100644
33549--- a/drivers/char/random.c
33550+++ b/drivers/char/random.c
33551@@ -272,8 +272,13 @@
33552 /*
33553 * Configuration information
33554 */
33555+#ifdef CONFIG_GRKERNSEC_RANDNET
33556+#define INPUT_POOL_WORDS 512
33557+#define OUTPUT_POOL_WORDS 128
33558+#else
33559 #define INPUT_POOL_WORDS 128
33560 #define OUTPUT_POOL_WORDS 32
33561+#endif
33562 #define SEC_XFER_SIZE 512
33563 #define EXTRACT_SIZE 10
33564
33565@@ -313,10 +318,17 @@ static struct poolinfo {
33566 int poolwords;
33567 int tap1, tap2, tap3, tap4, tap5;
33568 } poolinfo_table[] = {
33569+#ifdef CONFIG_GRKERNSEC_RANDNET
33570+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
33571+ { 512, 411, 308, 208, 104, 1 },
33572+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
33573+ { 128, 103, 76, 51, 25, 1 },
33574+#else
33575 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
33576 { 128, 103, 76, 51, 25, 1 },
33577 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
33578 { 32, 26, 20, 14, 7, 1 },
33579+#endif
33580 #if 0
33581 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
33582 { 2048, 1638, 1231, 819, 411, 1 },
33583@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
33584 input_rotate += i ? 7 : 14;
33585 }
33586
33587- ACCESS_ONCE(r->input_rotate) = input_rotate;
33588- ACCESS_ONCE(r->add_ptr) = i;
33589+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
33590+ ACCESS_ONCE_RW(r->add_ptr) = i;
33591 smp_wmb();
33592
33593 if (out)
33594@@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
33595
33596 extract_buf(r, tmp);
33597 i = min_t(int, nbytes, EXTRACT_SIZE);
33598- if (copy_to_user(buf, tmp, i)) {
33599+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
33600 ret = -EFAULT;
33601 break;
33602 }
33603@@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
33604 #include <linux/sysctl.h>
33605
33606 static int min_read_thresh = 8, min_write_thresh;
33607-static int max_read_thresh = INPUT_POOL_WORDS * 32;
33608+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
33609 static int max_write_thresh = INPUT_POOL_WORDS * 32;
33610 static char sysctl_bootid[16];
33611
33612@@ -1372,7 +1384,7 @@ static char sysctl_bootid[16];
33613 static int proc_do_uuid(ctl_table *table, int write,
33614 void __user *buffer, size_t *lenp, loff_t *ppos)
33615 {
33616- ctl_table fake_table;
33617+ ctl_table_no_const fake_table;
33618 unsigned char buf[64], tmp_uuid[16], *uuid;
33619
33620 uuid = table->data;
33621diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
33622index d780295..b29f3a8 100644
33623--- a/drivers/char/sonypi.c
33624+++ b/drivers/char/sonypi.c
33625@@ -54,6 +54,7 @@
33626
33627 #include <asm/uaccess.h>
33628 #include <asm/io.h>
33629+#include <asm/local.h>
33630
33631 #include <linux/sonypi.h>
33632
33633@@ -490,7 +491,7 @@ static struct sonypi_device {
33634 spinlock_t fifo_lock;
33635 wait_queue_head_t fifo_proc_list;
33636 struct fasync_struct *fifo_async;
33637- int open_count;
33638+ local_t open_count;
33639 int model;
33640 struct input_dev *input_jog_dev;
33641 struct input_dev *input_key_dev;
33642@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33643 static int sonypi_misc_release(struct inode *inode, struct file *file)
33644 {
33645 mutex_lock(&sonypi_device.lock);
33646- sonypi_device.open_count--;
33647+ local_dec(&sonypi_device.open_count);
33648 mutex_unlock(&sonypi_device.lock);
33649 return 0;
33650 }
33651@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33652 {
33653 mutex_lock(&sonypi_device.lock);
33654 /* Flush input queue on first open */
33655- if (!sonypi_device.open_count)
33656+ if (!local_read(&sonypi_device.open_count))
33657 kfifo_reset(&sonypi_device.fifo);
33658- sonypi_device.open_count++;
33659+ local_inc(&sonypi_device.open_count);
33660 mutex_unlock(&sonypi_device.lock);
33661
33662 return 0;
33663diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33664index 93211df..c7805f7 100644
33665--- a/drivers/char/tpm/tpm.c
33666+++ b/drivers/char/tpm/tpm.c
33667@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33668 chip->vendor.req_complete_val)
33669 goto out_recv;
33670
33671- if ((status == chip->vendor.req_canceled)) {
33672+ if (status == chip->vendor.req_canceled) {
33673 dev_err(chip->dev, "Operation Canceled\n");
33674 rc = -ECANCELED;
33675 goto out;
33676diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33677index 56051d0..11cf3b7 100644
33678--- a/drivers/char/tpm/tpm_acpi.c
33679+++ b/drivers/char/tpm/tpm_acpi.c
33680@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33681 virt = acpi_os_map_memory(start, len);
33682 if (!virt) {
33683 kfree(log->bios_event_log);
33684+ log->bios_event_log = NULL;
33685 printk("%s: ERROR - Unable to map memory\n", __func__);
33686 return -EIO;
33687 }
33688
33689- memcpy_fromio(log->bios_event_log, virt, len);
33690+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33691
33692 acpi_os_unmap_memory(virt, len);
33693 return 0;
33694diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33695index 84ddc55..1d32f1e 100644
33696--- a/drivers/char/tpm/tpm_eventlog.c
33697+++ b/drivers/char/tpm/tpm_eventlog.c
33698@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33699 event = addr;
33700
33701 if ((event->event_type == 0 && event->event_size == 0) ||
33702- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33703+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33704 return NULL;
33705
33706 return addr;
33707@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33708 return NULL;
33709
33710 if ((event->event_type == 0 && event->event_size == 0) ||
33711- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33712+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33713 return NULL;
33714
33715 (*pos)++;
33716@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33717 int i;
33718
33719 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33720- seq_putc(m, data[i]);
33721+ if (!seq_putc(m, data[i]))
33722+ return -EFAULT;
33723
33724 return 0;
33725 }
33726diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33727index ee4dbea..69c817b 100644
33728--- a/drivers/char/virtio_console.c
33729+++ b/drivers/char/virtio_console.c
33730@@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33731 if (to_user) {
33732 ssize_t ret;
33733
33734- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33735+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33736 if (ret)
33737 return -EFAULT;
33738 } else {
33739@@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33740 if (!port_has_data(port) && !port->host_connected)
33741 return 0;
33742
33743- return fill_readbuf(port, ubuf, count, true);
33744+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33745 }
33746
33747 static int wait_port_writable(struct port *port, bool nonblock)
33748diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33749index 8ae1a61..9c00613 100644
33750--- a/drivers/clocksource/arm_generic.c
33751+++ b/drivers/clocksource/arm_generic.c
33752@@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33753 return NOTIFY_OK;
33754 }
33755
33756-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33757+static struct notifier_block arch_timer_cpu_nb = {
33758 .notifier_call = arch_timer_cpu_notify,
33759 };
33760
33761diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c
33762index fce2000..1110478 100644
33763--- a/drivers/connector/cn_proc.c
33764+++ b/drivers/connector/cn_proc.c
33765@@ -313,6 +313,12 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
33766 (task_active_pid_ns(current) != &init_pid_ns))
33767 return;
33768
33769+ /* Can only change if privileged. */
33770+ if (!capable(CAP_NET_ADMIN)) {
33771+ err = EPERM;
33772+ goto out;
33773+ }
33774+
33775 mc_op = (enum proc_cn_mcast_op *)msg->data;
33776 switch (*mc_op) {
33777 case PROC_CN_MCAST_LISTEN:
33778@@ -325,6 +331,8 @@ static void cn_proc_mcast_ctl(struct cn_msg *msg,
33779 err = EINVAL;
33780 break;
33781 }
33782+
33783+out:
33784 cn_proc_ack(err, msg->seq, msg->ack);
33785 }
33786
33787diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
33788index 7b0d49d..134fac9 100644
33789--- a/drivers/cpufreq/acpi-cpufreq.c
33790+++ b/drivers/cpufreq/acpi-cpufreq.c
33791@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
33792 return sprintf(buf, "%u\n", boost_enabled);
33793 }
33794
33795-static struct global_attr global_boost = __ATTR(boost, 0644,
33796+static global_attr_no_const global_boost = __ATTR(boost, 0644,
33797 show_global_boost,
33798 store_global_boost);
33799
33800@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33801 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
33802 per_cpu(acfreq_data, cpu) = data;
33803
33804- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
33805- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33806+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
33807+ pax_open_kernel();
33808+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
33809+ pax_close_kernel();
33810+ }
33811
33812 result = acpi_processor_register_performance(data->acpi_data, cpu);
33813 if (result)
33814@@ -835,7 +838,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33815 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
33816 break;
33817 case ACPI_ADR_SPACE_FIXED_HARDWARE:
33818- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33819+ pax_open_kernel();
33820+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
33821+ pax_close_kernel();
33822 policy->cur = get_cur_freq_on_cpu(cpu);
33823 break;
33824 default:
33825@@ -846,8 +851,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
33826 acpi_processor_notify_smm(THIS_MODULE);
33827
33828 /* Check for APERF/MPERF support in hardware */
33829- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
33830- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33831+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
33832+ pax_open_kernel();
33833+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
33834+ pax_close_kernel();
33835+ }
33836
33837 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
33838 for (i = 0; i < perf->state_count; i++)
33839diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33840index 1f93dbd..305cef1 100644
33841--- a/drivers/cpufreq/cpufreq.c
33842+++ b/drivers/cpufreq/cpufreq.c
33843@@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33844 return NOTIFY_OK;
33845 }
33846
33847-static struct notifier_block __refdata cpufreq_cpu_notifier = {
33848+static struct notifier_block cpufreq_cpu_notifier = {
33849 .notifier_call = cpufreq_cpu_callback,
33850 };
33851
33852@@ -1875,8 +1875,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
33853
33854 pr_debug("trying to register driver %s\n", driver_data->name);
33855
33856- if (driver_data->setpolicy)
33857- driver_data->flags |= CPUFREQ_CONST_LOOPS;
33858+ if (driver_data->setpolicy) {
33859+ pax_open_kernel();
33860+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
33861+ pax_close_kernel();
33862+ }
33863
33864 spin_lock_irqsave(&cpufreq_driver_lock, flags);
33865 if (cpufreq_driver) {
33866diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
33867index 6c5f1d3..c7e2f35e 100644
33868--- a/drivers/cpufreq/cpufreq_governor.c
33869+++ b/drivers/cpufreq/cpufreq_governor.c
33870@@ -243,7 +243,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33871 * governor, thus we are bound to jiffes/HZ
33872 */
33873 if (dbs_data->governor == GOV_CONSERVATIVE) {
33874- struct cs_ops *ops = dbs_data->gov_ops;
33875+ const struct cs_ops *ops = dbs_data->gov_ops;
33876
33877 cpufreq_register_notifier(ops->notifier_block,
33878 CPUFREQ_TRANSITION_NOTIFIER);
33879@@ -251,7 +251,7 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
33880 dbs_data->min_sampling_rate = MIN_SAMPLING_RATE_RATIO *
33881 jiffies_to_usecs(10);
33882 } else {
33883- struct od_ops *ops = dbs_data->gov_ops;
33884+ const struct od_ops *ops = dbs_data->gov_ops;
33885
33886 od_tuners->io_is_busy = ops->io_busy();
33887 }
33888@@ -268,7 +268,7 @@ second_time:
33889 cs_dbs_info->enable = 1;
33890 cs_dbs_info->requested_freq = policy->cur;
33891 } else {
33892- struct od_ops *ops = dbs_data->gov_ops;
33893+ const struct od_ops *ops = dbs_data->gov_ops;
33894 od_dbs_info->rate_mult = 1;
33895 od_dbs_info->sample_type = OD_NORMAL_SAMPLE;
33896 ops->powersave_bias_init_cpu(cpu);
33897@@ -289,7 +289,7 @@ second_time:
33898 mutex_destroy(&cpu_cdbs->timer_mutex);
33899 dbs_data->enable--;
33900 if (!dbs_data->enable) {
33901- struct cs_ops *ops = dbs_data->gov_ops;
33902+ const struct cs_ops *ops = dbs_data->gov_ops;
33903
33904 sysfs_remove_group(cpufreq_global_kobject,
33905 dbs_data->attr_group);
33906diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
33907index f661654..6c8e638 100644
33908--- a/drivers/cpufreq/cpufreq_governor.h
33909+++ b/drivers/cpufreq/cpufreq_governor.h
33910@@ -142,7 +142,7 @@ struct dbs_data {
33911 void (*gov_check_cpu)(int cpu, unsigned int load);
33912
33913 /* Governor specific ops, see below */
33914- void *gov_ops;
33915+ const void *gov_ops;
33916 };
33917
33918 /* Governor specific ops, will be passed to dbs_data->gov_ops */
33919diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33920index 9d7732b..0b1a793 100644
33921--- a/drivers/cpufreq/cpufreq_stats.c
33922+++ b/drivers/cpufreq/cpufreq_stats.c
33923@@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33924 }
33925
33926 /* priority=1 so this will get called before cpufreq_remove_dev */
33927-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33928+static struct notifier_block cpufreq_stat_cpu_notifier = {
33929 .notifier_call = cpufreq_stat_cpu_callback,
33930 .priority = 1,
33931 };
33932diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
33933index 827629c9..0bc6a03 100644
33934--- a/drivers/cpufreq/p4-clockmod.c
33935+++ b/drivers/cpufreq/p4-clockmod.c
33936@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33937 case 0x0F: /* Core Duo */
33938 case 0x16: /* Celeron Core */
33939 case 0x1C: /* Atom */
33940- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33941+ pax_open_kernel();
33942+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33943+ pax_close_kernel();
33944 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
33945 case 0x0D: /* Pentium M (Dothan) */
33946- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33947+ pax_open_kernel();
33948+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33949+ pax_close_kernel();
33950 /* fall through */
33951 case 0x09: /* Pentium M (Banias) */
33952 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
33953@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
33954
33955 /* on P-4s, the TSC runs with constant frequency independent whether
33956 * throttling is active or not. */
33957- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33958+ pax_open_kernel();
33959+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
33960+ pax_close_kernel();
33961
33962 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
33963 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
33964diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
33965index 3a953d5..f5993f6 100644
33966--- a/drivers/cpufreq/speedstep-centrino.c
33967+++ b/drivers/cpufreq/speedstep-centrino.c
33968@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
33969 !cpu_has(cpu, X86_FEATURE_EST))
33970 return -ENODEV;
33971
33972- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
33973- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33974+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
33975+ pax_open_kernel();
33976+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
33977+ pax_close_kernel();
33978+ }
33979
33980 if (policy->cpu != 0)
33981 return -ENODEV;
33982diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
33983index e1f6860..f8de20b 100644
33984--- a/drivers/cpuidle/cpuidle.c
33985+++ b/drivers/cpuidle/cpuidle.c
33986@@ -279,7 +279,7 @@ static int poll_idle(struct cpuidle_device *dev,
33987
33988 static void poll_idle_init(struct cpuidle_driver *drv)
33989 {
33990- struct cpuidle_state *state = &drv->states[0];
33991+ cpuidle_state_no_const *state = &drv->states[0];
33992
33993 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
33994 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
33995diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
33996index ea2f8e7..70ac501 100644
33997--- a/drivers/cpuidle/governor.c
33998+++ b/drivers/cpuidle/governor.c
33999@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34000 mutex_lock(&cpuidle_lock);
34001 if (__cpuidle_find_governor(gov->name) == NULL) {
34002 ret = 0;
34003- list_add_tail(&gov->governor_list, &cpuidle_governors);
34004+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34005 if (!cpuidle_curr_governor ||
34006 cpuidle_curr_governor->rating < gov->rating)
34007 cpuidle_switch_governor(gov);
34008@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34009 new_gov = cpuidle_replace_governor(gov->rating);
34010 cpuidle_switch_governor(new_gov);
34011 }
34012- list_del(&gov->governor_list);
34013+ pax_list_del((struct list_head *)&gov->governor_list);
34014 mutex_unlock(&cpuidle_lock);
34015 }
34016
34017diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34018index 428754a..8bdf9cc 100644
34019--- a/drivers/cpuidle/sysfs.c
34020+++ b/drivers/cpuidle/sysfs.c
34021@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34022 NULL
34023 };
34024
34025-static struct attribute_group cpuidle_attr_group = {
34026+static attribute_group_no_const cpuidle_attr_group = {
34027 .attrs = cpuidle_default_attrs,
34028 .name = "cpuidle",
34029 };
34030diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34031index 3b36797..289c16a 100644
34032--- a/drivers/devfreq/devfreq.c
34033+++ b/drivers/devfreq/devfreq.c
34034@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34035 goto err_out;
34036 }
34037
34038- list_add(&governor->node, &devfreq_governor_list);
34039+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34040
34041 list_for_each_entry(devfreq, &devfreq_list, node) {
34042 int ret = 0;
34043@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34044 }
34045 }
34046
34047- list_del(&governor->node);
34048+ pax_list_del((struct list_head *)&governor->node);
34049 err_out:
34050 mutex_unlock(&devfreq_list_lock);
34051
34052diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34053index b70709b..1d8d02a 100644
34054--- a/drivers/dma/sh/shdma.c
34055+++ b/drivers/dma/sh/shdma.c
34056@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34057 return ret;
34058 }
34059
34060-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34061+static struct notifier_block sh_dmae_nmi_notifier = {
34062 .notifier_call = sh_dmae_nmi_handler,
34063
34064 /* Run before NMI debug handler and KGDB */
34065diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34066index 0ca1ca7..6e6f454 100644
34067--- a/drivers/edac/edac_mc_sysfs.c
34068+++ b/drivers/edac/edac_mc_sysfs.c
34069@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34070 struct dev_ch_attribute {
34071 struct device_attribute attr;
34072 int channel;
34073-};
34074+} __do_const;
34075
34076 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34077 struct dev_ch_attribute dev_attr_legacy_##_name = \
34078diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34079index 0056c4d..23b54d9 100644
34080--- a/drivers/edac/edac_pci_sysfs.c
34081+++ b/drivers/edac/edac_pci_sysfs.c
34082@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34083 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34084 static int edac_pci_poll_msec = 1000; /* one second workq period */
34085
34086-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34087-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34088+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34089+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34090
34091 static struct kobject *edac_pci_top_main_kobj;
34092 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34093@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34094 void *value;
34095 ssize_t(*show) (void *, char *);
34096 ssize_t(*store) (void *, const char *, size_t);
34097-};
34098+} __do_const;
34099
34100 /* Set of show/store abstract level functions for PCI Parity object */
34101 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34102@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34103 edac_printk(KERN_CRIT, EDAC_PCI,
34104 "Signaled System Error on %s\n",
34105 pci_name(dev));
34106- atomic_inc(&pci_nonparity_count);
34107+ atomic_inc_unchecked(&pci_nonparity_count);
34108 }
34109
34110 if (status & (PCI_STATUS_PARITY)) {
34111@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34112 "Master Data Parity Error on %s\n",
34113 pci_name(dev));
34114
34115- atomic_inc(&pci_parity_count);
34116+ atomic_inc_unchecked(&pci_parity_count);
34117 }
34118
34119 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34120@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34121 "Detected Parity Error on %s\n",
34122 pci_name(dev));
34123
34124- atomic_inc(&pci_parity_count);
34125+ atomic_inc_unchecked(&pci_parity_count);
34126 }
34127 }
34128
34129@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34130 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34131 "Signaled System Error on %s\n",
34132 pci_name(dev));
34133- atomic_inc(&pci_nonparity_count);
34134+ atomic_inc_unchecked(&pci_nonparity_count);
34135 }
34136
34137 if (status & (PCI_STATUS_PARITY)) {
34138@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34139 "Master Data Parity Error on "
34140 "%s\n", pci_name(dev));
34141
34142- atomic_inc(&pci_parity_count);
34143+ atomic_inc_unchecked(&pci_parity_count);
34144 }
34145
34146 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34147@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34148 "Detected Parity Error on %s\n",
34149 pci_name(dev));
34150
34151- atomic_inc(&pci_parity_count);
34152+ atomic_inc_unchecked(&pci_parity_count);
34153 }
34154 }
34155 }
34156@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34157 if (!check_pci_errors)
34158 return;
34159
34160- before_count = atomic_read(&pci_parity_count);
34161+ before_count = atomic_read_unchecked(&pci_parity_count);
34162
34163 /* scan all PCI devices looking for a Parity Error on devices and
34164 * bridges.
34165@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34166 /* Only if operator has selected panic on PCI Error */
34167 if (edac_pci_get_panic_on_pe()) {
34168 /* If the count is different 'after' from 'before' */
34169- if (before_count != atomic_read(&pci_parity_count))
34170+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34171 panic("EDAC: PCI Parity Error");
34172 }
34173 }
34174diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34175index 6796799..99e8377 100644
34176--- a/drivers/edac/mce_amd.h
34177+++ b/drivers/edac/mce_amd.h
34178@@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
34179 struct amd_decoder_ops {
34180 bool (*mc0_mce)(u16, u8);
34181 bool (*mc1_mce)(u16, u8);
34182-};
34183+} __no_const;
34184
34185 void amd_report_gart_errors(bool);
34186 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34187diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34188index 57ea7f4..789e3c3 100644
34189--- a/drivers/firewire/core-card.c
34190+++ b/drivers/firewire/core-card.c
34191@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34192
34193 void fw_core_remove_card(struct fw_card *card)
34194 {
34195- struct fw_card_driver dummy_driver = dummy_driver_template;
34196+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34197
34198 card->driver->update_phy_reg(card, 4,
34199 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34200diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34201index f8d2287..5aaf4db 100644
34202--- a/drivers/firewire/core-cdev.c
34203+++ b/drivers/firewire/core-cdev.c
34204@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
34205 int ret;
34206
34207 if ((request->channels == 0 && request->bandwidth == 0) ||
34208- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34209- request->bandwidth < 0)
34210+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34211 return -EINVAL;
34212
34213 r = kmalloc(sizeof(*r), GFP_KERNEL);
34214diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34215index af3e8aa..eb2f227 100644
34216--- a/drivers/firewire/core-device.c
34217+++ b/drivers/firewire/core-device.c
34218@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34219 struct config_rom_attribute {
34220 struct device_attribute attr;
34221 u32 key;
34222-};
34223+} __do_const;
34224
34225 static ssize_t show_immediate(struct device *dev,
34226 struct device_attribute *dattr, char *buf)
34227diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34228index 28a94c7..58da63a 100644
34229--- a/drivers/firewire/core-transaction.c
34230+++ b/drivers/firewire/core-transaction.c
34231@@ -38,6 +38,7 @@
34232 #include <linux/timer.h>
34233 #include <linux/types.h>
34234 #include <linux/workqueue.h>
34235+#include <linux/sched.h>
34236
34237 #include <asm/byteorder.h>
34238
34239diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34240index 515a42c..5ecf3ba 100644
34241--- a/drivers/firewire/core.h
34242+++ b/drivers/firewire/core.h
34243@@ -111,6 +111,7 @@ struct fw_card_driver {
34244
34245 int (*stop_iso)(struct fw_iso_context *ctx);
34246 };
34247+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34248
34249 void fw_card_initialize(struct fw_card *card,
34250 const struct fw_card_driver *driver, struct device *device);
34251diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34252index 94a58a0..f5eba42 100644
34253--- a/drivers/firmware/dmi-id.c
34254+++ b/drivers/firmware/dmi-id.c
34255@@ -16,7 +16,7 @@
34256 struct dmi_device_attribute{
34257 struct device_attribute dev_attr;
34258 int field;
34259-};
34260+} __do_const;
34261 #define to_dmi_dev_attr(_dev_attr) \
34262 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34263
34264diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34265index 982f1f5..d21e5da 100644
34266--- a/drivers/firmware/dmi_scan.c
34267+++ b/drivers/firmware/dmi_scan.c
34268@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
34269 }
34270 }
34271 else {
34272- /*
34273- * no iounmap() for that ioremap(); it would be a no-op, but
34274- * it's so early in setup that sucker gets confused into doing
34275- * what it shouldn't if we actually call it.
34276- */
34277 p = dmi_ioremap(0xF0000, 0x10000);
34278 if (p == NULL)
34279 goto error;
34280@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34281 if (buf == NULL)
34282 return -1;
34283
34284- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34285+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34286
34287 iounmap(buf);
34288 return 0;
34289diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34290index bcb201c..4fd34dd 100644
34291--- a/drivers/firmware/efivars.c
34292+++ b/drivers/firmware/efivars.c
34293@@ -133,7 +133,7 @@ struct efivar_attribute {
34294 };
34295
34296 static struct efivars __efivars;
34297-static struct efivar_operations ops;
34298+static efivar_operations_no_const ops __read_only;
34299
34300 #define PSTORE_EFI_ATTRIBUTES \
34301 (EFI_VARIABLE_NON_VOLATILE | \
34302@@ -1734,7 +1734,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34303 static int
34304 create_efivars_bin_attributes(struct efivars *efivars)
34305 {
34306- struct bin_attribute *attr;
34307+ bin_attribute_no_const *attr;
34308 int error;
34309
34310 /* new_var */
34311diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34312index 2a90ba6..07f3733 100644
34313--- a/drivers/firmware/google/memconsole.c
34314+++ b/drivers/firmware/google/memconsole.c
34315@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34316 if (!found_memconsole())
34317 return -ENODEV;
34318
34319- memconsole_bin_attr.size = memconsole_length;
34320+ pax_open_kernel();
34321+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34322+ pax_close_kernel();
34323
34324 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34325
34326diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34327index 6f2306d..af9476a 100644
34328--- a/drivers/gpio/gpio-ich.c
34329+++ b/drivers/gpio/gpio-ich.c
34330@@ -69,7 +69,7 @@ struct ichx_desc {
34331 /* Some chipsets have quirks, let these use their own request/get */
34332 int (*request)(struct gpio_chip *chip, unsigned offset);
34333 int (*get)(struct gpio_chip *chip, unsigned offset);
34334-};
34335+} __do_const;
34336
34337 static struct {
34338 spinlock_t lock;
34339diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34340index 9902732..64b62dd 100644
34341--- a/drivers/gpio/gpio-vr41xx.c
34342+++ b/drivers/gpio/gpio-vr41xx.c
34343@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34344 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34345 maskl, pendl, maskh, pendh);
34346
34347- atomic_inc(&irq_err_count);
34348+ atomic_inc_unchecked(&irq_err_count);
34349
34350 return -EINVAL;
34351 }
34352diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34353index 7b2d378..cc947ea 100644
34354--- a/drivers/gpu/drm/drm_crtc_helper.c
34355+++ b/drivers/gpu/drm/drm_crtc_helper.c
34356@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34357 struct drm_crtc *tmp;
34358 int crtc_mask = 1;
34359
34360- WARN(!crtc, "checking null crtc?\n");
34361+ BUG_ON(!crtc);
34362
34363 dev = crtc->dev;
34364
34365diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34366index be174ca..7f38143 100644
34367--- a/drivers/gpu/drm/drm_drv.c
34368+++ b/drivers/gpu/drm/drm_drv.c
34369@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
34370 /**
34371 * Copy and IOCTL return string to user space
34372 */
34373-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34374+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34375 {
34376 int len;
34377
34378@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
34379 struct drm_file *file_priv = filp->private_data;
34380 struct drm_device *dev;
34381 struct drm_ioctl_desc *ioctl;
34382- drm_ioctl_t *func;
34383+ drm_ioctl_no_const_t func;
34384 unsigned int nr = DRM_IOCTL_NR(cmd);
34385 int retcode = -EINVAL;
34386 char stack_kdata[128];
34387@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
34388 return -ENODEV;
34389
34390 atomic_inc(&dev->ioctl_count);
34391- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
34392+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
34393 ++file_priv->ioctl_count;
34394
34395 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
34396diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
34397index 133b413..fd68225 100644
34398--- a/drivers/gpu/drm/drm_fops.c
34399+++ b/drivers/gpu/drm/drm_fops.c
34400@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
34401 }
34402
34403 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
34404- atomic_set(&dev->counts[i], 0);
34405+ atomic_set_unchecked(&dev->counts[i], 0);
34406
34407 dev->sigdata.lock = NULL;
34408
34409@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
34410 if (drm_device_is_unplugged(dev))
34411 return -ENODEV;
34412
34413- if (!dev->open_count++)
34414+ if (local_inc_return(&dev->open_count) == 1)
34415 need_setup = 1;
34416 mutex_lock(&dev->struct_mutex);
34417 old_mapping = dev->dev_mapping;
34418@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
34419 retcode = drm_open_helper(inode, filp, dev);
34420 if (retcode)
34421 goto err_undo;
34422- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
34423+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
34424 if (need_setup) {
34425 retcode = drm_setup(dev);
34426 if (retcode)
34427@@ -164,7 +164,7 @@ err_undo:
34428 iput(container_of(dev->dev_mapping, struct inode, i_data));
34429 dev->dev_mapping = old_mapping;
34430 mutex_unlock(&dev->struct_mutex);
34431- dev->open_count--;
34432+ local_dec(&dev->open_count);
34433 return retcode;
34434 }
34435 EXPORT_SYMBOL(drm_open);
34436@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
34437
34438 mutex_lock(&drm_global_mutex);
34439
34440- DRM_DEBUG("open_count = %d\n", dev->open_count);
34441+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
34442
34443 if (dev->driver->preclose)
34444 dev->driver->preclose(dev, file_priv);
34445@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
34446 * Begin inline drm_release
34447 */
34448
34449- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
34450+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
34451 task_pid_nr(current),
34452 (long)old_encode_dev(file_priv->minor->device),
34453- dev->open_count);
34454+ local_read(&dev->open_count));
34455
34456 /* Release any auth tokens that might point to this file_priv,
34457 (do that under the drm_global_mutex) */
34458@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
34459 * End inline drm_release
34460 */
34461
34462- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
34463- if (!--dev->open_count) {
34464+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
34465+ if (local_dec_and_test(&dev->open_count)) {
34466 if (atomic_read(&dev->ioctl_count)) {
34467 DRM_ERROR("Device busy: %d\n",
34468 atomic_read(&dev->ioctl_count));
34469diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
34470index f731116..629842c 100644
34471--- a/drivers/gpu/drm/drm_global.c
34472+++ b/drivers/gpu/drm/drm_global.c
34473@@ -36,7 +36,7 @@
34474 struct drm_global_item {
34475 struct mutex mutex;
34476 void *object;
34477- int refcount;
34478+ atomic_t refcount;
34479 };
34480
34481 static struct drm_global_item glob[DRM_GLOBAL_NUM];
34482@@ -49,7 +49,7 @@ void drm_global_init(void)
34483 struct drm_global_item *item = &glob[i];
34484 mutex_init(&item->mutex);
34485 item->object = NULL;
34486- item->refcount = 0;
34487+ atomic_set(&item->refcount, 0);
34488 }
34489 }
34490
34491@@ -59,7 +59,7 @@ void drm_global_release(void)
34492 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
34493 struct drm_global_item *item = &glob[i];
34494 BUG_ON(item->object != NULL);
34495- BUG_ON(item->refcount != 0);
34496+ BUG_ON(atomic_read(&item->refcount) != 0);
34497 }
34498 }
34499
34500@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34501 void *object;
34502
34503 mutex_lock(&item->mutex);
34504- if (item->refcount == 0) {
34505+ if (atomic_read(&item->refcount) == 0) {
34506 item->object = kzalloc(ref->size, GFP_KERNEL);
34507 if (unlikely(item->object == NULL)) {
34508 ret = -ENOMEM;
34509@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
34510 goto out_err;
34511
34512 }
34513- ++item->refcount;
34514+ atomic_inc(&item->refcount);
34515 ref->object = item->object;
34516 object = item->object;
34517 mutex_unlock(&item->mutex);
34518@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
34519 struct drm_global_item *item = &glob[ref->global_type];
34520
34521 mutex_lock(&item->mutex);
34522- BUG_ON(item->refcount == 0);
34523+ BUG_ON(atomic_read(&item->refcount) == 0);
34524 BUG_ON(ref->object != item->object);
34525- if (--item->refcount == 0) {
34526+ if (atomic_dec_and_test(&item->refcount)) {
34527 ref->release(ref);
34528 item->object = NULL;
34529 }
34530diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
34531index d4b20ce..77a8d41 100644
34532--- a/drivers/gpu/drm/drm_info.c
34533+++ b/drivers/gpu/drm/drm_info.c
34534@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
34535 struct drm_local_map *map;
34536 struct drm_map_list *r_list;
34537
34538- /* Hardcoded from _DRM_FRAME_BUFFER,
34539- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
34540- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
34541- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
34542+ static const char * const types[] = {
34543+ [_DRM_FRAME_BUFFER] = "FB",
34544+ [_DRM_REGISTERS] = "REG",
34545+ [_DRM_SHM] = "SHM",
34546+ [_DRM_AGP] = "AGP",
34547+ [_DRM_SCATTER_GATHER] = "SG",
34548+ [_DRM_CONSISTENT] = "PCI",
34549+ [_DRM_GEM] = "GEM" };
34550 const char *type;
34551 int i;
34552
34553@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
34554 map = r_list->map;
34555 if (!map)
34556 continue;
34557- if (map->type < 0 || map->type > 5)
34558+ if (map->type >= ARRAY_SIZE(types))
34559 type = "??";
34560 else
34561 type = types[map->type];
34562@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
34563 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
34564 vma->vm_flags & VM_LOCKED ? 'l' : '-',
34565 vma->vm_flags & VM_IO ? 'i' : '-',
34566+#ifdef CONFIG_GRKERNSEC_HIDESYM
34567+ 0);
34568+#else
34569 vma->vm_pgoff);
34570+#endif
34571
34572 #if defined(__i386__)
34573 pgprot = pgprot_val(vma->vm_page_prot);
34574diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
34575index 2f4c434..dd12cd2 100644
34576--- a/drivers/gpu/drm/drm_ioc32.c
34577+++ b/drivers/gpu/drm/drm_ioc32.c
34578@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
34579 request = compat_alloc_user_space(nbytes);
34580 if (!access_ok(VERIFY_WRITE, request, nbytes))
34581 return -EFAULT;
34582- list = (struct drm_buf_desc *) (request + 1);
34583+ list = (struct drm_buf_desc __user *) (request + 1);
34584
34585 if (__put_user(count, &request->count)
34586 || __put_user(list, &request->list))
34587@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
34588 request = compat_alloc_user_space(nbytes);
34589 if (!access_ok(VERIFY_WRITE, request, nbytes))
34590 return -EFAULT;
34591- list = (struct drm_buf_pub *) (request + 1);
34592+ list = (struct drm_buf_pub __user *) (request + 1);
34593
34594 if (__put_user(count, &request->count)
34595 || __put_user(list, &request->list))
34596@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
34597 return 0;
34598 }
34599
34600-drm_ioctl_compat_t *drm_compat_ioctls[] = {
34601+drm_ioctl_compat_t drm_compat_ioctls[] = {
34602 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
34603 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
34604 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
34605@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
34606 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34607 {
34608 unsigned int nr = DRM_IOCTL_NR(cmd);
34609- drm_ioctl_compat_t *fn;
34610 int ret;
34611
34612 /* Assume that ioctls without an explicit compat routine will just
34613@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34614 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
34615 return drm_ioctl(filp, cmd, arg);
34616
34617- fn = drm_compat_ioctls[nr];
34618-
34619- if (fn != NULL)
34620- ret = (*fn) (filp, cmd, arg);
34621+ if (drm_compat_ioctls[nr] != NULL)
34622+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
34623 else
34624 ret = drm_ioctl(filp, cmd, arg);
34625
34626diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
34627index e77bd8b..1571b85 100644
34628--- a/drivers/gpu/drm/drm_ioctl.c
34629+++ b/drivers/gpu/drm/drm_ioctl.c
34630@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
34631 stats->data[i].value =
34632 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
34633 else
34634- stats->data[i].value = atomic_read(&dev->counts[i]);
34635+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
34636 stats->data[i].type = dev->types[i];
34637 }
34638
34639diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
34640index d752c96..fe08455 100644
34641--- a/drivers/gpu/drm/drm_lock.c
34642+++ b/drivers/gpu/drm/drm_lock.c
34643@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34644 if (drm_lock_take(&master->lock, lock->context)) {
34645 master->lock.file_priv = file_priv;
34646 master->lock.lock_time = jiffies;
34647- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
34648+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
34649 break; /* Got lock */
34650 }
34651
34652@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
34653 return -EINVAL;
34654 }
34655
34656- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
34657+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
34658
34659 if (drm_lock_free(&master->lock, lock->context)) {
34660 /* FIXME: Should really bail out here. */
34661diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
34662index 200e104..59facda 100644
34663--- a/drivers/gpu/drm/drm_stub.c
34664+++ b/drivers/gpu/drm/drm_stub.c
34665@@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
34666
34667 drm_device_set_unplugged(dev);
34668
34669- if (dev->open_count == 0) {
34670+ if (local_read(&dev->open_count) == 0) {
34671 drm_put_dev(dev);
34672 }
34673 mutex_unlock(&drm_global_mutex);
34674diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
34675index 004ecdf..db1f6e0 100644
34676--- a/drivers/gpu/drm/i810/i810_dma.c
34677+++ b/drivers/gpu/drm/i810/i810_dma.c
34678@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
34679 dma->buflist[vertex->idx],
34680 vertex->discard, vertex->used);
34681
34682- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34683- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34684+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
34685+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34686 sarea_priv->last_enqueue = dev_priv->counter - 1;
34687 sarea_priv->last_dispatch = (int)hw_status[5];
34688
34689@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
34690 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
34691 mc->last_render);
34692
34693- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34694- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
34695+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
34696+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
34697 sarea_priv->last_enqueue = dev_priv->counter - 1;
34698 sarea_priv->last_dispatch = (int)hw_status[5];
34699
34700diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
34701index 6e0acad..93c8289 100644
34702--- a/drivers/gpu/drm/i810/i810_drv.h
34703+++ b/drivers/gpu/drm/i810/i810_drv.h
34704@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
34705 int page_flipping;
34706
34707 wait_queue_head_t irq_queue;
34708- atomic_t irq_received;
34709- atomic_t irq_emitted;
34710+ atomic_unchecked_t irq_received;
34711+ atomic_unchecked_t irq_emitted;
34712
34713 int front_offset;
34714 } drm_i810_private_t;
34715diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
34716index 8a7c48b..72effc2 100644
34717--- a/drivers/gpu/drm/i915/i915_debugfs.c
34718+++ b/drivers/gpu/drm/i915/i915_debugfs.c
34719@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
34720 I915_READ(GTIMR));
34721 }
34722 seq_printf(m, "Interrupts received: %d\n",
34723- atomic_read(&dev_priv->irq_received));
34724+ atomic_read_unchecked(&dev_priv->irq_received));
34725 for_each_ring(ring, dev_priv, i) {
34726 if (IS_GEN6(dev) || IS_GEN7(dev)) {
34727 seq_printf(m,
34728diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
34729index 99daa89..84ebd44 100644
34730--- a/drivers/gpu/drm/i915/i915_dma.c
34731+++ b/drivers/gpu/drm/i915/i915_dma.c
34732@@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
34733 bool can_switch;
34734
34735 spin_lock(&dev->count_lock);
34736- can_switch = (dev->open_count == 0);
34737+ can_switch = (local_read(&dev->open_count) == 0);
34738 spin_unlock(&dev->count_lock);
34739 return can_switch;
34740 }
34741diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
34742index 7339a4b..445aaba 100644
34743--- a/drivers/gpu/drm/i915/i915_drv.h
34744+++ b/drivers/gpu/drm/i915/i915_drv.h
34745@@ -656,7 +656,7 @@ typedef struct drm_i915_private {
34746 drm_dma_handle_t *status_page_dmah;
34747 struct resource mch_res;
34748
34749- atomic_t irq_received;
34750+ atomic_unchecked_t irq_received;
34751
34752 /* protects the irq masks */
34753 spinlock_t irq_lock;
34754@@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
34755 * will be page flipped away on the next vblank. When it
34756 * reaches 0, dev_priv->pending_flip_queue will be woken up.
34757 */
34758- atomic_t pending_flip;
34759+ atomic_unchecked_t pending_flip;
34760 };
34761 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
34762
34763@@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
34764 struct drm_i915_private *dev_priv, unsigned port);
34765 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
34766 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
34767-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34768+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
34769 {
34770 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
34771 }
34772diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34773index 26d08bb..fccb984 100644
34774--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34775+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
34776@@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
34777 i915_gem_clflush_object(obj);
34778
34779 if (obj->base.pending_write_domain)
34780- flips |= atomic_read(&obj->pending_flip);
34781+ flips |= atomic_read_unchecked(&obj->pending_flip);
34782
34783 flush_domains |= obj->base.write_domain;
34784 }
34785@@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
34786
34787 static int
34788 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
34789- int count)
34790+ unsigned int count)
34791 {
34792- int i;
34793+ unsigned int i;
34794
34795 for (i = 0; i < count; i++) {
34796 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
34797diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
34798index 3c59584..500f2e9 100644
34799--- a/drivers/gpu/drm/i915/i915_ioc32.c
34800+++ b/drivers/gpu/drm/i915/i915_ioc32.c
34801@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
34802 (unsigned long)request);
34803 }
34804
34805-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34806+static drm_ioctl_compat_t i915_compat_ioctls[] = {
34807 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
34808 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
34809 [DRM_I915_GETPARAM] = compat_i915_getparam,
34810@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
34811 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
34812 {
34813 unsigned int nr = DRM_IOCTL_NR(cmd);
34814- drm_ioctl_compat_t *fn = NULL;
34815 int ret;
34816
34817 if (nr < DRM_COMMAND_BASE)
34818 return drm_compat_ioctl(filp, cmd, arg);
34819
34820- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
34821- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34822-
34823- if (fn != NULL)
34824+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
34825+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
34826 ret = (*fn) (filp, cmd, arg);
34827- else
34828+ } else
34829 ret = drm_ioctl(filp, cmd, arg);
34830
34831 return ret;
34832diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
34833index fe84338..a863190 100644
34834--- a/drivers/gpu/drm/i915/i915_irq.c
34835+++ b/drivers/gpu/drm/i915/i915_irq.c
34836@@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
34837 u32 pipe_stats[I915_MAX_PIPES];
34838 bool blc_event;
34839
34840- atomic_inc(&dev_priv->irq_received);
34841+ atomic_inc_unchecked(&dev_priv->irq_received);
34842
34843 while (true) {
34844 iir = I915_READ(VLV_IIR);
34845@@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
34846 irqreturn_t ret = IRQ_NONE;
34847 int i;
34848
34849- atomic_inc(&dev_priv->irq_received);
34850+ atomic_inc_unchecked(&dev_priv->irq_received);
34851
34852 /* disable master interrupt before clearing iir */
34853 de_ier = I915_READ(DEIER);
34854@@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
34855 int ret = IRQ_NONE;
34856 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
34857
34858- atomic_inc(&dev_priv->irq_received);
34859+ atomic_inc_unchecked(&dev_priv->irq_received);
34860
34861 /* disable master interrupt before clearing iir */
34862 de_ier = I915_READ(DEIER);
34863@@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
34864 {
34865 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34866
34867- atomic_set(&dev_priv->irq_received, 0);
34868+ atomic_set_unchecked(&dev_priv->irq_received, 0);
34869
34870 I915_WRITE(HWSTAM, 0xeffe);
34871
34872@@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
34873 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34874 int pipe;
34875
34876- atomic_set(&dev_priv->irq_received, 0);
34877+ atomic_set_unchecked(&dev_priv->irq_received, 0);
34878
34879 /* VLV magic */
34880 I915_WRITE(VLV_IMR, 0);
34881@@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
34882 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34883 int pipe;
34884
34885- atomic_set(&dev_priv->irq_received, 0);
34886+ atomic_set_unchecked(&dev_priv->irq_received, 0);
34887
34888 for_each_pipe(pipe)
34889 I915_WRITE(PIPESTAT(pipe), 0);
34890@@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
34891 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
34892 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
34893
34894- atomic_inc(&dev_priv->irq_received);
34895+ atomic_inc_unchecked(&dev_priv->irq_received);
34896
34897 iir = I915_READ16(IIR);
34898 if (iir == 0)
34899@@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
34900 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34901 int pipe;
34902
34903- atomic_set(&dev_priv->irq_received, 0);
34904+ atomic_set_unchecked(&dev_priv->irq_received, 0);
34905
34906 if (I915_HAS_HOTPLUG(dev)) {
34907 I915_WRITE(PORT_HOTPLUG_EN, 0);
34908@@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
34909 };
34910 int pipe, ret = IRQ_NONE;
34911
34912- atomic_inc(&dev_priv->irq_received);
34913+ atomic_inc_unchecked(&dev_priv->irq_received);
34914
34915 iir = I915_READ(IIR);
34916 do {
34917@@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
34918 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
34919 int pipe;
34920
34921- atomic_set(&dev_priv->irq_received, 0);
34922+ atomic_set_unchecked(&dev_priv->irq_received, 0);
34923
34924 I915_WRITE(PORT_HOTPLUG_EN, 0);
34925 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
34926@@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
34927 int irq_received;
34928 int ret = IRQ_NONE, pipe;
34929
34930- atomic_inc(&dev_priv->irq_received);
34931+ atomic_inc_unchecked(&dev_priv->irq_received);
34932
34933 iir = I915_READ(IIR);
34934
34935diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
34936index 80aa1fc..85cfce3 100644
34937--- a/drivers/gpu/drm/i915/intel_display.c
34938+++ b/drivers/gpu/drm/i915/intel_display.c
34939@@ -2255,7 +2255,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
34940
34941 wait_event(dev_priv->pending_flip_queue,
34942 atomic_read(&dev_priv->mm.wedged) ||
34943- atomic_read(&obj->pending_flip) == 0);
34944+ atomic_read_unchecked(&obj->pending_flip) == 0);
34945
34946 /* Big Hammer, we also need to ensure that any pending
34947 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
34948@@ -7122,8 +7122,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
34949
34950 obj = work->old_fb_obj;
34951
34952- atomic_clear_mask(1 << intel_crtc->plane,
34953- &obj->pending_flip.counter);
34954+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
34955 wake_up(&dev_priv->pending_flip_queue);
34956
34957 queue_work(dev_priv->wq, &work->work);
34958@@ -7490,7 +7489,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34959 /* Block clients from rendering to the new back buffer until
34960 * the flip occurs and the object is no longer visible.
34961 */
34962- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34963+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34964 atomic_inc(&intel_crtc->unpin_work_count);
34965
34966 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
34967@@ -7507,7 +7506,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
34968
34969 cleanup_pending:
34970 atomic_dec(&intel_crtc->unpin_work_count);
34971- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34972+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
34973 drm_gem_object_unreference(&work->old_fb_obj->base);
34974 drm_gem_object_unreference(&obj->base);
34975 mutex_unlock(&dev->struct_mutex);
34976@@ -8849,13 +8848,13 @@ struct intel_quirk {
34977 int subsystem_vendor;
34978 int subsystem_device;
34979 void (*hook)(struct drm_device *dev);
34980-};
34981+} __do_const;
34982
34983 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
34984 struct intel_dmi_quirk {
34985 void (*hook)(struct drm_device *dev);
34986 const struct dmi_system_id (*dmi_id_list)[];
34987-};
34988+} __do_const;
34989
34990 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34991 {
34992@@ -8863,18 +8862,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
34993 return 1;
34994 }
34995
34996+static const struct dmi_system_id intel_dmi_quirks_table[] = {
34997+ {
34998+ .callback = intel_dmi_reverse_brightness,
34999+ .ident = "NCR Corporation",
35000+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35001+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35002+ },
35003+ },
35004+ { } /* terminating entry */
35005+};
35006+
35007 static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35008 {
35009- .dmi_id_list = &(const struct dmi_system_id[]) {
35010- {
35011- .callback = intel_dmi_reverse_brightness,
35012- .ident = "NCR Corporation",
35013- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35014- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35015- },
35016- },
35017- { } /* terminating entry */
35018- },
35019+ .dmi_id_list = &intel_dmi_quirks_table,
35020 .hook = quirk_invert_brightness,
35021 },
35022 };
35023diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35024index 54558a0..2d97005 100644
35025--- a/drivers/gpu/drm/mga/mga_drv.h
35026+++ b/drivers/gpu/drm/mga/mga_drv.h
35027@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35028 u32 clear_cmd;
35029 u32 maccess;
35030
35031- atomic_t vbl_received; /**< Number of vblanks received. */
35032+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35033 wait_queue_head_t fence_queue;
35034- atomic_t last_fence_retired;
35035+ atomic_unchecked_t last_fence_retired;
35036 u32 next_fence_to_post;
35037
35038 unsigned int fb_cpp;
35039diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35040index 709e90d..89a1c0d 100644
35041--- a/drivers/gpu/drm/mga/mga_ioc32.c
35042+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35043@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35044 return 0;
35045 }
35046
35047-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35048+drm_ioctl_compat_t mga_compat_ioctls[] = {
35049 [DRM_MGA_INIT] = compat_mga_init,
35050 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35051 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35052@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35053 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35054 {
35055 unsigned int nr = DRM_IOCTL_NR(cmd);
35056- drm_ioctl_compat_t *fn = NULL;
35057 int ret;
35058
35059 if (nr < DRM_COMMAND_BASE)
35060 return drm_compat_ioctl(filp, cmd, arg);
35061
35062- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35063- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35064-
35065- if (fn != NULL)
35066+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35067+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35068 ret = (*fn) (filp, cmd, arg);
35069- else
35070+ } else
35071 ret = drm_ioctl(filp, cmd, arg);
35072
35073 return ret;
35074diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35075index 598c281..60d590e 100644
35076--- a/drivers/gpu/drm/mga/mga_irq.c
35077+++ b/drivers/gpu/drm/mga/mga_irq.c
35078@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35079 if (crtc != 0)
35080 return 0;
35081
35082- return atomic_read(&dev_priv->vbl_received);
35083+ return atomic_read_unchecked(&dev_priv->vbl_received);
35084 }
35085
35086
35087@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35088 /* VBLANK interrupt */
35089 if (status & MGA_VLINEPEN) {
35090 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35091- atomic_inc(&dev_priv->vbl_received);
35092+ atomic_inc_unchecked(&dev_priv->vbl_received);
35093 drm_handle_vblank(dev, 0);
35094 handled = 1;
35095 }
35096@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35097 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35098 MGA_WRITE(MGA_PRIMEND, prim_end);
35099
35100- atomic_inc(&dev_priv->last_fence_retired);
35101+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35102 DRM_WAKEUP(&dev_priv->fence_queue);
35103 handled = 1;
35104 }
35105@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35106 * using fences.
35107 */
35108 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35109- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35110+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35111 - *sequence) <= (1 << 23)));
35112
35113 *sequence = cur_fence;
35114diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35115index 865eddf..62c4cc3 100644
35116--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35117+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35118@@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35119 struct bit_table {
35120 const char id;
35121 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35122-};
35123+} __no_const;
35124
35125 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35126
35127diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35128index aa89eb9..d45d38b 100644
35129--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35130+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35131@@ -80,7 +80,7 @@ struct nouveau_drm {
35132 struct drm_global_reference mem_global_ref;
35133 struct ttm_bo_global_ref bo_global_ref;
35134 struct ttm_bo_device bdev;
35135- atomic_t validate_sequence;
35136+ atomic_unchecked_t validate_sequence;
35137 int (*move)(struct nouveau_channel *,
35138 struct ttm_buffer_object *,
35139 struct ttm_mem_reg *, struct ttm_mem_reg *);
35140diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
35141index cdb83ac..27f0a16 100644
35142--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
35143+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
35144@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
35145 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
35146 struct nouveau_channel *);
35147 u32 (*read)(struct nouveau_channel *);
35148-};
35149+} __no_const;
35150
35151 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
35152
35153diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35154index 8bf695c..9fbc90a 100644
35155--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35156+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35157@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35158 int trycnt = 0;
35159 int ret, i;
35160
35161- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35162+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35163 retry:
35164 if (++trycnt > 100000) {
35165 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
35166diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35167index 08214bc..9208577 100644
35168--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35169+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35170@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35171 unsigned long arg)
35172 {
35173 unsigned int nr = DRM_IOCTL_NR(cmd);
35174- drm_ioctl_compat_t *fn = NULL;
35175+ drm_ioctl_compat_t fn = NULL;
35176 int ret;
35177
35178 if (nr < DRM_COMMAND_BASE)
35179diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35180index 25d3495..d81aaf6 100644
35181--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35182+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35183@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35184 bool can_switch;
35185
35186 spin_lock(&dev->count_lock);
35187- can_switch = (dev->open_count == 0);
35188+ can_switch = (local_read(&dev->open_count) == 0);
35189 spin_unlock(&dev->count_lock);
35190 return can_switch;
35191 }
35192diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35193index d4660cf..70dbe65 100644
35194--- a/drivers/gpu/drm/r128/r128_cce.c
35195+++ b/drivers/gpu/drm/r128/r128_cce.c
35196@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35197
35198 /* GH: Simple idle check.
35199 */
35200- atomic_set(&dev_priv->idle_count, 0);
35201+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35202
35203 /* We don't support anything other than bus-mastering ring mode,
35204 * but the ring can be in either AGP or PCI space for the ring
35205diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35206index 930c71b..499aded 100644
35207--- a/drivers/gpu/drm/r128/r128_drv.h
35208+++ b/drivers/gpu/drm/r128/r128_drv.h
35209@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35210 int is_pci;
35211 unsigned long cce_buffers_offset;
35212
35213- atomic_t idle_count;
35214+ atomic_unchecked_t idle_count;
35215
35216 int page_flipping;
35217 int current_page;
35218 u32 crtc_offset;
35219 u32 crtc_offset_cntl;
35220
35221- atomic_t vbl_received;
35222+ atomic_unchecked_t vbl_received;
35223
35224 u32 color_fmt;
35225 unsigned int front_offset;
35226diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35227index a954c54..9cc595c 100644
35228--- a/drivers/gpu/drm/r128/r128_ioc32.c
35229+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35230@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35231 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35232 }
35233
35234-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35235+drm_ioctl_compat_t r128_compat_ioctls[] = {
35236 [DRM_R128_INIT] = compat_r128_init,
35237 [DRM_R128_DEPTH] = compat_r128_depth,
35238 [DRM_R128_STIPPLE] = compat_r128_stipple,
35239@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35240 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35241 {
35242 unsigned int nr = DRM_IOCTL_NR(cmd);
35243- drm_ioctl_compat_t *fn = NULL;
35244 int ret;
35245
35246 if (nr < DRM_COMMAND_BASE)
35247 return drm_compat_ioctl(filp, cmd, arg);
35248
35249- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35250- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35251-
35252- if (fn != NULL)
35253+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35254+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35255 ret = (*fn) (filp, cmd, arg);
35256- else
35257+ } else
35258 ret = drm_ioctl(filp, cmd, arg);
35259
35260 return ret;
35261diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35262index 2ea4f09..d391371 100644
35263--- a/drivers/gpu/drm/r128/r128_irq.c
35264+++ b/drivers/gpu/drm/r128/r128_irq.c
35265@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35266 if (crtc != 0)
35267 return 0;
35268
35269- return atomic_read(&dev_priv->vbl_received);
35270+ return atomic_read_unchecked(&dev_priv->vbl_received);
35271 }
35272
35273 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35274@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35275 /* VBLANK interrupt */
35276 if (status & R128_CRTC_VBLANK_INT) {
35277 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35278- atomic_inc(&dev_priv->vbl_received);
35279+ atomic_inc_unchecked(&dev_priv->vbl_received);
35280 drm_handle_vblank(dev, 0);
35281 return IRQ_HANDLED;
35282 }
35283diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35284index 19bb7e6..de7e2a2 100644
35285--- a/drivers/gpu/drm/r128/r128_state.c
35286+++ b/drivers/gpu/drm/r128/r128_state.c
35287@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35288
35289 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35290 {
35291- if (atomic_read(&dev_priv->idle_count) == 0)
35292+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35293 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35294 else
35295- atomic_set(&dev_priv->idle_count, 0);
35296+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35297 }
35298
35299 #endif
35300diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35301index 5a82b6b..9e69c73 100644
35302--- a/drivers/gpu/drm/radeon/mkregtable.c
35303+++ b/drivers/gpu/drm/radeon/mkregtable.c
35304@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35305 regex_t mask_rex;
35306 regmatch_t match[4];
35307 char buf[1024];
35308- size_t end;
35309+ long end;
35310 int len;
35311 int done = 0;
35312 int r;
35313 unsigned o;
35314 struct offset *offset;
35315 char last_reg_s[10];
35316- int last_reg;
35317+ unsigned long last_reg;
35318
35319 if (regcomp
35320 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35321diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35322index 0d6562b..a154330 100644
35323--- a/drivers/gpu/drm/radeon/radeon_device.c
35324+++ b/drivers/gpu/drm/radeon/radeon_device.c
35325@@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35326 bool can_switch;
35327
35328 spin_lock(&dev->count_lock);
35329- can_switch = (dev->open_count == 0);
35330+ can_switch = (local_read(&dev->open_count) == 0);
35331 spin_unlock(&dev->count_lock);
35332 return can_switch;
35333 }
35334diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35335index e7fdf16..f4f6490 100644
35336--- a/drivers/gpu/drm/radeon/radeon_drv.h
35337+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35338@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
35339
35340 /* SW interrupt */
35341 wait_queue_head_t swi_queue;
35342- atomic_t swi_emitted;
35343+ atomic_unchecked_t swi_emitted;
35344 int vblank_crtc;
35345 uint32_t irq_enable_reg;
35346 uint32_t r500_disp_irq_reg;
35347diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35348index c180df8..5fd8186 100644
35349--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35350+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35351@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35352 request = compat_alloc_user_space(sizeof(*request));
35353 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35354 || __put_user(req32.param, &request->param)
35355- || __put_user((void __user *)(unsigned long)req32.value,
35356+ || __put_user((unsigned long)req32.value,
35357 &request->value))
35358 return -EFAULT;
35359
35360@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35361 #define compat_radeon_cp_setparam NULL
35362 #endif /* X86_64 || IA64 */
35363
35364-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35365+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35366 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35367 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35368 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35369@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35370 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35371 {
35372 unsigned int nr = DRM_IOCTL_NR(cmd);
35373- drm_ioctl_compat_t *fn = NULL;
35374 int ret;
35375
35376 if (nr < DRM_COMMAND_BASE)
35377 return drm_compat_ioctl(filp, cmd, arg);
35378
35379- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35380- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35381-
35382- if (fn != NULL)
35383+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35384+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35385 ret = (*fn) (filp, cmd, arg);
35386- else
35387+ } else
35388 ret = drm_ioctl(filp, cmd, arg);
35389
35390 return ret;
35391diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35392index e771033..a0bc6b3 100644
35393--- a/drivers/gpu/drm/radeon/radeon_irq.c
35394+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35395@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
35396 unsigned int ret;
35397 RING_LOCALS;
35398
35399- atomic_inc(&dev_priv->swi_emitted);
35400- ret = atomic_read(&dev_priv->swi_emitted);
35401+ atomic_inc_unchecked(&dev_priv->swi_emitted);
35402+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
35403
35404 BEGIN_RING(4);
35405 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
35406@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
35407 drm_radeon_private_t *dev_priv =
35408 (drm_radeon_private_t *) dev->dev_private;
35409
35410- atomic_set(&dev_priv->swi_emitted, 0);
35411+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
35412 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
35413
35414 dev->max_vblank_count = 0x001fffff;
35415diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
35416index 8e9057b..af6dacb 100644
35417--- a/drivers/gpu/drm/radeon/radeon_state.c
35418+++ b/drivers/gpu/drm/radeon/radeon_state.c
35419@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
35420 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
35421 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
35422
35423- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35424+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
35425 sarea_priv->nbox * sizeof(depth_boxes[0])))
35426 return -EFAULT;
35427
35428@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
35429 {
35430 drm_radeon_private_t *dev_priv = dev->dev_private;
35431 drm_radeon_getparam_t *param = data;
35432- int value;
35433+ int value = 0;
35434
35435 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
35436
35437diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
35438index 93f760e..8088227 100644
35439--- a/drivers/gpu/drm/radeon/radeon_ttm.c
35440+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
35441@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
35442 man->size = size >> PAGE_SHIFT;
35443 }
35444
35445-static struct vm_operations_struct radeon_ttm_vm_ops;
35446+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
35447 static const struct vm_operations_struct *ttm_vm_ops = NULL;
35448
35449 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
35450@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
35451 }
35452 if (unlikely(ttm_vm_ops == NULL)) {
35453 ttm_vm_ops = vma->vm_ops;
35454+ pax_open_kernel();
35455 radeon_ttm_vm_ops = *ttm_vm_ops;
35456 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
35457+ pax_close_kernel();
35458 }
35459 vma->vm_ops = &radeon_ttm_vm_ops;
35460 return 0;
35461@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
35462 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
35463 else
35464 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
35465- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35466- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35467- radeon_mem_types_list[i].driver_features = 0;
35468+ pax_open_kernel();
35469+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35470+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
35471+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35472 if (i == 0)
35473- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35474+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
35475 else
35476- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35477-
35478+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
35479+ pax_close_kernel();
35480 }
35481 /* Add ttm page pool to debugfs */
35482 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
35483- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35484- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35485- radeon_mem_types_list[i].driver_features = 0;
35486- radeon_mem_types_list[i++].data = NULL;
35487+ pax_open_kernel();
35488+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35489+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
35490+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35491+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35492+ pax_close_kernel();
35493 #ifdef CONFIG_SWIOTLB
35494 if (swiotlb_nr_tbl()) {
35495 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
35496- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35497- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35498- radeon_mem_types_list[i].driver_features = 0;
35499- radeon_mem_types_list[i++].data = NULL;
35500+ pax_open_kernel();
35501+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
35502+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
35503+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
35504+ *(void **)&radeon_mem_types_list[i++].data = NULL;
35505+ pax_close_kernel();
35506 }
35507 #endif
35508 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
35509diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
35510index 5706d2a..17aedaa 100644
35511--- a/drivers/gpu/drm/radeon/rs690.c
35512+++ b/drivers/gpu/drm/radeon/rs690.c
35513@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
35514 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
35515 rdev->pm.sideport_bandwidth.full)
35516 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
35517- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
35518+ read_delay_latency.full = dfixed_const(800 * 1000);
35519 read_delay_latency.full = dfixed_div(read_delay_latency,
35520 rdev->pm.igp_sideport_mclk);
35521+ a.full = dfixed_const(370);
35522+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
35523 } else {
35524 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
35525 rdev->pm.k8_bandwidth.full)
35526diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35527index bd2a3b4..122d9ad 100644
35528--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
35529+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
35530@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
35531 static int ttm_pool_mm_shrink(struct shrinker *shrink,
35532 struct shrink_control *sc)
35533 {
35534- static atomic_t start_pool = ATOMIC_INIT(0);
35535+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
35536 unsigned i;
35537- unsigned pool_offset = atomic_add_return(1, &start_pool);
35538+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
35539 struct ttm_page_pool *pool;
35540 int shrink_pages = sc->nr_to_scan;
35541
35542diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
35543index 1eb060c..188b1fc 100644
35544--- a/drivers/gpu/drm/udl/udl_fb.c
35545+++ b/drivers/gpu/drm/udl/udl_fb.c
35546@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
35547 fb_deferred_io_cleanup(info);
35548 kfree(info->fbdefio);
35549 info->fbdefio = NULL;
35550- info->fbops->fb_mmap = udl_fb_mmap;
35551 }
35552
35553 pr_warn("released /dev/fb%d user=%d count=%d\n",
35554diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
35555index 893a650..6190d3b 100644
35556--- a/drivers/gpu/drm/via/via_drv.h
35557+++ b/drivers/gpu/drm/via/via_drv.h
35558@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
35559 typedef uint32_t maskarray_t[5];
35560
35561 typedef struct drm_via_irq {
35562- atomic_t irq_received;
35563+ atomic_unchecked_t irq_received;
35564 uint32_t pending_mask;
35565 uint32_t enable_mask;
35566 wait_queue_head_t irq_queue;
35567@@ -75,7 +75,7 @@ typedef struct drm_via_private {
35568 struct timeval last_vblank;
35569 int last_vblank_valid;
35570 unsigned usec_per_vblank;
35571- atomic_t vbl_received;
35572+ atomic_unchecked_t vbl_received;
35573 drm_via_state_t hc_state;
35574 char pci_buf[VIA_PCI_BUF_SIZE];
35575 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
35576diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
35577index ac98964..5dbf512 100644
35578--- a/drivers/gpu/drm/via/via_irq.c
35579+++ b/drivers/gpu/drm/via/via_irq.c
35580@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
35581 if (crtc != 0)
35582 return 0;
35583
35584- return atomic_read(&dev_priv->vbl_received);
35585+ return atomic_read_unchecked(&dev_priv->vbl_received);
35586 }
35587
35588 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35589@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35590
35591 status = VIA_READ(VIA_REG_INTERRUPT);
35592 if (status & VIA_IRQ_VBLANK_PENDING) {
35593- atomic_inc(&dev_priv->vbl_received);
35594- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
35595+ atomic_inc_unchecked(&dev_priv->vbl_received);
35596+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
35597 do_gettimeofday(&cur_vblank);
35598 if (dev_priv->last_vblank_valid) {
35599 dev_priv->usec_per_vblank =
35600@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35601 dev_priv->last_vblank = cur_vblank;
35602 dev_priv->last_vblank_valid = 1;
35603 }
35604- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
35605+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
35606 DRM_DEBUG("US per vblank is: %u\n",
35607 dev_priv->usec_per_vblank);
35608 }
35609@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
35610
35611 for (i = 0; i < dev_priv->num_irqs; ++i) {
35612 if (status & cur_irq->pending_mask) {
35613- atomic_inc(&cur_irq->irq_received);
35614+ atomic_inc_unchecked(&cur_irq->irq_received);
35615 DRM_WAKEUP(&cur_irq->irq_queue);
35616 handled = 1;
35617 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
35618@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
35619 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35620 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
35621 masks[irq][4]));
35622- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
35623+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
35624 } else {
35625 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
35626 (((cur_irq_sequence =
35627- atomic_read(&cur_irq->irq_received)) -
35628+ atomic_read_unchecked(&cur_irq->irq_received)) -
35629 *sequence) <= (1 << 23)));
35630 }
35631 *sequence = cur_irq_sequence;
35632@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
35633 }
35634
35635 for (i = 0; i < dev_priv->num_irqs; ++i) {
35636- atomic_set(&cur_irq->irq_received, 0);
35637+ atomic_set_unchecked(&cur_irq->irq_received, 0);
35638 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
35639 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
35640 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
35641@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
35642 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
35643 case VIA_IRQ_RELATIVE:
35644 irqwait->request.sequence +=
35645- atomic_read(&cur_irq->irq_received);
35646+ atomic_read_unchecked(&cur_irq->irq_received);
35647 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
35648 case VIA_IRQ_ABSOLUTE:
35649 break;
35650diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35651index 13aeda7..4a952d1 100644
35652--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35653+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
35654@@ -290,7 +290,7 @@ struct vmw_private {
35655 * Fencing and IRQs.
35656 */
35657
35658- atomic_t marker_seq;
35659+ atomic_unchecked_t marker_seq;
35660 wait_queue_head_t fence_queue;
35661 wait_queue_head_t fifo_queue;
35662 int fence_queue_waiters; /* Protected by hw_mutex */
35663diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35664index 3eb1486..0a47ee9 100644
35665--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35666+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
35667@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
35668 (unsigned int) min,
35669 (unsigned int) fifo->capabilities);
35670
35671- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35672+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
35673 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
35674 vmw_marker_queue_init(&fifo->marker_queue);
35675 return vmw_fifo_send_fence(dev_priv, &dummy);
35676@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
35677 if (reserveable)
35678 iowrite32(bytes, fifo_mem +
35679 SVGA_FIFO_RESERVED);
35680- return fifo_mem + (next_cmd >> 2);
35681+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
35682 } else {
35683 need_bounce = true;
35684 }
35685@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35686
35687 fm = vmw_fifo_reserve(dev_priv, bytes);
35688 if (unlikely(fm == NULL)) {
35689- *seqno = atomic_read(&dev_priv->marker_seq);
35690+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35691 ret = -ENOMEM;
35692 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
35693 false, 3*HZ);
35694@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
35695 }
35696
35697 do {
35698- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
35699+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
35700 } while (*seqno == 0);
35701
35702 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
35703diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35704index 4640adb..e1384ed 100644
35705--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35706+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
35707@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
35708 * emitted. Then the fence is stale and signaled.
35709 */
35710
35711- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
35712+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
35713 > VMW_FENCE_WRAP);
35714
35715 return ret;
35716@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
35717
35718 if (fifo_idle)
35719 down_read(&fifo_state->rwsem);
35720- signal_seq = atomic_read(&dev_priv->marker_seq);
35721+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
35722 ret = 0;
35723
35724 for (;;) {
35725diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35726index 8a8725c..afed796 100644
35727--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35728+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
35729@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
35730 while (!vmw_lag_lt(queue, us)) {
35731 spin_lock(&queue->lock);
35732 if (list_empty(&queue->head))
35733- seqno = atomic_read(&dev_priv->marker_seq);
35734+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
35735 else {
35736 marker = list_first_entry(&queue->head,
35737 struct vmw_marker, head);
35738diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
35739index ceb3040..6160c5c 100644
35740--- a/drivers/hid/hid-core.c
35741+++ b/drivers/hid/hid-core.c
35742@@ -2242,7 +2242,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
35743
35744 int hid_add_device(struct hid_device *hdev)
35745 {
35746- static atomic_t id = ATOMIC_INIT(0);
35747+ static atomic_unchecked_t id = ATOMIC_INIT(0);
35748 int ret;
35749
35750 if (WARN_ON(hdev->status & HID_STAT_ADDED))
35751@@ -2276,7 +2276,7 @@ int hid_add_device(struct hid_device *hdev)
35752 /* XXX hack, any other cleaner solution after the driver core
35753 * is converted to allow more than 20 bytes as the device name? */
35754 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
35755- hdev->vendor, hdev->product, atomic_inc_return(&id));
35756+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
35757
35758 hid_debug_register(hdev, dev_name(&hdev->dev));
35759 ret = device_add(&hdev->dev);
35760diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
35761index eec3291..8ed706b 100644
35762--- a/drivers/hid/hid-wiimote-debug.c
35763+++ b/drivers/hid/hid-wiimote-debug.c
35764@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
35765 else if (size == 0)
35766 return -EIO;
35767
35768- if (copy_to_user(u, buf, size))
35769+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
35770 return -EFAULT;
35771
35772 *off += size;
35773diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
35774index 773a2f2..7ce08bc 100644
35775--- a/drivers/hv/channel.c
35776+++ b/drivers/hv/channel.c
35777@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
35778 int ret = 0;
35779 int t;
35780
35781- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
35782- atomic_inc(&vmbus_connection.next_gpadl_handle);
35783+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
35784+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
35785
35786 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
35787 if (ret)
35788diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
35789index 3648f8f..30ef30d 100644
35790--- a/drivers/hv/hv.c
35791+++ b/drivers/hv/hv.c
35792@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
35793 u64 output_address = (output) ? virt_to_phys(output) : 0;
35794 u32 output_address_hi = output_address >> 32;
35795 u32 output_address_lo = output_address & 0xFFFFFFFF;
35796- void *hypercall_page = hv_context.hypercall_page;
35797+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
35798
35799 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
35800 "=a"(hv_status_lo) : "d" (control_hi),
35801diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
35802index d8d1fad..b91caf7 100644
35803--- a/drivers/hv/hyperv_vmbus.h
35804+++ b/drivers/hv/hyperv_vmbus.h
35805@@ -594,7 +594,7 @@ enum vmbus_connect_state {
35806 struct vmbus_connection {
35807 enum vmbus_connect_state conn_state;
35808
35809- atomic_t next_gpadl_handle;
35810+ atomic_unchecked_t next_gpadl_handle;
35811
35812 /*
35813 * Represents channel interrupts. Each bit position represents a
35814diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
35815index 8e1a9ec..4687821 100644
35816--- a/drivers/hv/vmbus_drv.c
35817+++ b/drivers/hv/vmbus_drv.c
35818@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
35819 {
35820 int ret = 0;
35821
35822- static atomic_t device_num = ATOMIC_INIT(0);
35823+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
35824
35825 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
35826- atomic_inc_return(&device_num));
35827+ atomic_inc_return_unchecked(&device_num));
35828
35829 child_device_obj->device.bus = &hv_bus;
35830 child_device_obj->device.parent = &hv_acpi_dev->dev;
35831diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
35832index 1672e2a..4a6297c 100644
35833--- a/drivers/hwmon/acpi_power_meter.c
35834+++ b/drivers/hwmon/acpi_power_meter.c
35835@@ -117,7 +117,7 @@ struct sensor_template {
35836 struct device_attribute *devattr,
35837 const char *buf, size_t count);
35838 int index;
35839-};
35840+} __do_const;
35841
35842 /* Averaging interval */
35843 static int update_avg_interval(struct acpi_power_meter_resource *resource)
35844@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
35845 struct sensor_template *attrs)
35846 {
35847 struct device *dev = &resource->acpi_dev->dev;
35848- struct sensor_device_attribute *sensors =
35849+ sensor_device_attribute_no_const *sensors =
35850 &resource->sensors[resource->num_sensors];
35851 int res = 0;
35852
35853diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
35854index b41baff..4953e4d 100644
35855--- a/drivers/hwmon/applesmc.c
35856+++ b/drivers/hwmon/applesmc.c
35857@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
35858 {
35859 struct applesmc_node_group *grp;
35860 struct applesmc_dev_attr *node;
35861- struct attribute *attr;
35862+ attribute_no_const *attr;
35863 int ret, i;
35864
35865 for (grp = groups; grp->format; grp++) {
35866diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
35867index 56dbcfb..9874bf1 100644
35868--- a/drivers/hwmon/asus_atk0110.c
35869+++ b/drivers/hwmon/asus_atk0110.c
35870@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
35871 struct atk_sensor_data {
35872 struct list_head list;
35873 struct atk_data *data;
35874- struct device_attribute label_attr;
35875- struct device_attribute input_attr;
35876- struct device_attribute limit1_attr;
35877- struct device_attribute limit2_attr;
35878+ device_attribute_no_const label_attr;
35879+ device_attribute_no_const input_attr;
35880+ device_attribute_no_const limit1_attr;
35881+ device_attribute_no_const limit2_attr;
35882 char label_attr_name[ATTR_NAME_SIZE];
35883 char input_attr_name[ATTR_NAME_SIZE];
35884 char limit1_attr_name[ATTR_NAME_SIZE];
35885@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
35886 static struct device_attribute atk_name_attr =
35887 __ATTR(name, 0444, atk_name_show, NULL);
35888
35889-static void atk_init_attribute(struct device_attribute *attr, char *name,
35890+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
35891 sysfs_show_func show)
35892 {
35893 sysfs_attr_init(&attr->attr);
35894diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
35895index d64923d..72591e8 100644
35896--- a/drivers/hwmon/coretemp.c
35897+++ b/drivers/hwmon/coretemp.c
35898@@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
35899 return NOTIFY_OK;
35900 }
35901
35902-static struct notifier_block coretemp_cpu_notifier __refdata = {
35903+static struct notifier_block coretemp_cpu_notifier = {
35904 .notifier_call = coretemp_cpu_callback,
35905 };
35906
35907diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
35908index a14f634..2916ee2 100644
35909--- a/drivers/hwmon/ibmaem.c
35910+++ b/drivers/hwmon/ibmaem.c
35911@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
35912 struct aem_rw_sensor_template *rw)
35913 {
35914 struct device *dev = &data->pdev->dev;
35915- struct sensor_device_attribute *sensors = data->sensors;
35916+ sensor_device_attribute_no_const *sensors = data->sensors;
35917 int err;
35918
35919 /* Set up read-only sensors */
35920diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
35921index 7d19b1b..8fdaaac 100644
35922--- a/drivers/hwmon/pmbus/pmbus_core.c
35923+++ b/drivers/hwmon/pmbus/pmbus_core.c
35924@@ -811,7 +811,7 @@ static ssize_t pmbus_show_label(struct device *dev,
35925
35926 #define PMBUS_ADD_ATTR(data, _name, _idx, _mode, _type, _show, _set) \
35927 do { \
35928- struct sensor_device_attribute *a \
35929+ sensor_device_attribute_no_const *a \
35930 = &data->_type##s[data->num_##_type##s].attribute; \
35931 BUG_ON(data->num_attributes >= data->max_attributes); \
35932 sysfs_attr_init(&a->dev_attr.attr); \
35933diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
35934index 1c85d39..55ed3cf 100644
35935--- a/drivers/hwmon/sht15.c
35936+++ b/drivers/hwmon/sht15.c
35937@@ -169,7 +169,7 @@ struct sht15_data {
35938 int supply_uV;
35939 bool supply_uV_valid;
35940 struct work_struct update_supply_work;
35941- atomic_t interrupt_handled;
35942+ atomic_unchecked_t interrupt_handled;
35943 };
35944
35945 /**
35946@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
35947 return ret;
35948
35949 gpio_direction_input(data->pdata->gpio_data);
35950- atomic_set(&data->interrupt_handled, 0);
35951+ atomic_set_unchecked(&data->interrupt_handled, 0);
35952
35953 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35954 if (gpio_get_value(data->pdata->gpio_data) == 0) {
35955 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
35956 /* Only relevant if the interrupt hasn't occurred. */
35957- if (!atomic_read(&data->interrupt_handled))
35958+ if (!atomic_read_unchecked(&data->interrupt_handled))
35959 schedule_work(&data->read_work);
35960 }
35961 ret = wait_event_timeout(data->wait_queue,
35962@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
35963
35964 /* First disable the interrupt */
35965 disable_irq_nosync(irq);
35966- atomic_inc(&data->interrupt_handled);
35967+ atomic_inc_unchecked(&data->interrupt_handled);
35968 /* Then schedule a reading work struct */
35969 if (data->state != SHT15_READING_NOTHING)
35970 schedule_work(&data->read_work);
35971@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
35972 * If not, then start the interrupt again - care here as could
35973 * have gone low in meantime so verify it hasn't!
35974 */
35975- atomic_set(&data->interrupt_handled, 0);
35976+ atomic_set_unchecked(&data->interrupt_handled, 0);
35977 enable_irq(gpio_to_irq(data->pdata->gpio_data));
35978 /* If still not occurred or another handler was scheduled */
35979 if (gpio_get_value(data->pdata->gpio_data)
35980- || atomic_read(&data->interrupt_handled))
35981+ || atomic_read_unchecked(&data->interrupt_handled))
35982 return;
35983 }
35984
35985diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
35986index 76f157b..9c0db1b 100644
35987--- a/drivers/hwmon/via-cputemp.c
35988+++ b/drivers/hwmon/via-cputemp.c
35989@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
35990 return NOTIFY_OK;
35991 }
35992
35993-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
35994+static struct notifier_block via_cputemp_cpu_notifier = {
35995 .notifier_call = via_cputemp_cpu_callback,
35996 };
35997
35998diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
35999index 378fcb5..5e91fa8 100644
36000--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36001+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36002@@ -43,7 +43,7 @@
36003 extern struct i2c_adapter amd756_smbus;
36004
36005 static struct i2c_adapter *s4882_adapter;
36006-static struct i2c_algorithm *s4882_algo;
36007+static i2c_algorithm_no_const *s4882_algo;
36008
36009 /* Wrapper access functions for multiplexed SMBus */
36010 static DEFINE_MUTEX(amd756_lock);
36011diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36012index 29015eb..af2d8e9 100644
36013--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36014+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36015@@ -41,7 +41,7 @@
36016 extern struct i2c_adapter *nforce2_smbus;
36017
36018 static struct i2c_adapter *s4985_adapter;
36019-static struct i2c_algorithm *s4985_algo;
36020+static i2c_algorithm_no_const *s4985_algo;
36021
36022 /* Wrapper access functions for multiplexed SMBus */
36023 static DEFINE_MUTEX(nforce2_lock);
36024diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36025index 8126824..55a2798 100644
36026--- a/drivers/ide/ide-cd.c
36027+++ b/drivers/ide/ide-cd.c
36028@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36029 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36030 if ((unsigned long)buf & alignment
36031 || blk_rq_bytes(rq) & q->dma_pad_mask
36032- || object_is_on_stack(buf))
36033+ || object_starts_on_stack(buf))
36034 drive->dma = 0;
36035 }
36036 }
36037diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36038index 8848f16..f8e6dd8 100644
36039--- a/drivers/iio/industrialio-core.c
36040+++ b/drivers/iio/industrialio-core.c
36041@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36042 }
36043
36044 static
36045-int __iio_device_attr_init(struct device_attribute *dev_attr,
36046+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36047 const char *postfix,
36048 struct iio_chan_spec const *chan,
36049 ssize_t (*readfunc)(struct device *dev,
36050diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36051index 394fea2..c833880 100644
36052--- a/drivers/infiniband/core/cm.c
36053+++ b/drivers/infiniband/core/cm.c
36054@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36055
36056 struct cm_counter_group {
36057 struct kobject obj;
36058- atomic_long_t counter[CM_ATTR_COUNT];
36059+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36060 };
36061
36062 struct cm_counter_attribute {
36063@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36064 struct ib_mad_send_buf *msg = NULL;
36065 int ret;
36066
36067- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36068+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36069 counter[CM_REQ_COUNTER]);
36070
36071 /* Quick state check to discard duplicate REQs. */
36072@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36073 if (!cm_id_priv)
36074 return;
36075
36076- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36077+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36078 counter[CM_REP_COUNTER]);
36079 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36080 if (ret)
36081@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
36082 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36083 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36084 spin_unlock_irq(&cm_id_priv->lock);
36085- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36086+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36087 counter[CM_RTU_COUNTER]);
36088 goto out;
36089 }
36090@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
36091 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36092 dreq_msg->local_comm_id);
36093 if (!cm_id_priv) {
36094- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36095+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36096 counter[CM_DREQ_COUNTER]);
36097 cm_issue_drep(work->port, work->mad_recv_wc);
36098 return -EINVAL;
36099@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
36100 case IB_CM_MRA_REP_RCVD:
36101 break;
36102 case IB_CM_TIMEWAIT:
36103- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36104+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36105 counter[CM_DREQ_COUNTER]);
36106 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36107 goto unlock;
36108@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
36109 cm_free_msg(msg);
36110 goto deref;
36111 case IB_CM_DREQ_RCVD:
36112- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36113+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36114 counter[CM_DREQ_COUNTER]);
36115 goto unlock;
36116 default:
36117@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
36118 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36119 cm_id_priv->msg, timeout)) {
36120 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36121- atomic_long_inc(&work->port->
36122+ atomic_long_inc_unchecked(&work->port->
36123 counter_group[CM_RECV_DUPLICATES].
36124 counter[CM_MRA_COUNTER]);
36125 goto out;
36126@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
36127 break;
36128 case IB_CM_MRA_REQ_RCVD:
36129 case IB_CM_MRA_REP_RCVD:
36130- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36131+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36132 counter[CM_MRA_COUNTER]);
36133 /* fall through */
36134 default:
36135@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
36136 case IB_CM_LAP_IDLE:
36137 break;
36138 case IB_CM_MRA_LAP_SENT:
36139- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36140+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36141 counter[CM_LAP_COUNTER]);
36142 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36143 goto unlock;
36144@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
36145 cm_free_msg(msg);
36146 goto deref;
36147 case IB_CM_LAP_RCVD:
36148- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36149+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36150 counter[CM_LAP_COUNTER]);
36151 goto unlock;
36152 default:
36153@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36154 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36155 if (cur_cm_id_priv) {
36156 spin_unlock_irq(&cm.lock);
36157- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36158+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36159 counter[CM_SIDR_REQ_COUNTER]);
36160 goto out; /* Duplicate message. */
36161 }
36162@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36163 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36164 msg->retries = 1;
36165
36166- atomic_long_add(1 + msg->retries,
36167+ atomic_long_add_unchecked(1 + msg->retries,
36168 &port->counter_group[CM_XMIT].counter[attr_index]);
36169 if (msg->retries)
36170- atomic_long_add(msg->retries,
36171+ atomic_long_add_unchecked(msg->retries,
36172 &port->counter_group[CM_XMIT_RETRIES].
36173 counter[attr_index]);
36174
36175@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36176 }
36177
36178 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36179- atomic_long_inc(&port->counter_group[CM_RECV].
36180+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36181 counter[attr_id - CM_ATTR_ID_OFFSET]);
36182
36183 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36184@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36185 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36186
36187 return sprintf(buf, "%ld\n",
36188- atomic_long_read(&group->counter[cm_attr->index]));
36189+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36190 }
36191
36192 static const struct sysfs_ops cm_counter_ops = {
36193diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36194index 176c8f9..2627b62 100644
36195--- a/drivers/infiniband/core/fmr_pool.c
36196+++ b/drivers/infiniband/core/fmr_pool.c
36197@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36198
36199 struct task_struct *thread;
36200
36201- atomic_t req_ser;
36202- atomic_t flush_ser;
36203+ atomic_unchecked_t req_ser;
36204+ atomic_unchecked_t flush_ser;
36205
36206 wait_queue_head_t force_wait;
36207 };
36208@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36209 struct ib_fmr_pool *pool = pool_ptr;
36210
36211 do {
36212- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36213+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36214 ib_fmr_batch_release(pool);
36215
36216- atomic_inc(&pool->flush_ser);
36217+ atomic_inc_unchecked(&pool->flush_ser);
36218 wake_up_interruptible(&pool->force_wait);
36219
36220 if (pool->flush_function)
36221@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36222 }
36223
36224 set_current_state(TASK_INTERRUPTIBLE);
36225- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36226+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36227 !kthread_should_stop())
36228 schedule();
36229 __set_current_state(TASK_RUNNING);
36230@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36231 pool->dirty_watermark = params->dirty_watermark;
36232 pool->dirty_len = 0;
36233 spin_lock_init(&pool->pool_lock);
36234- atomic_set(&pool->req_ser, 0);
36235- atomic_set(&pool->flush_ser, 0);
36236+ atomic_set_unchecked(&pool->req_ser, 0);
36237+ atomic_set_unchecked(&pool->flush_ser, 0);
36238 init_waitqueue_head(&pool->force_wait);
36239
36240 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36241@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36242 }
36243 spin_unlock_irq(&pool->pool_lock);
36244
36245- serial = atomic_inc_return(&pool->req_ser);
36246+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36247 wake_up_process(pool->thread);
36248
36249 if (wait_event_interruptible(pool->force_wait,
36250- atomic_read(&pool->flush_ser) - serial >= 0))
36251+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36252 return -EINTR;
36253
36254 return 0;
36255@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36256 } else {
36257 list_add_tail(&fmr->list, &pool->dirty_list);
36258 if (++pool->dirty_len >= pool->dirty_watermark) {
36259- atomic_inc(&pool->req_ser);
36260+ atomic_inc_unchecked(&pool->req_ser);
36261 wake_up_process(pool->thread);
36262 }
36263 }
36264diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36265index afd8179..598063f 100644
36266--- a/drivers/infiniband/hw/cxgb4/mem.c
36267+++ b/drivers/infiniband/hw/cxgb4/mem.c
36268@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36269 int err;
36270 struct fw_ri_tpte tpt;
36271 u32 stag_idx;
36272- static atomic_t key;
36273+ static atomic_unchecked_t key;
36274
36275 if (c4iw_fatal_error(rdev))
36276 return -EIO;
36277@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36278 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36279 rdev->stats.stag.max = rdev->stats.stag.cur;
36280 mutex_unlock(&rdev->stats.lock);
36281- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36282+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36283 }
36284 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36285 __func__, stag_state, type, pdid, stag_idx);
36286diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36287index 79b3dbc..96e5fcc 100644
36288--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36289+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36290@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36291 struct ib_atomic_eth *ateth;
36292 struct ipath_ack_entry *e;
36293 u64 vaddr;
36294- atomic64_t *maddr;
36295+ atomic64_unchecked_t *maddr;
36296 u64 sdata;
36297 u32 rkey;
36298 u8 next;
36299@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36300 IB_ACCESS_REMOTE_ATOMIC)))
36301 goto nack_acc_unlck;
36302 /* Perform atomic OP and save result. */
36303- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36304+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36305 sdata = be64_to_cpu(ateth->swap_data);
36306 e = &qp->s_ack_queue[qp->r_head_ack_queue];
36307 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
36308- (u64) atomic64_add_return(sdata, maddr) - sdata :
36309+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36310 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36311 be64_to_cpu(ateth->compare_data),
36312 sdata);
36313diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
36314index 1f95bba..9530f87 100644
36315--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
36316+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
36317@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
36318 unsigned long flags;
36319 struct ib_wc wc;
36320 u64 sdata;
36321- atomic64_t *maddr;
36322+ atomic64_unchecked_t *maddr;
36323 enum ib_wc_status send_status;
36324
36325 /*
36326@@ -382,11 +382,11 @@ again:
36327 IB_ACCESS_REMOTE_ATOMIC)))
36328 goto acc_err;
36329 /* Perform atomic OP and save result. */
36330- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
36331+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
36332 sdata = wqe->wr.wr.atomic.compare_add;
36333 *(u64 *) sqp->s_sge.sge.vaddr =
36334 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
36335- (u64) atomic64_add_return(sdata, maddr) - sdata :
36336+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
36337 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
36338 sdata, wqe->wr.wr.atomic.swap);
36339 goto send_comp;
36340diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
36341index 5b152a3..c1f3e83 100644
36342--- a/drivers/infiniband/hw/nes/nes.c
36343+++ b/drivers/infiniband/hw/nes/nes.c
36344@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
36345 LIST_HEAD(nes_adapter_list);
36346 static LIST_HEAD(nes_dev_list);
36347
36348-atomic_t qps_destroyed;
36349+atomic_unchecked_t qps_destroyed;
36350
36351 static unsigned int ee_flsh_adapter;
36352 static unsigned int sysfs_nonidx_addr;
36353@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
36354 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
36355 struct nes_adapter *nesadapter = nesdev->nesadapter;
36356
36357- atomic_inc(&qps_destroyed);
36358+ atomic_inc_unchecked(&qps_destroyed);
36359
36360 /* Free the control structures */
36361
36362diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
36363index 33cc589..3bd6538 100644
36364--- a/drivers/infiniband/hw/nes/nes.h
36365+++ b/drivers/infiniband/hw/nes/nes.h
36366@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
36367 extern unsigned int wqm_quanta;
36368 extern struct list_head nes_adapter_list;
36369
36370-extern atomic_t cm_connects;
36371-extern atomic_t cm_accepts;
36372-extern atomic_t cm_disconnects;
36373-extern atomic_t cm_closes;
36374-extern atomic_t cm_connecteds;
36375-extern atomic_t cm_connect_reqs;
36376-extern atomic_t cm_rejects;
36377-extern atomic_t mod_qp_timouts;
36378-extern atomic_t qps_created;
36379-extern atomic_t qps_destroyed;
36380-extern atomic_t sw_qps_destroyed;
36381+extern atomic_unchecked_t cm_connects;
36382+extern atomic_unchecked_t cm_accepts;
36383+extern atomic_unchecked_t cm_disconnects;
36384+extern atomic_unchecked_t cm_closes;
36385+extern atomic_unchecked_t cm_connecteds;
36386+extern atomic_unchecked_t cm_connect_reqs;
36387+extern atomic_unchecked_t cm_rejects;
36388+extern atomic_unchecked_t mod_qp_timouts;
36389+extern atomic_unchecked_t qps_created;
36390+extern atomic_unchecked_t qps_destroyed;
36391+extern atomic_unchecked_t sw_qps_destroyed;
36392 extern u32 mh_detected;
36393 extern u32 mh_pauses_sent;
36394 extern u32 cm_packets_sent;
36395@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
36396 extern u32 cm_packets_received;
36397 extern u32 cm_packets_dropped;
36398 extern u32 cm_packets_retrans;
36399-extern atomic_t cm_listens_created;
36400-extern atomic_t cm_listens_destroyed;
36401+extern atomic_unchecked_t cm_listens_created;
36402+extern atomic_unchecked_t cm_listens_destroyed;
36403 extern u32 cm_backlog_drops;
36404-extern atomic_t cm_loopbacks;
36405-extern atomic_t cm_nodes_created;
36406-extern atomic_t cm_nodes_destroyed;
36407-extern atomic_t cm_accel_dropped_pkts;
36408-extern atomic_t cm_resets_recvd;
36409-extern atomic_t pau_qps_created;
36410-extern atomic_t pau_qps_destroyed;
36411+extern atomic_unchecked_t cm_loopbacks;
36412+extern atomic_unchecked_t cm_nodes_created;
36413+extern atomic_unchecked_t cm_nodes_destroyed;
36414+extern atomic_unchecked_t cm_accel_dropped_pkts;
36415+extern atomic_unchecked_t cm_resets_recvd;
36416+extern atomic_unchecked_t pau_qps_created;
36417+extern atomic_unchecked_t pau_qps_destroyed;
36418
36419 extern u32 int_mod_timer_init;
36420 extern u32 int_mod_cq_depth_256;
36421diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
36422index 22ea67e..dcbe3bc 100644
36423--- a/drivers/infiniband/hw/nes/nes_cm.c
36424+++ b/drivers/infiniband/hw/nes/nes_cm.c
36425@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
36426 u32 cm_packets_retrans;
36427 u32 cm_packets_created;
36428 u32 cm_packets_received;
36429-atomic_t cm_listens_created;
36430-atomic_t cm_listens_destroyed;
36431+atomic_unchecked_t cm_listens_created;
36432+atomic_unchecked_t cm_listens_destroyed;
36433 u32 cm_backlog_drops;
36434-atomic_t cm_loopbacks;
36435-atomic_t cm_nodes_created;
36436-atomic_t cm_nodes_destroyed;
36437-atomic_t cm_accel_dropped_pkts;
36438-atomic_t cm_resets_recvd;
36439+atomic_unchecked_t cm_loopbacks;
36440+atomic_unchecked_t cm_nodes_created;
36441+atomic_unchecked_t cm_nodes_destroyed;
36442+atomic_unchecked_t cm_accel_dropped_pkts;
36443+atomic_unchecked_t cm_resets_recvd;
36444
36445 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
36446 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
36447@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
36448
36449 static struct nes_cm_core *g_cm_core;
36450
36451-atomic_t cm_connects;
36452-atomic_t cm_accepts;
36453-atomic_t cm_disconnects;
36454-atomic_t cm_closes;
36455-atomic_t cm_connecteds;
36456-atomic_t cm_connect_reqs;
36457-atomic_t cm_rejects;
36458+atomic_unchecked_t cm_connects;
36459+atomic_unchecked_t cm_accepts;
36460+atomic_unchecked_t cm_disconnects;
36461+atomic_unchecked_t cm_closes;
36462+atomic_unchecked_t cm_connecteds;
36463+atomic_unchecked_t cm_connect_reqs;
36464+atomic_unchecked_t cm_rejects;
36465
36466 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
36467 {
36468@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
36469 kfree(listener);
36470 listener = NULL;
36471 ret = 0;
36472- atomic_inc(&cm_listens_destroyed);
36473+ atomic_inc_unchecked(&cm_listens_destroyed);
36474 } else {
36475 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
36476 }
36477@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
36478 cm_node->rem_mac);
36479
36480 add_hte_node(cm_core, cm_node);
36481- atomic_inc(&cm_nodes_created);
36482+ atomic_inc_unchecked(&cm_nodes_created);
36483
36484 return cm_node;
36485 }
36486@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
36487 }
36488
36489 atomic_dec(&cm_core->node_cnt);
36490- atomic_inc(&cm_nodes_destroyed);
36491+ atomic_inc_unchecked(&cm_nodes_destroyed);
36492 nesqp = cm_node->nesqp;
36493 if (nesqp) {
36494 nesqp->cm_node = NULL;
36495@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
36496
36497 static void drop_packet(struct sk_buff *skb)
36498 {
36499- atomic_inc(&cm_accel_dropped_pkts);
36500+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36501 dev_kfree_skb_any(skb);
36502 }
36503
36504@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
36505 {
36506
36507 int reset = 0; /* whether to send reset in case of err.. */
36508- atomic_inc(&cm_resets_recvd);
36509+ atomic_inc_unchecked(&cm_resets_recvd);
36510 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
36511 " refcnt=%d\n", cm_node, cm_node->state,
36512 atomic_read(&cm_node->ref_count));
36513@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
36514 rem_ref_cm_node(cm_node->cm_core, cm_node);
36515 return NULL;
36516 }
36517- atomic_inc(&cm_loopbacks);
36518+ atomic_inc_unchecked(&cm_loopbacks);
36519 loopbackremotenode->loopbackpartner = cm_node;
36520 loopbackremotenode->tcp_cntxt.rcv_wscale =
36521 NES_CM_DEFAULT_RCV_WND_SCALE;
36522@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
36523 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
36524 else {
36525 rem_ref_cm_node(cm_core, cm_node);
36526- atomic_inc(&cm_accel_dropped_pkts);
36527+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
36528 dev_kfree_skb_any(skb);
36529 }
36530 break;
36531@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36532
36533 if ((cm_id) && (cm_id->event_handler)) {
36534 if (issue_disconn) {
36535- atomic_inc(&cm_disconnects);
36536+ atomic_inc_unchecked(&cm_disconnects);
36537 cm_event.event = IW_CM_EVENT_DISCONNECT;
36538 cm_event.status = disconn_status;
36539 cm_event.local_addr = cm_id->local_addr;
36540@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
36541 }
36542
36543 if (issue_close) {
36544- atomic_inc(&cm_closes);
36545+ atomic_inc_unchecked(&cm_closes);
36546 nes_disconnect(nesqp, 1);
36547
36548 cm_id->provider_data = nesqp;
36549@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36550
36551 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
36552 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
36553- atomic_inc(&cm_accepts);
36554+ atomic_inc_unchecked(&cm_accepts);
36555
36556 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
36557 netdev_refcnt_read(nesvnic->netdev));
36558@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
36559 struct nes_cm_core *cm_core;
36560 u8 *start_buff;
36561
36562- atomic_inc(&cm_rejects);
36563+ atomic_inc_unchecked(&cm_rejects);
36564 cm_node = (struct nes_cm_node *)cm_id->provider_data;
36565 loopback = cm_node->loopbackpartner;
36566 cm_core = cm_node->cm_core;
36567@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
36568 ntohl(cm_id->local_addr.sin_addr.s_addr),
36569 ntohs(cm_id->local_addr.sin_port));
36570
36571- atomic_inc(&cm_connects);
36572+ atomic_inc_unchecked(&cm_connects);
36573 nesqp->active_conn = 1;
36574
36575 /* cache the cm_id in the qp */
36576@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
36577 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
36578 return err;
36579 }
36580- atomic_inc(&cm_listens_created);
36581+ atomic_inc_unchecked(&cm_listens_created);
36582 }
36583
36584 cm_id->add_ref(cm_id);
36585@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
36586
36587 if (nesqp->destroyed)
36588 return;
36589- atomic_inc(&cm_connecteds);
36590+ atomic_inc_unchecked(&cm_connecteds);
36591 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
36592 " local port 0x%04X. jiffies = %lu.\n",
36593 nesqp->hwqp.qp_id,
36594@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
36595
36596 cm_id->add_ref(cm_id);
36597 ret = cm_id->event_handler(cm_id, &cm_event);
36598- atomic_inc(&cm_closes);
36599+ atomic_inc_unchecked(&cm_closes);
36600 cm_event.event = IW_CM_EVENT_CLOSE;
36601 cm_event.status = 0;
36602 cm_event.provider_data = cm_id->provider_data;
36603@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
36604 return;
36605 cm_id = cm_node->cm_id;
36606
36607- atomic_inc(&cm_connect_reqs);
36608+ atomic_inc_unchecked(&cm_connect_reqs);
36609 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36610 cm_node, cm_id, jiffies);
36611
36612@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
36613 return;
36614 cm_id = cm_node->cm_id;
36615
36616- atomic_inc(&cm_connect_reqs);
36617+ atomic_inc_unchecked(&cm_connect_reqs);
36618 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
36619 cm_node, cm_id, jiffies);
36620
36621diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
36622index 4166452..fc952c3 100644
36623--- a/drivers/infiniband/hw/nes/nes_mgt.c
36624+++ b/drivers/infiniband/hw/nes/nes_mgt.c
36625@@ -40,8 +40,8 @@
36626 #include "nes.h"
36627 #include "nes_mgt.h"
36628
36629-atomic_t pau_qps_created;
36630-atomic_t pau_qps_destroyed;
36631+atomic_unchecked_t pau_qps_created;
36632+atomic_unchecked_t pau_qps_destroyed;
36633
36634 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
36635 {
36636@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
36637 {
36638 struct sk_buff *skb;
36639 unsigned long flags;
36640- atomic_inc(&pau_qps_destroyed);
36641+ atomic_inc_unchecked(&pau_qps_destroyed);
36642
36643 /* Free packets that have not yet been forwarded */
36644 /* Lock is acquired by skb_dequeue when removing the skb */
36645@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
36646 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
36647 skb_queue_head_init(&nesqp->pau_list);
36648 spin_lock_init(&nesqp->pau_lock);
36649- atomic_inc(&pau_qps_created);
36650+ atomic_inc_unchecked(&pau_qps_created);
36651 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
36652 }
36653
36654diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
36655index 9542e16..a008c40 100644
36656--- a/drivers/infiniband/hw/nes/nes_nic.c
36657+++ b/drivers/infiniband/hw/nes/nes_nic.c
36658@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
36659 target_stat_values[++index] = mh_detected;
36660 target_stat_values[++index] = mh_pauses_sent;
36661 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
36662- target_stat_values[++index] = atomic_read(&cm_connects);
36663- target_stat_values[++index] = atomic_read(&cm_accepts);
36664- target_stat_values[++index] = atomic_read(&cm_disconnects);
36665- target_stat_values[++index] = atomic_read(&cm_connecteds);
36666- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
36667- target_stat_values[++index] = atomic_read(&cm_rejects);
36668- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
36669- target_stat_values[++index] = atomic_read(&qps_created);
36670- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
36671- target_stat_values[++index] = atomic_read(&qps_destroyed);
36672- target_stat_values[++index] = atomic_read(&cm_closes);
36673+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
36674+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
36675+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
36676+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
36677+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
36678+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
36679+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
36680+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
36681+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
36682+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
36683+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
36684 target_stat_values[++index] = cm_packets_sent;
36685 target_stat_values[++index] = cm_packets_bounced;
36686 target_stat_values[++index] = cm_packets_created;
36687 target_stat_values[++index] = cm_packets_received;
36688 target_stat_values[++index] = cm_packets_dropped;
36689 target_stat_values[++index] = cm_packets_retrans;
36690- target_stat_values[++index] = atomic_read(&cm_listens_created);
36691- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
36692+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
36693+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
36694 target_stat_values[++index] = cm_backlog_drops;
36695- target_stat_values[++index] = atomic_read(&cm_loopbacks);
36696- target_stat_values[++index] = atomic_read(&cm_nodes_created);
36697- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
36698- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
36699- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
36700+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
36701+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
36702+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
36703+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
36704+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
36705 target_stat_values[++index] = nesadapter->free_4kpbl;
36706 target_stat_values[++index] = nesadapter->free_256pbl;
36707 target_stat_values[++index] = int_mod_timer_init;
36708 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
36709 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
36710 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
36711- target_stat_values[++index] = atomic_read(&pau_qps_created);
36712- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
36713+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
36714+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
36715 }
36716
36717 /**
36718diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
36719index 07e4fba..685f041 100644
36720--- a/drivers/infiniband/hw/nes/nes_verbs.c
36721+++ b/drivers/infiniband/hw/nes/nes_verbs.c
36722@@ -46,9 +46,9 @@
36723
36724 #include <rdma/ib_umem.h>
36725
36726-atomic_t mod_qp_timouts;
36727-atomic_t qps_created;
36728-atomic_t sw_qps_destroyed;
36729+atomic_unchecked_t mod_qp_timouts;
36730+atomic_unchecked_t qps_created;
36731+atomic_unchecked_t sw_qps_destroyed;
36732
36733 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
36734
36735@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
36736 if (init_attr->create_flags)
36737 return ERR_PTR(-EINVAL);
36738
36739- atomic_inc(&qps_created);
36740+ atomic_inc_unchecked(&qps_created);
36741 switch (init_attr->qp_type) {
36742 case IB_QPT_RC:
36743 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
36744@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
36745 struct iw_cm_event cm_event;
36746 int ret = 0;
36747
36748- atomic_inc(&sw_qps_destroyed);
36749+ atomic_inc_unchecked(&sw_qps_destroyed);
36750 nesqp->destroyed = 1;
36751
36752 /* Blow away the connection if it exists. */
36753diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
36754index 4d11575..3e890e5 100644
36755--- a/drivers/infiniband/hw/qib/qib.h
36756+++ b/drivers/infiniband/hw/qib/qib.h
36757@@ -51,6 +51,7 @@
36758 #include <linux/completion.h>
36759 #include <linux/kref.h>
36760 #include <linux/sched.h>
36761+#include <linux/slab.h>
36762
36763 #include "qib_common.h"
36764 #include "qib_verbs.h"
36765diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
36766index da739d9..da1c7f4 100644
36767--- a/drivers/input/gameport/gameport.c
36768+++ b/drivers/input/gameport/gameport.c
36769@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
36770 */
36771 static void gameport_init_port(struct gameport *gameport)
36772 {
36773- static atomic_t gameport_no = ATOMIC_INIT(0);
36774+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
36775
36776 __module_get(THIS_MODULE);
36777
36778 mutex_init(&gameport->drv_mutex);
36779 device_initialize(&gameport->dev);
36780 dev_set_name(&gameport->dev, "gameport%lu",
36781- (unsigned long)atomic_inc_return(&gameport_no) - 1);
36782+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
36783 gameport->dev.bus = &gameport_bus;
36784 gameport->dev.release = gameport_release_port;
36785 if (gameport->parent)
36786diff --git a/drivers/input/input.c b/drivers/input/input.c
36787index c044699..174d71a 100644
36788--- a/drivers/input/input.c
36789+++ b/drivers/input/input.c
36790@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
36791 */
36792 int input_register_device(struct input_dev *dev)
36793 {
36794- static atomic_t input_no = ATOMIC_INIT(0);
36795+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
36796 struct input_devres *devres = NULL;
36797 struct input_handler *handler;
36798 unsigned int packet_size;
36799@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
36800 dev->setkeycode = input_default_setkeycode;
36801
36802 dev_set_name(&dev->dev, "input%ld",
36803- (unsigned long) atomic_inc_return(&input_no) - 1);
36804+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
36805
36806 error = device_add(&dev->dev);
36807 if (error)
36808diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
36809index 04c69af..5f92d00 100644
36810--- a/drivers/input/joystick/sidewinder.c
36811+++ b/drivers/input/joystick/sidewinder.c
36812@@ -30,6 +30,7 @@
36813 #include <linux/kernel.h>
36814 #include <linux/module.h>
36815 #include <linux/slab.h>
36816+#include <linux/sched.h>
36817 #include <linux/init.h>
36818 #include <linux/input.h>
36819 #include <linux/gameport.h>
36820diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
36821index d6cbfe9..6225402 100644
36822--- a/drivers/input/joystick/xpad.c
36823+++ b/drivers/input/joystick/xpad.c
36824@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
36825
36826 static int xpad_led_probe(struct usb_xpad *xpad)
36827 {
36828- static atomic_t led_seq = ATOMIC_INIT(0);
36829+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
36830 long led_no;
36831 struct xpad_led *led;
36832 struct led_classdev *led_cdev;
36833@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
36834 if (!led)
36835 return -ENOMEM;
36836
36837- led_no = (long)atomic_inc_return(&led_seq) - 1;
36838+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
36839
36840 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
36841 led->xpad = xpad;
36842diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
36843index fe1df23..5b710f3 100644
36844--- a/drivers/input/mouse/psmouse.h
36845+++ b/drivers/input/mouse/psmouse.h
36846@@ -115,7 +115,7 @@ struct psmouse_attribute {
36847 ssize_t (*set)(struct psmouse *psmouse, void *data,
36848 const char *buf, size_t count);
36849 bool protect;
36850-};
36851+} __do_const;
36852 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
36853
36854 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
36855diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
36856index 4c842c3..590b0bf 100644
36857--- a/drivers/input/mousedev.c
36858+++ b/drivers/input/mousedev.c
36859@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
36860
36861 spin_unlock_irq(&client->packet_lock);
36862
36863- if (copy_to_user(buffer, data, count))
36864+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
36865 return -EFAULT;
36866
36867 return count;
36868diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
36869index 25fc597..558bf3b 100644
36870--- a/drivers/input/serio/serio.c
36871+++ b/drivers/input/serio/serio.c
36872@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
36873 */
36874 static void serio_init_port(struct serio *serio)
36875 {
36876- static atomic_t serio_no = ATOMIC_INIT(0);
36877+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
36878
36879 __module_get(THIS_MODULE);
36880
36881@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
36882 mutex_init(&serio->drv_mutex);
36883 device_initialize(&serio->dev);
36884 dev_set_name(&serio->dev, "serio%ld",
36885- (long)atomic_inc_return(&serio_no) - 1);
36886+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
36887 serio->dev.bus = &serio_bus;
36888 serio->dev.release = serio_release_port;
36889 serio->dev.groups = serio_device_attr_groups;
36890diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
36891index ddbdaca..be18a78 100644
36892--- a/drivers/iommu/iommu.c
36893+++ b/drivers/iommu/iommu.c
36894@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
36895 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
36896 {
36897 bus_register_notifier(bus, &iommu_bus_nb);
36898- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
36899+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
36900 }
36901
36902 /**
36903diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
36904index 89562a8..218999b 100644
36905--- a/drivers/isdn/capi/capi.c
36906+++ b/drivers/isdn/capi/capi.c
36907@@ -81,8 +81,8 @@ struct capiminor {
36908
36909 struct capi20_appl *ap;
36910 u32 ncci;
36911- atomic_t datahandle;
36912- atomic_t msgid;
36913+ atomic_unchecked_t datahandle;
36914+ atomic_unchecked_t msgid;
36915
36916 struct tty_port port;
36917 int ttyinstop;
36918@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
36919 capimsg_setu16(s, 2, mp->ap->applid);
36920 capimsg_setu8 (s, 4, CAPI_DATA_B3);
36921 capimsg_setu8 (s, 5, CAPI_RESP);
36922- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
36923+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
36924 capimsg_setu32(s, 8, mp->ncci);
36925 capimsg_setu16(s, 12, datahandle);
36926 }
36927@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
36928 mp->outbytes -= len;
36929 spin_unlock_bh(&mp->outlock);
36930
36931- datahandle = atomic_inc_return(&mp->datahandle);
36932+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
36933 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
36934 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36935 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
36936 capimsg_setu16(skb->data, 2, mp->ap->applid);
36937 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
36938 capimsg_setu8 (skb->data, 5, CAPI_REQ);
36939- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
36940+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
36941 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
36942 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
36943 capimsg_setu16(skb->data, 16, len); /* Data length */
36944diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
36945index 67abf3f..076b3a6 100644
36946--- a/drivers/isdn/gigaset/interface.c
36947+++ b/drivers/isdn/gigaset/interface.c
36948@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
36949 }
36950 tty->driver_data = cs;
36951
36952- ++cs->port.count;
36953+ atomic_inc(&cs->port.count);
36954
36955- if (cs->port.count == 1) {
36956+ if (atomic_read(&cs->port.count) == 1) {
36957 tty_port_tty_set(&cs->port, tty);
36958 tty->low_latency = 1;
36959 }
36960@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
36961
36962 if (!cs->connected)
36963 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
36964- else if (!cs->port.count)
36965+ else if (!atomic_read(&cs->port.count))
36966 dev_warn(cs->dev, "%s: device not opened\n", __func__);
36967- else if (!--cs->port.count)
36968+ else if (!atomic_dec_return(&cs->port.count))
36969 tty_port_tty_set(&cs->port, NULL);
36970
36971 mutex_unlock(&cs->mutex);
36972diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
36973index 821f7ac..28d4030 100644
36974--- a/drivers/isdn/hardware/avm/b1.c
36975+++ b/drivers/isdn/hardware/avm/b1.c
36976@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
36977 }
36978 if (left) {
36979 if (t4file->user) {
36980- if (copy_from_user(buf, dp, left))
36981+ if (left > sizeof buf || copy_from_user(buf, dp, left))
36982 return -EFAULT;
36983 } else {
36984 memcpy(buf, dp, left);
36985@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
36986 }
36987 if (left) {
36988 if (config->user) {
36989- if (copy_from_user(buf, dp, left))
36990+ if (left > sizeof buf || copy_from_user(buf, dp, left))
36991 return -EFAULT;
36992 } else {
36993 memcpy(buf, dp, left);
36994diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
36995index e09dc8a..15e2efb 100644
36996--- a/drivers/isdn/i4l/isdn_tty.c
36997+++ b/drivers/isdn/i4l/isdn_tty.c
36998@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
36999
37000 #ifdef ISDN_DEBUG_MODEM_OPEN
37001 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37002- port->count);
37003+ atomic_read(&port->count));
37004 #endif
37005- port->count++;
37006+ atomic_inc(&port->count);
37007 port->tty = tty;
37008 /*
37009 * Start up serial port
37010@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37011 #endif
37012 return;
37013 }
37014- if ((tty->count == 1) && (port->count != 1)) {
37015+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37016 /*
37017 * Uh, oh. tty->count is 1, which means that the tty
37018 * structure will be freed. Info->count should always
37019@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37020 * serial port won't be shutdown.
37021 */
37022 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37023- "info->count is %d\n", port->count);
37024- port->count = 1;
37025+ "info->count is %d\n", atomic_read(&port->count));
37026+ atomic_set(&port->count, 1);
37027 }
37028- if (--port->count < 0) {
37029+ if (atomic_dec_return(&port->count) < 0) {
37030 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37031- info->line, port->count);
37032- port->count = 0;
37033+ info->line, atomic_read(&port->count));
37034+ atomic_set(&port->count, 0);
37035 }
37036- if (port->count) {
37037+ if (atomic_read(&port->count)) {
37038 #ifdef ISDN_DEBUG_MODEM_OPEN
37039 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37040 #endif
37041@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37042 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37043 return;
37044 isdn_tty_shutdown(info);
37045- port->count = 0;
37046+ atomic_set(&port->count, 0);
37047 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37048 port->tty = NULL;
37049 wake_up_interruptible(&port->open_wait);
37050@@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37051 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37052 modem_info *info = &dev->mdm.info[i];
37053
37054- if (info->port.count == 0)
37055+ if (atomic_read(&info->port.count) == 0)
37056 continue;
37057 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37058 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37059diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37060index e74df7c..03a03ba 100644
37061--- a/drivers/isdn/icn/icn.c
37062+++ b/drivers/isdn/icn/icn.c
37063@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37064 if (count > len)
37065 count = len;
37066 if (user) {
37067- if (copy_from_user(msg, buf, count))
37068+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37069 return -EFAULT;
37070 } else
37071 memcpy(msg, buf, count);
37072diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37073index 6a8405d..0bd1c7e 100644
37074--- a/drivers/leds/leds-clevo-mail.c
37075+++ b/drivers/leds/leds-clevo-mail.c
37076@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37077 * detected as working, but in reality it is not) as low as
37078 * possible.
37079 */
37080-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37081+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37082 {
37083 .callback = clevo_mail_led_dmi_callback,
37084 .ident = "Clevo D410J",
37085diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37086index ec9b287..65c9bf4 100644
37087--- a/drivers/leds/leds-ss4200.c
37088+++ b/drivers/leds/leds-ss4200.c
37089@@ -92,7 +92,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37090 * detected as working, but in reality it is not) as low as
37091 * possible.
37092 */
37093-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37094+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37095 {
37096 .callback = ss4200_led_dmi_callback,
37097 .ident = "Intel SS4200-E",
37098diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37099index a5ebc00..982886f 100644
37100--- a/drivers/lguest/core.c
37101+++ b/drivers/lguest/core.c
37102@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37103 * it's worked so far. The end address needs +1 because __get_vm_area
37104 * allocates an extra guard page, so we need space for that.
37105 */
37106+
37107+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37108+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37109+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37110+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37111+#else
37112 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37113 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37114 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37115+#endif
37116+
37117 if (!switcher_vma) {
37118 err = -ENOMEM;
37119 printk("lguest: could not map switcher pages high\n");
37120@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37121 * Now the Switcher is mapped at the right address, we can't fail!
37122 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37123 */
37124- memcpy(switcher_vma->addr, start_switcher_text,
37125+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37126 end_switcher_text - start_switcher_text);
37127
37128 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37129diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37130index 4af12e1..0e89afe 100644
37131--- a/drivers/lguest/x86/core.c
37132+++ b/drivers/lguest/x86/core.c
37133@@ -59,7 +59,7 @@ static struct {
37134 /* Offset from where switcher.S was compiled to where we've copied it */
37135 static unsigned long switcher_offset(void)
37136 {
37137- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37138+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37139 }
37140
37141 /* This cpu's struct lguest_pages. */
37142@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37143 * These copies are pretty cheap, so we do them unconditionally: */
37144 /* Save the current Host top-level page directory.
37145 */
37146+
37147+#ifdef CONFIG_PAX_PER_CPU_PGD
37148+ pages->state.host_cr3 = read_cr3();
37149+#else
37150 pages->state.host_cr3 = __pa(current->mm->pgd);
37151+#endif
37152+
37153 /*
37154 * Set up the Guest's page tables to see this CPU's pages (and no
37155 * other CPU's pages).
37156@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37157 * compiled-in switcher code and the high-mapped copy we just made.
37158 */
37159 for (i = 0; i < IDT_ENTRIES; i++)
37160- default_idt_entries[i] += switcher_offset();
37161+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37162
37163 /*
37164 * Set up the Switcher's per-cpu areas.
37165@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37166 * it will be undisturbed when we switch. To change %cs and jump we
37167 * need this structure to feed to Intel's "lcall" instruction.
37168 */
37169- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37170+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37171 lguest_entry.segment = LGUEST_CS;
37172
37173 /*
37174diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37175index 40634b0..4f5855e 100644
37176--- a/drivers/lguest/x86/switcher_32.S
37177+++ b/drivers/lguest/x86/switcher_32.S
37178@@ -87,6 +87,7 @@
37179 #include <asm/page.h>
37180 #include <asm/segment.h>
37181 #include <asm/lguest.h>
37182+#include <asm/processor-flags.h>
37183
37184 // We mark the start of the code to copy
37185 // It's placed in .text tho it's never run here
37186@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
37187 // Changes type when we load it: damn Intel!
37188 // For after we switch over our page tables
37189 // That entry will be read-only: we'd crash.
37190+
37191+#ifdef CONFIG_PAX_KERNEXEC
37192+ mov %cr0, %edx
37193+ xor $X86_CR0_WP, %edx
37194+ mov %edx, %cr0
37195+#endif
37196+
37197 movl $(GDT_ENTRY_TSS*8), %edx
37198 ltr %dx
37199
37200@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
37201 // Let's clear it again for our return.
37202 // The GDT descriptor of the Host
37203 // Points to the table after two "size" bytes
37204- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
37205+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
37206 // Clear "used" from type field (byte 5, bit 2)
37207- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
37208+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
37209+
37210+#ifdef CONFIG_PAX_KERNEXEC
37211+ mov %cr0, %eax
37212+ xor $X86_CR0_WP, %eax
37213+ mov %eax, %cr0
37214+#endif
37215
37216 // Once our page table's switched, the Guest is live!
37217 // The Host fades as we run this final step.
37218@@ -295,13 +309,12 @@ deliver_to_host:
37219 // I consulted gcc, and it gave
37220 // These instructions, which I gladly credit:
37221 leal (%edx,%ebx,8), %eax
37222- movzwl (%eax),%edx
37223- movl 4(%eax), %eax
37224- xorw %ax, %ax
37225- orl %eax, %edx
37226+ movl 4(%eax), %edx
37227+ movw (%eax), %dx
37228 // Now the address of the handler's in %edx
37229 // We call it now: its "iret" drops us home.
37230- jmp *%edx
37231+ ljmp $__KERNEL_CS, $1f
37232+1: jmp *%edx
37233
37234 // Every interrupt can come to us here
37235 // But we must truly tell each apart.
37236diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
37237index 7155945..4bcc562 100644
37238--- a/drivers/md/bitmap.c
37239+++ b/drivers/md/bitmap.c
37240@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
37241 chunk_kb ? "KB" : "B");
37242 if (bitmap->storage.file) {
37243 seq_printf(seq, ", file: ");
37244- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
37245+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
37246 }
37247
37248 seq_printf(seq, "\n");
37249diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
37250index 0666b5d..ed82cb4 100644
37251--- a/drivers/md/dm-ioctl.c
37252+++ b/drivers/md/dm-ioctl.c
37253@@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
37254 cmd == DM_LIST_VERSIONS_CMD)
37255 return 0;
37256
37257- if ((cmd == DM_DEV_CREATE_CMD)) {
37258+ if (cmd == DM_DEV_CREATE_CMD) {
37259 if (!*param->name) {
37260 DMWARN("name not supplied when creating device");
37261 return -EINVAL;
37262diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
37263index fa51918..c26253c 100644
37264--- a/drivers/md/dm-raid1.c
37265+++ b/drivers/md/dm-raid1.c
37266@@ -40,7 +40,7 @@ enum dm_raid1_error {
37267
37268 struct mirror {
37269 struct mirror_set *ms;
37270- atomic_t error_count;
37271+ atomic_unchecked_t error_count;
37272 unsigned long error_type;
37273 struct dm_dev *dev;
37274 sector_t offset;
37275@@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
37276 struct mirror *m;
37277
37278 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
37279- if (!atomic_read(&m->error_count))
37280+ if (!atomic_read_unchecked(&m->error_count))
37281 return m;
37282
37283 return NULL;
37284@@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
37285 * simple way to tell if a device has encountered
37286 * errors.
37287 */
37288- atomic_inc(&m->error_count);
37289+ atomic_inc_unchecked(&m->error_count);
37290
37291 if (test_and_set_bit(error_type, &m->error_type))
37292 return;
37293@@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
37294 struct mirror *m = get_default_mirror(ms);
37295
37296 do {
37297- if (likely(!atomic_read(&m->error_count)))
37298+ if (likely(!atomic_read_unchecked(&m->error_count)))
37299 return m;
37300
37301 if (m-- == ms->mirror)
37302@@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
37303 {
37304 struct mirror *default_mirror = get_default_mirror(m->ms);
37305
37306- return !atomic_read(&default_mirror->error_count);
37307+ return !atomic_read_unchecked(&default_mirror->error_count);
37308 }
37309
37310 static int mirror_available(struct mirror_set *ms, struct bio *bio)
37311@@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
37312 */
37313 if (likely(region_in_sync(ms, region, 1)))
37314 m = choose_mirror(ms, bio->bi_sector);
37315- else if (m && atomic_read(&m->error_count))
37316+ else if (m && atomic_read_unchecked(&m->error_count))
37317 m = NULL;
37318
37319 if (likely(m))
37320@@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
37321 }
37322
37323 ms->mirror[mirror].ms = ms;
37324- atomic_set(&(ms->mirror[mirror].error_count), 0);
37325+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
37326 ms->mirror[mirror].error_type = 0;
37327 ms->mirror[mirror].offset = offset;
37328
37329@@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
37330 */
37331 static char device_status_char(struct mirror *m)
37332 {
37333- if (!atomic_read(&(m->error_count)))
37334+ if (!atomic_read_unchecked(&(m->error_count)))
37335 return 'A';
37336
37337 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
37338diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
37339index c89cde8..9d184cf 100644
37340--- a/drivers/md/dm-stripe.c
37341+++ b/drivers/md/dm-stripe.c
37342@@ -20,7 +20,7 @@ struct stripe {
37343 struct dm_dev *dev;
37344 sector_t physical_start;
37345
37346- atomic_t error_count;
37347+ atomic_unchecked_t error_count;
37348 };
37349
37350 struct stripe_c {
37351@@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
37352 kfree(sc);
37353 return r;
37354 }
37355- atomic_set(&(sc->stripe[i].error_count), 0);
37356+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
37357 }
37358
37359 ti->private = sc;
37360@@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
37361 DMEMIT("%d ", sc->stripes);
37362 for (i = 0; i < sc->stripes; i++) {
37363 DMEMIT("%s ", sc->stripe[i].dev->name);
37364- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
37365+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
37366 'D' : 'A';
37367 }
37368 buffer[i] = '\0';
37369@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
37370 */
37371 for (i = 0; i < sc->stripes; i++)
37372 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
37373- atomic_inc(&(sc->stripe[i].error_count));
37374- if (atomic_read(&(sc->stripe[i].error_count)) <
37375+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
37376+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
37377 DM_IO_ERROR_THRESHOLD)
37378 schedule_work(&sc->trigger_event);
37379 }
37380diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
37381index daf25d0..d74f49f 100644
37382--- a/drivers/md/dm-table.c
37383+++ b/drivers/md/dm-table.c
37384@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
37385 if (!dev_size)
37386 return 0;
37387
37388- if ((start >= dev_size) || (start + len > dev_size)) {
37389+ if ((start >= dev_size) || (len > dev_size - start)) {
37390 DMWARN("%s: %s too small for target: "
37391 "start=%llu, len=%llu, dev_size=%llu",
37392 dm_device_name(ti->table->md), bdevname(bdev, b),
37393diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
37394index 4d6e853..a234157 100644
37395--- a/drivers/md/dm-thin-metadata.c
37396+++ b/drivers/md/dm-thin-metadata.c
37397@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37398 {
37399 pmd->info.tm = pmd->tm;
37400 pmd->info.levels = 2;
37401- pmd->info.value_type.context = pmd->data_sm;
37402+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37403 pmd->info.value_type.size = sizeof(__le64);
37404 pmd->info.value_type.inc = data_block_inc;
37405 pmd->info.value_type.dec = data_block_dec;
37406@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
37407
37408 pmd->bl_info.tm = pmd->tm;
37409 pmd->bl_info.levels = 1;
37410- pmd->bl_info.value_type.context = pmd->data_sm;
37411+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
37412 pmd->bl_info.value_type.size = sizeof(__le64);
37413 pmd->bl_info.value_type.inc = data_block_inc;
37414 pmd->bl_info.value_type.dec = data_block_dec;
37415diff --git a/drivers/md/dm.c b/drivers/md/dm.c
37416index 314a0e2..1376406 100644
37417--- a/drivers/md/dm.c
37418+++ b/drivers/md/dm.c
37419@@ -170,9 +170,9 @@ struct mapped_device {
37420 /*
37421 * Event handling.
37422 */
37423- atomic_t event_nr;
37424+ atomic_unchecked_t event_nr;
37425 wait_queue_head_t eventq;
37426- atomic_t uevent_seq;
37427+ atomic_unchecked_t uevent_seq;
37428 struct list_head uevent_list;
37429 spinlock_t uevent_lock; /* Protect access to uevent_list */
37430
37431@@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
37432 rwlock_init(&md->map_lock);
37433 atomic_set(&md->holders, 1);
37434 atomic_set(&md->open_count, 0);
37435- atomic_set(&md->event_nr, 0);
37436- atomic_set(&md->uevent_seq, 0);
37437+ atomic_set_unchecked(&md->event_nr, 0);
37438+ atomic_set_unchecked(&md->uevent_seq, 0);
37439 INIT_LIST_HEAD(&md->uevent_list);
37440 spin_lock_init(&md->uevent_lock);
37441
37442@@ -2014,7 +2014,7 @@ static void event_callback(void *context)
37443
37444 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
37445
37446- atomic_inc(&md->event_nr);
37447+ atomic_inc_unchecked(&md->event_nr);
37448 wake_up(&md->eventq);
37449 }
37450
37451@@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
37452
37453 uint32_t dm_next_uevent_seq(struct mapped_device *md)
37454 {
37455- return atomic_add_return(1, &md->uevent_seq);
37456+ return atomic_add_return_unchecked(1, &md->uevent_seq);
37457 }
37458
37459 uint32_t dm_get_event_nr(struct mapped_device *md)
37460 {
37461- return atomic_read(&md->event_nr);
37462+ return atomic_read_unchecked(&md->event_nr);
37463 }
37464
37465 int dm_wait_event(struct mapped_device *md, int event_nr)
37466 {
37467 return wait_event_interruptible(md->eventq,
37468- (event_nr != atomic_read(&md->event_nr)));
37469+ (event_nr != atomic_read_unchecked(&md->event_nr)));
37470 }
37471
37472 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
37473diff --git a/drivers/md/md.c b/drivers/md/md.c
37474index 3db3d1b..9487468 100644
37475--- a/drivers/md/md.c
37476+++ b/drivers/md/md.c
37477@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
37478 * start build, activate spare
37479 */
37480 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
37481-static atomic_t md_event_count;
37482+static atomic_unchecked_t md_event_count;
37483 void md_new_event(struct mddev *mddev)
37484 {
37485- atomic_inc(&md_event_count);
37486+ atomic_inc_unchecked(&md_event_count);
37487 wake_up(&md_event_waiters);
37488 }
37489 EXPORT_SYMBOL_GPL(md_new_event);
37490@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
37491 */
37492 static void md_new_event_inintr(struct mddev *mddev)
37493 {
37494- atomic_inc(&md_event_count);
37495+ atomic_inc_unchecked(&md_event_count);
37496 wake_up(&md_event_waiters);
37497 }
37498
37499@@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
37500 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
37501 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
37502 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
37503- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37504+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
37505
37506 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
37507 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
37508@@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
37509 else
37510 sb->resync_offset = cpu_to_le64(0);
37511
37512- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
37513+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
37514
37515 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
37516 sb->size = cpu_to_le64(mddev->dev_sectors);
37517@@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
37518 static ssize_t
37519 errors_show(struct md_rdev *rdev, char *page)
37520 {
37521- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
37522+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
37523 }
37524
37525 static ssize_t
37526@@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
37527 char *e;
37528 unsigned long n = simple_strtoul(buf, &e, 10);
37529 if (*buf && (*e == 0 || *e == '\n')) {
37530- atomic_set(&rdev->corrected_errors, n);
37531+ atomic_set_unchecked(&rdev->corrected_errors, n);
37532 return len;
37533 }
37534 return -EINVAL;
37535@@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
37536 rdev->sb_loaded = 0;
37537 rdev->bb_page = NULL;
37538 atomic_set(&rdev->nr_pending, 0);
37539- atomic_set(&rdev->read_errors, 0);
37540- atomic_set(&rdev->corrected_errors, 0);
37541+ atomic_set_unchecked(&rdev->read_errors, 0);
37542+ atomic_set_unchecked(&rdev->corrected_errors, 0);
37543
37544 INIT_LIST_HEAD(&rdev->same_set);
37545 init_waitqueue_head(&rdev->blocked_wait);
37546@@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
37547
37548 spin_unlock(&pers_lock);
37549 seq_printf(seq, "\n");
37550- seq->poll_event = atomic_read(&md_event_count);
37551+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37552 return 0;
37553 }
37554 if (v == (void*)2) {
37555@@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
37556 return error;
37557
37558 seq = file->private_data;
37559- seq->poll_event = atomic_read(&md_event_count);
37560+ seq->poll_event = atomic_read_unchecked(&md_event_count);
37561 return error;
37562 }
37563
37564@@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
37565 /* always allow read */
37566 mask = POLLIN | POLLRDNORM;
37567
37568- if (seq->poll_event != atomic_read(&md_event_count))
37569+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
37570 mask |= POLLERR | POLLPRI;
37571 return mask;
37572 }
37573@@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
37574 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
37575 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
37576 (int)part_stat_read(&disk->part0, sectors[1]) -
37577- atomic_read(&disk->sync_io);
37578+ atomic_read_unchecked(&disk->sync_io);
37579 /* sync IO will cause sync_io to increase before the disk_stats
37580 * as sync_io is counted when a request starts, and
37581 * disk_stats is counted when it completes.
37582diff --git a/drivers/md/md.h b/drivers/md/md.h
37583index eca59c3..7c42285 100644
37584--- a/drivers/md/md.h
37585+++ b/drivers/md/md.h
37586@@ -94,13 +94,13 @@ struct md_rdev {
37587 * only maintained for arrays that
37588 * support hot removal
37589 */
37590- atomic_t read_errors; /* number of consecutive read errors that
37591+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
37592 * we have tried to ignore.
37593 */
37594 struct timespec last_read_error; /* monotonic time since our
37595 * last read error
37596 */
37597- atomic_t corrected_errors; /* number of corrected read errors,
37598+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
37599 * for reporting to userspace and storing
37600 * in superblock.
37601 */
37602@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
37603
37604 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
37605 {
37606- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37607+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
37608 }
37609
37610 struct md_personality
37611diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
37612index 1cbfc6b..56e1dbb 100644
37613--- a/drivers/md/persistent-data/dm-space-map.h
37614+++ b/drivers/md/persistent-data/dm-space-map.h
37615@@ -60,6 +60,7 @@ struct dm_space_map {
37616 int (*root_size)(struct dm_space_map *sm, size_t *result);
37617 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
37618 };
37619+typedef struct dm_space_map __no_const dm_space_map_no_const;
37620
37621 /*----------------------------------------------------------------*/
37622
37623diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
37624index d5bddfc..b079b4b 100644
37625--- a/drivers/md/raid1.c
37626+++ b/drivers/md/raid1.c
37627@@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
37628 if (r1_sync_page_io(rdev, sect, s,
37629 bio->bi_io_vec[idx].bv_page,
37630 READ) != 0)
37631- atomic_add(s, &rdev->corrected_errors);
37632+ atomic_add_unchecked(s, &rdev->corrected_errors);
37633 }
37634 sectors -= s;
37635 sect += s;
37636@@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
37637 test_bit(In_sync, &rdev->flags)) {
37638 if (r1_sync_page_io(rdev, sect, s,
37639 conf->tmppage, READ)) {
37640- atomic_add(s, &rdev->corrected_errors);
37641+ atomic_add_unchecked(s, &rdev->corrected_errors);
37642 printk(KERN_INFO
37643 "md/raid1:%s: read error corrected "
37644 "(%d sectors at %llu on %s)\n",
37645diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
37646index 64d4824..8b9ea57 100644
37647--- a/drivers/md/raid10.c
37648+++ b/drivers/md/raid10.c
37649@@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
37650 /* The write handler will notice the lack of
37651 * R10BIO_Uptodate and record any errors etc
37652 */
37653- atomic_add(r10_bio->sectors,
37654+ atomic_add_unchecked(r10_bio->sectors,
37655 &conf->mirrors[d].rdev->corrected_errors);
37656
37657 /* for reconstruct, we always reschedule after a read.
37658@@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37659 {
37660 struct timespec cur_time_mon;
37661 unsigned long hours_since_last;
37662- unsigned int read_errors = atomic_read(&rdev->read_errors);
37663+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
37664
37665 ktime_get_ts(&cur_time_mon);
37666
37667@@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
37668 * overflowing the shift of read_errors by hours_since_last.
37669 */
37670 if (hours_since_last >= 8 * sizeof(read_errors))
37671- atomic_set(&rdev->read_errors, 0);
37672+ atomic_set_unchecked(&rdev->read_errors, 0);
37673 else
37674- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
37675+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
37676 }
37677
37678 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
37679@@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37680 return;
37681
37682 check_decay_read_errors(mddev, rdev);
37683- atomic_inc(&rdev->read_errors);
37684- if (atomic_read(&rdev->read_errors) > max_read_errors) {
37685+ atomic_inc_unchecked(&rdev->read_errors);
37686+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
37687 char b[BDEVNAME_SIZE];
37688 bdevname(rdev->bdev, b);
37689
37690@@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37691 "md/raid10:%s: %s: Raid device exceeded "
37692 "read_error threshold [cur %d:max %d]\n",
37693 mdname(mddev), b,
37694- atomic_read(&rdev->read_errors), max_read_errors);
37695+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
37696 printk(KERN_NOTICE
37697 "md/raid10:%s: %s: Failing raid device\n",
37698 mdname(mddev), b);
37699@@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
37700 sect +
37701 choose_data_offset(r10_bio, rdev)),
37702 bdevname(rdev->bdev, b));
37703- atomic_add(s, &rdev->corrected_errors);
37704+ atomic_add_unchecked(s, &rdev->corrected_errors);
37705 }
37706
37707 rdev_dec_pending(rdev, mddev);
37708diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
37709index 19d77a0..56051b92 100644
37710--- a/drivers/md/raid5.c
37711+++ b/drivers/md/raid5.c
37712@@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
37713 mdname(conf->mddev), STRIPE_SECTORS,
37714 (unsigned long long)s,
37715 bdevname(rdev->bdev, b));
37716- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
37717+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
37718 clear_bit(R5_ReadError, &sh->dev[i].flags);
37719 clear_bit(R5_ReWrite, &sh->dev[i].flags);
37720 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
37721 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
37722
37723- if (atomic_read(&rdev->read_errors))
37724- atomic_set(&rdev->read_errors, 0);
37725+ if (atomic_read_unchecked(&rdev->read_errors))
37726+ atomic_set_unchecked(&rdev->read_errors, 0);
37727 } else {
37728 const char *bdn = bdevname(rdev->bdev, b);
37729 int retry = 0;
37730 int set_bad = 0;
37731
37732 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
37733- atomic_inc(&rdev->read_errors);
37734+ atomic_inc_unchecked(&rdev->read_errors);
37735 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
37736 printk_ratelimited(
37737 KERN_WARNING
37738@@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
37739 mdname(conf->mddev),
37740 (unsigned long long)s,
37741 bdn);
37742- } else if (atomic_read(&rdev->read_errors)
37743+ } else if (atomic_read_unchecked(&rdev->read_errors)
37744 > conf->max_nr_stripes)
37745 printk(KERN_WARNING
37746 "md/raid:%s: Too many read errors, failing device %s.\n",
37747diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
37748index d33101a..6b13069 100644
37749--- a/drivers/media/dvb-core/dvbdev.c
37750+++ b/drivers/media/dvb-core/dvbdev.c
37751@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
37752 const struct dvb_device *template, void *priv, int type)
37753 {
37754 struct dvb_device *dvbdev;
37755- struct file_operations *dvbdevfops;
37756+ file_operations_no_const *dvbdevfops;
37757 struct device *clsdev;
37758 int minor;
37759 int id;
37760diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
37761index 404f63a..4796533 100644
37762--- a/drivers/media/dvb-frontends/dib3000.h
37763+++ b/drivers/media/dvb-frontends/dib3000.h
37764@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
37765 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
37766 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
37767 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
37768-};
37769+} __no_const;
37770
37771 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
37772 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
37773diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
37774index 8e9a668..78d6310 100644
37775--- a/drivers/media/platform/omap/omap_vout.c
37776+++ b/drivers/media/platform/omap/omap_vout.c
37777@@ -63,7 +63,6 @@ enum omap_vout_channels {
37778 OMAP_VIDEO2,
37779 };
37780
37781-static struct videobuf_queue_ops video_vbq_ops;
37782 /* Variables configurable through module params*/
37783 static u32 video1_numbuffers = 3;
37784 static u32 video2_numbuffers = 3;
37785@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
37786 {
37787 struct videobuf_queue *q;
37788 struct omap_vout_device *vout = NULL;
37789+ static struct videobuf_queue_ops video_vbq_ops = {
37790+ .buf_setup = omap_vout_buffer_setup,
37791+ .buf_prepare = omap_vout_buffer_prepare,
37792+ .buf_release = omap_vout_buffer_release,
37793+ .buf_queue = omap_vout_buffer_queue,
37794+ };
37795
37796 vout = video_drvdata(file);
37797 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
37798@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
37799 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
37800
37801 q = &vout->vbq;
37802- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
37803- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
37804- video_vbq_ops.buf_release = omap_vout_buffer_release;
37805- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
37806 spin_lock_init(&vout->vbq_lock);
37807
37808 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
37809diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
37810index b671e20..34088b7 100644
37811--- a/drivers/media/platform/s5p-tv/mixer.h
37812+++ b/drivers/media/platform/s5p-tv/mixer.h
37813@@ -155,7 +155,7 @@ struct mxr_layer {
37814 /** layer index (unique identifier) */
37815 int idx;
37816 /** callbacks for layer methods */
37817- struct mxr_layer_ops ops;
37818+ struct mxr_layer_ops *ops;
37819 /** format array */
37820 const struct mxr_format **fmt_array;
37821 /** size of format array */
37822diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37823index b93a21f..2535195 100644
37824--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37825+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
37826@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
37827 {
37828 struct mxr_layer *layer;
37829 int ret;
37830- struct mxr_layer_ops ops = {
37831+ static struct mxr_layer_ops ops = {
37832 .release = mxr_graph_layer_release,
37833 .buffer_set = mxr_graph_buffer_set,
37834 .stream_set = mxr_graph_stream_set,
37835diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
37836index 3b1670a..595c939 100644
37837--- a/drivers/media/platform/s5p-tv/mixer_reg.c
37838+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
37839@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
37840 layer->update_buf = next;
37841 }
37842
37843- layer->ops.buffer_set(layer, layer->update_buf);
37844+ layer->ops->buffer_set(layer, layer->update_buf);
37845
37846 if (done && done != layer->shadow_buf)
37847 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
37848diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
37849index 1f3b743..e839271 100644
37850--- a/drivers/media/platform/s5p-tv/mixer_video.c
37851+++ b/drivers/media/platform/s5p-tv/mixer_video.c
37852@@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
37853 layer->geo.src.height = layer->geo.src.full_height;
37854
37855 mxr_geometry_dump(mdev, &layer->geo);
37856- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37857+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37858 mxr_geometry_dump(mdev, &layer->geo);
37859 }
37860
37861@@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
37862 layer->geo.dst.full_width = mbus_fmt.width;
37863 layer->geo.dst.full_height = mbus_fmt.height;
37864 layer->geo.dst.field = mbus_fmt.field;
37865- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37866+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
37867
37868 mxr_geometry_dump(mdev, &layer->geo);
37869 }
37870@@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
37871 /* set source size to highest accepted value */
37872 geo->src.full_width = max(geo->dst.full_width, pix->width);
37873 geo->src.full_height = max(geo->dst.full_height, pix->height);
37874- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37875+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37876 mxr_geometry_dump(mdev, &layer->geo);
37877 /* set cropping to total visible screen */
37878 geo->src.width = pix->width;
37879@@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
37880 geo->src.x_offset = 0;
37881 geo->src.y_offset = 0;
37882 /* assure consistency of geometry */
37883- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37884+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
37885 mxr_geometry_dump(mdev, &layer->geo);
37886 /* set full size to lowest possible value */
37887 geo->src.full_width = 0;
37888 geo->src.full_height = 0;
37889- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37890+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
37891 mxr_geometry_dump(mdev, &layer->geo);
37892
37893 /* returning results */
37894@@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
37895 target->width = s->r.width;
37896 target->height = s->r.height;
37897
37898- layer->ops.fix_geometry(layer, stage, s->flags);
37899+ layer->ops->fix_geometry(layer, stage, s->flags);
37900
37901 /* retrieve update selection rectangle */
37902 res.left = target->x_offset;
37903@@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
37904 mxr_output_get(mdev);
37905
37906 mxr_layer_update_output(layer);
37907- layer->ops.format_set(layer);
37908+ layer->ops->format_set(layer);
37909 /* enabling layer in hardware */
37910 spin_lock_irqsave(&layer->enq_slock, flags);
37911 layer->state = MXR_LAYER_STREAMING;
37912 spin_unlock_irqrestore(&layer->enq_slock, flags);
37913
37914- layer->ops.stream_set(layer, MXR_ENABLE);
37915+ layer->ops->stream_set(layer, MXR_ENABLE);
37916 mxr_streamer_get(mdev);
37917
37918 return 0;
37919@@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
37920 spin_unlock_irqrestore(&layer->enq_slock, flags);
37921
37922 /* disabling layer in hardware */
37923- layer->ops.stream_set(layer, MXR_DISABLE);
37924+ layer->ops->stream_set(layer, MXR_DISABLE);
37925 /* remove one streamer */
37926 mxr_streamer_put(mdev);
37927 /* allow changes in output configuration */
37928@@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
37929
37930 void mxr_layer_release(struct mxr_layer *layer)
37931 {
37932- if (layer->ops.release)
37933- layer->ops.release(layer);
37934+ if (layer->ops->release)
37935+ layer->ops->release(layer);
37936 }
37937
37938 void mxr_base_layer_release(struct mxr_layer *layer)
37939@@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
37940
37941 layer->mdev = mdev;
37942 layer->idx = idx;
37943- layer->ops = *ops;
37944+ layer->ops = ops;
37945
37946 spin_lock_init(&layer->enq_slock);
37947 INIT_LIST_HEAD(&layer->enq_list);
37948diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37949index 3d13a63..da31bf1 100644
37950--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37951+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
37952@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
37953 {
37954 struct mxr_layer *layer;
37955 int ret;
37956- struct mxr_layer_ops ops = {
37957+ static struct mxr_layer_ops ops = {
37958 .release = mxr_vp_layer_release,
37959 .buffer_set = mxr_vp_buffer_set,
37960 .stream_set = mxr_vp_stream_set,
37961diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
37962index 643d80a..56bb96b 100644
37963--- a/drivers/media/radio/radio-cadet.c
37964+++ b/drivers/media/radio/radio-cadet.c
37965@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37966 unsigned char readbuf[RDS_BUFFER];
37967 int i = 0;
37968
37969+ if (count > RDS_BUFFER)
37970+ return -EFAULT;
37971 mutex_lock(&dev->lock);
37972 if (dev->rdsstat == 0)
37973 cadet_start_rds(dev);
37974@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
37975 while (i < count && dev->rdsin != dev->rdsout)
37976 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
37977
37978- if (i && copy_to_user(data, readbuf, i))
37979+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
37980 i = -EFAULT;
37981 unlock:
37982 mutex_unlock(&dev->lock);
37983diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
37984index 3940bb0..fb3952a 100644
37985--- a/drivers/media/usb/dvb-usb/cxusb.c
37986+++ b/drivers/media/usb/dvb-usb/cxusb.c
37987@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
37988
37989 struct dib0700_adapter_state {
37990 int (*set_param_save) (struct dvb_frontend *);
37991-};
37992+} __no_const;
37993
37994 static int dib7070_set_param_override(struct dvb_frontend *fe)
37995 {
37996diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
37997index 9382895..ac8093c 100644
37998--- a/drivers/media/usb/dvb-usb/dw2102.c
37999+++ b/drivers/media/usb/dvb-usb/dw2102.c
38000@@ -95,7 +95,7 @@ struct su3000_state {
38001
38002 struct s6x0_state {
38003 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38004-};
38005+} __no_const;
38006
38007 /* debug */
38008 static int dvb_usb_dw2102_debug;
38009diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38010index aa6e7c7..4cd8061 100644
38011--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38012+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38013@@ -1923,7 +1923,8 @@ struct v4l2_ioctl_info {
38014 struct file *file, void *fh, void *p);
38015 } u;
38016 void (*debug)(const void *arg, bool write_only);
38017-};
38018+} __do_const;
38019+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38020
38021 /* This control needs a priority check */
38022 #define INFO_FL_PRIO (1 << 0)
38023@@ -2108,7 +2109,7 @@ static long __video_do_ioctl(struct file *file,
38024 struct video_device *vfd = video_devdata(file);
38025 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38026 bool write_only = false;
38027- struct v4l2_ioctl_info default_info;
38028+ v4l2_ioctl_info_no_const default_info;
38029 const struct v4l2_ioctl_info *info;
38030 void *fh = file->private_data;
38031 struct v4l2_fh *vfh = NULL;
38032diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
38033index 29b2172..a7c5b31 100644
38034--- a/drivers/memstick/host/r592.c
38035+++ b/drivers/memstick/host/r592.c
38036@@ -454,7 +454,7 @@ static int r592_transfer_fifo_pio(struct r592_device *dev)
38037 /* Executes one TPC (data is read/written from small or large fifo) */
38038 static void r592_execute_tpc(struct r592_device *dev)
38039 {
38040- bool is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38041+ bool is_write;
38042 int len, error;
38043 u32 status, reg;
38044
38045@@ -463,6 +463,7 @@ static void r592_execute_tpc(struct r592_device *dev)
38046 return;
38047 }
38048
38049+ is_write = dev->req->tpc >= MS_TPC_SET_RW_REG_ADRS;
38050 len = dev->req->long_data ?
38051 dev->req->sg.length : dev->req->data_len;
38052
38053diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38054index fb69baa..cf7ad22 100644
38055--- a/drivers/message/fusion/mptbase.c
38056+++ b/drivers/message/fusion/mptbase.c
38057@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38058 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38059 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38060
38061+#ifdef CONFIG_GRKERNSEC_HIDESYM
38062+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38063+#else
38064 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38065 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38066+#endif
38067+
38068 /*
38069 * Rounding UP to nearest 4-kB boundary here...
38070 */
38071diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38072index fa43c39..daeb158 100644
38073--- a/drivers/message/fusion/mptsas.c
38074+++ b/drivers/message/fusion/mptsas.c
38075@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38076 return 0;
38077 }
38078
38079+static inline void
38080+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38081+{
38082+ if (phy_info->port_details) {
38083+ phy_info->port_details->rphy = rphy;
38084+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38085+ ioc->name, rphy));
38086+ }
38087+
38088+ if (rphy) {
38089+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38090+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38091+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38092+ ioc->name, rphy, rphy->dev.release));
38093+ }
38094+}
38095+
38096 /* no mutex */
38097 static void
38098 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
38099@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
38100 return NULL;
38101 }
38102
38103-static inline void
38104-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38105-{
38106- if (phy_info->port_details) {
38107- phy_info->port_details->rphy = rphy;
38108- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
38109- ioc->name, rphy));
38110- }
38111-
38112- if (rphy) {
38113- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
38114- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
38115- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
38116- ioc->name, rphy, rphy->dev.release));
38117- }
38118-}
38119-
38120 static inline struct sas_port *
38121 mptsas_get_port(struct mptsas_phyinfo *phy_info)
38122 {
38123diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
38124index 164afa7..b6b2e74 100644
38125--- a/drivers/message/fusion/mptscsih.c
38126+++ b/drivers/message/fusion/mptscsih.c
38127@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
38128
38129 h = shost_priv(SChost);
38130
38131- if (h) {
38132- if (h->info_kbuf == NULL)
38133- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38134- return h->info_kbuf;
38135- h->info_kbuf[0] = '\0';
38136+ if (!h)
38137+ return NULL;
38138
38139- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38140- h->info_kbuf[size-1] = '\0';
38141- }
38142+ if (h->info_kbuf == NULL)
38143+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
38144+ return h->info_kbuf;
38145+ h->info_kbuf[0] = '\0';
38146+
38147+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
38148+ h->info_kbuf[size-1] = '\0';
38149
38150 return h->info_kbuf;
38151 }
38152diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
38153index 8001aa6..b137580 100644
38154--- a/drivers/message/i2o/i2o_proc.c
38155+++ b/drivers/message/i2o/i2o_proc.c
38156@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
38157 "Array Controller Device"
38158 };
38159
38160-static char *chtostr(char *tmp, u8 *chars, int n)
38161-{
38162- tmp[0] = 0;
38163- return strncat(tmp, (char *)chars, n);
38164-}
38165-
38166 static int i2o_report_query_status(struct seq_file *seq, int block_status,
38167 char *group)
38168 {
38169@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38170 } *result;
38171
38172 i2o_exec_execute_ddm_table ddm_table;
38173- char tmp[28 + 1];
38174
38175 result = kmalloc(sizeof(*result), GFP_KERNEL);
38176 if (!result)
38177@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
38178
38179 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
38180 seq_printf(seq, "%-#8x", ddm_table.module_id);
38181- seq_printf(seq, "%-29s",
38182- chtostr(tmp, ddm_table.module_name_version, 28));
38183+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
38184 seq_printf(seq, "%9d ", ddm_table.data_size);
38185 seq_printf(seq, "%8d", ddm_table.code_size);
38186
38187@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38188
38189 i2o_driver_result_table *result;
38190 i2o_driver_store_table *dst;
38191- char tmp[28 + 1];
38192
38193 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
38194 if (result == NULL)
38195@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
38196
38197 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
38198 seq_printf(seq, "%-#8x", dst->module_id);
38199- seq_printf(seq, "%-29s",
38200- chtostr(tmp, dst->module_name_version, 28));
38201- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
38202+ seq_printf(seq, "%-.28s", dst->module_name_version);
38203+ seq_printf(seq, "%-.8s", dst->date);
38204 seq_printf(seq, "%8d ", dst->module_size);
38205 seq_printf(seq, "%8d ", dst->mpb_size);
38206 seq_printf(seq, "0x%04x", dst->module_flags);
38207@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38208 // == (allow) 512d bytes (max)
38209 static u16 *work16 = (u16 *) work32;
38210 int token;
38211- char tmp[16 + 1];
38212
38213 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
38214
38215@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
38216 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
38217 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
38218 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
38219- seq_printf(seq, "Vendor info : %s\n",
38220- chtostr(tmp, (u8 *) (work32 + 2), 16));
38221- seq_printf(seq, "Product info : %s\n",
38222- chtostr(tmp, (u8 *) (work32 + 6), 16));
38223- seq_printf(seq, "Description : %s\n",
38224- chtostr(tmp, (u8 *) (work32 + 10), 16));
38225- seq_printf(seq, "Product rev. : %s\n",
38226- chtostr(tmp, (u8 *) (work32 + 14), 8));
38227+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
38228+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
38229+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
38230+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
38231
38232 seq_printf(seq, "Serial number : ");
38233 print_serial_number(seq, (u8 *) (work32 + 16),
38234@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38235 u8 pad[256]; // allow up to 256 byte (max) serial number
38236 } result;
38237
38238- char tmp[24 + 1];
38239-
38240 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
38241
38242 if (token < 0) {
38243@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
38244 }
38245
38246 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
38247- seq_printf(seq, "Module name : %s\n",
38248- chtostr(tmp, result.module_name, 24));
38249- seq_printf(seq, "Module revision : %s\n",
38250- chtostr(tmp, result.module_rev, 8));
38251+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
38252+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
38253
38254 seq_printf(seq, "Serial number : ");
38255 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
38256@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38257 u8 instance_number[4];
38258 } result;
38259
38260- char tmp[64 + 1];
38261-
38262 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
38263
38264 if (token < 0) {
38265@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
38266 return 0;
38267 }
38268
38269- seq_printf(seq, "Device name : %s\n",
38270- chtostr(tmp, result.device_name, 64));
38271- seq_printf(seq, "Service name : %s\n",
38272- chtostr(tmp, result.service_name, 64));
38273- seq_printf(seq, "Physical name : %s\n",
38274- chtostr(tmp, result.physical_location, 64));
38275- seq_printf(seq, "Instance number : %s\n",
38276- chtostr(tmp, result.instance_number, 4));
38277+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
38278+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
38279+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
38280+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
38281
38282 return 0;
38283 }
38284diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
38285index a8c08f3..155fe3d 100644
38286--- a/drivers/message/i2o/iop.c
38287+++ b/drivers/message/i2o/iop.c
38288@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
38289
38290 spin_lock_irqsave(&c->context_list_lock, flags);
38291
38292- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
38293- atomic_inc(&c->context_list_counter);
38294+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
38295+ atomic_inc_unchecked(&c->context_list_counter);
38296
38297- entry->context = atomic_read(&c->context_list_counter);
38298+ entry->context = atomic_read_unchecked(&c->context_list_counter);
38299
38300 list_add(&entry->list, &c->context_list);
38301
38302@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
38303
38304 #if BITS_PER_LONG == 64
38305 spin_lock_init(&c->context_list_lock);
38306- atomic_set(&c->context_list_counter, 0);
38307+ atomic_set_unchecked(&c->context_list_counter, 0);
38308 INIT_LIST_HEAD(&c->context_list);
38309 #endif
38310
38311diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
38312index 45ece11..8efa218 100644
38313--- a/drivers/mfd/janz-cmodio.c
38314+++ b/drivers/mfd/janz-cmodio.c
38315@@ -13,6 +13,7 @@
38316
38317 #include <linux/kernel.h>
38318 #include <linux/module.h>
38319+#include <linux/slab.h>
38320 #include <linux/init.h>
38321 #include <linux/pci.h>
38322 #include <linux/interrupt.h>
38323diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
38324index a5f9888..1c0ed56 100644
38325--- a/drivers/mfd/twl4030-irq.c
38326+++ b/drivers/mfd/twl4030-irq.c
38327@@ -35,6 +35,7 @@
38328 #include <linux/of.h>
38329 #include <linux/irqdomain.h>
38330 #include <linux/i2c/twl.h>
38331+#include <asm/pgtable.h>
38332
38333 #include "twl-core.h"
38334
38335@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
38336 * Install an irq handler for each of the SIH modules;
38337 * clone dummy irq_chip since PIH can't *do* anything
38338 */
38339- twl4030_irq_chip = dummy_irq_chip;
38340- twl4030_irq_chip.name = "twl4030";
38341+ pax_open_kernel();
38342+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
38343+ *(const char **)&twl4030_irq_chip.name = "twl4030";
38344
38345- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38346+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
38347+ pax_close_kernel();
38348
38349 for (i = irq_base; i < irq_end; i++) {
38350 irq_set_chip_and_handler(i, &twl4030_irq_chip,
38351diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
38352index 277a8db..0e0b754 100644
38353--- a/drivers/mfd/twl6030-irq.c
38354+++ b/drivers/mfd/twl6030-irq.c
38355@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
38356 * install an irq handler for each of the modules;
38357 * clone dummy irq_chip since PIH can't *do* anything
38358 */
38359- twl6030_irq_chip = dummy_irq_chip;
38360- twl6030_irq_chip.name = "twl6030";
38361- twl6030_irq_chip.irq_set_type = NULL;
38362- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38363+ pax_open_kernel();
38364+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
38365+ *(const char **)&twl6030_irq_chip.name = "twl6030";
38366+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
38367+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
38368+ pax_close_kernel();
38369
38370 for (i = irq_base; i < irq_end; i++) {
38371 irq_set_chip_and_handler(i, &twl6030_irq_chip,
38372diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
38373index f428d86..274c368 100644
38374--- a/drivers/misc/c2port/core.c
38375+++ b/drivers/misc/c2port/core.c
38376@@ -924,7 +924,9 @@ struct c2port_device *c2port_device_register(char *name,
38377 mutex_init(&c2dev->mutex);
38378
38379 /* Create binary file */
38380- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38381+ pax_open_kernel();
38382+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
38383+ pax_close_kernel();
38384 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
38385 if (unlikely(ret))
38386 goto error_device_create_bin_file;
38387diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
38388index 3aa9a96..59cf685 100644
38389--- a/drivers/misc/kgdbts.c
38390+++ b/drivers/misc/kgdbts.c
38391@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
38392 char before[BREAK_INSTR_SIZE];
38393 char after[BREAK_INSTR_SIZE];
38394
38395- probe_kernel_read(before, (char *)kgdbts_break_test,
38396+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
38397 BREAK_INSTR_SIZE);
38398 init_simple_test();
38399 ts.tst = plant_and_detach_test;
38400@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
38401 /* Activate test with initial breakpoint */
38402 if (!is_early)
38403 kgdb_breakpoint();
38404- probe_kernel_read(after, (char *)kgdbts_break_test,
38405+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
38406 BREAK_INSTR_SIZE);
38407 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
38408 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
38409diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
38410index 4a87e5c..76bdf5c 100644
38411--- a/drivers/misc/lis3lv02d/lis3lv02d.c
38412+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
38413@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
38414 * the lid is closed. This leads to interrupts as soon as a little move
38415 * is done.
38416 */
38417- atomic_inc(&lis3->count);
38418+ atomic_inc_unchecked(&lis3->count);
38419
38420 wake_up_interruptible(&lis3->misc_wait);
38421 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
38422@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
38423 if (lis3->pm_dev)
38424 pm_runtime_get_sync(lis3->pm_dev);
38425
38426- atomic_set(&lis3->count, 0);
38427+ atomic_set_unchecked(&lis3->count, 0);
38428 return 0;
38429 }
38430
38431@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
38432 add_wait_queue(&lis3->misc_wait, &wait);
38433 while (true) {
38434 set_current_state(TASK_INTERRUPTIBLE);
38435- data = atomic_xchg(&lis3->count, 0);
38436+ data = atomic_xchg_unchecked(&lis3->count, 0);
38437 if (data)
38438 break;
38439
38440@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
38441 struct lis3lv02d, miscdev);
38442
38443 poll_wait(file, &lis3->misc_wait, wait);
38444- if (atomic_read(&lis3->count))
38445+ if (atomic_read_unchecked(&lis3->count))
38446 return POLLIN | POLLRDNORM;
38447 return 0;
38448 }
38449diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
38450index c439c82..1f20f57 100644
38451--- a/drivers/misc/lis3lv02d/lis3lv02d.h
38452+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
38453@@ -297,7 +297,7 @@ struct lis3lv02d {
38454 struct input_polled_dev *idev; /* input device */
38455 struct platform_device *pdev; /* platform device */
38456 struct regulator_bulk_data regulators[2];
38457- atomic_t count; /* interrupt count after last read */
38458+ atomic_unchecked_t count; /* interrupt count after last read */
38459 union axis_conversion ac; /* hw -> logical axis */
38460 int mapped_btns[3];
38461
38462diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
38463index 2f30bad..c4c13d0 100644
38464--- a/drivers/misc/sgi-gru/gruhandles.c
38465+++ b/drivers/misc/sgi-gru/gruhandles.c
38466@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
38467 unsigned long nsec;
38468
38469 nsec = CLKS2NSEC(clks);
38470- atomic_long_inc(&mcs_op_statistics[op].count);
38471- atomic_long_add(nsec, &mcs_op_statistics[op].total);
38472+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
38473+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
38474 if (mcs_op_statistics[op].max < nsec)
38475 mcs_op_statistics[op].max = nsec;
38476 }
38477diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
38478index 950dbe9..eeef0f8 100644
38479--- a/drivers/misc/sgi-gru/gruprocfs.c
38480+++ b/drivers/misc/sgi-gru/gruprocfs.c
38481@@ -32,9 +32,9 @@
38482
38483 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
38484
38485-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
38486+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
38487 {
38488- unsigned long val = atomic_long_read(v);
38489+ unsigned long val = atomic_long_read_unchecked(v);
38490
38491 seq_printf(s, "%16lu %s\n", val, id);
38492 }
38493@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
38494
38495 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
38496 for (op = 0; op < mcsop_last; op++) {
38497- count = atomic_long_read(&mcs_op_statistics[op].count);
38498- total = atomic_long_read(&mcs_op_statistics[op].total);
38499+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
38500+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
38501 max = mcs_op_statistics[op].max;
38502 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
38503 count ? total / count : 0, max);
38504diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
38505index 5c3ce24..4915ccb 100644
38506--- a/drivers/misc/sgi-gru/grutables.h
38507+++ b/drivers/misc/sgi-gru/grutables.h
38508@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
38509 * GRU statistics.
38510 */
38511 struct gru_stats_s {
38512- atomic_long_t vdata_alloc;
38513- atomic_long_t vdata_free;
38514- atomic_long_t gts_alloc;
38515- atomic_long_t gts_free;
38516- atomic_long_t gms_alloc;
38517- atomic_long_t gms_free;
38518- atomic_long_t gts_double_allocate;
38519- atomic_long_t assign_context;
38520- atomic_long_t assign_context_failed;
38521- atomic_long_t free_context;
38522- atomic_long_t load_user_context;
38523- atomic_long_t load_kernel_context;
38524- atomic_long_t lock_kernel_context;
38525- atomic_long_t unlock_kernel_context;
38526- atomic_long_t steal_user_context;
38527- atomic_long_t steal_kernel_context;
38528- atomic_long_t steal_context_failed;
38529- atomic_long_t nopfn;
38530- atomic_long_t asid_new;
38531- atomic_long_t asid_next;
38532- atomic_long_t asid_wrap;
38533- atomic_long_t asid_reuse;
38534- atomic_long_t intr;
38535- atomic_long_t intr_cbr;
38536- atomic_long_t intr_tfh;
38537- atomic_long_t intr_spurious;
38538- atomic_long_t intr_mm_lock_failed;
38539- atomic_long_t call_os;
38540- atomic_long_t call_os_wait_queue;
38541- atomic_long_t user_flush_tlb;
38542- atomic_long_t user_unload_context;
38543- atomic_long_t user_exception;
38544- atomic_long_t set_context_option;
38545- atomic_long_t check_context_retarget_intr;
38546- atomic_long_t check_context_unload;
38547- atomic_long_t tlb_dropin;
38548- atomic_long_t tlb_preload_page;
38549- atomic_long_t tlb_dropin_fail_no_asid;
38550- atomic_long_t tlb_dropin_fail_upm;
38551- atomic_long_t tlb_dropin_fail_invalid;
38552- atomic_long_t tlb_dropin_fail_range_active;
38553- atomic_long_t tlb_dropin_fail_idle;
38554- atomic_long_t tlb_dropin_fail_fmm;
38555- atomic_long_t tlb_dropin_fail_no_exception;
38556- atomic_long_t tfh_stale_on_fault;
38557- atomic_long_t mmu_invalidate_range;
38558- atomic_long_t mmu_invalidate_page;
38559- atomic_long_t flush_tlb;
38560- atomic_long_t flush_tlb_gru;
38561- atomic_long_t flush_tlb_gru_tgh;
38562- atomic_long_t flush_tlb_gru_zero_asid;
38563+ atomic_long_unchecked_t vdata_alloc;
38564+ atomic_long_unchecked_t vdata_free;
38565+ atomic_long_unchecked_t gts_alloc;
38566+ atomic_long_unchecked_t gts_free;
38567+ atomic_long_unchecked_t gms_alloc;
38568+ atomic_long_unchecked_t gms_free;
38569+ atomic_long_unchecked_t gts_double_allocate;
38570+ atomic_long_unchecked_t assign_context;
38571+ atomic_long_unchecked_t assign_context_failed;
38572+ atomic_long_unchecked_t free_context;
38573+ atomic_long_unchecked_t load_user_context;
38574+ atomic_long_unchecked_t load_kernel_context;
38575+ atomic_long_unchecked_t lock_kernel_context;
38576+ atomic_long_unchecked_t unlock_kernel_context;
38577+ atomic_long_unchecked_t steal_user_context;
38578+ atomic_long_unchecked_t steal_kernel_context;
38579+ atomic_long_unchecked_t steal_context_failed;
38580+ atomic_long_unchecked_t nopfn;
38581+ atomic_long_unchecked_t asid_new;
38582+ atomic_long_unchecked_t asid_next;
38583+ atomic_long_unchecked_t asid_wrap;
38584+ atomic_long_unchecked_t asid_reuse;
38585+ atomic_long_unchecked_t intr;
38586+ atomic_long_unchecked_t intr_cbr;
38587+ atomic_long_unchecked_t intr_tfh;
38588+ atomic_long_unchecked_t intr_spurious;
38589+ atomic_long_unchecked_t intr_mm_lock_failed;
38590+ atomic_long_unchecked_t call_os;
38591+ atomic_long_unchecked_t call_os_wait_queue;
38592+ atomic_long_unchecked_t user_flush_tlb;
38593+ atomic_long_unchecked_t user_unload_context;
38594+ atomic_long_unchecked_t user_exception;
38595+ atomic_long_unchecked_t set_context_option;
38596+ atomic_long_unchecked_t check_context_retarget_intr;
38597+ atomic_long_unchecked_t check_context_unload;
38598+ atomic_long_unchecked_t tlb_dropin;
38599+ atomic_long_unchecked_t tlb_preload_page;
38600+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
38601+ atomic_long_unchecked_t tlb_dropin_fail_upm;
38602+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
38603+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
38604+ atomic_long_unchecked_t tlb_dropin_fail_idle;
38605+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
38606+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
38607+ atomic_long_unchecked_t tfh_stale_on_fault;
38608+ atomic_long_unchecked_t mmu_invalidate_range;
38609+ atomic_long_unchecked_t mmu_invalidate_page;
38610+ atomic_long_unchecked_t flush_tlb;
38611+ atomic_long_unchecked_t flush_tlb_gru;
38612+ atomic_long_unchecked_t flush_tlb_gru_tgh;
38613+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
38614
38615- atomic_long_t copy_gpa;
38616- atomic_long_t read_gpa;
38617+ atomic_long_unchecked_t copy_gpa;
38618+ atomic_long_unchecked_t read_gpa;
38619
38620- atomic_long_t mesq_receive;
38621- atomic_long_t mesq_receive_none;
38622- atomic_long_t mesq_send;
38623- atomic_long_t mesq_send_failed;
38624- atomic_long_t mesq_noop;
38625- atomic_long_t mesq_send_unexpected_error;
38626- atomic_long_t mesq_send_lb_overflow;
38627- atomic_long_t mesq_send_qlimit_reached;
38628- atomic_long_t mesq_send_amo_nacked;
38629- atomic_long_t mesq_send_put_nacked;
38630- atomic_long_t mesq_page_overflow;
38631- atomic_long_t mesq_qf_locked;
38632- atomic_long_t mesq_qf_noop_not_full;
38633- atomic_long_t mesq_qf_switch_head_failed;
38634- atomic_long_t mesq_qf_unexpected_error;
38635- atomic_long_t mesq_noop_unexpected_error;
38636- atomic_long_t mesq_noop_lb_overflow;
38637- atomic_long_t mesq_noop_qlimit_reached;
38638- atomic_long_t mesq_noop_amo_nacked;
38639- atomic_long_t mesq_noop_put_nacked;
38640- atomic_long_t mesq_noop_page_overflow;
38641+ atomic_long_unchecked_t mesq_receive;
38642+ atomic_long_unchecked_t mesq_receive_none;
38643+ atomic_long_unchecked_t mesq_send;
38644+ atomic_long_unchecked_t mesq_send_failed;
38645+ atomic_long_unchecked_t mesq_noop;
38646+ atomic_long_unchecked_t mesq_send_unexpected_error;
38647+ atomic_long_unchecked_t mesq_send_lb_overflow;
38648+ atomic_long_unchecked_t mesq_send_qlimit_reached;
38649+ atomic_long_unchecked_t mesq_send_amo_nacked;
38650+ atomic_long_unchecked_t mesq_send_put_nacked;
38651+ atomic_long_unchecked_t mesq_page_overflow;
38652+ atomic_long_unchecked_t mesq_qf_locked;
38653+ atomic_long_unchecked_t mesq_qf_noop_not_full;
38654+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
38655+ atomic_long_unchecked_t mesq_qf_unexpected_error;
38656+ atomic_long_unchecked_t mesq_noop_unexpected_error;
38657+ atomic_long_unchecked_t mesq_noop_lb_overflow;
38658+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
38659+ atomic_long_unchecked_t mesq_noop_amo_nacked;
38660+ atomic_long_unchecked_t mesq_noop_put_nacked;
38661+ atomic_long_unchecked_t mesq_noop_page_overflow;
38662
38663 };
38664
38665@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
38666 tghop_invalidate, mcsop_last};
38667
38668 struct mcs_op_statistic {
38669- atomic_long_t count;
38670- atomic_long_t total;
38671+ atomic_long_unchecked_t count;
38672+ atomic_long_unchecked_t total;
38673 unsigned long max;
38674 };
38675
38676@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
38677
38678 #define STAT(id) do { \
38679 if (gru_options & OPT_STATS) \
38680- atomic_long_inc(&gru_stats.id); \
38681+ atomic_long_inc_unchecked(&gru_stats.id); \
38682 } while (0)
38683
38684 #ifdef CONFIG_SGI_GRU_DEBUG
38685diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
38686index c862cd4..0d176fe 100644
38687--- a/drivers/misc/sgi-xp/xp.h
38688+++ b/drivers/misc/sgi-xp/xp.h
38689@@ -288,7 +288,7 @@ struct xpc_interface {
38690 xpc_notify_func, void *);
38691 void (*received) (short, int, void *);
38692 enum xp_retval (*partid_to_nasids) (short, void *);
38693-};
38694+} __no_const;
38695
38696 extern struct xpc_interface xpc_interface;
38697
38698diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
38699index b94d5f7..7f494c5 100644
38700--- a/drivers/misc/sgi-xp/xpc.h
38701+++ b/drivers/misc/sgi-xp/xpc.h
38702@@ -835,6 +835,7 @@ struct xpc_arch_operations {
38703 void (*received_payload) (struct xpc_channel *, void *);
38704 void (*notify_senders_of_disconnect) (struct xpc_channel *);
38705 };
38706+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
38707
38708 /* struct xpc_partition act_state values (for XPC HB) */
38709
38710@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
38711 /* found in xpc_main.c */
38712 extern struct device *xpc_part;
38713 extern struct device *xpc_chan;
38714-extern struct xpc_arch_operations xpc_arch_ops;
38715+extern xpc_arch_operations_no_const xpc_arch_ops;
38716 extern int xpc_disengage_timelimit;
38717 extern int xpc_disengage_timedout;
38718 extern int xpc_activate_IRQ_rcvd;
38719diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
38720index d971817..33bdca5 100644
38721--- a/drivers/misc/sgi-xp/xpc_main.c
38722+++ b/drivers/misc/sgi-xp/xpc_main.c
38723@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
38724 .notifier_call = xpc_system_die,
38725 };
38726
38727-struct xpc_arch_operations xpc_arch_ops;
38728+xpc_arch_operations_no_const xpc_arch_ops;
38729
38730 /*
38731 * Timer function to enforce the timelimit on the partition disengage.
38732@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
38733
38734 if (((die_args->trapnr == X86_TRAP_MF) ||
38735 (die_args->trapnr == X86_TRAP_XF)) &&
38736- !user_mode_vm(die_args->regs))
38737+ !user_mode(die_args->regs))
38738 xpc_die_deactivate();
38739
38740 break;
38741diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
38742index 6d8f701..35b6369 100644
38743--- a/drivers/mmc/core/mmc_ops.c
38744+++ b/drivers/mmc/core/mmc_ops.c
38745@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
38746 void *data_buf;
38747 int is_on_stack;
38748
38749- is_on_stack = object_is_on_stack(buf);
38750+ is_on_stack = object_starts_on_stack(buf);
38751 if (is_on_stack) {
38752 /*
38753 * dma onto stack is unsafe/nonportable, but callers to this
38754diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
38755index 53b8fd9..615b462 100644
38756--- a/drivers/mmc/host/dw_mmc.h
38757+++ b/drivers/mmc/host/dw_mmc.h
38758@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
38759 int (*parse_dt)(struct dw_mci *host);
38760 int (*setup_bus)(struct dw_mci *host,
38761 struct device_node *slot_np, u8 bus_width);
38762-};
38763+} __do_const;
38764 #endif /* _DW_MMC_H_ */
38765diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
38766index 82a8de1..3c56ccb 100644
38767--- a/drivers/mmc/host/sdhci-s3c.c
38768+++ b/drivers/mmc/host/sdhci-s3c.c
38769@@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
38770 * we can use overriding functions instead of default.
38771 */
38772 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
38773- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38774- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38775- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38776+ pax_open_kernel();
38777+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
38778+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
38779+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
38780+ pax_close_kernel();
38781 }
38782
38783 /* It supports additional host capabilities if needed */
38784diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
38785index a4eb8b5..8c0628f 100644
38786--- a/drivers/mtd/devices/doc2000.c
38787+++ b/drivers/mtd/devices/doc2000.c
38788@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
38789
38790 /* The ECC will not be calculated correctly if less than 512 is written */
38791 /* DBB-
38792- if (len != 0x200 && eccbuf)
38793+ if (len != 0x200)
38794 printk(KERN_WARNING
38795 "ECC needs a full sector write (adr: %lx size %lx)\n",
38796 (long) to, (long) len);
38797diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
38798index 0c8bb6b..6f35deb 100644
38799--- a/drivers/mtd/nand/denali.c
38800+++ b/drivers/mtd/nand/denali.c
38801@@ -24,6 +24,7 @@
38802 #include <linux/slab.h>
38803 #include <linux/mtd/mtd.h>
38804 #include <linux/module.h>
38805+#include <linux/slab.h>
38806
38807 #include "denali.h"
38808
38809diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
38810index 51b9d6a..52af9a7 100644
38811--- a/drivers/mtd/nftlmount.c
38812+++ b/drivers/mtd/nftlmount.c
38813@@ -24,6 +24,7 @@
38814 #include <asm/errno.h>
38815 #include <linux/delay.h>
38816 #include <linux/slab.h>
38817+#include <linux/sched.h>
38818 #include <linux/mtd/mtd.h>
38819 #include <linux/mtd/nand.h>
38820 #include <linux/mtd/nftl.h>
38821diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
38822index 8dd6ba5..419cc1d 100644
38823--- a/drivers/mtd/sm_ftl.c
38824+++ b/drivers/mtd/sm_ftl.c
38825@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
38826 #define SM_CIS_VENDOR_OFFSET 0x59
38827 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
38828 {
38829- struct attribute_group *attr_group;
38830+ attribute_group_no_const *attr_group;
38831 struct attribute **attributes;
38832 struct sm_sysfs_attribute *vendor_attribute;
38833
38834diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
38835index b7d45f3..b5c89d9 100644
38836--- a/drivers/net/bonding/bond_main.c
38837+++ b/drivers/net/bonding/bond_main.c
38838@@ -4861,7 +4861,7 @@ static unsigned int bond_get_num_tx_queues(void)
38839 return tx_queues;
38840 }
38841
38842-static struct rtnl_link_ops bond_link_ops __read_mostly = {
38843+static struct rtnl_link_ops bond_link_ops = {
38844 .kind = "bond",
38845 .priv_size = sizeof(struct bonding),
38846 .setup = bond_setup,
38847diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
38848index 70dba5d..11a0919 100644
38849--- a/drivers/net/ethernet/8390/ax88796.c
38850+++ b/drivers/net/ethernet/8390/ax88796.c
38851@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
38852 if (ax->plat->reg_offsets)
38853 ei_local->reg_offset = ax->plat->reg_offsets;
38854 else {
38855+ resource_size_t _mem_size = mem_size;
38856+ do_div(_mem_size, 0x18);
38857 ei_local->reg_offset = ax->reg_offsets;
38858 for (ret = 0; ret < 0x18; ret++)
38859- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
38860+ ax->reg_offsets[ret] = _mem_size * ret;
38861 }
38862
38863 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
38864diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38865index 0991534..8098e92 100644
38866--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38867+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
38868@@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
38869 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
38870 {
38871 /* RX_MODE controlling object */
38872- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
38873+ bnx2x_init_rx_mode_obj(bp);
38874
38875 /* multicast configuration controlling object */
38876 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
38877diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38878index 09b625e..15b16fe 100644
38879--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38880+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
38881@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
38882 return rc;
38883 }
38884
38885-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38886- struct bnx2x_rx_mode_obj *o)
38887+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
38888 {
38889 if (CHIP_IS_E1x(bp)) {
38890- o->wait_comp = bnx2x_empty_rx_mode_wait;
38891- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
38892+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
38893+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
38894 } else {
38895- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
38896- o->config_rx_mode = bnx2x_set_rx_mode_e2;
38897+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
38898+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
38899 }
38900 }
38901
38902diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38903index adbd91b..58ec94a 100644
38904--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38905+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
38906@@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
38907
38908 /********************* RX MODE ****************/
38909
38910-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
38911- struct bnx2x_rx_mode_obj *o);
38912+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
38913
38914 /**
38915 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
38916diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
38917index d330e81..ce1fb9a 100644
38918--- a/drivers/net/ethernet/broadcom/tg3.h
38919+++ b/drivers/net/ethernet/broadcom/tg3.h
38920@@ -146,6 +146,7 @@
38921 #define CHIPREV_ID_5750_A0 0x4000
38922 #define CHIPREV_ID_5750_A1 0x4001
38923 #define CHIPREV_ID_5750_A3 0x4003
38924+#define CHIPREV_ID_5750_C1 0x4201
38925 #define CHIPREV_ID_5750_C2 0x4202
38926 #define CHIPREV_ID_5752_A0_HW 0x5000
38927 #define CHIPREV_ID_5752_A0 0x6000
38928diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38929index 8cffcdf..aadf043 100644
38930--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38931+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
38932@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
38933 */
38934 struct l2t_skb_cb {
38935 arp_failure_handler_func arp_failure_handler;
38936-};
38937+} __no_const;
38938
38939 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
38940
38941diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
38942index 4c83003..2a2a5b9 100644
38943--- a/drivers/net/ethernet/dec/tulip/de4x5.c
38944+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
38945@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38946 for (i=0; i<ETH_ALEN; i++) {
38947 tmp.addr[i] = dev->dev_addr[i];
38948 }
38949- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38950+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
38951 break;
38952
38953 case DE4X5_SET_HWADDR: /* Set the hardware address */
38954@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
38955 spin_lock_irqsave(&lp->lock, flags);
38956 memcpy(&statbuf, &lp->pktStats, ioc->len);
38957 spin_unlock_irqrestore(&lp->lock, flags);
38958- if (copy_to_user(ioc->data, &statbuf, ioc->len))
38959+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
38960 return -EFAULT;
38961 break;
38962 }
38963diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
38964index 4d6f3c5..6169e60 100644
38965--- a/drivers/net/ethernet/emulex/benet/be_main.c
38966+++ b/drivers/net/ethernet/emulex/benet/be_main.c
38967@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
38968
38969 if (wrapped)
38970 newacc += 65536;
38971- ACCESS_ONCE(*acc) = newacc;
38972+ ACCESS_ONCE_RW(*acc) = newacc;
38973 }
38974
38975 void be_parse_stats(struct be_adapter *adapter)
38976diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
38977index 74d749e..eefb1bd 100644
38978--- a/drivers/net/ethernet/faraday/ftgmac100.c
38979+++ b/drivers/net/ethernet/faraday/ftgmac100.c
38980@@ -31,6 +31,8 @@
38981 #include <linux/netdevice.h>
38982 #include <linux/phy.h>
38983 #include <linux/platform_device.h>
38984+#include <linux/interrupt.h>
38985+#include <linux/irqreturn.h>
38986 #include <net/ip.h>
38987
38988 #include "ftgmac100.h"
38989diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
38990index b901a01..1ff32ee 100644
38991--- a/drivers/net/ethernet/faraday/ftmac100.c
38992+++ b/drivers/net/ethernet/faraday/ftmac100.c
38993@@ -31,6 +31,8 @@
38994 #include <linux/module.h>
38995 #include <linux/netdevice.h>
38996 #include <linux/platform_device.h>
38997+#include <linux/interrupt.h>
38998+#include <linux/irqreturn.h>
38999
39000 #include "ftmac100.h"
39001
39002diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39003index bb9256a..56d8752 100644
39004--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39005+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39006@@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39007 }
39008
39009 /* update the base incval used to calculate frequency adjustment */
39010- ACCESS_ONCE(adapter->base_incval) = incval;
39011+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39012 smp_mb();
39013
39014 /* need lock to prevent incorrect read while modifying cyclecounter */
39015diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39016index fbe5363..266b4e3 100644
39017--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39018+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39019@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39020 struct __vxge_hw_fifo *fifo;
39021 struct vxge_hw_fifo_config *config;
39022 u32 txdl_size, txdl_per_memblock;
39023- struct vxge_hw_mempool_cbs fifo_mp_callback;
39024+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39025+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39026+ };
39027+
39028 struct __vxge_hw_virtualpath *vpath;
39029
39030 if ((vp == NULL) || (attr == NULL)) {
39031@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39032 goto exit;
39033 }
39034
39035- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39036-
39037 fifo->mempool =
39038 __vxge_hw_mempool_create(vpath->hldev,
39039 fifo->config->memblock_size,
39040diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
39041index 998974f..ecd26db 100644
39042--- a/drivers/net/ethernet/realtek/r8169.c
39043+++ b/drivers/net/ethernet/realtek/r8169.c
39044@@ -741,22 +741,22 @@ struct rtl8169_private {
39045 struct mdio_ops {
39046 void (*write)(struct rtl8169_private *, int, int);
39047 int (*read)(struct rtl8169_private *, int);
39048- } mdio_ops;
39049+ } __no_const mdio_ops;
39050
39051 struct pll_power_ops {
39052 void (*down)(struct rtl8169_private *);
39053 void (*up)(struct rtl8169_private *);
39054- } pll_power_ops;
39055+ } __no_const pll_power_ops;
39056
39057 struct jumbo_ops {
39058 void (*enable)(struct rtl8169_private *);
39059 void (*disable)(struct rtl8169_private *);
39060- } jumbo_ops;
39061+ } __no_const jumbo_ops;
39062
39063 struct csi_ops {
39064 void (*write)(struct rtl8169_private *, int, int);
39065 u32 (*read)(struct rtl8169_private *, int);
39066- } csi_ops;
39067+ } __no_const csi_ops;
39068
39069 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
39070 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
39071diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
39072index 0767043f..08c2553 100644
39073--- a/drivers/net/ethernet/sfc/ptp.c
39074+++ b/drivers/net/ethernet/sfc/ptp.c
39075@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
39076 (u32)((u64)ptp->start.dma_addr >> 32));
39077
39078 /* Clear flag that signals MC ready */
39079- ACCESS_ONCE(*start) = 0;
39080+ ACCESS_ONCE_RW(*start) = 0;
39081 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
39082 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
39083
39084diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39085index 0c74a70..3bc6f68 100644
39086--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39087+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
39088@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
39089
39090 writel(value, ioaddr + MMC_CNTRL);
39091
39092- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39093- MMC_CNTRL, value);
39094+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
39095+// MMC_CNTRL, value);
39096 }
39097
39098 /* To mask all all interrupts.*/
39099diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
39100index e6fe0d8..2b7d752 100644
39101--- a/drivers/net/hyperv/hyperv_net.h
39102+++ b/drivers/net/hyperv/hyperv_net.h
39103@@ -101,7 +101,7 @@ struct rndis_device {
39104
39105 enum rndis_device_state state;
39106 bool link_state;
39107- atomic_t new_req_id;
39108+ atomic_unchecked_t new_req_id;
39109
39110 spinlock_t request_lock;
39111 struct list_head req_list;
39112diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
39113index 2b657d4..9903bc0 100644
39114--- a/drivers/net/hyperv/rndis_filter.c
39115+++ b/drivers/net/hyperv/rndis_filter.c
39116@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
39117 * template
39118 */
39119 set = &rndis_msg->msg.set_req;
39120- set->req_id = atomic_inc_return(&dev->new_req_id);
39121+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39122
39123 /* Add to the request list */
39124 spin_lock_irqsave(&dev->request_lock, flags);
39125@@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
39126
39127 /* Setup the rndis set */
39128 halt = &request->request_msg.msg.halt_req;
39129- halt->req_id = atomic_inc_return(&dev->new_req_id);
39130+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
39131
39132 /* Ignore return since this msg is optional. */
39133 rndis_filter_send_request(dev, request);
39134diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
39135index 1e9cb0b..7839125 100644
39136--- a/drivers/net/ieee802154/fakehard.c
39137+++ b/drivers/net/ieee802154/fakehard.c
39138@@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
39139 phy->transmit_power = 0xbf;
39140
39141 dev->netdev_ops = &fake_ops;
39142- dev->ml_priv = &fake_mlme;
39143+ dev->ml_priv = (void *)&fake_mlme;
39144
39145 priv = netdev_priv(dev);
39146 priv->phy = phy;
39147diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
39148index d3fb97d..19520c7 100644
39149--- a/drivers/net/macvlan.c
39150+++ b/drivers/net/macvlan.c
39151@@ -851,13 +851,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
39152 int macvlan_link_register(struct rtnl_link_ops *ops)
39153 {
39154 /* common fields */
39155- ops->priv_size = sizeof(struct macvlan_dev);
39156- ops->validate = macvlan_validate;
39157- ops->maxtype = IFLA_MACVLAN_MAX;
39158- ops->policy = macvlan_policy;
39159- ops->changelink = macvlan_changelink;
39160- ops->get_size = macvlan_get_size;
39161- ops->fill_info = macvlan_fill_info;
39162+ pax_open_kernel();
39163+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
39164+ *(void **)&ops->validate = macvlan_validate;
39165+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
39166+ *(const void **)&ops->policy = macvlan_policy;
39167+ *(void **)&ops->changelink = macvlan_changelink;
39168+ *(void **)&ops->get_size = macvlan_get_size;
39169+ *(void **)&ops->fill_info = macvlan_fill_info;
39170+ pax_close_kernel();
39171
39172 return rtnl_link_register(ops);
39173 };
39174@@ -913,7 +915,7 @@ static int macvlan_device_event(struct notifier_block *unused,
39175 return NOTIFY_DONE;
39176 }
39177
39178-static struct notifier_block macvlan_notifier_block __read_mostly = {
39179+static struct notifier_block macvlan_notifier_block = {
39180 .notifier_call = macvlan_device_event,
39181 };
39182
39183diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
39184index 0f0f9ce..0ca5819 100644
39185--- a/drivers/net/macvtap.c
39186+++ b/drivers/net/macvtap.c
39187@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
39188 return NOTIFY_DONE;
39189 }
39190
39191-static struct notifier_block macvtap_notifier_block __read_mostly = {
39192+static struct notifier_block macvtap_notifier_block = {
39193 .notifier_call = macvtap_device_event,
39194 };
39195
39196diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
39197index daec9b0..6428fcb 100644
39198--- a/drivers/net/phy/mdio-bitbang.c
39199+++ b/drivers/net/phy/mdio-bitbang.c
39200@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
39201 struct mdiobb_ctrl *ctrl = bus->priv;
39202
39203 module_put(ctrl->ops->owner);
39204+ mdiobus_unregister(bus);
39205 mdiobus_free(bus);
39206 }
39207 EXPORT_SYMBOL(free_mdio_bitbang);
39208diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
39209index 508570e..f706dc7 100644
39210--- a/drivers/net/ppp/ppp_generic.c
39211+++ b/drivers/net/ppp/ppp_generic.c
39212@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39213 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
39214 struct ppp_stats stats;
39215 struct ppp_comp_stats cstats;
39216- char *vers;
39217
39218 switch (cmd) {
39219 case SIOCGPPPSTATS:
39220@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39221 break;
39222
39223 case SIOCGPPPVER:
39224- vers = PPP_VERSION;
39225- if (copy_to_user(addr, vers, strlen(vers) + 1))
39226+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
39227 break;
39228 err = 0;
39229 break;
39230diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
39231index ad86660..9fd0884 100644
39232--- a/drivers/net/team/team.c
39233+++ b/drivers/net/team/team.c
39234@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
39235 return NOTIFY_DONE;
39236 }
39237
39238-static struct notifier_block team_notifier_block __read_mostly = {
39239+static struct notifier_block team_notifier_block = {
39240 .notifier_call = team_device_event,
39241 };
39242
39243diff --git a/drivers/net/tun.c b/drivers/net/tun.c
39244index 2917a86..edd463f 100644
39245--- a/drivers/net/tun.c
39246+++ b/drivers/net/tun.c
39247@@ -1836,7 +1836,7 @@ unlock:
39248 }
39249
39250 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39251- unsigned long arg, int ifreq_len)
39252+ unsigned long arg, size_t ifreq_len)
39253 {
39254 struct tun_file *tfile = file->private_data;
39255 struct tun_struct *tun;
39256@@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
39257 int vnet_hdr_sz;
39258 int ret;
39259
39260+ if (ifreq_len > sizeof ifr)
39261+ return -EFAULT;
39262+
39263 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
39264 if (copy_from_user(&ifr, argp, ifreq_len))
39265 return -EFAULT;
39266diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
39267index cd8ccb2..cff5144 100644
39268--- a/drivers/net/usb/hso.c
39269+++ b/drivers/net/usb/hso.c
39270@@ -71,7 +71,7 @@
39271 #include <asm/byteorder.h>
39272 #include <linux/serial_core.h>
39273 #include <linux/serial.h>
39274-
39275+#include <asm/local.h>
39276
39277 #define MOD_AUTHOR "Option Wireless"
39278 #define MOD_DESCRIPTION "USB High Speed Option driver"
39279@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
39280 struct urb *urb;
39281
39282 urb = serial->rx_urb[0];
39283- if (serial->port.count > 0) {
39284+ if (atomic_read(&serial->port.count) > 0) {
39285 count = put_rxbuf_data(urb, serial);
39286 if (count == -1)
39287 return;
39288@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
39289 DUMP1(urb->transfer_buffer, urb->actual_length);
39290
39291 /* Anyone listening? */
39292- if (serial->port.count == 0)
39293+ if (atomic_read(&serial->port.count) == 0)
39294 return;
39295
39296 if (status == 0) {
39297@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39298 tty_port_tty_set(&serial->port, tty);
39299
39300 /* check for port already opened, if not set the termios */
39301- serial->port.count++;
39302- if (serial->port.count == 1) {
39303+ if (atomic_inc_return(&serial->port.count) == 1) {
39304 serial->rx_state = RX_IDLE;
39305 /* Force default termio settings */
39306 _hso_serial_set_termios(tty, NULL);
39307@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
39308 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
39309 if (result) {
39310 hso_stop_serial_device(serial->parent);
39311- serial->port.count--;
39312+ atomic_dec(&serial->port.count);
39313 kref_put(&serial->parent->ref, hso_serial_ref_free);
39314 }
39315 } else {
39316@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
39317
39318 /* reset the rts and dtr */
39319 /* do the actual close */
39320- serial->port.count--;
39321+ atomic_dec(&serial->port.count);
39322
39323- if (serial->port.count <= 0) {
39324- serial->port.count = 0;
39325+ if (atomic_read(&serial->port.count) <= 0) {
39326+ atomic_set(&serial->port.count, 0);
39327 tty_port_tty_set(&serial->port, NULL);
39328 if (!usb_gone)
39329 hso_stop_serial_device(serial->parent);
39330@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
39331
39332 /* the actual setup */
39333 spin_lock_irqsave(&serial->serial_lock, flags);
39334- if (serial->port.count)
39335+ if (atomic_read(&serial->port.count))
39336 _hso_serial_set_termios(tty, old);
39337 else
39338 tty->termios = *old;
39339@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
39340 D1("Pending read interrupt on port %d\n", i);
39341 spin_lock(&serial->serial_lock);
39342 if (serial->rx_state == RX_IDLE &&
39343- serial->port.count > 0) {
39344+ atomic_read(&serial->port.count) > 0) {
39345 /* Setup and send a ctrl req read on
39346 * port i */
39347 if (!serial->rx_urb_filled[0]) {
39348@@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
39349 /* Start all serial ports */
39350 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
39351 if (serial_table[i] && (serial_table[i]->interface == iface)) {
39352- if (dev2ser(serial_table[i])->port.count) {
39353+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
39354 result =
39355 hso_start_serial_device(serial_table[i], GFP_NOIO);
39356 hso_kick_transmit(dev2ser(serial_table[i]));
39357diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
39358index 656230e..15525a8 100644
39359--- a/drivers/net/vxlan.c
39360+++ b/drivers/net/vxlan.c
39361@@ -1428,7 +1428,7 @@ nla_put_failure:
39362 return -EMSGSIZE;
39363 }
39364
39365-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
39366+static struct rtnl_link_ops vxlan_link_ops = {
39367 .kind = "vxlan",
39368 .maxtype = IFLA_VXLAN_MAX,
39369 .policy = vxlan_policy,
39370diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39371index 8d78253..bebbb68 100644
39372--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39373+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
39374@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39375 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
39376 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
39377
39378- ACCESS_ONCE(ads->ds_link) = i->link;
39379- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
39380+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
39381+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
39382
39383 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
39384 ctl6 = SM(i->keytype, AR_EncrType);
39385@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39386
39387 if ((i->is_first || i->is_last) &&
39388 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
39389- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
39390+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
39391 | set11nTries(i->rates, 1)
39392 | set11nTries(i->rates, 2)
39393 | set11nTries(i->rates, 3)
39394 | (i->dur_update ? AR_DurUpdateEna : 0)
39395 | SM(0, AR_BurstDur);
39396
39397- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
39398+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
39399 | set11nRate(i->rates, 1)
39400 | set11nRate(i->rates, 2)
39401 | set11nRate(i->rates, 3);
39402 } else {
39403- ACCESS_ONCE(ads->ds_ctl2) = 0;
39404- ACCESS_ONCE(ads->ds_ctl3) = 0;
39405+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
39406+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
39407 }
39408
39409 if (!i->is_first) {
39410- ACCESS_ONCE(ads->ds_ctl0) = 0;
39411- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39412- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39413+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
39414+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39415+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39416 return;
39417 }
39418
39419@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39420 break;
39421 }
39422
39423- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39424+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
39425 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39426 | SM(i->txpower, AR_XmitPower)
39427 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39428@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39429 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
39430 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
39431
39432- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
39433- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
39434+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
39435+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
39436
39437 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
39438 return;
39439
39440- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39441+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
39442 | set11nPktDurRTSCTS(i->rates, 1);
39443
39444- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39445+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
39446 | set11nPktDurRTSCTS(i->rates, 3);
39447
39448- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39449+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
39450 | set11nRateFlags(i->rates, 1)
39451 | set11nRateFlags(i->rates, 2)
39452 | set11nRateFlags(i->rates, 3)
39453diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39454index 301bf72..3f5654f 100644
39455--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39456+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
39457@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39458 (i->qcu << AR_TxQcuNum_S) | desc_len;
39459
39460 checksum += val;
39461- ACCESS_ONCE(ads->info) = val;
39462+ ACCESS_ONCE_RW(ads->info) = val;
39463
39464 checksum += i->link;
39465- ACCESS_ONCE(ads->link) = i->link;
39466+ ACCESS_ONCE_RW(ads->link) = i->link;
39467
39468 checksum += i->buf_addr[0];
39469- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
39470+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
39471 checksum += i->buf_addr[1];
39472- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
39473+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
39474 checksum += i->buf_addr[2];
39475- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
39476+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
39477 checksum += i->buf_addr[3];
39478- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
39479+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
39480
39481 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
39482- ACCESS_ONCE(ads->ctl3) = val;
39483+ ACCESS_ONCE_RW(ads->ctl3) = val;
39484 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
39485- ACCESS_ONCE(ads->ctl5) = val;
39486+ ACCESS_ONCE_RW(ads->ctl5) = val;
39487 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
39488- ACCESS_ONCE(ads->ctl7) = val;
39489+ ACCESS_ONCE_RW(ads->ctl7) = val;
39490 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
39491- ACCESS_ONCE(ads->ctl9) = val;
39492+ ACCESS_ONCE_RW(ads->ctl9) = val;
39493
39494 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
39495- ACCESS_ONCE(ads->ctl10) = checksum;
39496+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
39497
39498 if (i->is_first || i->is_last) {
39499- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
39500+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
39501 | set11nTries(i->rates, 1)
39502 | set11nTries(i->rates, 2)
39503 | set11nTries(i->rates, 3)
39504 | (i->dur_update ? AR_DurUpdateEna : 0)
39505 | SM(0, AR_BurstDur);
39506
39507- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
39508+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
39509 | set11nRate(i->rates, 1)
39510 | set11nRate(i->rates, 2)
39511 | set11nRate(i->rates, 3);
39512 } else {
39513- ACCESS_ONCE(ads->ctl13) = 0;
39514- ACCESS_ONCE(ads->ctl14) = 0;
39515+ ACCESS_ONCE_RW(ads->ctl13) = 0;
39516+ ACCESS_ONCE_RW(ads->ctl14) = 0;
39517 }
39518
39519 ads->ctl20 = 0;
39520@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39521
39522 ctl17 = SM(i->keytype, AR_EncrType);
39523 if (!i->is_first) {
39524- ACCESS_ONCE(ads->ctl11) = 0;
39525- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39526- ACCESS_ONCE(ads->ctl15) = 0;
39527- ACCESS_ONCE(ads->ctl16) = 0;
39528- ACCESS_ONCE(ads->ctl17) = ctl17;
39529- ACCESS_ONCE(ads->ctl18) = 0;
39530- ACCESS_ONCE(ads->ctl19) = 0;
39531+ ACCESS_ONCE_RW(ads->ctl11) = 0;
39532+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
39533+ ACCESS_ONCE_RW(ads->ctl15) = 0;
39534+ ACCESS_ONCE_RW(ads->ctl16) = 0;
39535+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39536+ ACCESS_ONCE_RW(ads->ctl18) = 0;
39537+ ACCESS_ONCE_RW(ads->ctl19) = 0;
39538 return;
39539 }
39540
39541- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39542+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
39543 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
39544 | SM(i->txpower, AR_XmitPower)
39545 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
39546@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
39547 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
39548 ctl12 |= SM(val, AR_PAPRDChainMask);
39549
39550- ACCESS_ONCE(ads->ctl12) = ctl12;
39551- ACCESS_ONCE(ads->ctl17) = ctl17;
39552+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
39553+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
39554
39555- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39556+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
39557 | set11nPktDurRTSCTS(i->rates, 1);
39558
39559- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39560+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
39561 | set11nPktDurRTSCTS(i->rates, 3);
39562
39563- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
39564+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
39565 | set11nRateFlags(i->rates, 1)
39566 | set11nRateFlags(i->rates, 2)
39567 | set11nRateFlags(i->rates, 3)
39568 | SM(i->rtscts_rate, AR_RTSCTSRate);
39569
39570- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
39571+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
39572 }
39573
39574 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
39575diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
39576index 9d26fc5..60d9f14 100644
39577--- a/drivers/net/wireless/ath/ath9k/hw.h
39578+++ b/drivers/net/wireless/ath/ath9k/hw.h
39579@@ -658,7 +658,7 @@ struct ath_hw_private_ops {
39580
39581 /* ANI */
39582 void (*ani_cache_ini_regs)(struct ath_hw *ah);
39583-};
39584+} __no_const;
39585
39586 /**
39587 * struct ath_hw_ops - callbacks used by hardware code and driver code
39588@@ -688,7 +688,7 @@ struct ath_hw_ops {
39589 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
39590 struct ath_hw_antcomb_conf *antconf);
39591 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
39592-};
39593+} __no_const;
39594
39595 struct ath_nf_limits {
39596 s16 max;
39597diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
39598index 3726cd6..b655808 100644
39599--- a/drivers/net/wireless/iwlegacy/3945-mac.c
39600+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
39601@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
39602 */
39603 if (il3945_mod_params.disable_hw_scan) {
39604 D_INFO("Disabling hw_scan\n");
39605- il3945_mac_ops.hw_scan = NULL;
39606+ pax_open_kernel();
39607+ *(void **)&il3945_mac_ops.hw_scan = NULL;
39608+ pax_close_kernel();
39609 }
39610
39611 D_INFO("*** LOAD DRIVER ***\n");
39612diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39613index 5b9533e..7733880 100644
39614--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39615+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
39616@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
39617 {
39618 struct iwl_priv *priv = file->private_data;
39619 char buf[64];
39620- int buf_size;
39621+ size_t buf_size;
39622 u32 offset, len;
39623
39624 memset(buf, 0, sizeof(buf));
39625@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
39626 struct iwl_priv *priv = file->private_data;
39627
39628 char buf[8];
39629- int buf_size;
39630+ size_t buf_size;
39631 u32 reset_flag;
39632
39633 memset(buf, 0, sizeof(buf));
39634@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
39635 {
39636 struct iwl_priv *priv = file->private_data;
39637 char buf[8];
39638- int buf_size;
39639+ size_t buf_size;
39640 int ht40;
39641
39642 memset(buf, 0, sizeof(buf));
39643@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
39644 {
39645 struct iwl_priv *priv = file->private_data;
39646 char buf[8];
39647- int buf_size;
39648+ size_t buf_size;
39649 int value;
39650
39651 memset(buf, 0, sizeof(buf));
39652@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
39653 {
39654 struct iwl_priv *priv = file->private_data;
39655 char buf[8];
39656- int buf_size;
39657+ size_t buf_size;
39658 int clear;
39659
39660 memset(buf, 0, sizeof(buf));
39661@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
39662 {
39663 struct iwl_priv *priv = file->private_data;
39664 char buf[8];
39665- int buf_size;
39666+ size_t buf_size;
39667 int trace;
39668
39669 memset(buf, 0, sizeof(buf));
39670@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
39671 {
39672 struct iwl_priv *priv = file->private_data;
39673 char buf[8];
39674- int buf_size;
39675+ size_t buf_size;
39676 int missed;
39677
39678 memset(buf, 0, sizeof(buf));
39679@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
39680
39681 struct iwl_priv *priv = file->private_data;
39682 char buf[8];
39683- int buf_size;
39684+ size_t buf_size;
39685 int plcp;
39686
39687 memset(buf, 0, sizeof(buf));
39688@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
39689
39690 struct iwl_priv *priv = file->private_data;
39691 char buf[8];
39692- int buf_size;
39693+ size_t buf_size;
39694 int flush;
39695
39696 memset(buf, 0, sizeof(buf));
39697@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
39698
39699 struct iwl_priv *priv = file->private_data;
39700 char buf[8];
39701- int buf_size;
39702+ size_t buf_size;
39703 int rts;
39704
39705 if (!priv->cfg->ht_params)
39706@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
39707 {
39708 struct iwl_priv *priv = file->private_data;
39709 char buf[8];
39710- int buf_size;
39711+ size_t buf_size;
39712
39713 memset(buf, 0, sizeof(buf));
39714 buf_size = min(count, sizeof(buf) - 1);
39715@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
39716 struct iwl_priv *priv = file->private_data;
39717 u32 event_log_flag;
39718 char buf[8];
39719- int buf_size;
39720+ size_t buf_size;
39721
39722 /* check that the interface is up */
39723 if (!iwl_is_ready(priv))
39724@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
39725 struct iwl_priv *priv = file->private_data;
39726 char buf[8];
39727 u32 calib_disabled;
39728- int buf_size;
39729+ size_t buf_size;
39730
39731 memset(buf, 0, sizeof(buf));
39732 buf_size = min(count, sizeof(buf) - 1);
39733diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
39734index 35708b9..31f7754 100644
39735--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
39736+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
39737@@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
39738 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
39739
39740 char buf[8];
39741- int buf_size;
39742+ size_t buf_size;
39743 u32 reset_flag;
39744
39745 memset(buf, 0, sizeof(buf));
39746@@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
39747 {
39748 struct iwl_trans *trans = file->private_data;
39749 char buf[8];
39750- int buf_size;
39751+ size_t buf_size;
39752 int csr;
39753
39754 memset(buf, 0, sizeof(buf));
39755diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
39756index ff90855..e46d223 100644
39757--- a/drivers/net/wireless/mac80211_hwsim.c
39758+++ b/drivers/net/wireless/mac80211_hwsim.c
39759@@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
39760
39761 if (channels > 1) {
39762 hwsim_if_comb.num_different_channels = channels;
39763- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39764- mac80211_hwsim_ops.cancel_hw_scan =
39765- mac80211_hwsim_cancel_hw_scan;
39766- mac80211_hwsim_ops.sw_scan_start = NULL;
39767- mac80211_hwsim_ops.sw_scan_complete = NULL;
39768- mac80211_hwsim_ops.remain_on_channel =
39769- mac80211_hwsim_roc;
39770- mac80211_hwsim_ops.cancel_remain_on_channel =
39771- mac80211_hwsim_croc;
39772- mac80211_hwsim_ops.add_chanctx =
39773- mac80211_hwsim_add_chanctx;
39774- mac80211_hwsim_ops.remove_chanctx =
39775- mac80211_hwsim_remove_chanctx;
39776- mac80211_hwsim_ops.change_chanctx =
39777- mac80211_hwsim_change_chanctx;
39778- mac80211_hwsim_ops.assign_vif_chanctx =
39779- mac80211_hwsim_assign_vif_chanctx;
39780- mac80211_hwsim_ops.unassign_vif_chanctx =
39781- mac80211_hwsim_unassign_vif_chanctx;
39782+ pax_open_kernel();
39783+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
39784+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
39785+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
39786+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
39787+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
39788+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
39789+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
39790+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
39791+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
39792+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
39793+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
39794+ pax_close_kernel();
39795 }
39796
39797 spin_lock_init(&hwsim_radio_lock);
39798diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
39799index abe1d03..fb02c22 100644
39800--- a/drivers/net/wireless/rndis_wlan.c
39801+++ b/drivers/net/wireless/rndis_wlan.c
39802@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
39803
39804 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
39805
39806- if (rts_threshold < 0 || rts_threshold > 2347)
39807+ if (rts_threshold > 2347)
39808 rts_threshold = 2347;
39809
39810 tmp = cpu_to_le32(rts_threshold);
39811diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
39812index 0751b35..246ba3e 100644
39813--- a/drivers/net/wireless/rt2x00/rt2x00.h
39814+++ b/drivers/net/wireless/rt2x00/rt2x00.h
39815@@ -398,7 +398,7 @@ struct rt2x00_intf {
39816 * for hardware which doesn't support hardware
39817 * sequence counting.
39818 */
39819- atomic_t seqno;
39820+ atomic_unchecked_t seqno;
39821 };
39822
39823 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
39824diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
39825index e488b94..14b6a0c 100644
39826--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
39827+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
39828@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
39829 * sequence counter given by mac80211.
39830 */
39831 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
39832- seqno = atomic_add_return(0x10, &intf->seqno);
39833+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
39834 else
39835- seqno = atomic_read(&intf->seqno);
39836+ seqno = atomic_read_unchecked(&intf->seqno);
39837
39838 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
39839 hdr->seq_ctrl |= cpu_to_le16(seqno);
39840diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
39841index e57ee48..541cf6c 100644
39842--- a/drivers/net/wireless/ti/wl1251/sdio.c
39843+++ b/drivers/net/wireless/ti/wl1251/sdio.c
39844@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
39845
39846 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
39847
39848- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39849- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39850+ pax_open_kernel();
39851+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
39852+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
39853+ pax_close_kernel();
39854
39855 wl1251_info("using dedicated interrupt line");
39856 } else {
39857- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39858- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39859+ pax_open_kernel();
39860+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
39861+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
39862+ pax_close_kernel();
39863
39864 wl1251_info("using SDIO interrupt");
39865 }
39866diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
39867index e5f5f8f..fdf15b7 100644
39868--- a/drivers/net/wireless/ti/wl12xx/main.c
39869+++ b/drivers/net/wireless/ti/wl12xx/main.c
39870@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39871 sizeof(wl->conf.mem));
39872
39873 /* read data preparation is only needed by wl127x */
39874- wl->ops->prepare_read = wl127x_prepare_read;
39875+ pax_open_kernel();
39876+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39877+ pax_close_kernel();
39878
39879 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39880 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39881@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
39882 sizeof(wl->conf.mem));
39883
39884 /* read data preparation is only needed by wl127x */
39885- wl->ops->prepare_read = wl127x_prepare_read;
39886+ pax_open_kernel();
39887+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
39888+ pax_close_kernel();
39889
39890 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
39891 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
39892diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
39893index 8d8c1f8..e754844 100644
39894--- a/drivers/net/wireless/ti/wl18xx/main.c
39895+++ b/drivers/net/wireless/ti/wl18xx/main.c
39896@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
39897 }
39898
39899 if (!checksum_param) {
39900- wl18xx_ops.set_rx_csum = NULL;
39901- wl18xx_ops.init_vif = NULL;
39902+ pax_open_kernel();
39903+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
39904+ *(void **)&wl18xx_ops.init_vif = NULL;
39905+ pax_close_kernel();
39906 }
39907
39908 /* Enable 11a Band only if we have 5G antennas */
39909diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
39910index d93b2b6..ae50401 100644
39911--- a/drivers/oprofile/buffer_sync.c
39912+++ b/drivers/oprofile/buffer_sync.c
39913@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
39914 if (cookie == NO_COOKIE)
39915 offset = pc;
39916 if (cookie == INVALID_COOKIE) {
39917- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39918+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39919 offset = pc;
39920 }
39921 if (cookie != last_cookie) {
39922@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
39923 /* add userspace sample */
39924
39925 if (!mm) {
39926- atomic_inc(&oprofile_stats.sample_lost_no_mm);
39927+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
39928 return 0;
39929 }
39930
39931 cookie = lookup_dcookie(mm, s->eip, &offset);
39932
39933 if (cookie == INVALID_COOKIE) {
39934- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
39935+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
39936 return 0;
39937 }
39938
39939@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
39940 /* ignore backtraces if failed to add a sample */
39941 if (state == sb_bt_start) {
39942 state = sb_bt_ignore;
39943- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
39944+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
39945 }
39946 }
39947 release_mm(mm);
39948diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
39949index c0cc4e7..44d4e54 100644
39950--- a/drivers/oprofile/event_buffer.c
39951+++ b/drivers/oprofile/event_buffer.c
39952@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
39953 }
39954
39955 if (buffer_pos == buffer_size) {
39956- atomic_inc(&oprofile_stats.event_lost_overflow);
39957+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
39958 return;
39959 }
39960
39961diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
39962index ed2c3ec..deda85a 100644
39963--- a/drivers/oprofile/oprof.c
39964+++ b/drivers/oprofile/oprof.c
39965@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
39966 if (oprofile_ops.switch_events())
39967 return;
39968
39969- atomic_inc(&oprofile_stats.multiplex_counter);
39970+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
39971 start_switch_worker();
39972 }
39973
39974diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
39975index 917d28e..d62d981 100644
39976--- a/drivers/oprofile/oprofile_stats.c
39977+++ b/drivers/oprofile/oprofile_stats.c
39978@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
39979 cpu_buf->sample_invalid_eip = 0;
39980 }
39981
39982- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
39983- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
39984- atomic_set(&oprofile_stats.event_lost_overflow, 0);
39985- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
39986- atomic_set(&oprofile_stats.multiplex_counter, 0);
39987+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
39988+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
39989+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
39990+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
39991+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
39992 }
39993
39994
39995diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
39996index 38b6fc0..b5cbfce 100644
39997--- a/drivers/oprofile/oprofile_stats.h
39998+++ b/drivers/oprofile/oprofile_stats.h
39999@@ -13,11 +13,11 @@
40000 #include <linux/atomic.h>
40001
40002 struct oprofile_stat_struct {
40003- atomic_t sample_lost_no_mm;
40004- atomic_t sample_lost_no_mapping;
40005- atomic_t bt_lost_no_mapping;
40006- atomic_t event_lost_overflow;
40007- atomic_t multiplex_counter;
40008+ atomic_unchecked_t sample_lost_no_mm;
40009+ atomic_unchecked_t sample_lost_no_mapping;
40010+ atomic_unchecked_t bt_lost_no_mapping;
40011+ atomic_unchecked_t event_lost_overflow;
40012+ atomic_unchecked_t multiplex_counter;
40013 };
40014
40015 extern struct oprofile_stat_struct oprofile_stats;
40016diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
40017index 849357c..b83c1e0 100644
40018--- a/drivers/oprofile/oprofilefs.c
40019+++ b/drivers/oprofile/oprofilefs.c
40020@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
40021
40022
40023 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
40024- char const *name, atomic_t *val)
40025+ char const *name, atomic_unchecked_t *val)
40026 {
40027 return __oprofilefs_create_file(sb, root, name,
40028 &atomic_ro_fops, 0444, val);
40029diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
40030index 93404f7..4a313d8 100644
40031--- a/drivers/oprofile/timer_int.c
40032+++ b/drivers/oprofile/timer_int.c
40033@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
40034 return NOTIFY_OK;
40035 }
40036
40037-static struct notifier_block __refdata oprofile_cpu_notifier = {
40038+static struct notifier_block oprofile_cpu_notifier = {
40039 .notifier_call = oprofile_cpu_notify,
40040 };
40041
40042diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
40043index 3f56bc0..707d642 100644
40044--- a/drivers/parport/procfs.c
40045+++ b/drivers/parport/procfs.c
40046@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
40047
40048 *ppos += len;
40049
40050- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
40051+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
40052 }
40053
40054 #ifdef CONFIG_PARPORT_1284
40055@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
40056
40057 *ppos += len;
40058
40059- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
40060+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
40061 }
40062 #endif /* IEEE1284.3 support. */
40063
40064diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
40065index c35e8ad..fc33beb 100644
40066--- a/drivers/pci/hotplug/acpiphp_ibm.c
40067+++ b/drivers/pci/hotplug/acpiphp_ibm.c
40068@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
40069 goto init_cleanup;
40070 }
40071
40072- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40073+ pax_open_kernel();
40074+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
40075+ pax_close_kernel();
40076 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
40077
40078 return retval;
40079diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
40080index a6a71c4..c91097b 100644
40081--- a/drivers/pci/hotplug/cpcihp_generic.c
40082+++ b/drivers/pci/hotplug/cpcihp_generic.c
40083@@ -73,7 +73,6 @@ static u16 port;
40084 static unsigned int enum_bit;
40085 static u8 enum_mask;
40086
40087-static struct cpci_hp_controller_ops generic_hpc_ops;
40088 static struct cpci_hp_controller generic_hpc;
40089
40090 static int __init validate_parameters(void)
40091@@ -139,6 +138,10 @@ static int query_enum(void)
40092 return ((value & enum_mask) == enum_mask);
40093 }
40094
40095+static struct cpci_hp_controller_ops generic_hpc_ops = {
40096+ .query_enum = query_enum,
40097+};
40098+
40099 static int __init cpcihp_generic_init(void)
40100 {
40101 int status;
40102@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
40103 pci_dev_put(dev);
40104
40105 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
40106- generic_hpc_ops.query_enum = query_enum;
40107 generic_hpc.ops = &generic_hpc_ops;
40108
40109 status = cpci_hp_register_controller(&generic_hpc);
40110diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
40111index 449b4bb..257e2e8 100644
40112--- a/drivers/pci/hotplug/cpcihp_zt5550.c
40113+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
40114@@ -59,7 +59,6 @@
40115 /* local variables */
40116 static bool debug;
40117 static bool poll;
40118-static struct cpci_hp_controller_ops zt5550_hpc_ops;
40119 static struct cpci_hp_controller zt5550_hpc;
40120
40121 /* Primary cPCI bus bridge device */
40122@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
40123 return 0;
40124 }
40125
40126+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
40127+ .query_enum = zt5550_hc_query_enum,
40128+};
40129+
40130 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
40131 {
40132 int status;
40133@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
40134 dbg("returned from zt5550_hc_config");
40135
40136 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
40137- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
40138 zt5550_hpc.ops = &zt5550_hpc_ops;
40139 if(!poll) {
40140 zt5550_hpc.irq = hc_dev->irq;
40141 zt5550_hpc.irq_flags = IRQF_SHARED;
40142 zt5550_hpc.dev_id = hc_dev;
40143
40144- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40145- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40146- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40147+ pax_open_kernel();
40148+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
40149+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
40150+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
40151+ pax_open_kernel();
40152 } else {
40153 info("using ENUM# polling mode");
40154 }
40155diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
40156index 76ba8a1..20ca857 100644
40157--- a/drivers/pci/hotplug/cpqphp_nvram.c
40158+++ b/drivers/pci/hotplug/cpqphp_nvram.c
40159@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
40160
40161 void compaq_nvram_init (void __iomem *rom_start)
40162 {
40163+
40164+#ifndef CONFIG_PAX_KERNEXEC
40165 if (rom_start) {
40166 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
40167 }
40168+#endif
40169+
40170 dbg("int15 entry = %p\n", compaq_int15_entry_point);
40171
40172 /* initialize our int15 lock */
40173diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
40174index 202f4a9..8ee47d0 100644
40175--- a/drivers/pci/hotplug/pci_hotplug_core.c
40176+++ b/drivers/pci/hotplug/pci_hotplug_core.c
40177@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
40178 return -EINVAL;
40179 }
40180
40181- slot->ops->owner = owner;
40182- slot->ops->mod_name = mod_name;
40183+ pax_open_kernel();
40184+ *(struct module **)&slot->ops->owner = owner;
40185+ *(const char **)&slot->ops->mod_name = mod_name;
40186+ pax_close_kernel();
40187
40188 mutex_lock(&pci_hp_mutex);
40189 /*
40190diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
40191index 939bd1d..a1459c9 100644
40192--- a/drivers/pci/hotplug/pciehp_core.c
40193+++ b/drivers/pci/hotplug/pciehp_core.c
40194@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
40195 struct slot *slot = ctrl->slot;
40196 struct hotplug_slot *hotplug = NULL;
40197 struct hotplug_slot_info *info = NULL;
40198- struct hotplug_slot_ops *ops = NULL;
40199+ hotplug_slot_ops_no_const *ops = NULL;
40200 char name[SLOT_NAME_SIZE];
40201 int retval = -ENOMEM;
40202
40203diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
40204index 9c6e9bb..2916736 100644
40205--- a/drivers/pci/pci-sysfs.c
40206+++ b/drivers/pci/pci-sysfs.c
40207@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
40208 {
40209 /* allocate attribute structure, piggyback attribute name */
40210 int name_len = write_combine ? 13 : 10;
40211- struct bin_attribute *res_attr;
40212+ bin_attribute_no_const *res_attr;
40213 int retval;
40214
40215 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
40216@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
40217 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
40218 {
40219 int retval;
40220- struct bin_attribute *attr;
40221+ bin_attribute_no_const *attr;
40222
40223 /* If the device has VPD, try to expose it in sysfs. */
40224 if (dev->vpd) {
40225@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
40226 {
40227 int retval;
40228 int rom_size = 0;
40229- struct bin_attribute *attr;
40230+ bin_attribute_no_const *attr;
40231
40232 if (!sysfs_initialized)
40233 return -EACCES;
40234diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
40235index e851829..a1a7196 100644
40236--- a/drivers/pci/pci.h
40237+++ b/drivers/pci/pci.h
40238@@ -98,7 +98,7 @@ struct pci_vpd_ops {
40239 struct pci_vpd {
40240 unsigned int len;
40241 const struct pci_vpd_ops *ops;
40242- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
40243+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
40244 };
40245
40246 extern int pci_vpd_pci22_init(struct pci_dev *dev);
40247diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
40248index 8474b6a..ee81993 100644
40249--- a/drivers/pci/pcie/aspm.c
40250+++ b/drivers/pci/pcie/aspm.c
40251@@ -27,9 +27,9 @@
40252 #define MODULE_PARAM_PREFIX "pcie_aspm."
40253
40254 /* Note: those are not register definitions */
40255-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
40256-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
40257-#define ASPM_STATE_L1 (4) /* L1 state */
40258+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
40259+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
40260+#define ASPM_STATE_L1 (4U) /* L1 state */
40261 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
40262 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
40263
40264diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
40265index 6186f03..1a78714 100644
40266--- a/drivers/pci/probe.c
40267+++ b/drivers/pci/probe.c
40268@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
40269 struct pci_bus_region region;
40270 bool bar_too_big = false, bar_disabled = false;
40271
40272- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
40273+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
40274
40275 /* No printks while decoding is disabled! */
40276 if (!dev->mmio_always_on) {
40277diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
40278index 9b8505c..f00870a 100644
40279--- a/drivers/pci/proc.c
40280+++ b/drivers/pci/proc.c
40281@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
40282 static int __init pci_proc_init(void)
40283 {
40284 struct pci_dev *dev = NULL;
40285+
40286+#ifdef CONFIG_GRKERNSEC_PROC_ADD
40287+#ifdef CONFIG_GRKERNSEC_PROC_USER
40288+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
40289+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
40290+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
40291+#endif
40292+#else
40293 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
40294+#endif
40295 proc_create("devices", 0, proc_bus_pci_dir,
40296 &proc_bus_pci_dev_operations);
40297 proc_initialized = 1;
40298diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
40299index 2111dbb..79e434b 100644
40300--- a/drivers/platform/x86/msi-laptop.c
40301+++ b/drivers/platform/x86/msi-laptop.c
40302@@ -820,12 +820,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
40303 int result;
40304
40305 /* allow userland write sysfs file */
40306- dev_attr_bluetooth.store = store_bluetooth;
40307- dev_attr_wlan.store = store_wlan;
40308- dev_attr_threeg.store = store_threeg;
40309- dev_attr_bluetooth.attr.mode |= S_IWUSR;
40310- dev_attr_wlan.attr.mode |= S_IWUSR;
40311- dev_attr_threeg.attr.mode |= S_IWUSR;
40312+ pax_open_kernel();
40313+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
40314+ *(void **)&dev_attr_wlan.store = store_wlan;
40315+ *(void **)&dev_attr_threeg.store = store_threeg;
40316+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
40317+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
40318+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
40319+ pax_close_kernel();
40320
40321 /* disable hardware control by fn key */
40322 result = ec_read(MSI_STANDARD_EC_SCM_LOAD_ADDRESS, &data);
40323diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
40324index b8ad71f..3ec9bb4 100644
40325--- a/drivers/platform/x86/sony-laptop.c
40326+++ b/drivers/platform/x86/sony-laptop.c
40327@@ -2356,7 +2356,7 @@ static void sony_nc_lid_resume_cleanup(struct platform_device *pd)
40328 }
40329
40330 /* High speed charging function */
40331-static struct device_attribute *hsc_handle;
40332+static device_attribute_no_const *hsc_handle;
40333
40334 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
40335 struct device_attribute *attr,
40336diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
40337index f946ca7..f25c833 100644
40338--- a/drivers/platform/x86/thinkpad_acpi.c
40339+++ b/drivers/platform/x86/thinkpad_acpi.c
40340@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
40341 return 0;
40342 }
40343
40344-void static hotkey_mask_warn_incomplete_mask(void)
40345+static void hotkey_mask_warn_incomplete_mask(void)
40346 {
40347 /* log only what the user can fix... */
40348 const u32 wantedmask = hotkey_driver_mask &
40349@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
40350 }
40351 }
40352
40353-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40354- struct tp_nvram_state *newn,
40355- const u32 event_mask)
40356-{
40357-
40358 #define TPACPI_COMPARE_KEY(__scancode, __member) \
40359 do { \
40360 if ((event_mask & (1 << __scancode)) && \
40361@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40362 tpacpi_hotkey_send_key(__scancode); \
40363 } while (0)
40364
40365- void issue_volchange(const unsigned int oldvol,
40366- const unsigned int newvol)
40367- {
40368- unsigned int i = oldvol;
40369+static void issue_volchange(const unsigned int oldvol,
40370+ const unsigned int newvol,
40371+ const u32 event_mask)
40372+{
40373+ unsigned int i = oldvol;
40374
40375- while (i > newvol) {
40376- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40377- i--;
40378- }
40379- while (i < newvol) {
40380- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40381- i++;
40382- }
40383+ while (i > newvol) {
40384+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
40385+ i--;
40386 }
40387+ while (i < newvol) {
40388+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40389+ i++;
40390+ }
40391+}
40392
40393- void issue_brightnesschange(const unsigned int oldbrt,
40394- const unsigned int newbrt)
40395- {
40396- unsigned int i = oldbrt;
40397+static void issue_brightnesschange(const unsigned int oldbrt,
40398+ const unsigned int newbrt,
40399+ const u32 event_mask)
40400+{
40401+ unsigned int i = oldbrt;
40402
40403- while (i > newbrt) {
40404- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40405- i--;
40406- }
40407- while (i < newbrt) {
40408- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40409- i++;
40410- }
40411+ while (i > newbrt) {
40412+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
40413+ i--;
40414+ }
40415+ while (i < newbrt) {
40416+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40417+ i++;
40418 }
40419+}
40420
40421+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40422+ struct tp_nvram_state *newn,
40423+ const u32 event_mask)
40424+{
40425 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
40426 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
40427 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
40428@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40429 oldn->volume_level != newn->volume_level) {
40430 /* recently muted, or repeated mute keypress, or
40431 * multiple presses ending in mute */
40432- issue_volchange(oldn->volume_level, newn->volume_level);
40433+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40434 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
40435 }
40436 } else {
40437@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40438 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
40439 }
40440 if (oldn->volume_level != newn->volume_level) {
40441- issue_volchange(oldn->volume_level, newn->volume_level);
40442+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
40443 } else if (oldn->volume_toggle != newn->volume_toggle) {
40444 /* repeated vol up/down keypress at end of scale ? */
40445 if (newn->volume_level == 0)
40446@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40447 /* handle brightness */
40448 if (oldn->brightness_level != newn->brightness_level) {
40449 issue_brightnesschange(oldn->brightness_level,
40450- newn->brightness_level);
40451+ newn->brightness_level,
40452+ event_mask);
40453 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
40454 /* repeated key presses that didn't change state */
40455 if (newn->brightness_level == 0)
40456@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
40457 && !tp_features.bright_unkfw)
40458 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
40459 }
40460+}
40461
40462 #undef TPACPI_COMPARE_KEY
40463 #undef TPACPI_MAY_SEND_KEY
40464-}
40465
40466 /*
40467 * Polling driver
40468diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
40469index 769d265..a3a05ca 100644
40470--- a/drivers/pnp/pnpbios/bioscalls.c
40471+++ b/drivers/pnp/pnpbios/bioscalls.c
40472@@ -58,7 +58,7 @@ do { \
40473 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
40474 } while(0)
40475
40476-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
40477+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
40478 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
40479
40480 /*
40481@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40482
40483 cpu = get_cpu();
40484 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
40485+
40486+ pax_open_kernel();
40487 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
40488+ pax_close_kernel();
40489
40490 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
40491 spin_lock_irqsave(&pnp_bios_lock, flags);
40492@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
40493 :"memory");
40494 spin_unlock_irqrestore(&pnp_bios_lock, flags);
40495
40496+ pax_open_kernel();
40497 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
40498+ pax_close_kernel();
40499+
40500 put_cpu();
40501
40502 /* If we get here and this is set then the PnP BIOS faulted on us. */
40503@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
40504 return status;
40505 }
40506
40507-void pnpbios_calls_init(union pnp_bios_install_struct *header)
40508+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
40509 {
40510 int i;
40511
40512@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40513 pnp_bios_callpoint.offset = header->fields.pm16offset;
40514 pnp_bios_callpoint.segment = PNP_CS16;
40515
40516+ pax_open_kernel();
40517+
40518 for_each_possible_cpu(i) {
40519 struct desc_struct *gdt = get_cpu_gdt_table(i);
40520 if (!gdt)
40521@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
40522 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
40523 (unsigned long)__va(header->fields.pm16dseg));
40524 }
40525+
40526+ pax_close_kernel();
40527 }
40528diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
40529index 3e6db1c..1fbbdae 100644
40530--- a/drivers/pnp/resource.c
40531+++ b/drivers/pnp/resource.c
40532@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
40533 return 1;
40534
40535 /* check if the resource is valid */
40536- if (*irq < 0 || *irq > 15)
40537+ if (*irq > 15)
40538 return 0;
40539
40540 /* check if the resource is reserved */
40541@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
40542 return 1;
40543
40544 /* check if the resource is valid */
40545- if (*dma < 0 || *dma == 4 || *dma > 7)
40546+ if (*dma == 4 || *dma > 7)
40547 return 0;
40548
40549 /* check if the resource is reserved */
40550diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
40551index 7df7c5f..bd48c47 100644
40552--- a/drivers/power/pda_power.c
40553+++ b/drivers/power/pda_power.c
40554@@ -37,7 +37,11 @@ static int polling;
40555
40556 #ifdef CONFIG_USB_OTG_UTILS
40557 static struct usb_phy *transceiver;
40558-static struct notifier_block otg_nb;
40559+static int otg_handle_notification(struct notifier_block *nb,
40560+ unsigned long event, void *unused);
40561+static struct notifier_block otg_nb = {
40562+ .notifier_call = otg_handle_notification
40563+};
40564 #endif
40565
40566 static struct regulator *ac_draw;
40567@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
40568
40569 #ifdef CONFIG_USB_OTG_UTILS
40570 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
40571- otg_nb.notifier_call = otg_handle_notification;
40572 ret = usb_register_notifier(transceiver, &otg_nb);
40573 if (ret) {
40574 dev_err(dev, "failure to register otg notifier\n");
40575diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
40576index cc439fd..8fa30df 100644
40577--- a/drivers/power/power_supply.h
40578+++ b/drivers/power/power_supply.h
40579@@ -16,12 +16,12 @@ struct power_supply;
40580
40581 #ifdef CONFIG_SYSFS
40582
40583-extern void power_supply_init_attrs(struct device_type *dev_type);
40584+extern void power_supply_init_attrs(void);
40585 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
40586
40587 #else
40588
40589-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
40590+static inline void power_supply_init_attrs(void) {}
40591 #define power_supply_uevent NULL
40592
40593 #endif /* CONFIG_SYSFS */
40594diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
40595index 8a7cfb3..493e0a2 100644
40596--- a/drivers/power/power_supply_core.c
40597+++ b/drivers/power/power_supply_core.c
40598@@ -24,7 +24,10 @@
40599 struct class *power_supply_class;
40600 EXPORT_SYMBOL_GPL(power_supply_class);
40601
40602-static struct device_type power_supply_dev_type;
40603+extern const struct attribute_group *power_supply_attr_groups[];
40604+static struct device_type power_supply_dev_type = {
40605+ .groups = power_supply_attr_groups,
40606+};
40607
40608 static int __power_supply_changed_work(struct device *dev, void *data)
40609 {
40610@@ -393,7 +396,6 @@ static int __init power_supply_class_init(void)
40611 return PTR_ERR(power_supply_class);
40612
40613 power_supply_class->dev_uevent = power_supply_uevent;
40614- power_supply_init_attrs(&power_supply_dev_type);
40615
40616 return 0;
40617 }
40618diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
40619index 40fa3b7..d9c2e0e 100644
40620--- a/drivers/power/power_supply_sysfs.c
40621+++ b/drivers/power/power_supply_sysfs.c
40622@@ -229,17 +229,15 @@ static struct attribute_group power_supply_attr_group = {
40623 .is_visible = power_supply_attr_is_visible,
40624 };
40625
40626-static const struct attribute_group *power_supply_attr_groups[] = {
40627+const struct attribute_group *power_supply_attr_groups[] = {
40628 &power_supply_attr_group,
40629 NULL,
40630 };
40631
40632-void power_supply_init_attrs(struct device_type *dev_type)
40633+void power_supply_init_attrs(void)
40634 {
40635 int i;
40636
40637- dev_type->groups = power_supply_attr_groups;
40638-
40639 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
40640 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
40641 }
40642diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
40643index 4d7c635..9860196 100644
40644--- a/drivers/regulator/max8660.c
40645+++ b/drivers/regulator/max8660.c
40646@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
40647 max8660->shadow_regs[MAX8660_OVER1] = 5;
40648 } else {
40649 /* Otherwise devices can be toggled via software */
40650- max8660_dcdc_ops.enable = max8660_dcdc_enable;
40651- max8660_dcdc_ops.disable = max8660_dcdc_disable;
40652+ pax_open_kernel();
40653+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
40654+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
40655+ pax_close_kernel();
40656 }
40657
40658 /*
40659diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
40660index 9a8ea91..c483dd9 100644
40661--- a/drivers/regulator/max8973-regulator.c
40662+++ b/drivers/regulator/max8973-regulator.c
40663@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
40664 if (!pdata->enable_ext_control) {
40665 max->desc.enable_reg = MAX8973_VOUT;
40666 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
40667- max8973_dcdc_ops.enable = regulator_enable_regmap;
40668- max8973_dcdc_ops.disable = regulator_disable_regmap;
40669- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40670+ pax_open_kernel();
40671+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
40672+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
40673+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
40674+ pax_close_kernel();
40675 }
40676
40677 max->enable_external_control = pdata->enable_ext_control;
40678diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
40679index 0d84b1f..c2da6ac 100644
40680--- a/drivers/regulator/mc13892-regulator.c
40681+++ b/drivers/regulator/mc13892-regulator.c
40682@@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
40683 }
40684 mc13xxx_unlock(mc13892);
40685
40686- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40687+ pax_open_kernel();
40688+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
40689 = mc13892_vcam_set_mode;
40690- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40691+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
40692 = mc13892_vcam_get_mode;
40693+ pax_close_kernel();
40694
40695 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
40696 ARRAY_SIZE(mc13892_regulators));
40697diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
40698index 16630aa..6afc992 100644
40699--- a/drivers/rtc/rtc-cmos.c
40700+++ b/drivers/rtc/rtc-cmos.c
40701@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
40702 hpet_rtc_timer_init();
40703
40704 /* export at least the first block of NVRAM */
40705- nvram.size = address_space - NVRAM_OFFSET;
40706+ pax_open_kernel();
40707+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
40708+ pax_close_kernel();
40709 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
40710 if (retval < 0) {
40711 dev_dbg(dev, "can't create nvram file? %d\n", retval);
40712diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
40713index 9a86b4b..3a383dc 100644
40714--- a/drivers/rtc/rtc-dev.c
40715+++ b/drivers/rtc/rtc-dev.c
40716@@ -14,6 +14,7 @@
40717 #include <linux/module.h>
40718 #include <linux/rtc.h>
40719 #include <linux/sched.h>
40720+#include <linux/grsecurity.h>
40721 #include "rtc-core.h"
40722
40723 static dev_t rtc_devt;
40724@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
40725 if (copy_from_user(&tm, uarg, sizeof(tm)))
40726 return -EFAULT;
40727
40728+ gr_log_timechange();
40729+
40730 return rtc_set_time(rtc, &tm);
40731
40732 case RTC_PIE_ON:
40733diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
40734index e0d0ba4..3c65868 100644
40735--- a/drivers/rtc/rtc-ds1307.c
40736+++ b/drivers/rtc/rtc-ds1307.c
40737@@ -106,7 +106,7 @@ struct ds1307 {
40738 u8 offset; /* register's offset */
40739 u8 regs[11];
40740 u16 nvram_offset;
40741- struct bin_attribute *nvram;
40742+ bin_attribute_no_const *nvram;
40743 enum ds_type type;
40744 unsigned long flags;
40745 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
40746diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
40747index 130f29a..6179d03 100644
40748--- a/drivers/rtc/rtc-m48t59.c
40749+++ b/drivers/rtc/rtc-m48t59.c
40750@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
40751 goto out;
40752 }
40753
40754- m48t59_nvram_attr.size = pdata->offset;
40755+ pax_open_kernel();
40756+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
40757+ pax_close_kernel();
40758
40759 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
40760 if (ret) {
40761diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
40762index e693af6..2e525b6 100644
40763--- a/drivers/scsi/bfa/bfa_fcpim.h
40764+++ b/drivers/scsi/bfa/bfa_fcpim.h
40765@@ -36,7 +36,7 @@ struct bfa_iotag_s {
40766
40767 struct bfa_itn_s {
40768 bfa_isr_func_t isr;
40769-};
40770+} __no_const;
40771
40772 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
40773 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
40774diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
40775index 23a90e7..9cf04ee 100644
40776--- a/drivers/scsi/bfa/bfa_ioc.h
40777+++ b/drivers/scsi/bfa/bfa_ioc.h
40778@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
40779 bfa_ioc_disable_cbfn_t disable_cbfn;
40780 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
40781 bfa_ioc_reset_cbfn_t reset_cbfn;
40782-};
40783+} __no_const;
40784
40785 /*
40786 * IOC event notification mechanism.
40787@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
40788 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
40789 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
40790 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
40791-};
40792+} __no_const;
40793
40794 /*
40795 * Queue element to wait for room in request queue. FIFO order is
40796diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
40797index 593085a..47aa999 100644
40798--- a/drivers/scsi/hosts.c
40799+++ b/drivers/scsi/hosts.c
40800@@ -42,7 +42,7 @@
40801 #include "scsi_logging.h"
40802
40803
40804-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40805+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
40806
40807
40808 static void scsi_host_cls_release(struct device *dev)
40809@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
40810 * subtract one because we increment first then return, but we need to
40811 * know what the next host number was before increment
40812 */
40813- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
40814+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
40815 shost->dma_channel = 0xff;
40816
40817 /* These three are default values which can be overridden */
40818diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
40819index 4f33806..afd6f60 100644
40820--- a/drivers/scsi/hpsa.c
40821+++ b/drivers/scsi/hpsa.c
40822@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
40823 unsigned long flags;
40824
40825 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
40826- return h->access.command_completed(h, q);
40827+ return h->access->command_completed(h, q);
40828
40829 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
40830 a = rq->head[rq->current_entry];
40831@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
40832 while (!list_empty(&h->reqQ)) {
40833 c = list_entry(h->reqQ.next, struct CommandList, list);
40834 /* can't do anything if fifo is full */
40835- if ((h->access.fifo_full(h))) {
40836+ if ((h->access->fifo_full(h))) {
40837 dev_warn(&h->pdev->dev, "fifo full\n");
40838 break;
40839 }
40840@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
40841
40842 /* Tell the controller execute command */
40843 spin_unlock_irqrestore(&h->lock, flags);
40844- h->access.submit_command(h, c);
40845+ h->access->submit_command(h, c);
40846 spin_lock_irqsave(&h->lock, flags);
40847 }
40848 spin_unlock_irqrestore(&h->lock, flags);
40849@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
40850
40851 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
40852 {
40853- return h->access.command_completed(h, q);
40854+ return h->access->command_completed(h, q);
40855 }
40856
40857 static inline bool interrupt_pending(struct ctlr_info *h)
40858 {
40859- return h->access.intr_pending(h);
40860+ return h->access->intr_pending(h);
40861 }
40862
40863 static inline long interrupt_not_for_us(struct ctlr_info *h)
40864 {
40865- return (h->access.intr_pending(h) == 0) ||
40866+ return (h->access->intr_pending(h) == 0) ||
40867 (h->interrupts_enabled == 0);
40868 }
40869
40870@@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
40871 if (prod_index < 0)
40872 return -ENODEV;
40873 h->product_name = products[prod_index].product_name;
40874- h->access = *(products[prod_index].access);
40875+ h->access = products[prod_index].access;
40876
40877 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
40878 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
40879@@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
40880
40881 assert_spin_locked(&lockup_detector_lock);
40882 remove_ctlr_from_lockup_detector_list(h);
40883- h->access.set_intr_mask(h, HPSA_INTR_OFF);
40884+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
40885 spin_lock_irqsave(&h->lock, flags);
40886 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
40887 spin_unlock_irqrestore(&h->lock, flags);
40888@@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
40889 }
40890
40891 /* make sure the board interrupts are off */
40892- h->access.set_intr_mask(h, HPSA_INTR_OFF);
40893+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
40894
40895 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
40896 goto clean2;
40897@@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
40898 * fake ones to scoop up any residual completions.
40899 */
40900 spin_lock_irqsave(&h->lock, flags);
40901- h->access.set_intr_mask(h, HPSA_INTR_OFF);
40902+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
40903 spin_unlock_irqrestore(&h->lock, flags);
40904 free_irqs(h);
40905 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
40906@@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
40907 dev_info(&h->pdev->dev, "Board READY.\n");
40908 dev_info(&h->pdev->dev,
40909 "Waiting for stale completions to drain.\n");
40910- h->access.set_intr_mask(h, HPSA_INTR_ON);
40911+ h->access->set_intr_mask(h, HPSA_INTR_ON);
40912 msleep(10000);
40913- h->access.set_intr_mask(h, HPSA_INTR_OFF);
40914+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
40915
40916 rc = controller_reset_failed(h->cfgtable);
40917 if (rc)
40918@@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
40919 }
40920
40921 /* Turn the interrupts on so we can service requests */
40922- h->access.set_intr_mask(h, HPSA_INTR_ON);
40923+ h->access->set_intr_mask(h, HPSA_INTR_ON);
40924
40925 hpsa_hba_inquiry(h);
40926 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
40927@@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
40928 * To write all data in the battery backed cache to disks
40929 */
40930 hpsa_flush_cache(h);
40931- h->access.set_intr_mask(h, HPSA_INTR_OFF);
40932+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
40933 hpsa_free_irqs_and_disable_msix(h);
40934 }
40935
40936@@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
40937 return;
40938 }
40939 /* Change the access methods to the performant access methods */
40940- h->access = SA5_performant_access;
40941+ h->access = &SA5_performant_access;
40942 h->transMethod = CFGTBL_Trans_Performant;
40943 }
40944
40945diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
40946index 9816479..c5d4e97 100644
40947--- a/drivers/scsi/hpsa.h
40948+++ b/drivers/scsi/hpsa.h
40949@@ -79,7 +79,7 @@ struct ctlr_info {
40950 unsigned int msix_vector;
40951 unsigned int msi_vector;
40952 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
40953- struct access_method access;
40954+ struct access_method *access;
40955
40956 /* queue and queue Info */
40957 struct list_head reqQ;
40958diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
40959index c772d8d..35c362c 100644
40960--- a/drivers/scsi/libfc/fc_exch.c
40961+++ b/drivers/scsi/libfc/fc_exch.c
40962@@ -100,12 +100,12 @@ struct fc_exch_mgr {
40963 u16 pool_max_index;
40964
40965 struct {
40966- atomic_t no_free_exch;
40967- atomic_t no_free_exch_xid;
40968- atomic_t xid_not_found;
40969- atomic_t xid_busy;
40970- atomic_t seq_not_found;
40971- atomic_t non_bls_resp;
40972+ atomic_unchecked_t no_free_exch;
40973+ atomic_unchecked_t no_free_exch_xid;
40974+ atomic_unchecked_t xid_not_found;
40975+ atomic_unchecked_t xid_busy;
40976+ atomic_unchecked_t seq_not_found;
40977+ atomic_unchecked_t non_bls_resp;
40978 } stats;
40979 };
40980
40981@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
40982 /* allocate memory for exchange */
40983 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
40984 if (!ep) {
40985- atomic_inc(&mp->stats.no_free_exch);
40986+ atomic_inc_unchecked(&mp->stats.no_free_exch);
40987 goto out;
40988 }
40989 memset(ep, 0, sizeof(*ep));
40990@@ -786,7 +786,7 @@ out:
40991 return ep;
40992 err:
40993 spin_unlock_bh(&pool->lock);
40994- atomic_inc(&mp->stats.no_free_exch_xid);
40995+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
40996 mempool_free(ep, mp->ep_pool);
40997 return NULL;
40998 }
40999@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41000 xid = ntohs(fh->fh_ox_id); /* we originated exch */
41001 ep = fc_exch_find(mp, xid);
41002 if (!ep) {
41003- atomic_inc(&mp->stats.xid_not_found);
41004+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41005 reject = FC_RJT_OX_ID;
41006 goto out;
41007 }
41008@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41009 ep = fc_exch_find(mp, xid);
41010 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
41011 if (ep) {
41012- atomic_inc(&mp->stats.xid_busy);
41013+ atomic_inc_unchecked(&mp->stats.xid_busy);
41014 reject = FC_RJT_RX_ID;
41015 goto rel;
41016 }
41017@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41018 }
41019 xid = ep->xid; /* get our XID */
41020 } else if (!ep) {
41021- atomic_inc(&mp->stats.xid_not_found);
41022+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41023 reject = FC_RJT_RX_ID; /* XID not found */
41024 goto out;
41025 }
41026@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
41027 } else {
41028 sp = &ep->seq;
41029 if (sp->id != fh->fh_seq_id) {
41030- atomic_inc(&mp->stats.seq_not_found);
41031+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41032 if (f_ctl & FC_FC_END_SEQ) {
41033 /*
41034 * Update sequence_id based on incoming last
41035@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41036
41037 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
41038 if (!ep) {
41039- atomic_inc(&mp->stats.xid_not_found);
41040+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41041 goto out;
41042 }
41043 if (ep->esb_stat & ESB_ST_COMPLETE) {
41044- atomic_inc(&mp->stats.xid_not_found);
41045+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41046 goto rel;
41047 }
41048 if (ep->rxid == FC_XID_UNKNOWN)
41049 ep->rxid = ntohs(fh->fh_rx_id);
41050 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
41051- atomic_inc(&mp->stats.xid_not_found);
41052+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41053 goto rel;
41054 }
41055 if (ep->did != ntoh24(fh->fh_s_id) &&
41056 ep->did != FC_FID_FLOGI) {
41057- atomic_inc(&mp->stats.xid_not_found);
41058+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41059 goto rel;
41060 }
41061 sof = fr_sof(fp);
41062@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41063 sp->ssb_stat |= SSB_ST_RESP;
41064 sp->id = fh->fh_seq_id;
41065 } else if (sp->id != fh->fh_seq_id) {
41066- atomic_inc(&mp->stats.seq_not_found);
41067+ atomic_inc_unchecked(&mp->stats.seq_not_found);
41068 goto rel;
41069 }
41070
41071@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
41072 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
41073
41074 if (!sp)
41075- atomic_inc(&mp->stats.xid_not_found);
41076+ atomic_inc_unchecked(&mp->stats.xid_not_found);
41077 else
41078- atomic_inc(&mp->stats.non_bls_resp);
41079+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
41080
41081 fc_frame_free(fp);
41082 }
41083@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
41084
41085 list_for_each_entry(ema, &lport->ema_list, ema_list) {
41086 mp = ema->mp;
41087- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
41088+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
41089 st->fc_no_free_exch_xid +=
41090- atomic_read(&mp->stats.no_free_exch_xid);
41091- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
41092- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
41093- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
41094- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
41095+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
41096+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
41097+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
41098+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
41099+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
41100 }
41101 }
41102 EXPORT_SYMBOL(fc_exch_update_stats);
41103diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
41104index bdb81cd..d3c7c2c 100644
41105--- a/drivers/scsi/libsas/sas_ata.c
41106+++ b/drivers/scsi/libsas/sas_ata.c
41107@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
41108 .postreset = ata_std_postreset,
41109 .error_handler = ata_std_error_handler,
41110 .post_internal_cmd = sas_ata_post_internal,
41111- .qc_defer = ata_std_qc_defer,
41112+ .qc_defer = ata_std_qc_defer,
41113 .qc_prep = ata_noop_qc_prep,
41114 .qc_issue = sas_ata_qc_issue,
41115 .qc_fill_rtf = sas_ata_qc_fill_rtf,
41116diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
41117index df4c13a..a51e90c 100644
41118--- a/drivers/scsi/lpfc/lpfc.h
41119+++ b/drivers/scsi/lpfc/lpfc.h
41120@@ -424,7 +424,7 @@ struct lpfc_vport {
41121 struct dentry *debug_nodelist;
41122 struct dentry *vport_debugfs_root;
41123 struct lpfc_debugfs_trc *disc_trc;
41124- atomic_t disc_trc_cnt;
41125+ atomic_unchecked_t disc_trc_cnt;
41126 #endif
41127 uint8_t stat_data_enabled;
41128 uint8_t stat_data_blocked;
41129@@ -842,8 +842,8 @@ struct lpfc_hba {
41130 struct timer_list fabric_block_timer;
41131 unsigned long bit_flags;
41132 #define FABRIC_COMANDS_BLOCKED 0
41133- atomic_t num_rsrc_err;
41134- atomic_t num_cmd_success;
41135+ atomic_unchecked_t num_rsrc_err;
41136+ atomic_unchecked_t num_cmd_success;
41137 unsigned long last_rsrc_error_time;
41138 unsigned long last_ramp_down_time;
41139 unsigned long last_ramp_up_time;
41140@@ -879,7 +879,7 @@ struct lpfc_hba {
41141
41142 struct dentry *debug_slow_ring_trc;
41143 struct lpfc_debugfs_trc *slow_ring_trc;
41144- atomic_t slow_ring_trc_cnt;
41145+ atomic_unchecked_t slow_ring_trc_cnt;
41146 /* iDiag debugfs sub-directory */
41147 struct dentry *idiag_root;
41148 struct dentry *idiag_pci_cfg;
41149diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
41150index f63f5ff..de29189 100644
41151--- a/drivers/scsi/lpfc/lpfc_debugfs.c
41152+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
41153@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
41154
41155 #include <linux/debugfs.h>
41156
41157-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41158+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
41159 static unsigned long lpfc_debugfs_start_time = 0L;
41160
41161 /* iDiag */
41162@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
41163 lpfc_debugfs_enable = 0;
41164
41165 len = 0;
41166- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
41167+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
41168 (lpfc_debugfs_max_disc_trc - 1);
41169 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
41170 dtp = vport->disc_trc + i;
41171@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
41172 lpfc_debugfs_enable = 0;
41173
41174 len = 0;
41175- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
41176+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
41177 (lpfc_debugfs_max_slow_ring_trc - 1);
41178 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
41179 dtp = phba->slow_ring_trc + i;
41180@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
41181 !vport || !vport->disc_trc)
41182 return;
41183
41184- index = atomic_inc_return(&vport->disc_trc_cnt) &
41185+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
41186 (lpfc_debugfs_max_disc_trc - 1);
41187 dtp = vport->disc_trc + index;
41188 dtp->fmt = fmt;
41189 dtp->data1 = data1;
41190 dtp->data2 = data2;
41191 dtp->data3 = data3;
41192- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41193+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41194 dtp->jif = jiffies;
41195 #endif
41196 return;
41197@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
41198 !phba || !phba->slow_ring_trc)
41199 return;
41200
41201- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
41202+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
41203 (lpfc_debugfs_max_slow_ring_trc - 1);
41204 dtp = phba->slow_ring_trc + index;
41205 dtp->fmt = fmt;
41206 dtp->data1 = data1;
41207 dtp->data2 = data2;
41208 dtp->data3 = data3;
41209- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
41210+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
41211 dtp->jif = jiffies;
41212 #endif
41213 return;
41214@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41215 "slow_ring buffer\n");
41216 goto debug_failed;
41217 }
41218- atomic_set(&phba->slow_ring_trc_cnt, 0);
41219+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
41220 memset(phba->slow_ring_trc, 0,
41221 (sizeof(struct lpfc_debugfs_trc) *
41222 lpfc_debugfs_max_slow_ring_trc));
41223@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
41224 "buffer\n");
41225 goto debug_failed;
41226 }
41227- atomic_set(&vport->disc_trc_cnt, 0);
41228+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
41229
41230 snprintf(name, sizeof(name), "discovery_trace");
41231 vport->debug_disc_trc =
41232diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
41233index 89ad558..76956c4 100644
41234--- a/drivers/scsi/lpfc/lpfc_init.c
41235+++ b/drivers/scsi/lpfc/lpfc_init.c
41236@@ -10618,8 +10618,10 @@ lpfc_init(void)
41237 "misc_register returned with status %d", error);
41238
41239 if (lpfc_enable_npiv) {
41240- lpfc_transport_functions.vport_create = lpfc_vport_create;
41241- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41242+ pax_open_kernel();
41243+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
41244+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
41245+ pax_close_kernel();
41246 }
41247 lpfc_transport_template =
41248 fc_attach_transport(&lpfc_transport_functions);
41249diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
41250index 60e5a17..ff7a793 100644
41251--- a/drivers/scsi/lpfc/lpfc_scsi.c
41252+++ b/drivers/scsi/lpfc/lpfc_scsi.c
41253@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
41254 uint32_t evt_posted;
41255
41256 spin_lock_irqsave(&phba->hbalock, flags);
41257- atomic_inc(&phba->num_rsrc_err);
41258+ atomic_inc_unchecked(&phba->num_rsrc_err);
41259 phba->last_rsrc_error_time = jiffies;
41260
41261 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
41262@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
41263 unsigned long flags;
41264 struct lpfc_hba *phba = vport->phba;
41265 uint32_t evt_posted;
41266- atomic_inc(&phba->num_cmd_success);
41267+ atomic_inc_unchecked(&phba->num_cmd_success);
41268
41269 if (vport->cfg_lun_queue_depth <= queue_depth)
41270 return;
41271@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41272 unsigned long num_rsrc_err, num_cmd_success;
41273 int i;
41274
41275- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
41276- num_cmd_success = atomic_read(&phba->num_cmd_success);
41277+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
41278+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
41279
41280 /*
41281 * The error and success command counters are global per
41282@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
41283 }
41284 }
41285 lpfc_destroy_vport_work_array(phba, vports);
41286- atomic_set(&phba->num_rsrc_err, 0);
41287- atomic_set(&phba->num_cmd_success, 0);
41288+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41289+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41290 }
41291
41292 /**
41293@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
41294 }
41295 }
41296 lpfc_destroy_vport_work_array(phba, vports);
41297- atomic_set(&phba->num_rsrc_err, 0);
41298- atomic_set(&phba->num_cmd_success, 0);
41299+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
41300+ atomic_set_unchecked(&phba->num_cmd_success, 0);
41301 }
41302
41303 /**
41304diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
41305index b46f5e9..c4c4ccb 100644
41306--- a/drivers/scsi/pmcraid.c
41307+++ b/drivers/scsi/pmcraid.c
41308@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
41309 res->scsi_dev = scsi_dev;
41310 scsi_dev->hostdata = res;
41311 res->change_detected = 0;
41312- atomic_set(&res->read_failures, 0);
41313- atomic_set(&res->write_failures, 0);
41314+ atomic_set_unchecked(&res->read_failures, 0);
41315+ atomic_set_unchecked(&res->write_failures, 0);
41316 rc = 0;
41317 }
41318 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
41319@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
41320
41321 /* If this was a SCSI read/write command keep count of errors */
41322 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
41323- atomic_inc(&res->read_failures);
41324+ atomic_inc_unchecked(&res->read_failures);
41325 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
41326- atomic_inc(&res->write_failures);
41327+ atomic_inc_unchecked(&res->write_failures);
41328
41329 if (!RES_IS_GSCSI(res->cfg_entry) &&
41330 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
41331@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
41332 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41333 * hrrq_id assigned here in queuecommand
41334 */
41335- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41336+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41337 pinstance->num_hrrq;
41338 cmd->cmd_done = pmcraid_io_done;
41339
41340@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
41341 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
41342 * hrrq_id assigned here in queuecommand
41343 */
41344- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
41345+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
41346 pinstance->num_hrrq;
41347
41348 if (request_size) {
41349@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
41350
41351 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
41352 /* add resources only after host is added into system */
41353- if (!atomic_read(&pinstance->expose_resources))
41354+ if (!atomic_read_unchecked(&pinstance->expose_resources))
41355 return;
41356
41357 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
41358@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
41359 init_waitqueue_head(&pinstance->reset_wait_q);
41360
41361 atomic_set(&pinstance->outstanding_cmds, 0);
41362- atomic_set(&pinstance->last_message_id, 0);
41363- atomic_set(&pinstance->expose_resources, 0);
41364+ atomic_set_unchecked(&pinstance->last_message_id, 0);
41365+ atomic_set_unchecked(&pinstance->expose_resources, 0);
41366
41367 INIT_LIST_HEAD(&pinstance->free_res_q);
41368 INIT_LIST_HEAD(&pinstance->used_res_q);
41369@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
41370 /* Schedule worker thread to handle CCN and take care of adding and
41371 * removing devices to OS
41372 */
41373- atomic_set(&pinstance->expose_resources, 1);
41374+ atomic_set_unchecked(&pinstance->expose_resources, 1);
41375 schedule_work(&pinstance->worker_q);
41376 return rc;
41377
41378diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
41379index e1d150f..6c6df44 100644
41380--- a/drivers/scsi/pmcraid.h
41381+++ b/drivers/scsi/pmcraid.h
41382@@ -748,7 +748,7 @@ struct pmcraid_instance {
41383 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
41384
41385 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
41386- atomic_t last_message_id;
41387+ atomic_unchecked_t last_message_id;
41388
41389 /* configuration table */
41390 struct pmcraid_config_table *cfg_table;
41391@@ -777,7 +777,7 @@ struct pmcraid_instance {
41392 atomic_t outstanding_cmds;
41393
41394 /* should add/delete resources to mid-layer now ?*/
41395- atomic_t expose_resources;
41396+ atomic_unchecked_t expose_resources;
41397
41398
41399
41400@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
41401 struct pmcraid_config_table_entry_ext cfg_entry_ext;
41402 };
41403 struct scsi_device *scsi_dev; /* Link scsi_device structure */
41404- atomic_t read_failures; /* count of failed READ commands */
41405- atomic_t write_failures; /* count of failed WRITE commands */
41406+ atomic_unchecked_t read_failures; /* count of failed READ commands */
41407+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
41408
41409 /* To indicate add/delete/modify during CCN */
41410 u8 change_detected;
41411diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
41412index 83d7984..a27d947 100644
41413--- a/drivers/scsi/qla2xxx/qla_attr.c
41414+++ b/drivers/scsi/qla2xxx/qla_attr.c
41415@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
41416 return 0;
41417 }
41418
41419-struct fc_function_template qla2xxx_transport_functions = {
41420+fc_function_template_no_const qla2xxx_transport_functions = {
41421
41422 .show_host_node_name = 1,
41423 .show_host_port_name = 1,
41424@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
41425 .bsg_timeout = qla24xx_bsg_timeout,
41426 };
41427
41428-struct fc_function_template qla2xxx_transport_vport_functions = {
41429+fc_function_template_no_const qla2xxx_transport_vport_functions = {
41430
41431 .show_host_node_name = 1,
41432 .show_host_port_name = 1,
41433diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
41434index 2411d1a..4673766 100644
41435--- a/drivers/scsi/qla2xxx/qla_gbl.h
41436+++ b/drivers/scsi/qla2xxx/qla_gbl.h
41437@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
41438 struct device_attribute;
41439 extern struct device_attribute *qla2x00_host_attrs[];
41440 struct fc_function_template;
41441-extern struct fc_function_template qla2xxx_transport_functions;
41442-extern struct fc_function_template qla2xxx_transport_vport_functions;
41443+extern fc_function_template_no_const qla2xxx_transport_functions;
41444+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
41445 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
41446 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
41447 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
41448diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
41449index 10d23f8..a7d5d4c 100644
41450--- a/drivers/scsi/qla2xxx/qla_os.c
41451+++ b/drivers/scsi/qla2xxx/qla_os.c
41452@@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
41453 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
41454 /* Ok, a 64bit DMA mask is applicable. */
41455 ha->flags.enable_64bit_addressing = 1;
41456- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41457- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41458+ pax_open_kernel();
41459+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
41460+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
41461+ pax_close_kernel();
41462 return;
41463 }
41464 }
41465diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
41466index 329d553..f20d31d 100644
41467--- a/drivers/scsi/qla4xxx/ql4_def.h
41468+++ b/drivers/scsi/qla4xxx/ql4_def.h
41469@@ -273,7 +273,7 @@ struct ddb_entry {
41470 * (4000 only) */
41471 atomic_t relogin_timer; /* Max Time to wait for
41472 * relogin to complete */
41473- atomic_t relogin_retry_count; /* Num of times relogin has been
41474+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
41475 * retried */
41476 uint32_t default_time2wait; /* Default Min time between
41477 * relogins (+aens) */
41478diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
41479index 4cec123..7c1329f 100644
41480--- a/drivers/scsi/qla4xxx/ql4_os.c
41481+++ b/drivers/scsi/qla4xxx/ql4_os.c
41482@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
41483 */
41484 if (!iscsi_is_session_online(cls_sess)) {
41485 /* Reset retry relogin timer */
41486- atomic_inc(&ddb_entry->relogin_retry_count);
41487+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
41488 DEBUG2(ql4_printk(KERN_INFO, ha,
41489 "%s: index[%d] relogin timed out-retrying"
41490 " relogin (%d), retry (%d)\n", __func__,
41491 ddb_entry->fw_ddb_index,
41492- atomic_read(&ddb_entry->relogin_retry_count),
41493+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
41494 ddb_entry->default_time2wait + 4));
41495 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
41496 atomic_set(&ddb_entry->retry_relogin_timer,
41497@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
41498
41499 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
41500 atomic_set(&ddb_entry->relogin_timer, 0);
41501- atomic_set(&ddb_entry->relogin_retry_count, 0);
41502+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
41503 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
41504 ddb_entry->default_relogin_timeout =
41505 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
41506diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
41507index 2c0d0ec..4e8681a 100644
41508--- a/drivers/scsi/scsi.c
41509+++ b/drivers/scsi/scsi.c
41510@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
41511 unsigned long timeout;
41512 int rtn = 0;
41513
41514- atomic_inc(&cmd->device->iorequest_cnt);
41515+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41516
41517 /* check if the device is still usable */
41518 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
41519diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
41520index f1bf5af..f67e943 100644
41521--- a/drivers/scsi/scsi_lib.c
41522+++ b/drivers/scsi/scsi_lib.c
41523@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
41524 shost = sdev->host;
41525 scsi_init_cmd_errh(cmd);
41526 cmd->result = DID_NO_CONNECT << 16;
41527- atomic_inc(&cmd->device->iorequest_cnt);
41528+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
41529
41530 /*
41531 * SCSI request completion path will do scsi_device_unbusy(),
41532@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
41533
41534 INIT_LIST_HEAD(&cmd->eh_entry);
41535
41536- atomic_inc(&cmd->device->iodone_cnt);
41537+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
41538 if (cmd->result)
41539- atomic_inc(&cmd->device->ioerr_cnt);
41540+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
41541
41542 disposition = scsi_decide_disposition(cmd);
41543 if (disposition != SUCCESS &&
41544diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
41545index 931a7d9..0c2a754 100644
41546--- a/drivers/scsi/scsi_sysfs.c
41547+++ b/drivers/scsi/scsi_sysfs.c
41548@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
41549 char *buf) \
41550 { \
41551 struct scsi_device *sdev = to_scsi_device(dev); \
41552- unsigned long long count = atomic_read(&sdev->field); \
41553+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
41554 return snprintf(buf, 20, "0x%llx\n", count); \
41555 } \
41556 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
41557diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
41558index 84a1fdf..693b0d6 100644
41559--- a/drivers/scsi/scsi_tgt_lib.c
41560+++ b/drivers/scsi/scsi_tgt_lib.c
41561@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
41562 int err;
41563
41564 dprintk("%lx %u\n", uaddr, len);
41565- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
41566+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
41567 if (err) {
41568 /*
41569 * TODO: need to fixup sg_tablesize, max_segment_size,
41570diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
41571index e894ca7..de9d7660 100644
41572--- a/drivers/scsi/scsi_transport_fc.c
41573+++ b/drivers/scsi/scsi_transport_fc.c
41574@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
41575 * Netlink Infrastructure
41576 */
41577
41578-static atomic_t fc_event_seq;
41579+static atomic_unchecked_t fc_event_seq;
41580
41581 /**
41582 * fc_get_event_number - Obtain the next sequential FC event number
41583@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
41584 u32
41585 fc_get_event_number(void)
41586 {
41587- return atomic_add_return(1, &fc_event_seq);
41588+ return atomic_add_return_unchecked(1, &fc_event_seq);
41589 }
41590 EXPORT_SYMBOL(fc_get_event_number);
41591
41592@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
41593 {
41594 int error;
41595
41596- atomic_set(&fc_event_seq, 0);
41597+ atomic_set_unchecked(&fc_event_seq, 0);
41598
41599 error = transport_class_register(&fc_host_class);
41600 if (error)
41601@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
41602 char *cp;
41603
41604 *val = simple_strtoul(buf, &cp, 0);
41605- if ((*cp && (*cp != '\n')) || (*val < 0))
41606+ if (*cp && (*cp != '\n'))
41607 return -EINVAL;
41608 /*
41609 * Check for overflow; dev_loss_tmo is u32
41610diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
41611index 31969f2..2b348f0 100644
41612--- a/drivers/scsi/scsi_transport_iscsi.c
41613+++ b/drivers/scsi/scsi_transport_iscsi.c
41614@@ -79,7 +79,7 @@ struct iscsi_internal {
41615 struct transport_container session_cont;
41616 };
41617
41618-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
41619+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
41620 static struct workqueue_struct *iscsi_eh_timer_workq;
41621
41622 static DEFINE_IDA(iscsi_sess_ida);
41623@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
41624 int err;
41625
41626 ihost = shost->shost_data;
41627- session->sid = atomic_add_return(1, &iscsi_session_nr);
41628+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
41629
41630 if (target_id == ISCSI_MAX_TARGET) {
41631 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
41632@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
41633 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
41634 ISCSI_TRANSPORT_VERSION);
41635
41636- atomic_set(&iscsi_session_nr, 0);
41637+ atomic_set_unchecked(&iscsi_session_nr, 0);
41638
41639 err = class_register(&iscsi_transport_class);
41640 if (err)
41641diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
41642index f379c7f..e8fc69c 100644
41643--- a/drivers/scsi/scsi_transport_srp.c
41644+++ b/drivers/scsi/scsi_transport_srp.c
41645@@ -33,7 +33,7 @@
41646 #include "scsi_transport_srp_internal.h"
41647
41648 struct srp_host_attrs {
41649- atomic_t next_port_id;
41650+ atomic_unchecked_t next_port_id;
41651 };
41652 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
41653
41654@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
41655 struct Scsi_Host *shost = dev_to_shost(dev);
41656 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
41657
41658- atomic_set(&srp_host->next_port_id, 0);
41659+ atomic_set_unchecked(&srp_host->next_port_id, 0);
41660 return 0;
41661 }
41662
41663@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
41664 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
41665 rport->roles = ids->roles;
41666
41667- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
41668+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
41669 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
41670
41671 transport_setup_device(&rport->dev);
41672diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
41673index 7992635..609faf8 100644
41674--- a/drivers/scsi/sd.c
41675+++ b/drivers/scsi/sd.c
41676@@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
41677 sdkp->disk = gd;
41678 sdkp->index = index;
41679 atomic_set(&sdkp->openers, 0);
41680- atomic_set(&sdkp->device->ioerr_cnt, 0);
41681+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
41682
41683 if (!sdp->request_queue->rq_timeout) {
41684 if (sdp->type != TYPE_MOD)
41685diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
41686index be2c9a6..275525c 100644
41687--- a/drivers/scsi/sg.c
41688+++ b/drivers/scsi/sg.c
41689@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
41690 sdp->disk->disk_name,
41691 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
41692 NULL,
41693- (char *)arg);
41694+ (char __user *)arg);
41695 case BLKTRACESTART:
41696 return blk_trace_startstop(sdp->device->request_queue, 1);
41697 case BLKTRACESTOP:
41698diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
41699index 19ee901..6e8c2ef 100644
41700--- a/drivers/spi/spi.c
41701+++ b/drivers/spi/spi.c
41702@@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
41703 EXPORT_SYMBOL_GPL(spi_bus_unlock);
41704
41705 /* portable code must never pass more than 32 bytes */
41706-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
41707+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
41708
41709 static u8 *buf;
41710
41711diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
41712index c7a5f97..71ecd35 100644
41713--- a/drivers/staging/iio/iio_hwmon.c
41714+++ b/drivers/staging/iio/iio_hwmon.c
41715@@ -72,7 +72,7 @@ static void iio_hwmon_free_attrs(struct iio_hwmon_state *st)
41716 static int iio_hwmon_probe(struct platform_device *pdev)
41717 {
41718 struct iio_hwmon_state *st;
41719- struct sensor_device_attribute *a;
41720+ sensor_device_attribute_no_const *a;
41721 int ret, i;
41722 int in_i = 1, temp_i = 1, curr_i = 1;
41723 enum iio_chan_type type;
41724diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
41725index 34afc16..ffe44dd 100644
41726--- a/drivers/staging/octeon/ethernet-rx.c
41727+++ b/drivers/staging/octeon/ethernet-rx.c
41728@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41729 /* Increment RX stats for virtual ports */
41730 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
41731 #ifdef CONFIG_64BIT
41732- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
41733- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
41734+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
41735+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
41736 #else
41737- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
41738- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
41739+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
41740+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
41741 #endif
41742 }
41743 netif_receive_skb(skb);
41744@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
41745 dev->name);
41746 */
41747 #ifdef CONFIG_64BIT
41748- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
41749+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41750 #else
41751- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
41752+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
41753 #endif
41754 dev_kfree_skb_irq(skb);
41755 }
41756diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
41757index ef32dc1..a159d68 100644
41758--- a/drivers/staging/octeon/ethernet.c
41759+++ b/drivers/staging/octeon/ethernet.c
41760@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
41761 * since the RX tasklet also increments it.
41762 */
41763 #ifdef CONFIG_64BIT
41764- atomic64_add(rx_status.dropped_packets,
41765- (atomic64_t *)&priv->stats.rx_dropped);
41766+ atomic64_add_unchecked(rx_status.dropped_packets,
41767+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
41768 #else
41769- atomic_add(rx_status.dropped_packets,
41770- (atomic_t *)&priv->stats.rx_dropped);
41771+ atomic_add_unchecked(rx_status.dropped_packets,
41772+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
41773 #endif
41774 }
41775
41776diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
41777index a2b7e03..aaf3630 100644
41778--- a/drivers/staging/ramster/tmem.c
41779+++ b/drivers/staging/ramster/tmem.c
41780@@ -50,25 +50,25 @@
41781 * A tmem host implementation must use this function to register callbacks
41782 * for memory allocation.
41783 */
41784-static struct tmem_hostops tmem_hostops;
41785+static struct tmem_hostops *tmem_hostops;
41786
41787 static void tmem_objnode_tree_init(void);
41788
41789 void tmem_register_hostops(struct tmem_hostops *m)
41790 {
41791 tmem_objnode_tree_init();
41792- tmem_hostops = *m;
41793+ tmem_hostops = m;
41794 }
41795
41796 /*
41797 * A tmem host implementation must use this function to register
41798 * callbacks for a page-accessible memory (PAM) implementation.
41799 */
41800-static struct tmem_pamops tmem_pamops;
41801+static struct tmem_pamops *tmem_pamops;
41802
41803 void tmem_register_pamops(struct tmem_pamops *m)
41804 {
41805- tmem_pamops = *m;
41806+ tmem_pamops = m;
41807 }
41808
41809 /*
41810@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
41811 obj->pampd_count = 0;
41812 #ifdef CONFIG_RAMSTER
41813 if (tmem_pamops.new_obj != NULL)
41814- (*tmem_pamops.new_obj)(obj);
41815+ (tmem_pamops->new_obj)(obj);
41816 #endif
41817 SET_SENTINEL(obj, OBJ);
41818
41819@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
41820 rbnode = rb_next(rbnode);
41821 tmem_pampd_destroy_all_in_obj(obj, true);
41822 tmem_obj_free(obj, hb);
41823- (*tmem_hostops.obj_free)(obj, pool);
41824+ (tmem_hostops->obj_free)(obj, pool);
41825 }
41826 spin_unlock(&hb->lock);
41827 }
41828@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
41829 ASSERT_SENTINEL(obj, OBJ);
41830 BUG_ON(obj->pool == NULL);
41831 ASSERT_SENTINEL(obj->pool, POOL);
41832- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
41833+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
41834 if (unlikely(objnode == NULL))
41835 goto out;
41836 objnode->obj = obj;
41837@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
41838 ASSERT_SENTINEL(pool, POOL);
41839 objnode->obj->objnode_count--;
41840 objnode->obj = NULL;
41841- (*tmem_hostops.objnode_free)(objnode, pool);
41842+ (tmem_hostops->objnode_free)(objnode, pool);
41843 }
41844
41845 /*
41846@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
41847 void *old_pampd = *(void **)slot;
41848 *(void **)slot = new_pampd;
41849 if (!no_free)
41850- (*tmem_pamops.free)(old_pampd, obj->pool,
41851+ (tmem_pamops->free)(old_pampd, obj->pool,
41852 NULL, 0, false);
41853 ret = new_pampd;
41854 }
41855@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
41856 if (objnode->slots[i]) {
41857 if (ht == 1) {
41858 obj->pampd_count--;
41859- (*tmem_pamops.free)(objnode->slots[i],
41860+ (tmem_pamops->free)(objnode->slots[i],
41861 obj->pool, NULL, 0, true);
41862 objnode->slots[i] = NULL;
41863 continue;
41864@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41865 return;
41866 if (obj->objnode_tree_height == 0) {
41867 obj->pampd_count--;
41868- (*tmem_pamops.free)(obj->objnode_tree_root,
41869+ (tmem_pamops->free)(obj->objnode_tree_root,
41870 obj->pool, NULL, 0, true);
41871 } else {
41872 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
41873@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
41874 obj->objnode_tree_root = NULL;
41875 #ifdef CONFIG_RAMSTER
41876 if (tmem_pamops.free_obj != NULL)
41877- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
41878+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
41879 #endif
41880 }
41881
41882@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41883 /* if found, is a dup put, flush the old one */
41884 pampd_del = tmem_pampd_delete_from_obj(obj, index);
41885 BUG_ON(pampd_del != pampd);
41886- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41887+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
41888 if (obj->pampd_count == 0) {
41889 objnew = obj;
41890 objfound = NULL;
41891@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41892 pampd = NULL;
41893 }
41894 } else {
41895- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
41896+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
41897 if (unlikely(obj == NULL)) {
41898 ret = -ENOMEM;
41899 goto out;
41900@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41901 if (unlikely(ret == -ENOMEM))
41902 /* may have partially built objnode tree ("stump") */
41903 goto delete_and_free;
41904- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
41905+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
41906 goto out;
41907
41908 delete_and_free:
41909 (void)tmem_pampd_delete_from_obj(obj, index);
41910 if (pampd)
41911- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
41912+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
41913 if (objnew) {
41914 tmem_obj_free(objnew, hb);
41915- (*tmem_hostops.obj_free)(objnew, pool);
41916+ (tmem_hostops->obj_free)(objnew, pool);
41917 }
41918 out:
41919 spin_unlock(&hb->lock);
41920@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
41921 if (pampd != NULL) {
41922 BUG_ON(obj == NULL);
41923 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
41924- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
41925+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
41926 } else if (delete) {
41927 BUG_ON(obj == NULL);
41928 (void)tmem_pampd_delete_from_obj(obj, index);
41929@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41930 int ret = 0;
41931
41932 if (!is_ephemeral(pool))
41933- new_pampd = (*tmem_pamops.repatriate_preload)(
41934+ new_pampd = (tmem_pamops->repatriate_preload)(
41935 old_pampd, pool, oidp, index, &intransit);
41936 if (intransit)
41937 ret = -EAGAIN;
41938@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
41939 /* must release the hb->lock else repatriate can't sleep */
41940 spin_unlock(&hb->lock);
41941 if (!intransit)
41942- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
41943+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
41944 oidp, index, free, data);
41945 if (ret == -EAGAIN) {
41946 /* rare I think, but should cond_resched()??? */
41947@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
41948 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
41949 /* if we bug here, pamops wasn't properly set up for ramster */
41950 BUG_ON(tmem_pamops.replace_in_obj == NULL);
41951- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
41952+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
41953 out:
41954 spin_unlock(&hb->lock);
41955 return ret;
41956@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
41957 if (free) {
41958 if (obj->pampd_count == 0) {
41959 tmem_obj_free(obj, hb);
41960- (*tmem_hostops.obj_free)(obj, pool);
41961+ (tmem_hostops->obj_free)(obj, pool);
41962 obj = NULL;
41963 }
41964 }
41965 if (free)
41966- ret = (*tmem_pamops.get_data_and_free)(
41967+ ret = (tmem_pamops->get_data_and_free)(
41968 data, sizep, raw, pampd, pool, oidp, index);
41969 else
41970- ret = (*tmem_pamops.get_data)(
41971+ ret = (tmem_pamops->get_data)(
41972 data, sizep, raw, pampd, pool, oidp, index);
41973 if (ret < 0)
41974 goto out;
41975@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
41976 pampd = tmem_pampd_delete_from_obj(obj, index);
41977 if (pampd == NULL)
41978 goto out;
41979- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
41980+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
41981 if (obj->pampd_count == 0) {
41982 tmem_obj_free(obj, hb);
41983- (*tmem_hostops.obj_free)(obj, pool);
41984+ (tmem_hostops->obj_free)(obj, pool);
41985 }
41986 ret = 0;
41987
41988@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
41989 goto out;
41990 tmem_pampd_destroy_all_in_obj(obj, false);
41991 tmem_obj_free(obj, hb);
41992- (*tmem_hostops.obj_free)(obj, pool);
41993+ (tmem_hostops->obj_free)(obj, pool);
41994 ret = 0;
41995
41996 out:
41997diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
41998index dc23395..cf7e9b1 100644
41999--- a/drivers/staging/rtl8712/rtl871x_io.h
42000+++ b/drivers/staging/rtl8712/rtl871x_io.h
42001@@ -108,7 +108,7 @@ struct _io_ops {
42002 u8 *pmem);
42003 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42004 u8 *pmem);
42005-};
42006+} __no_const;
42007
42008 struct io_req {
42009 struct list_head list;
42010diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42011index 1f5088b..0e59820 100644
42012--- a/drivers/staging/sbe-2t3e3/netdev.c
42013+++ b/drivers/staging/sbe-2t3e3/netdev.c
42014@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42015 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
42016
42017 if (rlen)
42018- if (copy_to_user(data, &resp, rlen))
42019+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
42020 return -EFAULT;
42021
42022 return 0;
42023diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
42024index 5dddc4d..34fcb2f 100644
42025--- a/drivers/staging/usbip/vhci.h
42026+++ b/drivers/staging/usbip/vhci.h
42027@@ -83,7 +83,7 @@ struct vhci_hcd {
42028 unsigned resuming:1;
42029 unsigned long re_timeout;
42030
42031- atomic_t seqnum;
42032+ atomic_unchecked_t seqnum;
42033
42034 /*
42035 * NOTE:
42036diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
42037index c3aa219..bf8b3de 100644
42038--- a/drivers/staging/usbip/vhci_hcd.c
42039+++ b/drivers/staging/usbip/vhci_hcd.c
42040@@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
42041 return;
42042 }
42043
42044- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
42045+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42046 if (priv->seqnum == 0xffff)
42047 dev_info(&urb->dev->dev, "seqnum max\n");
42048
42049@@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
42050 return -ENOMEM;
42051 }
42052
42053- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
42054+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
42055 if (unlink->seqnum == 0xffff)
42056 pr_info("seqnum max\n");
42057
42058@@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
42059 vdev->rhport = rhport;
42060 }
42061
42062- atomic_set(&vhci->seqnum, 0);
42063+ atomic_set_unchecked(&vhci->seqnum, 0);
42064 spin_lock_init(&vhci->lock);
42065
42066 hcd->power_budget = 0; /* no limit */
42067diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
42068index ba5f1c0..11d8122 100644
42069--- a/drivers/staging/usbip/vhci_rx.c
42070+++ b/drivers/staging/usbip/vhci_rx.c
42071@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
42072 if (!urb) {
42073 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
42074 pr_info("max seqnum %d\n",
42075- atomic_read(&the_controller->seqnum));
42076+ atomic_read_unchecked(&the_controller->seqnum));
42077 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
42078 return;
42079 }
42080diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
42081index 5f13890..36a044b 100644
42082--- a/drivers/staging/vt6655/hostap.c
42083+++ b/drivers/staging/vt6655/hostap.c
42084@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
42085 *
42086 */
42087
42088+static net_device_ops_no_const apdev_netdev_ops;
42089+
42090 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42091 {
42092 PSDevice apdev_priv;
42093 struct net_device *dev = pDevice->dev;
42094 int ret;
42095- const struct net_device_ops apdev_netdev_ops = {
42096- .ndo_start_xmit = pDevice->tx_80211,
42097- };
42098
42099 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42100
42101@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42102 *apdev_priv = *pDevice;
42103 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42104
42105+ /* only half broken now */
42106+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42107 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42108
42109 pDevice->apdev->type = ARPHRD_IEEE80211;
42110diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
42111index 26a7d0e..897b083 100644
42112--- a/drivers/staging/vt6656/hostap.c
42113+++ b/drivers/staging/vt6656/hostap.c
42114@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
42115 *
42116 */
42117
42118+static net_device_ops_no_const apdev_netdev_ops;
42119+
42120 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42121 {
42122 PSDevice apdev_priv;
42123 struct net_device *dev = pDevice->dev;
42124 int ret;
42125- const struct net_device_ops apdev_netdev_ops = {
42126- .ndo_start_xmit = pDevice->tx_80211,
42127- };
42128
42129 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
42130
42131@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
42132 *apdev_priv = *pDevice;
42133 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
42134
42135+ /* only half broken now */
42136+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
42137 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
42138
42139 pDevice->apdev->type = ARPHRD_IEEE80211;
42140diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
42141index 56c8e60..1920c63 100644
42142--- a/drivers/staging/zcache/tmem.c
42143+++ b/drivers/staging/zcache/tmem.c
42144@@ -39,7 +39,7 @@
42145 * A tmem host implementation must use this function to register callbacks
42146 * for memory allocation.
42147 */
42148-static struct tmem_hostops tmem_hostops;
42149+static tmem_hostops_no_const tmem_hostops;
42150
42151 static void tmem_objnode_tree_init(void);
42152
42153@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
42154 * A tmem host implementation must use this function to register
42155 * callbacks for a page-accessible memory (PAM) implementation
42156 */
42157-static struct tmem_pamops tmem_pamops;
42158+static tmem_pamops_no_const tmem_pamops;
42159
42160 void tmem_register_pamops(struct tmem_pamops *m)
42161 {
42162diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
42163index 0d4aa82..f7832d4 100644
42164--- a/drivers/staging/zcache/tmem.h
42165+++ b/drivers/staging/zcache/tmem.h
42166@@ -180,6 +180,7 @@ struct tmem_pamops {
42167 void (*new_obj)(struct tmem_obj *);
42168 int (*replace_in_obj)(void *, struct tmem_obj *);
42169 };
42170+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
42171 extern void tmem_register_pamops(struct tmem_pamops *m);
42172
42173 /* memory allocation methods provided by the host implementation */
42174@@ -189,6 +190,7 @@ struct tmem_hostops {
42175 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
42176 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
42177 };
42178+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
42179 extern void tmem_register_hostops(struct tmem_hostops *m);
42180
42181 /* core tmem accessor functions */
42182diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
42183index 96f4981..4daaa7e 100644
42184--- a/drivers/target/target_core_device.c
42185+++ b/drivers/target/target_core_device.c
42186@@ -1370,7 +1370,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
42187 spin_lock_init(&dev->se_port_lock);
42188 spin_lock_init(&dev->se_tmr_lock);
42189 spin_lock_init(&dev->qf_cmd_lock);
42190- atomic_set(&dev->dev_ordered_id, 0);
42191+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
42192 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
42193 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
42194 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
42195diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
42196index bd587b7..173daf3 100644
42197--- a/drivers/target/target_core_transport.c
42198+++ b/drivers/target/target_core_transport.c
42199@@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
42200 * Used to determine when ORDERED commands should go from
42201 * Dormant to Active status.
42202 */
42203- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
42204+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
42205 smp_mb__after_atomic_inc();
42206 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
42207 cmd->se_ordered_id, cmd->sam_task_attr,
42208diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
42209index b09c8d1f..c4225c0 100644
42210--- a/drivers/tty/cyclades.c
42211+++ b/drivers/tty/cyclades.c
42212@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
42213 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
42214 info->port.count);
42215 #endif
42216- info->port.count++;
42217+ atomic_inc(&info->port.count);
42218 #ifdef CY_DEBUG_COUNT
42219 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
42220- current->pid, info->port.count);
42221+ current->pid, atomic_read(&info->port.count));
42222 #endif
42223
42224 /*
42225@@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
42226 for (j = 0; j < cy_card[i].nports; j++) {
42227 info = &cy_card[i].ports[j];
42228
42229- if (info->port.count) {
42230+ if (atomic_read(&info->port.count)) {
42231 /* XXX is the ldisc num worth this? */
42232 struct tty_struct *tty;
42233 struct tty_ldisc *ld;
42234diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
42235index 13ee53b..418d164 100644
42236--- a/drivers/tty/hvc/hvc_console.c
42237+++ b/drivers/tty/hvc/hvc_console.c
42238@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
42239
42240 spin_lock_irqsave(&hp->port.lock, flags);
42241 /* Check and then increment for fast path open. */
42242- if (hp->port.count++ > 0) {
42243+ if (atomic_inc_return(&hp->port.count) > 1) {
42244 spin_unlock_irqrestore(&hp->port.lock, flags);
42245 hvc_kick();
42246 return 0;
42247@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42248
42249 spin_lock_irqsave(&hp->port.lock, flags);
42250
42251- if (--hp->port.count == 0) {
42252+ if (atomic_dec_return(&hp->port.count) == 0) {
42253 spin_unlock_irqrestore(&hp->port.lock, flags);
42254 /* We are done with the tty pointer now. */
42255 tty_port_tty_set(&hp->port, NULL);
42256@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
42257 */
42258 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
42259 } else {
42260- if (hp->port.count < 0)
42261+ if (atomic_read(&hp->port.count) < 0)
42262 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
42263- hp->vtermno, hp->port.count);
42264+ hp->vtermno, atomic_read(&hp->port.count));
42265 spin_unlock_irqrestore(&hp->port.lock, flags);
42266 }
42267 }
42268@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
42269 * open->hangup case this can be called after the final close so prevent
42270 * that from happening for now.
42271 */
42272- if (hp->port.count <= 0) {
42273+ if (atomic_read(&hp->port.count) <= 0) {
42274 spin_unlock_irqrestore(&hp->port.lock, flags);
42275 return;
42276 }
42277
42278- hp->port.count = 0;
42279+ atomic_set(&hp->port.count, 0);
42280 spin_unlock_irqrestore(&hp->port.lock, flags);
42281 tty_port_tty_set(&hp->port, NULL);
42282
42283@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
42284 return -EPIPE;
42285
42286 /* FIXME what's this (unprotected) check for? */
42287- if (hp->port.count <= 0)
42288+ if (atomic_read(&hp->port.count) <= 0)
42289 return -EIO;
42290
42291 spin_lock_irqsave(&hp->lock, flags);
42292diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
42293index 8776357..b2d4afd 100644
42294--- a/drivers/tty/hvc/hvcs.c
42295+++ b/drivers/tty/hvc/hvcs.c
42296@@ -83,6 +83,7 @@
42297 #include <asm/hvcserver.h>
42298 #include <asm/uaccess.h>
42299 #include <asm/vio.h>
42300+#include <asm/local.h>
42301
42302 /*
42303 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
42304@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
42305
42306 spin_lock_irqsave(&hvcsd->lock, flags);
42307
42308- if (hvcsd->port.count > 0) {
42309+ if (atomic_read(&hvcsd->port.count) > 0) {
42310 spin_unlock_irqrestore(&hvcsd->lock, flags);
42311 printk(KERN_INFO "HVCS: vterm state unchanged. "
42312 "The hvcs device node is still in use.\n");
42313@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
42314 }
42315 }
42316
42317- hvcsd->port.count = 0;
42318+ atomic_set(&hvcsd->port.count, 0);
42319 hvcsd->port.tty = tty;
42320 tty->driver_data = hvcsd;
42321
42322@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
42323 unsigned long flags;
42324
42325 spin_lock_irqsave(&hvcsd->lock, flags);
42326- hvcsd->port.count++;
42327+ atomic_inc(&hvcsd->port.count);
42328 hvcsd->todo_mask |= HVCS_SCHED_READ;
42329 spin_unlock_irqrestore(&hvcsd->lock, flags);
42330
42331@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42332 hvcsd = tty->driver_data;
42333
42334 spin_lock_irqsave(&hvcsd->lock, flags);
42335- if (--hvcsd->port.count == 0) {
42336+ if (atomic_dec_and_test(&hvcsd->port.count)) {
42337
42338 vio_disable_interrupts(hvcsd->vdev);
42339
42340@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
42341
42342 free_irq(irq, hvcsd);
42343 return;
42344- } else if (hvcsd->port.count < 0) {
42345+ } else if (atomic_read(&hvcsd->port.count) < 0) {
42346 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
42347 " is missmanaged.\n",
42348- hvcsd->vdev->unit_address, hvcsd->port.count);
42349+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
42350 }
42351
42352 spin_unlock_irqrestore(&hvcsd->lock, flags);
42353@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42354
42355 spin_lock_irqsave(&hvcsd->lock, flags);
42356 /* Preserve this so that we know how many kref refs to put */
42357- temp_open_count = hvcsd->port.count;
42358+ temp_open_count = atomic_read(&hvcsd->port.count);
42359
42360 /*
42361 * Don't kref put inside the spinlock because the destruction
42362@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
42363 tty->driver_data = NULL;
42364 hvcsd->port.tty = NULL;
42365
42366- hvcsd->port.count = 0;
42367+ atomic_set(&hvcsd->port.count, 0);
42368
42369 /* This will drop any buffered data on the floor which is OK in a hangup
42370 * scenario. */
42371@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
42372 * the middle of a write operation? This is a crummy place to do this
42373 * but we want to keep it all in the spinlock.
42374 */
42375- if (hvcsd->port.count <= 0) {
42376+ if (atomic_read(&hvcsd->port.count) <= 0) {
42377 spin_unlock_irqrestore(&hvcsd->lock, flags);
42378 return -ENODEV;
42379 }
42380@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
42381 {
42382 struct hvcs_struct *hvcsd = tty->driver_data;
42383
42384- if (!hvcsd || hvcsd->port.count <= 0)
42385+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
42386 return 0;
42387
42388 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
42389diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
42390index 2cde13d..645d78f 100644
42391--- a/drivers/tty/ipwireless/tty.c
42392+++ b/drivers/tty/ipwireless/tty.c
42393@@ -29,6 +29,7 @@
42394 #include <linux/tty_driver.h>
42395 #include <linux/tty_flip.h>
42396 #include <linux/uaccess.h>
42397+#include <asm/local.h>
42398
42399 #include "tty.h"
42400 #include "network.h"
42401@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42402 mutex_unlock(&tty->ipw_tty_mutex);
42403 return -ENODEV;
42404 }
42405- if (tty->port.count == 0)
42406+ if (atomic_read(&tty->port.count) == 0)
42407 tty->tx_bytes_queued = 0;
42408
42409- tty->port.count++;
42410+ atomic_inc(&tty->port.count);
42411
42412 tty->port.tty = linux_tty;
42413 linux_tty->driver_data = tty;
42414@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
42415
42416 static void do_ipw_close(struct ipw_tty *tty)
42417 {
42418- tty->port.count--;
42419-
42420- if (tty->port.count == 0) {
42421+ if (atomic_dec_return(&tty->port.count) == 0) {
42422 struct tty_struct *linux_tty = tty->port.tty;
42423
42424 if (linux_tty != NULL) {
42425@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
42426 return;
42427
42428 mutex_lock(&tty->ipw_tty_mutex);
42429- if (tty->port.count == 0) {
42430+ if (atomic_read(&tty->port.count) == 0) {
42431 mutex_unlock(&tty->ipw_tty_mutex);
42432 return;
42433 }
42434@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
42435 return;
42436 }
42437
42438- if (!tty->port.count) {
42439+ if (!atomic_read(&tty->port.count)) {
42440 mutex_unlock(&tty->ipw_tty_mutex);
42441 return;
42442 }
42443@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
42444 return -ENODEV;
42445
42446 mutex_lock(&tty->ipw_tty_mutex);
42447- if (!tty->port.count) {
42448+ if (!atomic_read(&tty->port.count)) {
42449 mutex_unlock(&tty->ipw_tty_mutex);
42450 return -EINVAL;
42451 }
42452@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
42453 if (!tty)
42454 return -ENODEV;
42455
42456- if (!tty->port.count)
42457+ if (!atomic_read(&tty->port.count))
42458 return -EINVAL;
42459
42460 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
42461@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
42462 if (!tty)
42463 return 0;
42464
42465- if (!tty->port.count)
42466+ if (!atomic_read(&tty->port.count))
42467 return 0;
42468
42469 return tty->tx_bytes_queued;
42470@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
42471 if (!tty)
42472 return -ENODEV;
42473
42474- if (!tty->port.count)
42475+ if (!atomic_read(&tty->port.count))
42476 return -EINVAL;
42477
42478 return get_control_lines(tty);
42479@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
42480 if (!tty)
42481 return -ENODEV;
42482
42483- if (!tty->port.count)
42484+ if (!atomic_read(&tty->port.count))
42485 return -EINVAL;
42486
42487 return set_control_lines(tty, set, clear);
42488@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
42489 if (!tty)
42490 return -ENODEV;
42491
42492- if (!tty->port.count)
42493+ if (!atomic_read(&tty->port.count))
42494 return -EINVAL;
42495
42496 /* FIXME: Exactly how is the tty object locked here .. */
42497@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
42498 * are gone */
42499 mutex_lock(&ttyj->ipw_tty_mutex);
42500 }
42501- while (ttyj->port.count)
42502+ while (atomic_read(&ttyj->port.count))
42503 do_ipw_close(ttyj);
42504 ipwireless_disassociate_network_ttys(network,
42505 ttyj->channel_idx);
42506diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
42507index f9d2850..b006f04 100644
42508--- a/drivers/tty/moxa.c
42509+++ b/drivers/tty/moxa.c
42510@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
42511 }
42512
42513 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
42514- ch->port.count++;
42515+ atomic_inc(&ch->port.count);
42516 tty->driver_data = ch;
42517 tty_port_tty_set(&ch->port, tty);
42518 mutex_lock(&ch->port.mutex);
42519diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
42520index bfd6771..e0d93c4 100644
42521--- a/drivers/tty/n_gsm.c
42522+++ b/drivers/tty/n_gsm.c
42523@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
42524 spin_lock_init(&dlci->lock);
42525 mutex_init(&dlci->mutex);
42526 dlci->fifo = &dlci->_fifo;
42527- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
42528+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
42529 kfree(dlci);
42530 return NULL;
42531 }
42532@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
42533 struct gsm_dlci *dlci = tty->driver_data;
42534 struct tty_port *port = &dlci->port;
42535
42536- port->count++;
42537+ atomic_inc(&port->count);
42538 dlci_get(dlci);
42539 dlci_get(dlci->gsm->dlci[0]);
42540 mux_get(dlci->gsm);
42541diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
42542index 19083ef..6e34e97 100644
42543--- a/drivers/tty/n_tty.c
42544+++ b/drivers/tty/n_tty.c
42545@@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
42546 {
42547 *ops = tty_ldisc_N_TTY;
42548 ops->owner = NULL;
42549- ops->refcount = ops->flags = 0;
42550+ atomic_set(&ops->refcount, 0);
42551+ ops->flags = 0;
42552 }
42553 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
42554diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
42555index 79ff3a5..1fe9399 100644
42556--- a/drivers/tty/pty.c
42557+++ b/drivers/tty/pty.c
42558@@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
42559 panic("Couldn't register Unix98 pts driver");
42560
42561 /* Now create the /dev/ptmx special device */
42562+ pax_open_kernel();
42563 tty_default_fops(&ptmx_fops);
42564- ptmx_fops.open = ptmx_open;
42565+ *(void **)&ptmx_fops.open = ptmx_open;
42566+ pax_close_kernel();
42567
42568 cdev_init(&ptmx_cdev, &ptmx_fops);
42569 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
42570diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
42571index e42009a..566a036 100644
42572--- a/drivers/tty/rocket.c
42573+++ b/drivers/tty/rocket.c
42574@@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42575 tty->driver_data = info;
42576 tty_port_tty_set(port, tty);
42577
42578- if (port->count++ == 0) {
42579+ if (atomic_inc_return(&port->count) == 1) {
42580 atomic_inc(&rp_num_ports_open);
42581
42582 #ifdef ROCKET_DEBUG_OPEN
42583@@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
42584 #endif
42585 }
42586 #ifdef ROCKET_DEBUG_OPEN
42587- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
42588+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
42589 #endif
42590
42591 /*
42592@@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
42593 spin_unlock_irqrestore(&info->port.lock, flags);
42594 return;
42595 }
42596- if (info->port.count)
42597+ if (atomic_read(&info->port.count))
42598 atomic_dec(&rp_num_ports_open);
42599 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
42600 spin_unlock_irqrestore(&info->port.lock, flags);
42601diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
42602index 1002054..dd644a8 100644
42603--- a/drivers/tty/serial/kgdboc.c
42604+++ b/drivers/tty/serial/kgdboc.c
42605@@ -24,8 +24,9 @@
42606 #define MAX_CONFIG_LEN 40
42607
42608 static struct kgdb_io kgdboc_io_ops;
42609+static struct kgdb_io kgdboc_io_ops_console;
42610
42611-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
42612+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
42613 static int configured = -1;
42614
42615 static char config[MAX_CONFIG_LEN];
42616@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
42617 kgdboc_unregister_kbd();
42618 if (configured == 1)
42619 kgdb_unregister_io_module(&kgdboc_io_ops);
42620+ else if (configured == 2)
42621+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
42622 }
42623
42624 static int configure_kgdboc(void)
42625@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
42626 int err;
42627 char *cptr = config;
42628 struct console *cons;
42629+ int is_console = 0;
42630
42631 err = kgdboc_option_setup(config);
42632 if (err || !strlen(config) || isspace(config[0]))
42633 goto noconfig;
42634
42635 err = -ENODEV;
42636- kgdboc_io_ops.is_console = 0;
42637 kgdb_tty_driver = NULL;
42638
42639 kgdboc_use_kms = 0;
42640@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
42641 int idx;
42642 if (cons->device && cons->device(cons, &idx) == p &&
42643 idx == tty_line) {
42644- kgdboc_io_ops.is_console = 1;
42645+ is_console = 1;
42646 break;
42647 }
42648 cons = cons->next;
42649@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
42650 kgdb_tty_line = tty_line;
42651
42652 do_register:
42653- err = kgdb_register_io_module(&kgdboc_io_ops);
42654+ if (is_console) {
42655+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
42656+ configured = 2;
42657+ } else {
42658+ err = kgdb_register_io_module(&kgdboc_io_ops);
42659+ configured = 1;
42660+ }
42661 if (err)
42662 goto noconfig;
42663
42664@@ -205,8 +214,6 @@ do_register:
42665 if (err)
42666 goto nmi_con_failed;
42667
42668- configured = 1;
42669-
42670 return 0;
42671
42672 nmi_con_failed:
42673@@ -223,7 +230,7 @@ noconfig:
42674 static int __init init_kgdboc(void)
42675 {
42676 /* Already configured? */
42677- if (configured == 1)
42678+ if (configured >= 1)
42679 return 0;
42680
42681 return configure_kgdboc();
42682@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
42683 if (config[len - 1] == '\n')
42684 config[len - 1] = '\0';
42685
42686- if (configured == 1)
42687+ if (configured >= 1)
42688 cleanup_kgdboc();
42689
42690 /* Go and configure with the new params. */
42691@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
42692 .post_exception = kgdboc_post_exp_handler,
42693 };
42694
42695+static struct kgdb_io kgdboc_io_ops_console = {
42696+ .name = "kgdboc",
42697+ .read_char = kgdboc_get_char,
42698+ .write_char = kgdboc_put_char,
42699+ .pre_exception = kgdboc_pre_exp_handler,
42700+ .post_exception = kgdboc_post_exp_handler,
42701+ .is_console = 1
42702+};
42703+
42704 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
42705 /* This is only available if kgdboc is a built in for early debugging */
42706 static int __init kgdboc_early_init(char *opt)
42707diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
42708index e514b3a..c73d614 100644
42709--- a/drivers/tty/serial/samsung.c
42710+++ b/drivers/tty/serial/samsung.c
42711@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
42712 }
42713 }
42714
42715+static int s3c64xx_serial_startup(struct uart_port *port);
42716 static int s3c24xx_serial_startup(struct uart_port *port)
42717 {
42718 struct s3c24xx_uart_port *ourport = to_ourport(port);
42719 int ret;
42720
42721+ /* Startup sequence is different for s3c64xx and higher SoC's */
42722+ if (s3c24xx_serial_has_interrupt_mask(port))
42723+ return s3c64xx_serial_startup(port);
42724+
42725 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
42726 port->mapbase, port->membase);
42727
42728@@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
42729 /* setup info for port */
42730 port->dev = &platdev->dev;
42731
42732- /* Startup sequence is different for s3c64xx and higher SoC's */
42733- if (s3c24xx_serial_has_interrupt_mask(port))
42734- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
42735-
42736 port->uartclk = 1;
42737
42738 if (cfg->uart_flags & UPF_CONS_FLOW) {
42739diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
42740index 2c7230a..2104f16 100644
42741--- a/drivers/tty/serial/serial_core.c
42742+++ b/drivers/tty/serial/serial_core.c
42743@@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
42744 uart_flush_buffer(tty);
42745 uart_shutdown(tty, state);
42746 spin_lock_irqsave(&port->lock, flags);
42747- port->count = 0;
42748+ atomic_set(&port->count, 0);
42749 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
42750 spin_unlock_irqrestore(&port->lock, flags);
42751 tty_port_tty_set(port, NULL);
42752@@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42753 goto end;
42754 }
42755
42756- port->count++;
42757+ atomic_inc(&port->count);
42758 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
42759 retval = -ENXIO;
42760 goto err_dec_count;
42761@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42762 /*
42763 * Make sure the device is in D0 state.
42764 */
42765- if (port->count == 1)
42766+ if (atomic_read(&port->count) == 1)
42767 uart_change_pm(state, 0);
42768
42769 /*
42770@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
42771 end:
42772 return retval;
42773 err_dec_count:
42774- port->count--;
42775+ atomic_inc(&port->count);
42776 mutex_unlock(&port->mutex);
42777 goto end;
42778 }
42779diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
42780index 9e071f6..f30ae69 100644
42781--- a/drivers/tty/synclink.c
42782+++ b/drivers/tty/synclink.c
42783@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42784
42785 if (debug_level >= DEBUG_LEVEL_INFO)
42786 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
42787- __FILE__,__LINE__, info->device_name, info->port.count);
42788+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
42789
42790 if (tty_port_close_start(&info->port, tty, filp) == 0)
42791 goto cleanup;
42792@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
42793 cleanup:
42794 if (debug_level >= DEBUG_LEVEL_INFO)
42795 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
42796- tty->driver->name, info->port.count);
42797+ tty->driver->name, atomic_read(&info->port.count));
42798
42799 } /* end of mgsl_close() */
42800
42801@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
42802
42803 mgsl_flush_buffer(tty);
42804 shutdown(info);
42805-
42806- info->port.count = 0;
42807+
42808+ atomic_set(&info->port.count, 0);
42809 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42810 info->port.tty = NULL;
42811
42812@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42813
42814 if (debug_level >= DEBUG_LEVEL_INFO)
42815 printk("%s(%d):block_til_ready before block on %s count=%d\n",
42816- __FILE__,__LINE__, tty->driver->name, port->count );
42817+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42818
42819 spin_lock_irqsave(&info->irq_spinlock, flags);
42820 if (!tty_hung_up_p(filp)) {
42821 extra_count = true;
42822- port->count--;
42823+ atomic_dec(&port->count);
42824 }
42825 spin_unlock_irqrestore(&info->irq_spinlock, flags);
42826 port->blocked_open++;
42827@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42828
42829 if (debug_level >= DEBUG_LEVEL_INFO)
42830 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
42831- __FILE__,__LINE__, tty->driver->name, port->count );
42832+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42833
42834 tty_unlock(tty);
42835 schedule();
42836@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
42837
42838 /* FIXME: Racy on hangup during close wait */
42839 if (extra_count)
42840- port->count++;
42841+ atomic_inc(&port->count);
42842 port->blocked_open--;
42843
42844 if (debug_level >= DEBUG_LEVEL_INFO)
42845 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
42846- __FILE__,__LINE__, tty->driver->name, port->count );
42847+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
42848
42849 if (!retval)
42850 port->flags |= ASYNC_NORMAL_ACTIVE;
42851@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42852
42853 if (debug_level >= DEBUG_LEVEL_INFO)
42854 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
42855- __FILE__,__LINE__,tty->driver->name, info->port.count);
42856+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
42857
42858 /* If port is closing, signal caller to try again */
42859 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42860@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
42861 spin_unlock_irqrestore(&info->netlock, flags);
42862 goto cleanup;
42863 }
42864- info->port.count++;
42865+ atomic_inc(&info->port.count);
42866 spin_unlock_irqrestore(&info->netlock, flags);
42867
42868- if (info->port.count == 1) {
42869+ if (atomic_read(&info->port.count) == 1) {
42870 /* 1st open on this device, init hardware */
42871 retval = startup(info);
42872 if (retval < 0)
42873@@ -3451,8 +3451,8 @@ cleanup:
42874 if (retval) {
42875 if (tty->count == 1)
42876 info->port.tty = NULL; /* tty layer will release tty struct */
42877- if(info->port.count)
42878- info->port.count--;
42879+ if (atomic_read(&info->port.count))
42880+ atomic_dec(&info->port.count);
42881 }
42882
42883 return retval;
42884@@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42885 unsigned short new_crctype;
42886
42887 /* return error if TTY interface open */
42888- if (info->port.count)
42889+ if (atomic_read(&info->port.count))
42890 return -EBUSY;
42891
42892 switch (encoding)
42893@@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
42894
42895 /* arbitrate between network and tty opens */
42896 spin_lock_irqsave(&info->netlock, flags);
42897- if (info->port.count != 0 || info->netcount != 0) {
42898+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42899 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
42900 spin_unlock_irqrestore(&info->netlock, flags);
42901 return -EBUSY;
42902@@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42903 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
42904
42905 /* return error if TTY interface open */
42906- if (info->port.count)
42907+ if (atomic_read(&info->port.count))
42908 return -EBUSY;
42909
42910 if (cmd != SIOCWANDEV)
42911diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
42912index aba1e59..877ac33 100644
42913--- a/drivers/tty/synclink_gt.c
42914+++ b/drivers/tty/synclink_gt.c
42915@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
42916 tty->driver_data = info;
42917 info->port.tty = tty;
42918
42919- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
42920+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
42921
42922 /* If port is closing, signal caller to try again */
42923 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
42924@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
42925 mutex_unlock(&info->port.mutex);
42926 goto cleanup;
42927 }
42928- info->port.count++;
42929+ atomic_inc(&info->port.count);
42930 spin_unlock_irqrestore(&info->netlock, flags);
42931
42932- if (info->port.count == 1) {
42933+ if (atomic_read(&info->port.count) == 1) {
42934 /* 1st open on this device, init hardware */
42935 retval = startup(info);
42936 if (retval < 0) {
42937@@ -716,8 +716,8 @@ cleanup:
42938 if (retval) {
42939 if (tty->count == 1)
42940 info->port.tty = NULL; /* tty layer will release tty struct */
42941- if(info->port.count)
42942- info->port.count--;
42943+ if(atomic_read(&info->port.count))
42944+ atomic_dec(&info->port.count);
42945 }
42946
42947 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
42948@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42949
42950 if (sanity_check(info, tty->name, "close"))
42951 return;
42952- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
42953+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
42954
42955 if (tty_port_close_start(&info->port, tty, filp) == 0)
42956 goto cleanup;
42957@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
42958 tty_port_close_end(&info->port, tty);
42959 info->port.tty = NULL;
42960 cleanup:
42961- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
42962+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
42963 }
42964
42965 static void hangup(struct tty_struct *tty)
42966@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
42967 shutdown(info);
42968
42969 spin_lock_irqsave(&info->port.lock, flags);
42970- info->port.count = 0;
42971+ atomic_set(&info->port.count, 0);
42972 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
42973 info->port.tty = NULL;
42974 spin_unlock_irqrestore(&info->port.lock, flags);
42975@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
42976 unsigned short new_crctype;
42977
42978 /* return error if TTY interface open */
42979- if (info->port.count)
42980+ if (atomic_read(&info->port.count))
42981 return -EBUSY;
42982
42983 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
42984@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
42985
42986 /* arbitrate between network and tty opens */
42987 spin_lock_irqsave(&info->netlock, flags);
42988- if (info->port.count != 0 || info->netcount != 0) {
42989+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
42990 DBGINFO(("%s hdlc_open busy\n", dev->name));
42991 spin_unlock_irqrestore(&info->netlock, flags);
42992 return -EBUSY;
42993@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42994 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
42995
42996 /* return error if TTY interface open */
42997- if (info->port.count)
42998+ if (atomic_read(&info->port.count))
42999 return -EBUSY;
43000
43001 if (cmd != SIOCWANDEV)
43002@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43003 if (port == NULL)
43004 continue;
43005 spin_lock(&port->lock);
43006- if ((port->port.count || port->netcount) &&
43007+ if ((atomic_read(&port->port.count) || port->netcount) &&
43008 port->pending_bh && !port->bh_running &&
43009 !port->bh_requested) {
43010 DBGISR(("%s bh queued\n", port->device_name));
43011@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43012 spin_lock_irqsave(&info->lock, flags);
43013 if (!tty_hung_up_p(filp)) {
43014 extra_count = true;
43015- port->count--;
43016+ atomic_dec(&port->count);
43017 }
43018 spin_unlock_irqrestore(&info->lock, flags);
43019 port->blocked_open++;
43020@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43021 remove_wait_queue(&port->open_wait, &wait);
43022
43023 if (extra_count)
43024- port->count++;
43025+ atomic_inc(&port->count);
43026 port->blocked_open--;
43027
43028 if (!retval)
43029diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
43030index fd43fb6..34704ad 100644
43031--- a/drivers/tty/synclinkmp.c
43032+++ b/drivers/tty/synclinkmp.c
43033@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43034
43035 if (debug_level >= DEBUG_LEVEL_INFO)
43036 printk("%s(%d):%s open(), old ref count = %d\n",
43037- __FILE__,__LINE__,tty->driver->name, info->port.count);
43038+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43039
43040 /* If port is closing, signal caller to try again */
43041 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43042@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43043 spin_unlock_irqrestore(&info->netlock, flags);
43044 goto cleanup;
43045 }
43046- info->port.count++;
43047+ atomic_inc(&info->port.count);
43048 spin_unlock_irqrestore(&info->netlock, flags);
43049
43050- if (info->port.count == 1) {
43051+ if (atomic_read(&info->port.count) == 1) {
43052 /* 1st open on this device, init hardware */
43053 retval = startup(info);
43054 if (retval < 0)
43055@@ -797,8 +797,8 @@ cleanup:
43056 if (retval) {
43057 if (tty->count == 1)
43058 info->port.tty = NULL; /* tty layer will release tty struct */
43059- if(info->port.count)
43060- info->port.count--;
43061+ if(atomic_read(&info->port.count))
43062+ atomic_dec(&info->port.count);
43063 }
43064
43065 return retval;
43066@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43067
43068 if (debug_level >= DEBUG_LEVEL_INFO)
43069 printk("%s(%d):%s close() entry, count=%d\n",
43070- __FILE__,__LINE__, info->device_name, info->port.count);
43071+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43072
43073 if (tty_port_close_start(&info->port, tty, filp) == 0)
43074 goto cleanup;
43075@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43076 cleanup:
43077 if (debug_level >= DEBUG_LEVEL_INFO)
43078 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
43079- tty->driver->name, info->port.count);
43080+ tty->driver->name, atomic_read(&info->port.count));
43081 }
43082
43083 /* Called by tty_hangup() when a hangup is signaled.
43084@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
43085 shutdown(info);
43086
43087 spin_lock_irqsave(&info->port.lock, flags);
43088- info->port.count = 0;
43089+ atomic_set(&info->port.count, 0);
43090 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43091 info->port.tty = NULL;
43092 spin_unlock_irqrestore(&info->port.lock, flags);
43093@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43094 unsigned short new_crctype;
43095
43096 /* return error if TTY interface open */
43097- if (info->port.count)
43098+ if (atomic_read(&info->port.count))
43099 return -EBUSY;
43100
43101 switch (encoding)
43102@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
43103
43104 /* arbitrate between network and tty opens */
43105 spin_lock_irqsave(&info->netlock, flags);
43106- if (info->port.count != 0 || info->netcount != 0) {
43107+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43108 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43109 spin_unlock_irqrestore(&info->netlock, flags);
43110 return -EBUSY;
43111@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43112 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43113
43114 /* return error if TTY interface open */
43115- if (info->port.count)
43116+ if (atomic_read(&info->port.count))
43117 return -EBUSY;
43118
43119 if (cmd != SIOCWANDEV)
43120@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
43121 * do not request bottom half processing if the
43122 * device is not open in a normal mode.
43123 */
43124- if ( port && (port->port.count || port->netcount) &&
43125+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
43126 port->pending_bh && !port->bh_running &&
43127 !port->bh_requested ) {
43128 if ( debug_level >= DEBUG_LEVEL_ISR )
43129@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43130
43131 if (debug_level >= DEBUG_LEVEL_INFO)
43132 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
43133- __FILE__,__LINE__, tty->driver->name, port->count );
43134+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43135
43136 spin_lock_irqsave(&info->lock, flags);
43137 if (!tty_hung_up_p(filp)) {
43138 extra_count = true;
43139- port->count--;
43140+ atomic_dec(&port->count);
43141 }
43142 spin_unlock_irqrestore(&info->lock, flags);
43143 port->blocked_open++;
43144@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43145
43146 if (debug_level >= DEBUG_LEVEL_INFO)
43147 printk("%s(%d):%s block_til_ready() count=%d\n",
43148- __FILE__,__LINE__, tty->driver->name, port->count );
43149+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43150
43151 tty_unlock(tty);
43152 schedule();
43153@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43154 remove_wait_queue(&port->open_wait, &wait);
43155
43156 if (extra_count)
43157- port->count++;
43158+ atomic_inc(&port->count);
43159 port->blocked_open--;
43160
43161 if (debug_level >= DEBUG_LEVEL_INFO)
43162 printk("%s(%d):%s block_til_ready() after, count=%d\n",
43163- __FILE__,__LINE__, tty->driver->name, port->count );
43164+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43165
43166 if (!retval)
43167 port->flags |= ASYNC_NORMAL_ACTIVE;
43168diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
43169index b3c4a25..723916f 100644
43170--- a/drivers/tty/sysrq.c
43171+++ b/drivers/tty/sysrq.c
43172@@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
43173 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
43174 size_t count, loff_t *ppos)
43175 {
43176- if (count) {
43177+ if (count && capable(CAP_SYS_ADMIN)) {
43178 char c;
43179
43180 if (get_user(c, buf))
43181diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
43182index da9fde8..c07975f 100644
43183--- a/drivers/tty/tty_io.c
43184+++ b/drivers/tty/tty_io.c
43185@@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
43186
43187 void tty_default_fops(struct file_operations *fops)
43188 {
43189- *fops = tty_fops;
43190+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
43191 }
43192
43193 /*
43194diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
43195index c578229..45aa9ee 100644
43196--- a/drivers/tty/tty_ldisc.c
43197+++ b/drivers/tty/tty_ldisc.c
43198@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
43199 if (atomic_dec_and_test(&ld->users)) {
43200 struct tty_ldisc_ops *ldo = ld->ops;
43201
43202- ldo->refcount--;
43203+ atomic_dec(&ldo->refcount);
43204 module_put(ldo->owner);
43205 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43206
43207@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
43208 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43209 tty_ldiscs[disc] = new_ldisc;
43210 new_ldisc->num = disc;
43211- new_ldisc->refcount = 0;
43212+ atomic_set(&new_ldisc->refcount, 0);
43213 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43214
43215 return ret;
43216@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
43217 return -EINVAL;
43218
43219 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43220- if (tty_ldiscs[disc]->refcount)
43221+ if (atomic_read(&tty_ldiscs[disc]->refcount))
43222 ret = -EBUSY;
43223 else
43224 tty_ldiscs[disc] = NULL;
43225@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
43226 if (ldops) {
43227 ret = ERR_PTR(-EAGAIN);
43228 if (try_module_get(ldops->owner)) {
43229- ldops->refcount++;
43230+ atomic_inc(&ldops->refcount);
43231 ret = ldops;
43232 }
43233 }
43234@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
43235 unsigned long flags;
43236
43237 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
43238- ldops->refcount--;
43239+ atomic_dec(&ldops->refcount);
43240 module_put(ldops->owner);
43241 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
43242 }
43243diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
43244index b7ff59d..7c6105e 100644
43245--- a/drivers/tty/tty_port.c
43246+++ b/drivers/tty/tty_port.c
43247@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
43248 unsigned long flags;
43249
43250 spin_lock_irqsave(&port->lock, flags);
43251- port->count = 0;
43252+ atomic_set(&port->count, 0);
43253 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43254 if (port->tty) {
43255 set_bit(TTY_IO_ERROR, &port->tty->flags);
43256@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43257 /* The port lock protects the port counts */
43258 spin_lock_irqsave(&port->lock, flags);
43259 if (!tty_hung_up_p(filp))
43260- port->count--;
43261+ atomic_dec(&port->count);
43262 port->blocked_open++;
43263 spin_unlock_irqrestore(&port->lock, flags);
43264
43265@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
43266 we must not mess that up further */
43267 spin_lock_irqsave(&port->lock, flags);
43268 if (!tty_hung_up_p(filp))
43269- port->count++;
43270+ atomic_inc(&port->count);
43271 port->blocked_open--;
43272 if (retval == 0)
43273 port->flags |= ASYNC_NORMAL_ACTIVE;
43274@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
43275 return 0;
43276 }
43277
43278- if (tty->count == 1 && port->count != 1) {
43279+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
43280 printk(KERN_WARNING
43281 "tty_port_close_start: tty->count = 1 port count = %d.\n",
43282- port->count);
43283- port->count = 1;
43284+ atomic_read(&port->count));
43285+ atomic_set(&port->count, 1);
43286 }
43287- if (--port->count < 0) {
43288+ if (atomic_dec_return(&port->count) < 0) {
43289 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
43290- port->count);
43291- port->count = 0;
43292+ atomic_read(&port->count));
43293+ atomic_set(&port->count, 0);
43294 }
43295
43296- if (port->count) {
43297+ if (atomic_read(&port->count)) {
43298 spin_unlock_irqrestore(&port->lock, flags);
43299 if (port->ops->drop)
43300 port->ops->drop(port);
43301@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
43302 {
43303 spin_lock_irq(&port->lock);
43304 if (!tty_hung_up_p(filp))
43305- ++port->count;
43306+ atomic_inc(&port->count);
43307 spin_unlock_irq(&port->lock);
43308 tty_port_tty_set(port, tty);
43309
43310diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
43311index 681765b..d3ccdf2 100644
43312--- a/drivers/tty/vt/keyboard.c
43313+++ b/drivers/tty/vt/keyboard.c
43314@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
43315 kbd->kbdmode == VC_OFF) &&
43316 value != KVAL(K_SAK))
43317 return; /* SAK is allowed even in raw mode */
43318+
43319+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
43320+ {
43321+ void *func = fn_handler[value];
43322+ if (func == fn_show_state || func == fn_show_ptregs ||
43323+ func == fn_show_mem)
43324+ return;
43325+ }
43326+#endif
43327+
43328 fn_handler[value](vc);
43329 }
43330
43331@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43332 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
43333 return -EFAULT;
43334
43335- if (!capable(CAP_SYS_TTY_CONFIG))
43336- perm = 0;
43337-
43338 switch (cmd) {
43339 case KDGKBENT:
43340 /* Ensure another thread doesn't free it under us */
43341@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
43342 spin_unlock_irqrestore(&kbd_event_lock, flags);
43343 return put_user(val, &user_kbe->kb_value);
43344 case KDSKBENT:
43345+ if (!capable(CAP_SYS_TTY_CONFIG))
43346+ perm = 0;
43347+
43348 if (!perm)
43349 return -EPERM;
43350 if (!i && v == K_NOSUCHMAP) {
43351@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43352 int i, j, k;
43353 int ret;
43354
43355- if (!capable(CAP_SYS_TTY_CONFIG))
43356- perm = 0;
43357-
43358 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
43359 if (!kbs) {
43360 ret = -ENOMEM;
43361@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
43362 kfree(kbs);
43363 return ((p && *p) ? -EOVERFLOW : 0);
43364 case KDSKBSENT:
43365+ if (!capable(CAP_SYS_TTY_CONFIG))
43366+ perm = 0;
43367+
43368 if (!perm) {
43369 ret = -EPERM;
43370 goto reterr;
43371diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
43372index 5110f36..8dc0a74 100644
43373--- a/drivers/uio/uio.c
43374+++ b/drivers/uio/uio.c
43375@@ -25,6 +25,7 @@
43376 #include <linux/kobject.h>
43377 #include <linux/cdev.h>
43378 #include <linux/uio_driver.h>
43379+#include <asm/local.h>
43380
43381 #define UIO_MAX_DEVICES (1U << MINORBITS)
43382
43383@@ -32,10 +33,10 @@ struct uio_device {
43384 struct module *owner;
43385 struct device *dev;
43386 int minor;
43387- atomic_t event;
43388+ atomic_unchecked_t event;
43389 struct fasync_struct *async_queue;
43390 wait_queue_head_t wait;
43391- int vma_count;
43392+ local_t vma_count;
43393 struct uio_info *info;
43394 struct kobject *map_dir;
43395 struct kobject *portio_dir;
43396@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
43397 struct device_attribute *attr, char *buf)
43398 {
43399 struct uio_device *idev = dev_get_drvdata(dev);
43400- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
43401+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
43402 }
43403
43404 static struct device_attribute uio_class_attributes[] = {
43405@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
43406 {
43407 struct uio_device *idev = info->uio_dev;
43408
43409- atomic_inc(&idev->event);
43410+ atomic_inc_unchecked(&idev->event);
43411 wake_up_interruptible(&idev->wait);
43412 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
43413 }
43414@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
43415 }
43416
43417 listener->dev = idev;
43418- listener->event_count = atomic_read(&idev->event);
43419+ listener->event_count = atomic_read_unchecked(&idev->event);
43420 filep->private_data = listener;
43421
43422 if (idev->info->open) {
43423@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
43424 return -EIO;
43425
43426 poll_wait(filep, &idev->wait, wait);
43427- if (listener->event_count != atomic_read(&idev->event))
43428+ if (listener->event_count != atomic_read_unchecked(&idev->event))
43429 return POLLIN | POLLRDNORM;
43430 return 0;
43431 }
43432@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
43433 do {
43434 set_current_state(TASK_INTERRUPTIBLE);
43435
43436- event_count = atomic_read(&idev->event);
43437+ event_count = atomic_read_unchecked(&idev->event);
43438 if (event_count != listener->event_count) {
43439 if (copy_to_user(buf, &event_count, count))
43440 retval = -EFAULT;
43441@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
43442 static void uio_vma_open(struct vm_area_struct *vma)
43443 {
43444 struct uio_device *idev = vma->vm_private_data;
43445- idev->vma_count++;
43446+ local_inc(&idev->vma_count);
43447 }
43448
43449 static void uio_vma_close(struct vm_area_struct *vma)
43450 {
43451 struct uio_device *idev = vma->vm_private_data;
43452- idev->vma_count--;
43453+ local_dec(&idev->vma_count);
43454 }
43455
43456 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
43457@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
43458 idev->owner = owner;
43459 idev->info = info;
43460 init_waitqueue_head(&idev->wait);
43461- atomic_set(&idev->event, 0);
43462+ atomic_set_unchecked(&idev->event, 0);
43463
43464 ret = uio_get_minor(idev);
43465 if (ret)
43466diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
43467index b7eb86a..36d28af 100644
43468--- a/drivers/usb/atm/cxacru.c
43469+++ b/drivers/usb/atm/cxacru.c
43470@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
43471 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
43472 if (ret < 2)
43473 return -EINVAL;
43474- if (index < 0 || index > 0x7f)
43475+ if (index > 0x7f)
43476 return -EINVAL;
43477 pos += tmp;
43478
43479diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
43480index 35f10bf..6a38a0b 100644
43481--- a/drivers/usb/atm/usbatm.c
43482+++ b/drivers/usb/atm/usbatm.c
43483@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43484 if (printk_ratelimit())
43485 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
43486 __func__, vpi, vci);
43487- atomic_inc(&vcc->stats->rx_err);
43488+ atomic_inc_unchecked(&vcc->stats->rx_err);
43489 return;
43490 }
43491
43492@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43493 if (length > ATM_MAX_AAL5_PDU) {
43494 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
43495 __func__, length, vcc);
43496- atomic_inc(&vcc->stats->rx_err);
43497+ atomic_inc_unchecked(&vcc->stats->rx_err);
43498 goto out;
43499 }
43500
43501@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43502 if (sarb->len < pdu_length) {
43503 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
43504 __func__, pdu_length, sarb->len, vcc);
43505- atomic_inc(&vcc->stats->rx_err);
43506+ atomic_inc_unchecked(&vcc->stats->rx_err);
43507 goto out;
43508 }
43509
43510 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
43511 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
43512 __func__, vcc);
43513- atomic_inc(&vcc->stats->rx_err);
43514+ atomic_inc_unchecked(&vcc->stats->rx_err);
43515 goto out;
43516 }
43517
43518@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43519 if (printk_ratelimit())
43520 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
43521 __func__, length);
43522- atomic_inc(&vcc->stats->rx_drop);
43523+ atomic_inc_unchecked(&vcc->stats->rx_drop);
43524 goto out;
43525 }
43526
43527@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
43528
43529 vcc->push(vcc, skb);
43530
43531- atomic_inc(&vcc->stats->rx);
43532+ atomic_inc_unchecked(&vcc->stats->rx);
43533 out:
43534 skb_trim(sarb, 0);
43535 }
43536@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
43537 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
43538
43539 usbatm_pop(vcc, skb);
43540- atomic_inc(&vcc->stats->tx);
43541+ atomic_inc_unchecked(&vcc->stats->tx);
43542
43543 skb = skb_dequeue(&instance->sndqueue);
43544 }
43545@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
43546 if (!left--)
43547 return sprintf(page,
43548 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
43549- atomic_read(&atm_dev->stats.aal5.tx),
43550- atomic_read(&atm_dev->stats.aal5.tx_err),
43551- atomic_read(&atm_dev->stats.aal5.rx),
43552- atomic_read(&atm_dev->stats.aal5.rx_err),
43553- atomic_read(&atm_dev->stats.aal5.rx_drop));
43554+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
43555+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
43556+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
43557+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
43558+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
43559
43560 if (!left--) {
43561 if (instance->disconnected)
43562diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
43563index cbacea9..246cccd 100644
43564--- a/drivers/usb/core/devices.c
43565+++ b/drivers/usb/core/devices.c
43566@@ -126,7 +126,7 @@ static const char format_endpt[] =
43567 * time it gets called.
43568 */
43569 static struct device_connect_event {
43570- atomic_t count;
43571+ atomic_unchecked_t count;
43572 wait_queue_head_t wait;
43573 } device_event = {
43574 .count = ATOMIC_INIT(1),
43575@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
43576
43577 void usbfs_conn_disc_event(void)
43578 {
43579- atomic_add(2, &device_event.count);
43580+ atomic_add_unchecked(2, &device_event.count);
43581 wake_up(&device_event.wait);
43582 }
43583
43584@@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
43585
43586 poll_wait(file, &device_event.wait, wait);
43587
43588- event_count = atomic_read(&device_event.count);
43589+ event_count = atomic_read_unchecked(&device_event.count);
43590 if (file->f_version != event_count) {
43591 file->f_version = event_count;
43592 return POLLIN | POLLRDNORM;
43593diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
43594index 8e64adf..9a33a3c 100644
43595--- a/drivers/usb/core/hcd.c
43596+++ b/drivers/usb/core/hcd.c
43597@@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43598 */
43599 usb_get_urb(urb);
43600 atomic_inc(&urb->use_count);
43601- atomic_inc(&urb->dev->urbnum);
43602+ atomic_inc_unchecked(&urb->dev->urbnum);
43603 usbmon_urb_submit(&hcd->self, urb);
43604
43605 /* NOTE requirements on root-hub callers (usbfs and the hub
43606@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
43607 urb->hcpriv = NULL;
43608 INIT_LIST_HEAD(&urb->urb_list);
43609 atomic_dec(&urb->use_count);
43610- atomic_dec(&urb->dev->urbnum);
43611+ atomic_dec_unchecked(&urb->dev->urbnum);
43612 if (atomic_read(&urb->reject))
43613 wake_up(&usb_kill_urb_queue);
43614 usb_put_urb(urb);
43615diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
43616index 818e4a0..0fc9589 100644
43617--- a/drivers/usb/core/sysfs.c
43618+++ b/drivers/usb/core/sysfs.c
43619@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
43620 struct usb_device *udev;
43621
43622 udev = to_usb_device(dev);
43623- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
43624+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
43625 }
43626 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
43627
43628diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
43629index f81b925..78d22ec 100644
43630--- a/drivers/usb/core/usb.c
43631+++ b/drivers/usb/core/usb.c
43632@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
43633 set_dev_node(&dev->dev, dev_to_node(bus->controller));
43634 dev->state = USB_STATE_ATTACHED;
43635 dev->lpm_disable_count = 1;
43636- atomic_set(&dev->urbnum, 0);
43637+ atomic_set_unchecked(&dev->urbnum, 0);
43638
43639 INIT_LIST_HEAD(&dev->ep0.urb_list);
43640 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
43641diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
43642index 5e29dde..eca992f 100644
43643--- a/drivers/usb/early/ehci-dbgp.c
43644+++ b/drivers/usb/early/ehci-dbgp.c
43645@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
43646
43647 #ifdef CONFIG_KGDB
43648 static struct kgdb_io kgdbdbgp_io_ops;
43649-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
43650+static struct kgdb_io kgdbdbgp_io_ops_console;
43651+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
43652 #else
43653 #define dbgp_kgdb_mode (0)
43654 #endif
43655@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
43656 .write_char = kgdbdbgp_write_char,
43657 };
43658
43659+static struct kgdb_io kgdbdbgp_io_ops_console = {
43660+ .name = "kgdbdbgp",
43661+ .read_char = kgdbdbgp_read_char,
43662+ .write_char = kgdbdbgp_write_char,
43663+ .is_console = 1
43664+};
43665+
43666 static int kgdbdbgp_wait_time;
43667
43668 static int __init kgdbdbgp_parse_config(char *str)
43669@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
43670 ptr++;
43671 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
43672 }
43673- kgdb_register_io_module(&kgdbdbgp_io_ops);
43674- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
43675+ if (early_dbgp_console.index != -1)
43676+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
43677+ else
43678+ kgdb_register_io_module(&kgdbdbgp_io_ops);
43679
43680 return 0;
43681 }
43682diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
43683index 598dcc1..032dd4f 100644
43684--- a/drivers/usb/gadget/u_serial.c
43685+++ b/drivers/usb/gadget/u_serial.c
43686@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43687 spin_lock_irq(&port->port_lock);
43688
43689 /* already open? Great. */
43690- if (port->port.count) {
43691+ if (atomic_read(&port->port.count)) {
43692 status = 0;
43693- port->port.count++;
43694+ atomic_inc(&port->port.count);
43695
43696 /* currently opening/closing? wait ... */
43697 } else if (port->openclose) {
43698@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
43699 tty->driver_data = port;
43700 port->port.tty = tty;
43701
43702- port->port.count = 1;
43703+ atomic_set(&port->port.count, 1);
43704 port->openclose = false;
43705
43706 /* if connected, start the I/O stream */
43707@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43708
43709 spin_lock_irq(&port->port_lock);
43710
43711- if (port->port.count != 1) {
43712- if (port->port.count == 0)
43713+ if (atomic_read(&port->port.count) != 1) {
43714+ if (atomic_read(&port->port.count) == 0)
43715 WARN_ON(1);
43716 else
43717- --port->port.count;
43718+ atomic_dec(&port->port.count);
43719 goto exit;
43720 }
43721
43722@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
43723 * and sleep if necessary
43724 */
43725 port->openclose = true;
43726- port->port.count = 0;
43727+ atomic_set(&port->port.count, 0);
43728
43729 gser = port->port_usb;
43730 if (gser && gser->disconnect)
43731@@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
43732 int cond;
43733
43734 spin_lock_irq(&port->port_lock);
43735- cond = (port->port.count == 0) && !port->openclose;
43736+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
43737 spin_unlock_irq(&port->port_lock);
43738 return cond;
43739 }
43740@@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
43741 /* if it's already open, start I/O ... and notify the serial
43742 * protocol about open/close status (connect/disconnect).
43743 */
43744- if (port->port.count) {
43745+ if (atomic_read(&port->port.count)) {
43746 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
43747 gs_start_io(port);
43748 if (gser->connect)
43749@@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
43750
43751 port->port_usb = NULL;
43752 gser->ioport = NULL;
43753- if (port->port.count > 0 || port->openclose) {
43754+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
43755 wake_up_interruptible(&port->drain_wait);
43756 if (port->port.tty)
43757 tty_hangup(port->port.tty);
43758@@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
43759
43760 /* finally, free any unused/unusable I/O buffers */
43761 spin_lock_irqsave(&port->port_lock, flags);
43762- if (port->port.count == 0 && !port->openclose)
43763+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
43764 gs_buf_free(&port->port_write_buf);
43765 gs_free_requests(gser->out, &port->read_pool, NULL);
43766 gs_free_requests(gser->out, &port->read_queue, NULL);
43767diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
43768index 5f3bcd3..bfca43f 100644
43769--- a/drivers/usb/serial/console.c
43770+++ b/drivers/usb/serial/console.c
43771@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
43772
43773 info->port = port;
43774
43775- ++port->port.count;
43776+ atomic_inc(&port->port.count);
43777 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
43778 if (serial->type->set_termios) {
43779 /*
43780@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
43781 }
43782 /* Now that any required fake tty operations are completed restore
43783 * the tty port count */
43784- --port->port.count;
43785+ atomic_dec(&port->port.count);
43786 /* The console is special in terms of closing the device so
43787 * indicate this port is now acting as a system console. */
43788 port->port.console = 1;
43789@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
43790 free_tty:
43791 kfree(tty);
43792 reset_open_count:
43793- port->port.count = 0;
43794+ atomic_set(&port->port.count, 0);
43795 usb_autopm_put_interface(serial->interface);
43796 error_get_interface:
43797 usb_serial_put(serial);
43798diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
43799index 75f70f0..d467e1a 100644
43800--- a/drivers/usb/storage/usb.h
43801+++ b/drivers/usb/storage/usb.h
43802@@ -63,7 +63,7 @@ struct us_unusual_dev {
43803 __u8 useProtocol;
43804 __u8 useTransport;
43805 int (*initFunction)(struct us_data *);
43806-};
43807+} __do_const;
43808
43809
43810 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
43811diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
43812index d6bea3e..60b250e 100644
43813--- a/drivers/usb/wusbcore/wa-hc.h
43814+++ b/drivers/usb/wusbcore/wa-hc.h
43815@@ -192,7 +192,7 @@ struct wahc {
43816 struct list_head xfer_delayed_list;
43817 spinlock_t xfer_list_lock;
43818 struct work_struct xfer_work;
43819- atomic_t xfer_id_count;
43820+ atomic_unchecked_t xfer_id_count;
43821 };
43822
43823
43824@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
43825 INIT_LIST_HEAD(&wa->xfer_delayed_list);
43826 spin_lock_init(&wa->xfer_list_lock);
43827 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
43828- atomic_set(&wa->xfer_id_count, 1);
43829+ atomic_set_unchecked(&wa->xfer_id_count, 1);
43830 }
43831
43832 /**
43833diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
43834index 57c01ab..8a05959 100644
43835--- a/drivers/usb/wusbcore/wa-xfer.c
43836+++ b/drivers/usb/wusbcore/wa-xfer.c
43837@@ -296,7 +296,7 @@ out:
43838 */
43839 static void wa_xfer_id_init(struct wa_xfer *xfer)
43840 {
43841- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
43842+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
43843 }
43844
43845 /*
43846diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
43847index 8c55011..eed4ae1a 100644
43848--- a/drivers/video/aty/aty128fb.c
43849+++ b/drivers/video/aty/aty128fb.c
43850@@ -149,7 +149,7 @@ enum {
43851 };
43852
43853 /* Must match above enum */
43854-static char * const r128_family[] = {
43855+static const char * const r128_family[] = {
43856 "AGP",
43857 "PCI",
43858 "PRO AGP",
43859diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
43860index 4f27fdc..d3537e6 100644
43861--- a/drivers/video/aty/atyfb_base.c
43862+++ b/drivers/video/aty/atyfb_base.c
43863@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
43864 par->accel_flags = var->accel_flags; /* hack */
43865
43866 if (var->accel_flags) {
43867- info->fbops->fb_sync = atyfb_sync;
43868+ pax_open_kernel();
43869+ *(void **)&info->fbops->fb_sync = atyfb_sync;
43870+ pax_close_kernel();
43871 info->flags &= ~FBINFO_HWACCEL_DISABLED;
43872 } else {
43873- info->fbops->fb_sync = NULL;
43874+ pax_open_kernel();
43875+ *(void **)&info->fbops->fb_sync = NULL;
43876+ pax_close_kernel();
43877 info->flags |= FBINFO_HWACCEL_DISABLED;
43878 }
43879
43880diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
43881index 95ec042..e6affdd 100644
43882--- a/drivers/video/aty/mach64_cursor.c
43883+++ b/drivers/video/aty/mach64_cursor.c
43884@@ -7,6 +7,7 @@
43885 #include <linux/string.h>
43886
43887 #include <asm/io.h>
43888+#include <asm/pgtable.h>
43889
43890 #ifdef __sparc__
43891 #include <asm/fbio.h>
43892@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
43893 info->sprite.buf_align = 16; /* and 64 lines tall. */
43894 info->sprite.flags = FB_PIXMAP_IO;
43895
43896- info->fbops->fb_cursor = atyfb_cursor;
43897+ pax_open_kernel();
43898+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
43899+ pax_close_kernel();
43900
43901 return 0;
43902 }
43903diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
43904index 6c5ed6b..b727c88 100644
43905--- a/drivers/video/backlight/kb3886_bl.c
43906+++ b/drivers/video/backlight/kb3886_bl.c
43907@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
43908 static unsigned long kb3886bl_flags;
43909 #define KB3886BL_SUSPENDED 0x01
43910
43911-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
43912+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
43913 {
43914 .ident = "Sahara Touch-iT",
43915 .matches = {
43916diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
43917index 88cad6b..dd746c7 100644
43918--- a/drivers/video/fb_defio.c
43919+++ b/drivers/video/fb_defio.c
43920@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
43921
43922 BUG_ON(!fbdefio);
43923 mutex_init(&fbdefio->lock);
43924- info->fbops->fb_mmap = fb_deferred_io_mmap;
43925+ pax_open_kernel();
43926+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
43927+ pax_close_kernel();
43928 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
43929 INIT_LIST_HEAD(&fbdefio->pagelist);
43930 if (fbdefio->delay == 0) /* set a default of 1 s */
43931@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
43932 page->mapping = NULL;
43933 }
43934
43935- info->fbops->fb_mmap = NULL;
43936+ *(void **)&info->fbops->fb_mmap = NULL;
43937 mutex_destroy(&fbdefio->lock);
43938 }
43939 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
43940diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
43941index 5c3960d..15cf8fc 100644
43942--- a/drivers/video/fbcmap.c
43943+++ b/drivers/video/fbcmap.c
43944@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
43945 rc = -ENODEV;
43946 goto out;
43947 }
43948- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
43949- !info->fbops->fb_setcmap)) {
43950+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
43951 rc = -EINVAL;
43952 goto out1;
43953 }
43954diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
43955index dc61c12..e29796e 100644
43956--- a/drivers/video/fbmem.c
43957+++ b/drivers/video/fbmem.c
43958@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43959 image->dx += image->width + 8;
43960 }
43961 } else if (rotate == FB_ROTATE_UD) {
43962- for (x = 0; x < num && image->dx >= 0; x++) {
43963+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
43964 info->fbops->fb_imageblit(info, image);
43965 image->dx -= image->width + 8;
43966 }
43967@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
43968 image->dy += image->height + 8;
43969 }
43970 } else if (rotate == FB_ROTATE_CCW) {
43971- for (x = 0; x < num && image->dy >= 0; x++) {
43972+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
43973 info->fbops->fb_imageblit(info, image);
43974 image->dy -= image->height + 8;
43975 }
43976@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
43977 return -EFAULT;
43978 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
43979 return -EINVAL;
43980- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
43981+ if (con2fb.framebuffer >= FB_MAX)
43982 return -EINVAL;
43983 if (!registered_fb[con2fb.framebuffer])
43984 request_module("fb%d", con2fb.framebuffer);
43985diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
43986index 7672d2e..b56437f 100644
43987--- a/drivers/video/i810/i810_accel.c
43988+++ b/drivers/video/i810/i810_accel.c
43989@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
43990 }
43991 }
43992 printk("ringbuffer lockup!!!\n");
43993+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
43994 i810_report_error(mmio);
43995 par->dev_flags |= LOCKUP;
43996 info->pixmap.scan_align = 1;
43997diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
43998index 3c14e43..eafa544 100644
43999--- a/drivers/video/logo/logo_linux_clut224.ppm
44000+++ b/drivers/video/logo/logo_linux_clut224.ppm
44001@@ -1,1604 +1,1123 @@
44002 P3
44003-# Standard 224-color Linux logo
44004 80 80
44005 255
44006- 0 0 0 0 0 0 0 0 0 0 0 0
44007- 0 0 0 0 0 0 0 0 0 0 0 0
44008- 0 0 0 0 0 0 0 0 0 0 0 0
44009- 0 0 0 0 0 0 0 0 0 0 0 0
44010- 0 0 0 0 0 0 0 0 0 0 0 0
44011- 0 0 0 0 0 0 0 0 0 0 0 0
44012- 0 0 0 0 0 0 0 0 0 0 0 0
44013- 0 0 0 0 0 0 0 0 0 0 0 0
44014- 0 0 0 0 0 0 0 0 0 0 0 0
44015- 6 6 6 6 6 6 10 10 10 10 10 10
44016- 10 10 10 6 6 6 6 6 6 6 6 6
44017- 0 0 0 0 0 0 0 0 0 0 0 0
44018- 0 0 0 0 0 0 0 0 0 0 0 0
44019- 0 0 0 0 0 0 0 0 0 0 0 0
44020- 0 0 0 0 0 0 0 0 0 0 0 0
44021- 0 0 0 0 0 0 0 0 0 0 0 0
44022- 0 0 0 0 0 0 0 0 0 0 0 0
44023- 0 0 0 0 0 0 0 0 0 0 0 0
44024- 0 0 0 0 0 0 0 0 0 0 0 0
44025- 0 0 0 0 0 0 0 0 0 0 0 0
44026- 0 0 0 0 0 0 0 0 0 0 0 0
44027- 0 0 0 0 0 0 0 0 0 0 0 0
44028- 0 0 0 0 0 0 0 0 0 0 0 0
44029- 0 0 0 0 0 0 0 0 0 0 0 0
44030- 0 0 0 0 0 0 0 0 0 0 0 0
44031- 0 0 0 0 0 0 0 0 0 0 0 0
44032- 0 0 0 0 0 0 0 0 0 0 0 0
44033- 0 0 0 0 0 0 0 0 0 0 0 0
44034- 0 0 0 6 6 6 10 10 10 14 14 14
44035- 22 22 22 26 26 26 30 30 30 34 34 34
44036- 30 30 30 30 30 30 26 26 26 18 18 18
44037- 14 14 14 10 10 10 6 6 6 0 0 0
44038- 0 0 0 0 0 0 0 0 0 0 0 0
44039- 0 0 0 0 0 0 0 0 0 0 0 0
44040- 0 0 0 0 0 0 0 0 0 0 0 0
44041- 0 0 0 0 0 0 0 0 0 0 0 0
44042- 0 0 0 0 0 0 0 0 0 0 0 0
44043- 0 0 0 0 0 0 0 0 0 0 0 0
44044- 0 0 0 0 0 0 0 0 0 0 0 0
44045- 0 0 0 0 0 0 0 0 0 0 0 0
44046- 0 0 0 0 0 0 0 0 0 0 0 0
44047- 0 0 0 0 0 1 0 0 1 0 0 0
44048- 0 0 0 0 0 0 0 0 0 0 0 0
44049- 0 0 0 0 0 0 0 0 0 0 0 0
44050- 0 0 0 0 0 0 0 0 0 0 0 0
44051- 0 0 0 0 0 0 0 0 0 0 0 0
44052- 0 0 0 0 0 0 0 0 0 0 0 0
44053- 0 0 0 0 0 0 0 0 0 0 0 0
44054- 6 6 6 14 14 14 26 26 26 42 42 42
44055- 54 54 54 66 66 66 78 78 78 78 78 78
44056- 78 78 78 74 74 74 66 66 66 54 54 54
44057- 42 42 42 26 26 26 18 18 18 10 10 10
44058- 6 6 6 0 0 0 0 0 0 0 0 0
44059- 0 0 0 0 0 0 0 0 0 0 0 0
44060- 0 0 0 0 0 0 0 0 0 0 0 0
44061- 0 0 0 0 0 0 0 0 0 0 0 0
44062- 0 0 0 0 0 0 0 0 0 0 0 0
44063- 0 0 0 0 0 0 0 0 0 0 0 0
44064- 0 0 0 0 0 0 0 0 0 0 0 0
44065- 0 0 0 0 0 0 0 0 0 0 0 0
44066- 0 0 0 0 0 0 0 0 0 0 0 0
44067- 0 0 1 0 0 0 0 0 0 0 0 0
44068- 0 0 0 0 0 0 0 0 0 0 0 0
44069- 0 0 0 0 0 0 0 0 0 0 0 0
44070- 0 0 0 0 0 0 0 0 0 0 0 0
44071- 0 0 0 0 0 0 0 0 0 0 0 0
44072- 0 0 0 0 0 0 0 0 0 0 0 0
44073- 0 0 0 0 0 0 0 0 0 10 10 10
44074- 22 22 22 42 42 42 66 66 66 86 86 86
44075- 66 66 66 38 38 38 38 38 38 22 22 22
44076- 26 26 26 34 34 34 54 54 54 66 66 66
44077- 86 86 86 70 70 70 46 46 46 26 26 26
44078- 14 14 14 6 6 6 0 0 0 0 0 0
44079- 0 0 0 0 0 0 0 0 0 0 0 0
44080- 0 0 0 0 0 0 0 0 0 0 0 0
44081- 0 0 0 0 0 0 0 0 0 0 0 0
44082- 0 0 0 0 0 0 0 0 0 0 0 0
44083- 0 0 0 0 0 0 0 0 0 0 0 0
44084- 0 0 0 0 0 0 0 0 0 0 0 0
44085- 0 0 0 0 0 0 0 0 0 0 0 0
44086- 0 0 0 0 0 0 0 0 0 0 0 0
44087- 0 0 1 0 0 1 0 0 1 0 0 0
44088- 0 0 0 0 0 0 0 0 0 0 0 0
44089- 0 0 0 0 0 0 0 0 0 0 0 0
44090- 0 0 0 0 0 0 0 0 0 0 0 0
44091- 0 0 0 0 0 0 0 0 0 0 0 0
44092- 0 0 0 0 0 0 0 0 0 0 0 0
44093- 0 0 0 0 0 0 10 10 10 26 26 26
44094- 50 50 50 82 82 82 58 58 58 6 6 6
44095- 2 2 6 2 2 6 2 2 6 2 2 6
44096- 2 2 6 2 2 6 2 2 6 2 2 6
44097- 6 6 6 54 54 54 86 86 86 66 66 66
44098- 38 38 38 18 18 18 6 6 6 0 0 0
44099- 0 0 0 0 0 0 0 0 0 0 0 0
44100- 0 0 0 0 0 0 0 0 0 0 0 0
44101- 0 0 0 0 0 0 0 0 0 0 0 0
44102- 0 0 0 0 0 0 0 0 0 0 0 0
44103- 0 0 0 0 0 0 0 0 0 0 0 0
44104- 0 0 0 0 0 0 0 0 0 0 0 0
44105- 0 0 0 0 0 0 0 0 0 0 0 0
44106- 0 0 0 0 0 0 0 0 0 0 0 0
44107- 0 0 0 0 0 0 0 0 0 0 0 0
44108- 0 0 0 0 0 0 0 0 0 0 0 0
44109- 0 0 0 0 0 0 0 0 0 0 0 0
44110- 0 0 0 0 0 0 0 0 0 0 0 0
44111- 0 0 0 0 0 0 0 0 0 0 0 0
44112- 0 0 0 0 0 0 0 0 0 0 0 0
44113- 0 0 0 6 6 6 22 22 22 50 50 50
44114- 78 78 78 34 34 34 2 2 6 2 2 6
44115- 2 2 6 2 2 6 2 2 6 2 2 6
44116- 2 2 6 2 2 6 2 2 6 2 2 6
44117- 2 2 6 2 2 6 6 6 6 70 70 70
44118- 78 78 78 46 46 46 22 22 22 6 6 6
44119- 0 0 0 0 0 0 0 0 0 0 0 0
44120- 0 0 0 0 0 0 0 0 0 0 0 0
44121- 0 0 0 0 0 0 0 0 0 0 0 0
44122- 0 0 0 0 0 0 0 0 0 0 0 0
44123- 0 0 0 0 0 0 0 0 0 0 0 0
44124- 0 0 0 0 0 0 0 0 0 0 0 0
44125- 0 0 0 0 0 0 0 0 0 0 0 0
44126- 0 0 0 0 0 0 0 0 0 0 0 0
44127- 0 0 1 0 0 1 0 0 1 0 0 0
44128- 0 0 0 0 0 0 0 0 0 0 0 0
44129- 0 0 0 0 0 0 0 0 0 0 0 0
44130- 0 0 0 0 0 0 0 0 0 0 0 0
44131- 0 0 0 0 0 0 0 0 0 0 0 0
44132- 0 0 0 0 0 0 0 0 0 0 0 0
44133- 6 6 6 18 18 18 42 42 42 82 82 82
44134- 26 26 26 2 2 6 2 2 6 2 2 6
44135- 2 2 6 2 2 6 2 2 6 2 2 6
44136- 2 2 6 2 2 6 2 2 6 14 14 14
44137- 46 46 46 34 34 34 6 6 6 2 2 6
44138- 42 42 42 78 78 78 42 42 42 18 18 18
44139- 6 6 6 0 0 0 0 0 0 0 0 0
44140- 0 0 0 0 0 0 0 0 0 0 0 0
44141- 0 0 0 0 0 0 0 0 0 0 0 0
44142- 0 0 0 0 0 0 0 0 0 0 0 0
44143- 0 0 0 0 0 0 0 0 0 0 0 0
44144- 0 0 0 0 0 0 0 0 0 0 0 0
44145- 0 0 0 0 0 0 0 0 0 0 0 0
44146- 0 0 0 0 0 0 0 0 0 0 0 0
44147- 0 0 1 0 0 0 0 0 1 0 0 0
44148- 0 0 0 0 0 0 0 0 0 0 0 0
44149- 0 0 0 0 0 0 0 0 0 0 0 0
44150- 0 0 0 0 0 0 0 0 0 0 0 0
44151- 0 0 0 0 0 0 0 0 0 0 0 0
44152- 0 0 0 0 0 0 0 0 0 0 0 0
44153- 10 10 10 30 30 30 66 66 66 58 58 58
44154- 2 2 6 2 2 6 2 2 6 2 2 6
44155- 2 2 6 2 2 6 2 2 6 2 2 6
44156- 2 2 6 2 2 6 2 2 6 26 26 26
44157- 86 86 86 101 101 101 46 46 46 10 10 10
44158- 2 2 6 58 58 58 70 70 70 34 34 34
44159- 10 10 10 0 0 0 0 0 0 0 0 0
44160- 0 0 0 0 0 0 0 0 0 0 0 0
44161- 0 0 0 0 0 0 0 0 0 0 0 0
44162- 0 0 0 0 0 0 0 0 0 0 0 0
44163- 0 0 0 0 0 0 0 0 0 0 0 0
44164- 0 0 0 0 0 0 0 0 0 0 0 0
44165- 0 0 0 0 0 0 0 0 0 0 0 0
44166- 0 0 0 0 0 0 0 0 0 0 0 0
44167- 0 0 1 0 0 1 0 0 1 0 0 0
44168- 0 0 0 0 0 0 0 0 0 0 0 0
44169- 0 0 0 0 0 0 0 0 0 0 0 0
44170- 0 0 0 0 0 0 0 0 0 0 0 0
44171- 0 0 0 0 0 0 0 0 0 0 0 0
44172- 0 0 0 0 0 0 0 0 0 0 0 0
44173- 14 14 14 42 42 42 86 86 86 10 10 10
44174- 2 2 6 2 2 6 2 2 6 2 2 6
44175- 2 2 6 2 2 6 2 2 6 2 2 6
44176- 2 2 6 2 2 6 2 2 6 30 30 30
44177- 94 94 94 94 94 94 58 58 58 26 26 26
44178- 2 2 6 6 6 6 78 78 78 54 54 54
44179- 22 22 22 6 6 6 0 0 0 0 0 0
44180- 0 0 0 0 0 0 0 0 0 0 0 0
44181- 0 0 0 0 0 0 0 0 0 0 0 0
44182- 0 0 0 0 0 0 0 0 0 0 0 0
44183- 0 0 0 0 0 0 0 0 0 0 0 0
44184- 0 0 0 0 0 0 0 0 0 0 0 0
44185- 0 0 0 0 0 0 0 0 0 0 0 0
44186- 0 0 0 0 0 0 0 0 0 0 0 0
44187- 0 0 0 0 0 0 0 0 0 0 0 0
44188- 0 0 0 0 0 0 0 0 0 0 0 0
44189- 0 0 0 0 0 0 0 0 0 0 0 0
44190- 0 0 0 0 0 0 0 0 0 0 0 0
44191- 0 0 0 0 0 0 0 0 0 0 0 0
44192- 0 0 0 0 0 0 0 0 0 6 6 6
44193- 22 22 22 62 62 62 62 62 62 2 2 6
44194- 2 2 6 2 2 6 2 2 6 2 2 6
44195- 2 2 6 2 2 6 2 2 6 2 2 6
44196- 2 2 6 2 2 6 2 2 6 26 26 26
44197- 54 54 54 38 38 38 18 18 18 10 10 10
44198- 2 2 6 2 2 6 34 34 34 82 82 82
44199- 38 38 38 14 14 14 0 0 0 0 0 0
44200- 0 0 0 0 0 0 0 0 0 0 0 0
44201- 0 0 0 0 0 0 0 0 0 0 0 0
44202- 0 0 0 0 0 0 0 0 0 0 0 0
44203- 0 0 0 0 0 0 0 0 0 0 0 0
44204- 0 0 0 0 0 0 0 0 0 0 0 0
44205- 0 0 0 0 0 0 0 0 0 0 0 0
44206- 0 0 0 0 0 0 0 0 0 0 0 0
44207- 0 0 0 0 0 1 0 0 1 0 0 0
44208- 0 0 0 0 0 0 0 0 0 0 0 0
44209- 0 0 0 0 0 0 0 0 0 0 0 0
44210- 0 0 0 0 0 0 0 0 0 0 0 0
44211- 0 0 0 0 0 0 0 0 0 0 0 0
44212- 0 0 0 0 0 0 0 0 0 6 6 6
44213- 30 30 30 78 78 78 30 30 30 2 2 6
44214- 2 2 6 2 2 6 2 2 6 2 2 6
44215- 2 2 6 2 2 6 2 2 6 2 2 6
44216- 2 2 6 2 2 6 2 2 6 10 10 10
44217- 10 10 10 2 2 6 2 2 6 2 2 6
44218- 2 2 6 2 2 6 2 2 6 78 78 78
44219- 50 50 50 18 18 18 6 6 6 0 0 0
44220- 0 0 0 0 0 0 0 0 0 0 0 0
44221- 0 0 0 0 0 0 0 0 0 0 0 0
44222- 0 0 0 0 0 0 0 0 0 0 0 0
44223- 0 0 0 0 0 0 0 0 0 0 0 0
44224- 0 0 0 0 0 0 0 0 0 0 0 0
44225- 0 0 0 0 0 0 0 0 0 0 0 0
44226- 0 0 0 0 0 0 0 0 0 0 0 0
44227- 0 0 1 0 0 0 0 0 0 0 0 0
44228- 0 0 0 0 0 0 0 0 0 0 0 0
44229- 0 0 0 0 0 0 0 0 0 0 0 0
44230- 0 0 0 0 0 0 0 0 0 0 0 0
44231- 0 0 0 0 0 0 0 0 0 0 0 0
44232- 0 0 0 0 0 0 0 0 0 10 10 10
44233- 38 38 38 86 86 86 14 14 14 2 2 6
44234- 2 2 6 2 2 6 2 2 6 2 2 6
44235- 2 2 6 2 2 6 2 2 6 2 2 6
44236- 2 2 6 2 2 6 2 2 6 2 2 6
44237- 2 2 6 2 2 6 2 2 6 2 2 6
44238- 2 2 6 2 2 6 2 2 6 54 54 54
44239- 66 66 66 26 26 26 6 6 6 0 0 0
44240- 0 0 0 0 0 0 0 0 0 0 0 0
44241- 0 0 0 0 0 0 0 0 0 0 0 0
44242- 0 0 0 0 0 0 0 0 0 0 0 0
44243- 0 0 0 0 0 0 0 0 0 0 0 0
44244- 0 0 0 0 0 0 0 0 0 0 0 0
44245- 0 0 0 0 0 0 0 0 0 0 0 0
44246- 0 0 0 0 0 0 0 0 0 0 0 0
44247- 0 0 0 0 0 1 0 0 1 0 0 0
44248- 0 0 0 0 0 0 0 0 0 0 0 0
44249- 0 0 0 0 0 0 0 0 0 0 0 0
44250- 0 0 0 0 0 0 0 0 0 0 0 0
44251- 0 0 0 0 0 0 0 0 0 0 0 0
44252- 0 0 0 0 0 0 0 0 0 14 14 14
44253- 42 42 42 82 82 82 2 2 6 2 2 6
44254- 2 2 6 6 6 6 10 10 10 2 2 6
44255- 2 2 6 2 2 6 2 2 6 2 2 6
44256- 2 2 6 2 2 6 2 2 6 6 6 6
44257- 14 14 14 10 10 10 2 2 6 2 2 6
44258- 2 2 6 2 2 6 2 2 6 18 18 18
44259- 82 82 82 34 34 34 10 10 10 0 0 0
44260- 0 0 0 0 0 0 0 0 0 0 0 0
44261- 0 0 0 0 0 0 0 0 0 0 0 0
44262- 0 0 0 0 0 0 0 0 0 0 0 0
44263- 0 0 0 0 0 0 0 0 0 0 0 0
44264- 0 0 0 0 0 0 0 0 0 0 0 0
44265- 0 0 0 0 0 0 0 0 0 0 0 0
44266- 0 0 0 0 0 0 0 0 0 0 0 0
44267- 0 0 1 0 0 0 0 0 0 0 0 0
44268- 0 0 0 0 0 0 0 0 0 0 0 0
44269- 0 0 0 0 0 0 0 0 0 0 0 0
44270- 0 0 0 0 0 0 0 0 0 0 0 0
44271- 0 0 0 0 0 0 0 0 0 0 0 0
44272- 0 0 0 0 0 0 0 0 0 14 14 14
44273- 46 46 46 86 86 86 2 2 6 2 2 6
44274- 6 6 6 6 6 6 22 22 22 34 34 34
44275- 6 6 6 2 2 6 2 2 6 2 2 6
44276- 2 2 6 2 2 6 18 18 18 34 34 34
44277- 10 10 10 50 50 50 22 22 22 2 2 6
44278- 2 2 6 2 2 6 2 2 6 10 10 10
44279- 86 86 86 42 42 42 14 14 14 0 0 0
44280- 0 0 0 0 0 0 0 0 0 0 0 0
44281- 0 0 0 0 0 0 0 0 0 0 0 0
44282- 0 0 0 0 0 0 0 0 0 0 0 0
44283- 0 0 0 0 0 0 0 0 0 0 0 0
44284- 0 0 0 0 0 0 0 0 0 0 0 0
44285- 0 0 0 0 0 0 0 0 0 0 0 0
44286- 0 0 0 0 0 0 0 0 0 0 0 0
44287- 0 0 1 0 0 1 0 0 1 0 0 0
44288- 0 0 0 0 0 0 0 0 0 0 0 0
44289- 0 0 0 0 0 0 0 0 0 0 0 0
44290- 0 0 0 0 0 0 0 0 0 0 0 0
44291- 0 0 0 0 0 0 0 0 0 0 0 0
44292- 0 0 0 0 0 0 0 0 0 14 14 14
44293- 46 46 46 86 86 86 2 2 6 2 2 6
44294- 38 38 38 116 116 116 94 94 94 22 22 22
44295- 22 22 22 2 2 6 2 2 6 2 2 6
44296- 14 14 14 86 86 86 138 138 138 162 162 162
44297-154 154 154 38 38 38 26 26 26 6 6 6
44298- 2 2 6 2 2 6 2 2 6 2 2 6
44299- 86 86 86 46 46 46 14 14 14 0 0 0
44300- 0 0 0 0 0 0 0 0 0 0 0 0
44301- 0 0 0 0 0 0 0 0 0 0 0 0
44302- 0 0 0 0 0 0 0 0 0 0 0 0
44303- 0 0 0 0 0 0 0 0 0 0 0 0
44304- 0 0 0 0 0 0 0 0 0 0 0 0
44305- 0 0 0 0 0 0 0 0 0 0 0 0
44306- 0 0 0 0 0 0 0 0 0 0 0 0
44307- 0 0 0 0 0 0 0 0 0 0 0 0
44308- 0 0 0 0 0 0 0 0 0 0 0 0
44309- 0 0 0 0 0 0 0 0 0 0 0 0
44310- 0 0 0 0 0 0 0 0 0 0 0 0
44311- 0 0 0 0 0 0 0 0 0 0 0 0
44312- 0 0 0 0 0 0 0 0 0 14 14 14
44313- 46 46 46 86 86 86 2 2 6 14 14 14
44314-134 134 134 198 198 198 195 195 195 116 116 116
44315- 10 10 10 2 2 6 2 2 6 6 6 6
44316-101 98 89 187 187 187 210 210 210 218 218 218
44317-214 214 214 134 134 134 14 14 14 6 6 6
44318- 2 2 6 2 2 6 2 2 6 2 2 6
44319- 86 86 86 50 50 50 18 18 18 6 6 6
44320- 0 0 0 0 0 0 0 0 0 0 0 0
44321- 0 0 0 0 0 0 0 0 0 0 0 0
44322- 0 0 0 0 0 0 0 0 0 0 0 0
44323- 0 0 0 0 0 0 0 0 0 0 0 0
44324- 0 0 0 0 0 0 0 0 0 0 0 0
44325- 0 0 0 0 0 0 0 0 0 0 0 0
44326- 0 0 0 0 0 0 0 0 1 0 0 0
44327- 0 0 1 0 0 1 0 0 1 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 14 14 14
44333- 46 46 46 86 86 86 2 2 6 54 54 54
44334-218 218 218 195 195 195 226 226 226 246 246 246
44335- 58 58 58 2 2 6 2 2 6 30 30 30
44336-210 210 210 253 253 253 174 174 174 123 123 123
44337-221 221 221 234 234 234 74 74 74 2 2 6
44338- 2 2 6 2 2 6 2 2 6 2 2 6
44339- 70 70 70 58 58 58 22 22 22 6 6 6
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 14 14 14
44353- 46 46 46 82 82 82 2 2 6 106 106 106
44354-170 170 170 26 26 26 86 86 86 226 226 226
44355-123 123 123 10 10 10 14 14 14 46 46 46
44356-231 231 231 190 190 190 6 6 6 70 70 70
44357- 90 90 90 238 238 238 158 158 158 2 2 6
44358- 2 2 6 2 2 6 2 2 6 2 2 6
44359- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
44367- 0 0 1 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 14 14 14
44373- 42 42 42 86 86 86 6 6 6 116 116 116
44374-106 106 106 6 6 6 70 70 70 149 149 149
44375-128 128 128 18 18 18 38 38 38 54 54 54
44376-221 221 221 106 106 106 2 2 6 14 14 14
44377- 46 46 46 190 190 190 198 198 198 2 2 6
44378- 2 2 6 2 2 6 2 2 6 2 2 6
44379- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
44387- 0 0 1 0 0 0 0 0 1 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 14 14 14
44393- 42 42 42 94 94 94 14 14 14 101 101 101
44394-128 128 128 2 2 6 18 18 18 116 116 116
44395-118 98 46 121 92 8 121 92 8 98 78 10
44396-162 162 162 106 106 106 2 2 6 2 2 6
44397- 2 2 6 195 195 195 195 195 195 6 6 6
44398- 2 2 6 2 2 6 2 2 6 2 2 6
44399- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
44407- 0 0 1 0 0 0 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 10 10 10
44413- 38 38 38 90 90 90 14 14 14 58 58 58
44414-210 210 210 26 26 26 54 38 6 154 114 10
44415-226 170 11 236 186 11 225 175 15 184 144 12
44416-215 174 15 175 146 61 37 26 9 2 2 6
44417- 70 70 70 246 246 246 138 138 138 2 2 6
44418- 2 2 6 2 2 6 2 2 6 2 2 6
44419- 70 70 70 66 66 66 26 26 26 6 6 6
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 10 10 10
44433- 38 38 38 86 86 86 14 14 14 10 10 10
44434-195 195 195 188 164 115 192 133 9 225 175 15
44435-239 182 13 234 190 10 232 195 16 232 200 30
44436-245 207 45 241 208 19 232 195 16 184 144 12
44437-218 194 134 211 206 186 42 42 42 2 2 6
44438- 2 2 6 2 2 6 2 2 6 2 2 6
44439- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0 0 0 0 0 0 0 0
44448- 0 0 0 0 0 0 0 0 0 0 0 0
44449- 0 0 0 0 0 0 0 0 0 0 0 0
44450- 0 0 0 0 0 0 0 0 0 0 0 0
44451- 0 0 0 0 0 0 0 0 0 0 0 0
44452- 0 0 0 0 0 0 0 0 0 10 10 10
44453- 34 34 34 86 86 86 14 14 14 2 2 6
44454-121 87 25 192 133 9 219 162 10 239 182 13
44455-236 186 11 232 195 16 241 208 19 244 214 54
44456-246 218 60 246 218 38 246 215 20 241 208 19
44457-241 208 19 226 184 13 121 87 25 2 2 6
44458- 2 2 6 2 2 6 2 2 6 2 2 6
44459- 50 50 50 82 82 82 34 34 34 10 10 10
44460- 0 0 0 0 0 0 0 0 0 0 0 0
44461- 0 0 0 0 0 0 0 0 0 0 0 0
44462- 0 0 0 0 0 0 0 0 0 0 0 0
44463- 0 0 0 0 0 0 0 0 0 0 0 0
44464- 0 0 0 0 0 0 0 0 0 0 0 0
44465- 0 0 0 0 0 0 0 0 0 0 0 0
44466- 0 0 0 0 0 0 0 0 0 0 0 0
44467- 0 0 0 0 0 0 0 0 0 0 0 0
44468- 0 0 0 0 0 0 0 0 0 0 0 0
44469- 0 0 0 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 10 10 10
44473- 34 34 34 82 82 82 30 30 30 61 42 6
44474-180 123 7 206 145 10 230 174 11 239 182 13
44475-234 190 10 238 202 15 241 208 19 246 218 74
44476-246 218 38 246 215 20 246 215 20 246 215 20
44477-226 184 13 215 174 15 184 144 12 6 6 6
44478- 2 2 6 2 2 6 2 2 6 2 2 6
44479- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0 0 0 0 0
44488- 0 0 0 0 0 0 0 0 0 0 0 0
44489- 0 0 0 0 0 0 0 0 0 0 0 0
44490- 0 0 0 0 0 0 0 0 0 0 0 0
44491- 0 0 0 0 0 0 0 0 0 0 0 0
44492- 0 0 0 0 0 0 0 0 0 10 10 10
44493- 30 30 30 78 78 78 50 50 50 104 69 6
44494-192 133 9 216 158 10 236 178 12 236 186 11
44495-232 195 16 241 208 19 244 214 54 245 215 43
44496-246 215 20 246 215 20 241 208 19 198 155 10
44497-200 144 11 216 158 10 156 118 10 2 2 6
44498- 2 2 6 2 2 6 2 2 6 2 2 6
44499- 6 6 6 90 90 90 54 54 54 18 18 18
44500- 6 6 6 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 10 10 10
44513- 30 30 30 78 78 78 46 46 46 22 22 22
44514-137 92 6 210 162 10 239 182 13 238 190 10
44515-238 202 15 241 208 19 246 215 20 246 215 20
44516-241 208 19 203 166 17 185 133 11 210 150 10
44517-216 158 10 210 150 10 102 78 10 2 2 6
44518- 6 6 6 54 54 54 14 14 14 2 2 6
44519- 2 2 6 62 62 62 74 74 74 30 30 30
44520- 10 10 10 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 0 0 0 0 0 0 0
44528- 0 0 0 0 0 0 0 0 0 0 0 0
44529- 0 0 0 0 0 0 0 0 0 0 0 0
44530- 0 0 0 0 0 0 0 0 0 0 0 0
44531- 0 0 0 0 0 0 0 0 0 0 0 0
44532- 0 0 0 0 0 0 0 0 0 10 10 10
44533- 34 34 34 78 78 78 50 50 50 6 6 6
44534- 94 70 30 139 102 15 190 146 13 226 184 13
44535-232 200 30 232 195 16 215 174 15 190 146 13
44536-168 122 10 192 133 9 210 150 10 213 154 11
44537-202 150 34 182 157 106 101 98 89 2 2 6
44538- 2 2 6 78 78 78 116 116 116 58 58 58
44539- 2 2 6 22 22 22 90 90 90 46 46 46
44540- 18 18 18 6 6 6 0 0 0 0 0 0
44541- 0 0 0 0 0 0 0 0 0 0 0 0
44542- 0 0 0 0 0 0 0 0 0 0 0 0
44543- 0 0 0 0 0 0 0 0 0 0 0 0
44544- 0 0 0 0 0 0 0 0 0 0 0 0
44545- 0 0 0 0 0 0 0 0 0 0 0 0
44546- 0 0 0 0 0 0 0 0 0 0 0 0
44547- 0 0 0 0 0 0 0 0 0 0 0 0
44548- 0 0 0 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 50 50 50 6 6 6
44554-128 128 128 174 154 114 156 107 11 168 122 10
44555-198 155 10 184 144 12 197 138 11 200 144 11
44556-206 145 10 206 145 10 197 138 11 188 164 115
44557-195 195 195 198 198 198 174 174 174 14 14 14
44558- 2 2 6 22 22 22 116 116 116 116 116 116
44559- 22 22 22 2 2 6 74 74 74 70 70 70
44560- 30 30 30 10 10 10 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 0 0 0 0 0 0 0
44568- 0 0 0 0 0 0 0 0 0 0 0 0
44569- 0 0 0 0 0 0 0 0 0 0 0 0
44570- 0 0 0 0 0 0 0 0 0 0 0 0
44571- 0 0 0 0 0 0 0 0 0 0 0 0
44572- 0 0 0 0 0 0 6 6 6 18 18 18
44573- 50 50 50 101 101 101 26 26 26 10 10 10
44574-138 138 138 190 190 190 174 154 114 156 107 11
44575-197 138 11 200 144 11 197 138 11 192 133 9
44576-180 123 7 190 142 34 190 178 144 187 187 187
44577-202 202 202 221 221 221 214 214 214 66 66 66
44578- 2 2 6 2 2 6 50 50 50 62 62 62
44579- 6 6 6 2 2 6 10 10 10 90 90 90
44580- 50 50 50 18 18 18 6 6 6 0 0 0
44581- 0 0 0 0 0 0 0 0 0 0 0 0
44582- 0 0 0 0 0 0 0 0 0 0 0 0
44583- 0 0 0 0 0 0 0 0 0 0 0 0
44584- 0 0 0 0 0 0 0 0 0 0 0 0
44585- 0 0 0 0 0 0 0 0 0 0 0 0
44586- 0 0 0 0 0 0 0 0 0 0 0 0
44587- 0 0 0 0 0 0 0 0 0 0 0 0
44588- 0 0 0 0 0 0 0 0 0 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 10 10 10 34 34 34
44593- 74 74 74 74 74 74 2 2 6 6 6 6
44594-144 144 144 198 198 198 190 190 190 178 166 146
44595-154 121 60 156 107 11 156 107 11 168 124 44
44596-174 154 114 187 187 187 190 190 190 210 210 210
44597-246 246 246 253 253 253 253 253 253 182 182 182
44598- 6 6 6 2 2 6 2 2 6 2 2 6
44599- 2 2 6 2 2 6 2 2 6 62 62 62
44600- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0 0
44608- 0 0 0 0 0 0 0 0 0 0 0 0
44609- 0 0 0 0 0 0 0 0 0 0 0 0
44610- 0 0 0 0 0 0 0 0 0 0 0 0
44611- 0 0 0 0 0 0 0 0 0 0 0 0
44612- 0 0 0 10 10 10 22 22 22 54 54 54
44613- 94 94 94 18 18 18 2 2 6 46 46 46
44614-234 234 234 221 221 221 190 190 190 190 190 190
44615-190 190 190 187 187 187 187 187 187 190 190 190
44616-190 190 190 195 195 195 214 214 214 242 242 242
44617-253 253 253 253 253 253 253 253 253 253 253 253
44618- 82 82 82 2 2 6 2 2 6 2 2 6
44619- 2 2 6 2 2 6 2 2 6 14 14 14
44620- 86 86 86 54 54 54 22 22 22 6 6 6
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- 6 6 6 18 18 18 46 46 46 90 90 90
44633- 46 46 46 18 18 18 6 6 6 182 182 182
44634-253 253 253 246 246 246 206 206 206 190 190 190
44635-190 190 190 190 190 190 190 190 190 190 190 190
44636-206 206 206 231 231 231 250 250 250 253 253 253
44637-253 253 253 253 253 253 253 253 253 253 253 253
44638-202 202 202 14 14 14 2 2 6 2 2 6
44639- 2 2 6 2 2 6 2 2 6 2 2 6
44640- 42 42 42 86 86 86 42 42 42 18 18 18
44641- 6 6 6 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 0 0 0 0
44647- 0 0 0 0 0 0 0 0 0 0 0 0
44648- 0 0 0 0 0 0 0 0 0 0 0 0
44649- 0 0 0 0 0 0 0 0 0 0 0 0
44650- 0 0 0 0 0 0 0 0 0 0 0 0
44651- 0 0 0 0 0 0 0 0 0 6 6 6
44652- 14 14 14 38 38 38 74 74 74 66 66 66
44653- 2 2 6 6 6 6 90 90 90 250 250 250
44654-253 253 253 253 253 253 238 238 238 198 198 198
44655-190 190 190 190 190 190 195 195 195 221 221 221
44656-246 246 246 253 253 253 253 253 253 253 253 253
44657-253 253 253 253 253 253 253 253 253 253 253 253
44658-253 253 253 82 82 82 2 2 6 2 2 6
44659- 2 2 6 2 2 6 2 2 6 2 2 6
44660- 2 2 6 78 78 78 70 70 70 34 34 34
44661- 14 14 14 6 6 6 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 14 14 14
44672- 34 34 34 66 66 66 78 78 78 6 6 6
44673- 2 2 6 18 18 18 218 218 218 253 253 253
44674-253 253 253 253 253 253 253 253 253 246 246 246
44675-226 226 226 231 231 231 246 246 246 253 253 253
44676-253 253 253 253 253 253 253 253 253 253 253 253
44677-253 253 253 253 253 253 253 253 253 253 253 253
44678-253 253 253 178 178 178 2 2 6 2 2 6
44679- 2 2 6 2 2 6 2 2 6 2 2 6
44680- 2 2 6 18 18 18 90 90 90 62 62 62
44681- 30 30 30 10 10 10 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 0 0 0 0
44687- 0 0 0 0 0 0 0 0 0 0 0 0
44688- 0 0 0 0 0 0 0 0 0 0 0 0
44689- 0 0 0 0 0 0 0 0 0 0 0 0
44690- 0 0 0 0 0 0 0 0 0 0 0 0
44691- 0 0 0 0 0 0 10 10 10 26 26 26
44692- 58 58 58 90 90 90 18 18 18 2 2 6
44693- 2 2 6 110 110 110 253 253 253 253 253 253
44694-253 253 253 253 253 253 253 253 253 253 253 253
44695-250 250 250 253 253 253 253 253 253 253 253 253
44696-253 253 253 253 253 253 253 253 253 253 253 253
44697-253 253 253 253 253 253 253 253 253 253 253 253
44698-253 253 253 231 231 231 18 18 18 2 2 6
44699- 2 2 6 2 2 6 2 2 6 2 2 6
44700- 2 2 6 2 2 6 18 18 18 94 94 94
44701- 54 54 54 26 26 26 10 10 10 0 0 0
44702- 0 0 0 0 0 0 0 0 0 0 0 0
44703- 0 0 0 0 0 0 0 0 0 0 0 0
44704- 0 0 0 0 0 0 0 0 0 0 0 0
44705- 0 0 0 0 0 0 0 0 0 0 0 0
44706- 0 0 0 0 0 0 0 0 0 0 0 0
44707- 0 0 0 0 0 0 0 0 0 0 0 0
44708- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
44712- 90 90 90 26 26 26 2 2 6 2 2 6
44713- 14 14 14 195 195 195 250 250 250 253 253 253
44714-253 253 253 253 253 253 253 253 253 253 253 253
44715-253 253 253 253 253 253 253 253 253 253 253 253
44716-253 253 253 253 253 253 253 253 253 253 253 253
44717-253 253 253 253 253 253 253 253 253 253 253 253
44718-250 250 250 242 242 242 54 54 54 2 2 6
44719- 2 2 6 2 2 6 2 2 6 2 2 6
44720- 2 2 6 2 2 6 2 2 6 38 38 38
44721- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0
44727- 0 0 0 0 0 0 0 0 0 0 0 0
44728- 0 0 0 0 0 0 0 0 0 0 0 0
44729- 0 0 0 0 0 0 0 0 0 0 0 0
44730- 0 0 0 0 0 0 0 0 0 0 0 0
44731- 6 6 6 14 14 14 38 38 38 82 82 82
44732- 34 34 34 2 2 6 2 2 6 2 2 6
44733- 42 42 42 195 195 195 246 246 246 253 253 253
44734-253 253 253 253 253 253 253 253 253 250 250 250
44735-242 242 242 242 242 242 250 250 250 253 253 253
44736-253 253 253 253 253 253 253 253 253 253 253 253
44737-253 253 253 250 250 250 246 246 246 238 238 238
44738-226 226 226 231 231 231 101 101 101 6 6 6
44739- 2 2 6 2 2 6 2 2 6 2 2 6
44740- 2 2 6 2 2 6 2 2 6 2 2 6
44741- 38 38 38 82 82 82 42 42 42 14 14 14
44742- 6 6 6 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- 10 10 10 26 26 26 62 62 62 66 66 66
44752- 2 2 6 2 2 6 2 2 6 6 6 6
44753- 70 70 70 170 170 170 206 206 206 234 234 234
44754-246 246 246 250 250 250 250 250 250 238 238 238
44755-226 226 226 231 231 231 238 238 238 250 250 250
44756-250 250 250 250 250 250 246 246 246 231 231 231
44757-214 214 214 206 206 206 202 202 202 202 202 202
44758-198 198 198 202 202 202 182 182 182 18 18 18
44759- 2 2 6 2 2 6 2 2 6 2 2 6
44760- 2 2 6 2 2 6 2 2 6 2 2 6
44761- 2 2 6 62 62 62 66 66 66 30 30 30
44762- 10 10 10 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- 14 14 14 42 42 42 82 82 82 18 18 18
44772- 2 2 6 2 2 6 2 2 6 10 10 10
44773- 94 94 94 182 182 182 218 218 218 242 242 242
44774-250 250 250 253 253 253 253 253 253 250 250 250
44775-234 234 234 253 253 253 253 253 253 253 253 253
44776-253 253 253 253 253 253 253 253 253 246 246 246
44777-238 238 238 226 226 226 210 210 210 202 202 202
44778-195 195 195 195 195 195 210 210 210 158 158 158
44779- 6 6 6 14 14 14 50 50 50 14 14 14
44780- 2 2 6 2 2 6 2 2 6 2 2 6
44781- 2 2 6 6 6 6 86 86 86 46 46 46
44782- 18 18 18 6 6 6 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 6 6 6
44791- 22 22 22 54 54 54 70 70 70 2 2 6
44792- 2 2 6 10 10 10 2 2 6 22 22 22
44793-166 166 166 231 231 231 250 250 250 253 253 253
44794-253 253 253 253 253 253 253 253 253 250 250 250
44795-242 242 242 253 253 253 253 253 253 253 253 253
44796-253 253 253 253 253 253 253 253 253 253 253 253
44797-253 253 253 253 253 253 253 253 253 246 246 246
44798-231 231 231 206 206 206 198 198 198 226 226 226
44799- 94 94 94 2 2 6 6 6 6 38 38 38
44800- 30 30 30 2 2 6 2 2 6 2 2 6
44801- 2 2 6 2 2 6 62 62 62 66 66 66
44802- 26 26 26 10 10 10 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 10 10 10
44811- 30 30 30 74 74 74 50 50 50 2 2 6
44812- 26 26 26 26 26 26 2 2 6 106 106 106
44813-238 238 238 253 253 253 253 253 253 253 253 253
44814-253 253 253 253 253 253 253 253 253 253 253 253
44815-253 253 253 253 253 253 253 253 253 253 253 253
44816-253 253 253 253 253 253 253 253 253 253 253 253
44817-253 253 253 253 253 253 253 253 253 253 253 253
44818-253 253 253 246 246 246 218 218 218 202 202 202
44819-210 210 210 14 14 14 2 2 6 2 2 6
44820- 30 30 30 22 22 22 2 2 6 2 2 6
44821- 2 2 6 2 2 6 18 18 18 86 86 86
44822- 42 42 42 14 14 14 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 14 14 14
44831- 42 42 42 90 90 90 22 22 22 2 2 6
44832- 42 42 42 2 2 6 18 18 18 218 218 218
44833-253 253 253 253 253 253 253 253 253 253 253 253
44834-253 253 253 253 253 253 253 253 253 253 253 253
44835-253 253 253 253 253 253 253 253 253 253 253 253
44836-253 253 253 253 253 253 253 253 253 253 253 253
44837-253 253 253 253 253 253 253 253 253 253 253 253
44838-253 253 253 253 253 253 250 250 250 221 221 221
44839-218 218 218 101 101 101 2 2 6 14 14 14
44840- 18 18 18 38 38 38 10 10 10 2 2 6
44841- 2 2 6 2 2 6 2 2 6 78 78 78
44842- 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
44851- 54 54 54 82 82 82 2 2 6 26 26 26
44852- 22 22 22 2 2 6 123 123 123 253 253 253
44853-253 253 253 253 253 253 253 253 253 253 253 253
44854-253 253 253 253 253 253 253 253 253 253 253 253
44855-253 253 253 253 253 253 253 253 253 253 253 253
44856-253 253 253 253 253 253 253 253 253 253 253 253
44857-253 253 253 253 253 253 253 253 253 253 253 253
44858-253 253 253 253 253 253 253 253 253 250 250 250
44859-238 238 238 198 198 198 6 6 6 38 38 38
44860- 58 58 58 26 26 26 38 38 38 2 2 6
44861- 2 2 6 2 2 6 2 2 6 46 46 46
44862- 78 78 78 30 30 30 10 10 10 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 10 10 10 30 30 30
44871- 74 74 74 58 58 58 2 2 6 42 42 42
44872- 2 2 6 22 22 22 231 231 231 253 253 253
44873-253 253 253 253 253 253 253 253 253 253 253 253
44874-253 253 253 253 253 253 253 253 253 250 250 250
44875-253 253 253 253 253 253 253 253 253 253 253 253
44876-253 253 253 253 253 253 253 253 253 253 253 253
44877-253 253 253 253 253 253 253 253 253 253 253 253
44878-253 253 253 253 253 253 253 253 253 253 253 253
44879-253 253 253 246 246 246 46 46 46 38 38 38
44880- 42 42 42 14 14 14 38 38 38 14 14 14
44881- 2 2 6 2 2 6 2 2 6 6 6 6
44882- 86 86 86 46 46 46 14 14 14 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 6 6 6 14 14 14 42 42 42
44891- 90 90 90 18 18 18 18 18 18 26 26 26
44892- 2 2 6 116 116 116 253 253 253 253 253 253
44893-253 253 253 253 253 253 253 253 253 253 253 253
44894-253 253 253 253 253 253 250 250 250 238 238 238
44895-253 253 253 253 253 253 253 253 253 253 253 253
44896-253 253 253 253 253 253 253 253 253 253 253 253
44897-253 253 253 253 253 253 253 253 253 253 253 253
44898-253 253 253 253 253 253 253 253 253 253 253 253
44899-253 253 253 253 253 253 94 94 94 6 6 6
44900- 2 2 6 2 2 6 10 10 10 34 34 34
44901- 2 2 6 2 2 6 2 2 6 2 2 6
44902- 74 74 74 58 58 58 22 22 22 6 6 6
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 10 10 10 26 26 26 66 66 66
44911- 82 82 82 2 2 6 38 38 38 6 6 6
44912- 14 14 14 210 210 210 253 253 253 253 253 253
44913-253 253 253 253 253 253 253 253 253 253 253 253
44914-253 253 253 253 253 253 246 246 246 242 242 242
44915-253 253 253 253 253 253 253 253 253 253 253 253
44916-253 253 253 253 253 253 253 253 253 253 253 253
44917-253 253 253 253 253 253 253 253 253 253 253 253
44918-253 253 253 253 253 253 253 253 253 253 253 253
44919-253 253 253 253 253 253 144 144 144 2 2 6
44920- 2 2 6 2 2 6 2 2 6 46 46 46
44921- 2 2 6 2 2 6 2 2 6 2 2 6
44922- 42 42 42 74 74 74 30 30 30 10 10 10
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- 6 6 6 14 14 14 42 42 42 90 90 90
44931- 26 26 26 6 6 6 42 42 42 2 2 6
44932- 74 74 74 250 250 250 253 253 253 253 253 253
44933-253 253 253 253 253 253 253 253 253 253 253 253
44934-253 253 253 253 253 253 242 242 242 242 242 242
44935-253 253 253 253 253 253 253 253 253 253 253 253
44936-253 253 253 253 253 253 253 253 253 253 253 253
44937-253 253 253 253 253 253 253 253 253 253 253 253
44938-253 253 253 253 253 253 253 253 253 253 253 253
44939-253 253 253 253 253 253 182 182 182 2 2 6
44940- 2 2 6 2 2 6 2 2 6 46 46 46
44941- 2 2 6 2 2 6 2 2 6 2 2 6
44942- 10 10 10 86 86 86 38 38 38 10 10 10
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- 10 10 10 26 26 26 66 66 66 82 82 82
44951- 2 2 6 22 22 22 18 18 18 2 2 6
44952-149 149 149 253 253 253 253 253 253 253 253 253
44953-253 253 253 253 253 253 253 253 253 253 253 253
44954-253 253 253 253 253 253 234 234 234 242 242 242
44955-253 253 253 253 253 253 253 253 253 253 253 253
44956-253 253 253 253 253 253 253 253 253 253 253 253
44957-253 253 253 253 253 253 253 253 253 253 253 253
44958-253 253 253 253 253 253 253 253 253 253 253 253
44959-253 253 253 253 253 253 206 206 206 2 2 6
44960- 2 2 6 2 2 6 2 2 6 38 38 38
44961- 2 2 6 2 2 6 2 2 6 2 2 6
44962- 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
44970- 18 18 18 46 46 46 86 86 86 18 18 18
44971- 2 2 6 34 34 34 10 10 10 6 6 6
44972-210 210 210 253 253 253 253 253 253 253 253 253
44973-253 253 253 253 253 253 253 253 253 253 253 253
44974-253 253 253 253 253 253 234 234 234 242 242 242
44975-253 253 253 253 253 253 253 253 253 253 253 253
44976-253 253 253 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 253 253 253 253 253 253 253 253 253
44979-253 253 253 253 253 253 221 221 221 6 6 6
44980- 2 2 6 2 2 6 6 6 6 30 30 30
44981- 2 2 6 2 2 6 2 2 6 2 2 6
44982- 2 2 6 82 82 82 54 54 54 18 18 18
44983- 6 6 6 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 10 10 10
44990- 26 26 26 66 66 66 62 62 62 2 2 6
44991- 2 2 6 38 38 38 10 10 10 26 26 26
44992-238 238 238 253 253 253 253 253 253 253 253 253
44993-253 253 253 253 253 253 253 253 253 253 253 253
44994-253 253 253 253 253 253 231 231 231 238 238 238
44995-253 253 253 253 253 253 253 253 253 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 253 253 253 253 253 253 253 253 253
44999-253 253 253 253 253 253 231 231 231 6 6 6
45000- 2 2 6 2 2 6 10 10 10 30 30 30
45001- 2 2 6 2 2 6 2 2 6 2 2 6
45002- 2 2 6 66 66 66 58 58 58 22 22 22
45003- 6 6 6 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 10 10 10
45010- 38 38 38 78 78 78 6 6 6 2 2 6
45011- 2 2 6 46 46 46 14 14 14 42 42 42
45012-246 246 246 253 253 253 253 253 253 253 253 253
45013-253 253 253 253 253 253 253 253 253 253 253 253
45014-253 253 253 253 253 253 231 231 231 242 242 242
45015-253 253 253 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 253 253 253 253 253 253 253 253 253
45019-253 253 253 253 253 253 234 234 234 10 10 10
45020- 2 2 6 2 2 6 22 22 22 14 14 14
45021- 2 2 6 2 2 6 2 2 6 2 2 6
45022- 2 2 6 66 66 66 62 62 62 22 22 22
45023- 6 6 6 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 6 6 6 18 18 18
45030- 50 50 50 74 74 74 2 2 6 2 2 6
45031- 14 14 14 70 70 70 34 34 34 62 62 62
45032-250 250 250 253 253 253 253 253 253 253 253 253
45033-253 253 253 253 253 253 253 253 253 253 253 253
45034-253 253 253 253 253 253 231 231 231 246 246 246
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-253 253 253 253 253 253 253 253 253 253 253 253
45039-253 253 253 253 253 253 234 234 234 14 14 14
45040- 2 2 6 2 2 6 30 30 30 2 2 6
45041- 2 2 6 2 2 6 2 2 6 2 2 6
45042- 2 2 6 66 66 66 62 62 62 22 22 22
45043- 6 6 6 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 6 6 6 18 18 18
45050- 54 54 54 62 62 62 2 2 6 2 2 6
45051- 2 2 6 30 30 30 46 46 46 70 70 70
45052-250 250 250 253 253 253 253 253 253 253 253 253
45053-253 253 253 253 253 253 253 253 253 253 253 253
45054-253 253 253 253 253 253 231 231 231 246 246 246
45055-253 253 253 253 253 253 253 253 253 253 253 253
45056-253 253 253 253 253 253 253 253 253 253 253 253
45057-253 253 253 253 253 253 253 253 253 253 253 253
45058-253 253 253 253 253 253 253 253 253 253 253 253
45059-253 253 253 253 253 253 226 226 226 10 10 10
45060- 2 2 6 6 6 6 30 30 30 2 2 6
45061- 2 2 6 2 2 6 2 2 6 2 2 6
45062- 2 2 6 66 66 66 58 58 58 22 22 22
45063- 6 6 6 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 6 6 6 22 22 22
45070- 58 58 58 62 62 62 2 2 6 2 2 6
45071- 2 2 6 2 2 6 30 30 30 78 78 78
45072-250 250 250 253 253 253 253 253 253 253 253 253
45073-253 253 253 253 253 253 253 253 253 253 253 253
45074-253 253 253 253 253 253 231 231 231 246 246 246
45075-253 253 253 253 253 253 253 253 253 253 253 253
45076-253 253 253 253 253 253 253 253 253 253 253 253
45077-253 253 253 253 253 253 253 253 253 253 253 253
45078-253 253 253 253 253 253 253 253 253 253 253 253
45079-253 253 253 253 253 253 206 206 206 2 2 6
45080- 22 22 22 34 34 34 18 14 6 22 22 22
45081- 26 26 26 18 18 18 6 6 6 2 2 6
45082- 2 2 6 82 82 82 54 54 54 18 18 18
45083- 6 6 6 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 6 6 6 26 26 26
45090- 62 62 62 106 106 106 74 54 14 185 133 11
45091-210 162 10 121 92 8 6 6 6 62 62 62
45092-238 238 238 253 253 253 253 253 253 253 253 253
45093-253 253 253 253 253 253 253 253 253 253 253 253
45094-253 253 253 253 253 253 231 231 231 246 246 246
45095-253 253 253 253 253 253 253 253 253 253 253 253
45096-253 253 253 253 253 253 253 253 253 253 253 253
45097-253 253 253 253 253 253 253 253 253 253 253 253
45098-253 253 253 253 253 253 253 253 253 253 253 253
45099-253 253 253 253 253 253 158 158 158 18 18 18
45100- 14 14 14 2 2 6 2 2 6 2 2 6
45101- 6 6 6 18 18 18 66 66 66 38 38 38
45102- 6 6 6 94 94 94 50 50 50 18 18 18
45103- 6 6 6 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 6 6 6
45109- 10 10 10 10 10 10 18 18 18 38 38 38
45110- 78 78 78 142 134 106 216 158 10 242 186 14
45111-246 190 14 246 190 14 156 118 10 10 10 10
45112- 90 90 90 238 238 238 253 253 253 253 253 253
45113-253 253 253 253 253 253 253 253 253 253 253 253
45114-253 253 253 253 253 253 231 231 231 250 250 250
45115-253 253 253 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 253 253 253
45118-253 253 253 253 253 253 253 253 253 246 230 190
45119-238 204 91 238 204 91 181 142 44 37 26 9
45120- 2 2 6 2 2 6 2 2 6 2 2 6
45121- 2 2 6 2 2 6 38 38 38 46 46 46
45122- 26 26 26 106 106 106 54 54 54 18 18 18
45123- 6 6 6 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 6 6 6 14 14 14 22 22 22
45129- 30 30 30 38 38 38 50 50 50 70 70 70
45130-106 106 106 190 142 34 226 170 11 242 186 14
45131-246 190 14 246 190 14 246 190 14 154 114 10
45132- 6 6 6 74 74 74 226 226 226 253 253 253
45133-253 253 253 253 253 253 253 253 253 253 253 253
45134-253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 253 253 253 228 184 62
45139-241 196 14 241 208 19 232 195 16 38 30 10
45140- 2 2 6 2 2 6 2 2 6 2 2 6
45141- 2 2 6 6 6 6 30 30 30 26 26 26
45142-203 166 17 154 142 90 66 66 66 26 26 26
45143- 6 6 6 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- 6 6 6 18 18 18 38 38 38 58 58 58
45149- 78 78 78 86 86 86 101 101 101 123 123 123
45150-175 146 61 210 150 10 234 174 13 246 186 14
45151-246 190 14 246 190 14 246 190 14 238 190 10
45152-102 78 10 2 2 6 46 46 46 198 198 198
45153-253 253 253 253 253 253 253 253 253 253 253 253
45154-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 224 178 62
45159-242 186 14 241 196 14 210 166 10 22 18 6
45160- 2 2 6 2 2 6 2 2 6 2 2 6
45161- 2 2 6 2 2 6 6 6 6 121 92 8
45162-238 202 15 232 195 16 82 82 82 34 34 34
45163- 10 10 10 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- 14 14 14 38 38 38 70 70 70 154 122 46
45169-190 142 34 200 144 11 197 138 11 197 138 11
45170-213 154 11 226 170 11 242 186 14 246 190 14
45171-246 190 14 246 190 14 246 190 14 246 190 14
45172-225 175 15 46 32 6 2 2 6 22 22 22
45173-158 158 158 250 250 250 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 250 250 250 242 242 242 224 178 62
45179-239 182 13 236 186 11 213 154 11 46 32 6
45180- 2 2 6 2 2 6 2 2 6 2 2 6
45181- 2 2 6 2 2 6 61 42 6 225 175 15
45182-238 190 10 236 186 11 112 100 78 42 42 42
45183- 14 14 14 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 6 6 6
45188- 22 22 22 54 54 54 154 122 46 213 154 11
45189-226 170 11 230 174 11 226 170 11 226 170 11
45190-236 178 12 242 186 14 246 190 14 246 190 14
45191-246 190 14 246 190 14 246 190 14 246 190 14
45192-241 196 14 184 144 12 10 10 10 2 2 6
45193- 6 6 6 116 116 116 242 242 242 253 253 253
45194-253 253 253 253 253 253 253 253 253 253 253 253
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 231 231 231 198 198 198 214 170 54
45199-236 178 12 236 178 12 210 150 10 137 92 6
45200- 18 14 6 2 2 6 2 2 6 2 2 6
45201- 6 6 6 70 47 6 200 144 11 236 178 12
45202-239 182 13 239 182 13 124 112 88 58 58 58
45203- 22 22 22 6 6 6 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 10 10 10
45208- 30 30 30 70 70 70 180 133 36 226 170 11
45209-239 182 13 242 186 14 242 186 14 246 186 14
45210-246 190 14 246 190 14 246 190 14 246 190 14
45211-246 190 14 246 190 14 246 190 14 246 190 14
45212-246 190 14 232 195 16 98 70 6 2 2 6
45213- 2 2 6 2 2 6 66 66 66 221 221 221
45214-253 253 253 253 253 253 253 253 253 253 253 253
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 206 206 206 198 198 198 214 166 58
45219-230 174 11 230 174 11 216 158 10 192 133 9
45220-163 110 8 116 81 8 102 78 10 116 81 8
45221-167 114 7 197 138 11 226 170 11 239 182 13
45222-242 186 14 242 186 14 162 146 94 78 78 78
45223- 34 34 34 14 14 14 6 6 6 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 6 6 6
45228- 30 30 30 78 78 78 190 142 34 226 170 11
45229-239 182 13 246 190 14 246 190 14 246 190 14
45230-246 190 14 246 190 14 246 190 14 246 190 14
45231-246 190 14 246 190 14 246 190 14 246 190 14
45232-246 190 14 241 196 14 203 166 17 22 18 6
45233- 2 2 6 2 2 6 2 2 6 38 38 38
45234-218 218 218 253 253 253 253 253 253 253 253 253
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-250 250 250 206 206 206 198 198 198 202 162 69
45239-226 170 11 236 178 12 224 166 10 210 150 10
45240-200 144 11 197 138 11 192 133 9 197 138 11
45241-210 150 10 226 170 11 242 186 14 246 190 14
45242-246 190 14 246 186 14 225 175 15 124 112 88
45243- 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
45248- 30 30 30 78 78 78 174 135 50 224 166 10
45249-239 182 13 246 190 14 246 190 14 246 190 14
45250-246 190 14 246 190 14 246 190 14 246 190 14
45251-246 190 14 246 190 14 246 190 14 246 190 14
45252-246 190 14 246 190 14 241 196 14 139 102 15
45253- 2 2 6 2 2 6 2 2 6 2 2 6
45254- 78 78 78 250 250 250 253 253 253 253 253 253
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-250 250 250 214 214 214 198 198 198 190 150 46
45259-219 162 10 236 178 12 234 174 13 224 166 10
45260-216 158 10 213 154 11 213 154 11 216 158 10
45261-226 170 11 239 182 13 246 190 14 246 190 14
45262-246 190 14 246 190 14 242 186 14 206 162 42
45263-101 101 101 58 58 58 30 30 30 14 14 14
45264- 6 6 6 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 10 10 10
45268- 30 30 30 74 74 74 174 135 50 216 158 10
45269-236 178 12 246 190 14 246 190 14 246 190 14
45270-246 190 14 246 190 14 246 190 14 246 190 14
45271-246 190 14 246 190 14 246 190 14 246 190 14
45272-246 190 14 246 190 14 241 196 14 226 184 13
45273- 61 42 6 2 2 6 2 2 6 2 2 6
45274- 22 22 22 238 238 238 253 253 253 253 253 253
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 226 226 226 187 187 187 180 133 36
45279-216 158 10 236 178 12 239 182 13 236 178 12
45280-230 174 11 226 170 11 226 170 11 230 174 11
45281-236 178 12 242 186 14 246 190 14 246 190 14
45282-246 190 14 246 190 14 246 186 14 239 182 13
45283-206 162 42 106 106 106 66 66 66 34 34 34
45284- 14 14 14 6 6 6 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 6 6 6
45288- 26 26 26 70 70 70 163 133 67 213 154 11
45289-236 178 12 246 190 14 246 190 14 246 190 14
45290-246 190 14 246 190 14 246 190 14 246 190 14
45291-246 190 14 246 190 14 246 190 14 246 190 14
45292-246 190 14 246 190 14 246 190 14 241 196 14
45293-190 146 13 18 14 6 2 2 6 2 2 6
45294- 46 46 46 246 246 246 253 253 253 253 253 253
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 221 221 221 86 86 86 156 107 11
45299-216 158 10 236 178 12 242 186 14 246 186 14
45300-242 186 14 239 182 13 239 182 13 242 186 14
45301-242 186 14 246 186 14 246 190 14 246 190 14
45302-246 190 14 246 190 14 246 190 14 246 190 14
45303-242 186 14 225 175 15 142 122 72 66 66 66
45304- 30 30 30 10 10 10 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 6 6 6
45308- 26 26 26 70 70 70 163 133 67 210 150 10
45309-236 178 12 246 190 14 246 190 14 246 190 14
45310-246 190 14 246 190 14 246 190 14 246 190 14
45311-246 190 14 246 190 14 246 190 14 246 190 14
45312-246 190 14 246 190 14 246 190 14 246 190 14
45313-232 195 16 121 92 8 34 34 34 106 106 106
45314-221 221 221 253 253 253 253 253 253 253 253 253
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-242 242 242 82 82 82 18 14 6 163 110 8
45319-216 158 10 236 178 12 242 186 14 246 190 14
45320-246 190 14 246 190 14 246 190 14 246 190 14
45321-246 190 14 246 190 14 246 190 14 246 190 14
45322-246 190 14 246 190 14 246 190 14 246 190 14
45323-246 190 14 246 190 14 242 186 14 163 133 67
45324- 46 46 46 18 18 18 6 6 6 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 10 10 10
45328- 30 30 30 78 78 78 163 133 67 210 150 10
45329-236 178 12 246 186 14 246 190 14 246 190 14
45330-246 190 14 246 190 14 246 190 14 246 190 14
45331-246 190 14 246 190 14 246 190 14 246 190 14
45332-246 190 14 246 190 14 246 190 14 246 190 14
45333-241 196 14 215 174 15 190 178 144 253 253 253
45334-253 253 253 253 253 253 253 253 253 253 253 253
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 218 218 218
45338- 58 58 58 2 2 6 22 18 6 167 114 7
45339-216 158 10 236 178 12 246 186 14 246 190 14
45340-246 190 14 246 190 14 246 190 14 246 190 14
45341-246 190 14 246 190 14 246 190 14 246 190 14
45342-246 190 14 246 190 14 246 190 14 246 190 14
45343-246 190 14 246 186 14 242 186 14 190 150 46
45344- 54 54 54 22 22 22 6 6 6 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 14 14 14
45348- 38 38 38 86 86 86 180 133 36 213 154 11
45349-236 178 12 246 186 14 246 190 14 246 190 14
45350-246 190 14 246 190 14 246 190 14 246 190 14
45351-246 190 14 246 190 14 246 190 14 246 190 14
45352-246 190 14 246 190 14 246 190 14 246 190 14
45353-246 190 14 232 195 16 190 146 13 214 214 214
45354-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 170 170 170 26 26 26
45358- 2 2 6 2 2 6 37 26 9 163 110 8
45359-219 162 10 239 182 13 246 186 14 246 190 14
45360-246 190 14 246 190 14 246 190 14 246 190 14
45361-246 190 14 246 190 14 246 190 14 246 190 14
45362-246 190 14 246 190 14 246 190 14 246 190 14
45363-246 186 14 236 178 12 224 166 10 142 122 72
45364- 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
45368- 50 50 50 109 106 95 192 133 9 224 166 10
45369-242 186 14 246 190 14 246 190 14 246 190 14
45370-246 190 14 246 190 14 246 190 14 246 190 14
45371-246 190 14 246 190 14 246 190 14 246 190 14
45372-246 190 14 246 190 14 246 190 14 246 190 14
45373-242 186 14 226 184 13 210 162 10 142 110 46
45374-226 226 226 253 253 253 253 253 253 253 253 253
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-198 198 198 66 66 66 2 2 6 2 2 6
45378- 2 2 6 2 2 6 50 34 6 156 107 11
45379-219 162 10 239 182 13 246 186 14 246 190 14
45380-246 190 14 246 190 14 246 190 14 246 190 14
45381-246 190 14 246 190 14 246 190 14 246 190 14
45382-246 190 14 246 190 14 246 190 14 242 186 14
45383-234 174 13 213 154 11 154 122 46 66 66 66
45384- 30 30 30 10 10 10 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 6 6 6 22 22 22
45388- 58 58 58 154 121 60 206 145 10 234 174 13
45389-242 186 14 246 186 14 246 190 14 246 190 14
45390-246 190 14 246 190 14 246 190 14 246 190 14
45391-246 190 14 246 190 14 246 190 14 246 190 14
45392-246 190 14 246 190 14 246 190 14 246 190 14
45393-246 186 14 236 178 12 210 162 10 163 110 8
45394- 61 42 6 138 138 138 218 218 218 250 250 250
45395-253 253 253 253 253 253 253 253 253 250 250 250
45396-242 242 242 210 210 210 144 144 144 66 66 66
45397- 6 6 6 2 2 6 2 2 6 2 2 6
45398- 2 2 6 2 2 6 61 42 6 163 110 8
45399-216 158 10 236 178 12 246 190 14 246 190 14
45400-246 190 14 246 190 14 246 190 14 246 190 14
45401-246 190 14 246 190 14 246 190 14 246 190 14
45402-246 190 14 239 182 13 230 174 11 216 158 10
45403-190 142 34 124 112 88 70 70 70 38 38 38
45404- 18 18 18 6 6 6 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 6 6 6 22 22 22
45408- 62 62 62 168 124 44 206 145 10 224 166 10
45409-236 178 12 239 182 13 242 186 14 242 186 14
45410-246 186 14 246 190 14 246 190 14 246 190 14
45411-246 190 14 246 190 14 246 190 14 246 190 14
45412-246 190 14 246 190 14 246 190 14 246 190 14
45413-246 190 14 236 178 12 216 158 10 175 118 6
45414- 80 54 7 2 2 6 6 6 6 30 30 30
45415- 54 54 54 62 62 62 50 50 50 38 38 38
45416- 14 14 14 2 2 6 2 2 6 2 2 6
45417- 2 2 6 2 2 6 2 2 6 2 2 6
45418- 2 2 6 6 6 6 80 54 7 167 114 7
45419-213 154 11 236 178 12 246 190 14 246 190 14
45420-246 190 14 246 190 14 246 190 14 246 190 14
45421-246 190 14 242 186 14 239 182 13 239 182 13
45422-230 174 11 210 150 10 174 135 50 124 112 88
45423- 82 82 82 54 54 54 34 34 34 18 18 18
45424- 6 6 6 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 6 6 6 18 18 18
45428- 50 50 50 158 118 36 192 133 9 200 144 11
45429-216 158 10 219 162 10 224 166 10 226 170 11
45430-230 174 11 236 178 12 239 182 13 239 182 13
45431-242 186 14 246 186 14 246 190 14 246 190 14
45432-246 190 14 246 190 14 246 190 14 246 190 14
45433-246 186 14 230 174 11 210 150 10 163 110 8
45434-104 69 6 10 10 10 2 2 6 2 2 6
45435- 2 2 6 2 2 6 2 2 6 2 2 6
45436- 2 2 6 2 2 6 2 2 6 2 2 6
45437- 2 2 6 2 2 6 2 2 6 2 2 6
45438- 2 2 6 6 6 6 91 60 6 167 114 7
45439-206 145 10 230 174 11 242 186 14 246 190 14
45440-246 190 14 246 190 14 246 186 14 242 186 14
45441-239 182 13 230 174 11 224 166 10 213 154 11
45442-180 133 36 124 112 88 86 86 86 58 58 58
45443- 38 38 38 22 22 22 10 10 10 6 6 6
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 14 14 14
45448- 34 34 34 70 70 70 138 110 50 158 118 36
45449-167 114 7 180 123 7 192 133 9 197 138 11
45450-200 144 11 206 145 10 213 154 11 219 162 10
45451-224 166 10 230 174 11 239 182 13 242 186 14
45452-246 186 14 246 186 14 246 186 14 246 186 14
45453-239 182 13 216 158 10 185 133 11 152 99 6
45454-104 69 6 18 14 6 2 2 6 2 2 6
45455- 2 2 6 2 2 6 2 2 6 2 2 6
45456- 2 2 6 2 2 6 2 2 6 2 2 6
45457- 2 2 6 2 2 6 2 2 6 2 2 6
45458- 2 2 6 6 6 6 80 54 7 152 99 6
45459-192 133 9 219 162 10 236 178 12 239 182 13
45460-246 186 14 242 186 14 239 182 13 236 178 12
45461-224 166 10 206 145 10 192 133 9 154 121 60
45462- 94 94 94 62 62 62 42 42 42 22 22 22
45463- 14 14 14 6 6 6 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 6 6 6
45468- 18 18 18 34 34 34 58 58 58 78 78 78
45469-101 98 89 124 112 88 142 110 46 156 107 11
45470-163 110 8 167 114 7 175 118 6 180 123 7
45471-185 133 11 197 138 11 210 150 10 219 162 10
45472-226 170 11 236 178 12 236 178 12 234 174 13
45473-219 162 10 197 138 11 163 110 8 130 83 6
45474- 91 60 6 10 10 10 2 2 6 2 2 6
45475- 18 18 18 38 38 38 38 38 38 38 38 38
45476- 38 38 38 38 38 38 38 38 38 38 38 38
45477- 38 38 38 38 38 38 26 26 26 2 2 6
45478- 2 2 6 6 6 6 70 47 6 137 92 6
45479-175 118 6 200 144 11 219 162 10 230 174 11
45480-234 174 13 230 174 11 219 162 10 210 150 10
45481-192 133 9 163 110 8 124 112 88 82 82 82
45482- 50 50 50 30 30 30 14 14 14 6 6 6
45483- 0 0 0 0 0 0 0 0 0 0 0 0
45484- 0 0 0 0 0 0 0 0 0 0 0 0
45485- 0 0 0 0 0 0 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- 6 6 6 14 14 14 22 22 22 34 34 34
45489- 42 42 42 58 58 58 74 74 74 86 86 86
45490-101 98 89 122 102 70 130 98 46 121 87 25
45491-137 92 6 152 99 6 163 110 8 180 123 7
45492-185 133 11 197 138 11 206 145 10 200 144 11
45493-180 123 7 156 107 11 130 83 6 104 69 6
45494- 50 34 6 54 54 54 110 110 110 101 98 89
45495- 86 86 86 82 82 82 78 78 78 78 78 78
45496- 78 78 78 78 78 78 78 78 78 78 78 78
45497- 78 78 78 82 82 82 86 86 86 94 94 94
45498-106 106 106 101 101 101 86 66 34 124 80 6
45499-156 107 11 180 123 7 192 133 9 200 144 11
45500-206 145 10 200 144 11 192 133 9 175 118 6
45501-139 102 15 109 106 95 70 70 70 42 42 42
45502- 22 22 22 10 10 10 0 0 0 0 0 0
45503- 0 0 0 0 0 0 0 0 0 0 0 0
45504- 0 0 0 0 0 0 0 0 0 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 0 0 0
45508- 0 0 0 0 0 0 6 6 6 10 10 10
45509- 14 14 14 22 22 22 30 30 30 38 38 38
45510- 50 50 50 62 62 62 74 74 74 90 90 90
45511-101 98 89 112 100 78 121 87 25 124 80 6
45512-137 92 6 152 99 6 152 99 6 152 99 6
45513-138 86 6 124 80 6 98 70 6 86 66 30
45514-101 98 89 82 82 82 58 58 58 46 46 46
45515- 38 38 38 34 34 34 34 34 34 34 34 34
45516- 34 34 34 34 34 34 34 34 34 34 34 34
45517- 34 34 34 34 34 34 38 38 38 42 42 42
45518- 54 54 54 82 82 82 94 86 76 91 60 6
45519-134 86 6 156 107 11 167 114 7 175 118 6
45520-175 118 6 167 114 7 152 99 6 121 87 25
45521-101 98 89 62 62 62 34 34 34 18 18 18
45522- 6 6 6 0 0 0 0 0 0 0 0 0
45523- 0 0 0 0 0 0 0 0 0 0 0 0
45524- 0 0 0 0 0 0 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 0 0 0
45528- 0 0 0 0 0 0 0 0 0 0 0 0
45529- 0 0 0 6 6 6 6 6 6 10 10 10
45530- 18 18 18 22 22 22 30 30 30 42 42 42
45531- 50 50 50 66 66 66 86 86 86 101 98 89
45532-106 86 58 98 70 6 104 69 6 104 69 6
45533-104 69 6 91 60 6 82 62 34 90 90 90
45534- 62 62 62 38 38 38 22 22 22 14 14 14
45535- 10 10 10 10 10 10 10 10 10 10 10 10
45536- 10 10 10 10 10 10 6 6 6 10 10 10
45537- 10 10 10 10 10 10 10 10 10 14 14 14
45538- 22 22 22 42 42 42 70 70 70 89 81 66
45539- 80 54 7 104 69 6 124 80 6 137 92 6
45540-134 86 6 116 81 8 100 82 52 86 86 86
45541- 58 58 58 30 30 30 14 14 14 6 6 6
45542- 0 0 0 0 0 0 0 0 0 0 0 0
45543- 0 0 0 0 0 0 0 0 0 0 0 0
45544- 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 0 0 0
45548- 0 0 0 0 0 0 0 0 0 0 0 0
45549- 0 0 0 0 0 0 0 0 0 0 0 0
45550- 0 0 0 6 6 6 10 10 10 14 14 14
45551- 18 18 18 26 26 26 38 38 38 54 54 54
45552- 70 70 70 86 86 86 94 86 76 89 81 66
45553- 89 81 66 86 86 86 74 74 74 50 50 50
45554- 30 30 30 14 14 14 6 6 6 0 0 0
45555- 0 0 0 0 0 0 0 0 0 0 0 0
45556- 0 0 0 0 0 0 0 0 0 0 0 0
45557- 0 0 0 0 0 0 0 0 0 0 0 0
45558- 6 6 6 18 18 18 34 34 34 58 58 58
45559- 82 82 82 89 81 66 89 81 66 89 81 66
45560- 94 86 66 94 86 76 74 74 74 50 50 50
45561- 26 26 26 14 14 14 6 6 6 0 0 0
45562- 0 0 0 0 0 0 0 0 0 0 0 0
45563- 0 0 0 0 0 0 0 0 0 0 0 0
45564- 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 0 0 0
45568- 0 0 0 0 0 0 0 0 0 0 0 0
45569- 0 0 0 0 0 0 0 0 0 0 0 0
45570- 0 0 0 0 0 0 0 0 0 0 0 0
45571- 6 6 6 6 6 6 14 14 14 18 18 18
45572- 30 30 30 38 38 38 46 46 46 54 54 54
45573- 50 50 50 42 42 42 30 30 30 18 18 18
45574- 10 10 10 0 0 0 0 0 0 0 0 0
45575- 0 0 0 0 0 0 0 0 0 0 0 0
45576- 0 0 0 0 0 0 0 0 0 0 0 0
45577- 0 0 0 0 0 0 0 0 0 0 0 0
45578- 0 0 0 6 6 6 14 14 14 26 26 26
45579- 38 38 38 50 50 50 58 58 58 58 58 58
45580- 54 54 54 42 42 42 30 30 30 18 18 18
45581- 10 10 10 0 0 0 0 0 0 0 0 0
45582- 0 0 0 0 0 0 0 0 0 0 0 0
45583- 0 0 0 0 0 0 0 0 0 0 0 0
45584- 0 0 0 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 0 0 0
45588- 0 0 0 0 0 0 0 0 0 0 0 0
45589- 0 0 0 0 0 0 0 0 0 0 0 0
45590- 0 0 0 0 0 0 0 0 0 0 0 0
45591- 0 0 0 0 0 0 0 0 0 6 6 6
45592- 6 6 6 10 10 10 14 14 14 18 18 18
45593- 18 18 18 14 14 14 10 10 10 6 6 6
45594- 0 0 0 0 0 0 0 0 0 0 0 0
45595- 0 0 0 0 0 0 0 0 0 0 0 0
45596- 0 0 0 0 0 0 0 0 0 0 0 0
45597- 0 0 0 0 0 0 0 0 0 0 0 0
45598- 0 0 0 0 0 0 0 0 0 6 6 6
45599- 14 14 14 18 18 18 22 22 22 22 22 22
45600- 18 18 18 14 14 14 10 10 10 6 6 6
45601- 0 0 0 0 0 0 0 0 0 0 0 0
45602- 0 0 0 0 0 0 0 0 0 0 0 0
45603- 0 0 0 0 0 0 0 0 0 0 0 0
45604- 0 0 0 0 0 0 0 0 0 0 0 0
45605- 0 0 0 0 0 0 0 0 0 0 0 0
45606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45619+4 4 4 4 4 4
45620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45633+4 4 4 4 4 4
45634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45647+4 4 4 4 4 4
45648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45661+4 4 4 4 4 4
45662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45675+4 4 4 4 4 4
45676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45689+4 4 4 4 4 4
45690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45694+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
45695+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
45696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45699+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
45700+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45701+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
45702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45703+4 4 4 4 4 4
45704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45708+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
45709+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
45710+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45713+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
45714+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
45715+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
45716+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45717+4 4 4 4 4 4
45718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45722+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
45723+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
45724+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45727+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
45728+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
45729+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
45730+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
45731+4 4 4 4 4 4
45732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45735+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
45736+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
45737+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
45738+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
45739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45740+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45741+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
45742+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
45743+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
45744+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
45745+4 4 4 4 4 4
45746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45749+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
45750+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
45751+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
45752+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
45753+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
45754+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
45755+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
45756+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
45757+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
45758+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
45759+4 4 4 4 4 4
45760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
45763+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
45764+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
45765+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
45766+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
45767+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
45768+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
45769+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
45770+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
45771+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
45772+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
45773+4 4 4 4 4 4
45774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45776+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
45777+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
45778+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
45779+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
45780+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
45781+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
45782+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
45783+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
45784+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
45785+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
45786+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
45787+4 4 4 4 4 4
45788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45790+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
45791+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
45792+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
45793+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
45794+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
45795+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
45796+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
45797+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
45798+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
45799+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
45800+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
45801+4 4 4 4 4 4
45802+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45803+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45804+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
45805+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
45806+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
45807+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
45808+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
45809+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
45810+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
45811+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
45812+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
45813+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
45814+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
45815+4 4 4 4 4 4
45816+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45817+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45818+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
45819+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
45820+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
45821+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
45822+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
45823+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
45824+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
45825+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
45826+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
45827+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
45828+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
45829+4 4 4 4 4 4
45830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45831+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
45832+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
45833+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
45834+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
45835+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
45836+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
45837+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
45838+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
45839+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
45840+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
45841+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
45842+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
45843+4 4 4 4 4 4
45844+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
45845+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
45846+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
45847+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
45848+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
45849+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
45850+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
45851+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
45852+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
45853+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
45854+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
45855+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
45856+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
45857+0 0 0 4 4 4
45858+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
45859+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
45860+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
45861+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
45862+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
45863+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
45864+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
45865+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
45866+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
45867+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
45868+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
45869+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
45870+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
45871+2 0 0 0 0 0
45872+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
45873+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
45874+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
45875+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
45876+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
45877+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
45878+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
45879+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
45880+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
45881+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
45882+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
45883+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
45884+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
45885+37 38 37 0 0 0
45886+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45887+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
45888+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
45889+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
45890+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
45891+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
45892+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
45893+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
45894+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
45895+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
45896+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
45897+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
45898+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
45899+85 115 134 4 0 0
45900+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
45901+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
45902+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
45903+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
45904+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
45905+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
45906+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
45907+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
45908+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
45909+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
45910+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
45911+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
45912+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
45913+60 73 81 4 0 0
45914+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
45915+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
45916+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
45917+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
45918+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
45919+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
45920+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
45921+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
45922+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
45923+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
45924+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
45925+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
45926+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
45927+16 19 21 4 0 0
45928+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
45929+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
45930+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
45931+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
45932+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
45933+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
45934+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
45935+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
45936+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
45937+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
45938+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
45939+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
45940+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
45941+4 0 0 4 3 3
45942+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
45943+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
45944+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
45945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
45946+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
45947+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
45948+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
45949+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
45950+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
45951+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
45952+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
45953+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
45954+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
45955+3 2 2 4 4 4
45956+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
45957+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
45958+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
45959+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
45960+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
45961+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
45962+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
45963+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
45964+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
45965+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
45966+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
45967+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
45968+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
45969+4 4 4 4 4 4
45970+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
45971+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
45972+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
45973+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
45974+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
45975+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
45976+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
45977+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
45978+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
45979+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
45980+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
45981+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
45982+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
45983+4 4 4 4 4 4
45984+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
45985+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
45986+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
45987+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
45988+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
45989+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
45990+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
45991+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
45992+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
45993+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
45994+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
45995+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
45996+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
45997+5 5 5 5 5 5
45998+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
45999+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
46000+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
46001+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
46002+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
46003+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46004+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
46005+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
46006+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
46007+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
46008+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
46009+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
46010+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46011+5 5 5 4 4 4
46012+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
46013+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
46014+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
46015+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
46016+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46017+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
46018+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
46019+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
46020+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
46021+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
46022+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
46023+4 0 0 4 0 0 5 5 5 5 5 5 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
46026+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
46027+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
46028+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
46029+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
46030+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
46031+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46032+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46033+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
46034+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
46035+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
46036+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
46037+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
46038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46039+4 4 4 4 4 4
46040+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
46041+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
46042+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
46043+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
46044+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46045+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
46046+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
46047+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
46048+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
46049+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
46050+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
46051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46053+4 4 4 4 4 4
46054+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
46055+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
46056+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
46057+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
46058+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46059+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46060+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
46061+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
46062+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
46063+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
46064+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
46065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46067+4 4 4 4 4 4
46068+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
46069+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
46070+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
46071+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
46072+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46073+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
46074+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
46075+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
46076+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
46077+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
46078+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46081+4 4 4 4 4 4
46082+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
46083+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
46084+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
46085+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
46086+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
46087+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
46088+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
46089+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
46090+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
46091+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
46092+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
46093+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46094+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46095+4 4 4 4 4 4
46096+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
46097+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
46098+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
46099+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
46100+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
46101+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
46102+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
46103+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
46104+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
46105+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
46106+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
46107+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46108+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46109+4 4 4 4 4 4
46110+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
46111+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
46112+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
46113+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46114+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
46115+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
46116+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
46117+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
46118+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
46119+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
46120+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46121+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46122+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46123+4 4 4 4 4 4
46124+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
46125+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
46126+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
46127+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46128+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46129+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
46130+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
46131+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
46132+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
46133+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
46134+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46135+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46136+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46137+4 4 4 4 4 4
46138+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
46139+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
46140+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46141+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
46142+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46143+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
46144+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
46145+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
46146+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
46147+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
46148+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46149+4 4 4 4 4 4 4 4 4 4 4 4 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
46152+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
46153+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
46154+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46155+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
46156+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46157+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
46158+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
46159+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
46160+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46161+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46162+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46163+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
46166+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46167+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
46168+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
46169+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
46170+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
46171+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
46172+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
46173+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
46174+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46175+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46176+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46177+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46178+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46179+4 4 4 4 4 4
46180+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
46181+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
46182+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
46183+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
46184+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46185+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
46186+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
46187+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
46188+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46189+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46190+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46191+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46192+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46193+4 4 4 4 4 4
46194+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
46195+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
46196+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46197+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
46198+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
46199+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
46200+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
46201+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
46202+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46203+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46204+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46205+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46206+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46207+4 4 4 4 4 4
46208+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
46209+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
46210+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46211+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
46212+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
46213+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
46214+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
46215+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
46216+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
46217+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46218+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46220+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46221+4 4 4 4 4 4
46222+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46223+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
46224+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
46225+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
46226+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
46227+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
46228+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
46229+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
46230+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46231+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46232+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46234+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46235+4 4 4 4 4 4
46236+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
46237+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
46238+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46239+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
46240+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
46241+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
46242+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
46243+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
46244+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
46245+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46246+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46248+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46249+4 4 4 4 4 4
46250+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
46251+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
46252+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
46253+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
46254+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
46255+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
46256+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
46257+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
46258+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46259+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46260+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46263+4 4 4 4 4 4
46264+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46265+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
46266+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
46267+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
46268+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
46269+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
46270+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
46271+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
46272+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46273+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46274+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46277+4 4 4 4 4 4
46278+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46279+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
46280+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
46281+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
46282+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
46283+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
46284+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46285+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
46286+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
46287+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46288+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46291+4 4 4 4 4 4
46292+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46293+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
46294+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
46295+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46296+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
46297+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
46298+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
46299+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
46300+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
46301+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46302+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46305+4 4 4 4 4 4
46306+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
46307+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
46308+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
46309+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
46310+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
46311+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
46312+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
46313+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
46314+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
46315+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46316+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46319+4 4 4 4 4 4
46320+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46321+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
46322+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
46323+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
46324+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
46325+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
46326+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
46327+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
46328+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
46329+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46330+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46333+4 4 4 4 4 4
46334+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
46335+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
46336+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
46337+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
46338+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
46339+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
46340+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
46341+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
46342+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
46343+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46344+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46347+4 4 4 4 4 4
46348+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
46349+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
46350+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
46351+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
46352+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
46353+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
46354+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
46355+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
46356+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
46357+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
46358+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46361+4 4 4 4 4 4
46362+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
46363+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
46364+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
46365+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
46366+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
46367+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
46368+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
46369+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
46370+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
46371+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
46372+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46375+4 4 4 4 4 4
46376+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
46377+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46378+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
46379+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
46380+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
46381+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
46382+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
46383+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
46384+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
46385+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
46386+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46389+4 4 4 4 4 4
46390+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
46391+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
46392+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
46393+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
46394+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
46395+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
46396+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46397+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
46398+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
46399+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
46400+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46402+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46403+4 4 4 4 4 4
46404+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
46405+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
46406+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
46407+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
46408+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
46409+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
46410+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
46411+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
46412+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
46413+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
46414+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46415+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46416+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46417+4 4 4 4 4 4
46418+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
46419+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
46420+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46421+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
46422+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
46423+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
46424+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
46425+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
46426+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
46427+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
46430+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46431+4 4 4 4 4 4
46432+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46433+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
46434+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
46435+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
46436+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
46437+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
46438+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
46439+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
46440+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
46441+13 16 17 4 0 0 4 0 0 4 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4
46444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46445+4 4 4 4 4 4
46446+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
46447+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
46448+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
46449+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
46450+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
46451+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
46452+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
46453+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
46454+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
46455+4 0 0 4 0 0 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
46458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46459+4 4 4 4 4 4
46460+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
46461+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
46462+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
46463+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
46464+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
46465+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
46466+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
46467+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
46468+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46469+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
46472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46473+4 4 4 4 4 4
46474+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
46475+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46476+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
46477+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
46478+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
46479+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
46480+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
46481+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
46482+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
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 4 4 4 4 4 4 4 4 4 4 4 4
46486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46487+4 4 4 4 4 4
46488+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
46489+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
46490+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
46491+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
46492+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
46493+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
46494+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
46495+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
46496+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4
46500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46501+4 4 4 4 4 4
46502+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46503+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
46504+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
46505+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
46506+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
46507+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
46508+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
46509+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
46510+4 0 0 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46515+4 4 4 4 4 4
46516+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
46517+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
46518+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46519+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
46520+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
46521+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
46522+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
46523+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
46524+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46529+4 4 4 4 4 4
46530+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46531+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
46532+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
46533+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
46534+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
46535+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
46536+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
46537+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
46538+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46543+4 4 4 4 4 4
46544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46545+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
46546+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46547+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
46548+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
46549+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
46550+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
46551+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
46552+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46557+4 4 4 4 4 4
46558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46559+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
46560+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
46561+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
46562+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
46563+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
46564+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
46565+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
46566+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46571+4 4 4 4 4 4
46572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46573+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
46574+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
46575+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46576+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
46577+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
46578+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
46579+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46580+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46585+4 4 4 4 4 4
46586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46588+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46589+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
46590+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
46591+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
46592+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
46593+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46594+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46599+4 4 4 4 4 4
46600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46603+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46604+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
46605+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
46606+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
46607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46608+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46613+4 4 4 4 4 4
46614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46617+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
46618+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
46619+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
46620+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
46621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46622+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46627+4 4 4 4 4 4
46628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46631+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
46632+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
46633+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
46634+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
46635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46636+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46641+4 4 4 4 4 4
46642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46645+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
46646+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
46647+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
46648+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
46649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46650+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46655+4 4 4 4 4 4
46656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
46660+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
46661+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
46662+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
46663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46664+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46669+4 4 4 4 4 4
46670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46674+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
46675+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
46676+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46678+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46683+4 4 4 4 4 4
46684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46688+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
46689+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
46690+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46692+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46697+4 4 4 4 4 4
46698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46702+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
46703+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
46704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46706+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46711+4 4 4 4 4 4
46712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46716+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
46717+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
46718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46720+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
46724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46725+4 4 4 4 4 4
46726diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
46727index fe92eed..106e085 100644
46728--- a/drivers/video/mb862xx/mb862xxfb_accel.c
46729+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
46730@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
46731 struct mb862xxfb_par *par = info->par;
46732
46733 if (info->var.bits_per_pixel == 32) {
46734- info->fbops->fb_fillrect = cfb_fillrect;
46735- info->fbops->fb_copyarea = cfb_copyarea;
46736- info->fbops->fb_imageblit = cfb_imageblit;
46737+ pax_open_kernel();
46738+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46739+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46740+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46741+ pax_close_kernel();
46742 } else {
46743 outreg(disp, GC_L0EM, 3);
46744- info->fbops->fb_fillrect = mb86290fb_fillrect;
46745- info->fbops->fb_copyarea = mb86290fb_copyarea;
46746- info->fbops->fb_imageblit = mb86290fb_imageblit;
46747+ pax_open_kernel();
46748+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
46749+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
46750+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
46751+ pax_close_kernel();
46752 }
46753 outreg(draw, GDC_REG_DRAW_BASE, 0);
46754 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
46755diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
46756index ff22871..b129bed 100644
46757--- a/drivers/video/nvidia/nvidia.c
46758+++ b/drivers/video/nvidia/nvidia.c
46759@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
46760 info->fix.line_length = (info->var.xres_virtual *
46761 info->var.bits_per_pixel) >> 3;
46762 if (info->var.accel_flags) {
46763- info->fbops->fb_imageblit = nvidiafb_imageblit;
46764- info->fbops->fb_fillrect = nvidiafb_fillrect;
46765- info->fbops->fb_copyarea = nvidiafb_copyarea;
46766- info->fbops->fb_sync = nvidiafb_sync;
46767+ pax_open_kernel();
46768+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
46769+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
46770+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
46771+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
46772+ pax_close_kernel();
46773 info->pixmap.scan_align = 4;
46774 info->flags &= ~FBINFO_HWACCEL_DISABLED;
46775 info->flags |= FBINFO_READS_FAST;
46776 NVResetGraphics(info);
46777 } else {
46778- info->fbops->fb_imageblit = cfb_imageblit;
46779- info->fbops->fb_fillrect = cfb_fillrect;
46780- info->fbops->fb_copyarea = cfb_copyarea;
46781- info->fbops->fb_sync = NULL;
46782+ pax_open_kernel();
46783+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
46784+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
46785+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
46786+ *(void **)&info->fbops->fb_sync = NULL;
46787+ pax_close_kernel();
46788 info->pixmap.scan_align = 1;
46789 info->flags |= FBINFO_HWACCEL_DISABLED;
46790 info->flags &= ~FBINFO_READS_FAST;
46791@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
46792 info->pixmap.size = 8 * 1024;
46793 info->pixmap.flags = FB_PIXMAP_SYSTEM;
46794
46795- if (!hwcur)
46796- info->fbops->fb_cursor = NULL;
46797+ if (!hwcur) {
46798+ pax_open_kernel();
46799+ *(void **)&info->fbops->fb_cursor = NULL;
46800+ pax_close_kernel();
46801+ }
46802
46803 info->var.accel_flags = (!noaccel);
46804
46805diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
46806index 76d9053..dec2bfd 100644
46807--- a/drivers/video/s1d13xxxfb.c
46808+++ b/drivers/video/s1d13xxxfb.c
46809@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
46810
46811 switch(prod_id) {
46812 case S1D13506_PROD_ID: /* activate acceleration */
46813- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46814- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46815+ pax_open_kernel();
46816+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
46817+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
46818+ pax_close_kernel();
46819 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
46820 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
46821 break;
46822diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
46823index 97bd662..39fab85 100644
46824--- a/drivers/video/smscufx.c
46825+++ b/drivers/video/smscufx.c
46826@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
46827 fb_deferred_io_cleanup(info);
46828 kfree(info->fbdefio);
46829 info->fbdefio = NULL;
46830- info->fbops->fb_mmap = ufx_ops_mmap;
46831+ pax_open_kernel();
46832+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
46833+ pax_close_kernel();
46834 }
46835
46836 pr_debug("released /dev/fb%d user=%d count=%d",
46837diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
46838index 86d449e..8e04dc5 100644
46839--- a/drivers/video/udlfb.c
46840+++ b/drivers/video/udlfb.c
46841@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
46842 dlfb_urb_completion(urb);
46843
46844 error:
46845- atomic_add(bytes_sent, &dev->bytes_sent);
46846- atomic_add(bytes_identical, &dev->bytes_identical);
46847- atomic_add(width*height*2, &dev->bytes_rendered);
46848+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46849+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46850+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
46851 end_cycles = get_cycles();
46852- atomic_add(((unsigned int) ((end_cycles - start_cycles)
46853+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46854 >> 10)), /* Kcycles */
46855 &dev->cpu_kcycles_used);
46856
46857@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
46858 dlfb_urb_completion(urb);
46859
46860 error:
46861- atomic_add(bytes_sent, &dev->bytes_sent);
46862- atomic_add(bytes_identical, &dev->bytes_identical);
46863- atomic_add(bytes_rendered, &dev->bytes_rendered);
46864+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
46865+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
46866+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
46867 end_cycles = get_cycles();
46868- atomic_add(((unsigned int) ((end_cycles - start_cycles)
46869+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
46870 >> 10)), /* Kcycles */
46871 &dev->cpu_kcycles_used);
46872 }
46873@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
46874 fb_deferred_io_cleanup(info);
46875 kfree(info->fbdefio);
46876 info->fbdefio = NULL;
46877- info->fbops->fb_mmap = dlfb_ops_mmap;
46878+ pax_open_kernel();
46879+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
46880+ pax_close_kernel();
46881 }
46882
46883 pr_warn("released /dev/fb%d user=%d count=%d\n",
46884@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
46885 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46886 struct dlfb_data *dev = fb_info->par;
46887 return snprintf(buf, PAGE_SIZE, "%u\n",
46888- atomic_read(&dev->bytes_rendered));
46889+ atomic_read_unchecked(&dev->bytes_rendered));
46890 }
46891
46892 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46893@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
46894 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46895 struct dlfb_data *dev = fb_info->par;
46896 return snprintf(buf, PAGE_SIZE, "%u\n",
46897- atomic_read(&dev->bytes_identical));
46898+ atomic_read_unchecked(&dev->bytes_identical));
46899 }
46900
46901 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46902@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
46903 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46904 struct dlfb_data *dev = fb_info->par;
46905 return snprintf(buf, PAGE_SIZE, "%u\n",
46906- atomic_read(&dev->bytes_sent));
46907+ atomic_read_unchecked(&dev->bytes_sent));
46908 }
46909
46910 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46911@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
46912 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46913 struct dlfb_data *dev = fb_info->par;
46914 return snprintf(buf, PAGE_SIZE, "%u\n",
46915- atomic_read(&dev->cpu_kcycles_used));
46916+ atomic_read_unchecked(&dev->cpu_kcycles_used));
46917 }
46918
46919 static ssize_t edid_show(
46920@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
46921 struct fb_info *fb_info = dev_get_drvdata(fbdev);
46922 struct dlfb_data *dev = fb_info->par;
46923
46924- atomic_set(&dev->bytes_rendered, 0);
46925- atomic_set(&dev->bytes_identical, 0);
46926- atomic_set(&dev->bytes_sent, 0);
46927- atomic_set(&dev->cpu_kcycles_used, 0);
46928+ atomic_set_unchecked(&dev->bytes_rendered, 0);
46929+ atomic_set_unchecked(&dev->bytes_identical, 0);
46930+ atomic_set_unchecked(&dev->bytes_sent, 0);
46931+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
46932
46933 return count;
46934 }
46935diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
46936index b75db01..ad2f34a 100644
46937--- a/drivers/video/uvesafb.c
46938+++ b/drivers/video/uvesafb.c
46939@@ -19,6 +19,7 @@
46940 #include <linux/io.h>
46941 #include <linux/mutex.h>
46942 #include <linux/slab.h>
46943+#include <linux/moduleloader.h>
46944 #include <video/edid.h>
46945 #include <video/uvesafb.h>
46946 #ifdef CONFIG_X86
46947@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
46948 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
46949 par->pmi_setpal = par->ypan = 0;
46950 } else {
46951+
46952+#ifdef CONFIG_PAX_KERNEXEC
46953+#ifdef CONFIG_MODULES
46954+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
46955+#endif
46956+ if (!par->pmi_code) {
46957+ par->pmi_setpal = par->ypan = 0;
46958+ return 0;
46959+ }
46960+#endif
46961+
46962 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
46963 + task->t.regs.edi);
46964+
46965+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
46966+ pax_open_kernel();
46967+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
46968+ pax_close_kernel();
46969+
46970+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
46971+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
46972+#else
46973 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
46974 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
46975+#endif
46976+
46977 printk(KERN_INFO "uvesafb: protected mode interface info at "
46978 "%04x:%04x\n",
46979 (u16)task->t.regs.es, (u16)task->t.regs.edi);
46980@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
46981 par->ypan = ypan;
46982
46983 if (par->pmi_setpal || par->ypan) {
46984+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
46985 if (__supported_pte_mask & _PAGE_NX) {
46986 par->pmi_setpal = par->ypan = 0;
46987 printk(KERN_WARNING "uvesafb: NX protection is actively."
46988 "We have better not to use the PMI.\n");
46989- } else {
46990+ } else
46991+#endif
46992 uvesafb_vbe_getpmi(task, par);
46993- }
46994 }
46995 #else
46996 /* The protected mode interface is not available on non-x86. */
46997@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
46998 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
46999
47000 /* Disable blanking if the user requested so. */
47001- if (!blank)
47002- info->fbops->fb_blank = NULL;
47003+ if (!blank) {
47004+ pax_open_kernel();
47005+ *(void **)&info->fbops->fb_blank = NULL;
47006+ pax_close_kernel();
47007+ }
47008
47009 /*
47010 * Find out how much IO memory is required for the mode with
47011@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
47012 info->flags = FBINFO_FLAG_DEFAULT |
47013 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
47014
47015- if (!par->ypan)
47016- info->fbops->fb_pan_display = NULL;
47017+ if (!par->ypan) {
47018+ pax_open_kernel();
47019+ *(void **)&info->fbops->fb_pan_display = NULL;
47020+ pax_close_kernel();
47021+ }
47022 }
47023
47024 static void uvesafb_init_mtrr(struct fb_info *info)
47025@@ -1836,6 +1866,11 @@ out:
47026 if (par->vbe_modes)
47027 kfree(par->vbe_modes);
47028
47029+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47030+ if (par->pmi_code)
47031+ module_free_exec(NULL, par->pmi_code);
47032+#endif
47033+
47034 framebuffer_release(info);
47035 return err;
47036 }
47037@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
47038 kfree(par->vbe_state_orig);
47039 if (par->vbe_state_saved)
47040 kfree(par->vbe_state_saved);
47041+
47042+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47043+ if (par->pmi_code)
47044+ module_free_exec(NULL, par->pmi_code);
47045+#endif
47046+
47047 }
47048
47049 framebuffer_release(info);
47050diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
47051index 501b340..d80aa17 100644
47052--- a/drivers/video/vesafb.c
47053+++ b/drivers/video/vesafb.c
47054@@ -9,6 +9,7 @@
47055 */
47056
47057 #include <linux/module.h>
47058+#include <linux/moduleloader.h>
47059 #include <linux/kernel.h>
47060 #include <linux/errno.h>
47061 #include <linux/string.h>
47062@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
47063 static int vram_total __initdata; /* Set total amount of memory */
47064 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
47065 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
47066-static void (*pmi_start)(void) __read_mostly;
47067-static void (*pmi_pal) (void) __read_mostly;
47068+static void (*pmi_start)(void) __read_only;
47069+static void (*pmi_pal) (void) __read_only;
47070 static int depth __read_mostly;
47071 static int vga_compat __read_mostly;
47072 /* --------------------------------------------------------------------- */
47073@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
47074 unsigned int size_vmode;
47075 unsigned int size_remap;
47076 unsigned int size_total;
47077+ void *pmi_code = NULL;
47078
47079 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
47080 return -ENODEV;
47081@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
47082 size_remap = size_total;
47083 vesafb_fix.smem_len = size_remap;
47084
47085-#ifndef __i386__
47086- screen_info.vesapm_seg = 0;
47087-#endif
47088-
47089 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
47090 printk(KERN_WARNING
47091 "vesafb: cannot reserve video memory at 0x%lx\n",
47092@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
47093 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
47094 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
47095
47096+#ifdef __i386__
47097+
47098+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47099+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
47100+ if (!pmi_code)
47101+#elif !defined(CONFIG_PAX_KERNEXEC)
47102+ if (0)
47103+#endif
47104+
47105+#endif
47106+ screen_info.vesapm_seg = 0;
47107+
47108 if (screen_info.vesapm_seg) {
47109- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
47110- screen_info.vesapm_seg,screen_info.vesapm_off);
47111+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
47112+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
47113 }
47114
47115 if (screen_info.vesapm_seg < 0xc000)
47116@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
47117
47118 if (ypan || pmi_setpal) {
47119 unsigned short *pmi_base;
47120+
47121 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
47122- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
47123- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
47124+
47125+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47126+ pax_open_kernel();
47127+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
47128+#else
47129+ pmi_code = pmi_base;
47130+#endif
47131+
47132+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
47133+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
47134+
47135+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47136+ pmi_start = ktva_ktla(pmi_start);
47137+ pmi_pal = ktva_ktla(pmi_pal);
47138+ pax_close_kernel();
47139+#endif
47140+
47141 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
47142 if (pmi_base[3]) {
47143 printk(KERN_INFO "vesafb: pmi: ports = ");
47144@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47145 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
47146 (ypan ? FBINFO_HWACCEL_YPAN : 0);
47147
47148- if (!ypan)
47149- info->fbops->fb_pan_display = NULL;
47150+ if (!ypan) {
47151+ pax_open_kernel();
47152+ *(void **)&info->fbops->fb_pan_display = NULL;
47153+ pax_close_kernel();
47154+ }
47155
47156 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
47157 err = -ENOMEM;
47158@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
47159 info->node, info->fix.id);
47160 return 0;
47161 err:
47162+
47163+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47164+ module_free_exec(NULL, pmi_code);
47165+#endif
47166+
47167 if (info->screen_base)
47168 iounmap(info->screen_base);
47169 framebuffer_release(info);
47170diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
47171index 88714ae..16c2e11 100644
47172--- a/drivers/video/via/via_clock.h
47173+++ b/drivers/video/via/via_clock.h
47174@@ -56,7 +56,7 @@ struct via_clock {
47175
47176 void (*set_engine_pll_state)(u8 state);
47177 void (*set_engine_pll)(struct via_pll_config config);
47178-};
47179+} __no_const;
47180
47181
47182 static inline u32 get_pll_internal_frequency(u32 ref_freq,
47183diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
47184index fef20db..d28b1ab 100644
47185--- a/drivers/xen/xenfs/xenstored.c
47186+++ b/drivers/xen/xenfs/xenstored.c
47187@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
47188 static int xsd_kva_open(struct inode *inode, struct file *file)
47189 {
47190 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
47191+#ifdef CONFIG_GRKERNSEC_HIDESYM
47192+ NULL);
47193+#else
47194 xen_store_interface);
47195+#endif
47196+
47197 if (!file->private_data)
47198 return -ENOMEM;
47199 return 0;
47200diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
47201index 890bed5..17ae73e 100644
47202--- a/fs/9p/vfs_inode.c
47203+++ b/fs/9p/vfs_inode.c
47204@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
47205 void
47206 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47207 {
47208- char *s = nd_get_link(nd);
47209+ const char *s = nd_get_link(nd);
47210
47211 p9_debug(P9_DEBUG_VFS, " %s %s\n",
47212 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
47213diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
47214index 0efd152..b5802ad 100644
47215--- a/fs/Kconfig.binfmt
47216+++ b/fs/Kconfig.binfmt
47217@@ -89,7 +89,7 @@ config HAVE_AOUT
47218
47219 config BINFMT_AOUT
47220 tristate "Kernel support for a.out and ECOFF binaries"
47221- depends on HAVE_AOUT
47222+ depends on HAVE_AOUT && BROKEN
47223 ---help---
47224 A.out (Assembler.OUTput) is a set of formats for libraries and
47225 executables used in the earliest versions of UNIX. Linux used
47226diff --git a/fs/aio.c b/fs/aio.c
47227index 71f613c..9d01f1f 100644
47228--- a/fs/aio.c
47229+++ b/fs/aio.c
47230@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
47231 size += sizeof(struct io_event) * nr_events;
47232 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
47233
47234- if (nr_pages < 0)
47235+ if (nr_pages <= 0)
47236 return -EINVAL;
47237
47238 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
47239@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
47240 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47241 {
47242 ssize_t ret;
47243+ struct iovec iovstack;
47244
47245 #ifdef CONFIG_COMPAT
47246 if (compat)
47247 ret = compat_rw_copy_check_uvector(type,
47248 (struct compat_iovec __user *)kiocb->ki_buf,
47249- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47250+ kiocb->ki_nbytes, 1, &iovstack,
47251 &kiocb->ki_iovec);
47252 else
47253 #endif
47254 ret = rw_copy_check_uvector(type,
47255 (struct iovec __user *)kiocb->ki_buf,
47256- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
47257+ kiocb->ki_nbytes, 1, &iovstack,
47258 &kiocb->ki_iovec);
47259 if (ret < 0)
47260 goto out;
47261@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
47262 if (ret < 0)
47263 goto out;
47264
47265+ if (kiocb->ki_iovec == &iovstack) {
47266+ kiocb->ki_inline_vec = iovstack;
47267+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
47268+ }
47269 kiocb->ki_nr_segs = kiocb->ki_nbytes;
47270 kiocb->ki_cur_seg = 0;
47271 /* ki_nbytes/left now reflect bytes instead of segs */
47272diff --git a/fs/attr.c b/fs/attr.c
47273index 1449adb..a2038c2 100644
47274--- a/fs/attr.c
47275+++ b/fs/attr.c
47276@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
47277 unsigned long limit;
47278
47279 limit = rlimit(RLIMIT_FSIZE);
47280+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
47281 if (limit != RLIM_INFINITY && offset > limit)
47282 goto out_sig;
47283 if (offset > inode->i_sb->s_maxbytes)
47284diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
47285index 03bc1d3..6205356 100644
47286--- a/fs/autofs4/waitq.c
47287+++ b/fs/autofs4/waitq.c
47288@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
47289 {
47290 unsigned long sigpipe, flags;
47291 mm_segment_t fs;
47292- const char *data = (const char *)addr;
47293+ const char __user *data = (const char __force_user *)addr;
47294 ssize_t wr = 0;
47295
47296 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
47297@@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
47298 return 1;
47299 }
47300
47301+#ifdef CONFIG_GRKERNSEC_HIDESYM
47302+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
47303+#endif
47304+
47305 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47306 enum autofs_notify notify)
47307 {
47308@@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
47309
47310 /* If this is a direct mount request create a dummy name */
47311 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
47312+#ifdef CONFIG_GRKERNSEC_HIDESYM
47313+ /* this name does get written to userland via autofs4_write() */
47314+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
47315+#else
47316 qstr.len = sprintf(name, "%p", dentry);
47317+#endif
47318 else {
47319 qstr.len = autofs4_getpath(sbi, dentry, &name);
47320 if (!qstr.len) {
47321diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
47322index 2b3bda8..6a2d4be 100644
47323--- a/fs/befs/linuxvfs.c
47324+++ b/fs/befs/linuxvfs.c
47325@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47326 {
47327 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
47328 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
47329- char *link = nd_get_link(nd);
47330+ const char *link = nd_get_link(nd);
47331 if (!IS_ERR(link))
47332 kfree(link);
47333 }
47334diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
47335index 6043567..16a9239 100644
47336--- a/fs/binfmt_aout.c
47337+++ b/fs/binfmt_aout.c
47338@@ -16,6 +16,7 @@
47339 #include <linux/string.h>
47340 #include <linux/fs.h>
47341 #include <linux/file.h>
47342+#include <linux/security.h>
47343 #include <linux/stat.h>
47344 #include <linux/fcntl.h>
47345 #include <linux/ptrace.h>
47346@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
47347 #endif
47348 # define START_STACK(u) ((void __user *)u.start_stack)
47349
47350+ memset(&dump, 0, sizeof(dump));
47351+
47352 fs = get_fs();
47353 set_fs(KERNEL_DS);
47354 has_dumped = 1;
47355@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
47356
47357 /* If the size of the dump file exceeds the rlimit, then see what would happen
47358 if we wrote the stack, but not the data area. */
47359+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
47360 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
47361 dump.u_dsize = 0;
47362
47363 /* Make sure we have enough room to write the stack and data areas. */
47364+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
47365 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
47366 dump.u_ssize = 0;
47367
47368@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
47369 rlim = rlimit(RLIMIT_DATA);
47370 if (rlim >= RLIM_INFINITY)
47371 rlim = ~0;
47372+
47373+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
47374 if (ex.a_data + ex.a_bss > rlim)
47375 return -ENOMEM;
47376
47377@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
47378
47379 install_exec_creds(bprm);
47380
47381+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47382+ current->mm->pax_flags = 0UL;
47383+#endif
47384+
47385+#ifdef CONFIG_PAX_PAGEEXEC
47386+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
47387+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
47388+
47389+#ifdef CONFIG_PAX_EMUTRAMP
47390+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
47391+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
47392+#endif
47393+
47394+#ifdef CONFIG_PAX_MPROTECT
47395+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
47396+ current->mm->pax_flags |= MF_PAX_MPROTECT;
47397+#endif
47398+
47399+ }
47400+#endif
47401+
47402 if (N_MAGIC(ex) == OMAGIC) {
47403 unsigned long text_addr, map_size;
47404 loff_t pos;
47405@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
47406 }
47407
47408 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
47409- PROT_READ | PROT_WRITE | PROT_EXEC,
47410+ PROT_READ | PROT_WRITE,
47411 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
47412 fd_offset + ex.a_text);
47413 if (error != N_DATADDR(ex)) {
47414diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
47415index 0c42cdb..9551bb8 100644
47416--- a/fs/binfmt_elf.c
47417+++ b/fs/binfmt_elf.c
47418@@ -33,6 +33,7 @@
47419 #include <linux/elf.h>
47420 #include <linux/utsname.h>
47421 #include <linux/coredump.h>
47422+#include <linux/xattr.h>
47423 #include <asm/uaccess.h>
47424 #include <asm/param.h>
47425 #include <asm/page.h>
47426@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
47427 #define elf_core_dump NULL
47428 #endif
47429
47430+#ifdef CONFIG_PAX_MPROTECT
47431+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
47432+#endif
47433+
47434 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
47435 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
47436 #else
47437@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
47438 .load_binary = load_elf_binary,
47439 .load_shlib = load_elf_library,
47440 .core_dump = elf_core_dump,
47441+
47442+#ifdef CONFIG_PAX_MPROTECT
47443+ .handle_mprotect= elf_handle_mprotect,
47444+#endif
47445+
47446 .min_coredump = ELF_EXEC_PAGESIZE,
47447 };
47448
47449@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
47450
47451 static int set_brk(unsigned long start, unsigned long end)
47452 {
47453+ unsigned long e = end;
47454+
47455 start = ELF_PAGEALIGN(start);
47456 end = ELF_PAGEALIGN(end);
47457 if (end > start) {
47458@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
47459 if (BAD_ADDR(addr))
47460 return addr;
47461 }
47462- current->mm->start_brk = current->mm->brk = end;
47463+ current->mm->start_brk = current->mm->brk = e;
47464 return 0;
47465 }
47466
47467@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47468 elf_addr_t __user *u_rand_bytes;
47469 const char *k_platform = ELF_PLATFORM;
47470 const char *k_base_platform = ELF_BASE_PLATFORM;
47471- unsigned char k_rand_bytes[16];
47472+ u32 k_rand_bytes[4];
47473 int items;
47474 elf_addr_t *elf_info;
47475 int ei_index = 0;
47476 const struct cred *cred = current_cred();
47477 struct vm_area_struct *vma;
47478+ unsigned long saved_auxv[AT_VECTOR_SIZE];
47479
47480 /*
47481 * In some cases (e.g. Hyper-Threading), we want to avoid L1
47482@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47483 * Generate 16 random bytes for userspace PRNG seeding.
47484 */
47485 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
47486- u_rand_bytes = (elf_addr_t __user *)
47487- STACK_ALLOC(p, sizeof(k_rand_bytes));
47488+ srandom32(k_rand_bytes[0] ^ random32());
47489+ srandom32(k_rand_bytes[1] ^ random32());
47490+ srandom32(k_rand_bytes[2] ^ random32());
47491+ srandom32(k_rand_bytes[3] ^ random32());
47492+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
47493+ u_rand_bytes = (elf_addr_t __user *) p;
47494 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
47495 return -EFAULT;
47496
47497@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
47498 return -EFAULT;
47499 current->mm->env_end = p;
47500
47501+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
47502+
47503 /* Put the elf_info on the stack in the right place. */
47504 sp = (elf_addr_t __user *)envp + 1;
47505- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
47506+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
47507 return -EFAULT;
47508 return 0;
47509 }
47510@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
47511 an ELF header */
47512
47513 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47514- struct file *interpreter, unsigned long *interp_map_addr,
47515- unsigned long no_base)
47516+ struct file *interpreter, unsigned long no_base)
47517 {
47518 struct elf_phdr *elf_phdata;
47519 struct elf_phdr *eppnt;
47520- unsigned long load_addr = 0;
47521+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
47522 int load_addr_set = 0;
47523 unsigned long last_bss = 0, elf_bss = 0;
47524- unsigned long error = ~0UL;
47525+ unsigned long error = -EINVAL;
47526 unsigned long total_size;
47527 int retval, i, size;
47528
47529@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47530 goto out_close;
47531 }
47532
47533+#ifdef CONFIG_PAX_SEGMEXEC
47534+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
47535+ pax_task_size = SEGMEXEC_TASK_SIZE;
47536+#endif
47537+
47538 eppnt = elf_phdata;
47539 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
47540 if (eppnt->p_type == PT_LOAD) {
47541@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47542 map_addr = elf_map(interpreter, load_addr + vaddr,
47543 eppnt, elf_prot, elf_type, total_size);
47544 total_size = 0;
47545- if (!*interp_map_addr)
47546- *interp_map_addr = map_addr;
47547 error = map_addr;
47548 if (BAD_ADDR(map_addr))
47549 goto out_close;
47550@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
47551 k = load_addr + eppnt->p_vaddr;
47552 if (BAD_ADDR(k) ||
47553 eppnt->p_filesz > eppnt->p_memsz ||
47554- eppnt->p_memsz > TASK_SIZE ||
47555- TASK_SIZE - eppnt->p_memsz < k) {
47556+ eppnt->p_memsz > pax_task_size ||
47557+ pax_task_size - eppnt->p_memsz < k) {
47558 error = -ENOMEM;
47559 goto out_close;
47560 }
47561@@ -530,6 +551,315 @@ out:
47562 return error;
47563 }
47564
47565+#ifdef CONFIG_PAX_PT_PAX_FLAGS
47566+#ifdef CONFIG_PAX_SOFTMODE
47567+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
47568+{
47569+ unsigned long pax_flags = 0UL;
47570+
47571+#ifdef CONFIG_PAX_PAGEEXEC
47572+ if (elf_phdata->p_flags & PF_PAGEEXEC)
47573+ pax_flags |= MF_PAX_PAGEEXEC;
47574+#endif
47575+
47576+#ifdef CONFIG_PAX_SEGMEXEC
47577+ if (elf_phdata->p_flags & PF_SEGMEXEC)
47578+ pax_flags |= MF_PAX_SEGMEXEC;
47579+#endif
47580+
47581+#ifdef CONFIG_PAX_EMUTRAMP
47582+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
47583+ pax_flags |= MF_PAX_EMUTRAMP;
47584+#endif
47585+
47586+#ifdef CONFIG_PAX_MPROTECT
47587+ if (elf_phdata->p_flags & PF_MPROTECT)
47588+ pax_flags |= MF_PAX_MPROTECT;
47589+#endif
47590+
47591+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47592+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
47593+ pax_flags |= MF_PAX_RANDMMAP;
47594+#endif
47595+
47596+ return pax_flags;
47597+}
47598+#endif
47599+
47600+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
47601+{
47602+ unsigned long pax_flags = 0UL;
47603+
47604+#ifdef CONFIG_PAX_PAGEEXEC
47605+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
47606+ pax_flags |= MF_PAX_PAGEEXEC;
47607+#endif
47608+
47609+#ifdef CONFIG_PAX_SEGMEXEC
47610+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
47611+ pax_flags |= MF_PAX_SEGMEXEC;
47612+#endif
47613+
47614+#ifdef CONFIG_PAX_EMUTRAMP
47615+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
47616+ pax_flags |= MF_PAX_EMUTRAMP;
47617+#endif
47618+
47619+#ifdef CONFIG_PAX_MPROTECT
47620+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
47621+ pax_flags |= MF_PAX_MPROTECT;
47622+#endif
47623+
47624+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47625+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
47626+ pax_flags |= MF_PAX_RANDMMAP;
47627+#endif
47628+
47629+ return pax_flags;
47630+}
47631+#endif
47632+
47633+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47634+#ifdef CONFIG_PAX_SOFTMODE
47635+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
47636+{
47637+ unsigned long pax_flags = 0UL;
47638+
47639+#ifdef CONFIG_PAX_PAGEEXEC
47640+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
47641+ pax_flags |= MF_PAX_PAGEEXEC;
47642+#endif
47643+
47644+#ifdef CONFIG_PAX_SEGMEXEC
47645+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
47646+ pax_flags |= MF_PAX_SEGMEXEC;
47647+#endif
47648+
47649+#ifdef CONFIG_PAX_EMUTRAMP
47650+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
47651+ pax_flags |= MF_PAX_EMUTRAMP;
47652+#endif
47653+
47654+#ifdef CONFIG_PAX_MPROTECT
47655+ if (pax_flags_softmode & MF_PAX_MPROTECT)
47656+ pax_flags |= MF_PAX_MPROTECT;
47657+#endif
47658+
47659+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47660+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
47661+ pax_flags |= MF_PAX_RANDMMAP;
47662+#endif
47663+
47664+ return pax_flags;
47665+}
47666+#endif
47667+
47668+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
47669+{
47670+ unsigned long pax_flags = 0UL;
47671+
47672+#ifdef CONFIG_PAX_PAGEEXEC
47673+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
47674+ pax_flags |= MF_PAX_PAGEEXEC;
47675+#endif
47676+
47677+#ifdef CONFIG_PAX_SEGMEXEC
47678+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
47679+ pax_flags |= MF_PAX_SEGMEXEC;
47680+#endif
47681+
47682+#ifdef CONFIG_PAX_EMUTRAMP
47683+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
47684+ pax_flags |= MF_PAX_EMUTRAMP;
47685+#endif
47686+
47687+#ifdef CONFIG_PAX_MPROTECT
47688+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
47689+ pax_flags |= MF_PAX_MPROTECT;
47690+#endif
47691+
47692+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
47693+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
47694+ pax_flags |= MF_PAX_RANDMMAP;
47695+#endif
47696+
47697+ return pax_flags;
47698+}
47699+#endif
47700+
47701+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47702+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
47703+{
47704+ unsigned long pax_flags = 0UL;
47705+
47706+#ifdef CONFIG_PAX_EI_PAX
47707+
47708+#ifdef CONFIG_PAX_PAGEEXEC
47709+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
47710+ pax_flags |= MF_PAX_PAGEEXEC;
47711+#endif
47712+
47713+#ifdef CONFIG_PAX_SEGMEXEC
47714+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
47715+ pax_flags |= MF_PAX_SEGMEXEC;
47716+#endif
47717+
47718+#ifdef CONFIG_PAX_EMUTRAMP
47719+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
47720+ pax_flags |= MF_PAX_EMUTRAMP;
47721+#endif
47722+
47723+#ifdef CONFIG_PAX_MPROTECT
47724+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
47725+ pax_flags |= MF_PAX_MPROTECT;
47726+#endif
47727+
47728+#ifdef CONFIG_PAX_ASLR
47729+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
47730+ pax_flags |= MF_PAX_RANDMMAP;
47731+#endif
47732+
47733+#else
47734+
47735+#ifdef CONFIG_PAX_PAGEEXEC
47736+ pax_flags |= MF_PAX_PAGEEXEC;
47737+#endif
47738+
47739+#ifdef CONFIG_PAX_SEGMEXEC
47740+ pax_flags |= MF_PAX_SEGMEXEC;
47741+#endif
47742+
47743+#ifdef CONFIG_PAX_MPROTECT
47744+ pax_flags |= MF_PAX_MPROTECT;
47745+#endif
47746+
47747+#ifdef CONFIG_PAX_RANDMMAP
47748+ if (randomize_va_space)
47749+ pax_flags |= MF_PAX_RANDMMAP;
47750+#endif
47751+
47752+#endif
47753+
47754+ return pax_flags;
47755+}
47756+
47757+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
47758+{
47759+
47760+#ifdef CONFIG_PAX_PT_PAX_FLAGS
47761+ unsigned long i;
47762+
47763+ for (i = 0UL; i < elf_ex->e_phnum; i++)
47764+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
47765+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
47766+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
47767+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
47768+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
47769+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
47770+ return ~0UL;
47771+
47772+#ifdef CONFIG_PAX_SOFTMODE
47773+ if (pax_softmode)
47774+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
47775+ else
47776+#endif
47777+
47778+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
47779+ break;
47780+ }
47781+#endif
47782+
47783+ return ~0UL;
47784+}
47785+
47786+static unsigned long pax_parse_xattr_pax(struct file * const file)
47787+{
47788+
47789+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
47790+ ssize_t xattr_size, i;
47791+ unsigned char xattr_value[5];
47792+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
47793+
47794+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
47795+ if (xattr_size <= 0 || xattr_size > 5)
47796+ return ~0UL;
47797+
47798+ for (i = 0; i < xattr_size; i++)
47799+ switch (xattr_value[i]) {
47800+ default:
47801+ return ~0UL;
47802+
47803+#define parse_flag(option1, option2, flag) \
47804+ case option1: \
47805+ if (pax_flags_hardmode & MF_PAX_##flag) \
47806+ return ~0UL; \
47807+ pax_flags_hardmode |= MF_PAX_##flag; \
47808+ break; \
47809+ case option2: \
47810+ if (pax_flags_softmode & MF_PAX_##flag) \
47811+ return ~0UL; \
47812+ pax_flags_softmode |= MF_PAX_##flag; \
47813+ break;
47814+
47815+ parse_flag('p', 'P', PAGEEXEC);
47816+ parse_flag('e', 'E', EMUTRAMP);
47817+ parse_flag('m', 'M', MPROTECT);
47818+ parse_flag('r', 'R', RANDMMAP);
47819+ parse_flag('s', 'S', SEGMEXEC);
47820+
47821+#undef parse_flag
47822+ }
47823+
47824+ if (pax_flags_hardmode & pax_flags_softmode)
47825+ return ~0UL;
47826+
47827+#ifdef CONFIG_PAX_SOFTMODE
47828+ if (pax_softmode)
47829+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
47830+ else
47831+#endif
47832+
47833+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
47834+#else
47835+ return ~0UL;
47836+#endif
47837+
47838+}
47839+
47840+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
47841+{
47842+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
47843+
47844+ pax_flags = pax_parse_ei_pax(elf_ex);
47845+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
47846+ xattr_pax_flags = pax_parse_xattr_pax(file);
47847+
47848+ if (pt_pax_flags == ~0UL)
47849+ pt_pax_flags = xattr_pax_flags;
47850+ else if (xattr_pax_flags == ~0UL)
47851+ xattr_pax_flags = pt_pax_flags;
47852+ if (pt_pax_flags != xattr_pax_flags)
47853+ return -EINVAL;
47854+ if (pt_pax_flags != ~0UL)
47855+ pax_flags = pt_pax_flags;
47856+
47857+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
47858+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47859+ if ((__supported_pte_mask & _PAGE_NX))
47860+ pax_flags &= ~MF_PAX_SEGMEXEC;
47861+ else
47862+ pax_flags &= ~MF_PAX_PAGEEXEC;
47863+ }
47864+#endif
47865+
47866+ if (0 > pax_check_flags(&pax_flags))
47867+ return -EINVAL;
47868+
47869+ current->mm->pax_flags = pax_flags;
47870+ return 0;
47871+}
47872+#endif
47873+
47874 /*
47875 * These are the functions used to load ELF style executables and shared
47876 * libraries. There is no binary dependent code anywhere else.
47877@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
47878 {
47879 unsigned int random_variable = 0;
47880
47881+#ifdef CONFIG_PAX_RANDUSTACK
47882+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
47883+ return stack_top - current->mm->delta_stack;
47884+#endif
47885+
47886 if ((current->flags & PF_RANDOMIZE) &&
47887 !(current->personality & ADDR_NO_RANDOMIZE)) {
47888 random_variable = get_random_int() & STACK_RND_MASK;
47889@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
47890 unsigned long load_addr = 0, load_bias = 0;
47891 int load_addr_set = 0;
47892 char * elf_interpreter = NULL;
47893- unsigned long error;
47894+ unsigned long error = 0;
47895 struct elf_phdr *elf_ppnt, *elf_phdata;
47896 unsigned long elf_bss, elf_brk;
47897 int retval, i;
47898@@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
47899 unsigned long start_code, end_code, start_data, end_data;
47900 unsigned long reloc_func_desc __maybe_unused = 0;
47901 int executable_stack = EXSTACK_DEFAULT;
47902- unsigned long def_flags = 0;
47903 struct pt_regs *regs = current_pt_regs();
47904 struct {
47905 struct elfhdr elf_ex;
47906 struct elfhdr interp_elf_ex;
47907 } *loc;
47908+ unsigned long pax_task_size = TASK_SIZE;
47909
47910 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
47911 if (!loc) {
47912@@ -715,11 +1050,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
47913 goto out_free_dentry;
47914
47915 /* OK, This is the point of no return */
47916- current->mm->def_flags = def_flags;
47917+
47918+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47919+ current->mm->pax_flags = 0UL;
47920+#endif
47921+
47922+#ifdef CONFIG_PAX_DLRESOLVE
47923+ current->mm->call_dl_resolve = 0UL;
47924+#endif
47925+
47926+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
47927+ current->mm->call_syscall = 0UL;
47928+#endif
47929+
47930+#ifdef CONFIG_PAX_ASLR
47931+ current->mm->delta_mmap = 0UL;
47932+ current->mm->delta_stack = 0UL;
47933+ current->mm->aslr_gap = 0UL;
47934+#endif
47935+
47936+ current->mm->def_flags = 0;
47937+
47938+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47939+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
47940+ send_sig(SIGKILL, current, 0);
47941+ goto out_free_dentry;
47942+ }
47943+#endif
47944+
47945+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47946+ pax_set_initial_flags(bprm);
47947+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47948+ if (pax_set_initial_flags_func)
47949+ (pax_set_initial_flags_func)(bprm);
47950+#endif
47951+
47952+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47953+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
47954+ current->mm->context.user_cs_limit = PAGE_SIZE;
47955+ current->mm->def_flags |= VM_PAGEEXEC;
47956+ }
47957+#endif
47958+
47959+#ifdef CONFIG_PAX_SEGMEXEC
47960+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
47961+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
47962+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
47963+ pax_task_size = SEGMEXEC_TASK_SIZE;
47964+ current->mm->def_flags |= VM_NOHUGEPAGE;
47965+ }
47966+#endif
47967+
47968+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
47969+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47970+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
47971+ put_cpu();
47972+ }
47973+#endif
47974
47975 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
47976 may depend on the personality. */
47977 SET_PERSONALITY(loc->elf_ex);
47978+
47979+#ifdef CONFIG_PAX_ASLR
47980+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47981+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
47982+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
47983+ }
47984+#endif
47985+
47986+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47987+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47988+ executable_stack = EXSTACK_DISABLE_X;
47989+ current->personality &= ~READ_IMPLIES_EXEC;
47990+ } else
47991+#endif
47992+
47993 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
47994 current->personality |= READ_IMPLIES_EXEC;
47995
47996@@ -810,6 +1216,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
47997 #else
47998 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
47999 #endif
48000+
48001+#ifdef CONFIG_PAX_RANDMMAP
48002+ /* PaX: randomize base address at the default exe base if requested */
48003+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48004+#ifdef CONFIG_SPARC64
48005+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48006+#else
48007+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48008+#endif
48009+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48010+ elf_flags |= MAP_FIXED;
48011+ }
48012+#endif
48013+
48014 }
48015
48016 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48017@@ -842,9 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48018 * allowed task size. Note that p_filesz must always be
48019 * <= p_memsz so it is only necessary to check p_memsz.
48020 */
48021- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48022- elf_ppnt->p_memsz > TASK_SIZE ||
48023- TASK_SIZE - elf_ppnt->p_memsz < k) {
48024+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48025+ elf_ppnt->p_memsz > pax_task_size ||
48026+ pax_task_size - elf_ppnt->p_memsz < k) {
48027 /* set_brk can never work. Avoid overflows. */
48028 send_sig(SIGKILL, current, 0);
48029 retval = -EINVAL;
48030@@ -883,17 +1303,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
48031 goto out_free_dentry;
48032 }
48033 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48034- send_sig(SIGSEGV, current, 0);
48035- retval = -EFAULT; /* Nobody gets to see this, but.. */
48036- goto out_free_dentry;
48037+ /*
48038+ * This bss-zeroing can fail if the ELF
48039+ * file specifies odd protections. So
48040+ * we don't check the return value
48041+ */
48042 }
48043
48044+#ifdef CONFIG_PAX_RANDMMAP
48045+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48046+ unsigned long start, size;
48047+
48048+ start = ELF_PAGEALIGN(elf_brk);
48049+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48050+ down_read(&current->mm->mmap_sem);
48051+ retval = -ENOMEM;
48052+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48053+ unsigned long prot = PROT_NONE;
48054+
48055+ up_read(&current->mm->mmap_sem);
48056+ current->mm->aslr_gap += PAGE_ALIGN(size) >> PAGE_SHIFT;
48057+// if (current->personality & ADDR_NO_RANDOMIZE)
48058+// prot = PROT_READ;
48059+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
48060+ retval = IS_ERR_VALUE(start) ? start : 0;
48061+ } else
48062+ up_read(&current->mm->mmap_sem);
48063+ if (retval == 0)
48064+ retval = set_brk(start + size, start + size + PAGE_SIZE);
48065+ if (retval < 0) {
48066+ send_sig(SIGKILL, current, 0);
48067+ goto out_free_dentry;
48068+ }
48069+ }
48070+#endif
48071+
48072 if (elf_interpreter) {
48073- unsigned long interp_map_addr = 0;
48074-
48075 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48076 interpreter,
48077- &interp_map_addr,
48078 load_bias);
48079 if (!IS_ERR((void *)elf_entry)) {
48080 /*
48081@@ -1115,7 +1562,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48082 * Decide what to dump of a segment, part, all or none.
48083 */
48084 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48085- unsigned long mm_flags)
48086+ unsigned long mm_flags, long signr)
48087 {
48088 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48089
48090@@ -1152,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48091 if (vma->vm_file == NULL)
48092 return 0;
48093
48094- if (FILTER(MAPPED_PRIVATE))
48095+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48096 goto whole;
48097
48098 /*
48099@@ -1374,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48100 {
48101 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48102 int i = 0;
48103- do
48104+ do {
48105 i += 2;
48106- while (auxv[i - 2] != AT_NULL);
48107+ } while (auxv[i - 2] != AT_NULL);
48108 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48109 }
48110
48111@@ -2006,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48112 }
48113
48114 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48115- unsigned long mm_flags)
48116+ struct coredump_params *cprm)
48117 {
48118 struct vm_area_struct *vma;
48119 size_t size = 0;
48120
48121 for (vma = first_vma(current, gate_vma); vma != NULL;
48122 vma = next_vma(vma, gate_vma))
48123- size += vma_dump_size(vma, mm_flags);
48124+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48125 return size;
48126 }
48127
48128@@ -2107,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48129
48130 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48131
48132- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48133+ offset += elf_core_vma_data_size(gate_vma, cprm);
48134 offset += elf_core_extra_data_size();
48135 e_shoff = offset;
48136
48137@@ -2121,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48138 offset = dataoff;
48139
48140 size += sizeof(*elf);
48141+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48142 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48143 goto end_coredump;
48144
48145 size += sizeof(*phdr4note);
48146+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48147 if (size > cprm->limit
48148 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48149 goto end_coredump;
48150@@ -2138,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48151 phdr.p_offset = offset;
48152 phdr.p_vaddr = vma->vm_start;
48153 phdr.p_paddr = 0;
48154- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48155+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48156 phdr.p_memsz = vma->vm_end - vma->vm_start;
48157 offset += phdr.p_filesz;
48158 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48159@@ -2149,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48160 phdr.p_align = ELF_EXEC_PAGESIZE;
48161
48162 size += sizeof(phdr);
48163+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48164 if (size > cprm->limit
48165 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48166 goto end_coredump;
48167@@ -2173,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48168 unsigned long addr;
48169 unsigned long end;
48170
48171- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48172+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48173
48174 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48175 struct page *page;
48176@@ -2182,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48177 page = get_dump_page(addr);
48178 if (page) {
48179 void *kaddr = kmap(page);
48180+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48181 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48182 !dump_write(cprm->file, kaddr,
48183 PAGE_SIZE);
48184@@ -2199,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48185
48186 if (e_phnum == PN_XNUM) {
48187 size += sizeof(*shdr4extnum);
48188+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
48189 if (size > cprm->limit
48190 || !dump_write(cprm->file, shdr4extnum,
48191 sizeof(*shdr4extnum)))
48192@@ -2219,6 +2671,97 @@ out:
48193
48194 #endif /* CONFIG_ELF_CORE */
48195
48196+#ifdef CONFIG_PAX_MPROTECT
48197+/* PaX: non-PIC ELF libraries need relocations on their executable segments
48198+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48199+ * we'll remove VM_MAYWRITE for good on RELRO segments.
48200+ *
48201+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48202+ * basis because we want to allow the common case and not the special ones.
48203+ */
48204+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48205+{
48206+ struct elfhdr elf_h;
48207+ struct elf_phdr elf_p;
48208+ unsigned long i;
48209+ unsigned long oldflags;
48210+ bool is_textrel_rw, is_textrel_rx, is_relro;
48211+
48212+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48213+ return;
48214+
48215+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48216+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48217+
48218+#ifdef CONFIG_PAX_ELFRELOCS
48219+ /* possible TEXTREL */
48220+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48221+ 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);
48222+#else
48223+ is_textrel_rw = false;
48224+ is_textrel_rx = false;
48225+#endif
48226+
48227+ /* possible RELRO */
48228+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48229+
48230+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48231+ return;
48232+
48233+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48234+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48235+
48236+#ifdef CONFIG_PAX_ETEXECRELOCS
48237+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48238+#else
48239+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48240+#endif
48241+
48242+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48243+ !elf_check_arch(&elf_h) ||
48244+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48245+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48246+ return;
48247+
48248+ for (i = 0UL; i < elf_h.e_phnum; i++) {
48249+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48250+ return;
48251+ switch (elf_p.p_type) {
48252+ case PT_DYNAMIC:
48253+ if (!is_textrel_rw && !is_textrel_rx)
48254+ continue;
48255+ i = 0UL;
48256+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48257+ elf_dyn dyn;
48258+
48259+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48260+ return;
48261+ if (dyn.d_tag == DT_NULL)
48262+ return;
48263+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48264+ gr_log_textrel(vma);
48265+ if (is_textrel_rw)
48266+ vma->vm_flags |= VM_MAYWRITE;
48267+ else
48268+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48269+ vma->vm_flags &= ~VM_MAYWRITE;
48270+ return;
48271+ }
48272+ i++;
48273+ }
48274+ return;
48275+
48276+ case PT_GNU_RELRO:
48277+ if (!is_relro)
48278+ continue;
48279+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48280+ vma->vm_flags &= ~VM_MAYWRITE;
48281+ return;
48282+ }
48283+ }
48284+}
48285+#endif
48286+
48287 static int __init init_elf_binfmt(void)
48288 {
48289 register_binfmt(&elf_format);
48290diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48291index b563719..3868998 100644
48292--- a/fs/binfmt_flat.c
48293+++ b/fs/binfmt_flat.c
48294@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48295 realdatastart = (unsigned long) -ENOMEM;
48296 printk("Unable to allocate RAM for process data, errno %d\n",
48297 (int)-realdatastart);
48298+ down_write(&current->mm->mmap_sem);
48299 vm_munmap(textpos, text_len);
48300+ up_write(&current->mm->mmap_sem);
48301 ret = realdatastart;
48302 goto err;
48303 }
48304@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48305 }
48306 if (IS_ERR_VALUE(result)) {
48307 printk("Unable to read data+bss, errno %d\n", (int)-result);
48308+ down_write(&current->mm->mmap_sem);
48309 vm_munmap(textpos, text_len);
48310 vm_munmap(realdatastart, len);
48311+ up_write(&current->mm->mmap_sem);
48312 ret = result;
48313 goto err;
48314 }
48315@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48316 }
48317 if (IS_ERR_VALUE(result)) {
48318 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48319+ down_write(&current->mm->mmap_sem);
48320 vm_munmap(textpos, text_len + data_len + extra +
48321 MAX_SHARED_LIBS * sizeof(unsigned long));
48322+ up_write(&current->mm->mmap_sem);
48323 ret = result;
48324 goto err;
48325 }
48326diff --git a/fs/bio.c b/fs/bio.c
48327index b96fc6c..431d628 100644
48328--- a/fs/bio.c
48329+++ b/fs/bio.c
48330@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48331 /*
48332 * Overflow, abort
48333 */
48334- if (end < start)
48335+ if (end < start || end - start > INT_MAX - nr_pages)
48336 return ERR_PTR(-EINVAL);
48337
48338 nr_pages += end - start;
48339@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48340 /*
48341 * Overflow, abort
48342 */
48343- if (end < start)
48344+ if (end < start || end - start > INT_MAX - nr_pages)
48345 return ERR_PTR(-EINVAL);
48346
48347 nr_pages += end - start;
48348@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48349 const int read = bio_data_dir(bio) == READ;
48350 struct bio_map_data *bmd = bio->bi_private;
48351 int i;
48352- char *p = bmd->sgvecs[0].iov_base;
48353+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48354
48355 __bio_for_each_segment(bvec, bio, i, 0) {
48356 char *addr = page_address(bvec->bv_page);
48357diff --git a/fs/block_dev.c b/fs/block_dev.c
48358index 78333a3..23dcb4d 100644
48359--- a/fs/block_dev.c
48360+++ b/fs/block_dev.c
48361@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48362 else if (bdev->bd_contains == bdev)
48363 return true; /* is a whole device which isn't held */
48364
48365- else if (whole->bd_holder == bd_may_claim)
48366+ else if (whole->bd_holder == (void *)bd_may_claim)
48367 return true; /* is a partition of a device that is being partitioned */
48368 else if (whole->bd_holder != NULL)
48369 return false; /* is a partition of a held device */
48370diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48371index eea5da7..88fead70 100644
48372--- a/fs/btrfs/ctree.c
48373+++ b/fs/btrfs/ctree.c
48374@@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48375 free_extent_buffer(buf);
48376 add_root_to_dirty_list(root);
48377 } else {
48378- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48379- parent_start = parent->start;
48380- else
48381+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48382+ if (parent)
48383+ parent_start = parent->start;
48384+ else
48385+ parent_start = 0;
48386+ } else
48387 parent_start = 0;
48388
48389 WARN_ON(trans->transid != btrfs_header_generation(parent));
48390diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48391index cc93b23..f3c42bf 100644
48392--- a/fs/btrfs/inode.c
48393+++ b/fs/btrfs/inode.c
48394@@ -7296,7 +7296,7 @@ fail:
48395 return -ENOMEM;
48396 }
48397
48398-static int btrfs_getattr(struct vfsmount *mnt,
48399+int btrfs_getattr(struct vfsmount *mnt,
48400 struct dentry *dentry, struct kstat *stat)
48401 {
48402 struct inode *inode = dentry->d_inode;
48403@@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48404 return 0;
48405 }
48406
48407+EXPORT_SYMBOL(btrfs_getattr);
48408+
48409+dev_t get_btrfs_dev_from_inode(struct inode *inode)
48410+{
48411+ return BTRFS_I(inode)->root->anon_dev;
48412+}
48413+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48414+
48415 /*
48416 * If a file is moved, it will inherit the cow and compression flags of the new
48417 * directory.
48418diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48419index 338f259..b657640 100644
48420--- a/fs/btrfs/ioctl.c
48421+++ b/fs/btrfs/ioctl.c
48422@@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48423 for (i = 0; i < num_types; i++) {
48424 struct btrfs_space_info *tmp;
48425
48426+ /* Don't copy in more than we allocated */
48427 if (!slot_count)
48428 break;
48429
48430+ slot_count--;
48431+
48432 info = NULL;
48433 rcu_read_lock();
48434 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48435@@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48436 memcpy(dest, &space, sizeof(space));
48437 dest++;
48438 space_args.total_spaces++;
48439- slot_count--;
48440 }
48441- if (!slot_count)
48442- break;
48443 }
48444 up_read(&info->groups_sem);
48445 }
48446diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48447index 300e09a..9fe4539 100644
48448--- a/fs/btrfs/relocation.c
48449+++ b/fs/btrfs/relocation.c
48450@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48451 }
48452 spin_unlock(&rc->reloc_root_tree.lock);
48453
48454- BUG_ON((struct btrfs_root *)node->data != root);
48455+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
48456
48457 if (!del) {
48458 spin_lock(&rc->reloc_root_tree.lock);
48459diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48460index d8982e9..29a85fa 100644
48461--- a/fs/btrfs/super.c
48462+++ b/fs/btrfs/super.c
48463@@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48464 function, line, errstr);
48465 return;
48466 }
48467- ACCESS_ONCE(trans->transaction->aborted) = errno;
48468+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48469 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48470 }
48471 /*
48472diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48473index 622f469..e8d2d55 100644
48474--- a/fs/cachefiles/bind.c
48475+++ b/fs/cachefiles/bind.c
48476@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48477 args);
48478
48479 /* start by checking things over */
48480- ASSERT(cache->fstop_percent >= 0 &&
48481- cache->fstop_percent < cache->fcull_percent &&
48482+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
48483 cache->fcull_percent < cache->frun_percent &&
48484 cache->frun_percent < 100);
48485
48486- ASSERT(cache->bstop_percent >= 0 &&
48487- cache->bstop_percent < cache->bcull_percent &&
48488+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
48489 cache->bcull_percent < cache->brun_percent &&
48490 cache->brun_percent < 100);
48491
48492diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48493index 0a1467b..6a53245 100644
48494--- a/fs/cachefiles/daemon.c
48495+++ b/fs/cachefiles/daemon.c
48496@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48497 if (n > buflen)
48498 return -EMSGSIZE;
48499
48500- if (copy_to_user(_buffer, buffer, n) != 0)
48501+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48502 return -EFAULT;
48503
48504 return n;
48505@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48506 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48507 return -EIO;
48508
48509- if (datalen < 0 || datalen > PAGE_SIZE - 1)
48510+ if (datalen > PAGE_SIZE - 1)
48511 return -EOPNOTSUPP;
48512
48513 /* drag the command string into the kernel so we can parse it */
48514@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48515 if (args[0] != '%' || args[1] != '\0')
48516 return -EINVAL;
48517
48518- if (fstop < 0 || fstop >= cache->fcull_percent)
48519+ if (fstop >= cache->fcull_percent)
48520 return cachefiles_daemon_range_error(cache, args);
48521
48522 cache->fstop_percent = fstop;
48523@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48524 if (args[0] != '%' || args[1] != '\0')
48525 return -EINVAL;
48526
48527- if (bstop < 0 || bstop >= cache->bcull_percent)
48528+ if (bstop >= cache->bcull_percent)
48529 return cachefiles_daemon_range_error(cache, args);
48530
48531 cache->bstop_percent = bstop;
48532diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48533index 4938251..7e01445 100644
48534--- a/fs/cachefiles/internal.h
48535+++ b/fs/cachefiles/internal.h
48536@@ -59,7 +59,7 @@ struct cachefiles_cache {
48537 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48538 struct rb_root active_nodes; /* active nodes (can't be culled) */
48539 rwlock_t active_lock; /* lock for active_nodes */
48540- atomic_t gravecounter; /* graveyard uniquifier */
48541+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48542 unsigned frun_percent; /* when to stop culling (% files) */
48543 unsigned fcull_percent; /* when to start culling (% files) */
48544 unsigned fstop_percent; /* when to stop allocating (% files) */
48545@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48546 * proc.c
48547 */
48548 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48549-extern atomic_t cachefiles_lookup_histogram[HZ];
48550-extern atomic_t cachefiles_mkdir_histogram[HZ];
48551-extern atomic_t cachefiles_create_histogram[HZ];
48552+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48553+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48554+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48555
48556 extern int __init cachefiles_proc_init(void);
48557 extern void cachefiles_proc_cleanup(void);
48558 static inline
48559-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48560+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48561 {
48562 unsigned long jif = jiffies - start_jif;
48563 if (jif >= HZ)
48564 jif = HZ - 1;
48565- atomic_inc(&histogram[jif]);
48566+ atomic_inc_unchecked(&histogram[jif]);
48567 }
48568
48569 #else
48570diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48571index 8c01c5fc..15f982e 100644
48572--- a/fs/cachefiles/namei.c
48573+++ b/fs/cachefiles/namei.c
48574@@ -317,7 +317,7 @@ try_again:
48575 /* first step is to make up a grave dentry in the graveyard */
48576 sprintf(nbuffer, "%08x%08x",
48577 (uint32_t) get_seconds(),
48578- (uint32_t) atomic_inc_return(&cache->gravecounter));
48579+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48580
48581 /* do the multiway lock magic */
48582 trap = lock_rename(cache->graveyard, dir);
48583diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
48584index eccd339..4c1d995 100644
48585--- a/fs/cachefiles/proc.c
48586+++ b/fs/cachefiles/proc.c
48587@@ -14,9 +14,9 @@
48588 #include <linux/seq_file.h>
48589 #include "internal.h"
48590
48591-atomic_t cachefiles_lookup_histogram[HZ];
48592-atomic_t cachefiles_mkdir_histogram[HZ];
48593-atomic_t cachefiles_create_histogram[HZ];
48594+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48595+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48596+atomic_unchecked_t cachefiles_create_histogram[HZ];
48597
48598 /*
48599 * display the latency histogram
48600@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
48601 return 0;
48602 default:
48603 index = (unsigned long) v - 3;
48604- x = atomic_read(&cachefiles_lookup_histogram[index]);
48605- y = atomic_read(&cachefiles_mkdir_histogram[index]);
48606- z = atomic_read(&cachefiles_create_histogram[index]);
48607+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
48608+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
48609+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
48610 if (x == 0 && y == 0 && z == 0)
48611 return 0;
48612
48613diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
48614index 4809922..aab2c39 100644
48615--- a/fs/cachefiles/rdwr.c
48616+++ b/fs/cachefiles/rdwr.c
48617@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
48618 old_fs = get_fs();
48619 set_fs(KERNEL_DS);
48620 ret = file->f_op->write(
48621- file, (const void __user *) data, len, &pos);
48622+ file, (const void __force_user *) data, len, &pos);
48623 set_fs(old_fs);
48624 kunmap(page);
48625 if (ret != len)
48626diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
48627index 8c1aabe..bbf856a 100644
48628--- a/fs/ceph/dir.c
48629+++ b/fs/ceph/dir.c
48630@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
48631 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
48632 struct ceph_mds_client *mdsc = fsc->mdsc;
48633 unsigned frag = fpos_frag(filp->f_pos);
48634- int off = fpos_off(filp->f_pos);
48635+ unsigned int off = fpos_off(filp->f_pos);
48636 int err;
48637 u32 ftype;
48638 struct ceph_mds_reply_info_parsed *rinfo;
48639diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
48640index d9ea6ed..1e6c8ac 100644
48641--- a/fs/cifs/cifs_debug.c
48642+++ b/fs/cifs/cifs_debug.c
48643@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48644
48645 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
48646 #ifdef CONFIG_CIFS_STATS2
48647- atomic_set(&totBufAllocCount, 0);
48648- atomic_set(&totSmBufAllocCount, 0);
48649+ atomic_set_unchecked(&totBufAllocCount, 0);
48650+ atomic_set_unchecked(&totSmBufAllocCount, 0);
48651 #endif /* CONFIG_CIFS_STATS2 */
48652 spin_lock(&cifs_tcp_ses_lock);
48653 list_for_each(tmp1, &cifs_tcp_ses_list) {
48654@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48655 tcon = list_entry(tmp3,
48656 struct cifs_tcon,
48657 tcon_list);
48658- atomic_set(&tcon->num_smbs_sent, 0);
48659+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
48660 if (server->ops->clear_stats)
48661 server->ops->clear_stats(tcon);
48662 }
48663@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48664 smBufAllocCount.counter, cifs_min_small);
48665 #ifdef CONFIG_CIFS_STATS2
48666 seq_printf(m, "Total Large %d Small %d Allocations\n",
48667- atomic_read(&totBufAllocCount),
48668- atomic_read(&totSmBufAllocCount));
48669+ atomic_read_unchecked(&totBufAllocCount),
48670+ atomic_read_unchecked(&totSmBufAllocCount));
48671 #endif /* CONFIG_CIFS_STATS2 */
48672
48673 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
48674@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48675 if (tcon->need_reconnect)
48676 seq_puts(m, "\tDISCONNECTED ");
48677 seq_printf(m, "\nSMBs: %d",
48678- atomic_read(&tcon->num_smbs_sent));
48679+ atomic_read_unchecked(&tcon->num_smbs_sent));
48680 if (server->ops->print_stats)
48681 server->ops->print_stats(m, tcon);
48682 }
48683diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
48684index de7f916..6cb22a9 100644
48685--- a/fs/cifs/cifsfs.c
48686+++ b/fs/cifs/cifsfs.c
48687@@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
48688 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
48689 cifs_req_cachep = kmem_cache_create("cifs_request",
48690 CIFSMaxBufSize + max_hdr_size, 0,
48691- SLAB_HWCACHE_ALIGN, NULL);
48692+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
48693 if (cifs_req_cachep == NULL)
48694 return -ENOMEM;
48695
48696@@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
48697 efficient to alloc 1 per page off the slab compared to 17K (5page)
48698 alloc of large cifs buffers even when page debugging is on */
48699 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
48700- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
48701+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
48702 NULL);
48703 if (cifs_sm_req_cachep == NULL) {
48704 mempool_destroy(cifs_req_poolp);
48705@@ -1109,8 +1109,8 @@ init_cifs(void)
48706 atomic_set(&bufAllocCount, 0);
48707 atomic_set(&smBufAllocCount, 0);
48708 #ifdef CONFIG_CIFS_STATS2
48709- atomic_set(&totBufAllocCount, 0);
48710- atomic_set(&totSmBufAllocCount, 0);
48711+ atomic_set_unchecked(&totBufAllocCount, 0);
48712+ atomic_set_unchecked(&totSmBufAllocCount, 0);
48713 #endif /* CONFIG_CIFS_STATS2 */
48714
48715 atomic_set(&midCount, 0);
48716diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
48717index e6899ce..d6b2920 100644
48718--- a/fs/cifs/cifsglob.h
48719+++ b/fs/cifs/cifsglob.h
48720@@ -751,35 +751,35 @@ struct cifs_tcon {
48721 __u16 Flags; /* optional support bits */
48722 enum statusEnum tidStatus;
48723 #ifdef CONFIG_CIFS_STATS
48724- atomic_t num_smbs_sent;
48725+ atomic_unchecked_t num_smbs_sent;
48726 union {
48727 struct {
48728- atomic_t num_writes;
48729- atomic_t num_reads;
48730- atomic_t num_flushes;
48731- atomic_t num_oplock_brks;
48732- atomic_t num_opens;
48733- atomic_t num_closes;
48734- atomic_t num_deletes;
48735- atomic_t num_mkdirs;
48736- atomic_t num_posixopens;
48737- atomic_t num_posixmkdirs;
48738- atomic_t num_rmdirs;
48739- atomic_t num_renames;
48740- atomic_t num_t2renames;
48741- atomic_t num_ffirst;
48742- atomic_t num_fnext;
48743- atomic_t num_fclose;
48744- atomic_t num_hardlinks;
48745- atomic_t num_symlinks;
48746- atomic_t num_locks;
48747- atomic_t num_acl_get;
48748- atomic_t num_acl_set;
48749+ atomic_unchecked_t num_writes;
48750+ atomic_unchecked_t num_reads;
48751+ atomic_unchecked_t num_flushes;
48752+ atomic_unchecked_t num_oplock_brks;
48753+ atomic_unchecked_t num_opens;
48754+ atomic_unchecked_t num_closes;
48755+ atomic_unchecked_t num_deletes;
48756+ atomic_unchecked_t num_mkdirs;
48757+ atomic_unchecked_t num_posixopens;
48758+ atomic_unchecked_t num_posixmkdirs;
48759+ atomic_unchecked_t num_rmdirs;
48760+ atomic_unchecked_t num_renames;
48761+ atomic_unchecked_t num_t2renames;
48762+ atomic_unchecked_t num_ffirst;
48763+ atomic_unchecked_t num_fnext;
48764+ atomic_unchecked_t num_fclose;
48765+ atomic_unchecked_t num_hardlinks;
48766+ atomic_unchecked_t num_symlinks;
48767+ atomic_unchecked_t num_locks;
48768+ atomic_unchecked_t num_acl_get;
48769+ atomic_unchecked_t num_acl_set;
48770 } cifs_stats;
48771 #ifdef CONFIG_CIFS_SMB2
48772 struct {
48773- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48774- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48775+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48776+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48777 } smb2_stats;
48778 #endif /* CONFIG_CIFS_SMB2 */
48779 } stats;
48780@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
48781 }
48782
48783 #ifdef CONFIG_CIFS_STATS
48784-#define cifs_stats_inc atomic_inc
48785+#define cifs_stats_inc atomic_inc_unchecked
48786
48787 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
48788 unsigned int bytes)
48789@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
48790 /* Various Debug counters */
48791 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
48792 #ifdef CONFIG_CIFS_STATS2
48793-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
48794-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
48795+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
48796+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
48797 #endif
48798 GLOBAL_EXTERN atomic_t smBufAllocCount;
48799 GLOBAL_EXTERN atomic_t midCount;
48800diff --git a/fs/cifs/link.c b/fs/cifs/link.c
48801index 51dc2fb..1e12a33 100644
48802--- a/fs/cifs/link.c
48803+++ b/fs/cifs/link.c
48804@@ -616,7 +616,7 @@ symlink_exit:
48805
48806 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
48807 {
48808- char *p = nd_get_link(nd);
48809+ const char *p = nd_get_link(nd);
48810 if (!IS_ERR(p))
48811 kfree(p);
48812 }
48813diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
48814index 3a00c0d..42d901c 100644
48815--- a/fs/cifs/misc.c
48816+++ b/fs/cifs/misc.c
48817@@ -169,7 +169,7 @@ cifs_buf_get(void)
48818 memset(ret_buf, 0, buf_size + 3);
48819 atomic_inc(&bufAllocCount);
48820 #ifdef CONFIG_CIFS_STATS2
48821- atomic_inc(&totBufAllocCount);
48822+ atomic_inc_unchecked(&totBufAllocCount);
48823 #endif /* CONFIG_CIFS_STATS2 */
48824 }
48825
48826@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
48827 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
48828 atomic_inc(&smBufAllocCount);
48829 #ifdef CONFIG_CIFS_STATS2
48830- atomic_inc(&totSmBufAllocCount);
48831+ atomic_inc_unchecked(&totSmBufAllocCount);
48832 #endif /* CONFIG_CIFS_STATS2 */
48833
48834 }
48835diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
48836index 47bc5a8..10decbe 100644
48837--- a/fs/cifs/smb1ops.c
48838+++ b/fs/cifs/smb1ops.c
48839@@ -586,27 +586,27 @@ static void
48840 cifs_clear_stats(struct cifs_tcon *tcon)
48841 {
48842 #ifdef CONFIG_CIFS_STATS
48843- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
48844- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
48845- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
48846- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48847- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
48848- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
48849- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48850- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
48851- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
48852- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
48853- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
48854- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
48855- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
48856- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
48857- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
48858- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
48859- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
48860- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
48861- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
48862- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
48863- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
48864+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
48865+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
48866+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
48867+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48868+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
48869+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
48870+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48871+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
48872+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
48873+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
48874+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
48875+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
48876+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
48877+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
48878+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
48879+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
48880+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
48881+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
48882+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
48883+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
48884+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
48885 #endif
48886 }
48887
48888@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48889 {
48890 #ifdef CONFIG_CIFS_STATS
48891 seq_printf(m, " Oplocks breaks: %d",
48892- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
48893+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
48894 seq_printf(m, "\nReads: %d Bytes: %llu",
48895- atomic_read(&tcon->stats.cifs_stats.num_reads),
48896+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
48897 (long long)(tcon->bytes_read));
48898 seq_printf(m, "\nWrites: %d Bytes: %llu",
48899- atomic_read(&tcon->stats.cifs_stats.num_writes),
48900+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
48901 (long long)(tcon->bytes_written));
48902 seq_printf(m, "\nFlushes: %d",
48903- atomic_read(&tcon->stats.cifs_stats.num_flushes));
48904+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
48905 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
48906- atomic_read(&tcon->stats.cifs_stats.num_locks),
48907- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
48908- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
48909+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
48910+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
48911+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
48912 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
48913- atomic_read(&tcon->stats.cifs_stats.num_opens),
48914- atomic_read(&tcon->stats.cifs_stats.num_closes),
48915- atomic_read(&tcon->stats.cifs_stats.num_deletes));
48916+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
48917+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
48918+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
48919 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
48920- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
48921- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
48922+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
48923+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
48924 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
48925- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
48926- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
48927+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
48928+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
48929 seq_printf(m, "\nRenames: %d T2 Renames %d",
48930- atomic_read(&tcon->stats.cifs_stats.num_renames),
48931- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
48932+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
48933+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
48934 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
48935- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
48936- atomic_read(&tcon->stats.cifs_stats.num_fnext),
48937- atomic_read(&tcon->stats.cifs_stats.num_fclose));
48938+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
48939+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
48940+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
48941 #endif
48942 }
48943
48944diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
48945index c9c7aa7..065056a 100644
48946--- a/fs/cifs/smb2ops.c
48947+++ b/fs/cifs/smb2ops.c
48948@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
48949 #ifdef CONFIG_CIFS_STATS
48950 int i;
48951 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
48952- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48953- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48954+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48955+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48956 }
48957 #endif
48958 }
48959@@ -284,66 +284,66 @@ static void
48960 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48961 {
48962 #ifdef CONFIG_CIFS_STATS
48963- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48964- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48965+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48966+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48967 seq_printf(m, "\nNegotiates: %d sent %d failed",
48968- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
48969- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
48970+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
48971+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
48972 seq_printf(m, "\nSessionSetups: %d sent %d failed",
48973- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
48974- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
48975+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
48976+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
48977 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
48978 seq_printf(m, "\nLogoffs: %d sent %d failed",
48979- atomic_read(&sent[SMB2_LOGOFF_HE]),
48980- atomic_read(&failed[SMB2_LOGOFF_HE]));
48981+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
48982+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
48983 seq_printf(m, "\nTreeConnects: %d sent %d failed",
48984- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
48985- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
48986+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
48987+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
48988 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
48989- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
48990- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
48991+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
48992+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
48993 seq_printf(m, "\nCreates: %d sent %d failed",
48994- atomic_read(&sent[SMB2_CREATE_HE]),
48995- atomic_read(&failed[SMB2_CREATE_HE]));
48996+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
48997+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
48998 seq_printf(m, "\nCloses: %d sent %d failed",
48999- atomic_read(&sent[SMB2_CLOSE_HE]),
49000- atomic_read(&failed[SMB2_CLOSE_HE]));
49001+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49002+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49003 seq_printf(m, "\nFlushes: %d sent %d failed",
49004- atomic_read(&sent[SMB2_FLUSH_HE]),
49005- atomic_read(&failed[SMB2_FLUSH_HE]));
49006+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49007+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49008 seq_printf(m, "\nReads: %d sent %d failed",
49009- atomic_read(&sent[SMB2_READ_HE]),
49010- atomic_read(&failed[SMB2_READ_HE]));
49011+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
49012+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
49013 seq_printf(m, "\nWrites: %d sent %d failed",
49014- atomic_read(&sent[SMB2_WRITE_HE]),
49015- atomic_read(&failed[SMB2_WRITE_HE]));
49016+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49017+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49018 seq_printf(m, "\nLocks: %d sent %d failed",
49019- atomic_read(&sent[SMB2_LOCK_HE]),
49020- atomic_read(&failed[SMB2_LOCK_HE]));
49021+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49022+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49023 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49024- atomic_read(&sent[SMB2_IOCTL_HE]),
49025- atomic_read(&failed[SMB2_IOCTL_HE]));
49026+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49027+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49028 seq_printf(m, "\nCancels: %d sent %d failed",
49029- atomic_read(&sent[SMB2_CANCEL_HE]),
49030- atomic_read(&failed[SMB2_CANCEL_HE]));
49031+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49032+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49033 seq_printf(m, "\nEchos: %d sent %d failed",
49034- atomic_read(&sent[SMB2_ECHO_HE]),
49035- atomic_read(&failed[SMB2_ECHO_HE]));
49036+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49037+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49038 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49039- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49040- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49041+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49042+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49043 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49044- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49045- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49046+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49047+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49048 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49049- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49050- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49051+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49052+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49053 seq_printf(m, "\nSetInfos: %d sent %d failed",
49054- atomic_read(&sent[SMB2_SET_INFO_HE]),
49055- atomic_read(&failed[SMB2_SET_INFO_HE]));
49056+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49057+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49058 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49059- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49060- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49061+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49062+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49063 #endif
49064 }
49065
49066diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49067index 41d9d07..dbb4772 100644
49068--- a/fs/cifs/smb2pdu.c
49069+++ b/fs/cifs/smb2pdu.c
49070@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49071 default:
49072 cERROR(1, "info level %u isn't supported",
49073 srch_inf->info_level);
49074- rc = -EINVAL;
49075- goto qdir_exit;
49076+ return -EINVAL;
49077 }
49078
49079 req->FileIndex = cpu_to_le32(index);
49080diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49081index 958ae0e..505c9d0 100644
49082--- a/fs/coda/cache.c
49083+++ b/fs/coda/cache.c
49084@@ -24,7 +24,7 @@
49085 #include "coda_linux.h"
49086 #include "coda_cache.h"
49087
49088-static atomic_t permission_epoch = ATOMIC_INIT(0);
49089+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49090
49091 /* replace or extend an acl cache hit */
49092 void coda_cache_enter(struct inode *inode, int mask)
49093@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49094 struct coda_inode_info *cii = ITOC(inode);
49095
49096 spin_lock(&cii->c_lock);
49097- cii->c_cached_epoch = atomic_read(&permission_epoch);
49098+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49099 if (cii->c_uid != current_fsuid()) {
49100 cii->c_uid = current_fsuid();
49101 cii->c_cached_perm = mask;
49102@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49103 {
49104 struct coda_inode_info *cii = ITOC(inode);
49105 spin_lock(&cii->c_lock);
49106- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49107+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49108 spin_unlock(&cii->c_lock);
49109 }
49110
49111 /* remove all acl caches */
49112 void coda_cache_clear_all(struct super_block *sb)
49113 {
49114- atomic_inc(&permission_epoch);
49115+ atomic_inc_unchecked(&permission_epoch);
49116 }
49117
49118
49119@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49120 spin_lock(&cii->c_lock);
49121 hit = (mask & cii->c_cached_perm) == mask &&
49122 cii->c_uid == current_fsuid() &&
49123- cii->c_cached_epoch == atomic_read(&permission_epoch);
49124+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49125 spin_unlock(&cii->c_lock);
49126
49127 return hit;
49128diff --git a/fs/compat.c b/fs/compat.c
49129index 015e1e1..b8966ac 100644
49130--- a/fs/compat.c
49131+++ b/fs/compat.c
49132@@ -54,7 +54,7 @@
49133 #include <asm/ioctls.h>
49134 #include "internal.h"
49135
49136-int compat_log = 1;
49137+int compat_log = 0;
49138
49139 int compat_printk(const char *fmt, ...)
49140 {
49141@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49142
49143 set_fs(KERNEL_DS);
49144 /* The __user pointer cast is valid because of the set_fs() */
49145- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49146+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49147 set_fs(oldfs);
49148 /* truncating is ok because it's a user address */
49149 if (!ret)
49150@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49151 goto out;
49152
49153 ret = -EINVAL;
49154- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49155+ if (nr_segs > UIO_MAXIOV)
49156 goto out;
49157 if (nr_segs > fast_segs) {
49158 ret = -ENOMEM;
49159@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
49160
49161 struct compat_readdir_callback {
49162 struct compat_old_linux_dirent __user *dirent;
49163+ struct file * file;
49164 int result;
49165 };
49166
49167@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49168 buf->result = -EOVERFLOW;
49169 return -EOVERFLOW;
49170 }
49171+
49172+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49173+ return 0;
49174+
49175 buf->result++;
49176 dirent = buf->dirent;
49177 if (!access_ok(VERIFY_WRITE, dirent,
49178@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49179
49180 buf.result = 0;
49181 buf.dirent = dirent;
49182+ buf.file = f.file;
49183
49184 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49185 if (buf.result)
49186@@ -897,6 +903,7 @@ struct compat_linux_dirent {
49187 struct compat_getdents_callback {
49188 struct compat_linux_dirent __user *current_dir;
49189 struct compat_linux_dirent __user *previous;
49190+ struct file * file;
49191 int count;
49192 int error;
49193 };
49194@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49195 buf->error = -EOVERFLOW;
49196 return -EOVERFLOW;
49197 }
49198+
49199+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49200+ return 0;
49201+
49202 dirent = buf->previous;
49203 if (dirent) {
49204 if (__put_user(offset, &dirent->d_off))
49205@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49206 buf.previous = NULL;
49207 buf.count = count;
49208 buf.error = 0;
49209+ buf.file = f.file;
49210
49211 error = vfs_readdir(f.file, compat_filldir, &buf);
49212 if (error >= 0)
49213@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49214 struct compat_getdents_callback64 {
49215 struct linux_dirent64 __user *current_dir;
49216 struct linux_dirent64 __user *previous;
49217+ struct file * file;
49218 int count;
49219 int error;
49220 };
49221@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49222 buf->error = -EINVAL; /* only used if we fail.. */
49223 if (reclen > buf->count)
49224 return -EINVAL;
49225+
49226+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49227+ return 0;
49228+
49229 dirent = buf->previous;
49230
49231 if (dirent) {
49232@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49233 buf.previous = NULL;
49234 buf.count = count;
49235 buf.error = 0;
49236+ buf.file = f.file;
49237
49238 error = vfs_readdir(f.file, compat_filldir64, &buf);
49239 if (error >= 0)
49240 error = buf.error;
49241 lastdirent = buf.previous;
49242 if (lastdirent) {
49243- typeof(lastdirent->d_off) d_off = f.file->f_pos;
49244+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49245 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49246 error = -EFAULT;
49247 else
49248diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49249index a81147e..20bf2b5 100644
49250--- a/fs/compat_binfmt_elf.c
49251+++ b/fs/compat_binfmt_elf.c
49252@@ -30,11 +30,13 @@
49253 #undef elf_phdr
49254 #undef elf_shdr
49255 #undef elf_note
49256+#undef elf_dyn
49257 #undef elf_addr_t
49258 #define elfhdr elf32_hdr
49259 #define elf_phdr elf32_phdr
49260 #define elf_shdr elf32_shdr
49261 #define elf_note elf32_note
49262+#define elf_dyn Elf32_Dyn
49263 #define elf_addr_t Elf32_Addr
49264
49265 /*
49266diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49267index e2f57a0..3c78771 100644
49268--- a/fs/compat_ioctl.c
49269+++ b/fs/compat_ioctl.c
49270@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49271 return -EFAULT;
49272 if (__get_user(udata, &ss32->iomem_base))
49273 return -EFAULT;
49274- ss.iomem_base = compat_ptr(udata);
49275+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49276 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49277 __get_user(ss.port_high, &ss32->port_high))
49278 return -EFAULT;
49279@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49280 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49281 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49282 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49283- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49284+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49285 return -EFAULT;
49286
49287 return ioctl_preallocate(file, p);
49288@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49289 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49290 {
49291 unsigned int a, b;
49292- a = *(unsigned int *)p;
49293- b = *(unsigned int *)q;
49294+ a = *(const unsigned int *)p;
49295+ b = *(const unsigned int *)q;
49296 if (a > b)
49297 return 1;
49298 if (a < b)
49299diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49300index 712b10f..c33c4ca 100644
49301--- a/fs/configfs/dir.c
49302+++ b/fs/configfs/dir.c
49303@@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49304 static int configfs_depend_prep(struct dentry *origin,
49305 struct config_item *target)
49306 {
49307- struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49308+ struct configfs_dirent *child_sd, *sd;
49309 int ret = 0;
49310
49311- BUG_ON(!origin || !sd);
49312+ BUG_ON(!origin || !origin->d_fsdata);
49313+ sd = origin->d_fsdata;
49314
49315 if (sd->s_element == target) /* Boo-yah */
49316 goto out;
49317@@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49318 }
49319 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49320 struct configfs_dirent *next;
49321- const char * name;
49322+ const unsigned char * name;
49323+ char d_name[sizeof(next->s_dentry->d_iname)];
49324 int len;
49325 struct inode *inode = NULL;
49326
49327@@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49328 continue;
49329
49330 name = configfs_get_name(next);
49331- len = strlen(name);
49332+ if (next->s_dentry && name == next->s_dentry->d_iname) {
49333+ len = next->s_dentry->d_name.len;
49334+ memcpy(d_name, name, len);
49335+ name = d_name;
49336+ } else
49337+ len = strlen(name);
49338
49339 /*
49340 * We'll have a dentry and an inode for
49341diff --git a/fs/coredump.c b/fs/coredump.c
49342index 1774932..5812106 100644
49343--- a/fs/coredump.c
49344+++ b/fs/coredump.c
49345@@ -52,7 +52,7 @@ struct core_name {
49346 char *corename;
49347 int used, size;
49348 };
49349-static atomic_t call_count = ATOMIC_INIT(1);
49350+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49351
49352 /* The maximal length of core_pattern is also specified in sysctl.c */
49353
49354@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49355 {
49356 char *old_corename = cn->corename;
49357
49358- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49359+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49360 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49361
49362 if (!cn->corename) {
49363@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49364 int pid_in_pattern = 0;
49365 int err = 0;
49366
49367- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49368+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49369 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49370 cn->used = 0;
49371
49372@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49373 pipe = file->f_path.dentry->d_inode->i_pipe;
49374
49375 pipe_lock(pipe);
49376- pipe->readers++;
49377- pipe->writers--;
49378+ atomic_inc(&pipe->readers);
49379+ atomic_dec(&pipe->writers);
49380
49381- while ((pipe->readers > 1) && (!signal_pending(current))) {
49382+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49383 wake_up_interruptible_sync(&pipe->wait);
49384 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49385 pipe_wait(pipe);
49386 }
49387
49388- pipe->readers--;
49389- pipe->writers++;
49390+ atomic_dec(&pipe->readers);
49391+ atomic_inc(&pipe->writers);
49392 pipe_unlock(pipe);
49393
49394 }
49395@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49396 int ispipe;
49397 struct files_struct *displaced;
49398 bool need_nonrelative = false;
49399- static atomic_t core_dump_count = ATOMIC_INIT(0);
49400+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49401+ long signr = siginfo->si_signo;
49402 struct coredump_params cprm = {
49403 .siginfo = siginfo,
49404 .regs = signal_pt_regs(),
49405@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49406 .mm_flags = mm->flags,
49407 };
49408
49409- audit_core_dumps(siginfo->si_signo);
49410+ audit_core_dumps(signr);
49411+
49412+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49413+ gr_handle_brute_attach(cprm.mm_flags);
49414
49415 binfmt = mm->binfmt;
49416 if (!binfmt || !binfmt->core_dump)
49417@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49418 need_nonrelative = true;
49419 }
49420
49421- retval = coredump_wait(siginfo->si_signo, &core_state);
49422+ retval = coredump_wait(signr, &core_state);
49423 if (retval < 0)
49424 goto fail_creds;
49425
49426@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49427 }
49428 cprm.limit = RLIM_INFINITY;
49429
49430- dump_count = atomic_inc_return(&core_dump_count);
49431+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
49432 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49433 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49434 task_tgid_vnr(current), current->comm);
49435@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49436 } else {
49437 struct inode *inode;
49438
49439+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49440+
49441 if (cprm.limit < binfmt->min_coredump)
49442 goto fail_unlock;
49443
49444@@ -640,7 +646,7 @@ close_fail:
49445 filp_close(cprm.file, NULL);
49446 fail_dropcount:
49447 if (ispipe)
49448- atomic_dec(&core_dump_count);
49449+ atomic_dec_unchecked(&core_dump_count);
49450 fail_unlock:
49451 kfree(cn.corename);
49452 fail_corename:
49453@@ -659,7 +665,7 @@ fail:
49454 */
49455 int dump_write(struct file *file, const void *addr, int nr)
49456 {
49457- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49458+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49459 }
49460 EXPORT_SYMBOL(dump_write);
49461
49462diff --git a/fs/dcache.c b/fs/dcache.c
49463index 19153a0..428c2f5 100644
49464--- a/fs/dcache.c
49465+++ b/fs/dcache.c
49466@@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49467 mempages -= reserve;
49468
49469 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49470- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49471+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49472
49473 dcache_init();
49474 inode_init();
49475diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49476index a5f12b7..4ee8a6f 100644
49477--- a/fs/debugfs/inode.c
49478+++ b/fs/debugfs/inode.c
49479@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49480 */
49481 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49482 {
49483+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49484+ return __create_file(name, S_IFDIR | S_IRWXU,
49485+#else
49486 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49487+#endif
49488 parent, NULL, NULL);
49489 }
49490 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49491diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49492index cc7709e..7e7211f 100644
49493--- a/fs/ecryptfs/inode.c
49494+++ b/fs/ecryptfs/inode.c
49495@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49496 old_fs = get_fs();
49497 set_fs(get_ds());
49498 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49499- (char __user *)lower_buf,
49500+ (char __force_user *)lower_buf,
49501 PATH_MAX);
49502 set_fs(old_fs);
49503 if (rc < 0)
49504@@ -706,7 +706,7 @@ out:
49505 static void
49506 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49507 {
49508- char *buf = nd_get_link(nd);
49509+ const char *buf = nd_get_link(nd);
49510 if (!IS_ERR(buf)) {
49511 /* Free the char* */
49512 kfree(buf);
49513diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49514index 412e6ed..4292d22 100644
49515--- a/fs/ecryptfs/miscdev.c
49516+++ b/fs/ecryptfs/miscdev.c
49517@@ -315,7 +315,7 @@ check_list:
49518 goto out_unlock_msg_ctx;
49519 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49520 if (msg_ctx->msg) {
49521- if (copy_to_user(&buf[i], packet_length, packet_length_size))
49522+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49523 goto out_unlock_msg_ctx;
49524 i += packet_length_size;
49525 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49526diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49527index b2a34a1..162fa69 100644
49528--- a/fs/ecryptfs/read_write.c
49529+++ b/fs/ecryptfs/read_write.c
49530@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49531 return -EIO;
49532 fs_save = get_fs();
49533 set_fs(get_ds());
49534- rc = vfs_write(lower_file, data, size, &offset);
49535+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49536 set_fs(fs_save);
49537 mark_inode_dirty_sync(ecryptfs_inode);
49538 return rc;
49539@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49540 return -EIO;
49541 fs_save = get_fs();
49542 set_fs(get_ds());
49543- rc = vfs_read(lower_file, data, size, &offset);
49544+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49545 set_fs(fs_save);
49546 return rc;
49547 }
49548diff --git a/fs/exec.c b/fs/exec.c
49549index 20df02c..81c9e78 100644
49550--- a/fs/exec.c
49551+++ b/fs/exec.c
49552@@ -55,6 +55,17 @@
49553 #include <linux/pipe_fs_i.h>
49554 #include <linux/oom.h>
49555 #include <linux/compat.h>
49556+#include <linux/random.h>
49557+#include <linux/seq_file.h>
49558+#include <linux/coredump.h>
49559+#include <linux/mman.h>
49560+
49561+#ifdef CONFIG_PAX_REFCOUNT
49562+#include <linux/kallsyms.h>
49563+#include <linux/kdebug.h>
49564+#endif
49565+
49566+#include <trace/events/fs.h>
49567
49568 #include <asm/uaccess.h>
49569 #include <asm/mmu_context.h>
49570@@ -66,6 +77,18 @@
49571
49572 #include <trace/events/sched.h>
49573
49574+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49575+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49576+{
49577+ 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");
49578+}
49579+#endif
49580+
49581+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
49582+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
49583+EXPORT_SYMBOL(pax_set_initial_flags_func);
49584+#endif
49585+
49586 int suid_dumpable = 0;
49587
49588 static LIST_HEAD(formats);
49589@@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
49590 {
49591 BUG_ON(!fmt);
49592 write_lock(&binfmt_lock);
49593- insert ? list_add(&fmt->lh, &formats) :
49594- list_add_tail(&fmt->lh, &formats);
49595+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
49596+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
49597 write_unlock(&binfmt_lock);
49598 }
49599
49600@@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
49601 void unregister_binfmt(struct linux_binfmt * fmt)
49602 {
49603 write_lock(&binfmt_lock);
49604- list_del(&fmt->lh);
49605+ pax_list_del((struct list_head *)&fmt->lh);
49606 write_unlock(&binfmt_lock);
49607 }
49608
49609@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49610 int write)
49611 {
49612 struct page *page;
49613- int ret;
49614
49615-#ifdef CONFIG_STACK_GROWSUP
49616- if (write) {
49617- ret = expand_downwards(bprm->vma, pos);
49618- if (ret < 0)
49619- return NULL;
49620- }
49621-#endif
49622- ret = get_user_pages(current, bprm->mm, pos,
49623- 1, write, 1, &page, NULL);
49624- if (ret <= 0)
49625+ if (0 > expand_downwards(bprm->vma, pos))
49626+ return NULL;
49627+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
49628 return NULL;
49629
49630 if (write) {
49631@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49632 if (size <= ARG_MAX)
49633 return page;
49634
49635+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49636+ // only allow 512KB for argv+env on suid/sgid binaries
49637+ // to prevent easy ASLR exhaustion
49638+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
49639+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
49640+ (size > (512 * 1024))) {
49641+ put_page(page);
49642+ return NULL;
49643+ }
49644+#endif
49645+
49646 /*
49647 * Limit to 1/4-th the stack size for the argv+env strings.
49648 * This ensures that:
49649@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49650 vma->vm_end = STACK_TOP_MAX;
49651 vma->vm_start = vma->vm_end - PAGE_SIZE;
49652 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
49653+
49654+#ifdef CONFIG_PAX_SEGMEXEC
49655+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
49656+#endif
49657+
49658 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
49659 INIT_LIST_HEAD(&vma->anon_vma_chain);
49660
49661@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49662 mm->stack_vm = mm->total_vm = 1;
49663 up_write(&mm->mmap_sem);
49664 bprm->p = vma->vm_end - sizeof(void *);
49665+
49666+#ifdef CONFIG_PAX_RANDUSTACK
49667+ if (randomize_va_space)
49668+ bprm->p ^= random32() & ~PAGE_MASK;
49669+#endif
49670+
49671 return 0;
49672 err:
49673 up_write(&mm->mmap_sem);
49674@@ -384,19 +421,7 @@ err:
49675 return err;
49676 }
49677
49678-struct user_arg_ptr {
49679-#ifdef CONFIG_COMPAT
49680- bool is_compat;
49681-#endif
49682- union {
49683- const char __user *const __user *native;
49684-#ifdef CONFIG_COMPAT
49685- const compat_uptr_t __user *compat;
49686-#endif
49687- } ptr;
49688-};
49689-
49690-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49691+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49692 {
49693 const char __user *native;
49694
49695@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49696 compat_uptr_t compat;
49697
49698 if (get_user(compat, argv.ptr.compat + nr))
49699- return ERR_PTR(-EFAULT);
49700+ return (const char __force_user *)ERR_PTR(-EFAULT);
49701
49702 return compat_ptr(compat);
49703 }
49704 #endif
49705
49706 if (get_user(native, argv.ptr.native + nr))
49707- return ERR_PTR(-EFAULT);
49708+ return (const char __force_user *)ERR_PTR(-EFAULT);
49709
49710 return native;
49711 }
49712@@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
49713 if (!p)
49714 break;
49715
49716- if (IS_ERR(p))
49717+ if (IS_ERR((const char __force_kernel *)p))
49718 return -EFAULT;
49719
49720 if (i >= max)
49721@@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
49722
49723 ret = -EFAULT;
49724 str = get_user_arg_ptr(argv, argc);
49725- if (IS_ERR(str))
49726+ if (IS_ERR((const char __force_kernel *)str))
49727 goto out;
49728
49729 len = strnlen_user(str, MAX_ARG_STRLEN);
49730@@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
49731 int r;
49732 mm_segment_t oldfs = get_fs();
49733 struct user_arg_ptr argv = {
49734- .ptr.native = (const char __user *const __user *)__argv,
49735+ .ptr.native = (const char __force_user *const __force_user *)__argv,
49736 };
49737
49738 set_fs(KERNEL_DS);
49739@@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49740 unsigned long new_end = old_end - shift;
49741 struct mmu_gather tlb;
49742
49743- BUG_ON(new_start > new_end);
49744+ if (new_start >= new_end || new_start < mmap_min_addr)
49745+ return -ENOMEM;
49746
49747 /*
49748 * ensure there are no vmas between where we want to go
49749@@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49750 if (vma != find_vma(mm, new_start))
49751 return -EFAULT;
49752
49753+#ifdef CONFIG_PAX_SEGMEXEC
49754+ BUG_ON(pax_find_mirror_vma(vma));
49755+#endif
49756+
49757 /*
49758 * cover the whole range: [new_start, old_end)
49759 */
49760@@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49761 stack_top = arch_align_stack(stack_top);
49762 stack_top = PAGE_ALIGN(stack_top);
49763
49764- if (unlikely(stack_top < mmap_min_addr) ||
49765- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
49766- return -ENOMEM;
49767-
49768 stack_shift = vma->vm_end - stack_top;
49769
49770 bprm->p -= stack_shift;
49771@@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
49772 bprm->exec -= stack_shift;
49773
49774 down_write(&mm->mmap_sem);
49775+
49776+ /* Move stack pages down in memory. */
49777+ if (stack_shift) {
49778+ ret = shift_arg_pages(vma, stack_shift);
49779+ if (ret)
49780+ goto out_unlock;
49781+ }
49782+
49783 vm_flags = VM_STACK_FLAGS;
49784
49785+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49786+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49787+ vm_flags &= ~VM_EXEC;
49788+
49789+#ifdef CONFIG_PAX_MPROTECT
49790+ if (mm->pax_flags & MF_PAX_MPROTECT)
49791+ vm_flags &= ~VM_MAYEXEC;
49792+#endif
49793+
49794+ }
49795+#endif
49796+
49797 /*
49798 * Adjust stack execute permissions; explicitly enable for
49799 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
49800@@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49801 goto out_unlock;
49802 BUG_ON(prev != vma);
49803
49804- /* Move stack pages down in memory. */
49805- if (stack_shift) {
49806- ret = shift_arg_pages(vma, stack_shift);
49807- if (ret)
49808- goto out_unlock;
49809- }
49810-
49811 /* mprotect_fixup is overkill to remove the temporary stack flags */
49812 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
49813
49814@@ -737,6 +776,30 @@ int setup_arg_pages(struct linux_binprm *bprm,
49815 #endif
49816 current->mm->start_stack = bprm->p;
49817 ret = expand_stack(vma, stack_base);
49818+
49819+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
49820+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
49821+ unsigned long size, flags, vm_flags;
49822+
49823+ size = STACK_TOP - vma->vm_end;
49824+ flags = MAP_FIXED | MAP_PRIVATE;
49825+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
49826+
49827+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
49828+
49829+#ifdef CONFIG_X86
49830+ if (!ret) {
49831+ current->mm->aslr_gap += size >> PAGE_SHIFT;
49832+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
49833+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
49834+ if (!ret)
49835+ current->mm->aslr_gap += size >> PAGE_SHIFT;
49836+ }
49837+#endif
49838+
49839+ }
49840+#endif
49841+
49842 if (ret)
49843 ret = -EFAULT;
49844
49845@@ -772,6 +835,8 @@ struct file *open_exec(const char *name)
49846
49847 fsnotify_open(file);
49848
49849+ trace_open_exec(name);
49850+
49851 err = deny_write_access(file);
49852 if (err)
49853 goto exit;
49854@@ -795,7 +860,7 @@ int kernel_read(struct file *file, loff_t offset,
49855 old_fs = get_fs();
49856 set_fs(get_ds());
49857 /* The cast to a user pointer is valid due to the set_fs() */
49858- result = vfs_read(file, (void __user *)addr, count, &pos);
49859+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
49860 set_fs(old_fs);
49861 return result;
49862 }
49863@@ -1247,7 +1312,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
49864 }
49865 rcu_read_unlock();
49866
49867- if (p->fs->users > n_fs) {
49868+ if (atomic_read(&p->fs->users) > n_fs) {
49869 bprm->unsafe |= LSM_UNSAFE_SHARE;
49870 } else {
49871 res = -EAGAIN;
49872@@ -1447,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm)
49873
49874 EXPORT_SYMBOL(search_binary_handler);
49875
49876+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49877+static DEFINE_PER_CPU(u64, exec_counter);
49878+static int __init init_exec_counters(void)
49879+{
49880+ unsigned int cpu;
49881+
49882+ for_each_possible_cpu(cpu) {
49883+ per_cpu(exec_counter, cpu) = (u64)cpu;
49884+ }
49885+
49886+ return 0;
49887+}
49888+early_initcall(init_exec_counters);
49889+static inline void increment_exec_counter(void)
49890+{
49891+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
49892+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
49893+}
49894+#else
49895+static inline void increment_exec_counter(void) {}
49896+#endif
49897+
49898 /*
49899 * sys_execve() executes a new program.
49900 */
49901@@ -1454,6 +1541,11 @@ static int do_execve_common(const char *filename,
49902 struct user_arg_ptr argv,
49903 struct user_arg_ptr envp)
49904 {
49905+#ifdef CONFIG_GRKERNSEC
49906+ struct file *old_exec_file;
49907+ struct acl_subject_label *old_acl;
49908+ struct rlimit old_rlim[RLIM_NLIMITS];
49909+#endif
49910 struct linux_binprm *bprm;
49911 struct file *file;
49912 struct files_struct *displaced;
49913@@ -1461,6 +1553,8 @@ static int do_execve_common(const char *filename,
49914 int retval;
49915 const struct cred *cred = current_cred();
49916
49917+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
49918+
49919 /*
49920 * We move the actual failure in case of RLIMIT_NPROC excess from
49921 * set*uid() to execve() because too many poorly written programs
49922@@ -1501,12 +1595,27 @@ static int do_execve_common(const char *filename,
49923 if (IS_ERR(file))
49924 goto out_unmark;
49925
49926+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
49927+ retval = -EPERM;
49928+ goto out_file;
49929+ }
49930+
49931 sched_exec();
49932
49933 bprm->file = file;
49934 bprm->filename = filename;
49935 bprm->interp = filename;
49936
49937+ if (gr_process_user_ban()) {
49938+ retval = -EPERM;
49939+ goto out_file;
49940+ }
49941+
49942+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
49943+ retval = -EACCES;
49944+ goto out_file;
49945+ }
49946+
49947 retval = bprm_mm_init(bprm);
49948 if (retval)
49949 goto out_file;
49950@@ -1523,24 +1632,65 @@ static int do_execve_common(const char *filename,
49951 if (retval < 0)
49952 goto out;
49953
49954+#ifdef CONFIG_GRKERNSEC
49955+ old_acl = current->acl;
49956+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
49957+ old_exec_file = current->exec_file;
49958+ get_file(file);
49959+ current->exec_file = file;
49960+#endif
49961+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49962+ /* limit suid stack to 8MB
49963+ * we saved the old limits above and will restore them if this exec fails
49964+ */
49965+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
49966+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
49967+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
49968+#endif
49969+
49970+ if (!gr_tpe_allow(file)) {
49971+ retval = -EACCES;
49972+ goto out_fail;
49973+ }
49974+
49975+ if (gr_check_crash_exec(file)) {
49976+ retval = -EACCES;
49977+ goto out_fail;
49978+ }
49979+
49980+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
49981+ bprm->unsafe);
49982+ if (retval < 0)
49983+ goto out_fail;
49984+
49985 retval = copy_strings_kernel(1, &bprm->filename, bprm);
49986 if (retval < 0)
49987- goto out;
49988+ goto out_fail;
49989
49990 bprm->exec = bprm->p;
49991 retval = copy_strings(bprm->envc, envp, bprm);
49992 if (retval < 0)
49993- goto out;
49994+ goto out_fail;
49995
49996 retval = copy_strings(bprm->argc, argv, bprm);
49997 if (retval < 0)
49998- goto out;
49999+ goto out_fail;
50000+
50001+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50002+
50003+ gr_handle_exec_args(bprm, argv);
50004
50005 retval = search_binary_handler(bprm);
50006 if (retval < 0)
50007- goto out;
50008+ goto out_fail;
50009+#ifdef CONFIG_GRKERNSEC
50010+ if (old_exec_file)
50011+ fput(old_exec_file);
50012+#endif
50013
50014 /* execve succeeded */
50015+
50016+ increment_exec_counter();
50017 current->fs->in_exec = 0;
50018 current->in_execve = 0;
50019 acct_update_integrals(current);
50020@@ -1549,6 +1699,14 @@ static int do_execve_common(const char *filename,
50021 put_files_struct(displaced);
50022 return retval;
50023
50024+out_fail:
50025+#ifdef CONFIG_GRKERNSEC
50026+ current->acl = old_acl;
50027+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50028+ fput(current->exec_file);
50029+ current->exec_file = old_exec_file;
50030+#endif
50031+
50032 out:
50033 if (bprm->mm) {
50034 acct_arg_size(bprm, 0);
50035@@ -1697,3 +1855,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50036 return error;
50037 }
50038 #endif
50039+
50040+int pax_check_flags(unsigned long *flags)
50041+{
50042+ int retval = 0;
50043+
50044+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50045+ if (*flags & MF_PAX_SEGMEXEC)
50046+ {
50047+ *flags &= ~MF_PAX_SEGMEXEC;
50048+ retval = -EINVAL;
50049+ }
50050+#endif
50051+
50052+ if ((*flags & MF_PAX_PAGEEXEC)
50053+
50054+#ifdef CONFIG_PAX_PAGEEXEC
50055+ && (*flags & MF_PAX_SEGMEXEC)
50056+#endif
50057+
50058+ )
50059+ {
50060+ *flags &= ~MF_PAX_PAGEEXEC;
50061+ retval = -EINVAL;
50062+ }
50063+
50064+ if ((*flags & MF_PAX_MPROTECT)
50065+
50066+#ifdef CONFIG_PAX_MPROTECT
50067+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50068+#endif
50069+
50070+ )
50071+ {
50072+ *flags &= ~MF_PAX_MPROTECT;
50073+ retval = -EINVAL;
50074+ }
50075+
50076+ if ((*flags & MF_PAX_EMUTRAMP)
50077+
50078+#ifdef CONFIG_PAX_EMUTRAMP
50079+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50080+#endif
50081+
50082+ )
50083+ {
50084+ *flags &= ~MF_PAX_EMUTRAMP;
50085+ retval = -EINVAL;
50086+ }
50087+
50088+ return retval;
50089+}
50090+
50091+EXPORT_SYMBOL(pax_check_flags);
50092+
50093+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50094+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50095+{
50096+ struct task_struct *tsk = current;
50097+ struct mm_struct *mm = current->mm;
50098+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50099+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50100+ char *path_exec = NULL;
50101+ char *path_fault = NULL;
50102+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
50103+ siginfo_t info = { };
50104+
50105+ if (buffer_exec && buffer_fault) {
50106+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50107+
50108+ down_read(&mm->mmap_sem);
50109+ vma = mm->mmap;
50110+ while (vma && (!vma_exec || !vma_fault)) {
50111+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50112+ vma_exec = vma;
50113+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50114+ vma_fault = vma;
50115+ vma = vma->vm_next;
50116+ }
50117+ if (vma_exec) {
50118+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50119+ if (IS_ERR(path_exec))
50120+ path_exec = "<path too long>";
50121+ else {
50122+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50123+ if (path_exec) {
50124+ *path_exec = 0;
50125+ path_exec = buffer_exec;
50126+ } else
50127+ path_exec = "<path too long>";
50128+ }
50129+ }
50130+ if (vma_fault) {
50131+ start = vma_fault->vm_start;
50132+ end = vma_fault->vm_end;
50133+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50134+ if (vma_fault->vm_file) {
50135+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50136+ if (IS_ERR(path_fault))
50137+ path_fault = "<path too long>";
50138+ else {
50139+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50140+ if (path_fault) {
50141+ *path_fault = 0;
50142+ path_fault = buffer_fault;
50143+ } else
50144+ path_fault = "<path too long>";
50145+ }
50146+ } else
50147+ path_fault = "<anonymous mapping>";
50148+ }
50149+ up_read(&mm->mmap_sem);
50150+ }
50151+ if (tsk->signal->curr_ip)
50152+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50153+ else
50154+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50155+ 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),
50156+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
50157+ free_page((unsigned long)buffer_exec);
50158+ free_page((unsigned long)buffer_fault);
50159+ pax_report_insns(regs, pc, sp);
50160+ info.si_signo = SIGKILL;
50161+ info.si_errno = 0;
50162+ info.si_code = SI_KERNEL;
50163+ info.si_pid = 0;
50164+ info.si_uid = 0;
50165+ do_coredump(&info);
50166+}
50167+#endif
50168+
50169+#ifdef CONFIG_PAX_REFCOUNT
50170+void pax_report_refcount_overflow(struct pt_regs *regs)
50171+{
50172+ if (current->signal->curr_ip)
50173+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50174+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
50175+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50176+ else
50177+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50178+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50179+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50180+ show_regs(regs);
50181+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50182+}
50183+#endif
50184+
50185+#ifdef CONFIG_PAX_USERCOPY
50186+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50187+static noinline int check_stack_object(const void *obj, unsigned long len)
50188+{
50189+ const void * const stack = task_stack_page(current);
50190+ const void * const stackend = stack + THREAD_SIZE;
50191+
50192+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50193+ const void *frame = NULL;
50194+ const void *oldframe;
50195+#endif
50196+
50197+ if (obj + len < obj)
50198+ return -1;
50199+
50200+ if (obj + len <= stack || stackend <= obj)
50201+ return 0;
50202+
50203+ if (obj < stack || stackend < obj + len)
50204+ return -1;
50205+
50206+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50207+ oldframe = __builtin_frame_address(1);
50208+ if (oldframe)
50209+ frame = __builtin_frame_address(2);
50210+ /*
50211+ low ----------------------------------------------> high
50212+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
50213+ ^----------------^
50214+ allow copies only within here
50215+ */
50216+ while (stack <= frame && frame < stackend) {
50217+ /* if obj + len extends past the last frame, this
50218+ check won't pass and the next frame will be 0,
50219+ causing us to bail out and correctly report
50220+ the copy as invalid
50221+ */
50222+ if (obj + len <= frame)
50223+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50224+ oldframe = frame;
50225+ frame = *(const void * const *)frame;
50226+ }
50227+ return -1;
50228+#else
50229+ return 1;
50230+#endif
50231+}
50232+
50233+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50234+{
50235+ if (current->signal->curr_ip)
50236+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50237+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50238+ else
50239+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50240+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50241+ dump_stack();
50242+ gr_handle_kernel_exploit();
50243+ do_group_exit(SIGKILL);
50244+}
50245+#endif
50246+
50247+void __check_object_size(const void *ptr, unsigned long n, bool to)
50248+{
50249+
50250+#ifdef CONFIG_PAX_USERCOPY
50251+ const char *type;
50252+
50253+ if (!n)
50254+ return;
50255+
50256+ type = check_heap_object(ptr, n);
50257+ if (!type) {
50258+ if (check_stack_object(ptr, n) != -1)
50259+ return;
50260+ type = "<process stack>";
50261+ }
50262+
50263+ pax_report_usercopy(ptr, n, to, type);
50264+#endif
50265+
50266+}
50267+EXPORT_SYMBOL(__check_object_size);
50268+
50269+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50270+void pax_track_stack(void)
50271+{
50272+ unsigned long sp = (unsigned long)&sp;
50273+ if (sp < current_thread_info()->lowest_stack &&
50274+ sp > (unsigned long)task_stack_page(current))
50275+ current_thread_info()->lowest_stack = sp;
50276+}
50277+EXPORT_SYMBOL(pax_track_stack);
50278+#endif
50279+
50280+#ifdef CONFIG_PAX_SIZE_OVERFLOW
50281+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50282+{
50283+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50284+ dump_stack();
50285+ do_group_exit(SIGKILL);
50286+}
50287+EXPORT_SYMBOL(report_size_overflow);
50288+#endif
50289diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50290index 2616d0e..2ffdec9 100644
50291--- a/fs/ext2/balloc.c
50292+++ b/fs/ext2/balloc.c
50293@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50294
50295 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50296 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50297- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50298+ if (free_blocks < root_blocks + 1 &&
50299 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50300 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50301- !in_group_p (sbi->s_resgid))) {
50302+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50303 return 0;
50304 }
50305 return 1;
50306diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50307index 22548f5..41521d8 100644
50308--- a/fs/ext3/balloc.c
50309+++ b/fs/ext3/balloc.c
50310@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50311
50312 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50313 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50314- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50315+ if (free_blocks < root_blocks + 1 &&
50316 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50317 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50318- !in_group_p (sbi->s_resgid))) {
50319+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50320 return 0;
50321 }
50322 return 1;
50323diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50324index 2f2e0da..89b113a 100644
50325--- a/fs/ext4/balloc.c
50326+++ b/fs/ext4/balloc.c
50327@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50328 /* Hm, nope. Are (enough) root reserved clusters available? */
50329 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50330 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50331- capable(CAP_SYS_RESOURCE) ||
50332- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50333+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50334+ capable_nolog(CAP_SYS_RESOURCE)) {
50335
50336 if (free_clusters >= (nclusters + dirty_clusters))
50337 return 1;
50338diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50339index 8462eb3..4a71af6 100644
50340--- a/fs/ext4/ext4.h
50341+++ b/fs/ext4/ext4.h
50342@@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50343 unsigned long s_mb_last_start;
50344
50345 /* stats for buddy allocator */
50346- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50347- atomic_t s_bal_success; /* we found long enough chunks */
50348- atomic_t s_bal_allocated; /* in blocks */
50349- atomic_t s_bal_ex_scanned; /* total extents scanned */
50350- atomic_t s_bal_goals; /* goal hits */
50351- atomic_t s_bal_breaks; /* too long searches */
50352- atomic_t s_bal_2orders; /* 2^order hits */
50353+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50354+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50355+ atomic_unchecked_t s_bal_allocated; /* in blocks */
50356+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50357+ atomic_unchecked_t s_bal_goals; /* goal hits */
50358+ atomic_unchecked_t s_bal_breaks; /* too long searches */
50359+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50360 spinlock_t s_bal_lock;
50361 unsigned long s_mb_buddies_generated;
50362 unsigned long long s_mb_generation_time;
50363- atomic_t s_mb_lost_chunks;
50364- atomic_t s_mb_preallocated;
50365- atomic_t s_mb_discarded;
50366+ atomic_unchecked_t s_mb_lost_chunks;
50367+ atomic_unchecked_t s_mb_preallocated;
50368+ atomic_unchecked_t s_mb_discarded;
50369 atomic_t s_lock_busy;
50370
50371 /* locality groups */
50372diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50373index 061727a..7622abf 100644
50374--- a/fs/ext4/mballoc.c
50375+++ b/fs/ext4/mballoc.c
50376@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50377 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50378
50379 if (EXT4_SB(sb)->s_mb_stats)
50380- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50381+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50382
50383 break;
50384 }
50385@@ -2044,7 +2044,7 @@ repeat:
50386 ac->ac_status = AC_STATUS_CONTINUE;
50387 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50388 cr = 3;
50389- atomic_inc(&sbi->s_mb_lost_chunks);
50390+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50391 goto repeat;
50392 }
50393 }
50394@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50395 if (sbi->s_mb_stats) {
50396 ext4_msg(sb, KERN_INFO,
50397 "mballoc: %u blocks %u reqs (%u success)",
50398- atomic_read(&sbi->s_bal_allocated),
50399- atomic_read(&sbi->s_bal_reqs),
50400- atomic_read(&sbi->s_bal_success));
50401+ atomic_read_unchecked(&sbi->s_bal_allocated),
50402+ atomic_read_unchecked(&sbi->s_bal_reqs),
50403+ atomic_read_unchecked(&sbi->s_bal_success));
50404 ext4_msg(sb, KERN_INFO,
50405 "mballoc: %u extents scanned, %u goal hits, "
50406 "%u 2^N hits, %u breaks, %u lost",
50407- atomic_read(&sbi->s_bal_ex_scanned),
50408- atomic_read(&sbi->s_bal_goals),
50409- atomic_read(&sbi->s_bal_2orders),
50410- atomic_read(&sbi->s_bal_breaks),
50411- atomic_read(&sbi->s_mb_lost_chunks));
50412+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50413+ atomic_read_unchecked(&sbi->s_bal_goals),
50414+ atomic_read_unchecked(&sbi->s_bal_2orders),
50415+ atomic_read_unchecked(&sbi->s_bal_breaks),
50416+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50417 ext4_msg(sb, KERN_INFO,
50418 "mballoc: %lu generated and it took %Lu",
50419 sbi->s_mb_buddies_generated,
50420 sbi->s_mb_generation_time);
50421 ext4_msg(sb, KERN_INFO,
50422 "mballoc: %u preallocated, %u discarded",
50423- atomic_read(&sbi->s_mb_preallocated),
50424- atomic_read(&sbi->s_mb_discarded));
50425+ atomic_read_unchecked(&sbi->s_mb_preallocated),
50426+ atomic_read_unchecked(&sbi->s_mb_discarded));
50427 }
50428
50429 free_percpu(sbi->s_locality_groups);
50430@@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50431 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50432
50433 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50434- atomic_inc(&sbi->s_bal_reqs);
50435- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50436+ atomic_inc_unchecked(&sbi->s_bal_reqs);
50437+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50438 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50439- atomic_inc(&sbi->s_bal_success);
50440- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50441+ atomic_inc_unchecked(&sbi->s_bal_success);
50442+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50443 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50444 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50445- atomic_inc(&sbi->s_bal_goals);
50446+ atomic_inc_unchecked(&sbi->s_bal_goals);
50447 if (ac->ac_found > sbi->s_mb_max_to_scan)
50448- atomic_inc(&sbi->s_bal_breaks);
50449+ atomic_inc_unchecked(&sbi->s_bal_breaks);
50450 }
50451
50452 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50453@@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50454 trace_ext4_mb_new_inode_pa(ac, pa);
50455
50456 ext4_mb_use_inode_pa(ac, pa);
50457- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50458+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50459
50460 ei = EXT4_I(ac->ac_inode);
50461 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50462@@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50463 trace_ext4_mb_new_group_pa(ac, pa);
50464
50465 ext4_mb_use_group_pa(ac, pa);
50466- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50467+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50468
50469 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50470 lg = ac->ac_lg;
50471@@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50472 * from the bitmap and continue.
50473 */
50474 }
50475- atomic_add(free, &sbi->s_mb_discarded);
50476+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
50477
50478 return err;
50479 }
50480@@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50481 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50482 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50483 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50484- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50485+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50486 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50487
50488 return 0;
50489diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50490index 0465f36..99a003a 100644
50491--- a/fs/ext4/super.c
50492+++ b/fs/ext4/super.c
50493@@ -2429,7 +2429,7 @@ struct ext4_attr {
50494 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50495 const char *, size_t);
50496 int offset;
50497-};
50498+} __do_const;
50499
50500 static int parse_strtoul(const char *buf,
50501 unsigned long max, unsigned long *value)
50502diff --git a/fs/fcntl.c b/fs/fcntl.c
50503index 71a600a..20d87b1 100644
50504--- a/fs/fcntl.c
50505+++ b/fs/fcntl.c
50506@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50507 if (err)
50508 return err;
50509
50510+ if (gr_handle_chroot_fowner(pid, type))
50511+ return -ENOENT;
50512+ if (gr_check_protected_task_fowner(pid, type))
50513+ return -EACCES;
50514+
50515 f_modown(filp, pid, type, force);
50516 return 0;
50517 }
50518diff --git a/fs/fhandle.c b/fs/fhandle.c
50519index 999ff5c..41f4109 100644
50520--- a/fs/fhandle.c
50521+++ b/fs/fhandle.c
50522@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50523 } else
50524 retval = 0;
50525 /* copy the mount id */
50526- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50527- sizeof(*mnt_id)) ||
50528+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50529 copy_to_user(ufh, handle,
50530 sizeof(struct file_handle) + handle_bytes))
50531 retval = -EFAULT;
50532diff --git a/fs/fifo.c b/fs/fifo.c
50533index cf6f434..3d7942c 100644
50534--- a/fs/fifo.c
50535+++ b/fs/fifo.c
50536@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50537 */
50538 filp->f_op = &read_pipefifo_fops;
50539 pipe->r_counter++;
50540- if (pipe->readers++ == 0)
50541+ if (atomic_inc_return(&pipe->readers) == 1)
50542 wake_up_partner(inode);
50543
50544- if (!pipe->writers) {
50545+ if (!atomic_read(&pipe->writers)) {
50546 if ((filp->f_flags & O_NONBLOCK)) {
50547 /* suppress POLLHUP until we have
50548 * seen a writer */
50549@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50550 * errno=ENXIO when there is no process reading the FIFO.
50551 */
50552 ret = -ENXIO;
50553- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50554+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50555 goto err;
50556
50557 filp->f_op = &write_pipefifo_fops;
50558 pipe->w_counter++;
50559- if (!pipe->writers++)
50560+ if (atomic_inc_return(&pipe->writers) == 1)
50561 wake_up_partner(inode);
50562
50563- if (!pipe->readers) {
50564+ if (!atomic_read(&pipe->readers)) {
50565 if (wait_for_partner(inode, &pipe->r_counter))
50566 goto err_wr;
50567 }
50568@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50569 */
50570 filp->f_op = &rdwr_pipefifo_fops;
50571
50572- pipe->readers++;
50573- pipe->writers++;
50574+ atomic_inc(&pipe->readers);
50575+ atomic_inc(&pipe->writers);
50576 pipe->r_counter++;
50577 pipe->w_counter++;
50578- if (pipe->readers == 1 || pipe->writers == 1)
50579+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50580 wake_up_partner(inode);
50581 break;
50582
50583@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50584 return 0;
50585
50586 err_rd:
50587- if (!--pipe->readers)
50588+ if (atomic_dec_and_test(&pipe->readers))
50589 wake_up_interruptible(&pipe->wait);
50590 ret = -ERESTARTSYS;
50591 goto err;
50592
50593 err_wr:
50594- if (!--pipe->writers)
50595+ if (atomic_dec_and_test(&pipe->writers))
50596 wake_up_interruptible(&pipe->wait);
50597 ret = -ERESTARTSYS;
50598 goto err;
50599
50600 err:
50601- if (!pipe->readers && !pipe->writers)
50602+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
50603 free_pipe_info(inode);
50604
50605 err_nocleanup:
50606diff --git a/fs/file.c b/fs/file.c
50607index 2b3570b..c57924b 100644
50608--- a/fs/file.c
50609+++ b/fs/file.c
50610@@ -16,6 +16,7 @@
50611 #include <linux/slab.h>
50612 #include <linux/vmalloc.h>
50613 #include <linux/file.h>
50614+#include <linux/security.h>
50615 #include <linux/fdtable.h>
50616 #include <linux/bitops.h>
50617 #include <linux/interrupt.h>
50618@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
50619 if (!file)
50620 return __close_fd(files, fd);
50621
50622+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
50623 if (fd >= rlimit(RLIMIT_NOFILE))
50624 return -EBADF;
50625
50626@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
50627 if (unlikely(oldfd == newfd))
50628 return -EINVAL;
50629
50630+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
50631 if (newfd >= rlimit(RLIMIT_NOFILE))
50632 return -EBADF;
50633
50634@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
50635 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
50636 {
50637 int err;
50638+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
50639 if (from >= rlimit(RLIMIT_NOFILE))
50640 return -EINVAL;
50641 err = alloc_fd(from, flags);
50642diff --git a/fs/filesystems.c b/fs/filesystems.c
50643index da165f6..3671bdb 100644
50644--- a/fs/filesystems.c
50645+++ b/fs/filesystems.c
50646@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
50647 int len = dot ? dot - name : strlen(name);
50648
50649 fs = __get_fs_type(name, len);
50650+
50651+#ifdef CONFIG_GRKERNSEC_MODHARDEN
50652+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
50653+#else
50654 if (!fs && (request_module("%.*s", len, name) == 0))
50655+#endif
50656 fs = __get_fs_type(name, len);
50657
50658 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
50659diff --git a/fs/fs_struct.c b/fs/fs_struct.c
50660index fe6ca58..65318cf 100644
50661--- a/fs/fs_struct.c
50662+++ b/fs/fs_struct.c
50663@@ -4,6 +4,7 @@
50664 #include <linux/path.h>
50665 #include <linux/slab.h>
50666 #include <linux/fs_struct.h>
50667+#include <linux/grsecurity.h>
50668 #include "internal.h"
50669
50670 /*
50671@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
50672 write_seqcount_begin(&fs->seq);
50673 old_root = fs->root;
50674 fs->root = *path;
50675+ gr_set_chroot_entries(current, path);
50676 write_seqcount_end(&fs->seq);
50677 spin_unlock(&fs->lock);
50678 if (old_root.dentry)
50679@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
50680 return 1;
50681 }
50682
50683+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
50684+{
50685+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
50686+ return 0;
50687+ *p = *new;
50688+
50689+ /* This function is only called from pivot_root(). Leave our
50690+ gr_chroot_dentry and is_chrooted flags as-is, so that a
50691+ pivoted root isn't treated as a chroot
50692+ */
50693+ //gr_set_chroot_entries(task, new);
50694+
50695+ return 1;
50696+}
50697+
50698 void chroot_fs_refs(struct path *old_root, struct path *new_root)
50699 {
50700 struct task_struct *g, *p;
50701@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
50702 int hits = 0;
50703 spin_lock(&fs->lock);
50704 write_seqcount_begin(&fs->seq);
50705- hits += replace_path(&fs->root, old_root, new_root);
50706+ hits += replace_root_path(p, &fs->root, old_root, new_root);
50707 hits += replace_path(&fs->pwd, old_root, new_root);
50708 write_seqcount_end(&fs->seq);
50709 while (hits--) {
50710@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
50711 task_lock(tsk);
50712 spin_lock(&fs->lock);
50713 tsk->fs = NULL;
50714- kill = !--fs->users;
50715+ gr_clear_chroot_entries(tsk);
50716+ kill = !atomic_dec_return(&fs->users);
50717 spin_unlock(&fs->lock);
50718 task_unlock(tsk);
50719 if (kill)
50720@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50721 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
50722 /* We don't need to lock fs - think why ;-) */
50723 if (fs) {
50724- fs->users = 1;
50725+ atomic_set(&fs->users, 1);
50726 fs->in_exec = 0;
50727 spin_lock_init(&fs->lock);
50728 seqcount_init(&fs->seq);
50729@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50730 spin_lock(&old->lock);
50731 fs->root = old->root;
50732 path_get(&fs->root);
50733+ /* instead of calling gr_set_chroot_entries here,
50734+ we call it from every caller of this function
50735+ */
50736 fs->pwd = old->pwd;
50737 path_get(&fs->pwd);
50738 spin_unlock(&old->lock);
50739@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
50740
50741 task_lock(current);
50742 spin_lock(&fs->lock);
50743- kill = !--fs->users;
50744+ kill = !atomic_dec_return(&fs->users);
50745 current->fs = new_fs;
50746+ gr_set_chroot_entries(current, &new_fs->root);
50747 spin_unlock(&fs->lock);
50748 task_unlock(current);
50749
50750@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
50751
50752 int current_umask(void)
50753 {
50754- return current->fs->umask;
50755+ return current->fs->umask | gr_acl_umask();
50756 }
50757 EXPORT_SYMBOL(current_umask);
50758
50759 /* to be mentioned only in INIT_TASK */
50760 struct fs_struct init_fs = {
50761- .users = 1,
50762+ .users = ATOMIC_INIT(1),
50763 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
50764 .seq = SEQCNT_ZERO,
50765 .umask = 0022,
50766diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
50767index 8dcb114..b1072e2 100644
50768--- a/fs/fscache/cookie.c
50769+++ b/fs/fscache/cookie.c
50770@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
50771 parent ? (char *) parent->def->name : "<no-parent>",
50772 def->name, netfs_data);
50773
50774- fscache_stat(&fscache_n_acquires);
50775+ fscache_stat_unchecked(&fscache_n_acquires);
50776
50777 /* if there's no parent cookie, then we don't create one here either */
50778 if (!parent) {
50779- fscache_stat(&fscache_n_acquires_null);
50780+ fscache_stat_unchecked(&fscache_n_acquires_null);
50781 _leave(" [no parent]");
50782 return NULL;
50783 }
50784@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
50785 /* allocate and initialise a cookie */
50786 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
50787 if (!cookie) {
50788- fscache_stat(&fscache_n_acquires_oom);
50789+ fscache_stat_unchecked(&fscache_n_acquires_oom);
50790 _leave(" [ENOMEM]");
50791 return NULL;
50792 }
50793@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50794
50795 switch (cookie->def->type) {
50796 case FSCACHE_COOKIE_TYPE_INDEX:
50797- fscache_stat(&fscache_n_cookie_index);
50798+ fscache_stat_unchecked(&fscache_n_cookie_index);
50799 break;
50800 case FSCACHE_COOKIE_TYPE_DATAFILE:
50801- fscache_stat(&fscache_n_cookie_data);
50802+ fscache_stat_unchecked(&fscache_n_cookie_data);
50803 break;
50804 default:
50805- fscache_stat(&fscache_n_cookie_special);
50806+ fscache_stat_unchecked(&fscache_n_cookie_special);
50807 break;
50808 }
50809
50810@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50811 if (fscache_acquire_non_index_cookie(cookie) < 0) {
50812 atomic_dec(&parent->n_children);
50813 __fscache_cookie_put(cookie);
50814- fscache_stat(&fscache_n_acquires_nobufs);
50815+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
50816 _leave(" = NULL");
50817 return NULL;
50818 }
50819 }
50820
50821- fscache_stat(&fscache_n_acquires_ok);
50822+ fscache_stat_unchecked(&fscache_n_acquires_ok);
50823 _leave(" = %p", cookie);
50824 return cookie;
50825 }
50826@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
50827 cache = fscache_select_cache_for_object(cookie->parent);
50828 if (!cache) {
50829 up_read(&fscache_addremove_sem);
50830- fscache_stat(&fscache_n_acquires_no_cache);
50831+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
50832 _leave(" = -ENOMEDIUM [no cache]");
50833 return -ENOMEDIUM;
50834 }
50835@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
50836 object = cache->ops->alloc_object(cache, cookie);
50837 fscache_stat_d(&fscache_n_cop_alloc_object);
50838 if (IS_ERR(object)) {
50839- fscache_stat(&fscache_n_object_no_alloc);
50840+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
50841 ret = PTR_ERR(object);
50842 goto error;
50843 }
50844
50845- fscache_stat(&fscache_n_object_alloc);
50846+ fscache_stat_unchecked(&fscache_n_object_alloc);
50847
50848 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
50849
50850@@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
50851
50852 _enter("{%s}", cookie->def->name);
50853
50854- fscache_stat(&fscache_n_invalidates);
50855+ fscache_stat_unchecked(&fscache_n_invalidates);
50856
50857 /* Only permit invalidation of data files. Invalidating an index will
50858 * require the caller to release all its attachments to the tree rooted
50859@@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
50860 struct fscache_object *object;
50861 struct hlist_node *_p;
50862
50863- fscache_stat(&fscache_n_updates);
50864+ fscache_stat_unchecked(&fscache_n_updates);
50865
50866 if (!cookie) {
50867- fscache_stat(&fscache_n_updates_null);
50868+ fscache_stat_unchecked(&fscache_n_updates_null);
50869 _leave(" [no cookie]");
50870 return;
50871 }
50872@@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50873 struct fscache_object *object;
50874 unsigned long event;
50875
50876- fscache_stat(&fscache_n_relinquishes);
50877+ fscache_stat_unchecked(&fscache_n_relinquishes);
50878 if (retire)
50879- fscache_stat(&fscache_n_relinquishes_retire);
50880+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
50881
50882 if (!cookie) {
50883- fscache_stat(&fscache_n_relinquishes_null);
50884+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
50885 _leave(" [no cookie]");
50886 return;
50887 }
50888@@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50889
50890 /* wait for the cookie to finish being instantiated (or to fail) */
50891 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
50892- fscache_stat(&fscache_n_relinquishes_waitcrt);
50893+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
50894 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
50895 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
50896 }
50897diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
50898index ee38fef..0a326d4 100644
50899--- a/fs/fscache/internal.h
50900+++ b/fs/fscache/internal.h
50901@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
50902 * stats.c
50903 */
50904 #ifdef CONFIG_FSCACHE_STATS
50905-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50906-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50907+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50908+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50909
50910-extern atomic_t fscache_n_op_pend;
50911-extern atomic_t fscache_n_op_run;
50912-extern atomic_t fscache_n_op_enqueue;
50913-extern atomic_t fscache_n_op_deferred_release;
50914-extern atomic_t fscache_n_op_release;
50915-extern atomic_t fscache_n_op_gc;
50916-extern atomic_t fscache_n_op_cancelled;
50917-extern atomic_t fscache_n_op_rejected;
50918+extern atomic_unchecked_t fscache_n_op_pend;
50919+extern atomic_unchecked_t fscache_n_op_run;
50920+extern atomic_unchecked_t fscache_n_op_enqueue;
50921+extern atomic_unchecked_t fscache_n_op_deferred_release;
50922+extern atomic_unchecked_t fscache_n_op_release;
50923+extern atomic_unchecked_t fscache_n_op_gc;
50924+extern atomic_unchecked_t fscache_n_op_cancelled;
50925+extern atomic_unchecked_t fscache_n_op_rejected;
50926
50927-extern atomic_t fscache_n_attr_changed;
50928-extern atomic_t fscache_n_attr_changed_ok;
50929-extern atomic_t fscache_n_attr_changed_nobufs;
50930-extern atomic_t fscache_n_attr_changed_nomem;
50931-extern atomic_t fscache_n_attr_changed_calls;
50932+extern atomic_unchecked_t fscache_n_attr_changed;
50933+extern atomic_unchecked_t fscache_n_attr_changed_ok;
50934+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
50935+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
50936+extern atomic_unchecked_t fscache_n_attr_changed_calls;
50937
50938-extern atomic_t fscache_n_allocs;
50939-extern atomic_t fscache_n_allocs_ok;
50940-extern atomic_t fscache_n_allocs_wait;
50941-extern atomic_t fscache_n_allocs_nobufs;
50942-extern atomic_t fscache_n_allocs_intr;
50943-extern atomic_t fscache_n_allocs_object_dead;
50944-extern atomic_t fscache_n_alloc_ops;
50945-extern atomic_t fscache_n_alloc_op_waits;
50946+extern atomic_unchecked_t fscache_n_allocs;
50947+extern atomic_unchecked_t fscache_n_allocs_ok;
50948+extern atomic_unchecked_t fscache_n_allocs_wait;
50949+extern atomic_unchecked_t fscache_n_allocs_nobufs;
50950+extern atomic_unchecked_t fscache_n_allocs_intr;
50951+extern atomic_unchecked_t fscache_n_allocs_object_dead;
50952+extern atomic_unchecked_t fscache_n_alloc_ops;
50953+extern atomic_unchecked_t fscache_n_alloc_op_waits;
50954
50955-extern atomic_t fscache_n_retrievals;
50956-extern atomic_t fscache_n_retrievals_ok;
50957-extern atomic_t fscache_n_retrievals_wait;
50958-extern atomic_t fscache_n_retrievals_nodata;
50959-extern atomic_t fscache_n_retrievals_nobufs;
50960-extern atomic_t fscache_n_retrievals_intr;
50961-extern atomic_t fscache_n_retrievals_nomem;
50962-extern atomic_t fscache_n_retrievals_object_dead;
50963-extern atomic_t fscache_n_retrieval_ops;
50964-extern atomic_t fscache_n_retrieval_op_waits;
50965+extern atomic_unchecked_t fscache_n_retrievals;
50966+extern atomic_unchecked_t fscache_n_retrievals_ok;
50967+extern atomic_unchecked_t fscache_n_retrievals_wait;
50968+extern atomic_unchecked_t fscache_n_retrievals_nodata;
50969+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
50970+extern atomic_unchecked_t fscache_n_retrievals_intr;
50971+extern atomic_unchecked_t fscache_n_retrievals_nomem;
50972+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
50973+extern atomic_unchecked_t fscache_n_retrieval_ops;
50974+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
50975
50976-extern atomic_t fscache_n_stores;
50977-extern atomic_t fscache_n_stores_ok;
50978-extern atomic_t fscache_n_stores_again;
50979-extern atomic_t fscache_n_stores_nobufs;
50980-extern atomic_t fscache_n_stores_oom;
50981-extern atomic_t fscache_n_store_ops;
50982-extern atomic_t fscache_n_store_calls;
50983-extern atomic_t fscache_n_store_pages;
50984-extern atomic_t fscache_n_store_radix_deletes;
50985-extern atomic_t fscache_n_store_pages_over_limit;
50986+extern atomic_unchecked_t fscache_n_stores;
50987+extern atomic_unchecked_t fscache_n_stores_ok;
50988+extern atomic_unchecked_t fscache_n_stores_again;
50989+extern atomic_unchecked_t fscache_n_stores_nobufs;
50990+extern atomic_unchecked_t fscache_n_stores_oom;
50991+extern atomic_unchecked_t fscache_n_store_ops;
50992+extern atomic_unchecked_t fscache_n_store_calls;
50993+extern atomic_unchecked_t fscache_n_store_pages;
50994+extern atomic_unchecked_t fscache_n_store_radix_deletes;
50995+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
50996
50997-extern atomic_t fscache_n_store_vmscan_not_storing;
50998-extern atomic_t fscache_n_store_vmscan_gone;
50999-extern atomic_t fscache_n_store_vmscan_busy;
51000-extern atomic_t fscache_n_store_vmscan_cancelled;
51001-extern atomic_t fscache_n_store_vmscan_wait;
51002+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51003+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51004+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51005+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51006+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51007
51008-extern atomic_t fscache_n_marks;
51009-extern atomic_t fscache_n_uncaches;
51010+extern atomic_unchecked_t fscache_n_marks;
51011+extern atomic_unchecked_t fscache_n_uncaches;
51012
51013-extern atomic_t fscache_n_acquires;
51014-extern atomic_t fscache_n_acquires_null;
51015-extern atomic_t fscache_n_acquires_no_cache;
51016-extern atomic_t fscache_n_acquires_ok;
51017-extern atomic_t fscache_n_acquires_nobufs;
51018-extern atomic_t fscache_n_acquires_oom;
51019+extern atomic_unchecked_t fscache_n_acquires;
51020+extern atomic_unchecked_t fscache_n_acquires_null;
51021+extern atomic_unchecked_t fscache_n_acquires_no_cache;
51022+extern atomic_unchecked_t fscache_n_acquires_ok;
51023+extern atomic_unchecked_t fscache_n_acquires_nobufs;
51024+extern atomic_unchecked_t fscache_n_acquires_oom;
51025
51026-extern atomic_t fscache_n_invalidates;
51027-extern atomic_t fscache_n_invalidates_run;
51028+extern atomic_unchecked_t fscache_n_invalidates;
51029+extern atomic_unchecked_t fscache_n_invalidates_run;
51030
51031-extern atomic_t fscache_n_updates;
51032-extern atomic_t fscache_n_updates_null;
51033-extern atomic_t fscache_n_updates_run;
51034+extern atomic_unchecked_t fscache_n_updates;
51035+extern atomic_unchecked_t fscache_n_updates_null;
51036+extern atomic_unchecked_t fscache_n_updates_run;
51037
51038-extern atomic_t fscache_n_relinquishes;
51039-extern atomic_t fscache_n_relinquishes_null;
51040-extern atomic_t fscache_n_relinquishes_waitcrt;
51041-extern atomic_t fscache_n_relinquishes_retire;
51042+extern atomic_unchecked_t fscache_n_relinquishes;
51043+extern atomic_unchecked_t fscache_n_relinquishes_null;
51044+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51045+extern atomic_unchecked_t fscache_n_relinquishes_retire;
51046
51047-extern atomic_t fscache_n_cookie_index;
51048-extern atomic_t fscache_n_cookie_data;
51049-extern atomic_t fscache_n_cookie_special;
51050+extern atomic_unchecked_t fscache_n_cookie_index;
51051+extern atomic_unchecked_t fscache_n_cookie_data;
51052+extern atomic_unchecked_t fscache_n_cookie_special;
51053
51054-extern atomic_t fscache_n_object_alloc;
51055-extern atomic_t fscache_n_object_no_alloc;
51056-extern atomic_t fscache_n_object_lookups;
51057-extern atomic_t fscache_n_object_lookups_negative;
51058-extern atomic_t fscache_n_object_lookups_positive;
51059-extern atomic_t fscache_n_object_lookups_timed_out;
51060-extern atomic_t fscache_n_object_created;
51061-extern atomic_t fscache_n_object_avail;
51062-extern atomic_t fscache_n_object_dead;
51063+extern atomic_unchecked_t fscache_n_object_alloc;
51064+extern atomic_unchecked_t fscache_n_object_no_alloc;
51065+extern atomic_unchecked_t fscache_n_object_lookups;
51066+extern atomic_unchecked_t fscache_n_object_lookups_negative;
51067+extern atomic_unchecked_t fscache_n_object_lookups_positive;
51068+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51069+extern atomic_unchecked_t fscache_n_object_created;
51070+extern atomic_unchecked_t fscache_n_object_avail;
51071+extern atomic_unchecked_t fscache_n_object_dead;
51072
51073-extern atomic_t fscache_n_checkaux_none;
51074-extern atomic_t fscache_n_checkaux_okay;
51075-extern atomic_t fscache_n_checkaux_update;
51076-extern atomic_t fscache_n_checkaux_obsolete;
51077+extern atomic_unchecked_t fscache_n_checkaux_none;
51078+extern atomic_unchecked_t fscache_n_checkaux_okay;
51079+extern atomic_unchecked_t fscache_n_checkaux_update;
51080+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51081
51082 extern atomic_t fscache_n_cop_alloc_object;
51083 extern atomic_t fscache_n_cop_lookup_object;
51084@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51085 atomic_inc(stat);
51086 }
51087
51088+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51089+{
51090+ atomic_inc_unchecked(stat);
51091+}
51092+
51093 static inline void fscache_stat_d(atomic_t *stat)
51094 {
51095 atomic_dec(stat);
51096@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51097
51098 #define __fscache_stat(stat) (NULL)
51099 #define fscache_stat(stat) do {} while (0)
51100+#define fscache_stat_unchecked(stat) do {} while (0)
51101 #define fscache_stat_d(stat) do {} while (0)
51102 #endif
51103
51104diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51105index 50d41c1..10ee117 100644
51106--- a/fs/fscache/object.c
51107+++ b/fs/fscache/object.c
51108@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51109 /* Invalidate an object on disk */
51110 case FSCACHE_OBJECT_INVALIDATING:
51111 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51112- fscache_stat(&fscache_n_invalidates_run);
51113+ fscache_stat_unchecked(&fscache_n_invalidates_run);
51114 fscache_stat(&fscache_n_cop_invalidate_object);
51115 fscache_invalidate_object(object);
51116 fscache_stat_d(&fscache_n_cop_invalidate_object);
51117@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51118 /* update the object metadata on disk */
51119 case FSCACHE_OBJECT_UPDATING:
51120 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51121- fscache_stat(&fscache_n_updates_run);
51122+ fscache_stat_unchecked(&fscache_n_updates_run);
51123 fscache_stat(&fscache_n_cop_update_object);
51124 object->cache->ops->update_object(object);
51125 fscache_stat_d(&fscache_n_cop_update_object);
51126@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51127 spin_lock(&object->lock);
51128 object->state = FSCACHE_OBJECT_DEAD;
51129 spin_unlock(&object->lock);
51130- fscache_stat(&fscache_n_object_dead);
51131+ fscache_stat_unchecked(&fscache_n_object_dead);
51132 goto terminal_transit;
51133
51134 /* handle the parent cache of this object being withdrawn from
51135@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51136 spin_lock(&object->lock);
51137 object->state = FSCACHE_OBJECT_DEAD;
51138 spin_unlock(&object->lock);
51139- fscache_stat(&fscache_n_object_dead);
51140+ fscache_stat_unchecked(&fscache_n_object_dead);
51141 goto terminal_transit;
51142
51143 /* complain about the object being woken up once it is
51144@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51145 parent->cookie->def->name, cookie->def->name,
51146 object->cache->tag->name);
51147
51148- fscache_stat(&fscache_n_object_lookups);
51149+ fscache_stat_unchecked(&fscache_n_object_lookups);
51150 fscache_stat(&fscache_n_cop_lookup_object);
51151 ret = object->cache->ops->lookup_object(object);
51152 fscache_stat_d(&fscache_n_cop_lookup_object);
51153@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51154 if (ret == -ETIMEDOUT) {
51155 /* probably stuck behind another object, so move this one to
51156 * the back of the queue */
51157- fscache_stat(&fscache_n_object_lookups_timed_out);
51158+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51159 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51160 }
51161
51162@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51163
51164 spin_lock(&object->lock);
51165 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51166- fscache_stat(&fscache_n_object_lookups_negative);
51167+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51168
51169 /* transit here to allow write requests to begin stacking up
51170 * and read requests to begin returning ENODATA */
51171@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51172 * result, in which case there may be data available */
51173 spin_lock(&object->lock);
51174 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51175- fscache_stat(&fscache_n_object_lookups_positive);
51176+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51177
51178 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51179
51180@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51181 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51182 } else {
51183 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51184- fscache_stat(&fscache_n_object_created);
51185+ fscache_stat_unchecked(&fscache_n_object_created);
51186
51187 object->state = FSCACHE_OBJECT_AVAILABLE;
51188 spin_unlock(&object->lock);
51189@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51190 fscache_enqueue_dependents(object);
51191
51192 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51193- fscache_stat(&fscache_n_object_avail);
51194+ fscache_stat_unchecked(&fscache_n_object_avail);
51195
51196 _leave("");
51197 }
51198@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51199 enum fscache_checkaux result;
51200
51201 if (!object->cookie->def->check_aux) {
51202- fscache_stat(&fscache_n_checkaux_none);
51203+ fscache_stat_unchecked(&fscache_n_checkaux_none);
51204 return FSCACHE_CHECKAUX_OKAY;
51205 }
51206
51207@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51208 switch (result) {
51209 /* entry okay as is */
51210 case FSCACHE_CHECKAUX_OKAY:
51211- fscache_stat(&fscache_n_checkaux_okay);
51212+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
51213 break;
51214
51215 /* entry requires update */
51216 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51217- fscache_stat(&fscache_n_checkaux_update);
51218+ fscache_stat_unchecked(&fscache_n_checkaux_update);
51219 break;
51220
51221 /* entry requires deletion */
51222 case FSCACHE_CHECKAUX_OBSOLETE:
51223- fscache_stat(&fscache_n_checkaux_obsolete);
51224+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51225 break;
51226
51227 default:
51228diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51229index 762a9ec..2023284 100644
51230--- a/fs/fscache/operation.c
51231+++ b/fs/fscache/operation.c
51232@@ -17,7 +17,7 @@
51233 #include <linux/slab.h>
51234 #include "internal.h"
51235
51236-atomic_t fscache_op_debug_id;
51237+atomic_unchecked_t fscache_op_debug_id;
51238 EXPORT_SYMBOL(fscache_op_debug_id);
51239
51240 /**
51241@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51242 ASSERTCMP(atomic_read(&op->usage), >, 0);
51243 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51244
51245- fscache_stat(&fscache_n_op_enqueue);
51246+ fscache_stat_unchecked(&fscache_n_op_enqueue);
51247 switch (op->flags & FSCACHE_OP_TYPE) {
51248 case FSCACHE_OP_ASYNC:
51249 _debug("queue async");
51250@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51251 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51252 if (op->processor)
51253 fscache_enqueue_operation(op);
51254- fscache_stat(&fscache_n_op_run);
51255+ fscache_stat_unchecked(&fscache_n_op_run);
51256 }
51257
51258 /*
51259@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51260 if (object->n_in_progress > 0) {
51261 atomic_inc(&op->usage);
51262 list_add_tail(&op->pend_link, &object->pending_ops);
51263- fscache_stat(&fscache_n_op_pend);
51264+ fscache_stat_unchecked(&fscache_n_op_pend);
51265 } else if (!list_empty(&object->pending_ops)) {
51266 atomic_inc(&op->usage);
51267 list_add_tail(&op->pend_link, &object->pending_ops);
51268- fscache_stat(&fscache_n_op_pend);
51269+ fscache_stat_unchecked(&fscache_n_op_pend);
51270 fscache_start_operations(object);
51271 } else {
51272 ASSERTCMP(object->n_in_progress, ==, 0);
51273@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51274 object->n_exclusive++; /* reads and writes must wait */
51275 atomic_inc(&op->usage);
51276 list_add_tail(&op->pend_link, &object->pending_ops);
51277- fscache_stat(&fscache_n_op_pend);
51278+ fscache_stat_unchecked(&fscache_n_op_pend);
51279 ret = 0;
51280 } else {
51281 /* If we're in any other state, there must have been an I/O
51282@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51283 if (object->n_exclusive > 0) {
51284 atomic_inc(&op->usage);
51285 list_add_tail(&op->pend_link, &object->pending_ops);
51286- fscache_stat(&fscache_n_op_pend);
51287+ fscache_stat_unchecked(&fscache_n_op_pend);
51288 } else if (!list_empty(&object->pending_ops)) {
51289 atomic_inc(&op->usage);
51290 list_add_tail(&op->pend_link, &object->pending_ops);
51291- fscache_stat(&fscache_n_op_pend);
51292+ fscache_stat_unchecked(&fscache_n_op_pend);
51293 fscache_start_operations(object);
51294 } else {
51295 ASSERTCMP(object->n_exclusive, ==, 0);
51296@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51297 object->n_ops++;
51298 atomic_inc(&op->usage);
51299 list_add_tail(&op->pend_link, &object->pending_ops);
51300- fscache_stat(&fscache_n_op_pend);
51301+ fscache_stat_unchecked(&fscache_n_op_pend);
51302 ret = 0;
51303 } else if (object->state == FSCACHE_OBJECT_DYING ||
51304 object->state == FSCACHE_OBJECT_LC_DYING ||
51305 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51306- fscache_stat(&fscache_n_op_rejected);
51307+ fscache_stat_unchecked(&fscache_n_op_rejected);
51308 op->state = FSCACHE_OP_ST_CANCELLED;
51309 ret = -ENOBUFS;
51310 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51311@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51312 ret = -EBUSY;
51313 if (op->state == FSCACHE_OP_ST_PENDING) {
51314 ASSERT(!list_empty(&op->pend_link));
51315- fscache_stat(&fscache_n_op_cancelled);
51316+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51317 list_del_init(&op->pend_link);
51318 if (do_cancel)
51319 do_cancel(op);
51320@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51321 while (!list_empty(&object->pending_ops)) {
51322 op = list_entry(object->pending_ops.next,
51323 struct fscache_operation, pend_link);
51324- fscache_stat(&fscache_n_op_cancelled);
51325+ fscache_stat_unchecked(&fscache_n_op_cancelled);
51326 list_del_init(&op->pend_link);
51327
51328 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51329@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51330 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51331 op->state = FSCACHE_OP_ST_DEAD;
51332
51333- fscache_stat(&fscache_n_op_release);
51334+ fscache_stat_unchecked(&fscache_n_op_release);
51335
51336 if (op->release) {
51337 op->release(op);
51338@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51339 * lock, and defer it otherwise */
51340 if (!spin_trylock(&object->lock)) {
51341 _debug("defer put");
51342- fscache_stat(&fscache_n_op_deferred_release);
51343+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
51344
51345 cache = object->cache;
51346 spin_lock(&cache->op_gc_list_lock);
51347@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51348
51349 _debug("GC DEFERRED REL OBJ%x OP%x",
51350 object->debug_id, op->debug_id);
51351- fscache_stat(&fscache_n_op_gc);
51352+ fscache_stat_unchecked(&fscache_n_op_gc);
51353
51354 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51355 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51356diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51357index ff000e5..c44ec6d 100644
51358--- a/fs/fscache/page.c
51359+++ b/fs/fscache/page.c
51360@@ -61,7 +61,7 @@ try_again:
51361 val = radix_tree_lookup(&cookie->stores, page->index);
51362 if (!val) {
51363 rcu_read_unlock();
51364- fscache_stat(&fscache_n_store_vmscan_not_storing);
51365+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51366 __fscache_uncache_page(cookie, page);
51367 return true;
51368 }
51369@@ -91,11 +91,11 @@ try_again:
51370 spin_unlock(&cookie->stores_lock);
51371
51372 if (xpage) {
51373- fscache_stat(&fscache_n_store_vmscan_cancelled);
51374- fscache_stat(&fscache_n_store_radix_deletes);
51375+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51376+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51377 ASSERTCMP(xpage, ==, page);
51378 } else {
51379- fscache_stat(&fscache_n_store_vmscan_gone);
51380+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51381 }
51382
51383 wake_up_bit(&cookie->flags, 0);
51384@@ -110,11 +110,11 @@ page_busy:
51385 * sleeping on memory allocation, so we may need to impose a timeout
51386 * too. */
51387 if (!(gfp & __GFP_WAIT)) {
51388- fscache_stat(&fscache_n_store_vmscan_busy);
51389+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51390 return false;
51391 }
51392
51393- fscache_stat(&fscache_n_store_vmscan_wait);
51394+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51395 __fscache_wait_on_page_write(cookie, page);
51396 gfp &= ~__GFP_WAIT;
51397 goto try_again;
51398@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51399 FSCACHE_COOKIE_STORING_TAG);
51400 if (!radix_tree_tag_get(&cookie->stores, page->index,
51401 FSCACHE_COOKIE_PENDING_TAG)) {
51402- fscache_stat(&fscache_n_store_radix_deletes);
51403+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51404 xpage = radix_tree_delete(&cookie->stores, page->index);
51405 }
51406 spin_unlock(&cookie->stores_lock);
51407@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51408
51409 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51410
51411- fscache_stat(&fscache_n_attr_changed_calls);
51412+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51413
51414 if (fscache_object_is_active(object)) {
51415 fscache_stat(&fscache_n_cop_attr_changed);
51416@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51417
51418 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51419
51420- fscache_stat(&fscache_n_attr_changed);
51421+ fscache_stat_unchecked(&fscache_n_attr_changed);
51422
51423 op = kzalloc(sizeof(*op), GFP_KERNEL);
51424 if (!op) {
51425- fscache_stat(&fscache_n_attr_changed_nomem);
51426+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51427 _leave(" = -ENOMEM");
51428 return -ENOMEM;
51429 }
51430@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51431 if (fscache_submit_exclusive_op(object, op) < 0)
51432 goto nobufs;
51433 spin_unlock(&cookie->lock);
51434- fscache_stat(&fscache_n_attr_changed_ok);
51435+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51436 fscache_put_operation(op);
51437 _leave(" = 0");
51438 return 0;
51439@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51440 nobufs:
51441 spin_unlock(&cookie->lock);
51442 kfree(op);
51443- fscache_stat(&fscache_n_attr_changed_nobufs);
51444+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51445 _leave(" = %d", -ENOBUFS);
51446 return -ENOBUFS;
51447 }
51448@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51449 /* allocate a retrieval operation and attempt to submit it */
51450 op = kzalloc(sizeof(*op), GFP_NOIO);
51451 if (!op) {
51452- fscache_stat(&fscache_n_retrievals_nomem);
51453+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51454 return NULL;
51455 }
51456
51457@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51458 return 0;
51459 }
51460
51461- fscache_stat(&fscache_n_retrievals_wait);
51462+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
51463
51464 jif = jiffies;
51465 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51466 fscache_wait_bit_interruptible,
51467 TASK_INTERRUPTIBLE) != 0) {
51468- fscache_stat(&fscache_n_retrievals_intr);
51469+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51470 _leave(" = -ERESTARTSYS");
51471 return -ERESTARTSYS;
51472 }
51473@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51474 */
51475 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51476 struct fscache_retrieval *op,
51477- atomic_t *stat_op_waits,
51478- atomic_t *stat_object_dead)
51479+ atomic_unchecked_t *stat_op_waits,
51480+ atomic_unchecked_t *stat_object_dead)
51481 {
51482 int ret;
51483
51484@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51485 goto check_if_dead;
51486
51487 _debug(">>> WT");
51488- fscache_stat(stat_op_waits);
51489+ fscache_stat_unchecked(stat_op_waits);
51490 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51491 fscache_wait_bit_interruptible,
51492 TASK_INTERRUPTIBLE) != 0) {
51493@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51494
51495 check_if_dead:
51496 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51497- fscache_stat(stat_object_dead);
51498+ fscache_stat_unchecked(stat_object_dead);
51499 _leave(" = -ENOBUFS [cancelled]");
51500 return -ENOBUFS;
51501 }
51502 if (unlikely(fscache_object_is_dead(object))) {
51503 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51504 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51505- fscache_stat(stat_object_dead);
51506+ fscache_stat_unchecked(stat_object_dead);
51507 return -ENOBUFS;
51508 }
51509 return 0;
51510@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51511
51512 _enter("%p,%p,,,", cookie, page);
51513
51514- fscache_stat(&fscache_n_retrievals);
51515+ fscache_stat_unchecked(&fscache_n_retrievals);
51516
51517 if (hlist_empty(&cookie->backing_objects))
51518 goto nobufs;
51519@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51520 goto nobufs_unlock_dec;
51521 spin_unlock(&cookie->lock);
51522
51523- fscache_stat(&fscache_n_retrieval_ops);
51524+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51525
51526 /* pin the netfs read context in case we need to do the actual netfs
51527 * read because we've encountered a cache read failure */
51528@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51529
51530 error:
51531 if (ret == -ENOMEM)
51532- fscache_stat(&fscache_n_retrievals_nomem);
51533+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51534 else if (ret == -ERESTARTSYS)
51535- fscache_stat(&fscache_n_retrievals_intr);
51536+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51537 else if (ret == -ENODATA)
51538- fscache_stat(&fscache_n_retrievals_nodata);
51539+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51540 else if (ret < 0)
51541- fscache_stat(&fscache_n_retrievals_nobufs);
51542+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51543 else
51544- fscache_stat(&fscache_n_retrievals_ok);
51545+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51546
51547 fscache_put_retrieval(op);
51548 _leave(" = %d", ret);
51549@@ -467,7 +467,7 @@ nobufs_unlock:
51550 spin_unlock(&cookie->lock);
51551 kfree(op);
51552 nobufs:
51553- fscache_stat(&fscache_n_retrievals_nobufs);
51554+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51555 _leave(" = -ENOBUFS");
51556 return -ENOBUFS;
51557 }
51558@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51559
51560 _enter("%p,,%d,,,", cookie, *nr_pages);
51561
51562- fscache_stat(&fscache_n_retrievals);
51563+ fscache_stat_unchecked(&fscache_n_retrievals);
51564
51565 if (hlist_empty(&cookie->backing_objects))
51566 goto nobufs;
51567@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51568 goto nobufs_unlock_dec;
51569 spin_unlock(&cookie->lock);
51570
51571- fscache_stat(&fscache_n_retrieval_ops);
51572+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
51573
51574 /* pin the netfs read context in case we need to do the actual netfs
51575 * read because we've encountered a cache read failure */
51576@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51577
51578 error:
51579 if (ret == -ENOMEM)
51580- fscache_stat(&fscache_n_retrievals_nomem);
51581+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51582 else if (ret == -ERESTARTSYS)
51583- fscache_stat(&fscache_n_retrievals_intr);
51584+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
51585 else if (ret == -ENODATA)
51586- fscache_stat(&fscache_n_retrievals_nodata);
51587+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51588 else if (ret < 0)
51589- fscache_stat(&fscache_n_retrievals_nobufs);
51590+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51591 else
51592- fscache_stat(&fscache_n_retrievals_ok);
51593+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
51594
51595 fscache_put_retrieval(op);
51596 _leave(" = %d", ret);
51597@@ -591,7 +591,7 @@ nobufs_unlock:
51598 spin_unlock(&cookie->lock);
51599 kfree(op);
51600 nobufs:
51601- fscache_stat(&fscache_n_retrievals_nobufs);
51602+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51603 _leave(" = -ENOBUFS");
51604 return -ENOBUFS;
51605 }
51606@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51607
51608 _enter("%p,%p,,,", cookie, page);
51609
51610- fscache_stat(&fscache_n_allocs);
51611+ fscache_stat_unchecked(&fscache_n_allocs);
51612
51613 if (hlist_empty(&cookie->backing_objects))
51614 goto nobufs;
51615@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51616 goto nobufs_unlock;
51617 spin_unlock(&cookie->lock);
51618
51619- fscache_stat(&fscache_n_alloc_ops);
51620+ fscache_stat_unchecked(&fscache_n_alloc_ops);
51621
51622 ret = fscache_wait_for_retrieval_activation(
51623 object, op,
51624@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51625
51626 error:
51627 if (ret == -ERESTARTSYS)
51628- fscache_stat(&fscache_n_allocs_intr);
51629+ fscache_stat_unchecked(&fscache_n_allocs_intr);
51630 else if (ret < 0)
51631- fscache_stat(&fscache_n_allocs_nobufs);
51632+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51633 else
51634- fscache_stat(&fscache_n_allocs_ok);
51635+ fscache_stat_unchecked(&fscache_n_allocs_ok);
51636
51637 fscache_put_retrieval(op);
51638 _leave(" = %d", ret);
51639@@ -677,7 +677,7 @@ nobufs_unlock:
51640 spin_unlock(&cookie->lock);
51641 kfree(op);
51642 nobufs:
51643- fscache_stat(&fscache_n_allocs_nobufs);
51644+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51645 _leave(" = -ENOBUFS");
51646 return -ENOBUFS;
51647 }
51648@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51649
51650 spin_lock(&cookie->stores_lock);
51651
51652- fscache_stat(&fscache_n_store_calls);
51653+ fscache_stat_unchecked(&fscache_n_store_calls);
51654
51655 /* find a page to store */
51656 page = NULL;
51657@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51658 page = results[0];
51659 _debug("gang %d [%lx]", n, page->index);
51660 if (page->index > op->store_limit) {
51661- fscache_stat(&fscache_n_store_pages_over_limit);
51662+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
51663 goto superseded;
51664 }
51665
51666@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51667 spin_unlock(&cookie->stores_lock);
51668 spin_unlock(&object->lock);
51669
51670- fscache_stat(&fscache_n_store_pages);
51671+ fscache_stat_unchecked(&fscache_n_store_pages);
51672 fscache_stat(&fscache_n_cop_write_page);
51673 ret = object->cache->ops->write_page(op, page);
51674 fscache_stat_d(&fscache_n_cop_write_page);
51675@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51676 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51677 ASSERT(PageFsCache(page));
51678
51679- fscache_stat(&fscache_n_stores);
51680+ fscache_stat_unchecked(&fscache_n_stores);
51681
51682 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
51683 _leave(" = -ENOBUFS [invalidating]");
51684@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51685 spin_unlock(&cookie->stores_lock);
51686 spin_unlock(&object->lock);
51687
51688- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
51689+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
51690 op->store_limit = object->store_limit;
51691
51692 if (fscache_submit_op(object, &op->op) < 0)
51693@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51694
51695 spin_unlock(&cookie->lock);
51696 radix_tree_preload_end();
51697- fscache_stat(&fscache_n_store_ops);
51698- fscache_stat(&fscache_n_stores_ok);
51699+ fscache_stat_unchecked(&fscache_n_store_ops);
51700+ fscache_stat_unchecked(&fscache_n_stores_ok);
51701
51702 /* the work queue now carries its own ref on the object */
51703 fscache_put_operation(&op->op);
51704@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51705 return 0;
51706
51707 already_queued:
51708- fscache_stat(&fscache_n_stores_again);
51709+ fscache_stat_unchecked(&fscache_n_stores_again);
51710 already_pending:
51711 spin_unlock(&cookie->stores_lock);
51712 spin_unlock(&object->lock);
51713 spin_unlock(&cookie->lock);
51714 radix_tree_preload_end();
51715 kfree(op);
51716- fscache_stat(&fscache_n_stores_ok);
51717+ fscache_stat_unchecked(&fscache_n_stores_ok);
51718 _leave(" = 0");
51719 return 0;
51720
51721@@ -959,14 +959,14 @@ nobufs:
51722 spin_unlock(&cookie->lock);
51723 radix_tree_preload_end();
51724 kfree(op);
51725- fscache_stat(&fscache_n_stores_nobufs);
51726+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
51727 _leave(" = -ENOBUFS");
51728 return -ENOBUFS;
51729
51730 nomem_free:
51731 kfree(op);
51732 nomem:
51733- fscache_stat(&fscache_n_stores_oom);
51734+ fscache_stat_unchecked(&fscache_n_stores_oom);
51735 _leave(" = -ENOMEM");
51736 return -ENOMEM;
51737 }
51738@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
51739 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51740 ASSERTCMP(page, !=, NULL);
51741
51742- fscache_stat(&fscache_n_uncaches);
51743+ fscache_stat_unchecked(&fscache_n_uncaches);
51744
51745 /* cache withdrawal may beat us to it */
51746 if (!PageFsCache(page))
51747@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
51748 struct fscache_cookie *cookie = op->op.object->cookie;
51749
51750 #ifdef CONFIG_FSCACHE_STATS
51751- atomic_inc(&fscache_n_marks);
51752+ atomic_inc_unchecked(&fscache_n_marks);
51753 #endif
51754
51755 _debug("- mark %p{%lx}", page, page->index);
51756diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
51757index 8179e8b..5072cc7 100644
51758--- a/fs/fscache/stats.c
51759+++ b/fs/fscache/stats.c
51760@@ -18,99 +18,99 @@
51761 /*
51762 * operation counters
51763 */
51764-atomic_t fscache_n_op_pend;
51765-atomic_t fscache_n_op_run;
51766-atomic_t fscache_n_op_enqueue;
51767-atomic_t fscache_n_op_requeue;
51768-atomic_t fscache_n_op_deferred_release;
51769-atomic_t fscache_n_op_release;
51770-atomic_t fscache_n_op_gc;
51771-atomic_t fscache_n_op_cancelled;
51772-atomic_t fscache_n_op_rejected;
51773+atomic_unchecked_t fscache_n_op_pend;
51774+atomic_unchecked_t fscache_n_op_run;
51775+atomic_unchecked_t fscache_n_op_enqueue;
51776+atomic_unchecked_t fscache_n_op_requeue;
51777+atomic_unchecked_t fscache_n_op_deferred_release;
51778+atomic_unchecked_t fscache_n_op_release;
51779+atomic_unchecked_t fscache_n_op_gc;
51780+atomic_unchecked_t fscache_n_op_cancelled;
51781+atomic_unchecked_t fscache_n_op_rejected;
51782
51783-atomic_t fscache_n_attr_changed;
51784-atomic_t fscache_n_attr_changed_ok;
51785-atomic_t fscache_n_attr_changed_nobufs;
51786-atomic_t fscache_n_attr_changed_nomem;
51787-atomic_t fscache_n_attr_changed_calls;
51788+atomic_unchecked_t fscache_n_attr_changed;
51789+atomic_unchecked_t fscache_n_attr_changed_ok;
51790+atomic_unchecked_t fscache_n_attr_changed_nobufs;
51791+atomic_unchecked_t fscache_n_attr_changed_nomem;
51792+atomic_unchecked_t fscache_n_attr_changed_calls;
51793
51794-atomic_t fscache_n_allocs;
51795-atomic_t fscache_n_allocs_ok;
51796-atomic_t fscache_n_allocs_wait;
51797-atomic_t fscache_n_allocs_nobufs;
51798-atomic_t fscache_n_allocs_intr;
51799-atomic_t fscache_n_allocs_object_dead;
51800-atomic_t fscache_n_alloc_ops;
51801-atomic_t fscache_n_alloc_op_waits;
51802+atomic_unchecked_t fscache_n_allocs;
51803+atomic_unchecked_t fscache_n_allocs_ok;
51804+atomic_unchecked_t fscache_n_allocs_wait;
51805+atomic_unchecked_t fscache_n_allocs_nobufs;
51806+atomic_unchecked_t fscache_n_allocs_intr;
51807+atomic_unchecked_t fscache_n_allocs_object_dead;
51808+atomic_unchecked_t fscache_n_alloc_ops;
51809+atomic_unchecked_t fscache_n_alloc_op_waits;
51810
51811-atomic_t fscache_n_retrievals;
51812-atomic_t fscache_n_retrievals_ok;
51813-atomic_t fscache_n_retrievals_wait;
51814-atomic_t fscache_n_retrievals_nodata;
51815-atomic_t fscache_n_retrievals_nobufs;
51816-atomic_t fscache_n_retrievals_intr;
51817-atomic_t fscache_n_retrievals_nomem;
51818-atomic_t fscache_n_retrievals_object_dead;
51819-atomic_t fscache_n_retrieval_ops;
51820-atomic_t fscache_n_retrieval_op_waits;
51821+atomic_unchecked_t fscache_n_retrievals;
51822+atomic_unchecked_t fscache_n_retrievals_ok;
51823+atomic_unchecked_t fscache_n_retrievals_wait;
51824+atomic_unchecked_t fscache_n_retrievals_nodata;
51825+atomic_unchecked_t fscache_n_retrievals_nobufs;
51826+atomic_unchecked_t fscache_n_retrievals_intr;
51827+atomic_unchecked_t fscache_n_retrievals_nomem;
51828+atomic_unchecked_t fscache_n_retrievals_object_dead;
51829+atomic_unchecked_t fscache_n_retrieval_ops;
51830+atomic_unchecked_t fscache_n_retrieval_op_waits;
51831
51832-atomic_t fscache_n_stores;
51833-atomic_t fscache_n_stores_ok;
51834-atomic_t fscache_n_stores_again;
51835-atomic_t fscache_n_stores_nobufs;
51836-atomic_t fscache_n_stores_oom;
51837-atomic_t fscache_n_store_ops;
51838-atomic_t fscache_n_store_calls;
51839-atomic_t fscache_n_store_pages;
51840-atomic_t fscache_n_store_radix_deletes;
51841-atomic_t fscache_n_store_pages_over_limit;
51842+atomic_unchecked_t fscache_n_stores;
51843+atomic_unchecked_t fscache_n_stores_ok;
51844+atomic_unchecked_t fscache_n_stores_again;
51845+atomic_unchecked_t fscache_n_stores_nobufs;
51846+atomic_unchecked_t fscache_n_stores_oom;
51847+atomic_unchecked_t fscache_n_store_ops;
51848+atomic_unchecked_t fscache_n_store_calls;
51849+atomic_unchecked_t fscache_n_store_pages;
51850+atomic_unchecked_t fscache_n_store_radix_deletes;
51851+atomic_unchecked_t fscache_n_store_pages_over_limit;
51852
51853-atomic_t fscache_n_store_vmscan_not_storing;
51854-atomic_t fscache_n_store_vmscan_gone;
51855-atomic_t fscache_n_store_vmscan_busy;
51856-atomic_t fscache_n_store_vmscan_cancelled;
51857-atomic_t fscache_n_store_vmscan_wait;
51858+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51859+atomic_unchecked_t fscache_n_store_vmscan_gone;
51860+atomic_unchecked_t fscache_n_store_vmscan_busy;
51861+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51862+atomic_unchecked_t fscache_n_store_vmscan_wait;
51863
51864-atomic_t fscache_n_marks;
51865-atomic_t fscache_n_uncaches;
51866+atomic_unchecked_t fscache_n_marks;
51867+atomic_unchecked_t fscache_n_uncaches;
51868
51869-atomic_t fscache_n_acquires;
51870-atomic_t fscache_n_acquires_null;
51871-atomic_t fscache_n_acquires_no_cache;
51872-atomic_t fscache_n_acquires_ok;
51873-atomic_t fscache_n_acquires_nobufs;
51874-atomic_t fscache_n_acquires_oom;
51875+atomic_unchecked_t fscache_n_acquires;
51876+atomic_unchecked_t fscache_n_acquires_null;
51877+atomic_unchecked_t fscache_n_acquires_no_cache;
51878+atomic_unchecked_t fscache_n_acquires_ok;
51879+atomic_unchecked_t fscache_n_acquires_nobufs;
51880+atomic_unchecked_t fscache_n_acquires_oom;
51881
51882-atomic_t fscache_n_invalidates;
51883-atomic_t fscache_n_invalidates_run;
51884+atomic_unchecked_t fscache_n_invalidates;
51885+atomic_unchecked_t fscache_n_invalidates_run;
51886
51887-atomic_t fscache_n_updates;
51888-atomic_t fscache_n_updates_null;
51889-atomic_t fscache_n_updates_run;
51890+atomic_unchecked_t fscache_n_updates;
51891+atomic_unchecked_t fscache_n_updates_null;
51892+atomic_unchecked_t fscache_n_updates_run;
51893
51894-atomic_t fscache_n_relinquishes;
51895-atomic_t fscache_n_relinquishes_null;
51896-atomic_t fscache_n_relinquishes_waitcrt;
51897-atomic_t fscache_n_relinquishes_retire;
51898+atomic_unchecked_t fscache_n_relinquishes;
51899+atomic_unchecked_t fscache_n_relinquishes_null;
51900+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51901+atomic_unchecked_t fscache_n_relinquishes_retire;
51902
51903-atomic_t fscache_n_cookie_index;
51904-atomic_t fscache_n_cookie_data;
51905-atomic_t fscache_n_cookie_special;
51906+atomic_unchecked_t fscache_n_cookie_index;
51907+atomic_unchecked_t fscache_n_cookie_data;
51908+atomic_unchecked_t fscache_n_cookie_special;
51909
51910-atomic_t fscache_n_object_alloc;
51911-atomic_t fscache_n_object_no_alloc;
51912-atomic_t fscache_n_object_lookups;
51913-atomic_t fscache_n_object_lookups_negative;
51914-atomic_t fscache_n_object_lookups_positive;
51915-atomic_t fscache_n_object_lookups_timed_out;
51916-atomic_t fscache_n_object_created;
51917-atomic_t fscache_n_object_avail;
51918-atomic_t fscache_n_object_dead;
51919+atomic_unchecked_t fscache_n_object_alloc;
51920+atomic_unchecked_t fscache_n_object_no_alloc;
51921+atomic_unchecked_t fscache_n_object_lookups;
51922+atomic_unchecked_t fscache_n_object_lookups_negative;
51923+atomic_unchecked_t fscache_n_object_lookups_positive;
51924+atomic_unchecked_t fscache_n_object_lookups_timed_out;
51925+atomic_unchecked_t fscache_n_object_created;
51926+atomic_unchecked_t fscache_n_object_avail;
51927+atomic_unchecked_t fscache_n_object_dead;
51928
51929-atomic_t fscache_n_checkaux_none;
51930-atomic_t fscache_n_checkaux_okay;
51931-atomic_t fscache_n_checkaux_update;
51932-atomic_t fscache_n_checkaux_obsolete;
51933+atomic_unchecked_t fscache_n_checkaux_none;
51934+atomic_unchecked_t fscache_n_checkaux_okay;
51935+atomic_unchecked_t fscache_n_checkaux_update;
51936+atomic_unchecked_t fscache_n_checkaux_obsolete;
51937
51938 atomic_t fscache_n_cop_alloc_object;
51939 atomic_t fscache_n_cop_lookup_object;
51940@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
51941 seq_puts(m, "FS-Cache statistics\n");
51942
51943 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
51944- atomic_read(&fscache_n_cookie_index),
51945- atomic_read(&fscache_n_cookie_data),
51946- atomic_read(&fscache_n_cookie_special));
51947+ atomic_read_unchecked(&fscache_n_cookie_index),
51948+ atomic_read_unchecked(&fscache_n_cookie_data),
51949+ atomic_read_unchecked(&fscache_n_cookie_special));
51950
51951 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
51952- atomic_read(&fscache_n_object_alloc),
51953- atomic_read(&fscache_n_object_no_alloc),
51954- atomic_read(&fscache_n_object_avail),
51955- atomic_read(&fscache_n_object_dead));
51956+ atomic_read_unchecked(&fscache_n_object_alloc),
51957+ atomic_read_unchecked(&fscache_n_object_no_alloc),
51958+ atomic_read_unchecked(&fscache_n_object_avail),
51959+ atomic_read_unchecked(&fscache_n_object_dead));
51960 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
51961- atomic_read(&fscache_n_checkaux_none),
51962- atomic_read(&fscache_n_checkaux_okay),
51963- atomic_read(&fscache_n_checkaux_update),
51964- atomic_read(&fscache_n_checkaux_obsolete));
51965+ atomic_read_unchecked(&fscache_n_checkaux_none),
51966+ atomic_read_unchecked(&fscache_n_checkaux_okay),
51967+ atomic_read_unchecked(&fscache_n_checkaux_update),
51968+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
51969
51970 seq_printf(m, "Pages : mrk=%u unc=%u\n",
51971- atomic_read(&fscache_n_marks),
51972- atomic_read(&fscache_n_uncaches));
51973+ atomic_read_unchecked(&fscache_n_marks),
51974+ atomic_read_unchecked(&fscache_n_uncaches));
51975
51976 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
51977 " oom=%u\n",
51978- atomic_read(&fscache_n_acquires),
51979- atomic_read(&fscache_n_acquires_null),
51980- atomic_read(&fscache_n_acquires_no_cache),
51981- atomic_read(&fscache_n_acquires_ok),
51982- atomic_read(&fscache_n_acquires_nobufs),
51983- atomic_read(&fscache_n_acquires_oom));
51984+ atomic_read_unchecked(&fscache_n_acquires),
51985+ atomic_read_unchecked(&fscache_n_acquires_null),
51986+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
51987+ atomic_read_unchecked(&fscache_n_acquires_ok),
51988+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
51989+ atomic_read_unchecked(&fscache_n_acquires_oom));
51990
51991 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
51992- atomic_read(&fscache_n_object_lookups),
51993- atomic_read(&fscache_n_object_lookups_negative),
51994- atomic_read(&fscache_n_object_lookups_positive),
51995- atomic_read(&fscache_n_object_created),
51996- atomic_read(&fscache_n_object_lookups_timed_out));
51997+ atomic_read_unchecked(&fscache_n_object_lookups),
51998+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
51999+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
52000+ atomic_read_unchecked(&fscache_n_object_created),
52001+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52002
52003 seq_printf(m, "Invals : n=%u run=%u\n",
52004- atomic_read(&fscache_n_invalidates),
52005- atomic_read(&fscache_n_invalidates_run));
52006+ atomic_read_unchecked(&fscache_n_invalidates),
52007+ atomic_read_unchecked(&fscache_n_invalidates_run));
52008
52009 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52010- atomic_read(&fscache_n_updates),
52011- atomic_read(&fscache_n_updates_null),
52012- atomic_read(&fscache_n_updates_run));
52013+ atomic_read_unchecked(&fscache_n_updates),
52014+ atomic_read_unchecked(&fscache_n_updates_null),
52015+ atomic_read_unchecked(&fscache_n_updates_run));
52016
52017 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52018- atomic_read(&fscache_n_relinquishes),
52019- atomic_read(&fscache_n_relinquishes_null),
52020- atomic_read(&fscache_n_relinquishes_waitcrt),
52021- atomic_read(&fscache_n_relinquishes_retire));
52022+ atomic_read_unchecked(&fscache_n_relinquishes),
52023+ atomic_read_unchecked(&fscache_n_relinquishes_null),
52024+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52025+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
52026
52027 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52028- atomic_read(&fscache_n_attr_changed),
52029- atomic_read(&fscache_n_attr_changed_ok),
52030- atomic_read(&fscache_n_attr_changed_nobufs),
52031- atomic_read(&fscache_n_attr_changed_nomem),
52032- atomic_read(&fscache_n_attr_changed_calls));
52033+ atomic_read_unchecked(&fscache_n_attr_changed),
52034+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
52035+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52036+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52037+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
52038
52039 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52040- atomic_read(&fscache_n_allocs),
52041- atomic_read(&fscache_n_allocs_ok),
52042- atomic_read(&fscache_n_allocs_wait),
52043- atomic_read(&fscache_n_allocs_nobufs),
52044- atomic_read(&fscache_n_allocs_intr));
52045+ atomic_read_unchecked(&fscache_n_allocs),
52046+ atomic_read_unchecked(&fscache_n_allocs_ok),
52047+ atomic_read_unchecked(&fscache_n_allocs_wait),
52048+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
52049+ atomic_read_unchecked(&fscache_n_allocs_intr));
52050 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52051- atomic_read(&fscache_n_alloc_ops),
52052- atomic_read(&fscache_n_alloc_op_waits),
52053- atomic_read(&fscache_n_allocs_object_dead));
52054+ atomic_read_unchecked(&fscache_n_alloc_ops),
52055+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
52056+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
52057
52058 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52059 " int=%u oom=%u\n",
52060- atomic_read(&fscache_n_retrievals),
52061- atomic_read(&fscache_n_retrievals_ok),
52062- atomic_read(&fscache_n_retrievals_wait),
52063- atomic_read(&fscache_n_retrievals_nodata),
52064- atomic_read(&fscache_n_retrievals_nobufs),
52065- atomic_read(&fscache_n_retrievals_intr),
52066- atomic_read(&fscache_n_retrievals_nomem));
52067+ atomic_read_unchecked(&fscache_n_retrievals),
52068+ atomic_read_unchecked(&fscache_n_retrievals_ok),
52069+ atomic_read_unchecked(&fscache_n_retrievals_wait),
52070+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
52071+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52072+ atomic_read_unchecked(&fscache_n_retrievals_intr),
52073+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
52074 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52075- atomic_read(&fscache_n_retrieval_ops),
52076- atomic_read(&fscache_n_retrieval_op_waits),
52077- atomic_read(&fscache_n_retrievals_object_dead));
52078+ atomic_read_unchecked(&fscache_n_retrieval_ops),
52079+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52080+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52081
52082 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52083- atomic_read(&fscache_n_stores),
52084- atomic_read(&fscache_n_stores_ok),
52085- atomic_read(&fscache_n_stores_again),
52086- atomic_read(&fscache_n_stores_nobufs),
52087- atomic_read(&fscache_n_stores_oom));
52088+ atomic_read_unchecked(&fscache_n_stores),
52089+ atomic_read_unchecked(&fscache_n_stores_ok),
52090+ atomic_read_unchecked(&fscache_n_stores_again),
52091+ atomic_read_unchecked(&fscache_n_stores_nobufs),
52092+ atomic_read_unchecked(&fscache_n_stores_oom));
52093 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52094- atomic_read(&fscache_n_store_ops),
52095- atomic_read(&fscache_n_store_calls),
52096- atomic_read(&fscache_n_store_pages),
52097- atomic_read(&fscache_n_store_radix_deletes),
52098- atomic_read(&fscache_n_store_pages_over_limit));
52099+ atomic_read_unchecked(&fscache_n_store_ops),
52100+ atomic_read_unchecked(&fscache_n_store_calls),
52101+ atomic_read_unchecked(&fscache_n_store_pages),
52102+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
52103+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52104
52105 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52106- atomic_read(&fscache_n_store_vmscan_not_storing),
52107- atomic_read(&fscache_n_store_vmscan_gone),
52108- atomic_read(&fscache_n_store_vmscan_busy),
52109- atomic_read(&fscache_n_store_vmscan_cancelled),
52110- atomic_read(&fscache_n_store_vmscan_wait));
52111+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52112+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52113+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52114+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52115+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52116
52117 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52118- atomic_read(&fscache_n_op_pend),
52119- atomic_read(&fscache_n_op_run),
52120- atomic_read(&fscache_n_op_enqueue),
52121- atomic_read(&fscache_n_op_cancelled),
52122- atomic_read(&fscache_n_op_rejected));
52123+ atomic_read_unchecked(&fscache_n_op_pend),
52124+ atomic_read_unchecked(&fscache_n_op_run),
52125+ atomic_read_unchecked(&fscache_n_op_enqueue),
52126+ atomic_read_unchecked(&fscache_n_op_cancelled),
52127+ atomic_read_unchecked(&fscache_n_op_rejected));
52128 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52129- atomic_read(&fscache_n_op_deferred_release),
52130- atomic_read(&fscache_n_op_release),
52131- atomic_read(&fscache_n_op_gc));
52132+ atomic_read_unchecked(&fscache_n_op_deferred_release),
52133+ atomic_read_unchecked(&fscache_n_op_release),
52134+ atomic_read_unchecked(&fscache_n_op_gc));
52135
52136 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52137 atomic_read(&fscache_n_cop_alloc_object),
52138diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52139index e397b67..b0d8709 100644
52140--- a/fs/fuse/cuse.c
52141+++ b/fs/fuse/cuse.c
52142@@ -593,10 +593,12 @@ static int __init cuse_init(void)
52143 INIT_LIST_HEAD(&cuse_conntbl[i]);
52144
52145 /* inherit and extend fuse_dev_operations */
52146- cuse_channel_fops = fuse_dev_operations;
52147- cuse_channel_fops.owner = THIS_MODULE;
52148- cuse_channel_fops.open = cuse_channel_open;
52149- cuse_channel_fops.release = cuse_channel_release;
52150+ pax_open_kernel();
52151+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52152+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52153+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
52154+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
52155+ pax_close_kernel();
52156
52157 cuse_class = class_create(THIS_MODULE, "cuse");
52158 if (IS_ERR(cuse_class))
52159diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52160index e83351a..41e3c9c 100644
52161--- a/fs/fuse/dev.c
52162+++ b/fs/fuse/dev.c
52163@@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52164 ret = 0;
52165 pipe_lock(pipe);
52166
52167- if (!pipe->readers) {
52168+ if (!atomic_read(&pipe->readers)) {
52169 send_sig(SIGPIPE, current, 0);
52170 if (!ret)
52171 ret = -EPIPE;
52172diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52173index 315e1f8..91f890c 100644
52174--- a/fs/fuse/dir.c
52175+++ b/fs/fuse/dir.c
52176@@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52177 return link;
52178 }
52179
52180-static void free_link(char *link)
52181+static void free_link(const char *link)
52182 {
52183 if (!IS_ERR(link))
52184 free_page((unsigned long) link);
52185diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52186index 2b6f569..fcb4d1f 100644
52187--- a/fs/gfs2/inode.c
52188+++ b/fs/gfs2/inode.c
52189@@ -1499,7 +1499,7 @@ out:
52190
52191 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52192 {
52193- char *s = nd_get_link(nd);
52194+ const char *s = nd_get_link(nd);
52195 if (!IS_ERR(s))
52196 kfree(s);
52197 }
52198diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52199index 78bde32..767e906 100644
52200--- a/fs/hugetlbfs/inode.c
52201+++ b/fs/hugetlbfs/inode.c
52202@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52203 struct mm_struct *mm = current->mm;
52204 struct vm_area_struct *vma;
52205 struct hstate *h = hstate_file(file);
52206+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52207 struct vm_unmapped_area_info info;
52208
52209 if (len & ~huge_page_mask(h))
52210@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52211 return addr;
52212 }
52213
52214+#ifdef CONFIG_PAX_RANDMMAP
52215+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52216+#endif
52217+
52218 if (addr) {
52219 addr = ALIGN(addr, huge_page_size(h));
52220 vma = find_vma(mm, addr);
52221- if (TASK_SIZE - len >= addr &&
52222- (!vma || addr + len <= vma->vm_start))
52223+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52224 return addr;
52225 }
52226
52227 info.flags = 0;
52228 info.length = len;
52229 info.low_limit = TASK_UNMAPPED_BASE;
52230+
52231+#ifdef CONFIG_PAX_RANDMMAP
52232+ if (mm->pax_flags & MF_PAX_RANDMMAP)
52233+ info.low_limit += mm->delta_mmap;
52234+#endif
52235+
52236 info.high_limit = TASK_SIZE;
52237 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52238 info.align_offset = 0;
52239@@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52240 .kill_sb = kill_litter_super,
52241 };
52242
52243-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52244+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52245
52246 static int can_do_hugetlb_shm(void)
52247 {
52248diff --git a/fs/inode.c b/fs/inode.c
52249index 14084b7..29af1d9 100644
52250--- a/fs/inode.c
52251+++ b/fs/inode.c
52252@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52253
52254 #ifdef CONFIG_SMP
52255 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52256- static atomic_t shared_last_ino;
52257- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52258+ static atomic_unchecked_t shared_last_ino;
52259+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52260
52261 res = next - LAST_INO_BATCH;
52262 }
52263diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52264index 4a6cf28..d3a29d3 100644
52265--- a/fs/jffs2/erase.c
52266+++ b/fs/jffs2/erase.c
52267@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52268 struct jffs2_unknown_node marker = {
52269 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52270 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52271- .totlen = cpu_to_je32(c->cleanmarker_size)
52272+ .totlen = cpu_to_je32(c->cleanmarker_size),
52273+ .hdr_crc = cpu_to_je32(0)
52274 };
52275
52276 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52277diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52278index a6597d6..41b30ec 100644
52279--- a/fs/jffs2/wbuf.c
52280+++ b/fs/jffs2/wbuf.c
52281@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52282 {
52283 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52284 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52285- .totlen = constant_cpu_to_je32(8)
52286+ .totlen = constant_cpu_to_je32(8),
52287+ .hdr_crc = constant_cpu_to_je32(0)
52288 };
52289
52290 /*
52291diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52292index 1a543be..a4e1363 100644
52293--- a/fs/jfs/super.c
52294+++ b/fs/jfs/super.c
52295@@ -225,7 +225,7 @@ static const match_table_t tokens = {
52296 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52297 int *flag)
52298 {
52299- void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52300+ const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52301 char *p;
52302 struct jfs_sb_info *sbi = JFS_SBI(sb);
52303
52304@@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52305 /* Don't do anything ;-) */
52306 break;
52307 case Opt_iocharset:
52308- if (nls_map && nls_map != (void *) -1)
52309+ if (nls_map && nls_map != (const void *) -1)
52310 unload_nls(nls_map);
52311 if (!strcmp(args[0].from, "none"))
52312 nls_map = NULL;
52313@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52314
52315 jfs_inode_cachep =
52316 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52317- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52318+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52319 init_once);
52320 if (jfs_inode_cachep == NULL)
52321 return -ENOMEM;
52322diff --git a/fs/libfs.c b/fs/libfs.c
52323index 916da8c..1588998 100644
52324--- a/fs/libfs.c
52325+++ b/fs/libfs.c
52326@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52327
52328 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52329 struct dentry *next;
52330+ char d_name[sizeof(next->d_iname)];
52331+ const unsigned char *name;
52332+
52333 next = list_entry(p, struct dentry, d_u.d_child);
52334 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52335 if (!simple_positive(next)) {
52336@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52337
52338 spin_unlock(&next->d_lock);
52339 spin_unlock(&dentry->d_lock);
52340- if (filldir(dirent, next->d_name.name,
52341+ name = next->d_name.name;
52342+ if (name == next->d_iname) {
52343+ memcpy(d_name, name, next->d_name.len);
52344+ name = d_name;
52345+ }
52346+ if (filldir(dirent, name,
52347 next->d_name.len, filp->f_pos,
52348 next->d_inode->i_ino,
52349 dt_type(next->d_inode)) < 0)
52350diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52351index 52e5120..808936e 100644
52352--- a/fs/lockd/clntproc.c
52353+++ b/fs/lockd/clntproc.c
52354@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52355 /*
52356 * Cookie counter for NLM requests
52357 */
52358-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52359+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52360
52361 void nlmclnt_next_cookie(struct nlm_cookie *c)
52362 {
52363- u32 cookie = atomic_inc_return(&nlm_cookie);
52364+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52365
52366 memcpy(c->data, &cookie, 4);
52367 c->len=4;
52368diff --git a/fs/locks.c b/fs/locks.c
52369index a94e331..060bce3 100644
52370--- a/fs/locks.c
52371+++ b/fs/locks.c
52372@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52373 return;
52374
52375 if (filp->f_op && filp->f_op->flock) {
52376- struct file_lock fl = {
52377+ struct file_lock flock = {
52378 .fl_pid = current->tgid,
52379 .fl_file = filp,
52380 .fl_flags = FL_FLOCK,
52381 .fl_type = F_UNLCK,
52382 .fl_end = OFFSET_MAX,
52383 };
52384- filp->f_op->flock(filp, F_SETLKW, &fl);
52385- if (fl.fl_ops && fl.fl_ops->fl_release_private)
52386- fl.fl_ops->fl_release_private(&fl);
52387+ filp->f_op->flock(filp, F_SETLKW, &flock);
52388+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
52389+ flock.fl_ops->fl_release_private(&flock);
52390 }
52391
52392 lock_flocks();
52393diff --git a/fs/namei.c b/fs/namei.c
52394index 43a97ee..4e585fd 100644
52395--- a/fs/namei.c
52396+++ b/fs/namei.c
52397@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52398 if (ret != -EACCES)
52399 return ret;
52400
52401+#ifdef CONFIG_GRKERNSEC
52402+ /* we'll block if we have to log due to a denied capability use */
52403+ if (mask & MAY_NOT_BLOCK)
52404+ return -ECHILD;
52405+#endif
52406+
52407 if (S_ISDIR(inode->i_mode)) {
52408 /* DACs are overridable for directories */
52409- if (inode_capable(inode, CAP_DAC_OVERRIDE))
52410- return 0;
52411 if (!(mask & MAY_WRITE))
52412- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52413+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52414+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52415 return 0;
52416+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
52417+ return 0;
52418 return -EACCES;
52419 }
52420 /*
52421+ * Searching includes executable on directories, else just read.
52422+ */
52423+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52424+ if (mask == MAY_READ)
52425+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52426+ inode_capable(inode, CAP_DAC_READ_SEARCH))
52427+ return 0;
52428+
52429+ /*
52430 * Read/write DACs are always overridable.
52431 * Executable DACs are overridable when there is
52432 * at least one exec bit set.
52433@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52434 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52435 return 0;
52436
52437- /*
52438- * Searching includes executable on directories, else just read.
52439- */
52440- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52441- if (mask == MAY_READ)
52442- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52443- return 0;
52444-
52445 return -EACCES;
52446 }
52447
52448@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52449 {
52450 struct dentry *dentry = link->dentry;
52451 int error;
52452- char *s;
52453+ const char *s;
52454
52455 BUG_ON(nd->flags & LOOKUP_RCU);
52456
52457@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52458 if (error)
52459 goto out_put_nd_path;
52460
52461+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
52462+ dentry->d_inode, dentry, nd->path.mnt)) {
52463+ error = -EACCES;
52464+ goto out_put_nd_path;
52465+ }
52466+
52467 nd->last_type = LAST_BIND;
52468 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52469 error = PTR_ERR(*p);
52470@@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52471 break;
52472 res = walk_component(nd, path, &nd->last,
52473 nd->last_type, LOOKUP_FOLLOW);
52474+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52475+ res = -EACCES;
52476 put_link(nd, &link, cookie);
52477 } while (res > 0);
52478
52479@@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
52480 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52481 {
52482 unsigned long a, b, adata, bdata, mask, hash, len;
52483- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52484+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52485
52486 hash = a = 0;
52487 len = -sizeof(unsigned long);
52488@@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
52489 if (err)
52490 break;
52491 err = lookup_last(nd, &path);
52492+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
52493+ err = -EACCES;
52494 put_link(nd, &link, cookie);
52495 }
52496 }
52497@@ -1986,6 +2004,19 @@ static int path_lookupat(int dfd, const char *name,
52498 if (!err)
52499 err = complete_walk(nd);
52500
52501+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
52502+#ifdef CONFIG_GRKERNSEC
52503+ if (flags & LOOKUP_RCU) {
52504+ path_put(&nd->path);
52505+ err = -ECHILD;
52506+ } else
52507+#endif
52508+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52509+ path_put(&nd->path);
52510+ err = -ENOENT;
52511+ }
52512+ }
52513+
52514 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52515 if (!nd->inode->i_op->lookup) {
52516 path_put(&nd->path);
52517@@ -2013,8 +2044,17 @@ static int filename_lookup(int dfd, struct filename *name,
52518 retval = path_lookupat(dfd, name->name,
52519 flags | LOOKUP_REVAL, nd);
52520
52521- if (likely(!retval))
52522+ if (likely(!retval)) {
52523+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52524+#ifdef CONFIG_GRKERNSEC
52525+ if (flags & LOOKUP_RCU)
52526+ return -ECHILD;
52527+#endif
52528+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
52529+ return -ENOENT;
52530+ }
52531 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52532+ }
52533 return retval;
52534 }
52535
52536@@ -2392,6 +2432,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52537 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52538 return -EPERM;
52539
52540+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52541+ return -EPERM;
52542+ if (gr_handle_rawio(inode))
52543+ return -EPERM;
52544+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52545+ return -EACCES;
52546+
52547 return 0;
52548 }
52549
52550@@ -2613,7 +2660,7 @@ looked_up:
52551 * cleared otherwise prior to returning.
52552 */
52553 static int lookup_open(struct nameidata *nd, struct path *path,
52554- struct file *file,
52555+ struct path *link, struct file *file,
52556 const struct open_flags *op,
52557 bool got_write, int *opened)
52558 {
52559@@ -2648,6 +2695,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52560 /* Negative dentry, just create the file */
52561 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52562 umode_t mode = op->mode;
52563+
52564+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52565+ error = -EACCES;
52566+ goto out_dput;
52567+ }
52568+
52569+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52570+ error = -EACCES;
52571+ goto out_dput;
52572+ }
52573+
52574 if (!IS_POSIXACL(dir->d_inode))
52575 mode &= ~current_umask();
52576 /*
52577@@ -2669,6 +2727,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52578 nd->flags & LOOKUP_EXCL);
52579 if (error)
52580 goto out_dput;
52581+ else
52582+ gr_handle_create(dentry, nd->path.mnt);
52583 }
52584 out_no_open:
52585 path->dentry = dentry;
52586@@ -2683,7 +2743,7 @@ out_dput:
52587 /*
52588 * Handle the last step of open()
52589 */
52590-static int do_last(struct nameidata *nd, struct path *path,
52591+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52592 struct file *file, const struct open_flags *op,
52593 int *opened, struct filename *name)
52594 {
52595@@ -2712,16 +2772,44 @@ static int do_last(struct nameidata *nd, struct path *path,
52596 error = complete_walk(nd);
52597 if (error)
52598 return error;
52599+#ifdef CONFIG_GRKERNSEC
52600+ if (nd->flags & LOOKUP_RCU) {
52601+ error = -ECHILD;
52602+ goto out;
52603+ }
52604+#endif
52605+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52606+ error = -ENOENT;
52607+ goto out;
52608+ }
52609 audit_inode(name, nd->path.dentry, 0);
52610 if (open_flag & O_CREAT) {
52611 error = -EISDIR;
52612 goto out;
52613 }
52614+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
52615+ error = -EACCES;
52616+ goto out;
52617+ }
52618 goto finish_open;
52619 case LAST_BIND:
52620 error = complete_walk(nd);
52621 if (error)
52622 return error;
52623+#ifdef CONFIG_GRKERNSEC
52624+ if (nd->flags & LOOKUP_RCU) {
52625+ error = -ECHILD;
52626+ goto out;
52627+ }
52628+#endif
52629+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
52630+ error = -ENOENT;
52631+ goto out;
52632+ }
52633+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
52634+ error = -EACCES;
52635+ goto out;
52636+ }
52637 audit_inode(name, dir, 0);
52638 goto finish_open;
52639 }
52640@@ -2770,7 +2858,7 @@ retry_lookup:
52641 */
52642 }
52643 mutex_lock(&dir->d_inode->i_mutex);
52644- error = lookup_open(nd, path, file, op, got_write, opened);
52645+ error = lookup_open(nd, path, link, file, op, got_write, opened);
52646 mutex_unlock(&dir->d_inode->i_mutex);
52647
52648 if (error <= 0) {
52649@@ -2794,11 +2882,28 @@ retry_lookup:
52650 goto finish_open_created;
52651 }
52652
52653+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
52654+ error = -ENOENT;
52655+ goto exit_dput;
52656+ }
52657+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
52658+ error = -EACCES;
52659+ goto exit_dput;
52660+ }
52661+
52662 /*
52663 * create/update audit record if it already exists.
52664 */
52665- if (path->dentry->d_inode)
52666+ if (path->dentry->d_inode) {
52667+ /* only check if O_CREAT is specified, all other checks need to go
52668+ into may_open */
52669+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
52670+ error = -EACCES;
52671+ goto exit_dput;
52672+ }
52673+
52674 audit_inode(name, path->dentry, 0);
52675+ }
52676
52677 /*
52678 * If atomic_open() acquired write access it is dropped now due to
52679@@ -2839,6 +2944,11 @@ finish_lookup:
52680 }
52681 }
52682 BUG_ON(inode != path->dentry->d_inode);
52683+ /* if we're resolving a symlink to another symlink */
52684+ if (link && gr_handle_symlink_owner(link, inode)) {
52685+ error = -EACCES;
52686+ goto out;
52687+ }
52688 return 1;
52689 }
52690
52691@@ -2848,7 +2958,6 @@ finish_lookup:
52692 save_parent.dentry = nd->path.dentry;
52693 save_parent.mnt = mntget(path->mnt);
52694 nd->path.dentry = path->dentry;
52695-
52696 }
52697 nd->inode = inode;
52698 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
52699@@ -2857,6 +2966,22 @@ finish_lookup:
52700 path_put(&save_parent);
52701 return error;
52702 }
52703+
52704+#ifdef CONFIG_GRKERNSEC
52705+ if (nd->flags & LOOKUP_RCU) {
52706+ error = -ECHILD;
52707+ goto out;
52708+ }
52709+#endif
52710+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52711+ error = -ENOENT;
52712+ goto out;
52713+ }
52714+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
52715+ error = -EACCES;
52716+ goto out;
52717+ }
52718+
52719 error = -EISDIR;
52720 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
52721 goto out;
52722@@ -2955,7 +3080,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52723 if (unlikely(error))
52724 goto out;
52725
52726- error = do_last(nd, &path, file, op, &opened, pathname);
52727+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
52728 while (unlikely(error > 0)) { /* trailing symlink */
52729 struct path link = path;
52730 void *cookie;
52731@@ -2973,7 +3098,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52732 error = follow_link(&link, nd, &cookie);
52733 if (unlikely(error))
52734 break;
52735- error = do_last(nd, &path, file, op, &opened, pathname);
52736+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
52737 put_link(nd, &link, cookie);
52738 }
52739 out:
52740@@ -3073,8 +3198,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
52741 goto unlock;
52742
52743 error = -EEXIST;
52744- if (dentry->d_inode)
52745+ if (dentry->d_inode) {
52746+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
52747+ error = -ENOENT;
52748+ }
52749 goto fail;
52750+ }
52751 /*
52752 * Special case - lookup gave negative, but... we had foo/bar/
52753 * From the vfs_mknod() POV we just have a negative dentry -
52754@@ -3126,6 +3255,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
52755 }
52756 EXPORT_SYMBOL(user_path_create);
52757
52758+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
52759+{
52760+ struct filename *tmp = getname(pathname);
52761+ struct dentry *res;
52762+ if (IS_ERR(tmp))
52763+ return ERR_CAST(tmp);
52764+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
52765+ if (IS_ERR(res))
52766+ putname(tmp);
52767+ else
52768+ *to = tmp;
52769+ return res;
52770+}
52771+
52772 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
52773 {
52774 int error = may_create(dir, dentry);
52775@@ -3188,6 +3331,17 @@ retry:
52776
52777 if (!IS_POSIXACL(path.dentry->d_inode))
52778 mode &= ~current_umask();
52779+
52780+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
52781+ error = -EPERM;
52782+ goto out;
52783+ }
52784+
52785+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
52786+ error = -EACCES;
52787+ goto out;
52788+ }
52789+
52790 error = security_path_mknod(&path, dentry, mode, dev);
52791 if (error)
52792 goto out;
52793@@ -3204,6 +3358,8 @@ retry:
52794 break;
52795 }
52796 out:
52797+ if (!error)
52798+ gr_handle_create(dentry, path.mnt);
52799 done_path_create(&path, dentry);
52800 if (retry_estale(error, lookup_flags)) {
52801 lookup_flags |= LOOKUP_REVAL;
52802@@ -3256,9 +3412,16 @@ retry:
52803
52804 if (!IS_POSIXACL(path.dentry->d_inode))
52805 mode &= ~current_umask();
52806+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
52807+ error = -EACCES;
52808+ goto out;
52809+ }
52810 error = security_path_mkdir(&path, dentry, mode);
52811 if (!error)
52812 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
52813+ if (!error)
52814+ gr_handle_create(dentry, path.mnt);
52815+out:
52816 done_path_create(&path, dentry);
52817 if (retry_estale(error, lookup_flags)) {
52818 lookup_flags |= LOOKUP_REVAL;
52819@@ -3339,6 +3502,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
52820 struct filename *name;
52821 struct dentry *dentry;
52822 struct nameidata nd;
52823+ ino_t saved_ino = 0;
52824+ dev_t saved_dev = 0;
52825 unsigned int lookup_flags = 0;
52826 retry:
52827 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52828@@ -3371,10 +3536,21 @@ retry:
52829 error = -ENOENT;
52830 goto exit3;
52831 }
52832+
52833+ saved_ino = dentry->d_inode->i_ino;
52834+ saved_dev = gr_get_dev_from_dentry(dentry);
52835+
52836+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
52837+ error = -EACCES;
52838+ goto exit3;
52839+ }
52840+
52841 error = security_path_rmdir(&nd.path, dentry);
52842 if (error)
52843 goto exit3;
52844 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
52845+ if (!error && (saved_dev || saved_ino))
52846+ gr_handle_delete(saved_ino, saved_dev);
52847 exit3:
52848 dput(dentry);
52849 exit2:
52850@@ -3440,6 +3616,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
52851 struct dentry *dentry;
52852 struct nameidata nd;
52853 struct inode *inode = NULL;
52854+ ino_t saved_ino = 0;
52855+ dev_t saved_dev = 0;
52856 unsigned int lookup_flags = 0;
52857 retry:
52858 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52859@@ -3466,10 +3644,22 @@ retry:
52860 if (!inode)
52861 goto slashes;
52862 ihold(inode);
52863+
52864+ if (inode->i_nlink <= 1) {
52865+ saved_ino = inode->i_ino;
52866+ saved_dev = gr_get_dev_from_dentry(dentry);
52867+ }
52868+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
52869+ error = -EACCES;
52870+ goto exit2;
52871+ }
52872+
52873 error = security_path_unlink(&nd.path, dentry);
52874 if (error)
52875 goto exit2;
52876 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
52877+ if (!error && (saved_ino || saved_dev))
52878+ gr_handle_delete(saved_ino, saved_dev);
52879 exit2:
52880 dput(dentry);
52881 }
52882@@ -3547,9 +3737,17 @@ retry:
52883 if (IS_ERR(dentry))
52884 goto out_putname;
52885
52886+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
52887+ error = -EACCES;
52888+ goto out;
52889+ }
52890+
52891 error = security_path_symlink(&path, dentry, from->name);
52892 if (!error)
52893 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
52894+ if (!error)
52895+ gr_handle_create(dentry, path.mnt);
52896+out:
52897 done_path_create(&path, dentry);
52898 if (retry_estale(error, lookup_flags)) {
52899 lookup_flags |= LOOKUP_REVAL;
52900@@ -3623,6 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
52901 {
52902 struct dentry *new_dentry;
52903 struct path old_path, new_path;
52904+ struct filename *to = NULL;
52905 int how = 0;
52906 int error;
52907
52908@@ -3646,7 +3845,7 @@ retry:
52909 if (error)
52910 return error;
52911
52912- new_dentry = user_path_create(newdfd, newname, &new_path,
52913+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
52914 (how & LOOKUP_REVAL));
52915 error = PTR_ERR(new_dentry);
52916 if (IS_ERR(new_dentry))
52917@@ -3658,11 +3857,28 @@ retry:
52918 error = may_linkat(&old_path);
52919 if (unlikely(error))
52920 goto out_dput;
52921+
52922+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
52923+ old_path.dentry->d_inode,
52924+ old_path.dentry->d_inode->i_mode, to)) {
52925+ error = -EACCES;
52926+ goto out_dput;
52927+ }
52928+
52929+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
52930+ old_path.dentry, old_path.mnt, to)) {
52931+ error = -EACCES;
52932+ goto out_dput;
52933+ }
52934+
52935 error = security_path_link(old_path.dentry, &new_path, new_dentry);
52936 if (error)
52937 goto out_dput;
52938 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
52939+ if (!error)
52940+ gr_handle_create(new_dentry, new_path.mnt);
52941 out_dput:
52942+ putname(to);
52943 done_path_create(&new_path, new_dentry);
52944 if (retry_estale(error, how)) {
52945 how |= LOOKUP_REVAL;
52946@@ -3908,12 +4124,21 @@ retry:
52947 if (new_dentry == trap)
52948 goto exit5;
52949
52950+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
52951+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
52952+ to);
52953+ if (error)
52954+ goto exit5;
52955+
52956 error = security_path_rename(&oldnd.path, old_dentry,
52957 &newnd.path, new_dentry);
52958 if (error)
52959 goto exit5;
52960 error = vfs_rename(old_dir->d_inode, old_dentry,
52961 new_dir->d_inode, new_dentry);
52962+ if (!error)
52963+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
52964+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
52965 exit5:
52966 dput(new_dentry);
52967 exit4:
52968@@ -3945,6 +4170,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
52969
52970 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
52971 {
52972+ char tmpbuf[64];
52973+ const char *newlink;
52974 int len;
52975
52976 len = PTR_ERR(link);
52977@@ -3954,7 +4181,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
52978 len = strlen(link);
52979 if (len > (unsigned) buflen)
52980 len = buflen;
52981- if (copy_to_user(buffer, link, len))
52982+
52983+ if (len < sizeof(tmpbuf)) {
52984+ memcpy(tmpbuf, link, len);
52985+ newlink = tmpbuf;
52986+ } else
52987+ newlink = link;
52988+
52989+ if (copy_to_user(buffer, newlink, len))
52990 len = -EFAULT;
52991 out:
52992 return len;
52993diff --git a/fs/namespace.c b/fs/namespace.c
52994index a51054f..f9b53e5 100644
52995--- a/fs/namespace.c
52996+++ b/fs/namespace.c
52997@@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
52998 if (!(sb->s_flags & MS_RDONLY))
52999 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53000 up_write(&sb->s_umount);
53001+
53002+ gr_log_remount(mnt->mnt_devname, retval);
53003+
53004 return retval;
53005 }
53006
53007@@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53008 br_write_unlock(&vfsmount_lock);
53009 up_write(&namespace_sem);
53010 release_mounts(&umount_list);
53011+
53012+ gr_log_unmount(mnt->mnt_devname, retval);
53013+
53014 return retval;
53015 }
53016
53017@@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53018 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53019 MS_STRICTATIME);
53020
53021+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53022+ retval = -EPERM;
53023+ goto dput_out;
53024+ }
53025+
53026+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53027+ retval = -EPERM;
53028+ goto dput_out;
53029+ }
53030+
53031 if (flags & MS_REMOUNT)
53032 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53033 data_page);
53034@@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53035 dev_name, data_page);
53036 dput_out:
53037 path_put(&path);
53038+
53039+ gr_log_mount(dev_name, dir_name, retval);
53040+
53041 return retval;
53042 }
53043
53044@@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53045 if (error)
53046 goto out2;
53047
53048+ if (gr_handle_chroot_pivot()) {
53049+ error = -EPERM;
53050+ goto out2;
53051+ }
53052+
53053 get_fs_root(current->fs, &root);
53054 error = lock_mount(&old);
53055 if (error)
53056@@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53057 !nsown_capable(CAP_SYS_ADMIN))
53058 return -EPERM;
53059
53060- if (fs->users != 1)
53061+ if (atomic_read(&fs->users) != 1)
53062 return -EINVAL;
53063
53064 get_mnt_ns(mnt_ns);
53065diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53066index 59461c9..b17c57e 100644
53067--- a/fs/nfs/callback_xdr.c
53068+++ b/fs/nfs/callback_xdr.c
53069@@ -51,7 +51,7 @@ struct callback_op {
53070 callback_decode_arg_t decode_args;
53071 callback_encode_res_t encode_res;
53072 long res_maxsize;
53073-};
53074+} __do_const;
53075
53076 static struct callback_op callback_ops[];
53077
53078diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53079index ebeb94c..ff35337 100644
53080--- a/fs/nfs/inode.c
53081+++ b/fs/nfs/inode.c
53082@@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53083 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53084 }
53085
53086-static atomic_long_t nfs_attr_generation_counter;
53087+static atomic_long_unchecked_t nfs_attr_generation_counter;
53088
53089 static unsigned long nfs_read_attr_generation_counter(void)
53090 {
53091- return atomic_long_read(&nfs_attr_generation_counter);
53092+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53093 }
53094
53095 unsigned long nfs_inc_attr_generation_counter(void)
53096 {
53097- return atomic_long_inc_return(&nfs_attr_generation_counter);
53098+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53099 }
53100
53101 void nfs_fattr_init(struct nfs_fattr *fattr)
53102diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53103index 9d1c5db..1e13db8 100644
53104--- a/fs/nfsd/nfs4proc.c
53105+++ b/fs/nfsd/nfs4proc.c
53106@@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53107 nfsd4op_rsize op_rsize_bop;
53108 stateid_getter op_get_currentstateid;
53109 stateid_setter op_set_currentstateid;
53110-};
53111+} __do_const;
53112
53113 static struct nfsd4_operation nfsd4_ops[];
53114
53115diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53116index 0dc1158..ccf0338 100644
53117--- a/fs/nfsd/nfs4xdr.c
53118+++ b/fs/nfsd/nfs4xdr.c
53119@@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53120
53121 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53122
53123-static nfsd4_dec nfsd4_dec_ops[] = {
53124+static const nfsd4_dec nfsd4_dec_ops[] = {
53125 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53126 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53127 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53128@@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53129 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53130 };
53131
53132-static nfsd4_dec nfsd41_dec_ops[] = {
53133+static const nfsd4_dec nfsd41_dec_ops[] = {
53134 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53135 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53136 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53137@@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53138 };
53139
53140 struct nfsd4_minorversion_ops {
53141- nfsd4_dec *decoders;
53142+ const nfsd4_dec *decoders;
53143 int nops;
53144 };
53145
53146diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53147index d586117..143d568 100644
53148--- a/fs/nfsd/vfs.c
53149+++ b/fs/nfsd/vfs.c
53150@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53151 } else {
53152 oldfs = get_fs();
53153 set_fs(KERNEL_DS);
53154- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53155+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53156 set_fs(oldfs);
53157 }
53158
53159@@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53160
53161 /* Write the data. */
53162 oldfs = get_fs(); set_fs(KERNEL_DS);
53163- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53164+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53165 set_fs(oldfs);
53166 if (host_err < 0)
53167 goto out_nfserr;
53168@@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53169 */
53170
53171 oldfs = get_fs(); set_fs(KERNEL_DS);
53172- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53173+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53174 set_fs(oldfs);
53175
53176 if (host_err < 0)
53177diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53178index fea6bd5..8ee9d81 100644
53179--- a/fs/nls/nls_base.c
53180+++ b/fs/nls/nls_base.c
53181@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53182
53183 int register_nls(struct nls_table * nls)
53184 {
53185- struct nls_table ** tmp = &tables;
53186+ struct nls_table *tmp = tables;
53187
53188 if (nls->next)
53189 return -EBUSY;
53190
53191 spin_lock(&nls_lock);
53192- while (*tmp) {
53193- if (nls == *tmp) {
53194+ while (tmp) {
53195+ if (nls == tmp) {
53196 spin_unlock(&nls_lock);
53197 return -EBUSY;
53198 }
53199- tmp = &(*tmp)->next;
53200+ tmp = tmp->next;
53201 }
53202- nls->next = tables;
53203+ pax_open_kernel();
53204+ *(struct nls_table **)&nls->next = tables;
53205+ pax_close_kernel();
53206 tables = nls;
53207 spin_unlock(&nls_lock);
53208 return 0;
53209@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53210
53211 int unregister_nls(struct nls_table * nls)
53212 {
53213- struct nls_table ** tmp = &tables;
53214+ struct nls_table * const * tmp = &tables;
53215
53216 spin_lock(&nls_lock);
53217 while (*tmp) {
53218 if (nls == *tmp) {
53219- *tmp = nls->next;
53220+ pax_open_kernel();
53221+ *(struct nls_table **)tmp = nls->next;
53222+ pax_close_kernel();
53223 spin_unlock(&nls_lock);
53224 return 0;
53225 }
53226diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53227index 7424929..35f6be5 100644
53228--- a/fs/nls/nls_euc-jp.c
53229+++ b/fs/nls/nls_euc-jp.c
53230@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53231 p_nls = load_nls("cp932");
53232
53233 if (p_nls) {
53234- table.charset2upper = p_nls->charset2upper;
53235- table.charset2lower = p_nls->charset2lower;
53236+ pax_open_kernel();
53237+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53238+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53239+ pax_close_kernel();
53240 return register_nls(&table);
53241 }
53242
53243diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53244index e7bc1d7..06bd4bb 100644
53245--- a/fs/nls/nls_koi8-ru.c
53246+++ b/fs/nls/nls_koi8-ru.c
53247@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53248 p_nls = load_nls("koi8-u");
53249
53250 if (p_nls) {
53251- table.charset2upper = p_nls->charset2upper;
53252- table.charset2lower = p_nls->charset2lower;
53253+ pax_open_kernel();
53254+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53255+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53256+ pax_close_kernel();
53257 return register_nls(&table);
53258 }
53259
53260diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53261index 9ff4a5e..deb1f0f 100644
53262--- a/fs/notify/fanotify/fanotify_user.c
53263+++ b/fs/notify/fanotify/fanotify_user.c
53264@@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53265
53266 fd = fanotify_event_metadata.fd;
53267 ret = -EFAULT;
53268- if (copy_to_user(buf, &fanotify_event_metadata,
53269- fanotify_event_metadata.event_len))
53270+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53271+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53272 goto out_close_fd;
53273
53274 ret = prepare_for_access_response(group, event, fd);
53275diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53276index 7b51b05..5ea5ef6 100644
53277--- a/fs/notify/notification.c
53278+++ b/fs/notify/notification.c
53279@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53280 * get set to 0 so it will never get 'freed'
53281 */
53282 static struct fsnotify_event *q_overflow_event;
53283-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53284+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53285
53286 /**
53287 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53288@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53289 */
53290 u32 fsnotify_get_cookie(void)
53291 {
53292- return atomic_inc_return(&fsnotify_sync_cookie);
53293+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53294 }
53295 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53296
53297diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53298index 99e3610..02c1068 100644
53299--- a/fs/ntfs/dir.c
53300+++ b/fs/ntfs/dir.c
53301@@ -1329,7 +1329,7 @@ find_next_index_buffer:
53302 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53303 ~(s64)(ndir->itype.index.block_size - 1)));
53304 /* Bounds checks. */
53305- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53306+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53307 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53308 "inode 0x%lx or driver bug.", vdir->i_ino);
53309 goto err_out;
53310diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53311index 5b2d4f0..c6de396 100644
53312--- a/fs/ntfs/file.c
53313+++ b/fs/ntfs/file.c
53314@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53315 #endif /* NTFS_RW */
53316 };
53317
53318-const struct file_operations ntfs_empty_file_ops = {};
53319+const struct file_operations ntfs_empty_file_ops __read_only;
53320
53321-const struct inode_operations ntfs_empty_inode_ops = {};
53322+const struct inode_operations ntfs_empty_inode_ops __read_only;
53323diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53324index a9f78c7..ed8a381 100644
53325--- a/fs/ocfs2/localalloc.c
53326+++ b/fs/ocfs2/localalloc.c
53327@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53328 goto bail;
53329 }
53330
53331- atomic_inc(&osb->alloc_stats.moves);
53332+ atomic_inc_unchecked(&osb->alloc_stats.moves);
53333
53334 bail:
53335 if (handle)
53336diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53337index d355e6e..578d905 100644
53338--- a/fs/ocfs2/ocfs2.h
53339+++ b/fs/ocfs2/ocfs2.h
53340@@ -235,11 +235,11 @@ enum ocfs2_vol_state
53341
53342 struct ocfs2_alloc_stats
53343 {
53344- atomic_t moves;
53345- atomic_t local_data;
53346- atomic_t bitmap_data;
53347- atomic_t bg_allocs;
53348- atomic_t bg_extends;
53349+ atomic_unchecked_t moves;
53350+ atomic_unchecked_t local_data;
53351+ atomic_unchecked_t bitmap_data;
53352+ atomic_unchecked_t bg_allocs;
53353+ atomic_unchecked_t bg_extends;
53354 };
53355
53356 enum ocfs2_local_alloc_state
53357diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53358index b7e74b5..19c6536 100644
53359--- a/fs/ocfs2/suballoc.c
53360+++ b/fs/ocfs2/suballoc.c
53361@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53362 mlog_errno(status);
53363 goto bail;
53364 }
53365- atomic_inc(&osb->alloc_stats.bg_extends);
53366+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53367
53368 /* You should never ask for this much metadata */
53369 BUG_ON(bits_wanted >
53370@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53371 mlog_errno(status);
53372 goto bail;
53373 }
53374- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53375+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53376
53377 *suballoc_loc = res.sr_bg_blkno;
53378 *suballoc_bit_start = res.sr_bit_offset;
53379@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53380 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53381 res->sr_bits);
53382
53383- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53384+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53385
53386 BUG_ON(res->sr_bits != 1);
53387
53388@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53389 mlog_errno(status);
53390 goto bail;
53391 }
53392- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53393+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53394
53395 BUG_ON(res.sr_bits != 1);
53396
53397@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53398 cluster_start,
53399 num_clusters);
53400 if (!status)
53401- atomic_inc(&osb->alloc_stats.local_data);
53402+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
53403 } else {
53404 if (min_clusters > (osb->bitmap_cpg - 1)) {
53405 /* The only paths asking for contiguousness
53406@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53407 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53408 res.sr_bg_blkno,
53409 res.sr_bit_offset);
53410- atomic_inc(&osb->alloc_stats.bitmap_data);
53411+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53412 *num_clusters = res.sr_bits;
53413 }
53414 }
53415diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53416index 0e91ec2..f4b3fc6 100644
53417--- a/fs/ocfs2/super.c
53418+++ b/fs/ocfs2/super.c
53419@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53420 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53421 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53422 "Stats",
53423- atomic_read(&osb->alloc_stats.bitmap_data),
53424- atomic_read(&osb->alloc_stats.local_data),
53425- atomic_read(&osb->alloc_stats.bg_allocs),
53426- atomic_read(&osb->alloc_stats.moves),
53427- atomic_read(&osb->alloc_stats.bg_extends));
53428+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53429+ atomic_read_unchecked(&osb->alloc_stats.local_data),
53430+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53431+ atomic_read_unchecked(&osb->alloc_stats.moves),
53432+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53433
53434 out += snprintf(buf + out, len - out,
53435 "%10s => State: %u Descriptor: %llu Size: %u bits "
53436@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53437 spin_lock_init(&osb->osb_xattr_lock);
53438 ocfs2_init_steal_slots(osb);
53439
53440- atomic_set(&osb->alloc_stats.moves, 0);
53441- atomic_set(&osb->alloc_stats.local_data, 0);
53442- atomic_set(&osb->alloc_stats.bitmap_data, 0);
53443- atomic_set(&osb->alloc_stats.bg_allocs, 0);
53444- atomic_set(&osb->alloc_stats.bg_extends, 0);
53445+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53446+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53447+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53448+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53449+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53450
53451 /* Copy the blockcheck stats from the superblock probe */
53452 osb->osb_ecc_stats = *stats;
53453diff --git a/fs/open.c b/fs/open.c
53454index 9b33c0c..2ffcca2 100644
53455--- a/fs/open.c
53456+++ b/fs/open.c
53457@@ -31,6 +31,8 @@
53458 #include <linux/ima.h>
53459 #include <linux/dnotify.h>
53460
53461+#define CREATE_TRACE_POINTS
53462+#include <trace/events/fs.h>
53463 #include "internal.h"
53464
53465 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53466@@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53467 error = locks_verify_truncate(inode, NULL, length);
53468 if (!error)
53469 error = security_path_truncate(path);
53470+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53471+ error = -EACCES;
53472 if (!error)
53473 error = do_truncate(path->dentry, length, 0, NULL);
53474
53475@@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53476 error = locks_verify_truncate(inode, f.file, length);
53477 if (!error)
53478 error = security_path_truncate(&f.file->f_path);
53479+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53480+ error = -EACCES;
53481 if (!error)
53482 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53483 sb_end_write(inode->i_sb);
53484@@ -373,6 +379,9 @@ retry:
53485 if (__mnt_is_readonly(path.mnt))
53486 res = -EROFS;
53487
53488+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53489+ res = -EACCES;
53490+
53491 out_path_release:
53492 path_put(&path);
53493 if (retry_estale(res, lookup_flags)) {
53494@@ -404,6 +413,8 @@ retry:
53495 if (error)
53496 goto dput_and_out;
53497
53498+ gr_log_chdir(path.dentry, path.mnt);
53499+
53500 set_fs_pwd(current->fs, &path);
53501
53502 dput_and_out:
53503@@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53504 goto out_putf;
53505
53506 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53507+
53508+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53509+ error = -EPERM;
53510+
53511+ if (!error)
53512+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53513+
53514 if (!error)
53515 set_fs_pwd(current->fs, &f.file->f_path);
53516 out_putf:
53517@@ -462,7 +480,13 @@ retry:
53518 if (error)
53519 goto dput_and_out;
53520
53521+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53522+ goto dput_and_out;
53523+
53524 set_fs_root(current->fs, &path);
53525+
53526+ gr_handle_chroot_chdir(&path);
53527+
53528 error = 0;
53529 dput_and_out:
53530 path_put(&path);
53531@@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53532 if (error)
53533 return error;
53534 mutex_lock(&inode->i_mutex);
53535+
53536+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53537+ error = -EACCES;
53538+ goto out_unlock;
53539+ }
53540+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53541+ error = -EACCES;
53542+ goto out_unlock;
53543+ }
53544+
53545 error = security_path_chmod(path, mode);
53546 if (error)
53547 goto out_unlock;
53548@@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53549 uid = make_kuid(current_user_ns(), user);
53550 gid = make_kgid(current_user_ns(), group);
53551
53552+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
53553+ return -EACCES;
53554+
53555 newattrs.ia_valid = ATTR_CTIME;
53556 if (user != (uid_t) -1) {
53557 if (!uid_valid(uid))
53558@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53559 } else {
53560 fsnotify_open(f);
53561 fd_install(fd, f);
53562+ trace_do_sys_open(tmp->name, flags, mode);
53563 }
53564 }
53565 putname(tmp);
53566diff --git a/fs/pipe.c b/fs/pipe.c
53567index bd3479d..fb92c4d 100644
53568--- a/fs/pipe.c
53569+++ b/fs/pipe.c
53570@@ -438,9 +438,9 @@ redo:
53571 }
53572 if (bufs) /* More to do? */
53573 continue;
53574- if (!pipe->writers)
53575+ if (!atomic_read(&pipe->writers))
53576 break;
53577- if (!pipe->waiting_writers) {
53578+ if (!atomic_read(&pipe->waiting_writers)) {
53579 /* syscall merging: Usually we must not sleep
53580 * if O_NONBLOCK is set, or if we got some data.
53581 * But if a writer sleeps in kernel space, then
53582@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53583 mutex_lock(&inode->i_mutex);
53584 pipe = inode->i_pipe;
53585
53586- if (!pipe->readers) {
53587+ if (!atomic_read(&pipe->readers)) {
53588 send_sig(SIGPIPE, current, 0);
53589 ret = -EPIPE;
53590 goto out;
53591@@ -553,7 +553,7 @@ redo1:
53592 for (;;) {
53593 int bufs;
53594
53595- if (!pipe->readers) {
53596+ if (!atomic_read(&pipe->readers)) {
53597 send_sig(SIGPIPE, current, 0);
53598 if (!ret)
53599 ret = -EPIPE;
53600@@ -644,9 +644,9 @@ redo2:
53601 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53602 do_wakeup = 0;
53603 }
53604- pipe->waiting_writers++;
53605+ atomic_inc(&pipe->waiting_writers);
53606 pipe_wait(pipe);
53607- pipe->waiting_writers--;
53608+ atomic_dec(&pipe->waiting_writers);
53609 }
53610 out:
53611 mutex_unlock(&inode->i_mutex);
53612@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53613 mask = 0;
53614 if (filp->f_mode & FMODE_READ) {
53615 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53616- if (!pipe->writers && filp->f_version != pipe->w_counter)
53617+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53618 mask |= POLLHUP;
53619 }
53620
53621@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53622 * Most Unices do not set POLLERR for FIFOs but on Linux they
53623 * behave exactly like pipes for poll().
53624 */
53625- if (!pipe->readers)
53626+ if (!atomic_read(&pipe->readers))
53627 mask |= POLLERR;
53628 }
53629
53630@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
53631
53632 mutex_lock(&inode->i_mutex);
53633 pipe = inode->i_pipe;
53634- pipe->readers -= decr;
53635- pipe->writers -= decw;
53636+ atomic_sub(decr, &pipe->readers);
53637+ atomic_sub(decw, &pipe->writers);
53638
53639- if (!pipe->readers && !pipe->writers) {
53640+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
53641 free_pipe_info(inode);
53642 } else {
53643 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
53644@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
53645
53646 if (inode->i_pipe) {
53647 ret = 0;
53648- inode->i_pipe->readers++;
53649+ atomic_inc(&inode->i_pipe->readers);
53650 }
53651
53652 mutex_unlock(&inode->i_mutex);
53653@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
53654
53655 if (inode->i_pipe) {
53656 ret = 0;
53657- inode->i_pipe->writers++;
53658+ atomic_inc(&inode->i_pipe->writers);
53659 }
53660
53661 mutex_unlock(&inode->i_mutex);
53662@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
53663 if (inode->i_pipe) {
53664 ret = 0;
53665 if (filp->f_mode & FMODE_READ)
53666- inode->i_pipe->readers++;
53667+ atomic_inc(&inode->i_pipe->readers);
53668 if (filp->f_mode & FMODE_WRITE)
53669- inode->i_pipe->writers++;
53670+ atomic_inc(&inode->i_pipe->writers);
53671 }
53672
53673 mutex_unlock(&inode->i_mutex);
53674@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
53675 inode->i_pipe = NULL;
53676 }
53677
53678-static struct vfsmount *pipe_mnt __read_mostly;
53679+struct vfsmount *pipe_mnt __read_mostly;
53680
53681 /*
53682 * pipefs_dname() is called from d_path().
53683@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
53684 goto fail_iput;
53685 inode->i_pipe = pipe;
53686
53687- pipe->readers = pipe->writers = 1;
53688+ atomic_set(&pipe->readers, 1);
53689+ atomic_set(&pipe->writers, 1);
53690 inode->i_fop = &rdwr_pipefifo_fops;
53691
53692 /*
53693diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
53694index 15af622..0e9f4467 100644
53695--- a/fs/proc/Kconfig
53696+++ b/fs/proc/Kconfig
53697@@ -30,12 +30,12 @@ config PROC_FS
53698
53699 config PROC_KCORE
53700 bool "/proc/kcore support" if !ARM
53701- depends on PROC_FS && MMU
53702+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
53703
53704 config PROC_VMCORE
53705 bool "/proc/vmcore support"
53706- depends on PROC_FS && CRASH_DUMP
53707- default y
53708+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
53709+ default n
53710 help
53711 Exports the dump image of crashed kernel in ELF format.
53712
53713@@ -59,8 +59,8 @@ config PROC_SYSCTL
53714 limited in memory.
53715
53716 config PROC_PAGE_MONITOR
53717- default y
53718- depends on PROC_FS && MMU
53719+ default n
53720+ depends on PROC_FS && MMU && !GRKERNSEC
53721 bool "Enable /proc page monitoring" if EXPERT
53722 help
53723 Various /proc files exist to monitor process memory utilization:
53724diff --git a/fs/proc/array.c b/fs/proc/array.c
53725index 6a91e6f..e54dbc14 100644
53726--- a/fs/proc/array.c
53727+++ b/fs/proc/array.c
53728@@ -60,6 +60,7 @@
53729 #include <linux/tty.h>
53730 #include <linux/string.h>
53731 #include <linux/mman.h>
53732+#include <linux/grsecurity.h>
53733 #include <linux/proc_fs.h>
53734 #include <linux/ioport.h>
53735 #include <linux/uaccess.h>
53736@@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
53737 seq_putc(m, '\n');
53738 }
53739
53740+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53741+static inline void task_pax(struct seq_file *m, struct task_struct *p)
53742+{
53743+ if (p->mm)
53744+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
53745+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
53746+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
53747+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
53748+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
53749+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
53750+ else
53751+ seq_printf(m, "PaX:\t-----\n");
53752+}
53753+#endif
53754+
53755 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53756 struct pid *pid, struct task_struct *task)
53757 {
53758@@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53759 task_cpus_allowed(m, task);
53760 cpuset_task_status_allowed(m, task);
53761 task_context_switch_counts(m, task);
53762+
53763+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53764+ task_pax(m, task);
53765+#endif
53766+
53767+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
53768+ task_grsec_rbac(m, task);
53769+#endif
53770+
53771 return 0;
53772 }
53773
53774+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53775+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53776+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
53777+ _mm->pax_flags & MF_PAX_SEGMEXEC))
53778+#endif
53779+
53780 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53781 struct pid *pid, struct task_struct *task, int whole)
53782 {
53783@@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53784 char tcomm[sizeof(task->comm)];
53785 unsigned long flags;
53786
53787+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53788+ if (current->exec_id != m->exec_id) {
53789+ gr_log_badprocpid("stat");
53790+ return 0;
53791+ }
53792+#endif
53793+
53794 state = *get_task_state(task);
53795 vsize = eip = esp = 0;
53796 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53797@@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53798 gtime = task->gtime;
53799 }
53800
53801+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53802+ if (PAX_RAND_FLAGS(mm)) {
53803+ eip = 0;
53804+ esp = 0;
53805+ wchan = 0;
53806+ }
53807+#endif
53808+#ifdef CONFIG_GRKERNSEC_HIDESYM
53809+ wchan = 0;
53810+ eip =0;
53811+ esp =0;
53812+#endif
53813+
53814 /* scale priority and nice values from timeslices to -20..20 */
53815 /* to make it look like a "normal" Unix priority/nice value */
53816 priority = task_prio(task);
53817@@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53818 seq_put_decimal_ull(m, ' ', vsize);
53819 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
53820 seq_put_decimal_ull(m, ' ', rsslim);
53821+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53822+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
53823+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
53824+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
53825+#else
53826 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
53827 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
53828 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
53829+#endif
53830 seq_put_decimal_ull(m, ' ', esp);
53831 seq_put_decimal_ull(m, ' ', eip);
53832 /* The signal information here is obsolete.
53833@@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53834 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
53835 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
53836
53837- if (mm && permitted) {
53838+ if (mm && permitted
53839+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53840+ && !PAX_RAND_FLAGS(mm)
53841+#endif
53842+ ) {
53843 seq_put_decimal_ull(m, ' ', mm->start_data);
53844 seq_put_decimal_ull(m, ' ', mm->end_data);
53845 seq_put_decimal_ull(m, ' ', mm->start_brk);
53846@@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53847 struct pid *pid, struct task_struct *task)
53848 {
53849 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
53850- struct mm_struct *mm = get_task_mm(task);
53851+ struct mm_struct *mm;
53852
53853+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53854+ if (current->exec_id != m->exec_id) {
53855+ gr_log_badprocpid("statm");
53856+ return 0;
53857+ }
53858+#endif
53859+ mm = get_task_mm(task);
53860 if (mm) {
53861 size = task_statm(mm, &shared, &text, &data, &resident);
53862 mmput(mm);
53863@@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53864 return 0;
53865 }
53866
53867+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53868+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
53869+{
53870+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
53871+}
53872+#endif
53873+
53874 #ifdef CONFIG_CHECKPOINT_RESTORE
53875 static struct pid *
53876 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
53877diff --git a/fs/proc/base.c b/fs/proc/base.c
53878index 9b43ff77..ba3e990 100644
53879--- a/fs/proc/base.c
53880+++ b/fs/proc/base.c
53881@@ -111,6 +111,14 @@ struct pid_entry {
53882 union proc_op op;
53883 };
53884
53885+struct getdents_callback {
53886+ struct linux_dirent __user * current_dir;
53887+ struct linux_dirent __user * previous;
53888+ struct file * file;
53889+ int count;
53890+ int error;
53891+};
53892+
53893 #define NOD(NAME, MODE, IOP, FOP, OP) { \
53894 .name = (NAME), \
53895 .len = sizeof(NAME) - 1, \
53896@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
53897 if (!mm->arg_end)
53898 goto out_mm; /* Shh! No looking before we're done */
53899
53900+ if (gr_acl_handle_procpidmem(task))
53901+ goto out_mm;
53902+
53903 len = mm->arg_end - mm->arg_start;
53904
53905 if (len > PAGE_SIZE)
53906@@ -235,12 +246,28 @@ out:
53907 return res;
53908 }
53909
53910+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53911+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53912+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
53913+ _mm->pax_flags & MF_PAX_SEGMEXEC))
53914+#endif
53915+
53916 static int proc_pid_auxv(struct task_struct *task, char *buffer)
53917 {
53918 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
53919 int res = PTR_ERR(mm);
53920 if (mm && !IS_ERR(mm)) {
53921 unsigned int nwords = 0;
53922+
53923+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53924+ /* allow if we're currently ptracing this task */
53925+ if (PAX_RAND_FLAGS(mm) &&
53926+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
53927+ mmput(mm);
53928+ return 0;
53929+ }
53930+#endif
53931+
53932 do {
53933 nwords += 2;
53934 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
53935@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
53936 }
53937
53938
53939-#ifdef CONFIG_KALLSYMS
53940+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53941 /*
53942 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
53943 * Returns the resolved symbol. If that fails, simply return the address.
53944@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
53945 mutex_unlock(&task->signal->cred_guard_mutex);
53946 }
53947
53948-#ifdef CONFIG_STACKTRACE
53949+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53950
53951 #define MAX_STACK_TRACE_DEPTH 64
53952
53953@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
53954 return count;
53955 }
53956
53957-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53958+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53959 static int proc_pid_syscall(struct task_struct *task, char *buffer)
53960 {
53961 long nr;
53962@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
53963 /************************************************************************/
53964
53965 /* permission checks */
53966-static int proc_fd_access_allowed(struct inode *inode)
53967+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
53968 {
53969 struct task_struct *task;
53970 int allowed = 0;
53971@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
53972 */
53973 task = get_proc_task(inode);
53974 if (task) {
53975- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53976+ if (log)
53977+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53978+ else
53979+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53980 put_task_struct(task);
53981 }
53982 return allowed;
53983@@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
53984 struct task_struct *task,
53985 int hide_pid_min)
53986 {
53987+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53988+ return false;
53989+
53990+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53991+ rcu_read_lock();
53992+ {
53993+ const struct cred *tmpcred = current_cred();
53994+ const struct cred *cred = __task_cred(task);
53995+
53996+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
53997+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53998+ || in_group_p(grsec_proc_gid)
53999+#endif
54000+ ) {
54001+ rcu_read_unlock();
54002+ return true;
54003+ }
54004+ }
54005+ rcu_read_unlock();
54006+
54007+ if (!pid->hide_pid)
54008+ return false;
54009+#endif
54010+
54011 if (pid->hide_pid < hide_pid_min)
54012 return true;
54013 if (in_group_p(pid->pid_gid))
54014 return true;
54015+
54016 return ptrace_may_access(task, PTRACE_MODE_READ);
54017 }
54018
54019@@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54020 put_task_struct(task);
54021
54022 if (!has_perms) {
54023+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54024+ {
54025+#else
54026 if (pid->hide_pid == 2) {
54027+#endif
54028 /*
54029 * Let's make getdents(), stat(), and open()
54030 * consistent with each other. If a process
54031@@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54032 if (!task)
54033 return -ESRCH;
54034
54035+ if (gr_acl_handle_procpidmem(task)) {
54036+ put_task_struct(task);
54037+ return -EPERM;
54038+ }
54039+
54040 mm = mm_access(task, mode);
54041 put_task_struct(task);
54042
54043@@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54044
54045 file->private_data = mm;
54046
54047+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54048+ file->f_version = current->exec_id;
54049+#endif
54050+
54051 return 0;
54052 }
54053
54054@@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54055 ssize_t copied;
54056 char *page;
54057
54058+#ifdef CONFIG_GRKERNSEC
54059+ if (write)
54060+ return -EPERM;
54061+#endif
54062+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54063+ if (file->f_version != current->exec_id) {
54064+ gr_log_badprocpid("mem");
54065+ return 0;
54066+ }
54067+#endif
54068+
54069 if (!mm)
54070 return 0;
54071
54072@@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54073 if (!mm)
54074 return 0;
54075
54076+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54077+ if (file->f_version != current->exec_id) {
54078+ gr_log_badprocpid("environ");
54079+ return 0;
54080+ }
54081+#endif
54082+
54083 page = (char *)__get_free_page(GFP_TEMPORARY);
54084 if (!page)
54085 return -ENOMEM;
54086@@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54087 int error = -EACCES;
54088
54089 /* Are we allowed to snoop on the tasks file descriptors? */
54090- if (!proc_fd_access_allowed(inode))
54091+ if (!proc_fd_access_allowed(inode, 0))
54092 goto out;
54093
54094 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54095@@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54096 struct path path;
54097
54098 /* Are we allowed to snoop on the tasks file descriptors? */
54099- if (!proc_fd_access_allowed(inode))
54100- goto out;
54101+ /* logging this is needed for learning on chromium to work properly,
54102+ but we don't want to flood the logs from 'ps' which does a readlink
54103+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54104+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
54105+ */
54106+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54107+ if (!proc_fd_access_allowed(inode,0))
54108+ goto out;
54109+ } else {
54110+ if (!proc_fd_access_allowed(inode,1))
54111+ goto out;
54112+ }
54113
54114 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54115 if (error)
54116@@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54117 rcu_read_lock();
54118 cred = __task_cred(task);
54119 inode->i_uid = cred->euid;
54120+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54121+ inode->i_gid = grsec_proc_gid;
54122+#else
54123 inode->i_gid = cred->egid;
54124+#endif
54125 rcu_read_unlock();
54126 }
54127 security_task_to_inode(task, inode);
54128@@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54129 return -ENOENT;
54130 }
54131 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54132+#ifdef CONFIG_GRKERNSEC_PROC_USER
54133+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54134+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54135+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54136+#endif
54137 task_dumpable(task)) {
54138 cred = __task_cred(task);
54139 stat->uid = cred->euid;
54140+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54141+ stat->gid = grsec_proc_gid;
54142+#else
54143 stat->gid = cred->egid;
54144+#endif
54145 }
54146 }
54147 rcu_read_unlock();
54148@@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54149
54150 if (task) {
54151 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54152+#ifdef CONFIG_GRKERNSEC_PROC_USER
54153+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54154+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54155+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54156+#endif
54157 task_dumpable(task)) {
54158 rcu_read_lock();
54159 cred = __task_cred(task);
54160 inode->i_uid = cred->euid;
54161+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54162+ inode->i_gid = grsec_proc_gid;
54163+#else
54164 inode->i_gid = cred->egid;
54165+#endif
54166 rcu_read_unlock();
54167 } else {
54168 inode->i_uid = GLOBAL_ROOT_UID;
54169@@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54170 if (!task)
54171 goto out_no_task;
54172
54173+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54174+ goto out;
54175+
54176 /*
54177 * Yes, it does not scale. And it should not. Don't add
54178 * new entries into /proc/<tgid>/ without very good reasons.
54179@@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54180 if (!task)
54181 goto out_no_task;
54182
54183+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54184+ goto out;
54185+
54186 ret = 0;
54187 i = filp->f_pos;
54188 switch (i) {
54189@@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54190 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54191 #endif
54192 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54193-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54194+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54195 INF("syscall", S_IRUGO, proc_pid_syscall),
54196 #endif
54197 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54198@@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54199 #ifdef CONFIG_SECURITY
54200 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54201 #endif
54202-#ifdef CONFIG_KALLSYMS
54203+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54204 INF("wchan", S_IRUGO, proc_pid_wchan),
54205 #endif
54206-#ifdef CONFIG_STACKTRACE
54207+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54208 ONE("stack", S_IRUGO, proc_pid_stack),
54209 #endif
54210 #ifdef CONFIG_SCHEDSTATS
54211@@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54212 #ifdef CONFIG_HARDWALL
54213 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54214 #endif
54215+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54216+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54217+#endif
54218 #ifdef CONFIG_USER_NS
54219 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54220 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54221@@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54222 if (!inode)
54223 goto out;
54224
54225+#ifdef CONFIG_GRKERNSEC_PROC_USER
54226+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54227+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54228+ inode->i_gid = grsec_proc_gid;
54229+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54230+#else
54231 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54232+#endif
54233 inode->i_op = &proc_tgid_base_inode_operations;
54234 inode->i_fop = &proc_tgid_base_operations;
54235 inode->i_flags|=S_IMMUTABLE;
54236@@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54237 if (!task)
54238 goto out;
54239
54240+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54241+ goto out_put_task;
54242+
54243 result = proc_pid_instantiate(dir, dentry, task, NULL);
54244+out_put_task:
54245 put_task_struct(task);
54246 out:
54247 return result;
54248@@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54249 static int fake_filldir(void *buf, const char *name, int namelen,
54250 loff_t offset, u64 ino, unsigned d_type)
54251 {
54252+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
54253+ __buf->error = -EINVAL;
54254 return 0;
54255 }
54256
54257@@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54258 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54259 #endif
54260 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54261-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54262+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54263 INF("syscall", S_IRUGO, proc_pid_syscall),
54264 #endif
54265 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54266@@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54267 #ifdef CONFIG_SECURITY
54268 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54269 #endif
54270-#ifdef CONFIG_KALLSYMS
54271+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54272 INF("wchan", S_IRUGO, proc_pid_wchan),
54273 #endif
54274-#ifdef CONFIG_STACKTRACE
54275+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54276 ONE("stack", S_IRUGO, proc_pid_stack),
54277 #endif
54278 #ifdef CONFIG_SCHEDSTATS
54279diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54280index 82676e3..5f8518a 100644
54281--- a/fs/proc/cmdline.c
54282+++ b/fs/proc/cmdline.c
54283@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54284
54285 static int __init proc_cmdline_init(void)
54286 {
54287+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54288+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54289+#else
54290 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54291+#endif
54292 return 0;
54293 }
54294 module_init(proc_cmdline_init);
54295diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54296index b143471..bb105e5 100644
54297--- a/fs/proc/devices.c
54298+++ b/fs/proc/devices.c
54299@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54300
54301 static int __init proc_devices_init(void)
54302 {
54303+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54304+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54305+#else
54306 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54307+#endif
54308 return 0;
54309 }
54310 module_init(proc_devices_init);
54311diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54312index d7a4a28..0201742 100644
54313--- a/fs/proc/fd.c
54314+++ b/fs/proc/fd.c
54315@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54316 if (!task)
54317 return -ENOENT;
54318
54319- files = get_files_struct(task);
54320+ if (!gr_acl_handle_procpidmem(task))
54321+ files = get_files_struct(task);
54322 put_task_struct(task);
54323
54324 if (files) {
54325@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54326 */
54327 int proc_fd_permission(struct inode *inode, int mask)
54328 {
54329+ struct task_struct *task;
54330 int rv = generic_permission(inode, mask);
54331- if (rv == 0)
54332- return 0;
54333+
54334 if (task_pid(current) == proc_pid(inode))
54335 rv = 0;
54336+
54337+ task = get_proc_task(inode);
54338+ if (task == NULL)
54339+ return rv;
54340+
54341+ if (gr_acl_handle_procpidmem(task))
54342+ rv = -EACCES;
54343+
54344+ put_task_struct(task);
54345+
54346 return rv;
54347 }
54348
54349diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54350index 439ae688..c21ac36 100644
54351--- a/fs/proc/inode.c
54352+++ b/fs/proc/inode.c
54353@@ -21,11 +21,17 @@
54354 #include <linux/seq_file.h>
54355 #include <linux/slab.h>
54356 #include <linux/mount.h>
54357+#include <linux/grsecurity.h>
54358
54359 #include <asm/uaccess.h>
54360
54361 #include "internal.h"
54362
54363+#ifdef CONFIG_PROC_SYSCTL
54364+extern const struct inode_operations proc_sys_inode_operations;
54365+extern const struct inode_operations proc_sys_dir_operations;
54366+#endif
54367+
54368 static void proc_evict_inode(struct inode *inode)
54369 {
54370 struct proc_dir_entry *de;
54371@@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54372 ns = PROC_I(inode)->ns;
54373 if (ns_ops && ns)
54374 ns_ops->put(ns);
54375+
54376+#ifdef CONFIG_PROC_SYSCTL
54377+ if (inode->i_op == &proc_sys_inode_operations ||
54378+ inode->i_op == &proc_sys_dir_operations)
54379+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54380+#endif
54381+
54382 }
54383
54384 static struct kmem_cache * proc_inode_cachep;
54385@@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54386 if (de->mode) {
54387 inode->i_mode = de->mode;
54388 inode->i_uid = de->uid;
54389+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54390+ inode->i_gid = grsec_proc_gid;
54391+#else
54392 inode->i_gid = de->gid;
54393+#endif
54394 }
54395 if (de->size)
54396 inode->i_size = de->size;
54397diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54398index 252544c..04395b9 100644
54399--- a/fs/proc/internal.h
54400+++ b/fs/proc/internal.h
54401@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54402 struct pid *pid, struct task_struct *task);
54403 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54404 struct pid *pid, struct task_struct *task);
54405+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54406+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54407+#endif
54408 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54409
54410 extern const struct file_operations proc_tid_children_operations;
54411diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54412index e96d4f1..8b116ed 100644
54413--- a/fs/proc/kcore.c
54414+++ b/fs/proc/kcore.c
54415@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54416 * the addresses in the elf_phdr on our list.
54417 */
54418 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54419- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54420+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54421+ if (tsz > buflen)
54422 tsz = buflen;
54423-
54424+
54425 while (buflen) {
54426 struct kcore_list *m;
54427
54428@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54429 kfree(elf_buf);
54430 } else {
54431 if (kern_addr_valid(start)) {
54432- unsigned long n;
54433+ char *elf_buf;
54434+ mm_segment_t oldfs;
54435
54436- n = copy_to_user(buffer, (char *)start, tsz);
54437- /*
54438- * We cannot distinguish between fault on source
54439- * and fault on destination. When this happens
54440- * we clear too and hope it will trigger the
54441- * EFAULT again.
54442- */
54443- if (n) {
54444- if (clear_user(buffer + tsz - n,
54445- n))
54446+ elf_buf = kmalloc(tsz, GFP_KERNEL);
54447+ if (!elf_buf)
54448+ return -ENOMEM;
54449+ oldfs = get_fs();
54450+ set_fs(KERNEL_DS);
54451+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54452+ set_fs(oldfs);
54453+ if (copy_to_user(buffer, elf_buf, tsz)) {
54454+ kfree(elf_buf);
54455 return -EFAULT;
54456+ }
54457 }
54458+ set_fs(oldfs);
54459+ kfree(elf_buf);
54460 } else {
54461 if (clear_user(buffer, tsz))
54462 return -EFAULT;
54463@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54464
54465 static int open_kcore(struct inode *inode, struct file *filp)
54466 {
54467+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54468+ return -EPERM;
54469+#endif
54470 if (!capable(CAP_SYS_RAWIO))
54471 return -EPERM;
54472 if (kcore_need_update)
54473diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54474index 80e4645..53e5fcf 100644
54475--- a/fs/proc/meminfo.c
54476+++ b/fs/proc/meminfo.c
54477@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54478 vmi.used >> 10,
54479 vmi.largest_chunk >> 10
54480 #ifdef CONFIG_MEMORY_FAILURE
54481- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54482+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54483 #endif
54484 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54485 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54486diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54487index b1822dd..df622cb 100644
54488--- a/fs/proc/nommu.c
54489+++ b/fs/proc/nommu.c
54490@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54491 if (len < 1)
54492 len = 1;
54493 seq_printf(m, "%*c", len, ' ');
54494- seq_path(m, &file->f_path, "");
54495+ seq_path(m, &file->f_path, "\n\\");
54496 }
54497
54498 seq_putc(m, '\n');
54499diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54500index fe72cd0..21b52ff 100644
54501--- a/fs/proc/proc_net.c
54502+++ b/fs/proc/proc_net.c
54503@@ -23,6 +23,7 @@
54504 #include <linux/nsproxy.h>
54505 #include <net/net_namespace.h>
54506 #include <linux/seq_file.h>
54507+#include <linux/grsecurity.h>
54508
54509 #include "internal.h"
54510
54511@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54512 struct task_struct *task;
54513 struct nsproxy *ns;
54514 struct net *net = NULL;
54515+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54516+ const struct cred *cred = current_cred();
54517+#endif
54518+
54519+#ifdef CONFIG_GRKERNSEC_PROC_USER
54520+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54521+ return net;
54522+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54523+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54524+ return net;
54525+#endif
54526
54527 rcu_read_lock();
54528 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54529diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54530index 1827d88..43b0279 100644
54531--- a/fs/proc/proc_sysctl.c
54532+++ b/fs/proc/proc_sysctl.c
54533@@ -12,11 +12,15 @@
54534 #include <linux/module.h>
54535 #include "internal.h"
54536
54537+extern int gr_handle_chroot_sysctl(const int op);
54538+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54539+ const int op);
54540+
54541 static const struct dentry_operations proc_sys_dentry_operations;
54542 static const struct file_operations proc_sys_file_operations;
54543-static const struct inode_operations proc_sys_inode_operations;
54544+const struct inode_operations proc_sys_inode_operations;
54545 static const struct file_operations proc_sys_dir_file_operations;
54546-static const struct inode_operations proc_sys_dir_operations;
54547+const struct inode_operations proc_sys_dir_operations;
54548
54549 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54550 {
54551@@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54552
54553 err = NULL;
54554 d_set_d_op(dentry, &proc_sys_dentry_operations);
54555+
54556+ gr_handle_proc_create(dentry, inode);
54557+
54558 d_add(dentry, inode);
54559
54560 out:
54561@@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54562 struct inode *inode = filp->f_path.dentry->d_inode;
54563 struct ctl_table_header *head = grab_header(inode);
54564 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54565+ int op = write ? MAY_WRITE : MAY_READ;
54566 ssize_t error;
54567 size_t res;
54568
54569@@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54570 * and won't be until we finish.
54571 */
54572 error = -EPERM;
54573- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54574+ if (sysctl_perm(head, table, op))
54575 goto out;
54576
54577 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54578@@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54579 if (!table->proc_handler)
54580 goto out;
54581
54582+#ifdef CONFIG_GRKERNSEC
54583+ error = -EPERM;
54584+ if (gr_handle_chroot_sysctl(op))
54585+ goto out;
54586+ dget(filp->f_path.dentry);
54587+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54588+ dput(filp->f_path.dentry);
54589+ goto out;
54590+ }
54591+ dput(filp->f_path.dentry);
54592+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54593+ goto out;
54594+ if (write && !capable(CAP_SYS_ADMIN))
54595+ goto out;
54596+#endif
54597+
54598 /* careful: calling conventions are nasty here */
54599 res = count;
54600 error = table->proc_handler(table, write, buf, &res, ppos);
54601@@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54602 return -ENOMEM;
54603 } else {
54604 d_set_d_op(child, &proc_sys_dentry_operations);
54605+
54606+ gr_handle_proc_create(child, inode);
54607+
54608 d_add(child, inode);
54609 }
54610 } else {
54611@@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54612 if ((*pos)++ < file->f_pos)
54613 return 0;
54614
54615+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54616+ return 0;
54617+
54618 if (unlikely(S_ISLNK(table->mode)))
54619 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
54620 else
54621@@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
54622 if (IS_ERR(head))
54623 return PTR_ERR(head);
54624
54625+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
54626+ return -ENOENT;
54627+
54628 generic_fillattr(inode, stat);
54629 if (table)
54630 stat->mode = (stat->mode & S_IFMT) | table->mode;
54631@@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
54632 .llseek = generic_file_llseek,
54633 };
54634
54635-static const struct inode_operations proc_sys_inode_operations = {
54636+const struct inode_operations proc_sys_inode_operations = {
54637 .permission = proc_sys_permission,
54638 .setattr = proc_sys_setattr,
54639 .getattr = proc_sys_getattr,
54640 };
54641
54642-static const struct inode_operations proc_sys_dir_operations = {
54643+const struct inode_operations proc_sys_dir_operations = {
54644 .lookup = proc_sys_lookup,
54645 .permission = proc_sys_permission,
54646 .setattr = proc_sys_setattr,
54647@@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
54648 static struct ctl_dir *new_dir(struct ctl_table_set *set,
54649 const char *name, int namelen)
54650 {
54651- struct ctl_table *table;
54652+ ctl_table_no_const *table;
54653 struct ctl_dir *new;
54654 struct ctl_node *node;
54655 char *new_name;
54656@@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
54657 return NULL;
54658
54659 node = (struct ctl_node *)(new + 1);
54660- table = (struct ctl_table *)(node + 1);
54661+ table = (ctl_table_no_const *)(node + 1);
54662 new_name = (char *)(table + 2);
54663 memcpy(new_name, name, namelen);
54664 new_name[namelen] = '\0';
54665@@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
54666 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
54667 struct ctl_table_root *link_root)
54668 {
54669- struct ctl_table *link_table, *entry, *link;
54670+ ctl_table_no_const *link_table, *link;
54671+ struct ctl_table *entry;
54672 struct ctl_table_header *links;
54673 struct ctl_node *node;
54674 char *link_name;
54675@@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
54676 return NULL;
54677
54678 node = (struct ctl_node *)(links + 1);
54679- link_table = (struct ctl_table *)(node + nr_entries);
54680+ link_table = (ctl_table_no_const *)(node + nr_entries);
54681 link_name = (char *)&link_table[nr_entries + 1];
54682
54683 for (link = link_table, entry = table; entry->procname; link++, entry++) {
54684@@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54685 struct ctl_table_header ***subheader, struct ctl_table_set *set,
54686 struct ctl_table *table)
54687 {
54688- struct ctl_table *ctl_table_arg = NULL;
54689- struct ctl_table *entry, *files;
54690+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
54691+ struct ctl_table *entry;
54692 int nr_files = 0;
54693 int nr_dirs = 0;
54694 int err = -ENOMEM;
54695@@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54696 nr_files++;
54697 }
54698
54699- files = table;
54700 /* If there are mixed files and directories we need a new table */
54701 if (nr_dirs && nr_files) {
54702- struct ctl_table *new;
54703+ ctl_table_no_const *new;
54704 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
54705 GFP_KERNEL);
54706 if (!files)
54707@@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54708 /* Register everything except a directory full of subdirectories */
54709 if (nr_files || !nr_dirs) {
54710 struct ctl_table_header *header;
54711- header = __register_sysctl_table(set, path, files);
54712+ header = __register_sysctl_table(set, path, files ? files : table);
54713 if (!header) {
54714 kfree(ctl_table_arg);
54715 goto out;
54716diff --git a/fs/proc/root.c b/fs/proc/root.c
54717index c6e9fac..a740964 100644
54718--- a/fs/proc/root.c
54719+++ b/fs/proc/root.c
54720@@ -176,7 +176,15 @@ void __init proc_root_init(void)
54721 #ifdef CONFIG_PROC_DEVICETREE
54722 proc_device_tree_init();
54723 #endif
54724+#ifdef CONFIG_GRKERNSEC_PROC_ADD
54725+#ifdef CONFIG_GRKERNSEC_PROC_USER
54726+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
54727+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54728+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
54729+#endif
54730+#else
54731 proc_mkdir("bus", NULL);
54732+#endif
54733 proc_sys_init();
54734 }
54735
54736diff --git a/fs/proc/self.c b/fs/proc/self.c
54737index aa5cc3b..c91a5d0 100644
54738--- a/fs/proc/self.c
54739+++ b/fs/proc/self.c
54740@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
54741 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
54742 void *cookie)
54743 {
54744- char *s = nd_get_link(nd);
54745+ const char *s = nd_get_link(nd);
54746 if (!IS_ERR(s))
54747 kfree(s);
54748 }
54749diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
54750index ca5ce7f..02c1cf0 100644
54751--- a/fs/proc/task_mmu.c
54752+++ b/fs/proc/task_mmu.c
54753@@ -11,12 +11,19 @@
54754 #include <linux/rmap.h>
54755 #include <linux/swap.h>
54756 #include <linux/swapops.h>
54757+#include <linux/grsecurity.h>
54758
54759 #include <asm/elf.h>
54760 #include <asm/uaccess.h>
54761 #include <asm/tlbflush.h>
54762 #include "internal.h"
54763
54764+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54765+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54766+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54767+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54768+#endif
54769+
54770 void task_mem(struct seq_file *m, struct mm_struct *mm)
54771 {
54772 unsigned long data, text, lib, swap;
54773@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54774 "VmExe:\t%8lu kB\n"
54775 "VmLib:\t%8lu kB\n"
54776 "VmPTE:\t%8lu kB\n"
54777- "VmSwap:\t%8lu kB\n",
54778- hiwater_vm << (PAGE_SHIFT-10),
54779+ "VmSwap:\t%8lu kB\n"
54780+
54781+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54782+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
54783+#endif
54784+
54785+ ,hiwater_vm << (PAGE_SHIFT-10),
54786 total_vm << (PAGE_SHIFT-10),
54787 mm->locked_vm << (PAGE_SHIFT-10),
54788 mm->pinned_vm << (PAGE_SHIFT-10),
54789@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54790 data << (PAGE_SHIFT-10),
54791 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
54792 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
54793- swap << (PAGE_SHIFT-10));
54794+ swap << (PAGE_SHIFT-10)
54795+
54796+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54797+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54798+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
54799+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
54800+#else
54801+ , mm->context.user_cs_base
54802+ , mm->context.user_cs_limit
54803+#endif
54804+#endif
54805+
54806+ );
54807 }
54808
54809 unsigned long task_vsize(struct mm_struct *mm)
54810@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54811 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
54812 }
54813
54814- /* We don't show the stack guard page in /proc/maps */
54815+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54816+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
54817+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
54818+#else
54819 start = vma->vm_start;
54820- if (stack_guard_page_start(vma, start))
54821- start += PAGE_SIZE;
54822 end = vma->vm_end;
54823- if (stack_guard_page_end(vma, end))
54824- end -= PAGE_SIZE;
54825+#endif
54826
54827 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
54828 start,
54829@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54830 flags & VM_WRITE ? 'w' : '-',
54831 flags & VM_EXEC ? 'x' : '-',
54832 flags & VM_MAYSHARE ? 's' : 'p',
54833+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54834+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
54835+#else
54836 pgoff,
54837+#endif
54838 MAJOR(dev), MINOR(dev), ino, &len);
54839
54840 /*
54841@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54842 */
54843 if (file) {
54844 pad_len_spaces(m, len);
54845- seq_path(m, &file->f_path, "\n");
54846+ seq_path(m, &file->f_path, "\n\\");
54847 goto done;
54848 }
54849
54850@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54851 * Thread stack in /proc/PID/task/TID/maps or
54852 * the main process stack.
54853 */
54854- if (!is_pid || (vma->vm_start <= mm->start_stack &&
54855- vma->vm_end >= mm->start_stack)) {
54856+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
54857+ (vma->vm_start <= mm->start_stack &&
54858+ vma->vm_end >= mm->start_stack)) {
54859 name = "[stack]";
54860 } else {
54861 /* Thread stack in /proc/PID/maps */
54862@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
54863 struct proc_maps_private *priv = m->private;
54864 struct task_struct *task = priv->task;
54865
54866+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54867+ if (current->exec_id != m->exec_id) {
54868+ gr_log_badprocpid("maps");
54869+ return 0;
54870+ }
54871+#endif
54872+
54873 show_map_vma(m, vma, is_pid);
54874
54875 if (m->count < m->size) /* vma is copied successfully */
54876@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54877 .private = &mss,
54878 };
54879
54880+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54881+ if (current->exec_id != m->exec_id) {
54882+ gr_log_badprocpid("smaps");
54883+ return 0;
54884+ }
54885+#endif
54886 memset(&mss, 0, sizeof mss);
54887- mss.vma = vma;
54888- /* mmap_sem is held in m_start */
54889- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54890- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54891-
54892+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54893+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
54894+#endif
54895+ mss.vma = vma;
54896+ /* mmap_sem is held in m_start */
54897+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54898+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54899+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54900+ }
54901+#endif
54902 show_map_vma(m, vma, is_pid);
54903
54904 seq_printf(m,
54905@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54906 "KernelPageSize: %8lu kB\n"
54907 "MMUPageSize: %8lu kB\n"
54908 "Locked: %8lu kB\n",
54909+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54910+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
54911+#else
54912 (vma->vm_end - vma->vm_start) >> 10,
54913+#endif
54914 mss.resident >> 10,
54915 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
54916 mss.shared_clean >> 10,
54917@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54918 int n;
54919 char buffer[50];
54920
54921+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54922+ if (current->exec_id != m->exec_id) {
54923+ gr_log_badprocpid("numa_maps");
54924+ return 0;
54925+ }
54926+#endif
54927+
54928 if (!mm)
54929 return 0;
54930
54931@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54932 mpol_to_str(buffer, sizeof(buffer), pol);
54933 mpol_cond_put(pol);
54934
54935+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54936+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
54937+#else
54938 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
54939+#endif
54940
54941 if (file) {
54942 seq_printf(m, " file=");
54943- seq_path(m, &file->f_path, "\n\t= ");
54944+ seq_path(m, &file->f_path, "\n\t\\= ");
54945 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
54946 seq_printf(m, " heap");
54947 } else {
54948diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
54949index 1ccfa53..0848f95 100644
54950--- a/fs/proc/task_nommu.c
54951+++ b/fs/proc/task_nommu.c
54952@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54953 else
54954 bytes += kobjsize(mm);
54955
54956- if (current->fs && current->fs->users > 1)
54957+ if (current->fs && atomic_read(&current->fs->users) > 1)
54958 sbytes += kobjsize(current->fs);
54959 else
54960 bytes += kobjsize(current->fs);
54961@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
54962
54963 if (file) {
54964 pad_len_spaces(m, len);
54965- seq_path(m, &file->f_path, "");
54966+ seq_path(m, &file->f_path, "\n\\");
54967 } else if (mm) {
54968 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
54969
54970diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
54971index 16e8abb..2dcf914 100644
54972--- a/fs/quota/netlink.c
54973+++ b/fs/quota/netlink.c
54974@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
54975 void quota_send_warning(struct kqid qid, dev_t dev,
54976 const char warntype)
54977 {
54978- static atomic_t seq;
54979+ static atomic_unchecked_t seq;
54980 struct sk_buff *skb;
54981 void *msg_head;
54982 int ret;
54983@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
54984 "VFS: Not enough memory to send quota warning.\n");
54985 return;
54986 }
54987- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
54988+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
54989 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
54990 if (!msg_head) {
54991 printk(KERN_ERR
54992diff --git a/fs/readdir.c b/fs/readdir.c
54993index 5e69ef5..e5d9099 100644
54994--- a/fs/readdir.c
54995+++ b/fs/readdir.c
54996@@ -17,6 +17,7 @@
54997 #include <linux/security.h>
54998 #include <linux/syscalls.h>
54999 #include <linux/unistd.h>
55000+#include <linux/namei.h>
55001
55002 #include <asm/uaccess.h>
55003
55004@@ -67,6 +68,7 @@ struct old_linux_dirent {
55005
55006 struct readdir_callback {
55007 struct old_linux_dirent __user * dirent;
55008+ struct file * file;
55009 int result;
55010 };
55011
55012@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55013 buf->result = -EOVERFLOW;
55014 return -EOVERFLOW;
55015 }
55016+
55017+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55018+ return 0;
55019+
55020 buf->result++;
55021 dirent = buf->dirent;
55022 if (!access_ok(VERIFY_WRITE, dirent,
55023@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55024
55025 buf.result = 0;
55026 buf.dirent = dirent;
55027+ buf.file = f.file;
55028
55029 error = vfs_readdir(f.file, fillonedir, &buf);
55030 if (buf.result)
55031@@ -139,6 +146,7 @@ struct linux_dirent {
55032 struct getdents_callback {
55033 struct linux_dirent __user * current_dir;
55034 struct linux_dirent __user * previous;
55035+ struct file * file;
55036 int count;
55037 int error;
55038 };
55039@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55040 buf->error = -EOVERFLOW;
55041 return -EOVERFLOW;
55042 }
55043+
55044+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55045+ return 0;
55046+
55047 dirent = buf->previous;
55048 if (dirent) {
55049 if (__put_user(offset, &dirent->d_off))
55050@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55051 buf.previous = NULL;
55052 buf.count = count;
55053 buf.error = 0;
55054+ buf.file = f.file;
55055
55056 error = vfs_readdir(f.file, filldir, &buf);
55057 if (error >= 0)
55058@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55059 struct getdents_callback64 {
55060 struct linux_dirent64 __user * current_dir;
55061 struct linux_dirent64 __user * previous;
55062+ struct file *file;
55063 int count;
55064 int error;
55065 };
55066@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55067 buf->error = -EINVAL; /* only used if we fail.. */
55068 if (reclen > buf->count)
55069 return -EINVAL;
55070+
55071+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55072+ return 0;
55073+
55074 dirent = buf->previous;
55075 if (dirent) {
55076 if (__put_user(offset, &dirent->d_off))
55077@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55078
55079 buf.current_dir = dirent;
55080 buf.previous = NULL;
55081+ buf.file = f.file;
55082 buf.count = count;
55083 buf.error = 0;
55084
55085@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55086 error = buf.error;
55087 lastdirent = buf.previous;
55088 if (lastdirent) {
55089- typeof(lastdirent->d_off) d_off = f.file->f_pos;
55090+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55091 if (__put_user(d_off, &lastdirent->d_off))
55092 error = -EFAULT;
55093 else
55094diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55095index 2b7882b..1c5ef48 100644
55096--- a/fs/reiserfs/do_balan.c
55097+++ b/fs/reiserfs/do_balan.c
55098@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55099 return;
55100 }
55101
55102- atomic_inc(&(fs_generation(tb->tb_sb)));
55103+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55104 do_balance_starts(tb);
55105
55106 /* balance leaf returns 0 except if combining L R and S into
55107diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55108index e60e870..f40ac16 100644
55109--- a/fs/reiserfs/procfs.c
55110+++ b/fs/reiserfs/procfs.c
55111@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55112 "SMALL_TAILS " : "NO_TAILS ",
55113 replay_only(sb) ? "REPLAY_ONLY " : "",
55114 convert_reiserfs(sb) ? "CONV " : "",
55115- atomic_read(&r->s_generation_counter),
55116+ atomic_read_unchecked(&r->s_generation_counter),
55117 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55118 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55119 SF(s_good_search_by_key_reada), SF(s_bmaps),
55120diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55121index 157e474..65a6114 100644
55122--- a/fs/reiserfs/reiserfs.h
55123+++ b/fs/reiserfs/reiserfs.h
55124@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55125 /* Comment? -Hans */
55126 wait_queue_head_t s_wait;
55127 /* To be obsoleted soon by per buffer seals.. -Hans */
55128- atomic_t s_generation_counter; // increased by one every time the
55129+ atomic_unchecked_t s_generation_counter; // increased by one every time the
55130 // tree gets re-balanced
55131 unsigned long s_properties; /* File system properties. Currently holds
55132 on-disk FS format */
55133@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55134 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55135
55136 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55137-#define get_generation(s) atomic_read (&fs_generation(s))
55138+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55139 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55140 #define __fs_changed(gen,s) (gen != get_generation (s))
55141 #define fs_changed(gen,s) \
55142diff --git a/fs/select.c b/fs/select.c
55143index 2ef72d9..f213b17 100644
55144--- a/fs/select.c
55145+++ b/fs/select.c
55146@@ -20,6 +20,7 @@
55147 #include <linux/export.h>
55148 #include <linux/slab.h>
55149 #include <linux/poll.h>
55150+#include <linux/security.h>
55151 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55152 #include <linux/file.h>
55153 #include <linux/fdtable.h>
55154@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55155 struct poll_list *walk = head;
55156 unsigned long todo = nfds;
55157
55158+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55159 if (nfds > rlimit(RLIMIT_NOFILE))
55160 return -EINVAL;
55161
55162diff --git a/fs/seq_file.c b/fs/seq_file.c
55163index f2bc3df..239d4f6 100644
55164--- a/fs/seq_file.c
55165+++ b/fs/seq_file.c
55166@@ -10,6 +10,7 @@
55167 #include <linux/seq_file.h>
55168 #include <linux/slab.h>
55169 #include <linux/cred.h>
55170+#include <linux/sched.h>
55171
55172 #include <asm/uaccess.h>
55173 #include <asm/page.h>
55174@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55175 #ifdef CONFIG_USER_NS
55176 p->user_ns = file->f_cred->user_ns;
55177 #endif
55178+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55179+ p->exec_id = current->exec_id;
55180+#endif
55181
55182 /*
55183 * Wrappers around seq_open(e.g. swaps_open) need to be
55184@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55185 return 0;
55186 }
55187 if (!m->buf) {
55188- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55189+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55190 if (!m->buf)
55191 return -ENOMEM;
55192 }
55193@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55194 Eoverflow:
55195 m->op->stop(m, p);
55196 kfree(m->buf);
55197- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55198+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55199 return !m->buf ? -ENOMEM : -EAGAIN;
55200 }
55201
55202@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55203
55204 /* grab buffer if we didn't have one */
55205 if (!m->buf) {
55206- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55207+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55208 if (!m->buf)
55209 goto Enomem;
55210 }
55211@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55212 goto Fill;
55213 m->op->stop(m, p);
55214 kfree(m->buf);
55215- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55216+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55217 if (!m->buf)
55218 goto Enomem;
55219 m->count = 0;
55220@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55221 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55222 void *data)
55223 {
55224- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55225+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55226 int res = -ENOMEM;
55227
55228 if (op) {
55229diff --git a/fs/splice.c b/fs/splice.c
55230index 6909d89..5b2e8f9 100644
55231--- a/fs/splice.c
55232+++ b/fs/splice.c
55233@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55234 pipe_lock(pipe);
55235
55236 for (;;) {
55237- if (!pipe->readers) {
55238+ if (!atomic_read(&pipe->readers)) {
55239 send_sig(SIGPIPE, current, 0);
55240 if (!ret)
55241 ret = -EPIPE;
55242@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55243 do_wakeup = 0;
55244 }
55245
55246- pipe->waiting_writers++;
55247+ atomic_inc(&pipe->waiting_writers);
55248 pipe_wait(pipe);
55249- pipe->waiting_writers--;
55250+ atomic_dec(&pipe->waiting_writers);
55251 }
55252
55253 pipe_unlock(pipe);
55254@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55255 old_fs = get_fs();
55256 set_fs(get_ds());
55257 /* The cast to a user pointer is valid due to the set_fs() */
55258- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55259+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55260 set_fs(old_fs);
55261
55262 return res;
55263@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55264 old_fs = get_fs();
55265 set_fs(get_ds());
55266 /* The cast to a user pointer is valid due to the set_fs() */
55267- res = vfs_write(file, (const char __user *)buf, count, &pos);
55268+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55269 set_fs(old_fs);
55270
55271 return res;
55272@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55273 goto err;
55274
55275 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55276- vec[i].iov_base = (void __user *) page_address(page);
55277+ vec[i].iov_base = (void __force_user *) page_address(page);
55278 vec[i].iov_len = this_len;
55279 spd.pages[i] = page;
55280 spd.nr_pages++;
55281@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55282 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55283 {
55284 while (!pipe->nrbufs) {
55285- if (!pipe->writers)
55286+ if (!atomic_read(&pipe->writers))
55287 return 0;
55288
55289- if (!pipe->waiting_writers && sd->num_spliced)
55290+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55291 return 0;
55292
55293 if (sd->flags & SPLICE_F_NONBLOCK)
55294@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55295 * out of the pipe right after the splice_to_pipe(). So set
55296 * PIPE_READERS appropriately.
55297 */
55298- pipe->readers = 1;
55299+ atomic_set(&pipe->readers, 1);
55300
55301 current->splice_pipe = pipe;
55302 }
55303@@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55304 ret = -ERESTARTSYS;
55305 break;
55306 }
55307- if (!pipe->writers)
55308+ if (!atomic_read(&pipe->writers))
55309 break;
55310- if (!pipe->waiting_writers) {
55311+ if (!atomic_read(&pipe->waiting_writers)) {
55312 if (flags & SPLICE_F_NONBLOCK) {
55313 ret = -EAGAIN;
55314 break;
55315@@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55316 pipe_lock(pipe);
55317
55318 while (pipe->nrbufs >= pipe->buffers) {
55319- if (!pipe->readers) {
55320+ if (!atomic_read(&pipe->readers)) {
55321 send_sig(SIGPIPE, current, 0);
55322 ret = -EPIPE;
55323 break;
55324@@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55325 ret = -ERESTARTSYS;
55326 break;
55327 }
55328- pipe->waiting_writers++;
55329+ atomic_inc(&pipe->waiting_writers);
55330 pipe_wait(pipe);
55331- pipe->waiting_writers--;
55332+ atomic_dec(&pipe->waiting_writers);
55333 }
55334
55335 pipe_unlock(pipe);
55336@@ -1823,14 +1823,14 @@ retry:
55337 pipe_double_lock(ipipe, opipe);
55338
55339 do {
55340- if (!opipe->readers) {
55341+ if (!atomic_read(&opipe->readers)) {
55342 send_sig(SIGPIPE, current, 0);
55343 if (!ret)
55344 ret = -EPIPE;
55345 break;
55346 }
55347
55348- if (!ipipe->nrbufs && !ipipe->writers)
55349+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55350 break;
55351
55352 /*
55353@@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55354 pipe_double_lock(ipipe, opipe);
55355
55356 do {
55357- if (!opipe->readers) {
55358+ if (!atomic_read(&opipe->readers)) {
55359 send_sig(SIGPIPE, current, 0);
55360 if (!ret)
55361 ret = -EPIPE;
55362@@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55363 * return EAGAIN if we have the potential of some data in the
55364 * future, otherwise just return 0
55365 */
55366- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55367+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55368 ret = -EAGAIN;
55369
55370 pipe_unlock(ipipe);
55371diff --git a/fs/stat.c b/fs/stat.c
55372index 14f4545..9b7f55b 100644
55373--- a/fs/stat.c
55374+++ b/fs/stat.c
55375@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55376 stat->gid = inode->i_gid;
55377 stat->rdev = inode->i_rdev;
55378 stat->size = i_size_read(inode);
55379- stat->atime = inode->i_atime;
55380- stat->mtime = inode->i_mtime;
55381+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55382+ stat->atime = inode->i_ctime;
55383+ stat->mtime = inode->i_ctime;
55384+ } else {
55385+ stat->atime = inode->i_atime;
55386+ stat->mtime = inode->i_mtime;
55387+ }
55388 stat->ctime = inode->i_ctime;
55389 stat->blksize = (1 << inode->i_blkbits);
55390 stat->blocks = inode->i_blocks;
55391@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55392 if (retval)
55393 return retval;
55394
55395- if (inode->i_op->getattr)
55396- return inode->i_op->getattr(mnt, dentry, stat);
55397+ if (inode->i_op->getattr) {
55398+ retval = inode->i_op->getattr(mnt, dentry, stat);
55399+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55400+ stat->atime = stat->ctime;
55401+ stat->mtime = stat->ctime;
55402+ }
55403+ return retval;
55404+ }
55405
55406 generic_fillattr(inode, stat);
55407 return 0;
55408diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55409index 2fbdff6..5530a61 100644
55410--- a/fs/sysfs/dir.c
55411+++ b/fs/sysfs/dir.c
55412@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55413 struct sysfs_dirent *sd;
55414 int rc;
55415
55416+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55417+ const char *parent_name = parent_sd->s_name;
55418+
55419+ mode = S_IFDIR | S_IRWXU;
55420+
55421+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55422+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55423+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55424+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55425+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55426+#endif
55427+
55428 /* allocate */
55429 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55430 if (!sd)
55431diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55432index 602f56d..6853db8 100644
55433--- a/fs/sysfs/file.c
55434+++ b/fs/sysfs/file.c
55435@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55436
55437 struct sysfs_open_dirent {
55438 atomic_t refcnt;
55439- atomic_t event;
55440+ atomic_unchecked_t event;
55441 wait_queue_head_t poll;
55442 struct list_head buffers; /* goes through sysfs_buffer.list */
55443 };
55444@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55445 if (!sysfs_get_active(attr_sd))
55446 return -ENODEV;
55447
55448- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55449+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55450 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55451
55452 sysfs_put_active(attr_sd);
55453@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55454 return -ENOMEM;
55455
55456 atomic_set(&new_od->refcnt, 0);
55457- atomic_set(&new_od->event, 1);
55458+ atomic_set_unchecked(&new_od->event, 1);
55459 init_waitqueue_head(&new_od->poll);
55460 INIT_LIST_HEAD(&new_od->buffers);
55461 goto retry;
55462@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55463
55464 sysfs_put_active(attr_sd);
55465
55466- if (buffer->event != atomic_read(&od->event))
55467+ if (buffer->event != atomic_read_unchecked(&od->event))
55468 goto trigger;
55469
55470 return DEFAULT_POLLMASK;
55471@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55472
55473 od = sd->s_attr.open;
55474 if (od) {
55475- atomic_inc(&od->event);
55476+ atomic_inc_unchecked(&od->event);
55477 wake_up_interruptible(&od->poll);
55478 }
55479
55480diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55481index 3c9eb56..9dea5be 100644
55482--- a/fs/sysfs/symlink.c
55483+++ b/fs/sysfs/symlink.c
55484@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55485
55486 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55487 {
55488- char *page = nd_get_link(nd);
55489+ const char *page = nd_get_link(nd);
55490 if (!IS_ERR(page))
55491 free_page((unsigned long)page);
55492 }
55493diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55494index c175b4d..8f36a16 100644
55495--- a/fs/udf/misc.c
55496+++ b/fs/udf/misc.c
55497@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55498
55499 u8 udf_tag_checksum(const struct tag *t)
55500 {
55501- u8 *data = (u8 *)t;
55502+ const u8 *data = (const u8 *)t;
55503 u8 checksum = 0;
55504 int i;
55505 for (i = 0; i < sizeof(struct tag); ++i)
55506diff --git a/fs/utimes.c b/fs/utimes.c
55507index f4fb7ec..3fe03c0 100644
55508--- a/fs/utimes.c
55509+++ b/fs/utimes.c
55510@@ -1,6 +1,7 @@
55511 #include <linux/compiler.h>
55512 #include <linux/file.h>
55513 #include <linux/fs.h>
55514+#include <linux/security.h>
55515 #include <linux/linkage.h>
55516 #include <linux/mount.h>
55517 #include <linux/namei.h>
55518@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55519 goto mnt_drop_write_and_out;
55520 }
55521 }
55522+
55523+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55524+ error = -EACCES;
55525+ goto mnt_drop_write_and_out;
55526+ }
55527+
55528 mutex_lock(&inode->i_mutex);
55529 error = notify_change(path->dentry, &newattrs);
55530 mutex_unlock(&inode->i_mutex);
55531diff --git a/fs/xattr.c b/fs/xattr.c
55532index 3377dff..4feded6 100644
55533--- a/fs/xattr.c
55534+++ b/fs/xattr.c
55535@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55536 * Extended attribute SET operations
55537 */
55538 static long
55539-setxattr(struct dentry *d, const char __user *name, const void __user *value,
55540+setxattr(struct path *path, const char __user *name, const void __user *value,
55541 size_t size, int flags)
55542 {
55543 int error;
55544@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55545 posix_acl_fix_xattr_from_user(kvalue, size);
55546 }
55547
55548- error = vfs_setxattr(d, kname, kvalue, size, flags);
55549+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
55550+ error = -EACCES;
55551+ goto out;
55552+ }
55553+
55554+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
55555 out:
55556 if (vvalue)
55557 vfree(vvalue);
55558@@ -377,7 +382,7 @@ retry:
55559 return error;
55560 error = mnt_want_write(path.mnt);
55561 if (!error) {
55562- error = setxattr(path.dentry, name, value, size, flags);
55563+ error = setxattr(&path, name, value, size, flags);
55564 mnt_drop_write(path.mnt);
55565 }
55566 path_put(&path);
55567@@ -401,7 +406,7 @@ retry:
55568 return error;
55569 error = mnt_want_write(path.mnt);
55570 if (!error) {
55571- error = setxattr(path.dentry, name, value, size, flags);
55572+ error = setxattr(&path, name, value, size, flags);
55573 mnt_drop_write(path.mnt);
55574 }
55575 path_put(&path);
55576@@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
55577 const void __user *,value, size_t, size, int, flags)
55578 {
55579 struct fd f = fdget(fd);
55580- struct dentry *dentry;
55581 int error = -EBADF;
55582
55583 if (!f.file)
55584 return error;
55585- dentry = f.file->f_path.dentry;
55586- audit_inode(NULL, dentry, 0);
55587+ audit_inode(NULL, f.file->f_path.dentry, 0);
55588 error = mnt_want_write_file(f.file);
55589 if (!error) {
55590- error = setxattr(dentry, name, value, size, flags);
55591+ error = setxattr(&f.file->f_path, name, value, size, flags);
55592 mnt_drop_write_file(f.file);
55593 }
55594 fdput(f);
55595diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
55596index 9fbea87..6b19972 100644
55597--- a/fs/xattr_acl.c
55598+++ b/fs/xattr_acl.c
55599@@ -76,8 +76,8 @@ struct posix_acl *
55600 posix_acl_from_xattr(struct user_namespace *user_ns,
55601 const void *value, size_t size)
55602 {
55603- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
55604- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
55605+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
55606+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
55607 int count;
55608 struct posix_acl *acl;
55609 struct posix_acl_entry *acl_e;
55610diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
55611index 572a858..12a9b0d 100644
55612--- a/fs/xfs/xfs_bmap.c
55613+++ b/fs/xfs/xfs_bmap.c
55614@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
55615 int nmap,
55616 int ret_nmap);
55617 #else
55618-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
55619+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
55620 #endif /* DEBUG */
55621
55622 STATIC int
55623diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
55624index 1b9fc3e..e1bdde0 100644
55625--- a/fs/xfs/xfs_dir2_sf.c
55626+++ b/fs/xfs/xfs_dir2_sf.c
55627@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
55628 }
55629
55630 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
55631- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55632+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
55633+ char name[sfep->namelen];
55634+ memcpy(name, sfep->name, sfep->namelen);
55635+ if (filldir(dirent, name, sfep->namelen,
55636+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
55637+ *offset = off & 0x7fffffff;
55638+ return 0;
55639+ }
55640+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55641 off & 0x7fffffff, ino, DT_UNKNOWN)) {
55642 *offset = off & 0x7fffffff;
55643 return 0;
55644diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
55645index c1c3ef8..0952438 100644
55646--- a/fs/xfs/xfs_ioctl.c
55647+++ b/fs/xfs/xfs_ioctl.c
55648@@ -127,7 +127,7 @@ xfs_find_handle(
55649 }
55650
55651 error = -EFAULT;
55652- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
55653+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
55654 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
55655 goto out_put;
55656
55657diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
55658index d82efaa..0904a8e 100644
55659--- a/fs/xfs/xfs_iops.c
55660+++ b/fs/xfs/xfs_iops.c
55661@@ -395,7 +395,7 @@ xfs_vn_put_link(
55662 struct nameidata *nd,
55663 void *p)
55664 {
55665- char *s = nd_get_link(nd);
55666+ const char *s = nd_get_link(nd);
55667
55668 if (!IS_ERR(s))
55669 kfree(s);
55670diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
55671new file mode 100644
55672index 0000000..92247e4
55673--- /dev/null
55674+++ b/grsecurity/Kconfig
55675@@ -0,0 +1,1021 @@
55676+#
55677+# grecurity configuration
55678+#
55679+menu "Memory Protections"
55680+depends on GRKERNSEC
55681+
55682+config GRKERNSEC_KMEM
55683+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
55684+ default y if GRKERNSEC_CONFIG_AUTO
55685+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
55686+ help
55687+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
55688+ be written to or read from to modify or leak the contents of the running
55689+ kernel. /dev/port will also not be allowed to be opened and support
55690+ for /dev/cpu/*/msr will be removed. If you have module
55691+ support disabled, enabling this will close up five ways that are
55692+ currently used to insert malicious code into the running kernel.
55693+
55694+ Even with all these features enabled, we still highly recommend that
55695+ you use the RBAC system, as it is still possible for an attacker to
55696+ modify the running kernel through privileged I/O granted by ioperm/iopl.
55697+
55698+ If you are not using XFree86, you may be able to stop this additional
55699+ case by enabling the 'Disable privileged I/O' option. Though nothing
55700+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
55701+ but only to video memory, which is the only writing we allow in this
55702+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
55703+ not be allowed to mprotect it with PROT_WRITE later.
55704+ Enabling this feature will prevent the "cpupower" and "powertop" tools
55705+ from working.
55706+
55707+ It is highly recommended that you say Y here if you meet all the
55708+ conditions above.
55709+
55710+config GRKERNSEC_VM86
55711+ bool "Restrict VM86 mode"
55712+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55713+ depends on X86_32
55714+
55715+ help
55716+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
55717+ make use of a special execution mode on 32bit x86 processors called
55718+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
55719+ video cards and will still work with this option enabled. The purpose
55720+ of the option is to prevent exploitation of emulation errors in
55721+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
55722+ Nearly all users should be able to enable this option.
55723+
55724+config GRKERNSEC_IO
55725+ bool "Disable privileged I/O"
55726+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55727+ depends on X86
55728+ select RTC_CLASS
55729+ select RTC_INTF_DEV
55730+ select RTC_DRV_CMOS
55731+
55732+ help
55733+ If you say Y here, all ioperm and iopl calls will return an error.
55734+ Ioperm and iopl can be used to modify the running kernel.
55735+ Unfortunately, some programs need this access to operate properly,
55736+ the most notable of which are XFree86 and hwclock. hwclock can be
55737+ remedied by having RTC support in the kernel, so real-time
55738+ clock support is enabled if this option is enabled, to ensure
55739+ that hwclock operates correctly. XFree86 still will not
55740+ operate correctly with this option enabled, so DO NOT CHOOSE Y
55741+ IF YOU USE XFree86. If you use XFree86 and you still want to
55742+ protect your kernel against modification, use the RBAC system.
55743+
55744+config GRKERNSEC_JIT_HARDEN
55745+ bool "Harden BPF JIT against spray attacks"
55746+ default y if GRKERNSEC_CONFIG_AUTO
55747+ depends on BPF_JIT
55748+ help
55749+ If you say Y here, the native code generated by the kernel's Berkeley
55750+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
55751+ attacks that attempt to fit attacker-beneficial instructions in
55752+ 32bit immediate fields of JIT-generated native instructions. The
55753+ attacker will generally aim to cause an unintended instruction sequence
55754+ of JIT-generated native code to execute by jumping into the middle of
55755+ a generated instruction. This feature effectively randomizes the 32bit
55756+ immediate constants present in the generated code to thwart such attacks.
55757+
55758+ If you're using KERNEXEC, it's recommended that you enable this option
55759+ to supplement the hardening of the kernel.
55760+
55761+config GRKERNSEC_RAND_THREADSTACK
55762+ bool "Insert random gaps between thread stacks"
55763+ default y if GRKERNSEC_CONFIG_AUTO
55764+ depends on PAX_RANDMMAP && !PPC
55765+ help
55766+ If you say Y here, a random-sized gap will be enforced between allocated
55767+ thread stacks. Glibc's NPTL and other threading libraries that
55768+ pass MAP_STACK to the kernel for thread stack allocation are supported.
55769+ The implementation currently provides 8 bits of entropy for the gap.
55770+
55771+ Many distributions do not compile threaded remote services with the
55772+ -fstack-check argument to GCC, causing the variable-sized stack-based
55773+ allocator, alloca(), to not probe the stack on allocation. This
55774+ permits an unbounded alloca() to skip over any guard page and potentially
55775+ modify another thread's stack reliably. An enforced random gap
55776+ reduces the reliability of such an attack and increases the chance
55777+ that such a read/write to another thread's stack instead lands in
55778+ an unmapped area, causing a crash and triggering grsecurity's
55779+ anti-bruteforcing logic.
55780+
55781+config GRKERNSEC_PROC_MEMMAP
55782+ bool "Harden ASLR against information leaks and entropy reduction"
55783+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
55784+ depends on PAX_NOEXEC || PAX_ASLR
55785+ help
55786+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
55787+ give no information about the addresses of its mappings if
55788+ PaX features that rely on random addresses are enabled on the task.
55789+ In addition to sanitizing this information and disabling other
55790+ dangerous sources of information, this option causes reads of sensitive
55791+ /proc/<pid> entries where the file descriptor was opened in a different
55792+ task than the one performing the read. Such attempts are logged.
55793+ This option also limits argv/env strings for suid/sgid binaries
55794+ to 512KB to prevent a complete exhaustion of the stack entropy provided
55795+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
55796+ binaries to prevent alternative mmap layouts from being abused.
55797+
55798+ If you use PaX it is essential that you say Y here as it closes up
55799+ several holes that make full ASLR useless locally.
55800+
55801+config GRKERNSEC_BRUTE
55802+ bool "Deter exploit bruteforcing"
55803+ default y if GRKERNSEC_CONFIG_AUTO
55804+ help
55805+ If you say Y here, attempts to bruteforce exploits against forking
55806+ daemons such as apache or sshd, as well as against suid/sgid binaries
55807+ will be deterred. When a child of a forking daemon is killed by PaX
55808+ or crashes due to an illegal instruction or other suspicious signal,
55809+ the parent process will be delayed 30 seconds upon every subsequent
55810+ fork until the administrator is able to assess the situation and
55811+ restart the daemon.
55812+ In the suid/sgid case, the attempt is logged, the user has all their
55813+ processes terminated, and they are prevented from executing any further
55814+ processes for 15 minutes.
55815+ It is recommended that you also enable signal logging in the auditing
55816+ section so that logs are generated when a process triggers a suspicious
55817+ signal.
55818+ If the sysctl option is enabled, a sysctl option with name
55819+ "deter_bruteforce" is created.
55820+
55821+
55822+config GRKERNSEC_MODHARDEN
55823+ bool "Harden module auto-loading"
55824+ default y if GRKERNSEC_CONFIG_AUTO
55825+ depends on MODULES
55826+ help
55827+ If you say Y here, module auto-loading in response to use of some
55828+ feature implemented by an unloaded module will be restricted to
55829+ root users. Enabling this option helps defend against attacks
55830+ by unprivileged users who abuse the auto-loading behavior to
55831+ cause a vulnerable module to load that is then exploited.
55832+
55833+ If this option prevents a legitimate use of auto-loading for a
55834+ non-root user, the administrator can execute modprobe manually
55835+ with the exact name of the module mentioned in the alert log.
55836+ Alternatively, the administrator can add the module to the list
55837+ of modules loaded at boot by modifying init scripts.
55838+
55839+ Modification of init scripts will most likely be needed on
55840+ Ubuntu servers with encrypted home directory support enabled,
55841+ as the first non-root user logging in will cause the ecb(aes),
55842+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55843+
55844+config GRKERNSEC_HIDESYM
55845+ bool "Hide kernel symbols"
55846+ default y if GRKERNSEC_CONFIG_AUTO
55847+ select PAX_USERCOPY_SLABS
55848+ help
55849+ If you say Y here, getting information on loaded modules, and
55850+ displaying all kernel symbols through a syscall will be restricted
55851+ to users with CAP_SYS_MODULE. For software compatibility reasons,
55852+ /proc/kallsyms will be restricted to the root user. The RBAC
55853+ system can hide that entry even from root.
55854+
55855+ This option also prevents leaking of kernel addresses through
55856+ several /proc entries.
55857+
55858+ Note that this option is only effective provided the following
55859+ conditions are met:
55860+ 1) The kernel using grsecurity is not precompiled by some distribution
55861+ 2) You have also enabled GRKERNSEC_DMESG
55862+ 3) You are using the RBAC system and hiding other files such as your
55863+ kernel image and System.map. Alternatively, enabling this option
55864+ causes the permissions on /boot, /lib/modules, and the kernel
55865+ source directory to change at compile time to prevent
55866+ reading by non-root users.
55867+ If the above conditions are met, this option will aid in providing a
55868+ useful protection against local kernel exploitation of overflows
55869+ and arbitrary read/write vulnerabilities.
55870+
55871+config GRKERNSEC_KERN_LOCKOUT
55872+ bool "Active kernel exploit response"
55873+ default y if GRKERNSEC_CONFIG_AUTO
55874+ depends on X86 || ARM || PPC || SPARC
55875+ help
55876+ If you say Y here, when a PaX alert is triggered due to suspicious
55877+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55878+ or an OOPS occurs due to bad memory accesses, instead of just
55879+ terminating the offending process (and potentially allowing
55880+ a subsequent exploit from the same user), we will take one of two
55881+ actions:
55882+ If the user was root, we will panic the system
55883+ If the user was non-root, we will log the attempt, terminate
55884+ all processes owned by the user, then prevent them from creating
55885+ any new processes until the system is restarted
55886+ This deters repeated kernel exploitation/bruteforcing attempts
55887+ and is useful for later forensics.
55888+
55889+endmenu
55890+menu "Role Based Access Control Options"
55891+depends on GRKERNSEC
55892+
55893+config GRKERNSEC_RBAC_DEBUG
55894+ bool
55895+
55896+config GRKERNSEC_NO_RBAC
55897+ bool "Disable RBAC system"
55898+ help
55899+ If you say Y here, the /dev/grsec device will be removed from the kernel,
55900+ preventing the RBAC system from being enabled. You should only say Y
55901+ here if you have no intention of using the RBAC system, so as to prevent
55902+ an attacker with root access from misusing the RBAC system to hide files
55903+ and processes when loadable module support and /dev/[k]mem have been
55904+ locked down.
55905+
55906+config GRKERNSEC_ACL_HIDEKERN
55907+ bool "Hide kernel processes"
55908+ help
55909+ If you say Y here, all kernel threads will be hidden to all
55910+ processes but those whose subject has the "view hidden processes"
55911+ flag.
55912+
55913+config GRKERNSEC_ACL_MAXTRIES
55914+ int "Maximum tries before password lockout"
55915+ default 3
55916+ help
55917+ This option enforces the maximum number of times a user can attempt
55918+ to authorize themselves with the grsecurity RBAC system before being
55919+ denied the ability to attempt authorization again for a specified time.
55920+ The lower the number, the harder it will be to brute-force a password.
55921+
55922+config GRKERNSEC_ACL_TIMEOUT
55923+ int "Time to wait after max password tries, in seconds"
55924+ default 30
55925+ help
55926+ This option specifies the time the user must wait after attempting to
55927+ authorize to the RBAC system with the maximum number of invalid
55928+ passwords. The higher the number, the harder it will be to brute-force
55929+ a password.
55930+
55931+endmenu
55932+menu "Filesystem Protections"
55933+depends on GRKERNSEC
55934+
55935+config GRKERNSEC_PROC
55936+ bool "Proc restrictions"
55937+ default y if GRKERNSEC_CONFIG_AUTO
55938+ help
55939+ If you say Y here, the permissions of the /proc filesystem
55940+ will be altered to enhance system security and privacy. You MUST
55941+ choose either a user only restriction or a user and group restriction.
55942+ Depending upon the option you choose, you can either restrict users to
55943+ see only the processes they themselves run, or choose a group that can
55944+ view all processes and files normally restricted to root if you choose
55945+ the "restrict to user only" option. NOTE: If you're running identd or
55946+ ntpd as a non-root user, you will have to run it as the group you
55947+ specify here.
55948+
55949+config GRKERNSEC_PROC_USER
55950+ bool "Restrict /proc to user only"
55951+ depends on GRKERNSEC_PROC
55952+ help
55953+ If you say Y here, non-root users will only be able to view their own
55954+ processes, and restricts them from viewing network-related information,
55955+ and viewing kernel symbol and module information.
55956+
55957+config GRKERNSEC_PROC_USERGROUP
55958+ bool "Allow special group"
55959+ default y if GRKERNSEC_CONFIG_AUTO
55960+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
55961+ help
55962+ If you say Y here, you will be able to select a group that will be
55963+ able to view all processes and network-related information. If you've
55964+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
55965+ remain hidden. This option is useful if you want to run identd as
55966+ a non-root user. The group you select may also be chosen at boot time
55967+ via "grsec_proc_gid=" on the kernel commandline.
55968+
55969+config GRKERNSEC_PROC_GID
55970+ int "GID for special group"
55971+ depends on GRKERNSEC_PROC_USERGROUP
55972+ default 1001
55973+
55974+config GRKERNSEC_PROC_ADD
55975+ bool "Additional restrictions"
55976+ default y if GRKERNSEC_CONFIG_AUTO
55977+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
55978+ help
55979+ If you say Y here, additional restrictions will be placed on
55980+ /proc that keep normal users from viewing device information and
55981+ slabinfo information that could be useful for exploits.
55982+
55983+config GRKERNSEC_LINK
55984+ bool "Linking restrictions"
55985+ default y if GRKERNSEC_CONFIG_AUTO
55986+ help
55987+ If you say Y here, /tmp race exploits will be prevented, since users
55988+ will no longer be able to follow symlinks owned by other users in
55989+ world-writable +t directories (e.g. /tmp), unless the owner of the
55990+ symlink is the owner of the directory. users will also not be
55991+ able to hardlink to files they do not own. If the sysctl option is
55992+ enabled, a sysctl option with name "linking_restrictions" is created.
55993+
55994+config GRKERNSEC_SYMLINKOWN
55995+ bool "Kernel-enforced SymlinksIfOwnerMatch"
55996+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
55997+ help
55998+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
55999+ that prevents it from being used as a security feature. As Apache
56000+ verifies the symlink by performing a stat() against the target of
56001+ the symlink before it is followed, an attacker can setup a symlink
56002+ to point to a same-owned file, then replace the symlink with one
56003+ that targets another user's file just after Apache "validates" the
56004+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
56005+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56006+ will be in place for the group you specify. If the sysctl option
56007+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
56008+ created.
56009+
56010+config GRKERNSEC_SYMLINKOWN_GID
56011+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56012+ depends on GRKERNSEC_SYMLINKOWN
56013+ default 1006
56014+ help
56015+ Setting this GID determines what group kernel-enforced
56016+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56017+ is enabled, a sysctl option with name "symlinkown_gid" is created.
56018+
56019+config GRKERNSEC_FIFO
56020+ bool "FIFO restrictions"
56021+ default y if GRKERNSEC_CONFIG_AUTO
56022+ help
56023+ If you say Y here, users will not be able to write to FIFOs they don't
56024+ own in world-writable +t directories (e.g. /tmp), unless the owner of
56025+ the FIFO is the same owner of the directory it's held in. If the sysctl
56026+ option is enabled, a sysctl option with name "fifo_restrictions" is
56027+ created.
56028+
56029+config GRKERNSEC_SYSFS_RESTRICT
56030+ bool "Sysfs/debugfs restriction"
56031+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56032+ depends on SYSFS
56033+ help
56034+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56035+ any filesystem normally mounted under it (e.g. debugfs) will be
56036+ mostly accessible only by root. These filesystems generally provide access
56037+ to hardware and debug information that isn't appropriate for unprivileged
56038+ users of the system. Sysfs and debugfs have also become a large source
56039+ of new vulnerabilities, ranging from infoleaks to local compromise.
56040+ There has been very little oversight with an eye toward security involved
56041+ in adding new exporters of information to these filesystems, so their
56042+ use is discouraged.
56043+ For reasons of compatibility, a few directories have been whitelisted
56044+ for access by non-root users:
56045+ /sys/fs/selinux
56046+ /sys/fs/fuse
56047+ /sys/devices/system/cpu
56048+
56049+config GRKERNSEC_ROFS
56050+ bool "Runtime read-only mount protection"
56051+ help
56052+ If you say Y here, a sysctl option with name "romount_protect" will
56053+ be created. By setting this option to 1 at runtime, filesystems
56054+ will be protected in the following ways:
56055+ * No new writable mounts will be allowed
56056+ * Existing read-only mounts won't be able to be remounted read/write
56057+ * Write operations will be denied on all block devices
56058+ This option acts independently of grsec_lock: once it is set to 1,
56059+ it cannot be turned off. Therefore, please be mindful of the resulting
56060+ behavior if this option is enabled in an init script on a read-only
56061+ filesystem. This feature is mainly intended for secure embedded systems.
56062+
56063+config GRKERNSEC_DEVICE_SIDECHANNEL
56064+ bool "Eliminate stat/notify-based device sidechannels"
56065+ default y if GRKERNSEC_CONFIG_AUTO
56066+ help
56067+ If you say Y here, timing analyses on block or character
56068+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56069+ will be thwarted for unprivileged users. If a process without
56070+ CAP_MKNOD stats such a device, the last access and last modify times
56071+ will match the device's create time. No access or modify events
56072+ will be triggered through inotify/dnotify/fanotify for such devices.
56073+ This feature will prevent attacks that may at a minimum
56074+ allow an attacker to determine the administrator's password length.
56075+
56076+config GRKERNSEC_CHROOT
56077+ bool "Chroot jail restrictions"
56078+ default y if GRKERNSEC_CONFIG_AUTO
56079+ help
56080+ If you say Y here, you will be able to choose several options that will
56081+ make breaking out of a chrooted jail much more difficult. If you
56082+ encounter no software incompatibilities with the following options, it
56083+ is recommended that you enable each one.
56084+
56085+config GRKERNSEC_CHROOT_MOUNT
56086+ bool "Deny mounts"
56087+ default y if GRKERNSEC_CONFIG_AUTO
56088+ depends on GRKERNSEC_CHROOT
56089+ help
56090+ If you say Y here, processes inside a chroot will not be able to
56091+ mount or remount filesystems. If the sysctl option is enabled, a
56092+ sysctl option with name "chroot_deny_mount" is created.
56093+
56094+config GRKERNSEC_CHROOT_DOUBLE
56095+ bool "Deny double-chroots"
56096+ default y if GRKERNSEC_CONFIG_AUTO
56097+ depends on GRKERNSEC_CHROOT
56098+ help
56099+ If you say Y here, processes inside a chroot will not be able to chroot
56100+ again outside the chroot. This is a widely used method of breaking
56101+ out of a chroot jail and should not be allowed. If the sysctl
56102+ option is enabled, a sysctl option with name
56103+ "chroot_deny_chroot" is created.
56104+
56105+config GRKERNSEC_CHROOT_PIVOT
56106+ bool "Deny pivot_root in chroot"
56107+ default y if GRKERNSEC_CONFIG_AUTO
56108+ depends on GRKERNSEC_CHROOT
56109+ help
56110+ If you say Y here, processes inside a chroot will not be able to use
56111+ a function called pivot_root() that was introduced in Linux 2.3.41. It
56112+ works similar to chroot in that it changes the root filesystem. This
56113+ function could be misused in a chrooted process to attempt to break out
56114+ of the chroot, and therefore should not be allowed. If the sysctl
56115+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
56116+ created.
56117+
56118+config GRKERNSEC_CHROOT_CHDIR
56119+ bool "Enforce chdir(\"/\") on all chroots"
56120+ default y if GRKERNSEC_CONFIG_AUTO
56121+ depends on GRKERNSEC_CHROOT
56122+ help
56123+ If you say Y here, the current working directory of all newly-chrooted
56124+ applications will be set to the the root directory of the chroot.
56125+ The man page on chroot(2) states:
56126+ Note that this call does not change the current working
56127+ directory, so that `.' can be outside the tree rooted at
56128+ `/'. In particular, the super-user can escape from a
56129+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56130+
56131+ It is recommended that you say Y here, since it's not known to break
56132+ any software. If the sysctl option is enabled, a sysctl option with
56133+ name "chroot_enforce_chdir" is created.
56134+
56135+config GRKERNSEC_CHROOT_CHMOD
56136+ bool "Deny (f)chmod +s"
56137+ default y if GRKERNSEC_CONFIG_AUTO
56138+ depends on GRKERNSEC_CHROOT
56139+ help
56140+ If you say Y here, processes inside a chroot will not be able to chmod
56141+ or fchmod files to make them have suid or sgid bits. This protects
56142+ against another published method of breaking a chroot. If the sysctl
56143+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
56144+ created.
56145+
56146+config GRKERNSEC_CHROOT_FCHDIR
56147+ bool "Deny fchdir out of chroot"
56148+ default y if GRKERNSEC_CONFIG_AUTO
56149+ depends on GRKERNSEC_CHROOT
56150+ help
56151+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
56152+ to a file descriptor of the chrooting process that points to a directory
56153+ outside the filesystem will be stopped. If the sysctl option
56154+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56155+
56156+config GRKERNSEC_CHROOT_MKNOD
56157+ bool "Deny mknod"
56158+ default y if GRKERNSEC_CONFIG_AUTO
56159+ depends on GRKERNSEC_CHROOT
56160+ help
56161+ If you say Y here, processes inside a chroot will not be allowed to
56162+ mknod. The problem with using mknod inside a chroot is that it
56163+ would allow an attacker to create a device entry that is the same
56164+ as one on the physical root of your system, which could range from
56165+ anything from the console device to a device for your harddrive (which
56166+ they could then use to wipe the drive or steal data). It is recommended
56167+ that you say Y here, unless you run into software incompatibilities.
56168+ If the sysctl option is enabled, a sysctl option with name
56169+ "chroot_deny_mknod" is created.
56170+
56171+config GRKERNSEC_CHROOT_SHMAT
56172+ bool "Deny shmat() out of chroot"
56173+ default y if GRKERNSEC_CONFIG_AUTO
56174+ depends on GRKERNSEC_CHROOT
56175+ help
56176+ If you say Y here, processes inside a chroot will not be able to attach
56177+ to shared memory segments that were created outside of the chroot jail.
56178+ It is recommended that you say Y here. If the sysctl option is enabled,
56179+ a sysctl option with name "chroot_deny_shmat" is created.
56180+
56181+config GRKERNSEC_CHROOT_UNIX
56182+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
56183+ default y if GRKERNSEC_CONFIG_AUTO
56184+ depends on GRKERNSEC_CHROOT
56185+ help
56186+ If you say Y here, processes inside a chroot will not be able to
56187+ connect to abstract (meaning not belonging to a filesystem) Unix
56188+ domain sockets that were bound outside of a chroot. It is recommended
56189+ that you say Y here. If the sysctl option is enabled, a sysctl option
56190+ with name "chroot_deny_unix" is created.
56191+
56192+config GRKERNSEC_CHROOT_FINDTASK
56193+ bool "Protect outside processes"
56194+ default y if GRKERNSEC_CONFIG_AUTO
56195+ depends on GRKERNSEC_CHROOT
56196+ help
56197+ If you say Y here, processes inside a chroot will not be able to
56198+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56199+ getsid, or view any process outside of the chroot. If the sysctl
56200+ option is enabled, a sysctl option with name "chroot_findtask" is
56201+ created.
56202+
56203+config GRKERNSEC_CHROOT_NICE
56204+ bool "Restrict priority changes"
56205+ default y if GRKERNSEC_CONFIG_AUTO
56206+ depends on GRKERNSEC_CHROOT
56207+ help
56208+ If you say Y here, processes inside a chroot will not be able to raise
56209+ the priority of processes in the chroot, or alter the priority of
56210+ processes outside the chroot. This provides more security than simply
56211+ removing CAP_SYS_NICE from the process' capability set. If the
56212+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56213+ is created.
56214+
56215+config GRKERNSEC_CHROOT_SYSCTL
56216+ bool "Deny sysctl writes"
56217+ default y if GRKERNSEC_CONFIG_AUTO
56218+ depends on GRKERNSEC_CHROOT
56219+ help
56220+ If you say Y here, an attacker in a chroot will not be able to
56221+ write to sysctl entries, either by sysctl(2) or through a /proc
56222+ interface. It is strongly recommended that you say Y here. If the
56223+ sysctl option is enabled, a sysctl option with name
56224+ "chroot_deny_sysctl" is created.
56225+
56226+config GRKERNSEC_CHROOT_CAPS
56227+ bool "Capability restrictions"
56228+ default y if GRKERNSEC_CONFIG_AUTO
56229+ depends on GRKERNSEC_CHROOT
56230+ help
56231+ If you say Y here, the capabilities on all processes within a
56232+ chroot jail will be lowered to stop module insertion, raw i/o,
56233+ system and net admin tasks, rebooting the system, modifying immutable
56234+ files, modifying IPC owned by another, and changing the system time.
56235+ This is left an option because it can break some apps. Disable this
56236+ if your chrooted apps are having problems performing those kinds of
56237+ tasks. If the sysctl option is enabled, a sysctl option with
56238+ name "chroot_caps" is created.
56239+
56240+endmenu
56241+menu "Kernel Auditing"
56242+depends on GRKERNSEC
56243+
56244+config GRKERNSEC_AUDIT_GROUP
56245+ bool "Single group for auditing"
56246+ help
56247+ If you say Y here, the exec and chdir logging features will only operate
56248+ on a group you specify. This option is recommended if you only want to
56249+ watch certain users instead of having a large amount of logs from the
56250+ entire system. If the sysctl option is enabled, a sysctl option with
56251+ name "audit_group" is created.
56252+
56253+config GRKERNSEC_AUDIT_GID
56254+ int "GID for auditing"
56255+ depends on GRKERNSEC_AUDIT_GROUP
56256+ default 1007
56257+
56258+config GRKERNSEC_EXECLOG
56259+ bool "Exec logging"
56260+ help
56261+ If you say Y here, all execve() calls will be logged (since the
56262+ other exec*() calls are frontends to execve(), all execution
56263+ will be logged). Useful for shell-servers that like to keep track
56264+ of their users. If the sysctl option is enabled, a sysctl option with
56265+ name "exec_logging" is created.
56266+ WARNING: This option when enabled will produce a LOT of logs, especially
56267+ on an active system.
56268+
56269+config GRKERNSEC_RESLOG
56270+ bool "Resource logging"
56271+ default y if GRKERNSEC_CONFIG_AUTO
56272+ help
56273+ If you say Y here, all attempts to overstep resource limits will
56274+ be logged with the resource name, the requested size, and the current
56275+ limit. It is highly recommended that you say Y here. If the sysctl
56276+ option is enabled, a sysctl option with name "resource_logging" is
56277+ created. If the RBAC system is enabled, the sysctl value is ignored.
56278+
56279+config GRKERNSEC_CHROOT_EXECLOG
56280+ bool "Log execs within chroot"
56281+ help
56282+ If you say Y here, all executions inside a chroot jail will be logged
56283+ to syslog. This can cause a large amount of logs if certain
56284+ applications (eg. djb's daemontools) are installed on the system, and
56285+ is therefore left as an option. If the sysctl option is enabled, a
56286+ sysctl option with name "chroot_execlog" is created.
56287+
56288+config GRKERNSEC_AUDIT_PTRACE
56289+ bool "Ptrace logging"
56290+ help
56291+ If you say Y here, all attempts to attach to a process via ptrace
56292+ will be logged. If the sysctl option is enabled, a sysctl option
56293+ with name "audit_ptrace" is created.
56294+
56295+config GRKERNSEC_AUDIT_CHDIR
56296+ bool "Chdir logging"
56297+ help
56298+ If you say Y here, all chdir() calls will be logged. If the sysctl
56299+ option is enabled, a sysctl option with name "audit_chdir" is created.
56300+
56301+config GRKERNSEC_AUDIT_MOUNT
56302+ bool "(Un)Mount logging"
56303+ help
56304+ If you say Y here, all mounts and unmounts will be logged. If the
56305+ sysctl option is enabled, a sysctl option with name "audit_mount" is
56306+ created.
56307+
56308+config GRKERNSEC_SIGNAL
56309+ bool "Signal logging"
56310+ default y if GRKERNSEC_CONFIG_AUTO
56311+ help
56312+ If you say Y here, certain important signals will be logged, such as
56313+ SIGSEGV, which will as a result inform you of when a error in a program
56314+ occurred, which in some cases could mean a possible exploit attempt.
56315+ If the sysctl option is enabled, a sysctl option with name
56316+ "signal_logging" is created.
56317+
56318+config GRKERNSEC_FORKFAIL
56319+ bool "Fork failure logging"
56320+ help
56321+ If you say Y here, all failed fork() attempts will be logged.
56322+ This could suggest a fork bomb, or someone attempting to overstep
56323+ their process limit. If the sysctl option is enabled, a sysctl option
56324+ with name "forkfail_logging" is created.
56325+
56326+config GRKERNSEC_TIME
56327+ bool "Time change logging"
56328+ default y if GRKERNSEC_CONFIG_AUTO
56329+ help
56330+ If you say Y here, any changes of the system clock will be logged.
56331+ If the sysctl option is enabled, a sysctl option with name
56332+ "timechange_logging" is created.
56333+
56334+config GRKERNSEC_PROC_IPADDR
56335+ bool "/proc/<pid>/ipaddr support"
56336+ default y if GRKERNSEC_CONFIG_AUTO
56337+ help
56338+ If you say Y here, a new entry will be added to each /proc/<pid>
56339+ directory that contains the IP address of the person using the task.
56340+ The IP is carried across local TCP and AF_UNIX stream sockets.
56341+ This information can be useful for IDS/IPSes to perform remote response
56342+ to a local attack. The entry is readable by only the owner of the
56343+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56344+ the RBAC system), and thus does not create privacy concerns.
56345+
56346+config GRKERNSEC_RWXMAP_LOG
56347+ bool 'Denied RWX mmap/mprotect logging'
56348+ default y if GRKERNSEC_CONFIG_AUTO
56349+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56350+ help
56351+ If you say Y here, calls to mmap() and mprotect() with explicit
56352+ usage of PROT_WRITE and PROT_EXEC together will be logged when
56353+ denied by the PAX_MPROTECT feature. If the sysctl option is
56354+ enabled, a sysctl option with name "rwxmap_logging" is created.
56355+
56356+config GRKERNSEC_AUDIT_TEXTREL
56357+ bool 'ELF text relocations logging (READ HELP)'
56358+ depends on PAX_MPROTECT
56359+ help
56360+ If you say Y here, text relocations will be logged with the filename
56361+ of the offending library or binary. The purpose of the feature is
56362+ to help Linux distribution developers get rid of libraries and
56363+ binaries that need text relocations which hinder the future progress
56364+ of PaX. Only Linux distribution developers should say Y here, and
56365+ never on a production machine, as this option creates an information
56366+ leak that could aid an attacker in defeating the randomization of
56367+ a single memory region. If the sysctl option is enabled, a sysctl
56368+ option with name "audit_textrel" is created.
56369+
56370+endmenu
56371+
56372+menu "Executable Protections"
56373+depends on GRKERNSEC
56374+
56375+config GRKERNSEC_DMESG
56376+ bool "Dmesg(8) restriction"
56377+ default y if GRKERNSEC_CONFIG_AUTO
56378+ help
56379+ If you say Y here, non-root users will not be able to use dmesg(8)
56380+ to view the contents of the kernel's circular log buffer.
56381+ The kernel's log buffer often contains kernel addresses and other
56382+ identifying information useful to an attacker in fingerprinting a
56383+ system for a targeted exploit.
56384+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
56385+ created.
56386+
56387+config GRKERNSEC_HARDEN_PTRACE
56388+ bool "Deter ptrace-based process snooping"
56389+ default y if GRKERNSEC_CONFIG_AUTO
56390+ help
56391+ If you say Y here, TTY sniffers and other malicious monitoring
56392+ programs implemented through ptrace will be defeated. If you
56393+ have been using the RBAC system, this option has already been
56394+ enabled for several years for all users, with the ability to make
56395+ fine-grained exceptions.
56396+
56397+ This option only affects the ability of non-root users to ptrace
56398+ processes that are not a descendent of the ptracing process.
56399+ This means that strace ./binary and gdb ./binary will still work,
56400+ but attaching to arbitrary processes will not. If the sysctl
56401+ option is enabled, a sysctl option with name "harden_ptrace" is
56402+ created.
56403+
56404+config GRKERNSEC_PTRACE_READEXEC
56405+ bool "Require read access to ptrace sensitive binaries"
56406+ default y if GRKERNSEC_CONFIG_AUTO
56407+ help
56408+ If you say Y here, unprivileged users will not be able to ptrace unreadable
56409+ binaries. This option is useful in environments that
56410+ remove the read bits (e.g. file mode 4711) from suid binaries to
56411+ prevent infoleaking of their contents. This option adds
56412+ consistency to the use of that file mode, as the binary could normally
56413+ be read out when run without privileges while ptracing.
56414+
56415+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56416+ is created.
56417+
56418+config GRKERNSEC_SETXID
56419+ bool "Enforce consistent multithreaded privileges"
56420+ default y if GRKERNSEC_CONFIG_AUTO
56421+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56422+ help
56423+ If you say Y here, a change from a root uid to a non-root uid
56424+ in a multithreaded application will cause the resulting uids,
56425+ gids, supplementary groups, and capabilities in that thread
56426+ to be propagated to the other threads of the process. In most
56427+ cases this is unnecessary, as glibc will emulate this behavior
56428+ on behalf of the application. Other libcs do not act in the
56429+ same way, allowing the other threads of the process to continue
56430+ running with root privileges. If the sysctl option is enabled,
56431+ a sysctl option with name "consistent_setxid" is created.
56432+
56433+config GRKERNSEC_TPE
56434+ bool "Trusted Path Execution (TPE)"
56435+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56436+ help
56437+ If you say Y here, you will be able to choose a gid to add to the
56438+ supplementary groups of users you want to mark as "untrusted."
56439+ These users will not be able to execute any files that are not in
56440+ root-owned directories writable only by root. If the sysctl option
56441+ is enabled, a sysctl option with name "tpe" is created.
56442+
56443+config GRKERNSEC_TPE_ALL
56444+ bool "Partially restrict all non-root users"
56445+ depends on GRKERNSEC_TPE
56446+ help
56447+ If you say Y here, all non-root users will be covered under
56448+ a weaker TPE restriction. This is separate from, and in addition to,
56449+ the main TPE options that you have selected elsewhere. Thus, if a
56450+ "trusted" GID is chosen, this restriction applies to even that GID.
56451+ Under this restriction, all non-root users will only be allowed to
56452+ execute files in directories they own that are not group or
56453+ world-writable, or in directories owned by root and writable only by
56454+ root. If the sysctl option is enabled, a sysctl option with name
56455+ "tpe_restrict_all" is created.
56456+
56457+config GRKERNSEC_TPE_INVERT
56458+ bool "Invert GID option"
56459+ depends on GRKERNSEC_TPE
56460+ help
56461+ If you say Y here, the group you specify in the TPE configuration will
56462+ decide what group TPE restrictions will be *disabled* for. This
56463+ option is useful if you want TPE restrictions to be applied to most
56464+ users on the system. If the sysctl option is enabled, a sysctl option
56465+ with name "tpe_invert" is created. Unlike other sysctl options, this
56466+ entry will default to on for backward-compatibility.
56467+
56468+config GRKERNSEC_TPE_GID
56469+ int
56470+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56471+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56472+
56473+config GRKERNSEC_TPE_UNTRUSTED_GID
56474+ int "GID for TPE-untrusted users"
56475+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56476+ default 1005
56477+ help
56478+ Setting this GID determines what group TPE restrictions will be
56479+ *enabled* for. If the sysctl option is enabled, a sysctl option
56480+ with name "tpe_gid" is created.
56481+
56482+config GRKERNSEC_TPE_TRUSTED_GID
56483+ int "GID for TPE-trusted users"
56484+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56485+ default 1005
56486+ help
56487+ Setting this GID determines what group TPE restrictions will be
56488+ *disabled* for. If the sysctl option is enabled, a sysctl option
56489+ with name "tpe_gid" is created.
56490+
56491+endmenu
56492+menu "Network Protections"
56493+depends on GRKERNSEC
56494+
56495+config GRKERNSEC_RANDNET
56496+ bool "Larger entropy pools"
56497+ default y if GRKERNSEC_CONFIG_AUTO
56498+ help
56499+ If you say Y here, the entropy pools used for many features of Linux
56500+ and grsecurity will be doubled in size. Since several grsecurity
56501+ features use additional randomness, it is recommended that you say Y
56502+ here. Saying Y here has a similar effect as modifying
56503+ /proc/sys/kernel/random/poolsize.
56504+
56505+config GRKERNSEC_BLACKHOLE
56506+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56507+ default y if GRKERNSEC_CONFIG_AUTO
56508+ depends on NET
56509+ help
56510+ If you say Y here, neither TCP resets nor ICMP
56511+ destination-unreachable packets will be sent in response to packets
56512+ sent to ports for which no associated listening process exists.
56513+ This feature supports both IPV4 and IPV6 and exempts the
56514+ loopback interface from blackholing. Enabling this feature
56515+ makes a host more resilient to DoS attacks and reduces network
56516+ visibility against scanners.
56517+
56518+ The blackhole feature as-implemented is equivalent to the FreeBSD
56519+ blackhole feature, as it prevents RST responses to all packets, not
56520+ just SYNs. Under most application behavior this causes no
56521+ problems, but applications (like haproxy) may not close certain
56522+ connections in a way that cleanly terminates them on the remote
56523+ end, leaving the remote host in LAST_ACK state. Because of this
56524+ side-effect and to prevent intentional LAST_ACK DoSes, this
56525+ feature also adds automatic mitigation against such attacks.
56526+ The mitigation drastically reduces the amount of time a socket
56527+ can spend in LAST_ACK state. If you're using haproxy and not
56528+ all servers it connects to have this option enabled, consider
56529+ disabling this feature on the haproxy host.
56530+
56531+ If the sysctl option is enabled, two sysctl options with names
56532+ "ip_blackhole" and "lastack_retries" will be created.
56533+ While "ip_blackhole" takes the standard zero/non-zero on/off
56534+ toggle, "lastack_retries" uses the same kinds of values as
56535+ "tcp_retries1" and "tcp_retries2". The default value of 4
56536+ prevents a socket from lasting more than 45 seconds in LAST_ACK
56537+ state.
56538+
56539+config GRKERNSEC_NO_SIMULT_CONNECT
56540+ bool "Disable TCP Simultaneous Connect"
56541+ default y if GRKERNSEC_CONFIG_AUTO
56542+ depends on NET
56543+ help
56544+ If you say Y here, a feature by Willy Tarreau will be enabled that
56545+ removes a weakness in Linux's strict implementation of TCP that
56546+ allows two clients to connect to each other without either entering
56547+ a listening state. The weakness allows an attacker to easily prevent
56548+ a client from connecting to a known server provided the source port
56549+ for the connection is guessed correctly.
56550+
56551+ As the weakness could be used to prevent an antivirus or IPS from
56552+ fetching updates, or prevent an SSL gateway from fetching a CRL,
56553+ it should be eliminated by enabling this option. Though Linux is
56554+ one of few operating systems supporting simultaneous connect, it
56555+ has no legitimate use in practice and is rarely supported by firewalls.
56556+
56557+config GRKERNSEC_SOCKET
56558+ bool "Socket restrictions"
56559+ depends on NET
56560+ help
56561+ If you say Y here, you will be able to choose from several options.
56562+ If you assign a GID on your system and add it to the supplementary
56563+ groups of users you want to restrict socket access to, this patch
56564+ will perform up to three things, based on the option(s) you choose.
56565+
56566+config GRKERNSEC_SOCKET_ALL
56567+ bool "Deny any sockets to group"
56568+ depends on GRKERNSEC_SOCKET
56569+ help
56570+ If you say Y here, you will be able to choose a GID of whose users will
56571+ be unable to connect to other hosts from your machine or run server
56572+ applications from your machine. If the sysctl option is enabled, a
56573+ sysctl option with name "socket_all" is created.
56574+
56575+config GRKERNSEC_SOCKET_ALL_GID
56576+ int "GID to deny all sockets for"
56577+ depends on GRKERNSEC_SOCKET_ALL
56578+ default 1004
56579+ help
56580+ Here you can choose the GID to disable socket access for. Remember to
56581+ add the users you want socket access disabled for to the GID
56582+ specified here. If the sysctl option is enabled, a sysctl option
56583+ with name "socket_all_gid" is created.
56584+
56585+config GRKERNSEC_SOCKET_CLIENT
56586+ bool "Deny client sockets to group"
56587+ depends on GRKERNSEC_SOCKET
56588+ help
56589+ If you say Y here, you will be able to choose a GID of whose users will
56590+ be unable to connect to other hosts from your machine, but will be
56591+ able to run servers. If this option is enabled, all users in the group
56592+ you specify will have to use passive mode when initiating ftp transfers
56593+ from the shell on your machine. If the sysctl option is enabled, a
56594+ sysctl option with name "socket_client" is created.
56595+
56596+config GRKERNSEC_SOCKET_CLIENT_GID
56597+ int "GID to deny client sockets for"
56598+ depends on GRKERNSEC_SOCKET_CLIENT
56599+ default 1003
56600+ help
56601+ Here you can choose the GID to disable client socket access for.
56602+ Remember to add the users you want client socket access disabled for to
56603+ the GID specified here. If the sysctl option is enabled, a sysctl
56604+ option with name "socket_client_gid" is created.
56605+
56606+config GRKERNSEC_SOCKET_SERVER
56607+ bool "Deny server sockets to group"
56608+ depends on GRKERNSEC_SOCKET
56609+ help
56610+ If you say Y here, you will be able to choose a GID of whose users will
56611+ be unable to run server applications from your machine. If the sysctl
56612+ option is enabled, a sysctl option with name "socket_server" is created.
56613+
56614+config GRKERNSEC_SOCKET_SERVER_GID
56615+ int "GID to deny server sockets for"
56616+ depends on GRKERNSEC_SOCKET_SERVER
56617+ default 1002
56618+ help
56619+ Here you can choose the GID to disable server socket access for.
56620+ Remember to add the users you want server socket access disabled for to
56621+ the GID specified here. If the sysctl option is enabled, a sysctl
56622+ option with name "socket_server_gid" is created.
56623+
56624+endmenu
56625+menu "Sysctl Support"
56626+depends on GRKERNSEC && SYSCTL
56627+
56628+config GRKERNSEC_SYSCTL
56629+ bool "Sysctl support"
56630+ default y if GRKERNSEC_CONFIG_AUTO
56631+ help
56632+ If you say Y here, you will be able to change the options that
56633+ grsecurity runs with at bootup, without having to recompile your
56634+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56635+ to enable (1) or disable (0) various features. All the sysctl entries
56636+ are mutable until the "grsec_lock" entry is set to a non-zero value.
56637+ All features enabled in the kernel configuration are disabled at boot
56638+ if you do not say Y to the "Turn on features by default" option.
56639+ All options should be set at startup, and the grsec_lock entry should
56640+ be set to a non-zero value after all the options are set.
56641+ *THIS IS EXTREMELY IMPORTANT*
56642+
56643+config GRKERNSEC_SYSCTL_DISTRO
56644+ bool "Extra sysctl support for distro makers (READ HELP)"
56645+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56646+ help
56647+ If you say Y here, additional sysctl options will be created
56648+ for features that affect processes running as root. Therefore,
56649+ it is critical when using this option that the grsec_lock entry be
56650+ enabled after boot. Only distros with prebuilt kernel packages
56651+ with this option enabled that can ensure grsec_lock is enabled
56652+ after boot should use this option.
56653+ *Failure to set grsec_lock after boot makes all grsec features
56654+ this option covers useless*
56655+
56656+ Currently this option creates the following sysctl entries:
56657+ "Disable Privileged I/O": "disable_priv_io"
56658+
56659+config GRKERNSEC_SYSCTL_ON
56660+ bool "Turn on features by default"
56661+ default y if GRKERNSEC_CONFIG_AUTO
56662+ depends on GRKERNSEC_SYSCTL
56663+ help
56664+ If you say Y here, instead of having all features enabled in the
56665+ kernel configuration disabled at boot time, the features will be
56666+ enabled at boot time. It is recommended you say Y here unless
56667+ there is some reason you would want all sysctl-tunable features to
56668+ be disabled by default. As mentioned elsewhere, it is important
56669+ to enable the grsec_lock entry once you have finished modifying
56670+ the sysctl entries.
56671+
56672+endmenu
56673+menu "Logging Options"
56674+depends on GRKERNSEC
56675+
56676+config GRKERNSEC_FLOODTIME
56677+ int "Seconds in between log messages (minimum)"
56678+ default 10
56679+ help
56680+ This option allows you to enforce the number of seconds between
56681+ grsecurity log messages. The default should be suitable for most
56682+ people, however, if you choose to change it, choose a value small enough
56683+ to allow informative logs to be produced, but large enough to
56684+ prevent flooding.
56685+
56686+config GRKERNSEC_FLOODBURST
56687+ int "Number of messages in a burst (maximum)"
56688+ default 6
56689+ help
56690+ This option allows you to choose the maximum number of messages allowed
56691+ within the flood time interval you chose in a separate option. The
56692+ default should be suitable for most people, however if you find that
56693+ many of your logs are being interpreted as flooding, you may want to
56694+ raise this value.
56695+
56696+endmenu
56697diff --git a/grsecurity/Makefile b/grsecurity/Makefile
56698new file mode 100644
56699index 0000000..1b9afa9
56700--- /dev/null
56701+++ b/grsecurity/Makefile
56702@@ -0,0 +1,38 @@
56703+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
56704+# during 2001-2009 it has been completely redesigned by Brad Spengler
56705+# into an RBAC system
56706+#
56707+# All code in this directory and various hooks inserted throughout the kernel
56708+# are copyright Brad Spengler - Open Source Security, Inc., and released
56709+# under the GPL v2 or higher
56710+
56711+KBUILD_CFLAGS += -Werror
56712+
56713+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
56714+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
56715+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
56716+
56717+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
56718+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
56719+ gracl_learn.o grsec_log.o
56720+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
56721+
56722+ifdef CONFIG_NET
56723+obj-y += grsec_sock.o
56724+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
56725+endif
56726+
56727+ifndef CONFIG_GRKERNSEC
56728+obj-y += grsec_disabled.o
56729+endif
56730+
56731+ifdef CONFIG_GRKERNSEC_HIDESYM
56732+extra-y := grsec_hidesym.o
56733+$(obj)/grsec_hidesym.o:
56734+ @-chmod -f 500 /boot
56735+ @-chmod -f 500 /lib/modules
56736+ @-chmod -f 500 /lib64/modules
56737+ @-chmod -f 500 /lib32/modules
56738+ @-chmod -f 700 .
56739+ @echo ' grsec: protected kernel image paths'
56740+endif
56741diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
56742new file mode 100644
56743index 0000000..0767b2e
56744--- /dev/null
56745+++ b/grsecurity/gracl.c
56746@@ -0,0 +1,4067 @@
56747+#include <linux/kernel.h>
56748+#include <linux/module.h>
56749+#include <linux/sched.h>
56750+#include <linux/mm.h>
56751+#include <linux/file.h>
56752+#include <linux/fs.h>
56753+#include <linux/namei.h>
56754+#include <linux/mount.h>
56755+#include <linux/tty.h>
56756+#include <linux/proc_fs.h>
56757+#include <linux/lglock.h>
56758+#include <linux/slab.h>
56759+#include <linux/vmalloc.h>
56760+#include <linux/types.h>
56761+#include <linux/sysctl.h>
56762+#include <linux/netdevice.h>
56763+#include <linux/ptrace.h>
56764+#include <linux/gracl.h>
56765+#include <linux/gralloc.h>
56766+#include <linux/security.h>
56767+#include <linux/grinternal.h>
56768+#include <linux/pid_namespace.h>
56769+#include <linux/stop_machine.h>
56770+#include <linux/fdtable.h>
56771+#include <linux/percpu.h>
56772+#include <linux/lglock.h>
56773+#include <linux/hugetlb.h>
56774+#include "../fs/mount.h"
56775+
56776+#include <asm/uaccess.h>
56777+#include <asm/errno.h>
56778+#include <asm/mman.h>
56779+
56780+extern struct lglock vfsmount_lock;
56781+
56782+static struct acl_role_db acl_role_set;
56783+static struct name_db name_set;
56784+static struct inodev_db inodev_set;
56785+
56786+/* for keeping track of userspace pointers used for subjects, so we
56787+ can share references in the kernel as well
56788+*/
56789+
56790+static struct path real_root;
56791+
56792+static struct acl_subj_map_db subj_map_set;
56793+
56794+static struct acl_role_label *default_role;
56795+
56796+static struct acl_role_label *role_list;
56797+
56798+static u16 acl_sp_role_value;
56799+
56800+extern char *gr_shared_page[4];
56801+static DEFINE_MUTEX(gr_dev_mutex);
56802+DEFINE_RWLOCK(gr_inode_lock);
56803+
56804+struct gr_arg *gr_usermode;
56805+
56806+static unsigned int gr_status __read_only = GR_STATUS_INIT;
56807+
56808+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
56809+extern void gr_clear_learn_entries(void);
56810+
56811+unsigned char *gr_system_salt;
56812+unsigned char *gr_system_sum;
56813+
56814+static struct sprole_pw **acl_special_roles = NULL;
56815+static __u16 num_sprole_pws = 0;
56816+
56817+static struct acl_role_label *kernel_role = NULL;
56818+
56819+static unsigned int gr_auth_attempts = 0;
56820+static unsigned long gr_auth_expires = 0UL;
56821+
56822+#ifdef CONFIG_NET
56823+extern struct vfsmount *sock_mnt;
56824+#endif
56825+
56826+extern struct vfsmount *pipe_mnt;
56827+extern struct vfsmount *shm_mnt;
56828+
56829+#ifdef CONFIG_HUGETLBFS
56830+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56831+#endif
56832+
56833+static struct acl_object_label *fakefs_obj_rw;
56834+static struct acl_object_label *fakefs_obj_rwx;
56835+
56836+extern int gr_init_uidset(void);
56837+extern void gr_free_uidset(void);
56838+extern void gr_remove_uid(uid_t uid);
56839+extern int gr_find_uid(uid_t uid);
56840+
56841+__inline__ int
56842+gr_acl_is_enabled(void)
56843+{
56844+ return (gr_status & GR_READY);
56845+}
56846+
56847+#ifdef CONFIG_BTRFS_FS
56848+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56849+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56850+#endif
56851+
56852+static inline dev_t __get_dev(const struct dentry *dentry)
56853+{
56854+#ifdef CONFIG_BTRFS_FS
56855+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56856+ return get_btrfs_dev_from_inode(dentry->d_inode);
56857+ else
56858+#endif
56859+ return dentry->d_inode->i_sb->s_dev;
56860+}
56861+
56862+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56863+{
56864+ return __get_dev(dentry);
56865+}
56866+
56867+static char gr_task_roletype_to_char(struct task_struct *task)
56868+{
56869+ switch (task->role->roletype &
56870+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
56871+ GR_ROLE_SPECIAL)) {
56872+ case GR_ROLE_DEFAULT:
56873+ return 'D';
56874+ case GR_ROLE_USER:
56875+ return 'U';
56876+ case GR_ROLE_GROUP:
56877+ return 'G';
56878+ case GR_ROLE_SPECIAL:
56879+ return 'S';
56880+ }
56881+
56882+ return 'X';
56883+}
56884+
56885+char gr_roletype_to_char(void)
56886+{
56887+ return gr_task_roletype_to_char(current);
56888+}
56889+
56890+__inline__ int
56891+gr_acl_tpe_check(void)
56892+{
56893+ if (unlikely(!(gr_status & GR_READY)))
56894+ return 0;
56895+ if (current->role->roletype & GR_ROLE_TPE)
56896+ return 1;
56897+ else
56898+ return 0;
56899+}
56900+
56901+int
56902+gr_handle_rawio(const struct inode *inode)
56903+{
56904+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56905+ if (inode && S_ISBLK(inode->i_mode) &&
56906+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56907+ !capable(CAP_SYS_RAWIO))
56908+ return 1;
56909+#endif
56910+ return 0;
56911+}
56912+
56913+static int
56914+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
56915+{
56916+ if (likely(lena != lenb))
56917+ return 0;
56918+
56919+ return !memcmp(a, b, lena);
56920+}
56921+
56922+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
56923+{
56924+ *buflen -= namelen;
56925+ if (*buflen < 0)
56926+ return -ENAMETOOLONG;
56927+ *buffer -= namelen;
56928+ memcpy(*buffer, str, namelen);
56929+ return 0;
56930+}
56931+
56932+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
56933+{
56934+ return prepend(buffer, buflen, name->name, name->len);
56935+}
56936+
56937+static int prepend_path(const struct path *path, struct path *root,
56938+ char **buffer, int *buflen)
56939+{
56940+ struct dentry *dentry = path->dentry;
56941+ struct vfsmount *vfsmnt = path->mnt;
56942+ struct mount *mnt = real_mount(vfsmnt);
56943+ bool slash = false;
56944+ int error = 0;
56945+
56946+ while (dentry != root->dentry || vfsmnt != root->mnt) {
56947+ struct dentry * parent;
56948+
56949+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
56950+ /* Global root? */
56951+ if (!mnt_has_parent(mnt)) {
56952+ goto out;
56953+ }
56954+ dentry = mnt->mnt_mountpoint;
56955+ mnt = mnt->mnt_parent;
56956+ vfsmnt = &mnt->mnt;
56957+ continue;
56958+ }
56959+ parent = dentry->d_parent;
56960+ prefetch(parent);
56961+ spin_lock(&dentry->d_lock);
56962+ error = prepend_name(buffer, buflen, &dentry->d_name);
56963+ spin_unlock(&dentry->d_lock);
56964+ if (!error)
56965+ error = prepend(buffer, buflen, "/", 1);
56966+ if (error)
56967+ break;
56968+
56969+ slash = true;
56970+ dentry = parent;
56971+ }
56972+
56973+out:
56974+ if (!error && !slash)
56975+ error = prepend(buffer, buflen, "/", 1);
56976+
56977+ return error;
56978+}
56979+
56980+/* this must be called with vfsmount_lock and rename_lock held */
56981+
56982+static char *__our_d_path(const struct path *path, struct path *root,
56983+ char *buf, int buflen)
56984+{
56985+ char *res = buf + buflen;
56986+ int error;
56987+
56988+ prepend(&res, &buflen, "\0", 1);
56989+ error = prepend_path(path, root, &res, &buflen);
56990+ if (error)
56991+ return ERR_PTR(error);
56992+
56993+ return res;
56994+}
56995+
56996+static char *
56997+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
56998+{
56999+ char *retval;
57000+
57001+ retval = __our_d_path(path, root, buf, buflen);
57002+ if (unlikely(IS_ERR(retval)))
57003+ retval = strcpy(buf, "<path too long>");
57004+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57005+ retval[1] = '\0';
57006+
57007+ return retval;
57008+}
57009+
57010+static char *
57011+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57012+ char *buf, int buflen)
57013+{
57014+ struct path path;
57015+ char *res;
57016+
57017+ path.dentry = (struct dentry *)dentry;
57018+ path.mnt = (struct vfsmount *)vfsmnt;
57019+
57020+ /* we can use real_root.dentry, real_root.mnt, because this is only called
57021+ by the RBAC system */
57022+ res = gen_full_path(&path, &real_root, buf, buflen);
57023+
57024+ return res;
57025+}
57026+
57027+static char *
57028+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57029+ char *buf, int buflen)
57030+{
57031+ char *res;
57032+ struct path path;
57033+ struct path root;
57034+ struct task_struct *reaper = init_pid_ns.child_reaper;
57035+
57036+ path.dentry = (struct dentry *)dentry;
57037+ path.mnt = (struct vfsmount *)vfsmnt;
57038+
57039+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57040+ get_fs_root(reaper->fs, &root);
57041+
57042+ write_seqlock(&rename_lock);
57043+ br_read_lock(&vfsmount_lock);
57044+ res = gen_full_path(&path, &root, buf, buflen);
57045+ br_read_unlock(&vfsmount_lock);
57046+ write_sequnlock(&rename_lock);
57047+
57048+ path_put(&root);
57049+ return res;
57050+}
57051+
57052+static char *
57053+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57054+{
57055+ char *ret;
57056+ write_seqlock(&rename_lock);
57057+ br_read_lock(&vfsmount_lock);
57058+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57059+ PAGE_SIZE);
57060+ br_read_unlock(&vfsmount_lock);
57061+ write_sequnlock(&rename_lock);
57062+ return ret;
57063+}
57064+
57065+static char *
57066+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57067+{
57068+ char *ret;
57069+ char *buf;
57070+ int buflen;
57071+
57072+ write_seqlock(&rename_lock);
57073+ br_read_lock(&vfsmount_lock);
57074+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57075+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57076+ buflen = (int)(ret - buf);
57077+ if (buflen >= 5)
57078+ prepend(&ret, &buflen, "/proc", 5);
57079+ else
57080+ ret = strcpy(buf, "<path too long>");
57081+ br_read_unlock(&vfsmount_lock);
57082+ write_sequnlock(&rename_lock);
57083+ return ret;
57084+}
57085+
57086+char *
57087+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57088+{
57089+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57090+ PAGE_SIZE);
57091+}
57092+
57093+char *
57094+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57095+{
57096+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57097+ PAGE_SIZE);
57098+}
57099+
57100+char *
57101+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57102+{
57103+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57104+ PAGE_SIZE);
57105+}
57106+
57107+char *
57108+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57109+{
57110+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57111+ PAGE_SIZE);
57112+}
57113+
57114+char *
57115+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57116+{
57117+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57118+ PAGE_SIZE);
57119+}
57120+
57121+__inline__ __u32
57122+to_gr_audit(const __u32 reqmode)
57123+{
57124+ /* masks off auditable permission flags, then shifts them to create
57125+ auditing flags, and adds the special case of append auditing if
57126+ we're requesting write */
57127+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57128+}
57129+
57130+struct acl_subject_label *
57131+lookup_subject_map(const struct acl_subject_label *userp)
57132+{
57133+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
57134+ struct subject_map *match;
57135+
57136+ match = subj_map_set.s_hash[index];
57137+
57138+ while (match && match->user != userp)
57139+ match = match->next;
57140+
57141+ if (match != NULL)
57142+ return match->kernel;
57143+ else
57144+ return NULL;
57145+}
57146+
57147+static void
57148+insert_subj_map_entry(struct subject_map *subjmap)
57149+{
57150+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57151+ struct subject_map **curr;
57152+
57153+ subjmap->prev = NULL;
57154+
57155+ curr = &subj_map_set.s_hash[index];
57156+ if (*curr != NULL)
57157+ (*curr)->prev = subjmap;
57158+
57159+ subjmap->next = *curr;
57160+ *curr = subjmap;
57161+
57162+ return;
57163+}
57164+
57165+static struct acl_role_label *
57166+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57167+ const gid_t gid)
57168+{
57169+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57170+ struct acl_role_label *match;
57171+ struct role_allowed_ip *ipp;
57172+ unsigned int x;
57173+ u32 curr_ip = task->signal->curr_ip;
57174+
57175+ task->signal->saved_ip = curr_ip;
57176+
57177+ match = acl_role_set.r_hash[index];
57178+
57179+ while (match) {
57180+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57181+ for (x = 0; x < match->domain_child_num; x++) {
57182+ if (match->domain_children[x] == uid)
57183+ goto found;
57184+ }
57185+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57186+ break;
57187+ match = match->next;
57188+ }
57189+found:
57190+ if (match == NULL) {
57191+ try_group:
57192+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57193+ match = acl_role_set.r_hash[index];
57194+
57195+ while (match) {
57196+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57197+ for (x = 0; x < match->domain_child_num; x++) {
57198+ if (match->domain_children[x] == gid)
57199+ goto found2;
57200+ }
57201+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57202+ break;
57203+ match = match->next;
57204+ }
57205+found2:
57206+ if (match == NULL)
57207+ match = default_role;
57208+ if (match->allowed_ips == NULL)
57209+ return match;
57210+ else {
57211+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57212+ if (likely
57213+ ((ntohl(curr_ip) & ipp->netmask) ==
57214+ (ntohl(ipp->addr) & ipp->netmask)))
57215+ return match;
57216+ }
57217+ match = default_role;
57218+ }
57219+ } else if (match->allowed_ips == NULL) {
57220+ return match;
57221+ } else {
57222+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57223+ if (likely
57224+ ((ntohl(curr_ip) & ipp->netmask) ==
57225+ (ntohl(ipp->addr) & ipp->netmask)))
57226+ return match;
57227+ }
57228+ goto try_group;
57229+ }
57230+
57231+ return match;
57232+}
57233+
57234+struct acl_subject_label *
57235+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57236+ const struct acl_role_label *role)
57237+{
57238+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57239+ struct acl_subject_label *match;
57240+
57241+ match = role->subj_hash[index];
57242+
57243+ while (match && (match->inode != ino || match->device != dev ||
57244+ (match->mode & GR_DELETED))) {
57245+ match = match->next;
57246+ }
57247+
57248+ if (match && !(match->mode & GR_DELETED))
57249+ return match;
57250+ else
57251+ return NULL;
57252+}
57253+
57254+struct acl_subject_label *
57255+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57256+ const struct acl_role_label *role)
57257+{
57258+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57259+ struct acl_subject_label *match;
57260+
57261+ match = role->subj_hash[index];
57262+
57263+ while (match && (match->inode != ino || match->device != dev ||
57264+ !(match->mode & GR_DELETED))) {
57265+ match = match->next;
57266+ }
57267+
57268+ if (match && (match->mode & GR_DELETED))
57269+ return match;
57270+ else
57271+ return NULL;
57272+}
57273+
57274+static struct acl_object_label *
57275+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57276+ const struct acl_subject_label *subj)
57277+{
57278+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57279+ struct acl_object_label *match;
57280+
57281+ match = subj->obj_hash[index];
57282+
57283+ while (match && (match->inode != ino || match->device != dev ||
57284+ (match->mode & GR_DELETED))) {
57285+ match = match->next;
57286+ }
57287+
57288+ if (match && !(match->mode & GR_DELETED))
57289+ return match;
57290+ else
57291+ return NULL;
57292+}
57293+
57294+static struct acl_object_label *
57295+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57296+ const struct acl_subject_label *subj)
57297+{
57298+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57299+ struct acl_object_label *match;
57300+
57301+ match = subj->obj_hash[index];
57302+
57303+ while (match && (match->inode != ino || match->device != dev ||
57304+ !(match->mode & GR_DELETED))) {
57305+ match = match->next;
57306+ }
57307+
57308+ if (match && (match->mode & GR_DELETED))
57309+ return match;
57310+
57311+ match = subj->obj_hash[index];
57312+
57313+ while (match && (match->inode != ino || match->device != dev ||
57314+ (match->mode & GR_DELETED))) {
57315+ match = match->next;
57316+ }
57317+
57318+ if (match && !(match->mode & GR_DELETED))
57319+ return match;
57320+ else
57321+ return NULL;
57322+}
57323+
57324+static struct name_entry *
57325+lookup_name_entry(const char *name)
57326+{
57327+ unsigned int len = strlen(name);
57328+ unsigned int key = full_name_hash(name, len);
57329+ unsigned int index = key % name_set.n_size;
57330+ struct name_entry *match;
57331+
57332+ match = name_set.n_hash[index];
57333+
57334+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57335+ match = match->next;
57336+
57337+ return match;
57338+}
57339+
57340+static struct name_entry *
57341+lookup_name_entry_create(const char *name)
57342+{
57343+ unsigned int len = strlen(name);
57344+ unsigned int key = full_name_hash(name, len);
57345+ unsigned int index = key % name_set.n_size;
57346+ struct name_entry *match;
57347+
57348+ match = name_set.n_hash[index];
57349+
57350+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57351+ !match->deleted))
57352+ match = match->next;
57353+
57354+ if (match && match->deleted)
57355+ return match;
57356+
57357+ match = name_set.n_hash[index];
57358+
57359+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57360+ match->deleted))
57361+ match = match->next;
57362+
57363+ if (match && !match->deleted)
57364+ return match;
57365+ else
57366+ return NULL;
57367+}
57368+
57369+static struct inodev_entry *
57370+lookup_inodev_entry(const ino_t ino, const dev_t dev)
57371+{
57372+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57373+ struct inodev_entry *match;
57374+
57375+ match = inodev_set.i_hash[index];
57376+
57377+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57378+ match = match->next;
57379+
57380+ return match;
57381+}
57382+
57383+static void
57384+insert_inodev_entry(struct inodev_entry *entry)
57385+{
57386+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57387+ inodev_set.i_size);
57388+ struct inodev_entry **curr;
57389+
57390+ entry->prev = NULL;
57391+
57392+ curr = &inodev_set.i_hash[index];
57393+ if (*curr != NULL)
57394+ (*curr)->prev = entry;
57395+
57396+ entry->next = *curr;
57397+ *curr = entry;
57398+
57399+ return;
57400+}
57401+
57402+static void
57403+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57404+{
57405+ unsigned int index =
57406+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57407+ struct acl_role_label **curr;
57408+ struct acl_role_label *tmp, *tmp2;
57409+
57410+ curr = &acl_role_set.r_hash[index];
57411+
57412+ /* simple case, slot is empty, just set it to our role */
57413+ if (*curr == NULL) {
57414+ *curr = role;
57415+ } else {
57416+ /* example:
57417+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
57418+ 2 -> 3
57419+ */
57420+ /* first check to see if we can already be reached via this slot */
57421+ tmp = *curr;
57422+ while (tmp && tmp != role)
57423+ tmp = tmp->next;
57424+ if (tmp == role) {
57425+ /* we don't need to add ourselves to this slot's chain */
57426+ return;
57427+ }
57428+ /* we need to add ourselves to this chain, two cases */
57429+ if (role->next == NULL) {
57430+ /* simple case, append the current chain to our role */
57431+ role->next = *curr;
57432+ *curr = role;
57433+ } else {
57434+ /* 1 -> 2 -> 3 -> 4
57435+ 2 -> 3 -> 4
57436+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57437+ */
57438+ /* trickier case: walk our role's chain until we find
57439+ the role for the start of the current slot's chain */
57440+ tmp = role;
57441+ tmp2 = *curr;
57442+ while (tmp->next && tmp->next != tmp2)
57443+ tmp = tmp->next;
57444+ if (tmp->next == tmp2) {
57445+ /* from example above, we found 3, so just
57446+ replace this slot's chain with ours */
57447+ *curr = role;
57448+ } else {
57449+ /* we didn't find a subset of our role's chain
57450+ in the current slot's chain, so append their
57451+ chain to ours, and set us as the first role in
57452+ the slot's chain
57453+
57454+ we could fold this case with the case above,
57455+ but making it explicit for clarity
57456+ */
57457+ tmp->next = tmp2;
57458+ *curr = role;
57459+ }
57460+ }
57461+ }
57462+
57463+ return;
57464+}
57465+
57466+static void
57467+insert_acl_role_label(struct acl_role_label *role)
57468+{
57469+ int i;
57470+
57471+ if (role_list == NULL) {
57472+ role_list = role;
57473+ role->prev = NULL;
57474+ } else {
57475+ role->prev = role_list;
57476+ role_list = role;
57477+ }
57478+
57479+ /* used for hash chains */
57480+ role->next = NULL;
57481+
57482+ if (role->roletype & GR_ROLE_DOMAIN) {
57483+ for (i = 0; i < role->domain_child_num; i++)
57484+ __insert_acl_role_label(role, role->domain_children[i]);
57485+ } else
57486+ __insert_acl_role_label(role, role->uidgid);
57487+}
57488+
57489+static int
57490+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57491+{
57492+ struct name_entry **curr, *nentry;
57493+ struct inodev_entry *ientry;
57494+ unsigned int len = strlen(name);
57495+ unsigned int key = full_name_hash(name, len);
57496+ unsigned int index = key % name_set.n_size;
57497+
57498+ curr = &name_set.n_hash[index];
57499+
57500+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57501+ curr = &((*curr)->next);
57502+
57503+ if (*curr != NULL)
57504+ return 1;
57505+
57506+ nentry = acl_alloc(sizeof (struct name_entry));
57507+ if (nentry == NULL)
57508+ return 0;
57509+ ientry = acl_alloc(sizeof (struct inodev_entry));
57510+ if (ientry == NULL)
57511+ return 0;
57512+ ientry->nentry = nentry;
57513+
57514+ nentry->key = key;
57515+ nentry->name = name;
57516+ nentry->inode = inode;
57517+ nentry->device = device;
57518+ nentry->len = len;
57519+ nentry->deleted = deleted;
57520+
57521+ nentry->prev = NULL;
57522+ curr = &name_set.n_hash[index];
57523+ if (*curr != NULL)
57524+ (*curr)->prev = nentry;
57525+ nentry->next = *curr;
57526+ *curr = nentry;
57527+
57528+ /* insert us into the table searchable by inode/dev */
57529+ insert_inodev_entry(ientry);
57530+
57531+ return 1;
57532+}
57533+
57534+static void
57535+insert_acl_obj_label(struct acl_object_label *obj,
57536+ struct acl_subject_label *subj)
57537+{
57538+ unsigned int index =
57539+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57540+ struct acl_object_label **curr;
57541+
57542+
57543+ obj->prev = NULL;
57544+
57545+ curr = &subj->obj_hash[index];
57546+ if (*curr != NULL)
57547+ (*curr)->prev = obj;
57548+
57549+ obj->next = *curr;
57550+ *curr = obj;
57551+
57552+ return;
57553+}
57554+
57555+static void
57556+insert_acl_subj_label(struct acl_subject_label *obj,
57557+ struct acl_role_label *role)
57558+{
57559+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
57560+ struct acl_subject_label **curr;
57561+
57562+ obj->prev = NULL;
57563+
57564+ curr = &role->subj_hash[index];
57565+ if (*curr != NULL)
57566+ (*curr)->prev = obj;
57567+
57568+ obj->next = *curr;
57569+ *curr = obj;
57570+
57571+ return;
57572+}
57573+
57574+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
57575+
57576+static void *
57577+create_table(__u32 * len, int elementsize)
57578+{
57579+ unsigned int table_sizes[] = {
57580+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
57581+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
57582+ 4194301, 8388593, 16777213, 33554393, 67108859
57583+ };
57584+ void *newtable = NULL;
57585+ unsigned int pwr = 0;
57586+
57587+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
57588+ table_sizes[pwr] <= *len)
57589+ pwr++;
57590+
57591+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
57592+ return newtable;
57593+
57594+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
57595+ newtable =
57596+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
57597+ else
57598+ newtable = vmalloc(table_sizes[pwr] * elementsize);
57599+
57600+ *len = table_sizes[pwr];
57601+
57602+ return newtable;
57603+}
57604+
57605+static int
57606+init_variables(const struct gr_arg *arg)
57607+{
57608+ struct task_struct *reaper = init_pid_ns.child_reaper;
57609+ unsigned int stacksize;
57610+
57611+ subj_map_set.s_size = arg->role_db.num_subjects;
57612+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
57613+ name_set.n_size = arg->role_db.num_objects;
57614+ inodev_set.i_size = arg->role_db.num_objects;
57615+
57616+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
57617+ !name_set.n_size || !inodev_set.i_size)
57618+ return 1;
57619+
57620+ if (!gr_init_uidset())
57621+ return 1;
57622+
57623+ /* set up the stack that holds allocation info */
57624+
57625+ stacksize = arg->role_db.num_pointers + 5;
57626+
57627+ if (!acl_alloc_stack_init(stacksize))
57628+ return 1;
57629+
57630+ /* grab reference for the real root dentry and vfsmount */
57631+ get_fs_root(reaper->fs, &real_root);
57632+
57633+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57634+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
57635+#endif
57636+
57637+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
57638+ if (fakefs_obj_rw == NULL)
57639+ return 1;
57640+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
57641+
57642+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
57643+ if (fakefs_obj_rwx == NULL)
57644+ return 1;
57645+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
57646+
57647+ subj_map_set.s_hash =
57648+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
57649+ acl_role_set.r_hash =
57650+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
57651+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
57652+ inodev_set.i_hash =
57653+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
57654+
57655+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
57656+ !name_set.n_hash || !inodev_set.i_hash)
57657+ return 1;
57658+
57659+ memset(subj_map_set.s_hash, 0,
57660+ sizeof(struct subject_map *) * subj_map_set.s_size);
57661+ memset(acl_role_set.r_hash, 0,
57662+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
57663+ memset(name_set.n_hash, 0,
57664+ sizeof (struct name_entry *) * name_set.n_size);
57665+ memset(inodev_set.i_hash, 0,
57666+ sizeof (struct inodev_entry *) * inodev_set.i_size);
57667+
57668+ return 0;
57669+}
57670+
57671+/* free information not needed after startup
57672+ currently contains user->kernel pointer mappings for subjects
57673+*/
57674+
57675+static void
57676+free_init_variables(void)
57677+{
57678+ __u32 i;
57679+
57680+ if (subj_map_set.s_hash) {
57681+ for (i = 0; i < subj_map_set.s_size; i++) {
57682+ if (subj_map_set.s_hash[i]) {
57683+ kfree(subj_map_set.s_hash[i]);
57684+ subj_map_set.s_hash[i] = NULL;
57685+ }
57686+ }
57687+
57688+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
57689+ PAGE_SIZE)
57690+ kfree(subj_map_set.s_hash);
57691+ else
57692+ vfree(subj_map_set.s_hash);
57693+ }
57694+
57695+ return;
57696+}
57697+
57698+static void
57699+free_variables(void)
57700+{
57701+ struct acl_subject_label *s;
57702+ struct acl_role_label *r;
57703+ struct task_struct *task, *task2;
57704+ unsigned int x;
57705+
57706+ gr_clear_learn_entries();
57707+
57708+ read_lock(&tasklist_lock);
57709+ do_each_thread(task2, task) {
57710+ task->acl_sp_role = 0;
57711+ task->acl_role_id = 0;
57712+ task->acl = NULL;
57713+ task->role = NULL;
57714+ } while_each_thread(task2, task);
57715+ read_unlock(&tasklist_lock);
57716+
57717+ /* release the reference to the real root dentry and vfsmount */
57718+ path_put(&real_root);
57719+ memset(&real_root, 0, sizeof(real_root));
57720+
57721+ /* free all object hash tables */
57722+
57723+ FOR_EACH_ROLE_START(r)
57724+ if (r->subj_hash == NULL)
57725+ goto next_role;
57726+ FOR_EACH_SUBJECT_START(r, s, x)
57727+ if (s->obj_hash == NULL)
57728+ break;
57729+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57730+ kfree(s->obj_hash);
57731+ else
57732+ vfree(s->obj_hash);
57733+ FOR_EACH_SUBJECT_END(s, x)
57734+ FOR_EACH_NESTED_SUBJECT_START(r, s)
57735+ if (s->obj_hash == NULL)
57736+ break;
57737+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57738+ kfree(s->obj_hash);
57739+ else
57740+ vfree(s->obj_hash);
57741+ FOR_EACH_NESTED_SUBJECT_END(s)
57742+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
57743+ kfree(r->subj_hash);
57744+ else
57745+ vfree(r->subj_hash);
57746+ r->subj_hash = NULL;
57747+next_role:
57748+ FOR_EACH_ROLE_END(r)
57749+
57750+ acl_free_all();
57751+
57752+ if (acl_role_set.r_hash) {
57753+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
57754+ PAGE_SIZE)
57755+ kfree(acl_role_set.r_hash);
57756+ else
57757+ vfree(acl_role_set.r_hash);
57758+ }
57759+ if (name_set.n_hash) {
57760+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
57761+ PAGE_SIZE)
57762+ kfree(name_set.n_hash);
57763+ else
57764+ vfree(name_set.n_hash);
57765+ }
57766+
57767+ if (inodev_set.i_hash) {
57768+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
57769+ PAGE_SIZE)
57770+ kfree(inodev_set.i_hash);
57771+ else
57772+ vfree(inodev_set.i_hash);
57773+ }
57774+
57775+ gr_free_uidset();
57776+
57777+ memset(&name_set, 0, sizeof (struct name_db));
57778+ memset(&inodev_set, 0, sizeof (struct inodev_db));
57779+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
57780+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
57781+
57782+ default_role = NULL;
57783+ kernel_role = NULL;
57784+ role_list = NULL;
57785+
57786+ return;
57787+}
57788+
57789+static __u32
57790+count_user_objs(struct acl_object_label *userp)
57791+{
57792+ struct acl_object_label o_tmp;
57793+ __u32 num = 0;
57794+
57795+ while (userp) {
57796+ if (copy_from_user(&o_tmp, userp,
57797+ sizeof (struct acl_object_label)))
57798+ break;
57799+
57800+ userp = o_tmp.prev;
57801+ num++;
57802+ }
57803+
57804+ return num;
57805+}
57806+
57807+static struct acl_subject_label *
57808+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
57809+
57810+static int
57811+copy_user_glob(struct acl_object_label *obj)
57812+{
57813+ struct acl_object_label *g_tmp, **guser;
57814+ unsigned int len;
57815+ char *tmp;
57816+
57817+ if (obj->globbed == NULL)
57818+ return 0;
57819+
57820+ guser = &obj->globbed;
57821+ while (*guser) {
57822+ g_tmp = (struct acl_object_label *)
57823+ acl_alloc(sizeof (struct acl_object_label));
57824+ if (g_tmp == NULL)
57825+ return -ENOMEM;
57826+
57827+ if (copy_from_user(g_tmp, *guser,
57828+ sizeof (struct acl_object_label)))
57829+ return -EFAULT;
57830+
57831+ len = strnlen_user(g_tmp->filename, PATH_MAX);
57832+
57833+ if (!len || len >= PATH_MAX)
57834+ return -EINVAL;
57835+
57836+ if ((tmp = (char *) acl_alloc(len)) == NULL)
57837+ return -ENOMEM;
57838+
57839+ if (copy_from_user(tmp, g_tmp->filename, len))
57840+ return -EFAULT;
57841+ tmp[len-1] = '\0';
57842+ g_tmp->filename = tmp;
57843+
57844+ *guser = g_tmp;
57845+ guser = &(g_tmp->next);
57846+ }
57847+
57848+ return 0;
57849+}
57850+
57851+static int
57852+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
57853+ struct acl_role_label *role)
57854+{
57855+ struct acl_object_label *o_tmp;
57856+ unsigned int len;
57857+ int ret;
57858+ char *tmp;
57859+
57860+ while (userp) {
57861+ if ((o_tmp = (struct acl_object_label *)
57862+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
57863+ return -ENOMEM;
57864+
57865+ if (copy_from_user(o_tmp, userp,
57866+ sizeof (struct acl_object_label)))
57867+ return -EFAULT;
57868+
57869+ userp = o_tmp->prev;
57870+
57871+ len = strnlen_user(o_tmp->filename, PATH_MAX);
57872+
57873+ if (!len || len >= PATH_MAX)
57874+ return -EINVAL;
57875+
57876+ if ((tmp = (char *) acl_alloc(len)) == NULL)
57877+ return -ENOMEM;
57878+
57879+ if (copy_from_user(tmp, o_tmp->filename, len))
57880+ return -EFAULT;
57881+ tmp[len-1] = '\0';
57882+ o_tmp->filename = tmp;
57883+
57884+ insert_acl_obj_label(o_tmp, subj);
57885+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
57886+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
57887+ return -ENOMEM;
57888+
57889+ ret = copy_user_glob(o_tmp);
57890+ if (ret)
57891+ return ret;
57892+
57893+ if (o_tmp->nested) {
57894+ int already_copied;
57895+
57896+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
57897+ if (IS_ERR(o_tmp->nested))
57898+ return PTR_ERR(o_tmp->nested);
57899+
57900+ /* insert into nested subject list if we haven't copied this one yet
57901+ to prevent duplicate entries */
57902+ if (!already_copied) {
57903+ o_tmp->nested->next = role->hash->first;
57904+ role->hash->first = o_tmp->nested;
57905+ }
57906+ }
57907+ }
57908+
57909+ return 0;
57910+}
57911+
57912+static __u32
57913+count_user_subjs(struct acl_subject_label *userp)
57914+{
57915+ struct acl_subject_label s_tmp;
57916+ __u32 num = 0;
57917+
57918+ while (userp) {
57919+ if (copy_from_user(&s_tmp, userp,
57920+ sizeof (struct acl_subject_label)))
57921+ break;
57922+
57923+ userp = s_tmp.prev;
57924+ }
57925+
57926+ return num;
57927+}
57928+
57929+static int
57930+copy_user_allowedips(struct acl_role_label *rolep)
57931+{
57932+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
57933+
57934+ ruserip = rolep->allowed_ips;
57935+
57936+ while (ruserip) {
57937+ rlast = rtmp;
57938+
57939+ if ((rtmp = (struct role_allowed_ip *)
57940+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
57941+ return -ENOMEM;
57942+
57943+ if (copy_from_user(rtmp, ruserip,
57944+ sizeof (struct role_allowed_ip)))
57945+ return -EFAULT;
57946+
57947+ ruserip = rtmp->prev;
57948+
57949+ if (!rlast) {
57950+ rtmp->prev = NULL;
57951+ rolep->allowed_ips = rtmp;
57952+ } else {
57953+ rlast->next = rtmp;
57954+ rtmp->prev = rlast;
57955+ }
57956+
57957+ if (!ruserip)
57958+ rtmp->next = NULL;
57959+ }
57960+
57961+ return 0;
57962+}
57963+
57964+static int
57965+copy_user_transitions(struct acl_role_label *rolep)
57966+{
57967+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
57968+
57969+ unsigned int len;
57970+ char *tmp;
57971+
57972+ rusertp = rolep->transitions;
57973+
57974+ while (rusertp) {
57975+ rlast = rtmp;
57976+
57977+ if ((rtmp = (struct role_transition *)
57978+ acl_alloc(sizeof (struct role_transition))) == NULL)
57979+ return -ENOMEM;
57980+
57981+ if (copy_from_user(rtmp, rusertp,
57982+ sizeof (struct role_transition)))
57983+ return -EFAULT;
57984+
57985+ rusertp = rtmp->prev;
57986+
57987+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
57988+
57989+ if (!len || len >= GR_SPROLE_LEN)
57990+ return -EINVAL;
57991+
57992+ if ((tmp = (char *) acl_alloc(len)) == NULL)
57993+ return -ENOMEM;
57994+
57995+ if (copy_from_user(tmp, rtmp->rolename, len))
57996+ return -EFAULT;
57997+ tmp[len-1] = '\0';
57998+ rtmp->rolename = tmp;
57999+
58000+ if (!rlast) {
58001+ rtmp->prev = NULL;
58002+ rolep->transitions = rtmp;
58003+ } else {
58004+ rlast->next = rtmp;
58005+ rtmp->prev = rlast;
58006+ }
58007+
58008+ if (!rusertp)
58009+ rtmp->next = NULL;
58010+ }
58011+
58012+ return 0;
58013+}
58014+
58015+static struct acl_subject_label *
58016+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58017+{
58018+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58019+ unsigned int len;
58020+ char *tmp;
58021+ __u32 num_objs;
58022+ struct acl_ip_label **i_tmp, *i_utmp2;
58023+ struct gr_hash_struct ghash;
58024+ struct subject_map *subjmap;
58025+ unsigned int i_num;
58026+ int err;
58027+
58028+ if (already_copied != NULL)
58029+ *already_copied = 0;
58030+
58031+ s_tmp = lookup_subject_map(userp);
58032+
58033+ /* we've already copied this subject into the kernel, just return
58034+ the reference to it, and don't copy it over again
58035+ */
58036+ if (s_tmp) {
58037+ if (already_copied != NULL)
58038+ *already_copied = 1;
58039+ return(s_tmp);
58040+ }
58041+
58042+ if ((s_tmp = (struct acl_subject_label *)
58043+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58044+ return ERR_PTR(-ENOMEM);
58045+
58046+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58047+ if (subjmap == NULL)
58048+ return ERR_PTR(-ENOMEM);
58049+
58050+ subjmap->user = userp;
58051+ subjmap->kernel = s_tmp;
58052+ insert_subj_map_entry(subjmap);
58053+
58054+ if (copy_from_user(s_tmp, userp,
58055+ sizeof (struct acl_subject_label)))
58056+ return ERR_PTR(-EFAULT);
58057+
58058+ len = strnlen_user(s_tmp->filename, PATH_MAX);
58059+
58060+ if (!len || len >= PATH_MAX)
58061+ return ERR_PTR(-EINVAL);
58062+
58063+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58064+ return ERR_PTR(-ENOMEM);
58065+
58066+ if (copy_from_user(tmp, s_tmp->filename, len))
58067+ return ERR_PTR(-EFAULT);
58068+ tmp[len-1] = '\0';
58069+ s_tmp->filename = tmp;
58070+
58071+ if (!strcmp(s_tmp->filename, "/"))
58072+ role->root_label = s_tmp;
58073+
58074+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58075+ return ERR_PTR(-EFAULT);
58076+
58077+ /* copy user and group transition tables */
58078+
58079+ if (s_tmp->user_trans_num) {
58080+ uid_t *uidlist;
58081+
58082+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58083+ if (uidlist == NULL)
58084+ return ERR_PTR(-ENOMEM);
58085+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58086+ return ERR_PTR(-EFAULT);
58087+
58088+ s_tmp->user_transitions = uidlist;
58089+ }
58090+
58091+ if (s_tmp->group_trans_num) {
58092+ gid_t *gidlist;
58093+
58094+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58095+ if (gidlist == NULL)
58096+ return ERR_PTR(-ENOMEM);
58097+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58098+ return ERR_PTR(-EFAULT);
58099+
58100+ s_tmp->group_transitions = gidlist;
58101+ }
58102+
58103+ /* set up object hash table */
58104+ num_objs = count_user_objs(ghash.first);
58105+
58106+ s_tmp->obj_hash_size = num_objs;
58107+ s_tmp->obj_hash =
58108+ (struct acl_object_label **)
58109+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58110+
58111+ if (!s_tmp->obj_hash)
58112+ return ERR_PTR(-ENOMEM);
58113+
58114+ memset(s_tmp->obj_hash, 0,
58115+ s_tmp->obj_hash_size *
58116+ sizeof (struct acl_object_label *));
58117+
58118+ /* add in objects */
58119+ err = copy_user_objs(ghash.first, s_tmp, role);
58120+
58121+ if (err)
58122+ return ERR_PTR(err);
58123+
58124+ /* set pointer for parent subject */
58125+ if (s_tmp->parent_subject) {
58126+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58127+
58128+ if (IS_ERR(s_tmp2))
58129+ return s_tmp2;
58130+
58131+ s_tmp->parent_subject = s_tmp2;
58132+ }
58133+
58134+ /* add in ip acls */
58135+
58136+ if (!s_tmp->ip_num) {
58137+ s_tmp->ips = NULL;
58138+ goto insert;
58139+ }
58140+
58141+ i_tmp =
58142+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58143+ sizeof (struct acl_ip_label *));
58144+
58145+ if (!i_tmp)
58146+ return ERR_PTR(-ENOMEM);
58147+
58148+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58149+ *(i_tmp + i_num) =
58150+ (struct acl_ip_label *)
58151+ acl_alloc(sizeof (struct acl_ip_label));
58152+ if (!*(i_tmp + i_num))
58153+ return ERR_PTR(-ENOMEM);
58154+
58155+ if (copy_from_user
58156+ (&i_utmp2, s_tmp->ips + i_num,
58157+ sizeof (struct acl_ip_label *)))
58158+ return ERR_PTR(-EFAULT);
58159+
58160+ if (copy_from_user
58161+ (*(i_tmp + i_num), i_utmp2,
58162+ sizeof (struct acl_ip_label)))
58163+ return ERR_PTR(-EFAULT);
58164+
58165+ if ((*(i_tmp + i_num))->iface == NULL)
58166+ continue;
58167+
58168+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58169+ if (!len || len >= IFNAMSIZ)
58170+ return ERR_PTR(-EINVAL);
58171+ tmp = acl_alloc(len);
58172+ if (tmp == NULL)
58173+ return ERR_PTR(-ENOMEM);
58174+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58175+ return ERR_PTR(-EFAULT);
58176+ (*(i_tmp + i_num))->iface = tmp;
58177+ }
58178+
58179+ s_tmp->ips = i_tmp;
58180+
58181+insert:
58182+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58183+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58184+ return ERR_PTR(-ENOMEM);
58185+
58186+ return s_tmp;
58187+}
58188+
58189+static int
58190+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58191+{
58192+ struct acl_subject_label s_pre;
58193+ struct acl_subject_label * ret;
58194+ int err;
58195+
58196+ while (userp) {
58197+ if (copy_from_user(&s_pre, userp,
58198+ sizeof (struct acl_subject_label)))
58199+ return -EFAULT;
58200+
58201+ ret = do_copy_user_subj(userp, role, NULL);
58202+
58203+ err = PTR_ERR(ret);
58204+ if (IS_ERR(ret))
58205+ return err;
58206+
58207+ insert_acl_subj_label(ret, role);
58208+
58209+ userp = s_pre.prev;
58210+ }
58211+
58212+ return 0;
58213+}
58214+
58215+static int
58216+copy_user_acl(struct gr_arg *arg)
58217+{
58218+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58219+ struct acl_subject_label *subj_list;
58220+ struct sprole_pw *sptmp;
58221+ struct gr_hash_struct *ghash;
58222+ uid_t *domainlist;
58223+ unsigned int r_num;
58224+ unsigned int len;
58225+ char *tmp;
58226+ int err = 0;
58227+ __u16 i;
58228+ __u32 num_subjs;
58229+
58230+ /* we need a default and kernel role */
58231+ if (arg->role_db.num_roles < 2)
58232+ return -EINVAL;
58233+
58234+ /* copy special role authentication info from userspace */
58235+
58236+ num_sprole_pws = arg->num_sprole_pws;
58237+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58238+
58239+ if (!acl_special_roles && num_sprole_pws)
58240+ return -ENOMEM;
58241+
58242+ for (i = 0; i < num_sprole_pws; i++) {
58243+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58244+ if (!sptmp)
58245+ return -ENOMEM;
58246+ if (copy_from_user(sptmp, arg->sprole_pws + i,
58247+ sizeof (struct sprole_pw)))
58248+ return -EFAULT;
58249+
58250+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58251+
58252+ if (!len || len >= GR_SPROLE_LEN)
58253+ return -EINVAL;
58254+
58255+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58256+ return -ENOMEM;
58257+
58258+ if (copy_from_user(tmp, sptmp->rolename, len))
58259+ return -EFAULT;
58260+
58261+ tmp[len-1] = '\0';
58262+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58263+ printk(KERN_ALERT "Copying special role %s\n", tmp);
58264+#endif
58265+ sptmp->rolename = tmp;
58266+ acl_special_roles[i] = sptmp;
58267+ }
58268+
58269+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58270+
58271+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58272+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
58273+
58274+ if (!r_tmp)
58275+ return -ENOMEM;
58276+
58277+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
58278+ sizeof (struct acl_role_label *)))
58279+ return -EFAULT;
58280+
58281+ if (copy_from_user(r_tmp, r_utmp2,
58282+ sizeof (struct acl_role_label)))
58283+ return -EFAULT;
58284+
58285+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58286+
58287+ if (!len || len >= PATH_MAX)
58288+ return -EINVAL;
58289+
58290+ if ((tmp = (char *) acl_alloc(len)) == NULL)
58291+ return -ENOMEM;
58292+
58293+ if (copy_from_user(tmp, r_tmp->rolename, len))
58294+ return -EFAULT;
58295+
58296+ tmp[len-1] = '\0';
58297+ r_tmp->rolename = tmp;
58298+
58299+ if (!strcmp(r_tmp->rolename, "default")
58300+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58301+ default_role = r_tmp;
58302+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58303+ kernel_role = r_tmp;
58304+ }
58305+
58306+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58307+ return -ENOMEM;
58308+
58309+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58310+ return -EFAULT;
58311+
58312+ r_tmp->hash = ghash;
58313+
58314+ num_subjs = count_user_subjs(r_tmp->hash->first);
58315+
58316+ r_tmp->subj_hash_size = num_subjs;
58317+ r_tmp->subj_hash =
58318+ (struct acl_subject_label **)
58319+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58320+
58321+ if (!r_tmp->subj_hash)
58322+ return -ENOMEM;
58323+
58324+ err = copy_user_allowedips(r_tmp);
58325+ if (err)
58326+ return err;
58327+
58328+ /* copy domain info */
58329+ if (r_tmp->domain_children != NULL) {
58330+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58331+ if (domainlist == NULL)
58332+ return -ENOMEM;
58333+
58334+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58335+ return -EFAULT;
58336+
58337+ r_tmp->domain_children = domainlist;
58338+ }
58339+
58340+ err = copy_user_transitions(r_tmp);
58341+ if (err)
58342+ return err;
58343+
58344+ memset(r_tmp->subj_hash, 0,
58345+ r_tmp->subj_hash_size *
58346+ sizeof (struct acl_subject_label *));
58347+
58348+ /* acquire the list of subjects, then NULL out
58349+ the list prior to parsing the subjects for this role,
58350+ as during this parsing the list is replaced with a list
58351+ of *nested* subjects for the role
58352+ */
58353+ subj_list = r_tmp->hash->first;
58354+
58355+ /* set nested subject list to null */
58356+ r_tmp->hash->first = NULL;
58357+
58358+ err = copy_user_subjs(subj_list, r_tmp);
58359+
58360+ if (err)
58361+ return err;
58362+
58363+ insert_acl_role_label(r_tmp);
58364+ }
58365+
58366+ if (default_role == NULL || kernel_role == NULL)
58367+ return -EINVAL;
58368+
58369+ return err;
58370+}
58371+
58372+static int
58373+gracl_init(struct gr_arg *args)
58374+{
58375+ int error = 0;
58376+
58377+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58378+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58379+
58380+ if (init_variables(args)) {
58381+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58382+ error = -ENOMEM;
58383+ free_variables();
58384+ goto out;
58385+ }
58386+
58387+ error = copy_user_acl(args);
58388+ free_init_variables();
58389+ if (error) {
58390+ free_variables();
58391+ goto out;
58392+ }
58393+
58394+ if ((error = gr_set_acls(0))) {
58395+ free_variables();
58396+ goto out;
58397+ }
58398+
58399+ pax_open_kernel();
58400+ gr_status |= GR_READY;
58401+ pax_close_kernel();
58402+
58403+ out:
58404+ return error;
58405+}
58406+
58407+/* derived from glibc fnmatch() 0: match, 1: no match*/
58408+
58409+static int
58410+glob_match(const char *p, const char *n)
58411+{
58412+ char c;
58413+
58414+ while ((c = *p++) != '\0') {
58415+ switch (c) {
58416+ case '?':
58417+ if (*n == '\0')
58418+ return 1;
58419+ else if (*n == '/')
58420+ return 1;
58421+ break;
58422+ case '\\':
58423+ if (*n != c)
58424+ return 1;
58425+ break;
58426+ case '*':
58427+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
58428+ if (*n == '/')
58429+ return 1;
58430+ else if (c == '?') {
58431+ if (*n == '\0')
58432+ return 1;
58433+ else
58434+ ++n;
58435+ }
58436+ }
58437+ if (c == '\0') {
58438+ return 0;
58439+ } else {
58440+ const char *endp;
58441+
58442+ if ((endp = strchr(n, '/')) == NULL)
58443+ endp = n + strlen(n);
58444+
58445+ if (c == '[') {
58446+ for (--p; n < endp; ++n)
58447+ if (!glob_match(p, n))
58448+ return 0;
58449+ } else if (c == '/') {
58450+ while (*n != '\0' && *n != '/')
58451+ ++n;
58452+ if (*n == '/' && !glob_match(p, n + 1))
58453+ return 0;
58454+ } else {
58455+ for (--p; n < endp; ++n)
58456+ if (*n == c && !glob_match(p, n))
58457+ return 0;
58458+ }
58459+
58460+ return 1;
58461+ }
58462+ case '[':
58463+ {
58464+ int not;
58465+ char cold;
58466+
58467+ if (*n == '\0' || *n == '/')
58468+ return 1;
58469+
58470+ not = (*p == '!' || *p == '^');
58471+ if (not)
58472+ ++p;
58473+
58474+ c = *p++;
58475+ for (;;) {
58476+ unsigned char fn = (unsigned char)*n;
58477+
58478+ if (c == '\0')
58479+ return 1;
58480+ else {
58481+ if (c == fn)
58482+ goto matched;
58483+ cold = c;
58484+ c = *p++;
58485+
58486+ if (c == '-' && *p != ']') {
58487+ unsigned char cend = *p++;
58488+
58489+ if (cend == '\0')
58490+ return 1;
58491+
58492+ if (cold <= fn && fn <= cend)
58493+ goto matched;
58494+
58495+ c = *p++;
58496+ }
58497+ }
58498+
58499+ if (c == ']')
58500+ break;
58501+ }
58502+ if (!not)
58503+ return 1;
58504+ break;
58505+ matched:
58506+ while (c != ']') {
58507+ if (c == '\0')
58508+ return 1;
58509+
58510+ c = *p++;
58511+ }
58512+ if (not)
58513+ return 1;
58514+ }
58515+ break;
58516+ default:
58517+ if (c != *n)
58518+ return 1;
58519+ }
58520+
58521+ ++n;
58522+ }
58523+
58524+ if (*n == '\0')
58525+ return 0;
58526+
58527+ if (*n == '/')
58528+ return 0;
58529+
58530+ return 1;
58531+}
58532+
58533+static struct acl_object_label *
58534+chk_glob_label(struct acl_object_label *globbed,
58535+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58536+{
58537+ struct acl_object_label *tmp;
58538+
58539+ if (*path == NULL)
58540+ *path = gr_to_filename_nolock(dentry, mnt);
58541+
58542+ tmp = globbed;
58543+
58544+ while (tmp) {
58545+ if (!glob_match(tmp->filename, *path))
58546+ return tmp;
58547+ tmp = tmp->next;
58548+ }
58549+
58550+ return NULL;
58551+}
58552+
58553+static struct acl_object_label *
58554+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58555+ const ino_t curr_ino, const dev_t curr_dev,
58556+ const struct acl_subject_label *subj, char **path, const int checkglob)
58557+{
58558+ struct acl_subject_label *tmpsubj;
58559+ struct acl_object_label *retval;
58560+ struct acl_object_label *retval2;
58561+
58562+ tmpsubj = (struct acl_subject_label *) subj;
58563+ read_lock(&gr_inode_lock);
58564+ do {
58565+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
58566+ if (retval) {
58567+ if (checkglob && retval->globbed) {
58568+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
58569+ if (retval2)
58570+ retval = retval2;
58571+ }
58572+ break;
58573+ }
58574+ } while ((tmpsubj = tmpsubj->parent_subject));
58575+ read_unlock(&gr_inode_lock);
58576+
58577+ return retval;
58578+}
58579+
58580+static __inline__ struct acl_object_label *
58581+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58582+ struct dentry *curr_dentry,
58583+ const struct acl_subject_label *subj, char **path, const int checkglob)
58584+{
58585+ int newglob = checkglob;
58586+ ino_t inode;
58587+ dev_t device;
58588+
58589+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
58590+ as we don't want a / * rule to match instead of the / object
58591+ don't do this for create lookups that call this function though, since they're looking up
58592+ on the parent and thus need globbing checks on all paths
58593+ */
58594+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
58595+ newglob = GR_NO_GLOB;
58596+
58597+ spin_lock(&curr_dentry->d_lock);
58598+ inode = curr_dentry->d_inode->i_ino;
58599+ device = __get_dev(curr_dentry);
58600+ spin_unlock(&curr_dentry->d_lock);
58601+
58602+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
58603+}
58604+
58605+#ifdef CONFIG_HUGETLBFS
58606+static inline bool
58607+is_hugetlbfs_mnt(const struct vfsmount *mnt)
58608+{
58609+ int i;
58610+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
58611+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
58612+ return true;
58613+ }
58614+
58615+ return false;
58616+}
58617+#endif
58618+
58619+static struct acl_object_label *
58620+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58621+ const struct acl_subject_label *subj, char *path, const int checkglob)
58622+{
58623+ struct dentry *dentry = (struct dentry *) l_dentry;
58624+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58625+ struct mount *real_mnt = real_mount(mnt);
58626+ struct acl_object_label *retval;
58627+ struct dentry *parent;
58628+
58629+ write_seqlock(&rename_lock);
58630+ br_read_lock(&vfsmount_lock);
58631+
58632+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
58633+#ifdef CONFIG_NET
58634+ mnt == sock_mnt ||
58635+#endif
58636+#ifdef CONFIG_HUGETLBFS
58637+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
58638+#endif
58639+ /* ignore Eric Biederman */
58640+ IS_PRIVATE(l_dentry->d_inode))) {
58641+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
58642+ goto out;
58643+ }
58644+
58645+ for (;;) {
58646+ if (dentry == real_root.dentry && mnt == real_root.mnt)
58647+ break;
58648+
58649+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58650+ if (!mnt_has_parent(real_mnt))
58651+ break;
58652+
58653+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58654+ if (retval != NULL)
58655+ goto out;
58656+
58657+ dentry = real_mnt->mnt_mountpoint;
58658+ real_mnt = real_mnt->mnt_parent;
58659+ mnt = &real_mnt->mnt;
58660+ continue;
58661+ }
58662+
58663+ parent = dentry->d_parent;
58664+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58665+ if (retval != NULL)
58666+ goto out;
58667+
58668+ dentry = parent;
58669+ }
58670+
58671+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58672+
58673+ /* real_root is pinned so we don't have to hold a reference */
58674+ if (retval == NULL)
58675+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
58676+out:
58677+ br_read_unlock(&vfsmount_lock);
58678+ write_sequnlock(&rename_lock);
58679+
58680+ BUG_ON(retval == NULL);
58681+
58682+ return retval;
58683+}
58684+
58685+static __inline__ struct acl_object_label *
58686+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58687+ const struct acl_subject_label *subj)
58688+{
58689+ char *path = NULL;
58690+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
58691+}
58692+
58693+static __inline__ struct acl_object_label *
58694+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58695+ const struct acl_subject_label *subj)
58696+{
58697+ char *path = NULL;
58698+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
58699+}
58700+
58701+static __inline__ struct acl_object_label *
58702+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58703+ const struct acl_subject_label *subj, char *path)
58704+{
58705+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
58706+}
58707+
58708+static struct acl_subject_label *
58709+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58710+ const struct acl_role_label *role)
58711+{
58712+ struct dentry *dentry = (struct dentry *) l_dentry;
58713+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58714+ struct mount *real_mnt = real_mount(mnt);
58715+ struct acl_subject_label *retval;
58716+ struct dentry *parent;
58717+
58718+ write_seqlock(&rename_lock);
58719+ br_read_lock(&vfsmount_lock);
58720+
58721+ for (;;) {
58722+ if (dentry == real_root.dentry && mnt == real_root.mnt)
58723+ break;
58724+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58725+ if (!mnt_has_parent(real_mnt))
58726+ break;
58727+
58728+ spin_lock(&dentry->d_lock);
58729+ read_lock(&gr_inode_lock);
58730+ retval =
58731+ lookup_acl_subj_label(dentry->d_inode->i_ino,
58732+ __get_dev(dentry), role);
58733+ read_unlock(&gr_inode_lock);
58734+ spin_unlock(&dentry->d_lock);
58735+ if (retval != NULL)
58736+ goto out;
58737+
58738+ dentry = real_mnt->mnt_mountpoint;
58739+ real_mnt = real_mnt->mnt_parent;
58740+ mnt = &real_mnt->mnt;
58741+ continue;
58742+ }
58743+
58744+ spin_lock(&dentry->d_lock);
58745+ read_lock(&gr_inode_lock);
58746+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58747+ __get_dev(dentry), role);
58748+ read_unlock(&gr_inode_lock);
58749+ parent = dentry->d_parent;
58750+ spin_unlock(&dentry->d_lock);
58751+
58752+ if (retval != NULL)
58753+ goto out;
58754+
58755+ dentry = parent;
58756+ }
58757+
58758+ spin_lock(&dentry->d_lock);
58759+ read_lock(&gr_inode_lock);
58760+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58761+ __get_dev(dentry), role);
58762+ read_unlock(&gr_inode_lock);
58763+ spin_unlock(&dentry->d_lock);
58764+
58765+ if (unlikely(retval == NULL)) {
58766+ /* real_root is pinned, we don't need to hold a reference */
58767+ read_lock(&gr_inode_lock);
58768+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
58769+ __get_dev(real_root.dentry), role);
58770+ read_unlock(&gr_inode_lock);
58771+ }
58772+out:
58773+ br_read_unlock(&vfsmount_lock);
58774+ write_sequnlock(&rename_lock);
58775+
58776+ BUG_ON(retval == NULL);
58777+
58778+ return retval;
58779+}
58780+
58781+static void
58782+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
58783+{
58784+ struct task_struct *task = current;
58785+ const struct cred *cred = current_cred();
58786+
58787+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
58788+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58789+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58790+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
58791+
58792+ return;
58793+}
58794+
58795+static void
58796+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
58797+{
58798+ struct task_struct *task = current;
58799+ const struct cred *cred = current_cred();
58800+
58801+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58802+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58803+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58804+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
58805+
58806+ return;
58807+}
58808+
58809+static void
58810+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
58811+{
58812+ struct task_struct *task = current;
58813+ const struct cred *cred = current_cred();
58814+
58815+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58816+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58817+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58818+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
58819+
58820+ return;
58821+}
58822+
58823+__u32
58824+gr_search_file(const struct dentry * dentry, const __u32 mode,
58825+ const struct vfsmount * mnt)
58826+{
58827+ __u32 retval = mode;
58828+ struct acl_subject_label *curracl;
58829+ struct acl_object_label *currobj;
58830+
58831+ if (unlikely(!(gr_status & GR_READY)))
58832+ return (mode & ~GR_AUDITS);
58833+
58834+ curracl = current->acl;
58835+
58836+ currobj = chk_obj_label(dentry, mnt, curracl);
58837+ retval = currobj->mode & mode;
58838+
58839+ /* if we're opening a specified transfer file for writing
58840+ (e.g. /dev/initctl), then transfer our role to init
58841+ */
58842+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
58843+ current->role->roletype & GR_ROLE_PERSIST)) {
58844+ struct task_struct *task = init_pid_ns.child_reaper;
58845+
58846+ if (task->role != current->role) {
58847+ task->acl_sp_role = 0;
58848+ task->acl_role_id = current->acl_role_id;
58849+ task->role = current->role;
58850+ rcu_read_lock();
58851+ read_lock(&grsec_exec_file_lock);
58852+ gr_apply_subject_to_task(task);
58853+ read_unlock(&grsec_exec_file_lock);
58854+ rcu_read_unlock();
58855+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
58856+ }
58857+ }
58858+
58859+ if (unlikely
58860+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
58861+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
58862+ __u32 new_mode = mode;
58863+
58864+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58865+
58866+ retval = new_mode;
58867+
58868+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
58869+ new_mode |= GR_INHERIT;
58870+
58871+ if (!(mode & GR_NOLEARN))
58872+ gr_log_learn(dentry, mnt, new_mode);
58873+ }
58874+
58875+ return retval;
58876+}
58877+
58878+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
58879+ const struct dentry *parent,
58880+ const struct vfsmount *mnt)
58881+{
58882+ struct name_entry *match;
58883+ struct acl_object_label *matchpo;
58884+ struct acl_subject_label *curracl;
58885+ char *path;
58886+
58887+ if (unlikely(!(gr_status & GR_READY)))
58888+ return NULL;
58889+
58890+ preempt_disable();
58891+ path = gr_to_filename_rbac(new_dentry, mnt);
58892+ match = lookup_name_entry_create(path);
58893+
58894+ curracl = current->acl;
58895+
58896+ if (match) {
58897+ read_lock(&gr_inode_lock);
58898+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
58899+ read_unlock(&gr_inode_lock);
58900+
58901+ if (matchpo) {
58902+ preempt_enable();
58903+ return matchpo;
58904+ }
58905+ }
58906+
58907+ // lookup parent
58908+
58909+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
58910+
58911+ preempt_enable();
58912+ return matchpo;
58913+}
58914+
58915+__u32
58916+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
58917+ const struct vfsmount * mnt, const __u32 mode)
58918+{
58919+ struct acl_object_label *matchpo;
58920+ __u32 retval;
58921+
58922+ if (unlikely(!(gr_status & GR_READY)))
58923+ return (mode & ~GR_AUDITS);
58924+
58925+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
58926+
58927+ retval = matchpo->mode & mode;
58928+
58929+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
58930+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
58931+ __u32 new_mode = mode;
58932+
58933+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58934+
58935+ gr_log_learn(new_dentry, mnt, new_mode);
58936+ return new_mode;
58937+ }
58938+
58939+ return retval;
58940+}
58941+
58942+__u32
58943+gr_check_link(const struct dentry * new_dentry,
58944+ const struct dentry * parent_dentry,
58945+ const struct vfsmount * parent_mnt,
58946+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
58947+{
58948+ struct acl_object_label *obj;
58949+ __u32 oldmode, newmode;
58950+ __u32 needmode;
58951+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
58952+ GR_DELETE | GR_INHERIT;
58953+
58954+ if (unlikely(!(gr_status & GR_READY)))
58955+ return (GR_CREATE | GR_LINK);
58956+
58957+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
58958+ oldmode = obj->mode;
58959+
58960+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
58961+ newmode = obj->mode;
58962+
58963+ needmode = newmode & checkmodes;
58964+
58965+ // old name for hardlink must have at least the permissions of the new name
58966+ if ((oldmode & needmode) != needmode)
58967+ goto bad;
58968+
58969+ // if old name had restrictions/auditing, make sure the new name does as well
58970+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
58971+
58972+ // don't allow hardlinking of suid/sgid/fcapped files without permission
58973+ if (is_privileged_binary(old_dentry))
58974+ needmode |= GR_SETID;
58975+
58976+ if ((newmode & needmode) != needmode)
58977+ goto bad;
58978+
58979+ // enforce minimum permissions
58980+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
58981+ return newmode;
58982+bad:
58983+ needmode = oldmode;
58984+ if (is_privileged_binary(old_dentry))
58985+ needmode |= GR_SETID;
58986+
58987+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
58988+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
58989+ return (GR_CREATE | GR_LINK);
58990+ } else if (newmode & GR_SUPPRESS)
58991+ return GR_SUPPRESS;
58992+ else
58993+ return 0;
58994+}
58995+
58996+int
58997+gr_check_hidden_task(const struct task_struct *task)
58998+{
58999+ if (unlikely(!(gr_status & GR_READY)))
59000+ return 0;
59001+
59002+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59003+ return 1;
59004+
59005+ return 0;
59006+}
59007+
59008+int
59009+gr_check_protected_task(const struct task_struct *task)
59010+{
59011+ if (unlikely(!(gr_status & GR_READY) || !task))
59012+ return 0;
59013+
59014+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59015+ task->acl != current->acl)
59016+ return 1;
59017+
59018+ return 0;
59019+}
59020+
59021+int
59022+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59023+{
59024+ struct task_struct *p;
59025+ int ret = 0;
59026+
59027+ if (unlikely(!(gr_status & GR_READY) || !pid))
59028+ return ret;
59029+
59030+ read_lock(&tasklist_lock);
59031+ do_each_pid_task(pid, type, p) {
59032+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59033+ p->acl != current->acl) {
59034+ ret = 1;
59035+ goto out;
59036+ }
59037+ } while_each_pid_task(pid, type, p);
59038+out:
59039+ read_unlock(&tasklist_lock);
59040+
59041+ return ret;
59042+}
59043+
59044+void
59045+gr_copy_label(struct task_struct *tsk)
59046+{
59047+ tsk->signal->used_accept = 0;
59048+ tsk->acl_sp_role = 0;
59049+ tsk->acl_role_id = current->acl_role_id;
59050+ tsk->acl = current->acl;
59051+ tsk->role = current->role;
59052+ tsk->signal->curr_ip = current->signal->curr_ip;
59053+ tsk->signal->saved_ip = current->signal->saved_ip;
59054+ if (current->exec_file)
59055+ get_file(current->exec_file);
59056+ tsk->exec_file = current->exec_file;
59057+ tsk->is_writable = current->is_writable;
59058+ if (unlikely(current->signal->used_accept)) {
59059+ current->signal->curr_ip = 0;
59060+ current->signal->saved_ip = 0;
59061+ }
59062+
59063+ return;
59064+}
59065+
59066+static void
59067+gr_set_proc_res(struct task_struct *task)
59068+{
59069+ struct acl_subject_label *proc;
59070+ unsigned short i;
59071+
59072+ proc = task->acl;
59073+
59074+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59075+ return;
59076+
59077+ for (i = 0; i < RLIM_NLIMITS; i++) {
59078+ if (!(proc->resmask & (1 << i)))
59079+ continue;
59080+
59081+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59082+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59083+ }
59084+
59085+ return;
59086+}
59087+
59088+extern int __gr_process_user_ban(struct user_struct *user);
59089+
59090+int
59091+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59092+{
59093+ unsigned int i;
59094+ __u16 num;
59095+ uid_t *uidlist;
59096+ uid_t curuid;
59097+ int realok = 0;
59098+ int effectiveok = 0;
59099+ int fsok = 0;
59100+ uid_t globalreal, globaleffective, globalfs;
59101+
59102+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59103+ struct user_struct *user;
59104+
59105+ if (!uid_valid(real))
59106+ goto skipit;
59107+
59108+ /* find user based on global namespace */
59109+
59110+ globalreal = GR_GLOBAL_UID(real);
59111+
59112+ user = find_user(make_kuid(&init_user_ns, globalreal));
59113+ if (user == NULL)
59114+ goto skipit;
59115+
59116+ if (__gr_process_user_ban(user)) {
59117+ /* for find_user */
59118+ free_uid(user);
59119+ return 1;
59120+ }
59121+
59122+ /* for find_user */
59123+ free_uid(user);
59124+
59125+skipit:
59126+#endif
59127+
59128+ if (unlikely(!(gr_status & GR_READY)))
59129+ return 0;
59130+
59131+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59132+ gr_log_learn_uid_change(real, effective, fs);
59133+
59134+ num = current->acl->user_trans_num;
59135+ uidlist = current->acl->user_transitions;
59136+
59137+ if (uidlist == NULL)
59138+ return 0;
59139+
59140+ if (!uid_valid(real)) {
59141+ realok = 1;
59142+ globalreal = (uid_t)-1;
59143+ } else {
59144+ globalreal = GR_GLOBAL_UID(real);
59145+ }
59146+ if (!uid_valid(effective)) {
59147+ effectiveok = 1;
59148+ globaleffective = (uid_t)-1;
59149+ } else {
59150+ globaleffective = GR_GLOBAL_UID(effective);
59151+ }
59152+ if (!uid_valid(fs)) {
59153+ fsok = 1;
59154+ globalfs = (uid_t)-1;
59155+ } else {
59156+ globalfs = GR_GLOBAL_UID(fs);
59157+ }
59158+
59159+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
59160+ for (i = 0; i < num; i++) {
59161+ curuid = uidlist[i];
59162+ if (globalreal == curuid)
59163+ realok = 1;
59164+ if (globaleffective == curuid)
59165+ effectiveok = 1;
59166+ if (globalfs == curuid)
59167+ fsok = 1;
59168+ }
59169+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
59170+ for (i = 0; i < num; i++) {
59171+ curuid = uidlist[i];
59172+ if (globalreal == curuid)
59173+ break;
59174+ if (globaleffective == curuid)
59175+ break;
59176+ if (globalfs == curuid)
59177+ break;
59178+ }
59179+ /* not in deny list */
59180+ if (i == num) {
59181+ realok = 1;
59182+ effectiveok = 1;
59183+ fsok = 1;
59184+ }
59185+ }
59186+
59187+ if (realok && effectiveok && fsok)
59188+ return 0;
59189+ else {
59190+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59191+ return 1;
59192+ }
59193+}
59194+
59195+int
59196+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59197+{
59198+ unsigned int i;
59199+ __u16 num;
59200+ gid_t *gidlist;
59201+ gid_t curgid;
59202+ int realok = 0;
59203+ int effectiveok = 0;
59204+ int fsok = 0;
59205+ gid_t globalreal, globaleffective, globalfs;
59206+
59207+ if (unlikely(!(gr_status & GR_READY)))
59208+ return 0;
59209+
59210+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59211+ gr_log_learn_gid_change(real, effective, fs);
59212+
59213+ num = current->acl->group_trans_num;
59214+ gidlist = current->acl->group_transitions;
59215+
59216+ if (gidlist == NULL)
59217+ return 0;
59218+
59219+ if (!gid_valid(real)) {
59220+ realok = 1;
59221+ globalreal = (gid_t)-1;
59222+ } else {
59223+ globalreal = GR_GLOBAL_GID(real);
59224+ }
59225+ if (!gid_valid(effective)) {
59226+ effectiveok = 1;
59227+ globaleffective = (gid_t)-1;
59228+ } else {
59229+ globaleffective = GR_GLOBAL_GID(effective);
59230+ }
59231+ if (!gid_valid(fs)) {
59232+ fsok = 1;
59233+ globalfs = (gid_t)-1;
59234+ } else {
59235+ globalfs = GR_GLOBAL_GID(fs);
59236+ }
59237+
59238+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
59239+ for (i = 0; i < num; i++) {
59240+ curgid = gidlist[i];
59241+ if (globalreal == curgid)
59242+ realok = 1;
59243+ if (globaleffective == curgid)
59244+ effectiveok = 1;
59245+ if (globalfs == curgid)
59246+ fsok = 1;
59247+ }
59248+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
59249+ for (i = 0; i < num; i++) {
59250+ curgid = gidlist[i];
59251+ if (globalreal == curgid)
59252+ break;
59253+ if (globaleffective == curgid)
59254+ break;
59255+ if (globalfs == curgid)
59256+ break;
59257+ }
59258+ /* not in deny list */
59259+ if (i == num) {
59260+ realok = 1;
59261+ effectiveok = 1;
59262+ fsok = 1;
59263+ }
59264+ }
59265+
59266+ if (realok && effectiveok && fsok)
59267+ return 0;
59268+ else {
59269+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59270+ return 1;
59271+ }
59272+}
59273+
59274+extern int gr_acl_is_capable(const int cap);
59275+
59276+void
59277+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59278+{
59279+ struct acl_role_label *role = task->role;
59280+ struct acl_subject_label *subj = NULL;
59281+ struct acl_object_label *obj;
59282+ struct file *filp;
59283+ uid_t uid;
59284+ gid_t gid;
59285+
59286+ if (unlikely(!(gr_status & GR_READY)))
59287+ return;
59288+
59289+ uid = GR_GLOBAL_UID(kuid);
59290+ gid = GR_GLOBAL_GID(kgid);
59291+
59292+ filp = task->exec_file;
59293+
59294+ /* kernel process, we'll give them the kernel role */
59295+ if (unlikely(!filp)) {
59296+ task->role = kernel_role;
59297+ task->acl = kernel_role->root_label;
59298+ return;
59299+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59300+ role = lookup_acl_role_label(task, uid, gid);
59301+
59302+ /* don't change the role if we're not a privileged process */
59303+ if (role && task->role != role &&
59304+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59305+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59306+ return;
59307+
59308+ /* perform subject lookup in possibly new role
59309+ we can use this result below in the case where role == task->role
59310+ */
59311+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59312+
59313+ /* if we changed uid/gid, but result in the same role
59314+ and are using inheritance, don't lose the inherited subject
59315+ if current subject is other than what normal lookup
59316+ would result in, we arrived via inheritance, don't
59317+ lose subject
59318+ */
59319+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59320+ (subj == task->acl)))
59321+ task->acl = subj;
59322+
59323+ task->role = role;
59324+
59325+ task->is_writable = 0;
59326+
59327+ /* ignore additional mmap checks for processes that are writable
59328+ by the default ACL */
59329+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59330+ if (unlikely(obj->mode & GR_WRITE))
59331+ task->is_writable = 1;
59332+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59333+ if (unlikely(obj->mode & GR_WRITE))
59334+ task->is_writable = 1;
59335+
59336+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59337+ 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);
59338+#endif
59339+
59340+ gr_set_proc_res(task);
59341+
59342+ return;
59343+}
59344+
59345+int
59346+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59347+ const int unsafe_flags)
59348+{
59349+ struct task_struct *task = current;
59350+ struct acl_subject_label *newacl;
59351+ struct acl_object_label *obj;
59352+ __u32 retmode;
59353+
59354+ if (unlikely(!(gr_status & GR_READY)))
59355+ return 0;
59356+
59357+ newacl = chk_subj_label(dentry, mnt, task->role);
59358+
59359+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59360+ did an exec
59361+ */
59362+ rcu_read_lock();
59363+ read_lock(&tasklist_lock);
59364+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59365+ (task->parent->acl->mode & GR_POVERRIDE))) {
59366+ read_unlock(&tasklist_lock);
59367+ rcu_read_unlock();
59368+ goto skip_check;
59369+ }
59370+ read_unlock(&tasklist_lock);
59371+ rcu_read_unlock();
59372+
59373+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59374+ !(task->role->roletype & GR_ROLE_GOD) &&
59375+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59376+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59377+ if (unsafe_flags & LSM_UNSAFE_SHARE)
59378+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59379+ else
59380+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59381+ return -EACCES;
59382+ }
59383+
59384+skip_check:
59385+
59386+ obj = chk_obj_label(dentry, mnt, task->acl);
59387+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59388+
59389+ if (!(task->acl->mode & GR_INHERITLEARN) &&
59390+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59391+ if (obj->nested)
59392+ task->acl = obj->nested;
59393+ else
59394+ task->acl = newacl;
59395+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59396+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59397+
59398+ task->is_writable = 0;
59399+
59400+ /* ignore additional mmap checks for processes that are writable
59401+ by the default ACL */
59402+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
59403+ if (unlikely(obj->mode & GR_WRITE))
59404+ task->is_writable = 1;
59405+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
59406+ if (unlikely(obj->mode & GR_WRITE))
59407+ task->is_writable = 1;
59408+
59409+ gr_set_proc_res(task);
59410+
59411+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59412+ 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);
59413+#endif
59414+ return 0;
59415+}
59416+
59417+/* always called with valid inodev ptr */
59418+static void
59419+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59420+{
59421+ struct acl_object_label *matchpo;
59422+ struct acl_subject_label *matchps;
59423+ struct acl_subject_label *subj;
59424+ struct acl_role_label *role;
59425+ unsigned int x;
59426+
59427+ FOR_EACH_ROLE_START(role)
59428+ FOR_EACH_SUBJECT_START(role, subj, x)
59429+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59430+ matchpo->mode |= GR_DELETED;
59431+ FOR_EACH_SUBJECT_END(subj,x)
59432+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
59433+ /* nested subjects aren't in the role's subj_hash table */
59434+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59435+ matchpo->mode |= GR_DELETED;
59436+ FOR_EACH_NESTED_SUBJECT_END(subj)
59437+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59438+ matchps->mode |= GR_DELETED;
59439+ FOR_EACH_ROLE_END(role)
59440+
59441+ inodev->nentry->deleted = 1;
59442+
59443+ return;
59444+}
59445+
59446+void
59447+gr_handle_delete(const ino_t ino, const dev_t dev)
59448+{
59449+ struct inodev_entry *inodev;
59450+
59451+ if (unlikely(!(gr_status & GR_READY)))
59452+ return;
59453+
59454+ write_lock(&gr_inode_lock);
59455+ inodev = lookup_inodev_entry(ino, dev);
59456+ if (inodev != NULL)
59457+ do_handle_delete(inodev, ino, dev);
59458+ write_unlock(&gr_inode_lock);
59459+
59460+ return;
59461+}
59462+
59463+static void
59464+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59465+ const ino_t newinode, const dev_t newdevice,
59466+ struct acl_subject_label *subj)
59467+{
59468+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59469+ struct acl_object_label *match;
59470+
59471+ match = subj->obj_hash[index];
59472+
59473+ while (match && (match->inode != oldinode ||
59474+ match->device != olddevice ||
59475+ !(match->mode & GR_DELETED)))
59476+ match = match->next;
59477+
59478+ if (match && (match->inode == oldinode)
59479+ && (match->device == olddevice)
59480+ && (match->mode & GR_DELETED)) {
59481+ if (match->prev == NULL) {
59482+ subj->obj_hash[index] = match->next;
59483+ if (match->next != NULL)
59484+ match->next->prev = NULL;
59485+ } else {
59486+ match->prev->next = match->next;
59487+ if (match->next != NULL)
59488+ match->next->prev = match->prev;
59489+ }
59490+ match->prev = NULL;
59491+ match->next = NULL;
59492+ match->inode = newinode;
59493+ match->device = newdevice;
59494+ match->mode &= ~GR_DELETED;
59495+
59496+ insert_acl_obj_label(match, subj);
59497+ }
59498+
59499+ return;
59500+}
59501+
59502+static void
59503+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59504+ const ino_t newinode, const dev_t newdevice,
59505+ struct acl_role_label *role)
59506+{
59507+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59508+ struct acl_subject_label *match;
59509+
59510+ match = role->subj_hash[index];
59511+
59512+ while (match && (match->inode != oldinode ||
59513+ match->device != olddevice ||
59514+ !(match->mode & GR_DELETED)))
59515+ match = match->next;
59516+
59517+ if (match && (match->inode == oldinode)
59518+ && (match->device == olddevice)
59519+ && (match->mode & GR_DELETED)) {
59520+ if (match->prev == NULL) {
59521+ role->subj_hash[index] = match->next;
59522+ if (match->next != NULL)
59523+ match->next->prev = NULL;
59524+ } else {
59525+ match->prev->next = match->next;
59526+ if (match->next != NULL)
59527+ match->next->prev = match->prev;
59528+ }
59529+ match->prev = NULL;
59530+ match->next = NULL;
59531+ match->inode = newinode;
59532+ match->device = newdevice;
59533+ match->mode &= ~GR_DELETED;
59534+
59535+ insert_acl_subj_label(match, role);
59536+ }
59537+
59538+ return;
59539+}
59540+
59541+static void
59542+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59543+ const ino_t newinode, const dev_t newdevice)
59544+{
59545+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
59546+ struct inodev_entry *match;
59547+
59548+ match = inodev_set.i_hash[index];
59549+
59550+ while (match && (match->nentry->inode != oldinode ||
59551+ match->nentry->device != olddevice || !match->nentry->deleted))
59552+ match = match->next;
59553+
59554+ if (match && (match->nentry->inode == oldinode)
59555+ && (match->nentry->device == olddevice) &&
59556+ match->nentry->deleted) {
59557+ if (match->prev == NULL) {
59558+ inodev_set.i_hash[index] = match->next;
59559+ if (match->next != NULL)
59560+ match->next->prev = NULL;
59561+ } else {
59562+ match->prev->next = match->next;
59563+ if (match->next != NULL)
59564+ match->next->prev = match->prev;
59565+ }
59566+ match->prev = NULL;
59567+ match->next = NULL;
59568+ match->nentry->inode = newinode;
59569+ match->nentry->device = newdevice;
59570+ match->nentry->deleted = 0;
59571+
59572+ insert_inodev_entry(match);
59573+ }
59574+
59575+ return;
59576+}
59577+
59578+static void
59579+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
59580+{
59581+ struct acl_subject_label *subj;
59582+ struct acl_role_label *role;
59583+ unsigned int x;
59584+
59585+ FOR_EACH_ROLE_START(role)
59586+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
59587+
59588+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
59589+ if ((subj->inode == ino) && (subj->device == dev)) {
59590+ subj->inode = ino;
59591+ subj->device = dev;
59592+ }
59593+ /* nested subjects aren't in the role's subj_hash table */
59594+ update_acl_obj_label(matchn->inode, matchn->device,
59595+ ino, dev, subj);
59596+ FOR_EACH_NESTED_SUBJECT_END(subj)
59597+ FOR_EACH_SUBJECT_START(role, subj, x)
59598+ update_acl_obj_label(matchn->inode, matchn->device,
59599+ ino, dev, subj);
59600+ FOR_EACH_SUBJECT_END(subj,x)
59601+ FOR_EACH_ROLE_END(role)
59602+
59603+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
59604+
59605+ return;
59606+}
59607+
59608+static void
59609+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
59610+ const struct vfsmount *mnt)
59611+{
59612+ ino_t ino = dentry->d_inode->i_ino;
59613+ dev_t dev = __get_dev(dentry);
59614+
59615+ __do_handle_create(matchn, ino, dev);
59616+
59617+ return;
59618+}
59619+
59620+void
59621+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59622+{
59623+ struct name_entry *matchn;
59624+
59625+ if (unlikely(!(gr_status & GR_READY)))
59626+ return;
59627+
59628+ preempt_disable();
59629+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
59630+
59631+ if (unlikely((unsigned long)matchn)) {
59632+ write_lock(&gr_inode_lock);
59633+ do_handle_create(matchn, dentry, mnt);
59634+ write_unlock(&gr_inode_lock);
59635+ }
59636+ preempt_enable();
59637+
59638+ return;
59639+}
59640+
59641+void
59642+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59643+{
59644+ struct name_entry *matchn;
59645+
59646+ if (unlikely(!(gr_status & GR_READY)))
59647+ return;
59648+
59649+ preempt_disable();
59650+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
59651+
59652+ if (unlikely((unsigned long)matchn)) {
59653+ write_lock(&gr_inode_lock);
59654+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
59655+ write_unlock(&gr_inode_lock);
59656+ }
59657+ preempt_enable();
59658+
59659+ return;
59660+}
59661+
59662+void
59663+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59664+ struct dentry *old_dentry,
59665+ struct dentry *new_dentry,
59666+ struct vfsmount *mnt, const __u8 replace)
59667+{
59668+ struct name_entry *matchn;
59669+ struct inodev_entry *inodev;
59670+ struct inode *inode = new_dentry->d_inode;
59671+ ino_t old_ino = old_dentry->d_inode->i_ino;
59672+ dev_t old_dev = __get_dev(old_dentry);
59673+
59674+ /* vfs_rename swaps the name and parent link for old_dentry and
59675+ new_dentry
59676+ at this point, old_dentry has the new name, parent link, and inode
59677+ for the renamed file
59678+ if a file is being replaced by a rename, new_dentry has the inode
59679+ and name for the replaced file
59680+ */
59681+
59682+ if (unlikely(!(gr_status & GR_READY)))
59683+ return;
59684+
59685+ preempt_disable();
59686+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
59687+
59688+ /* we wouldn't have to check d_inode if it weren't for
59689+ NFS silly-renaming
59690+ */
59691+
59692+ write_lock(&gr_inode_lock);
59693+ if (unlikely(replace && inode)) {
59694+ ino_t new_ino = inode->i_ino;
59695+ dev_t new_dev = __get_dev(new_dentry);
59696+
59697+ inodev = lookup_inodev_entry(new_ino, new_dev);
59698+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
59699+ do_handle_delete(inodev, new_ino, new_dev);
59700+ }
59701+
59702+ inodev = lookup_inodev_entry(old_ino, old_dev);
59703+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
59704+ do_handle_delete(inodev, old_ino, old_dev);
59705+
59706+ if (unlikely((unsigned long)matchn))
59707+ do_handle_create(matchn, old_dentry, mnt);
59708+
59709+ write_unlock(&gr_inode_lock);
59710+ preempt_enable();
59711+
59712+ return;
59713+}
59714+
59715+static int
59716+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
59717+ unsigned char **sum)
59718+{
59719+ struct acl_role_label *r;
59720+ struct role_allowed_ip *ipp;
59721+ struct role_transition *trans;
59722+ unsigned int i;
59723+ int found = 0;
59724+ u32 curr_ip = current->signal->curr_ip;
59725+
59726+ current->signal->saved_ip = curr_ip;
59727+
59728+ /* check transition table */
59729+
59730+ for (trans = current->role->transitions; trans; trans = trans->next) {
59731+ if (!strcmp(rolename, trans->rolename)) {
59732+ found = 1;
59733+ break;
59734+ }
59735+ }
59736+
59737+ if (!found)
59738+ return 0;
59739+
59740+ /* handle special roles that do not require authentication
59741+ and check ip */
59742+
59743+ FOR_EACH_ROLE_START(r)
59744+ if (!strcmp(rolename, r->rolename) &&
59745+ (r->roletype & GR_ROLE_SPECIAL)) {
59746+ found = 0;
59747+ if (r->allowed_ips != NULL) {
59748+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
59749+ if ((ntohl(curr_ip) & ipp->netmask) ==
59750+ (ntohl(ipp->addr) & ipp->netmask))
59751+ found = 1;
59752+ }
59753+ } else
59754+ found = 2;
59755+ if (!found)
59756+ return 0;
59757+
59758+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
59759+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
59760+ *salt = NULL;
59761+ *sum = NULL;
59762+ return 1;
59763+ }
59764+ }
59765+ FOR_EACH_ROLE_END(r)
59766+
59767+ for (i = 0; i < num_sprole_pws; i++) {
59768+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
59769+ *salt = acl_special_roles[i]->salt;
59770+ *sum = acl_special_roles[i]->sum;
59771+ return 1;
59772+ }
59773+ }
59774+
59775+ return 0;
59776+}
59777+
59778+static void
59779+assign_special_role(char *rolename)
59780+{
59781+ struct acl_object_label *obj;
59782+ struct acl_role_label *r;
59783+ struct acl_role_label *assigned = NULL;
59784+ struct task_struct *tsk;
59785+ struct file *filp;
59786+
59787+ FOR_EACH_ROLE_START(r)
59788+ if (!strcmp(rolename, r->rolename) &&
59789+ (r->roletype & GR_ROLE_SPECIAL)) {
59790+ assigned = r;
59791+ break;
59792+ }
59793+ FOR_EACH_ROLE_END(r)
59794+
59795+ if (!assigned)
59796+ return;
59797+
59798+ read_lock(&tasklist_lock);
59799+ read_lock(&grsec_exec_file_lock);
59800+
59801+ tsk = current->real_parent;
59802+ if (tsk == NULL)
59803+ goto out_unlock;
59804+
59805+ filp = tsk->exec_file;
59806+ if (filp == NULL)
59807+ goto out_unlock;
59808+
59809+ tsk->is_writable = 0;
59810+
59811+ tsk->acl_sp_role = 1;
59812+ tsk->acl_role_id = ++acl_sp_role_value;
59813+ tsk->role = assigned;
59814+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
59815+
59816+ /* ignore additional mmap checks for processes that are writable
59817+ by the default ACL */
59818+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59819+ if (unlikely(obj->mode & GR_WRITE))
59820+ tsk->is_writable = 1;
59821+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
59822+ if (unlikely(obj->mode & GR_WRITE))
59823+ tsk->is_writable = 1;
59824+
59825+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59826+ 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));
59827+#endif
59828+
59829+out_unlock:
59830+ read_unlock(&grsec_exec_file_lock);
59831+ read_unlock(&tasklist_lock);
59832+ return;
59833+}
59834+
59835+int gr_check_secure_terminal(struct task_struct *task)
59836+{
59837+ struct task_struct *p, *p2, *p3;
59838+ struct files_struct *files;
59839+ struct fdtable *fdt;
59840+ struct file *our_file = NULL, *file;
59841+ int i;
59842+
59843+ if (task->signal->tty == NULL)
59844+ return 1;
59845+
59846+ files = get_files_struct(task);
59847+ if (files != NULL) {
59848+ rcu_read_lock();
59849+ fdt = files_fdtable(files);
59850+ for (i=0; i < fdt->max_fds; i++) {
59851+ file = fcheck_files(files, i);
59852+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
59853+ get_file(file);
59854+ our_file = file;
59855+ }
59856+ }
59857+ rcu_read_unlock();
59858+ put_files_struct(files);
59859+ }
59860+
59861+ if (our_file == NULL)
59862+ return 1;
59863+
59864+ read_lock(&tasklist_lock);
59865+ do_each_thread(p2, p) {
59866+ files = get_files_struct(p);
59867+ if (files == NULL ||
59868+ (p->signal && p->signal->tty == task->signal->tty)) {
59869+ if (files != NULL)
59870+ put_files_struct(files);
59871+ continue;
59872+ }
59873+ rcu_read_lock();
59874+ fdt = files_fdtable(files);
59875+ for (i=0; i < fdt->max_fds; i++) {
59876+ file = fcheck_files(files, i);
59877+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
59878+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
59879+ p3 = task;
59880+ while (task_pid_nr(p3) > 0) {
59881+ if (p3 == p)
59882+ break;
59883+ p3 = p3->real_parent;
59884+ }
59885+ if (p3 == p)
59886+ break;
59887+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
59888+ gr_handle_alertkill(p);
59889+ rcu_read_unlock();
59890+ put_files_struct(files);
59891+ read_unlock(&tasklist_lock);
59892+ fput(our_file);
59893+ return 0;
59894+ }
59895+ }
59896+ rcu_read_unlock();
59897+ put_files_struct(files);
59898+ } while_each_thread(p2, p);
59899+ read_unlock(&tasklist_lock);
59900+
59901+ fput(our_file);
59902+ return 1;
59903+}
59904+
59905+static int gr_rbac_disable(void *unused)
59906+{
59907+ pax_open_kernel();
59908+ gr_status &= ~GR_READY;
59909+ pax_close_kernel();
59910+
59911+ return 0;
59912+}
59913+
59914+ssize_t
59915+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
59916+{
59917+ struct gr_arg_wrapper uwrap;
59918+ unsigned char *sprole_salt = NULL;
59919+ unsigned char *sprole_sum = NULL;
59920+ int error = sizeof (struct gr_arg_wrapper);
59921+ int error2 = 0;
59922+
59923+ mutex_lock(&gr_dev_mutex);
59924+
59925+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
59926+ error = -EPERM;
59927+ goto out;
59928+ }
59929+
59930+ if (count != sizeof (struct gr_arg_wrapper)) {
59931+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
59932+ error = -EINVAL;
59933+ goto out;
59934+ }
59935+
59936+
59937+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
59938+ gr_auth_expires = 0;
59939+ gr_auth_attempts = 0;
59940+ }
59941+
59942+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
59943+ error = -EFAULT;
59944+ goto out;
59945+ }
59946+
59947+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
59948+ error = -EINVAL;
59949+ goto out;
59950+ }
59951+
59952+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
59953+ error = -EFAULT;
59954+ goto out;
59955+ }
59956+
59957+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59958+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59959+ time_after(gr_auth_expires, get_seconds())) {
59960+ error = -EBUSY;
59961+ goto out;
59962+ }
59963+
59964+ /* if non-root trying to do anything other than use a special role,
59965+ do not attempt authentication, do not count towards authentication
59966+ locking
59967+ */
59968+
59969+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
59970+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59971+ gr_is_global_nonroot(current_uid())) {
59972+ error = -EPERM;
59973+ goto out;
59974+ }
59975+
59976+ /* ensure pw and special role name are null terminated */
59977+
59978+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
59979+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
59980+
59981+ /* Okay.
59982+ * We have our enough of the argument structure..(we have yet
59983+ * to copy_from_user the tables themselves) . Copy the tables
59984+ * only if we need them, i.e. for loading operations. */
59985+
59986+ switch (gr_usermode->mode) {
59987+ case GR_STATUS:
59988+ if (gr_status & GR_READY) {
59989+ error = 1;
59990+ if (!gr_check_secure_terminal(current))
59991+ error = 3;
59992+ } else
59993+ error = 2;
59994+ goto out;
59995+ case GR_SHUTDOWN:
59996+ if ((gr_status & GR_READY)
59997+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59998+ stop_machine(gr_rbac_disable, NULL, NULL);
59999+ free_variables();
60000+ memset(gr_usermode, 0, sizeof (struct gr_arg));
60001+ memset(gr_system_salt, 0, GR_SALT_LEN);
60002+ memset(gr_system_sum, 0, GR_SHA_LEN);
60003+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60004+ } else if (gr_status & GR_READY) {
60005+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60006+ error = -EPERM;
60007+ } else {
60008+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60009+ error = -EAGAIN;
60010+ }
60011+ break;
60012+ case GR_ENABLE:
60013+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60014+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60015+ else {
60016+ if (gr_status & GR_READY)
60017+ error = -EAGAIN;
60018+ else
60019+ error = error2;
60020+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60021+ }
60022+ break;
60023+ case GR_RELOAD:
60024+ if (!(gr_status & GR_READY)) {
60025+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60026+ error = -EAGAIN;
60027+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60028+ stop_machine(gr_rbac_disable, NULL, NULL);
60029+ free_variables();
60030+ error2 = gracl_init(gr_usermode);
60031+ if (!error2)
60032+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60033+ else {
60034+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60035+ error = error2;
60036+ }
60037+ } else {
60038+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60039+ error = -EPERM;
60040+ }
60041+ break;
60042+ case GR_SEGVMOD:
60043+ if (unlikely(!(gr_status & GR_READY))) {
60044+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60045+ error = -EAGAIN;
60046+ break;
60047+ }
60048+
60049+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60050+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60051+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60052+ struct acl_subject_label *segvacl;
60053+ segvacl =
60054+ lookup_acl_subj_label(gr_usermode->segv_inode,
60055+ gr_usermode->segv_device,
60056+ current->role);
60057+ if (segvacl) {
60058+ segvacl->crashes = 0;
60059+ segvacl->expires = 0;
60060+ }
60061+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60062+ gr_remove_uid(gr_usermode->segv_uid);
60063+ }
60064+ } else {
60065+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60066+ error = -EPERM;
60067+ }
60068+ break;
60069+ case GR_SPROLE:
60070+ case GR_SPROLEPAM:
60071+ if (unlikely(!(gr_status & GR_READY))) {
60072+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60073+ error = -EAGAIN;
60074+ break;
60075+ }
60076+
60077+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60078+ current->role->expires = 0;
60079+ current->role->auth_attempts = 0;
60080+ }
60081+
60082+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60083+ time_after(current->role->expires, get_seconds())) {
60084+ error = -EBUSY;
60085+ goto out;
60086+ }
60087+
60088+ if (lookup_special_role_auth
60089+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60090+ && ((!sprole_salt && !sprole_sum)
60091+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60092+ char *p = "";
60093+ assign_special_role(gr_usermode->sp_role);
60094+ read_lock(&tasklist_lock);
60095+ if (current->real_parent)
60096+ p = current->real_parent->role->rolename;
60097+ read_unlock(&tasklist_lock);
60098+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60099+ p, acl_sp_role_value);
60100+ } else {
60101+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60102+ error = -EPERM;
60103+ if(!(current->role->auth_attempts++))
60104+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60105+
60106+ goto out;
60107+ }
60108+ break;
60109+ case GR_UNSPROLE:
60110+ if (unlikely(!(gr_status & GR_READY))) {
60111+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60112+ error = -EAGAIN;
60113+ break;
60114+ }
60115+
60116+ if (current->role->roletype & GR_ROLE_SPECIAL) {
60117+ char *p = "";
60118+ int i = 0;
60119+
60120+ read_lock(&tasklist_lock);
60121+ if (current->real_parent) {
60122+ p = current->real_parent->role->rolename;
60123+ i = current->real_parent->acl_role_id;
60124+ }
60125+ read_unlock(&tasklist_lock);
60126+
60127+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60128+ gr_set_acls(1);
60129+ } else {
60130+ error = -EPERM;
60131+ goto out;
60132+ }
60133+ break;
60134+ default:
60135+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60136+ error = -EINVAL;
60137+ break;
60138+ }
60139+
60140+ if (error != -EPERM)
60141+ goto out;
60142+
60143+ if(!(gr_auth_attempts++))
60144+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60145+
60146+ out:
60147+ mutex_unlock(&gr_dev_mutex);
60148+ return error;
60149+}
60150+
60151+/* must be called with
60152+ rcu_read_lock();
60153+ read_lock(&tasklist_lock);
60154+ read_lock(&grsec_exec_file_lock);
60155+*/
60156+int gr_apply_subject_to_task(struct task_struct *task)
60157+{
60158+ struct acl_object_label *obj;
60159+ char *tmpname;
60160+ struct acl_subject_label *tmpsubj;
60161+ struct file *filp;
60162+ struct name_entry *nmatch;
60163+
60164+ filp = task->exec_file;
60165+ if (filp == NULL)
60166+ return 0;
60167+
60168+ /* the following is to apply the correct subject
60169+ on binaries running when the RBAC system
60170+ is enabled, when the binaries have been
60171+ replaced or deleted since their execution
60172+ -----
60173+ when the RBAC system starts, the inode/dev
60174+ from exec_file will be one the RBAC system
60175+ is unaware of. It only knows the inode/dev
60176+ of the present file on disk, or the absence
60177+ of it.
60178+ */
60179+ preempt_disable();
60180+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60181+
60182+ nmatch = lookup_name_entry(tmpname);
60183+ preempt_enable();
60184+ tmpsubj = NULL;
60185+ if (nmatch) {
60186+ if (nmatch->deleted)
60187+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60188+ else
60189+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60190+ if (tmpsubj != NULL)
60191+ task->acl = tmpsubj;
60192+ }
60193+ if (tmpsubj == NULL)
60194+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60195+ task->role);
60196+ if (task->acl) {
60197+ task->is_writable = 0;
60198+ /* ignore additional mmap checks for processes that are writable
60199+ by the default ACL */
60200+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60201+ if (unlikely(obj->mode & GR_WRITE))
60202+ task->is_writable = 1;
60203+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60204+ if (unlikely(obj->mode & GR_WRITE))
60205+ task->is_writable = 1;
60206+
60207+ gr_set_proc_res(task);
60208+
60209+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60210+ 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);
60211+#endif
60212+ } else {
60213+ return 1;
60214+ }
60215+
60216+ return 0;
60217+}
60218+
60219+int
60220+gr_set_acls(const int type)
60221+{
60222+ struct task_struct *task, *task2;
60223+ struct acl_role_label *role = current->role;
60224+ __u16 acl_role_id = current->acl_role_id;
60225+ const struct cred *cred;
60226+ int ret;
60227+
60228+ rcu_read_lock();
60229+ read_lock(&tasklist_lock);
60230+ read_lock(&grsec_exec_file_lock);
60231+ do_each_thread(task2, task) {
60232+ /* check to see if we're called from the exit handler,
60233+ if so, only replace ACLs that have inherited the admin
60234+ ACL */
60235+
60236+ if (type && (task->role != role ||
60237+ task->acl_role_id != acl_role_id))
60238+ continue;
60239+
60240+ task->acl_role_id = 0;
60241+ task->acl_sp_role = 0;
60242+
60243+ if (task->exec_file) {
60244+ cred = __task_cred(task);
60245+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60246+ ret = gr_apply_subject_to_task(task);
60247+ if (ret) {
60248+ read_unlock(&grsec_exec_file_lock);
60249+ read_unlock(&tasklist_lock);
60250+ rcu_read_unlock();
60251+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60252+ return ret;
60253+ }
60254+ } else {
60255+ // it's a kernel process
60256+ task->role = kernel_role;
60257+ task->acl = kernel_role->root_label;
60258+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60259+ task->acl->mode &= ~GR_PROCFIND;
60260+#endif
60261+ }
60262+ } while_each_thread(task2, task);
60263+ read_unlock(&grsec_exec_file_lock);
60264+ read_unlock(&tasklist_lock);
60265+ rcu_read_unlock();
60266+
60267+ return 0;
60268+}
60269+
60270+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60271+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60272+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60273+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60274+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60275+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60276+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60277+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60278+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60279+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60280+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60281+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60282+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60283+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60284+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60285+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60286+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60287+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60288+};
60289+
60290+void
60291+gr_learn_resource(const struct task_struct *task,
60292+ const int res, const unsigned long wanted, const int gt)
60293+{
60294+ struct acl_subject_label *acl;
60295+ const struct cred *cred;
60296+
60297+ if (unlikely((gr_status & GR_READY) &&
60298+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60299+ goto skip_reslog;
60300+
60301+ gr_log_resource(task, res, wanted, gt);
60302+skip_reslog:
60303+
60304+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60305+ return;
60306+
60307+ acl = task->acl;
60308+
60309+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60310+ !(acl->resmask & (1 << (unsigned short) res))))
60311+ return;
60312+
60313+ if (wanted >= acl->res[res].rlim_cur) {
60314+ unsigned long res_add;
60315+
60316+ res_add = wanted + res_learn_bumps[res];
60317+
60318+ acl->res[res].rlim_cur = res_add;
60319+
60320+ if (wanted > acl->res[res].rlim_max)
60321+ acl->res[res].rlim_max = res_add;
60322+
60323+ /* only log the subject filename, since resource logging is supported for
60324+ single-subject learning only */
60325+ rcu_read_lock();
60326+ cred = __task_cred(task);
60327+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60328+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60329+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60330+ "", (unsigned long) res, &task->signal->saved_ip);
60331+ rcu_read_unlock();
60332+ }
60333+
60334+ return;
60335+}
60336+EXPORT_SYMBOL(gr_learn_resource);
60337+#endif
60338+
60339+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60340+void
60341+pax_set_initial_flags(struct linux_binprm *bprm)
60342+{
60343+ struct task_struct *task = current;
60344+ struct acl_subject_label *proc;
60345+ unsigned long flags;
60346+
60347+ if (unlikely(!(gr_status & GR_READY)))
60348+ return;
60349+
60350+ flags = pax_get_flags(task);
60351+
60352+ proc = task->acl;
60353+
60354+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60355+ flags &= ~MF_PAX_PAGEEXEC;
60356+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60357+ flags &= ~MF_PAX_SEGMEXEC;
60358+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60359+ flags &= ~MF_PAX_RANDMMAP;
60360+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60361+ flags &= ~MF_PAX_EMUTRAMP;
60362+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60363+ flags &= ~MF_PAX_MPROTECT;
60364+
60365+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60366+ flags |= MF_PAX_PAGEEXEC;
60367+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60368+ flags |= MF_PAX_SEGMEXEC;
60369+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60370+ flags |= MF_PAX_RANDMMAP;
60371+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60372+ flags |= MF_PAX_EMUTRAMP;
60373+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60374+ flags |= MF_PAX_MPROTECT;
60375+
60376+ pax_set_flags(task, flags);
60377+
60378+ return;
60379+}
60380+#endif
60381+
60382+int
60383+gr_handle_proc_ptrace(struct task_struct *task)
60384+{
60385+ struct file *filp;
60386+ struct task_struct *tmp = task;
60387+ struct task_struct *curtemp = current;
60388+ __u32 retmode;
60389+
60390+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60391+ if (unlikely(!(gr_status & GR_READY)))
60392+ return 0;
60393+#endif
60394+
60395+ read_lock(&tasklist_lock);
60396+ read_lock(&grsec_exec_file_lock);
60397+ filp = task->exec_file;
60398+
60399+ while (task_pid_nr(tmp) > 0) {
60400+ if (tmp == curtemp)
60401+ break;
60402+ tmp = tmp->real_parent;
60403+ }
60404+
60405+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60406+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60407+ read_unlock(&grsec_exec_file_lock);
60408+ read_unlock(&tasklist_lock);
60409+ return 1;
60410+ }
60411+
60412+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60413+ if (!(gr_status & GR_READY)) {
60414+ read_unlock(&grsec_exec_file_lock);
60415+ read_unlock(&tasklist_lock);
60416+ return 0;
60417+ }
60418+#endif
60419+
60420+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60421+ read_unlock(&grsec_exec_file_lock);
60422+ read_unlock(&tasklist_lock);
60423+
60424+ if (retmode & GR_NOPTRACE)
60425+ return 1;
60426+
60427+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60428+ && (current->acl != task->acl || (current->acl != current->role->root_label
60429+ && task_pid_nr(current) != task_pid_nr(task))))
60430+ return 1;
60431+
60432+ return 0;
60433+}
60434+
60435+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60436+{
60437+ if (unlikely(!(gr_status & GR_READY)))
60438+ return;
60439+
60440+ if (!(current->role->roletype & GR_ROLE_GOD))
60441+ return;
60442+
60443+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60444+ p->role->rolename, gr_task_roletype_to_char(p),
60445+ p->acl->filename);
60446+}
60447+
60448+int
60449+gr_handle_ptrace(struct task_struct *task, const long request)
60450+{
60451+ struct task_struct *tmp = task;
60452+ struct task_struct *curtemp = current;
60453+ __u32 retmode;
60454+
60455+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60456+ if (unlikely(!(gr_status & GR_READY)))
60457+ return 0;
60458+#endif
60459+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60460+ read_lock(&tasklist_lock);
60461+ while (task_pid_nr(tmp) > 0) {
60462+ if (tmp == curtemp)
60463+ break;
60464+ tmp = tmp->real_parent;
60465+ }
60466+
60467+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60468+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60469+ read_unlock(&tasklist_lock);
60470+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60471+ return 1;
60472+ }
60473+ read_unlock(&tasklist_lock);
60474+ }
60475+
60476+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60477+ if (!(gr_status & GR_READY))
60478+ return 0;
60479+#endif
60480+
60481+ read_lock(&grsec_exec_file_lock);
60482+ if (unlikely(!task->exec_file)) {
60483+ read_unlock(&grsec_exec_file_lock);
60484+ return 0;
60485+ }
60486+
60487+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60488+ read_unlock(&grsec_exec_file_lock);
60489+
60490+ if (retmode & GR_NOPTRACE) {
60491+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60492+ return 1;
60493+ }
60494+
60495+ if (retmode & GR_PTRACERD) {
60496+ switch (request) {
60497+ case PTRACE_SEIZE:
60498+ case PTRACE_POKETEXT:
60499+ case PTRACE_POKEDATA:
60500+ case PTRACE_POKEUSR:
60501+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60502+ case PTRACE_SETREGS:
60503+ case PTRACE_SETFPREGS:
60504+#endif
60505+#ifdef CONFIG_X86
60506+ case PTRACE_SETFPXREGS:
60507+#endif
60508+#ifdef CONFIG_ALTIVEC
60509+ case PTRACE_SETVRREGS:
60510+#endif
60511+ return 1;
60512+ default:
60513+ return 0;
60514+ }
60515+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
60516+ !(current->role->roletype & GR_ROLE_GOD) &&
60517+ (current->acl != task->acl)) {
60518+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60519+ return 1;
60520+ }
60521+
60522+ return 0;
60523+}
60524+
60525+static int is_writable_mmap(const struct file *filp)
60526+{
60527+ struct task_struct *task = current;
60528+ struct acl_object_label *obj, *obj2;
60529+
60530+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60531+ !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))) {
60532+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60533+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60534+ task->role->root_label);
60535+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60536+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60537+ return 1;
60538+ }
60539+ }
60540+ return 0;
60541+}
60542+
60543+int
60544+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60545+{
60546+ __u32 mode;
60547+
60548+ if (unlikely(!file || !(prot & PROT_EXEC)))
60549+ return 1;
60550+
60551+ if (is_writable_mmap(file))
60552+ return 0;
60553+
60554+ mode =
60555+ gr_search_file(file->f_path.dentry,
60556+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60557+ file->f_path.mnt);
60558+
60559+ if (!gr_tpe_allow(file))
60560+ return 0;
60561+
60562+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60563+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60564+ return 0;
60565+ } else if (unlikely(!(mode & GR_EXEC))) {
60566+ return 0;
60567+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60568+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60569+ return 1;
60570+ }
60571+
60572+ return 1;
60573+}
60574+
60575+int
60576+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60577+{
60578+ __u32 mode;
60579+
60580+ if (unlikely(!file || !(prot & PROT_EXEC)))
60581+ return 1;
60582+
60583+ if (is_writable_mmap(file))
60584+ return 0;
60585+
60586+ mode =
60587+ gr_search_file(file->f_path.dentry,
60588+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60589+ file->f_path.mnt);
60590+
60591+ if (!gr_tpe_allow(file))
60592+ return 0;
60593+
60594+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60595+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60596+ return 0;
60597+ } else if (unlikely(!(mode & GR_EXEC))) {
60598+ return 0;
60599+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60600+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60601+ return 1;
60602+ }
60603+
60604+ return 1;
60605+}
60606+
60607+void
60608+gr_acl_handle_psacct(struct task_struct *task, const long code)
60609+{
60610+ unsigned long runtime;
60611+ unsigned long cputime;
60612+ unsigned int wday, cday;
60613+ __u8 whr, chr;
60614+ __u8 wmin, cmin;
60615+ __u8 wsec, csec;
60616+ struct timespec timeval;
60617+
60618+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
60619+ !(task->acl->mode & GR_PROCACCT)))
60620+ return;
60621+
60622+ do_posix_clock_monotonic_gettime(&timeval);
60623+ runtime = timeval.tv_sec - task->start_time.tv_sec;
60624+ wday = runtime / (3600 * 24);
60625+ runtime -= wday * (3600 * 24);
60626+ whr = runtime / 3600;
60627+ runtime -= whr * 3600;
60628+ wmin = runtime / 60;
60629+ runtime -= wmin * 60;
60630+ wsec = runtime;
60631+
60632+ cputime = (task->utime + task->stime) / HZ;
60633+ cday = cputime / (3600 * 24);
60634+ cputime -= cday * (3600 * 24);
60635+ chr = cputime / 3600;
60636+ cputime -= chr * 3600;
60637+ cmin = cputime / 60;
60638+ cputime -= cmin * 60;
60639+ csec = cputime;
60640+
60641+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
60642+
60643+ return;
60644+}
60645+
60646+void gr_set_kernel_label(struct task_struct *task)
60647+{
60648+ if (gr_status & GR_READY) {
60649+ task->role = kernel_role;
60650+ task->acl = kernel_role->root_label;
60651+ }
60652+ return;
60653+}
60654+
60655+#ifdef CONFIG_TASKSTATS
60656+int gr_is_taskstats_denied(int pid)
60657+{
60658+ struct task_struct *task;
60659+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60660+ const struct cred *cred;
60661+#endif
60662+ int ret = 0;
60663+
60664+ /* restrict taskstats viewing to un-chrooted root users
60665+ who have the 'view' subject flag if the RBAC system is enabled
60666+ */
60667+
60668+ rcu_read_lock();
60669+ read_lock(&tasklist_lock);
60670+ task = find_task_by_vpid(pid);
60671+ if (task) {
60672+#ifdef CONFIG_GRKERNSEC_CHROOT
60673+ if (proc_is_chrooted(task))
60674+ ret = -EACCES;
60675+#endif
60676+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60677+ cred = __task_cred(task);
60678+#ifdef CONFIG_GRKERNSEC_PROC_USER
60679+ if (gr_is_global_nonroot(cred->uid))
60680+ ret = -EACCES;
60681+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60682+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
60683+ ret = -EACCES;
60684+#endif
60685+#endif
60686+ if (gr_status & GR_READY) {
60687+ if (!(task->acl->mode & GR_VIEW))
60688+ ret = -EACCES;
60689+ }
60690+ } else
60691+ ret = -ENOENT;
60692+
60693+ read_unlock(&tasklist_lock);
60694+ rcu_read_unlock();
60695+
60696+ return ret;
60697+}
60698+#endif
60699+
60700+/* AUXV entries are filled via a descendant of search_binary_handler
60701+ after we've already applied the subject for the target
60702+*/
60703+int gr_acl_enable_at_secure(void)
60704+{
60705+ if (unlikely(!(gr_status & GR_READY)))
60706+ return 0;
60707+
60708+ if (current->acl->mode & GR_ATSECURE)
60709+ return 1;
60710+
60711+ return 0;
60712+}
60713+
60714+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
60715+{
60716+ struct task_struct *task = current;
60717+ struct dentry *dentry = file->f_path.dentry;
60718+ struct vfsmount *mnt = file->f_path.mnt;
60719+ struct acl_object_label *obj, *tmp;
60720+ struct acl_subject_label *subj;
60721+ unsigned int bufsize;
60722+ int is_not_root;
60723+ char *path;
60724+ dev_t dev = __get_dev(dentry);
60725+
60726+ if (unlikely(!(gr_status & GR_READY)))
60727+ return 1;
60728+
60729+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60730+ return 1;
60731+
60732+ /* ignore Eric Biederman */
60733+ if (IS_PRIVATE(dentry->d_inode))
60734+ return 1;
60735+
60736+ subj = task->acl;
60737+ read_lock(&gr_inode_lock);
60738+ do {
60739+ obj = lookup_acl_obj_label(ino, dev, subj);
60740+ if (obj != NULL) {
60741+ read_unlock(&gr_inode_lock);
60742+ return (obj->mode & GR_FIND) ? 1 : 0;
60743+ }
60744+ } while ((subj = subj->parent_subject));
60745+ read_unlock(&gr_inode_lock);
60746+
60747+ /* this is purely an optimization since we're looking for an object
60748+ for the directory we're doing a readdir on
60749+ if it's possible for any globbed object to match the entry we're
60750+ filling into the directory, then the object we find here will be
60751+ an anchor point with attached globbed objects
60752+ */
60753+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
60754+ if (obj->globbed == NULL)
60755+ return (obj->mode & GR_FIND) ? 1 : 0;
60756+
60757+ is_not_root = ((obj->filename[0] == '/') &&
60758+ (obj->filename[1] == '\0')) ? 0 : 1;
60759+ bufsize = PAGE_SIZE - namelen - is_not_root;
60760+
60761+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
60762+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
60763+ return 1;
60764+
60765+ preempt_disable();
60766+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
60767+ bufsize);
60768+
60769+ bufsize = strlen(path);
60770+
60771+ /* if base is "/", don't append an additional slash */
60772+ if (is_not_root)
60773+ *(path + bufsize) = '/';
60774+ memcpy(path + bufsize + is_not_root, name, namelen);
60775+ *(path + bufsize + namelen + is_not_root) = '\0';
60776+
60777+ tmp = obj->globbed;
60778+ while (tmp) {
60779+ if (!glob_match(tmp->filename, path)) {
60780+ preempt_enable();
60781+ return (tmp->mode & GR_FIND) ? 1 : 0;
60782+ }
60783+ tmp = tmp->next;
60784+ }
60785+ preempt_enable();
60786+ return (obj->mode & GR_FIND) ? 1 : 0;
60787+}
60788+
60789+void gr_put_exec_file(struct task_struct *task)
60790+{
60791+ struct file *filp;
60792+
60793+ write_lock(&grsec_exec_file_lock);
60794+ filp = task->exec_file;
60795+ task->exec_file = NULL;
60796+ write_unlock(&grsec_exec_file_lock);
60797+
60798+ if (filp)
60799+ fput(filp);
60800+
60801+ return;
60802+}
60803+
60804+
60805+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
60806+EXPORT_SYMBOL(gr_acl_is_enabled);
60807+#endif
60808+EXPORT_SYMBOL(gr_set_kernel_label);
60809+#ifdef CONFIG_SECURITY
60810+EXPORT_SYMBOL(gr_check_user_change);
60811+EXPORT_SYMBOL(gr_check_group_change);
60812+#endif
60813+
60814diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
60815new file mode 100644
60816index 0000000..34fefda
60817--- /dev/null
60818+++ b/grsecurity/gracl_alloc.c
60819@@ -0,0 +1,105 @@
60820+#include <linux/kernel.h>
60821+#include <linux/mm.h>
60822+#include <linux/slab.h>
60823+#include <linux/vmalloc.h>
60824+#include <linux/gracl.h>
60825+#include <linux/grsecurity.h>
60826+
60827+static unsigned long alloc_stack_next = 1;
60828+static unsigned long alloc_stack_size = 1;
60829+static void **alloc_stack;
60830+
60831+static __inline__ int
60832+alloc_pop(void)
60833+{
60834+ if (alloc_stack_next == 1)
60835+ return 0;
60836+
60837+ kfree(alloc_stack[alloc_stack_next - 2]);
60838+
60839+ alloc_stack_next--;
60840+
60841+ return 1;
60842+}
60843+
60844+static __inline__ int
60845+alloc_push(void *buf)
60846+{
60847+ if (alloc_stack_next >= alloc_stack_size)
60848+ return 1;
60849+
60850+ alloc_stack[alloc_stack_next - 1] = buf;
60851+
60852+ alloc_stack_next++;
60853+
60854+ return 0;
60855+}
60856+
60857+void *
60858+acl_alloc(unsigned long len)
60859+{
60860+ void *ret = NULL;
60861+
60862+ if (!len || len > PAGE_SIZE)
60863+ goto out;
60864+
60865+ ret = kmalloc(len, GFP_KERNEL);
60866+
60867+ if (ret) {
60868+ if (alloc_push(ret)) {
60869+ kfree(ret);
60870+ ret = NULL;
60871+ }
60872+ }
60873+
60874+out:
60875+ return ret;
60876+}
60877+
60878+void *
60879+acl_alloc_num(unsigned long num, unsigned long len)
60880+{
60881+ if (!len || (num > (PAGE_SIZE / len)))
60882+ return NULL;
60883+
60884+ return acl_alloc(num * len);
60885+}
60886+
60887+void
60888+acl_free_all(void)
60889+{
60890+ if (gr_acl_is_enabled() || !alloc_stack)
60891+ return;
60892+
60893+ while (alloc_pop()) ;
60894+
60895+ if (alloc_stack) {
60896+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
60897+ kfree(alloc_stack);
60898+ else
60899+ vfree(alloc_stack);
60900+ }
60901+
60902+ alloc_stack = NULL;
60903+ alloc_stack_size = 1;
60904+ alloc_stack_next = 1;
60905+
60906+ return;
60907+}
60908+
60909+int
60910+acl_alloc_stack_init(unsigned long size)
60911+{
60912+ if ((size * sizeof (void *)) <= PAGE_SIZE)
60913+ alloc_stack =
60914+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
60915+ else
60916+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
60917+
60918+ alloc_stack_size = size;
60919+
60920+ if (!alloc_stack)
60921+ return 0;
60922+ else
60923+ return 1;
60924+}
60925diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
60926new file mode 100644
60927index 0000000..bdd51ea
60928--- /dev/null
60929+++ b/grsecurity/gracl_cap.c
60930@@ -0,0 +1,110 @@
60931+#include <linux/kernel.h>
60932+#include <linux/module.h>
60933+#include <linux/sched.h>
60934+#include <linux/gracl.h>
60935+#include <linux/grsecurity.h>
60936+#include <linux/grinternal.h>
60937+
60938+extern const char *captab_log[];
60939+extern int captab_log_entries;
60940+
60941+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60942+{
60943+ struct acl_subject_label *curracl;
60944+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60945+ kernel_cap_t cap_audit = __cap_empty_set;
60946+
60947+ if (!gr_acl_is_enabled())
60948+ return 1;
60949+
60950+ curracl = task->acl;
60951+
60952+ cap_drop = curracl->cap_lower;
60953+ cap_mask = curracl->cap_mask;
60954+ cap_audit = curracl->cap_invert_audit;
60955+
60956+ while ((curracl = curracl->parent_subject)) {
60957+ /* if the cap isn't specified in the current computed mask but is specified in the
60958+ current level subject, and is lowered in the current level subject, then add
60959+ it to the set of dropped capabilities
60960+ otherwise, add the current level subject's mask to the current computed mask
60961+ */
60962+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60963+ cap_raise(cap_mask, cap);
60964+ if (cap_raised(curracl->cap_lower, cap))
60965+ cap_raise(cap_drop, cap);
60966+ if (cap_raised(curracl->cap_invert_audit, cap))
60967+ cap_raise(cap_audit, cap);
60968+ }
60969+ }
60970+
60971+ if (!cap_raised(cap_drop, cap)) {
60972+ if (cap_raised(cap_audit, cap))
60973+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
60974+ return 1;
60975+ }
60976+
60977+ curracl = task->acl;
60978+
60979+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
60980+ && cap_raised(cred->cap_effective, cap)) {
60981+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60982+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
60983+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
60984+ gr_to_filename(task->exec_file->f_path.dentry,
60985+ task->exec_file->f_path.mnt) : curracl->filename,
60986+ curracl->filename, 0UL,
60987+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
60988+ return 1;
60989+ }
60990+
60991+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
60992+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
60993+
60994+ return 0;
60995+}
60996+
60997+int
60998+gr_acl_is_capable(const int cap)
60999+{
61000+ return gr_task_acl_is_capable(current, current_cred(), cap);
61001+}
61002+
61003+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61004+{
61005+ struct acl_subject_label *curracl;
61006+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61007+
61008+ if (!gr_acl_is_enabled())
61009+ return 1;
61010+
61011+ curracl = task->acl;
61012+
61013+ cap_drop = curracl->cap_lower;
61014+ cap_mask = curracl->cap_mask;
61015+
61016+ while ((curracl = curracl->parent_subject)) {
61017+ /* if the cap isn't specified in the current computed mask but is specified in the
61018+ current level subject, and is lowered in the current level subject, then add
61019+ it to the set of dropped capabilities
61020+ otherwise, add the current level subject's mask to the current computed mask
61021+ */
61022+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61023+ cap_raise(cap_mask, cap);
61024+ if (cap_raised(curracl->cap_lower, cap))
61025+ cap_raise(cap_drop, cap);
61026+ }
61027+ }
61028+
61029+ if (!cap_raised(cap_drop, cap))
61030+ return 1;
61031+
61032+ return 0;
61033+}
61034+
61035+int
61036+gr_acl_is_capable_nolog(const int cap)
61037+{
61038+ return gr_task_acl_is_capable_nolog(current, cap);
61039+}
61040+
61041diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61042new file mode 100644
61043index 0000000..a340c17
61044--- /dev/null
61045+++ b/grsecurity/gracl_fs.c
61046@@ -0,0 +1,431 @@
61047+#include <linux/kernel.h>
61048+#include <linux/sched.h>
61049+#include <linux/types.h>
61050+#include <linux/fs.h>
61051+#include <linux/file.h>
61052+#include <linux/stat.h>
61053+#include <linux/grsecurity.h>
61054+#include <linux/grinternal.h>
61055+#include <linux/gracl.h>
61056+
61057+umode_t
61058+gr_acl_umask(void)
61059+{
61060+ if (unlikely(!gr_acl_is_enabled()))
61061+ return 0;
61062+
61063+ return current->role->umask;
61064+}
61065+
61066+__u32
61067+gr_acl_handle_hidden_file(const struct dentry * dentry,
61068+ const struct vfsmount * mnt)
61069+{
61070+ __u32 mode;
61071+
61072+ if (unlikely(!dentry->d_inode))
61073+ return GR_FIND;
61074+
61075+ mode =
61076+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61077+
61078+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61079+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61080+ return mode;
61081+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61082+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61083+ return 0;
61084+ } else if (unlikely(!(mode & GR_FIND)))
61085+ return 0;
61086+
61087+ return GR_FIND;
61088+}
61089+
61090+__u32
61091+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61092+ int acc_mode)
61093+{
61094+ __u32 reqmode = GR_FIND;
61095+ __u32 mode;
61096+
61097+ if (unlikely(!dentry->d_inode))
61098+ return reqmode;
61099+
61100+ if (acc_mode & MAY_APPEND)
61101+ reqmode |= GR_APPEND;
61102+ else if (acc_mode & MAY_WRITE)
61103+ reqmode |= GR_WRITE;
61104+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61105+ reqmode |= GR_READ;
61106+
61107+ mode =
61108+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61109+ mnt);
61110+
61111+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61112+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61113+ reqmode & GR_READ ? " reading" : "",
61114+ reqmode & GR_WRITE ? " writing" : reqmode &
61115+ GR_APPEND ? " appending" : "");
61116+ return reqmode;
61117+ } else
61118+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61119+ {
61120+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61121+ reqmode & GR_READ ? " reading" : "",
61122+ reqmode & GR_WRITE ? " writing" : reqmode &
61123+ GR_APPEND ? " appending" : "");
61124+ return 0;
61125+ } else if (unlikely((mode & reqmode) != reqmode))
61126+ return 0;
61127+
61128+ return reqmode;
61129+}
61130+
61131+__u32
61132+gr_acl_handle_creat(const struct dentry * dentry,
61133+ const struct dentry * p_dentry,
61134+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61135+ const int imode)
61136+{
61137+ __u32 reqmode = GR_WRITE | GR_CREATE;
61138+ __u32 mode;
61139+
61140+ if (acc_mode & MAY_APPEND)
61141+ reqmode |= GR_APPEND;
61142+ // if a directory was required or the directory already exists, then
61143+ // don't count this open as a read
61144+ if ((acc_mode & MAY_READ) &&
61145+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61146+ reqmode |= GR_READ;
61147+ if ((open_flags & O_CREAT) &&
61148+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61149+ reqmode |= GR_SETID;
61150+
61151+ mode =
61152+ gr_check_create(dentry, p_dentry, p_mnt,
61153+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61154+
61155+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61156+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61157+ reqmode & GR_READ ? " reading" : "",
61158+ reqmode & GR_WRITE ? " writing" : reqmode &
61159+ GR_APPEND ? " appending" : "");
61160+ return reqmode;
61161+ } else
61162+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61163+ {
61164+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61165+ reqmode & GR_READ ? " reading" : "",
61166+ reqmode & GR_WRITE ? " writing" : reqmode &
61167+ GR_APPEND ? " appending" : "");
61168+ return 0;
61169+ } else if (unlikely((mode & reqmode) != reqmode))
61170+ return 0;
61171+
61172+ return reqmode;
61173+}
61174+
61175+__u32
61176+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61177+ const int fmode)
61178+{
61179+ __u32 mode, reqmode = GR_FIND;
61180+
61181+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61182+ reqmode |= GR_EXEC;
61183+ if (fmode & S_IWOTH)
61184+ reqmode |= GR_WRITE;
61185+ if (fmode & S_IROTH)
61186+ reqmode |= GR_READ;
61187+
61188+ mode =
61189+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61190+ mnt);
61191+
61192+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61193+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61194+ reqmode & GR_READ ? " reading" : "",
61195+ reqmode & GR_WRITE ? " writing" : "",
61196+ reqmode & GR_EXEC ? " executing" : "");
61197+ return reqmode;
61198+ } else
61199+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61200+ {
61201+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61202+ reqmode & GR_READ ? " reading" : "",
61203+ reqmode & GR_WRITE ? " writing" : "",
61204+ reqmode & GR_EXEC ? " executing" : "");
61205+ return 0;
61206+ } else if (unlikely((mode & reqmode) != reqmode))
61207+ return 0;
61208+
61209+ return reqmode;
61210+}
61211+
61212+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61213+{
61214+ __u32 mode;
61215+
61216+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61217+
61218+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61219+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61220+ return mode;
61221+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61222+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61223+ return 0;
61224+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61225+ return 0;
61226+
61227+ return (reqmode);
61228+}
61229+
61230+__u32
61231+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61232+{
61233+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61234+}
61235+
61236+__u32
61237+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61238+{
61239+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61240+}
61241+
61242+__u32
61243+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61244+{
61245+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61246+}
61247+
61248+__u32
61249+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61250+{
61251+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61252+}
61253+
61254+__u32
61255+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61256+ umode_t *modeptr)
61257+{
61258+ umode_t mode;
61259+
61260+ *modeptr &= ~gr_acl_umask();
61261+ mode = *modeptr;
61262+
61263+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61264+ return 1;
61265+
61266+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61267+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61268+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61269+ GR_CHMOD_ACL_MSG);
61270+ } else {
61271+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61272+ }
61273+}
61274+
61275+__u32
61276+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61277+{
61278+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61279+}
61280+
61281+__u32
61282+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61283+{
61284+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61285+}
61286+
61287+__u32
61288+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61289+{
61290+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61291+}
61292+
61293+__u32
61294+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61295+{
61296+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61297+ GR_UNIXCONNECT_ACL_MSG);
61298+}
61299+
61300+/* hardlinks require at minimum create and link permission,
61301+ any additional privilege required is based on the
61302+ privilege of the file being linked to
61303+*/
61304+__u32
61305+gr_acl_handle_link(const struct dentry * new_dentry,
61306+ const struct dentry * parent_dentry,
61307+ const struct vfsmount * parent_mnt,
61308+ const struct dentry * old_dentry,
61309+ const struct vfsmount * old_mnt, const struct filename *to)
61310+{
61311+ __u32 mode;
61312+ __u32 needmode = GR_CREATE | GR_LINK;
61313+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61314+
61315+ mode =
61316+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61317+ old_mnt);
61318+
61319+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61320+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61321+ return mode;
61322+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61323+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61324+ return 0;
61325+ } else if (unlikely((mode & needmode) != needmode))
61326+ return 0;
61327+
61328+ return 1;
61329+}
61330+
61331+__u32
61332+gr_acl_handle_symlink(const struct dentry * new_dentry,
61333+ const struct dentry * parent_dentry,
61334+ const struct vfsmount * parent_mnt, const struct filename *from)
61335+{
61336+ __u32 needmode = GR_WRITE | GR_CREATE;
61337+ __u32 mode;
61338+
61339+ mode =
61340+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
61341+ GR_CREATE | GR_AUDIT_CREATE |
61342+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61343+
61344+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61345+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61346+ return mode;
61347+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61348+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61349+ return 0;
61350+ } else if (unlikely((mode & needmode) != needmode))
61351+ return 0;
61352+
61353+ return (GR_WRITE | GR_CREATE);
61354+}
61355+
61356+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)
61357+{
61358+ __u32 mode;
61359+
61360+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61361+
61362+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61363+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61364+ return mode;
61365+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61366+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61367+ return 0;
61368+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
61369+ return 0;
61370+
61371+ return (reqmode);
61372+}
61373+
61374+__u32
61375+gr_acl_handle_mknod(const struct dentry * new_dentry,
61376+ const struct dentry * parent_dentry,
61377+ const struct vfsmount * parent_mnt,
61378+ const int mode)
61379+{
61380+ __u32 reqmode = GR_WRITE | GR_CREATE;
61381+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61382+ reqmode |= GR_SETID;
61383+
61384+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61385+ reqmode, GR_MKNOD_ACL_MSG);
61386+}
61387+
61388+__u32
61389+gr_acl_handle_mkdir(const struct dentry *new_dentry,
61390+ const struct dentry *parent_dentry,
61391+ const struct vfsmount *parent_mnt)
61392+{
61393+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61394+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61395+}
61396+
61397+#define RENAME_CHECK_SUCCESS(old, new) \
61398+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61399+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61400+
61401+int
61402+gr_acl_handle_rename(struct dentry *new_dentry,
61403+ struct dentry *parent_dentry,
61404+ const struct vfsmount *parent_mnt,
61405+ struct dentry *old_dentry,
61406+ struct inode *old_parent_inode,
61407+ struct vfsmount *old_mnt, const struct filename *newname)
61408+{
61409+ __u32 comp1, comp2;
61410+ int error = 0;
61411+
61412+ if (unlikely(!gr_acl_is_enabled()))
61413+ return 0;
61414+
61415+ if (!new_dentry->d_inode) {
61416+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61417+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61418+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61419+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61420+ GR_DELETE | GR_AUDIT_DELETE |
61421+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61422+ GR_SUPPRESS, old_mnt);
61423+ } else {
61424+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61425+ GR_CREATE | GR_DELETE |
61426+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61427+ GR_AUDIT_READ | GR_AUDIT_WRITE |
61428+ GR_SUPPRESS, parent_mnt);
61429+ comp2 =
61430+ gr_search_file(old_dentry,
61431+ GR_READ | GR_WRITE | GR_AUDIT_READ |
61432+ GR_DELETE | GR_AUDIT_DELETE |
61433+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61434+ }
61435+
61436+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61437+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61438+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61439+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61440+ && !(comp2 & GR_SUPPRESS)) {
61441+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61442+ error = -EACCES;
61443+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61444+ error = -EACCES;
61445+
61446+ return error;
61447+}
61448+
61449+void
61450+gr_acl_handle_exit(void)
61451+{
61452+ u16 id;
61453+ char *rolename;
61454+
61455+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61456+ !(current->role->roletype & GR_ROLE_PERSIST))) {
61457+ id = current->acl_role_id;
61458+ rolename = current->role->rolename;
61459+ gr_set_acls(1);
61460+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61461+ }
61462+
61463+ gr_put_exec_file(current);
61464+ return;
61465+}
61466+
61467+int
61468+gr_acl_handle_procpidmem(const struct task_struct *task)
61469+{
61470+ if (unlikely(!gr_acl_is_enabled()))
61471+ return 0;
61472+
61473+ if (task != current && task->acl->mode & GR_PROTPROCFD)
61474+ return -EACCES;
61475+
61476+ return 0;
61477+}
61478diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61479new file mode 100644
61480index 0000000..4699807
61481--- /dev/null
61482+++ b/grsecurity/gracl_ip.c
61483@@ -0,0 +1,384 @@
61484+#include <linux/kernel.h>
61485+#include <asm/uaccess.h>
61486+#include <asm/errno.h>
61487+#include <net/sock.h>
61488+#include <linux/file.h>
61489+#include <linux/fs.h>
61490+#include <linux/net.h>
61491+#include <linux/in.h>
61492+#include <linux/skbuff.h>
61493+#include <linux/ip.h>
61494+#include <linux/udp.h>
61495+#include <linux/types.h>
61496+#include <linux/sched.h>
61497+#include <linux/netdevice.h>
61498+#include <linux/inetdevice.h>
61499+#include <linux/gracl.h>
61500+#include <linux/grsecurity.h>
61501+#include <linux/grinternal.h>
61502+
61503+#define GR_BIND 0x01
61504+#define GR_CONNECT 0x02
61505+#define GR_INVERT 0x04
61506+#define GR_BINDOVERRIDE 0x08
61507+#define GR_CONNECTOVERRIDE 0x10
61508+#define GR_SOCK_FAMILY 0x20
61509+
61510+static const char * gr_protocols[IPPROTO_MAX] = {
61511+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61512+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61513+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61514+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61515+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61516+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61517+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61518+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61519+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61520+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61521+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61522+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61523+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61524+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61525+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61526+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61527+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61528+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61529+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61530+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61531+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61532+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61533+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61534+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61535+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61536+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61537+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61538+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61539+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61540+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61541+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61542+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61543+ };
61544+
61545+static const char * gr_socktypes[SOCK_MAX] = {
61546+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
61547+ "unknown:7", "unknown:8", "unknown:9", "packet"
61548+ };
61549+
61550+static const char * gr_sockfamilies[AF_MAX+1] = {
61551+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
61552+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
61553+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
61554+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
61555+ };
61556+
61557+const char *
61558+gr_proto_to_name(unsigned char proto)
61559+{
61560+ return gr_protocols[proto];
61561+}
61562+
61563+const char *
61564+gr_socktype_to_name(unsigned char type)
61565+{
61566+ return gr_socktypes[type];
61567+}
61568+
61569+const char *
61570+gr_sockfamily_to_name(unsigned char family)
61571+{
61572+ return gr_sockfamilies[family];
61573+}
61574+
61575+int
61576+gr_search_socket(const int domain, const int type, const int protocol)
61577+{
61578+ struct acl_subject_label *curr;
61579+ const struct cred *cred = current_cred();
61580+
61581+ if (unlikely(!gr_acl_is_enabled()))
61582+ goto exit;
61583+
61584+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
61585+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
61586+ goto exit; // let the kernel handle it
61587+
61588+ curr = current->acl;
61589+
61590+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
61591+ /* the family is allowed, if this is PF_INET allow it only if
61592+ the extra sock type/protocol checks pass */
61593+ if (domain == PF_INET)
61594+ goto inet_check;
61595+ goto exit;
61596+ } else {
61597+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61598+ __u32 fakeip = 0;
61599+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61600+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
61601+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
61602+ gr_to_filename(current->exec_file->f_path.dentry,
61603+ current->exec_file->f_path.mnt) :
61604+ curr->filename, curr->filename,
61605+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
61606+ &current->signal->saved_ip);
61607+ goto exit;
61608+ }
61609+ goto exit_fail;
61610+ }
61611+
61612+inet_check:
61613+ /* the rest of this checking is for IPv4 only */
61614+ if (!curr->ips)
61615+ goto exit;
61616+
61617+ if ((curr->ip_type & (1 << type)) &&
61618+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
61619+ goto exit;
61620+
61621+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61622+ /* we don't place acls on raw sockets , and sometimes
61623+ dgram/ip sockets are opened for ioctl and not
61624+ bind/connect, so we'll fake a bind learn log */
61625+ if (type == SOCK_RAW || type == SOCK_PACKET) {
61626+ __u32 fakeip = 0;
61627+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61628+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
61629+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
61630+ gr_to_filename(current->exec_file->f_path.dentry,
61631+ current->exec_file->f_path.mnt) :
61632+ curr->filename, curr->filename,
61633+ &fakeip, 0, type,
61634+ protocol, GR_CONNECT, &current->signal->saved_ip);
61635+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
61636+ __u32 fakeip = 0;
61637+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61638+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
61639+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
61640+ gr_to_filename(current->exec_file->f_path.dentry,
61641+ current->exec_file->f_path.mnt) :
61642+ curr->filename, curr->filename,
61643+ &fakeip, 0, type,
61644+ protocol, GR_BIND, &current->signal->saved_ip);
61645+ }
61646+ /* we'll log when they use connect or bind */
61647+ goto exit;
61648+ }
61649+
61650+exit_fail:
61651+ if (domain == PF_INET)
61652+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
61653+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
61654+ else
61655+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
61656+ gr_socktype_to_name(type), protocol);
61657+
61658+ return 0;
61659+exit:
61660+ return 1;
61661+}
61662+
61663+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)
61664+{
61665+ if ((ip->mode & mode) &&
61666+ (ip_port >= ip->low) &&
61667+ (ip_port <= ip->high) &&
61668+ ((ntohl(ip_addr) & our_netmask) ==
61669+ (ntohl(our_addr) & our_netmask))
61670+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
61671+ && (ip->type & (1 << type))) {
61672+ if (ip->mode & GR_INVERT)
61673+ return 2; // specifically denied
61674+ else
61675+ return 1; // allowed
61676+ }
61677+
61678+ return 0; // not specifically allowed, may continue parsing
61679+}
61680+
61681+static int
61682+gr_search_connectbind(const int full_mode, struct sock *sk,
61683+ struct sockaddr_in *addr, const int type)
61684+{
61685+ char iface[IFNAMSIZ] = {0};
61686+ struct acl_subject_label *curr;
61687+ struct acl_ip_label *ip;
61688+ struct inet_sock *isk;
61689+ struct net_device *dev;
61690+ struct in_device *idev;
61691+ unsigned long i;
61692+ int ret;
61693+ int mode = full_mode & (GR_BIND | GR_CONNECT);
61694+ __u32 ip_addr = 0;
61695+ __u32 our_addr;
61696+ __u32 our_netmask;
61697+ char *p;
61698+ __u16 ip_port = 0;
61699+ const struct cred *cred = current_cred();
61700+
61701+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
61702+ return 0;
61703+
61704+ curr = current->acl;
61705+ isk = inet_sk(sk);
61706+
61707+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
61708+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
61709+ addr->sin_addr.s_addr = curr->inaddr_any_override;
61710+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
61711+ struct sockaddr_in saddr;
61712+ int err;
61713+
61714+ saddr.sin_family = AF_INET;
61715+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
61716+ saddr.sin_port = isk->inet_sport;
61717+
61718+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61719+ if (err)
61720+ return err;
61721+
61722+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61723+ if (err)
61724+ return err;
61725+ }
61726+
61727+ if (!curr->ips)
61728+ return 0;
61729+
61730+ ip_addr = addr->sin_addr.s_addr;
61731+ ip_port = ntohs(addr->sin_port);
61732+
61733+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61734+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61735+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
61736+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
61737+ gr_to_filename(current->exec_file->f_path.dentry,
61738+ current->exec_file->f_path.mnt) :
61739+ curr->filename, curr->filename,
61740+ &ip_addr, ip_port, type,
61741+ sk->sk_protocol, mode, &current->signal->saved_ip);
61742+ return 0;
61743+ }
61744+
61745+ for (i = 0; i < curr->ip_num; i++) {
61746+ ip = *(curr->ips + i);
61747+ if (ip->iface != NULL) {
61748+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
61749+ p = strchr(iface, ':');
61750+ if (p != NULL)
61751+ *p = '\0';
61752+ dev = dev_get_by_name(sock_net(sk), iface);
61753+ if (dev == NULL)
61754+ continue;
61755+ idev = in_dev_get(dev);
61756+ if (idev == NULL) {
61757+ dev_put(dev);
61758+ continue;
61759+ }
61760+ rcu_read_lock();
61761+ for_ifa(idev) {
61762+ if (!strcmp(ip->iface, ifa->ifa_label)) {
61763+ our_addr = ifa->ifa_address;
61764+ our_netmask = 0xffffffff;
61765+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61766+ if (ret == 1) {
61767+ rcu_read_unlock();
61768+ in_dev_put(idev);
61769+ dev_put(dev);
61770+ return 0;
61771+ } else if (ret == 2) {
61772+ rcu_read_unlock();
61773+ in_dev_put(idev);
61774+ dev_put(dev);
61775+ goto denied;
61776+ }
61777+ }
61778+ } endfor_ifa(idev);
61779+ rcu_read_unlock();
61780+ in_dev_put(idev);
61781+ dev_put(dev);
61782+ } else {
61783+ our_addr = ip->addr;
61784+ our_netmask = ip->netmask;
61785+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61786+ if (ret == 1)
61787+ return 0;
61788+ else if (ret == 2)
61789+ goto denied;
61790+ }
61791+ }
61792+
61793+denied:
61794+ if (mode == GR_BIND)
61795+ 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));
61796+ else if (mode == GR_CONNECT)
61797+ 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));
61798+
61799+ return -EACCES;
61800+}
61801+
61802+int
61803+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
61804+{
61805+ /* always allow disconnection of dgram sockets with connect */
61806+ if (addr->sin_family == AF_UNSPEC)
61807+ return 0;
61808+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
61809+}
61810+
61811+int
61812+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
61813+{
61814+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
61815+}
61816+
61817+int gr_search_listen(struct socket *sock)
61818+{
61819+ struct sock *sk = sock->sk;
61820+ struct sockaddr_in addr;
61821+
61822+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61823+ addr.sin_port = inet_sk(sk)->inet_sport;
61824+
61825+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61826+}
61827+
61828+int gr_search_accept(struct socket *sock)
61829+{
61830+ struct sock *sk = sock->sk;
61831+ struct sockaddr_in addr;
61832+
61833+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61834+ addr.sin_port = inet_sk(sk)->inet_sport;
61835+
61836+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61837+}
61838+
61839+int
61840+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
61841+{
61842+ if (addr)
61843+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
61844+ else {
61845+ struct sockaddr_in sin;
61846+ const struct inet_sock *inet = inet_sk(sk);
61847+
61848+ sin.sin_addr.s_addr = inet->inet_daddr;
61849+ sin.sin_port = inet->inet_dport;
61850+
61851+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61852+ }
61853+}
61854+
61855+int
61856+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
61857+{
61858+ struct sockaddr_in sin;
61859+
61860+ if (unlikely(skb->len < sizeof (struct udphdr)))
61861+ return 0; // skip this packet
61862+
61863+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
61864+ sin.sin_port = udp_hdr(skb)->source;
61865+
61866+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61867+}
61868diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
61869new file mode 100644
61870index 0000000..25f54ef
61871--- /dev/null
61872+++ b/grsecurity/gracl_learn.c
61873@@ -0,0 +1,207 @@
61874+#include <linux/kernel.h>
61875+#include <linux/mm.h>
61876+#include <linux/sched.h>
61877+#include <linux/poll.h>
61878+#include <linux/string.h>
61879+#include <linux/file.h>
61880+#include <linux/types.h>
61881+#include <linux/vmalloc.h>
61882+#include <linux/grinternal.h>
61883+
61884+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
61885+ size_t count, loff_t *ppos);
61886+extern int gr_acl_is_enabled(void);
61887+
61888+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
61889+static int gr_learn_attached;
61890+
61891+/* use a 512k buffer */
61892+#define LEARN_BUFFER_SIZE (512 * 1024)
61893+
61894+static DEFINE_SPINLOCK(gr_learn_lock);
61895+static DEFINE_MUTEX(gr_learn_user_mutex);
61896+
61897+/* we need to maintain two buffers, so that the kernel context of grlearn
61898+ uses a semaphore around the userspace copying, and the other kernel contexts
61899+ use a spinlock when copying into the buffer, since they cannot sleep
61900+*/
61901+static char *learn_buffer;
61902+static char *learn_buffer_user;
61903+static int learn_buffer_len;
61904+static int learn_buffer_user_len;
61905+
61906+static ssize_t
61907+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
61908+{
61909+ DECLARE_WAITQUEUE(wait, current);
61910+ ssize_t retval = 0;
61911+
61912+ add_wait_queue(&learn_wait, &wait);
61913+ set_current_state(TASK_INTERRUPTIBLE);
61914+ do {
61915+ mutex_lock(&gr_learn_user_mutex);
61916+ spin_lock(&gr_learn_lock);
61917+ if (learn_buffer_len)
61918+ break;
61919+ spin_unlock(&gr_learn_lock);
61920+ mutex_unlock(&gr_learn_user_mutex);
61921+ if (file->f_flags & O_NONBLOCK) {
61922+ retval = -EAGAIN;
61923+ goto out;
61924+ }
61925+ if (signal_pending(current)) {
61926+ retval = -ERESTARTSYS;
61927+ goto out;
61928+ }
61929+
61930+ schedule();
61931+ } while (1);
61932+
61933+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
61934+ learn_buffer_user_len = learn_buffer_len;
61935+ retval = learn_buffer_len;
61936+ learn_buffer_len = 0;
61937+
61938+ spin_unlock(&gr_learn_lock);
61939+
61940+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
61941+ retval = -EFAULT;
61942+
61943+ mutex_unlock(&gr_learn_user_mutex);
61944+out:
61945+ set_current_state(TASK_RUNNING);
61946+ remove_wait_queue(&learn_wait, &wait);
61947+ return retval;
61948+}
61949+
61950+static unsigned int
61951+poll_learn(struct file * file, poll_table * wait)
61952+{
61953+ poll_wait(file, &learn_wait, wait);
61954+
61955+ if (learn_buffer_len)
61956+ return (POLLIN | POLLRDNORM);
61957+
61958+ return 0;
61959+}
61960+
61961+void
61962+gr_clear_learn_entries(void)
61963+{
61964+ char *tmp;
61965+
61966+ mutex_lock(&gr_learn_user_mutex);
61967+ spin_lock(&gr_learn_lock);
61968+ tmp = learn_buffer;
61969+ learn_buffer = NULL;
61970+ spin_unlock(&gr_learn_lock);
61971+ if (tmp)
61972+ vfree(tmp);
61973+ if (learn_buffer_user != NULL) {
61974+ vfree(learn_buffer_user);
61975+ learn_buffer_user = NULL;
61976+ }
61977+ learn_buffer_len = 0;
61978+ mutex_unlock(&gr_learn_user_mutex);
61979+
61980+ return;
61981+}
61982+
61983+void
61984+gr_add_learn_entry(const char *fmt, ...)
61985+{
61986+ va_list args;
61987+ unsigned int len;
61988+
61989+ if (!gr_learn_attached)
61990+ return;
61991+
61992+ spin_lock(&gr_learn_lock);
61993+
61994+ /* leave a gap at the end so we know when it's "full" but don't have to
61995+ compute the exact length of the string we're trying to append
61996+ */
61997+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
61998+ spin_unlock(&gr_learn_lock);
61999+ wake_up_interruptible(&learn_wait);
62000+ return;
62001+ }
62002+ if (learn_buffer == NULL) {
62003+ spin_unlock(&gr_learn_lock);
62004+ return;
62005+ }
62006+
62007+ va_start(args, fmt);
62008+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62009+ va_end(args);
62010+
62011+ learn_buffer_len += len + 1;
62012+
62013+ spin_unlock(&gr_learn_lock);
62014+ wake_up_interruptible(&learn_wait);
62015+
62016+ return;
62017+}
62018+
62019+static int
62020+open_learn(struct inode *inode, struct file *file)
62021+{
62022+ if (file->f_mode & FMODE_READ && gr_learn_attached)
62023+ return -EBUSY;
62024+ if (file->f_mode & FMODE_READ) {
62025+ int retval = 0;
62026+ mutex_lock(&gr_learn_user_mutex);
62027+ if (learn_buffer == NULL)
62028+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62029+ if (learn_buffer_user == NULL)
62030+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62031+ if (learn_buffer == NULL) {
62032+ retval = -ENOMEM;
62033+ goto out_error;
62034+ }
62035+ if (learn_buffer_user == NULL) {
62036+ retval = -ENOMEM;
62037+ goto out_error;
62038+ }
62039+ learn_buffer_len = 0;
62040+ learn_buffer_user_len = 0;
62041+ gr_learn_attached = 1;
62042+out_error:
62043+ mutex_unlock(&gr_learn_user_mutex);
62044+ return retval;
62045+ }
62046+ return 0;
62047+}
62048+
62049+static int
62050+close_learn(struct inode *inode, struct file *file)
62051+{
62052+ if (file->f_mode & FMODE_READ) {
62053+ char *tmp = NULL;
62054+ mutex_lock(&gr_learn_user_mutex);
62055+ spin_lock(&gr_learn_lock);
62056+ tmp = learn_buffer;
62057+ learn_buffer = NULL;
62058+ spin_unlock(&gr_learn_lock);
62059+ if (tmp)
62060+ vfree(tmp);
62061+ if (learn_buffer_user != NULL) {
62062+ vfree(learn_buffer_user);
62063+ learn_buffer_user = NULL;
62064+ }
62065+ learn_buffer_len = 0;
62066+ learn_buffer_user_len = 0;
62067+ gr_learn_attached = 0;
62068+ mutex_unlock(&gr_learn_user_mutex);
62069+ }
62070+
62071+ return 0;
62072+}
62073+
62074+const struct file_operations grsec_fops = {
62075+ .read = read_learn,
62076+ .write = write_grsec_handler,
62077+ .open = open_learn,
62078+ .release = close_learn,
62079+ .poll = poll_learn,
62080+};
62081diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62082new file mode 100644
62083index 0000000..39645c9
62084--- /dev/null
62085+++ b/grsecurity/gracl_res.c
62086@@ -0,0 +1,68 @@
62087+#include <linux/kernel.h>
62088+#include <linux/sched.h>
62089+#include <linux/gracl.h>
62090+#include <linux/grinternal.h>
62091+
62092+static const char *restab_log[] = {
62093+ [RLIMIT_CPU] = "RLIMIT_CPU",
62094+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62095+ [RLIMIT_DATA] = "RLIMIT_DATA",
62096+ [RLIMIT_STACK] = "RLIMIT_STACK",
62097+ [RLIMIT_CORE] = "RLIMIT_CORE",
62098+ [RLIMIT_RSS] = "RLIMIT_RSS",
62099+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
62100+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62101+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62102+ [RLIMIT_AS] = "RLIMIT_AS",
62103+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62104+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62105+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62106+ [RLIMIT_NICE] = "RLIMIT_NICE",
62107+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62108+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62109+ [GR_CRASH_RES] = "RLIMIT_CRASH"
62110+};
62111+
62112+void
62113+gr_log_resource(const struct task_struct *task,
62114+ const int res, const unsigned long wanted, const int gt)
62115+{
62116+ const struct cred *cred;
62117+ unsigned long rlim;
62118+
62119+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
62120+ return;
62121+
62122+ // not yet supported resource
62123+ if (unlikely(!restab_log[res]))
62124+ return;
62125+
62126+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62127+ rlim = task_rlimit_max(task, res);
62128+ else
62129+ rlim = task_rlimit(task, res);
62130+
62131+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62132+ return;
62133+
62134+ rcu_read_lock();
62135+ cred = __task_cred(task);
62136+
62137+ if (res == RLIMIT_NPROC &&
62138+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62139+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62140+ goto out_rcu_unlock;
62141+ else if (res == RLIMIT_MEMLOCK &&
62142+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62143+ goto out_rcu_unlock;
62144+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62145+ goto out_rcu_unlock;
62146+ rcu_read_unlock();
62147+
62148+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62149+
62150+ return;
62151+out_rcu_unlock:
62152+ rcu_read_unlock();
62153+ return;
62154+}
62155diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62156new file mode 100644
62157index 0000000..8c8fc9d
62158--- /dev/null
62159+++ b/grsecurity/gracl_segv.c
62160@@ -0,0 +1,303 @@
62161+#include <linux/kernel.h>
62162+#include <linux/mm.h>
62163+#include <asm/uaccess.h>
62164+#include <asm/errno.h>
62165+#include <asm/mman.h>
62166+#include <net/sock.h>
62167+#include <linux/file.h>
62168+#include <linux/fs.h>
62169+#include <linux/net.h>
62170+#include <linux/in.h>
62171+#include <linux/slab.h>
62172+#include <linux/types.h>
62173+#include <linux/sched.h>
62174+#include <linux/timer.h>
62175+#include <linux/gracl.h>
62176+#include <linux/grsecurity.h>
62177+#include <linux/grinternal.h>
62178+
62179+static struct crash_uid *uid_set;
62180+static unsigned short uid_used;
62181+static DEFINE_SPINLOCK(gr_uid_lock);
62182+extern rwlock_t gr_inode_lock;
62183+extern struct acl_subject_label *
62184+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62185+ struct acl_role_label *role);
62186+
62187+#ifdef CONFIG_BTRFS_FS
62188+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62189+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62190+#endif
62191+
62192+static inline dev_t __get_dev(const struct dentry *dentry)
62193+{
62194+#ifdef CONFIG_BTRFS_FS
62195+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62196+ return get_btrfs_dev_from_inode(dentry->d_inode);
62197+ else
62198+#endif
62199+ return dentry->d_inode->i_sb->s_dev;
62200+}
62201+
62202+int
62203+gr_init_uidset(void)
62204+{
62205+ uid_set =
62206+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62207+ uid_used = 0;
62208+
62209+ return uid_set ? 1 : 0;
62210+}
62211+
62212+void
62213+gr_free_uidset(void)
62214+{
62215+ if (uid_set)
62216+ kfree(uid_set);
62217+
62218+ return;
62219+}
62220+
62221+int
62222+gr_find_uid(const uid_t uid)
62223+{
62224+ struct crash_uid *tmp = uid_set;
62225+ uid_t buid;
62226+ int low = 0, high = uid_used - 1, mid;
62227+
62228+ while (high >= low) {
62229+ mid = (low + high) >> 1;
62230+ buid = tmp[mid].uid;
62231+ if (buid == uid)
62232+ return mid;
62233+ if (buid > uid)
62234+ high = mid - 1;
62235+ if (buid < uid)
62236+ low = mid + 1;
62237+ }
62238+
62239+ return -1;
62240+}
62241+
62242+static __inline__ void
62243+gr_insertsort(void)
62244+{
62245+ unsigned short i, j;
62246+ struct crash_uid index;
62247+
62248+ for (i = 1; i < uid_used; i++) {
62249+ index = uid_set[i];
62250+ j = i;
62251+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62252+ uid_set[j] = uid_set[j - 1];
62253+ j--;
62254+ }
62255+ uid_set[j] = index;
62256+ }
62257+
62258+ return;
62259+}
62260+
62261+static __inline__ void
62262+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62263+{
62264+ int loc;
62265+ uid_t uid = GR_GLOBAL_UID(kuid);
62266+
62267+ if (uid_used == GR_UIDTABLE_MAX)
62268+ return;
62269+
62270+ loc = gr_find_uid(uid);
62271+
62272+ if (loc >= 0) {
62273+ uid_set[loc].expires = expires;
62274+ return;
62275+ }
62276+
62277+ uid_set[uid_used].uid = uid;
62278+ uid_set[uid_used].expires = expires;
62279+ uid_used++;
62280+
62281+ gr_insertsort();
62282+
62283+ return;
62284+}
62285+
62286+void
62287+gr_remove_uid(const unsigned short loc)
62288+{
62289+ unsigned short i;
62290+
62291+ for (i = loc + 1; i < uid_used; i++)
62292+ uid_set[i - 1] = uid_set[i];
62293+
62294+ uid_used--;
62295+
62296+ return;
62297+}
62298+
62299+int
62300+gr_check_crash_uid(const kuid_t kuid)
62301+{
62302+ int loc;
62303+ int ret = 0;
62304+ uid_t uid;
62305+
62306+ if (unlikely(!gr_acl_is_enabled()))
62307+ return 0;
62308+
62309+ uid = GR_GLOBAL_UID(kuid);
62310+
62311+ spin_lock(&gr_uid_lock);
62312+ loc = gr_find_uid(uid);
62313+
62314+ if (loc < 0)
62315+ goto out_unlock;
62316+
62317+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
62318+ gr_remove_uid(loc);
62319+ else
62320+ ret = 1;
62321+
62322+out_unlock:
62323+ spin_unlock(&gr_uid_lock);
62324+ return ret;
62325+}
62326+
62327+static __inline__ int
62328+proc_is_setxid(const struct cred *cred)
62329+{
62330+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62331+ !uid_eq(cred->uid, cred->fsuid))
62332+ return 1;
62333+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62334+ !gid_eq(cred->gid, cred->fsgid))
62335+ return 1;
62336+
62337+ return 0;
62338+}
62339+
62340+extern int gr_fake_force_sig(int sig, struct task_struct *t);
62341+
62342+void
62343+gr_handle_crash(struct task_struct *task, const int sig)
62344+{
62345+ struct acl_subject_label *curr;
62346+ struct task_struct *tsk, *tsk2;
62347+ const struct cred *cred;
62348+ const struct cred *cred2;
62349+
62350+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62351+ return;
62352+
62353+ if (unlikely(!gr_acl_is_enabled()))
62354+ return;
62355+
62356+ curr = task->acl;
62357+
62358+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
62359+ return;
62360+
62361+ if (time_before_eq(curr->expires, get_seconds())) {
62362+ curr->expires = 0;
62363+ curr->crashes = 0;
62364+ }
62365+
62366+ curr->crashes++;
62367+
62368+ if (!curr->expires)
62369+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62370+
62371+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62372+ time_after(curr->expires, get_seconds())) {
62373+ rcu_read_lock();
62374+ cred = __task_cred(task);
62375+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62376+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62377+ spin_lock(&gr_uid_lock);
62378+ gr_insert_uid(cred->uid, curr->expires);
62379+ spin_unlock(&gr_uid_lock);
62380+ curr->expires = 0;
62381+ curr->crashes = 0;
62382+ read_lock(&tasklist_lock);
62383+ do_each_thread(tsk2, tsk) {
62384+ cred2 = __task_cred(tsk);
62385+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
62386+ gr_fake_force_sig(SIGKILL, tsk);
62387+ } while_each_thread(tsk2, tsk);
62388+ read_unlock(&tasklist_lock);
62389+ } else {
62390+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62391+ read_lock(&tasklist_lock);
62392+ read_lock(&grsec_exec_file_lock);
62393+ do_each_thread(tsk2, tsk) {
62394+ if (likely(tsk != task)) {
62395+ // if this thread has the same subject as the one that triggered
62396+ // RES_CRASH and it's the same binary, kill it
62397+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62398+ gr_fake_force_sig(SIGKILL, tsk);
62399+ }
62400+ } while_each_thread(tsk2, tsk);
62401+ read_unlock(&grsec_exec_file_lock);
62402+ read_unlock(&tasklist_lock);
62403+ }
62404+ rcu_read_unlock();
62405+ }
62406+
62407+ return;
62408+}
62409+
62410+int
62411+gr_check_crash_exec(const struct file *filp)
62412+{
62413+ struct acl_subject_label *curr;
62414+
62415+ if (unlikely(!gr_acl_is_enabled()))
62416+ return 0;
62417+
62418+ read_lock(&gr_inode_lock);
62419+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62420+ __get_dev(filp->f_path.dentry),
62421+ current->role);
62422+ read_unlock(&gr_inode_lock);
62423+
62424+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62425+ (!curr->crashes && !curr->expires))
62426+ return 0;
62427+
62428+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62429+ time_after(curr->expires, get_seconds()))
62430+ return 1;
62431+ else if (time_before_eq(curr->expires, get_seconds())) {
62432+ curr->crashes = 0;
62433+ curr->expires = 0;
62434+ }
62435+
62436+ return 0;
62437+}
62438+
62439+void
62440+gr_handle_alertkill(struct task_struct *task)
62441+{
62442+ struct acl_subject_label *curracl;
62443+ __u32 curr_ip;
62444+ struct task_struct *p, *p2;
62445+
62446+ if (unlikely(!gr_acl_is_enabled()))
62447+ return;
62448+
62449+ curracl = task->acl;
62450+ curr_ip = task->signal->curr_ip;
62451+
62452+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62453+ read_lock(&tasklist_lock);
62454+ do_each_thread(p2, p) {
62455+ if (p->signal->curr_ip == curr_ip)
62456+ gr_fake_force_sig(SIGKILL, p);
62457+ } while_each_thread(p2, p);
62458+ read_unlock(&tasklist_lock);
62459+ } else if (curracl->mode & GR_KILLPROC)
62460+ gr_fake_force_sig(SIGKILL, task);
62461+
62462+ return;
62463+}
62464diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62465new file mode 100644
62466index 0000000..98011b0
62467--- /dev/null
62468+++ b/grsecurity/gracl_shm.c
62469@@ -0,0 +1,40 @@
62470+#include <linux/kernel.h>
62471+#include <linux/mm.h>
62472+#include <linux/sched.h>
62473+#include <linux/file.h>
62474+#include <linux/ipc.h>
62475+#include <linux/gracl.h>
62476+#include <linux/grsecurity.h>
62477+#include <linux/grinternal.h>
62478+
62479+int
62480+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62481+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
62482+{
62483+ struct task_struct *task;
62484+
62485+ if (!gr_acl_is_enabled())
62486+ return 1;
62487+
62488+ rcu_read_lock();
62489+ read_lock(&tasklist_lock);
62490+
62491+ task = find_task_by_vpid(shm_cprid);
62492+
62493+ if (unlikely(!task))
62494+ task = find_task_by_vpid(shm_lapid);
62495+
62496+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62497+ (task_pid_nr(task) == shm_lapid)) &&
62498+ (task->acl->mode & GR_PROTSHM) &&
62499+ (task->acl != current->acl))) {
62500+ read_unlock(&tasklist_lock);
62501+ rcu_read_unlock();
62502+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62503+ return 0;
62504+ }
62505+ read_unlock(&tasklist_lock);
62506+ rcu_read_unlock();
62507+
62508+ return 1;
62509+}
62510diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62511new file mode 100644
62512index 0000000..bc0be01
62513--- /dev/null
62514+++ b/grsecurity/grsec_chdir.c
62515@@ -0,0 +1,19 @@
62516+#include <linux/kernel.h>
62517+#include <linux/sched.h>
62518+#include <linux/fs.h>
62519+#include <linux/file.h>
62520+#include <linux/grsecurity.h>
62521+#include <linux/grinternal.h>
62522+
62523+void
62524+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62525+{
62526+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62527+ if ((grsec_enable_chdir && grsec_enable_group &&
62528+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62529+ !grsec_enable_group)) {
62530+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62531+ }
62532+#endif
62533+ return;
62534+}
62535diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62536new file mode 100644
62537index 0000000..6d2de57
62538--- /dev/null
62539+++ b/grsecurity/grsec_chroot.c
62540@@ -0,0 +1,357 @@
62541+#include <linux/kernel.h>
62542+#include <linux/module.h>
62543+#include <linux/sched.h>
62544+#include <linux/file.h>
62545+#include <linux/fs.h>
62546+#include <linux/mount.h>
62547+#include <linux/types.h>
62548+#include "../fs/mount.h"
62549+#include <linux/grsecurity.h>
62550+#include <linux/grinternal.h>
62551+
62552+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
62553+{
62554+#ifdef CONFIG_GRKERNSEC
62555+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
62556+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
62557+ task->gr_is_chrooted = 1;
62558+ else
62559+ task->gr_is_chrooted = 0;
62560+
62561+ task->gr_chroot_dentry = path->dentry;
62562+#endif
62563+ return;
62564+}
62565+
62566+void gr_clear_chroot_entries(struct task_struct *task)
62567+{
62568+#ifdef CONFIG_GRKERNSEC
62569+ task->gr_is_chrooted = 0;
62570+ task->gr_chroot_dentry = NULL;
62571+#endif
62572+ return;
62573+}
62574+
62575+int
62576+gr_handle_chroot_unix(const pid_t pid)
62577+{
62578+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62579+ struct task_struct *p;
62580+
62581+ if (unlikely(!grsec_enable_chroot_unix))
62582+ return 1;
62583+
62584+ if (likely(!proc_is_chrooted(current)))
62585+ return 1;
62586+
62587+ rcu_read_lock();
62588+ read_lock(&tasklist_lock);
62589+ p = find_task_by_vpid_unrestricted(pid);
62590+ if (unlikely(p && !have_same_root(current, p))) {
62591+ read_unlock(&tasklist_lock);
62592+ rcu_read_unlock();
62593+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
62594+ return 0;
62595+ }
62596+ read_unlock(&tasklist_lock);
62597+ rcu_read_unlock();
62598+#endif
62599+ return 1;
62600+}
62601+
62602+int
62603+gr_handle_chroot_nice(void)
62604+{
62605+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62606+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
62607+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
62608+ return -EPERM;
62609+ }
62610+#endif
62611+ return 0;
62612+}
62613+
62614+int
62615+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
62616+{
62617+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62618+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
62619+ && proc_is_chrooted(current)) {
62620+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
62621+ return -EACCES;
62622+ }
62623+#endif
62624+ return 0;
62625+}
62626+
62627+int
62628+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
62629+{
62630+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62631+ struct task_struct *p;
62632+ int ret = 0;
62633+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
62634+ return ret;
62635+
62636+ read_lock(&tasklist_lock);
62637+ do_each_pid_task(pid, type, p) {
62638+ if (!have_same_root(current, p)) {
62639+ ret = 1;
62640+ goto out;
62641+ }
62642+ } while_each_pid_task(pid, type, p);
62643+out:
62644+ read_unlock(&tasklist_lock);
62645+ return ret;
62646+#endif
62647+ return 0;
62648+}
62649+
62650+int
62651+gr_pid_is_chrooted(struct task_struct *p)
62652+{
62653+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62654+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
62655+ return 0;
62656+
62657+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
62658+ !have_same_root(current, p)) {
62659+ return 1;
62660+ }
62661+#endif
62662+ return 0;
62663+}
62664+
62665+EXPORT_SYMBOL(gr_pid_is_chrooted);
62666+
62667+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
62668+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
62669+{
62670+ struct path path, currentroot;
62671+ int ret = 0;
62672+
62673+ path.dentry = (struct dentry *)u_dentry;
62674+ path.mnt = (struct vfsmount *)u_mnt;
62675+ get_fs_root(current->fs, &currentroot);
62676+ if (path_is_under(&path, &currentroot))
62677+ ret = 1;
62678+ path_put(&currentroot);
62679+
62680+ return ret;
62681+}
62682+#endif
62683+
62684+int
62685+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
62686+{
62687+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62688+ if (!grsec_enable_chroot_fchdir)
62689+ return 1;
62690+
62691+ if (!proc_is_chrooted(current))
62692+ return 1;
62693+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
62694+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
62695+ return 0;
62696+ }
62697+#endif
62698+ return 1;
62699+}
62700+
62701+int
62702+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62703+ const time_t shm_createtime)
62704+{
62705+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62706+ struct task_struct *p;
62707+ time_t starttime;
62708+
62709+ if (unlikely(!grsec_enable_chroot_shmat))
62710+ return 1;
62711+
62712+ if (likely(!proc_is_chrooted(current)))
62713+ return 1;
62714+
62715+ rcu_read_lock();
62716+ read_lock(&tasklist_lock);
62717+
62718+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
62719+ starttime = p->start_time.tv_sec;
62720+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
62721+ if (have_same_root(current, p)) {
62722+ goto allow;
62723+ } else {
62724+ read_unlock(&tasklist_lock);
62725+ rcu_read_unlock();
62726+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62727+ return 0;
62728+ }
62729+ }
62730+ /* creator exited, pid reuse, fall through to next check */
62731+ }
62732+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
62733+ if (unlikely(!have_same_root(current, p))) {
62734+ read_unlock(&tasklist_lock);
62735+ rcu_read_unlock();
62736+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62737+ return 0;
62738+ }
62739+ }
62740+
62741+allow:
62742+ read_unlock(&tasklist_lock);
62743+ rcu_read_unlock();
62744+#endif
62745+ return 1;
62746+}
62747+
62748+void
62749+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
62750+{
62751+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62752+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
62753+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
62754+#endif
62755+ return;
62756+}
62757+
62758+int
62759+gr_handle_chroot_mknod(const struct dentry *dentry,
62760+ const struct vfsmount *mnt, const int mode)
62761+{
62762+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62763+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
62764+ proc_is_chrooted(current)) {
62765+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
62766+ return -EPERM;
62767+ }
62768+#endif
62769+ return 0;
62770+}
62771+
62772+int
62773+gr_handle_chroot_mount(const struct dentry *dentry,
62774+ const struct vfsmount *mnt, const char *dev_name)
62775+{
62776+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62777+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
62778+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
62779+ return -EPERM;
62780+ }
62781+#endif
62782+ return 0;
62783+}
62784+
62785+int
62786+gr_handle_chroot_pivot(void)
62787+{
62788+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62789+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
62790+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
62791+ return -EPERM;
62792+ }
62793+#endif
62794+ return 0;
62795+}
62796+
62797+int
62798+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
62799+{
62800+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62801+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
62802+ !gr_is_outside_chroot(dentry, mnt)) {
62803+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
62804+ return -EPERM;
62805+ }
62806+#endif
62807+ return 0;
62808+}
62809+
62810+extern const char *captab_log[];
62811+extern int captab_log_entries;
62812+
62813+int
62814+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62815+{
62816+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62817+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62818+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62819+ if (cap_raised(chroot_caps, cap)) {
62820+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
62821+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
62822+ }
62823+ return 0;
62824+ }
62825+ }
62826+#endif
62827+ return 1;
62828+}
62829+
62830+int
62831+gr_chroot_is_capable(const int cap)
62832+{
62833+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62834+ return gr_task_chroot_is_capable(current, current_cred(), cap);
62835+#endif
62836+ return 1;
62837+}
62838+
62839+int
62840+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
62841+{
62842+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62843+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62844+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62845+ if (cap_raised(chroot_caps, cap)) {
62846+ return 0;
62847+ }
62848+ }
62849+#endif
62850+ return 1;
62851+}
62852+
62853+int
62854+gr_chroot_is_capable_nolog(const int cap)
62855+{
62856+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62857+ return gr_task_chroot_is_capable_nolog(current, cap);
62858+#endif
62859+ return 1;
62860+}
62861+
62862+int
62863+gr_handle_chroot_sysctl(const int op)
62864+{
62865+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62866+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
62867+ proc_is_chrooted(current))
62868+ return -EACCES;
62869+#endif
62870+ return 0;
62871+}
62872+
62873+void
62874+gr_handle_chroot_chdir(struct path *path)
62875+{
62876+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62877+ if (grsec_enable_chroot_chdir)
62878+ set_fs_pwd(current->fs, path);
62879+#endif
62880+ return;
62881+}
62882+
62883+int
62884+gr_handle_chroot_chmod(const struct dentry *dentry,
62885+ const struct vfsmount *mnt, const int mode)
62886+{
62887+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62888+ /* allow chmod +s on directories, but not files */
62889+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
62890+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
62891+ proc_is_chrooted(current)) {
62892+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
62893+ return -EPERM;
62894+ }
62895+#endif
62896+ return 0;
62897+}
62898diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
62899new file mode 100644
62900index 0000000..207d409
62901--- /dev/null
62902+++ b/grsecurity/grsec_disabled.c
62903@@ -0,0 +1,434 @@
62904+#include <linux/kernel.h>
62905+#include <linux/module.h>
62906+#include <linux/sched.h>
62907+#include <linux/file.h>
62908+#include <linux/fs.h>
62909+#include <linux/kdev_t.h>
62910+#include <linux/net.h>
62911+#include <linux/in.h>
62912+#include <linux/ip.h>
62913+#include <linux/skbuff.h>
62914+#include <linux/sysctl.h>
62915+
62916+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62917+void
62918+pax_set_initial_flags(struct linux_binprm *bprm)
62919+{
62920+ return;
62921+}
62922+#endif
62923+
62924+#ifdef CONFIG_SYSCTL
62925+__u32
62926+gr_handle_sysctl(const struct ctl_table * table, const int op)
62927+{
62928+ return 0;
62929+}
62930+#endif
62931+
62932+#ifdef CONFIG_TASKSTATS
62933+int gr_is_taskstats_denied(int pid)
62934+{
62935+ return 0;
62936+}
62937+#endif
62938+
62939+int
62940+gr_acl_is_enabled(void)
62941+{
62942+ return 0;
62943+}
62944+
62945+void
62946+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
62947+{
62948+ return;
62949+}
62950+
62951+int
62952+gr_handle_rawio(const struct inode *inode)
62953+{
62954+ return 0;
62955+}
62956+
62957+void
62958+gr_acl_handle_psacct(struct task_struct *task, const long code)
62959+{
62960+ return;
62961+}
62962+
62963+int
62964+gr_handle_ptrace(struct task_struct *task, const long request)
62965+{
62966+ return 0;
62967+}
62968+
62969+int
62970+gr_handle_proc_ptrace(struct task_struct *task)
62971+{
62972+ return 0;
62973+}
62974+
62975+int
62976+gr_set_acls(const int type)
62977+{
62978+ return 0;
62979+}
62980+
62981+int
62982+gr_check_hidden_task(const struct task_struct *tsk)
62983+{
62984+ return 0;
62985+}
62986+
62987+int
62988+gr_check_protected_task(const struct task_struct *task)
62989+{
62990+ return 0;
62991+}
62992+
62993+int
62994+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
62995+{
62996+ return 0;
62997+}
62998+
62999+void
63000+gr_copy_label(struct task_struct *tsk)
63001+{
63002+ return;
63003+}
63004+
63005+void
63006+gr_set_pax_flags(struct task_struct *task)
63007+{
63008+ return;
63009+}
63010+
63011+int
63012+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63013+ const int unsafe_share)
63014+{
63015+ return 0;
63016+}
63017+
63018+void
63019+gr_handle_delete(const ino_t ino, const dev_t dev)
63020+{
63021+ return;
63022+}
63023+
63024+void
63025+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63026+{
63027+ return;
63028+}
63029+
63030+void
63031+gr_handle_crash(struct task_struct *task, const int sig)
63032+{
63033+ return;
63034+}
63035+
63036+int
63037+gr_check_crash_exec(const struct file *filp)
63038+{
63039+ return 0;
63040+}
63041+
63042+int
63043+gr_check_crash_uid(const kuid_t uid)
63044+{
63045+ return 0;
63046+}
63047+
63048+void
63049+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63050+ struct dentry *old_dentry,
63051+ struct dentry *new_dentry,
63052+ struct vfsmount *mnt, const __u8 replace)
63053+{
63054+ return;
63055+}
63056+
63057+int
63058+gr_search_socket(const int family, const int type, const int protocol)
63059+{
63060+ return 1;
63061+}
63062+
63063+int
63064+gr_search_connectbind(const int mode, const struct socket *sock,
63065+ const struct sockaddr_in *addr)
63066+{
63067+ return 0;
63068+}
63069+
63070+void
63071+gr_handle_alertkill(struct task_struct *task)
63072+{
63073+ return;
63074+}
63075+
63076+__u32
63077+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63078+{
63079+ return 1;
63080+}
63081+
63082+__u32
63083+gr_acl_handle_hidden_file(const struct dentry * dentry,
63084+ const struct vfsmount * mnt)
63085+{
63086+ return 1;
63087+}
63088+
63089+__u32
63090+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63091+ int acc_mode)
63092+{
63093+ return 1;
63094+}
63095+
63096+__u32
63097+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63098+{
63099+ return 1;
63100+}
63101+
63102+__u32
63103+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63104+{
63105+ return 1;
63106+}
63107+
63108+int
63109+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63110+ unsigned int *vm_flags)
63111+{
63112+ return 1;
63113+}
63114+
63115+__u32
63116+gr_acl_handle_truncate(const struct dentry * dentry,
63117+ const struct vfsmount * mnt)
63118+{
63119+ return 1;
63120+}
63121+
63122+__u32
63123+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63124+{
63125+ return 1;
63126+}
63127+
63128+__u32
63129+gr_acl_handle_access(const struct dentry * dentry,
63130+ const struct vfsmount * mnt, const int fmode)
63131+{
63132+ return 1;
63133+}
63134+
63135+__u32
63136+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63137+ umode_t *mode)
63138+{
63139+ return 1;
63140+}
63141+
63142+__u32
63143+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63144+{
63145+ return 1;
63146+}
63147+
63148+__u32
63149+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63150+{
63151+ return 1;
63152+}
63153+
63154+void
63155+grsecurity_init(void)
63156+{
63157+ return;
63158+}
63159+
63160+umode_t gr_acl_umask(void)
63161+{
63162+ return 0;
63163+}
63164+
63165+__u32
63166+gr_acl_handle_mknod(const struct dentry * new_dentry,
63167+ const struct dentry * parent_dentry,
63168+ const struct vfsmount * parent_mnt,
63169+ const int mode)
63170+{
63171+ return 1;
63172+}
63173+
63174+__u32
63175+gr_acl_handle_mkdir(const struct dentry * new_dentry,
63176+ const struct dentry * parent_dentry,
63177+ const struct vfsmount * parent_mnt)
63178+{
63179+ return 1;
63180+}
63181+
63182+__u32
63183+gr_acl_handle_symlink(const struct dentry * new_dentry,
63184+ const struct dentry * parent_dentry,
63185+ const struct vfsmount * parent_mnt, const struct filename *from)
63186+{
63187+ return 1;
63188+}
63189+
63190+__u32
63191+gr_acl_handle_link(const struct dentry * new_dentry,
63192+ const struct dentry * parent_dentry,
63193+ const struct vfsmount * parent_mnt,
63194+ const struct dentry * old_dentry,
63195+ const struct vfsmount * old_mnt, const struct filename *to)
63196+{
63197+ return 1;
63198+}
63199+
63200+int
63201+gr_acl_handle_rename(const struct dentry *new_dentry,
63202+ const struct dentry *parent_dentry,
63203+ const struct vfsmount *parent_mnt,
63204+ const struct dentry *old_dentry,
63205+ const struct inode *old_parent_inode,
63206+ const struct vfsmount *old_mnt, const struct filename *newname)
63207+{
63208+ return 0;
63209+}
63210+
63211+int
63212+gr_acl_handle_filldir(const struct file *file, const char *name,
63213+ const int namelen, const ino_t ino)
63214+{
63215+ return 1;
63216+}
63217+
63218+int
63219+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63220+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63221+{
63222+ return 1;
63223+}
63224+
63225+int
63226+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63227+{
63228+ return 0;
63229+}
63230+
63231+int
63232+gr_search_accept(const struct socket *sock)
63233+{
63234+ return 0;
63235+}
63236+
63237+int
63238+gr_search_listen(const struct socket *sock)
63239+{
63240+ return 0;
63241+}
63242+
63243+int
63244+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63245+{
63246+ return 0;
63247+}
63248+
63249+__u32
63250+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63251+{
63252+ return 1;
63253+}
63254+
63255+__u32
63256+gr_acl_handle_creat(const struct dentry * dentry,
63257+ const struct dentry * p_dentry,
63258+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63259+ const int imode)
63260+{
63261+ return 1;
63262+}
63263+
63264+void
63265+gr_acl_handle_exit(void)
63266+{
63267+ return;
63268+}
63269+
63270+int
63271+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63272+{
63273+ return 1;
63274+}
63275+
63276+void
63277+gr_set_role_label(const kuid_t uid, const kgid_t gid)
63278+{
63279+ return;
63280+}
63281+
63282+int
63283+gr_acl_handle_procpidmem(const struct task_struct *task)
63284+{
63285+ return 0;
63286+}
63287+
63288+int
63289+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63290+{
63291+ return 0;
63292+}
63293+
63294+int
63295+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63296+{
63297+ return 0;
63298+}
63299+
63300+void
63301+gr_set_kernel_label(struct task_struct *task)
63302+{
63303+ return;
63304+}
63305+
63306+int
63307+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63308+{
63309+ return 0;
63310+}
63311+
63312+int
63313+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63314+{
63315+ return 0;
63316+}
63317+
63318+int gr_acl_enable_at_secure(void)
63319+{
63320+ return 0;
63321+}
63322+
63323+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63324+{
63325+ return dentry->d_inode->i_sb->s_dev;
63326+}
63327+
63328+void gr_put_exec_file(struct task_struct *task)
63329+{
63330+ return;
63331+}
63332+
63333+EXPORT_SYMBOL(gr_set_kernel_label);
63334+#ifdef CONFIG_SECURITY
63335+EXPORT_SYMBOL(gr_check_user_change);
63336+EXPORT_SYMBOL(gr_check_group_change);
63337+#endif
63338diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63339new file mode 100644
63340index 0000000..abfa971
63341--- /dev/null
63342+++ b/grsecurity/grsec_exec.c
63343@@ -0,0 +1,174 @@
63344+#include <linux/kernel.h>
63345+#include <linux/sched.h>
63346+#include <linux/file.h>
63347+#include <linux/binfmts.h>
63348+#include <linux/fs.h>
63349+#include <linux/types.h>
63350+#include <linux/grdefs.h>
63351+#include <linux/grsecurity.h>
63352+#include <linux/grinternal.h>
63353+#include <linux/capability.h>
63354+#include <linux/module.h>
63355+
63356+#include <asm/uaccess.h>
63357+
63358+#ifdef CONFIG_GRKERNSEC_EXECLOG
63359+static char gr_exec_arg_buf[132];
63360+static DEFINE_MUTEX(gr_exec_arg_mutex);
63361+#endif
63362+
63363+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63364+
63365+void
63366+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63367+{
63368+#ifdef CONFIG_GRKERNSEC_EXECLOG
63369+ char *grarg = gr_exec_arg_buf;
63370+ unsigned int i, x, execlen = 0;
63371+ char c;
63372+
63373+ if (!((grsec_enable_execlog && grsec_enable_group &&
63374+ in_group_p(grsec_audit_gid))
63375+ || (grsec_enable_execlog && !grsec_enable_group)))
63376+ return;
63377+
63378+ mutex_lock(&gr_exec_arg_mutex);
63379+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
63380+
63381+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
63382+ const char __user *p;
63383+ unsigned int len;
63384+
63385+ p = get_user_arg_ptr(argv, i);
63386+ if (IS_ERR(p))
63387+ goto log;
63388+
63389+ len = strnlen_user(p, 128 - execlen);
63390+ if (len > 128 - execlen)
63391+ len = 128 - execlen;
63392+ else if (len > 0)
63393+ len--;
63394+ if (copy_from_user(grarg + execlen, p, len))
63395+ goto log;
63396+
63397+ /* rewrite unprintable characters */
63398+ for (x = 0; x < len; x++) {
63399+ c = *(grarg + execlen + x);
63400+ if (c < 32 || c > 126)
63401+ *(grarg + execlen + x) = ' ';
63402+ }
63403+
63404+ execlen += len;
63405+ *(grarg + execlen) = ' ';
63406+ *(grarg + execlen + 1) = '\0';
63407+ execlen++;
63408+ }
63409+
63410+ log:
63411+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63412+ bprm->file->f_path.mnt, grarg);
63413+ mutex_unlock(&gr_exec_arg_mutex);
63414+#endif
63415+ return;
63416+}
63417+
63418+#ifdef CONFIG_GRKERNSEC
63419+extern int gr_acl_is_capable(const int cap);
63420+extern int gr_acl_is_capable_nolog(const int cap);
63421+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63422+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63423+extern int gr_chroot_is_capable(const int cap);
63424+extern int gr_chroot_is_capable_nolog(const int cap);
63425+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63426+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63427+#endif
63428+
63429+const char *captab_log[] = {
63430+ "CAP_CHOWN",
63431+ "CAP_DAC_OVERRIDE",
63432+ "CAP_DAC_READ_SEARCH",
63433+ "CAP_FOWNER",
63434+ "CAP_FSETID",
63435+ "CAP_KILL",
63436+ "CAP_SETGID",
63437+ "CAP_SETUID",
63438+ "CAP_SETPCAP",
63439+ "CAP_LINUX_IMMUTABLE",
63440+ "CAP_NET_BIND_SERVICE",
63441+ "CAP_NET_BROADCAST",
63442+ "CAP_NET_ADMIN",
63443+ "CAP_NET_RAW",
63444+ "CAP_IPC_LOCK",
63445+ "CAP_IPC_OWNER",
63446+ "CAP_SYS_MODULE",
63447+ "CAP_SYS_RAWIO",
63448+ "CAP_SYS_CHROOT",
63449+ "CAP_SYS_PTRACE",
63450+ "CAP_SYS_PACCT",
63451+ "CAP_SYS_ADMIN",
63452+ "CAP_SYS_BOOT",
63453+ "CAP_SYS_NICE",
63454+ "CAP_SYS_RESOURCE",
63455+ "CAP_SYS_TIME",
63456+ "CAP_SYS_TTY_CONFIG",
63457+ "CAP_MKNOD",
63458+ "CAP_LEASE",
63459+ "CAP_AUDIT_WRITE",
63460+ "CAP_AUDIT_CONTROL",
63461+ "CAP_SETFCAP",
63462+ "CAP_MAC_OVERRIDE",
63463+ "CAP_MAC_ADMIN",
63464+ "CAP_SYSLOG",
63465+ "CAP_WAKE_ALARM"
63466+};
63467+
63468+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63469+
63470+int gr_is_capable(const int cap)
63471+{
63472+#ifdef CONFIG_GRKERNSEC
63473+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63474+ return 1;
63475+ return 0;
63476+#else
63477+ return 1;
63478+#endif
63479+}
63480+
63481+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63482+{
63483+#ifdef CONFIG_GRKERNSEC
63484+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63485+ return 1;
63486+ return 0;
63487+#else
63488+ return 1;
63489+#endif
63490+}
63491+
63492+int gr_is_capable_nolog(const int cap)
63493+{
63494+#ifdef CONFIG_GRKERNSEC
63495+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63496+ return 1;
63497+ return 0;
63498+#else
63499+ return 1;
63500+#endif
63501+}
63502+
63503+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63504+{
63505+#ifdef CONFIG_GRKERNSEC
63506+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63507+ return 1;
63508+ return 0;
63509+#else
63510+ return 1;
63511+#endif
63512+}
63513+
63514+EXPORT_SYMBOL(gr_is_capable);
63515+EXPORT_SYMBOL(gr_is_capable_nolog);
63516+EXPORT_SYMBOL(gr_task_is_capable);
63517+EXPORT_SYMBOL(gr_task_is_capable_nolog);
63518diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63519new file mode 100644
63520index 0000000..06cc6ea
63521--- /dev/null
63522+++ b/grsecurity/grsec_fifo.c
63523@@ -0,0 +1,24 @@
63524+#include <linux/kernel.h>
63525+#include <linux/sched.h>
63526+#include <linux/fs.h>
63527+#include <linux/file.h>
63528+#include <linux/grinternal.h>
63529+
63530+int
63531+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63532+ const struct dentry *dir, const int flag, const int acc_mode)
63533+{
63534+#ifdef CONFIG_GRKERNSEC_FIFO
63535+ const struct cred *cred = current_cred();
63536+
63537+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
63538+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
63539+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
63540+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
63541+ if (!inode_permission(dentry->d_inode, acc_mode))
63542+ 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));
63543+ return -EACCES;
63544+ }
63545+#endif
63546+ return 0;
63547+}
63548diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
63549new file mode 100644
63550index 0000000..8ca18bf
63551--- /dev/null
63552+++ b/grsecurity/grsec_fork.c
63553@@ -0,0 +1,23 @@
63554+#include <linux/kernel.h>
63555+#include <linux/sched.h>
63556+#include <linux/grsecurity.h>
63557+#include <linux/grinternal.h>
63558+#include <linux/errno.h>
63559+
63560+void
63561+gr_log_forkfail(const int retval)
63562+{
63563+#ifdef CONFIG_GRKERNSEC_FORKFAIL
63564+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
63565+ switch (retval) {
63566+ case -EAGAIN:
63567+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
63568+ break;
63569+ case -ENOMEM:
63570+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
63571+ break;
63572+ }
63573+ }
63574+#endif
63575+ return;
63576+}
63577diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
63578new file mode 100644
63579index 0000000..a862e9f
63580--- /dev/null
63581+++ b/grsecurity/grsec_init.c
63582@@ -0,0 +1,283 @@
63583+#include <linux/kernel.h>
63584+#include <linux/sched.h>
63585+#include <linux/mm.h>
63586+#include <linux/gracl.h>
63587+#include <linux/slab.h>
63588+#include <linux/vmalloc.h>
63589+#include <linux/percpu.h>
63590+#include <linux/module.h>
63591+
63592+int grsec_enable_ptrace_readexec;
63593+int grsec_enable_setxid;
63594+int grsec_enable_symlinkown;
63595+kgid_t grsec_symlinkown_gid;
63596+int grsec_enable_brute;
63597+int grsec_enable_link;
63598+int grsec_enable_dmesg;
63599+int grsec_enable_harden_ptrace;
63600+int grsec_enable_fifo;
63601+int grsec_enable_execlog;
63602+int grsec_enable_signal;
63603+int grsec_enable_forkfail;
63604+int grsec_enable_audit_ptrace;
63605+int grsec_enable_time;
63606+int grsec_enable_audit_textrel;
63607+int grsec_enable_group;
63608+kgid_t grsec_audit_gid;
63609+int grsec_enable_chdir;
63610+int grsec_enable_mount;
63611+int grsec_enable_rofs;
63612+int grsec_enable_chroot_findtask;
63613+int grsec_enable_chroot_mount;
63614+int grsec_enable_chroot_shmat;
63615+int grsec_enable_chroot_fchdir;
63616+int grsec_enable_chroot_double;
63617+int grsec_enable_chroot_pivot;
63618+int grsec_enable_chroot_chdir;
63619+int grsec_enable_chroot_chmod;
63620+int grsec_enable_chroot_mknod;
63621+int grsec_enable_chroot_nice;
63622+int grsec_enable_chroot_execlog;
63623+int grsec_enable_chroot_caps;
63624+int grsec_enable_chroot_sysctl;
63625+int grsec_enable_chroot_unix;
63626+int grsec_enable_tpe;
63627+kgid_t grsec_tpe_gid;
63628+int grsec_enable_blackhole;
63629+#ifdef CONFIG_IPV6_MODULE
63630+EXPORT_SYMBOL(grsec_enable_blackhole);
63631+#endif
63632+int grsec_lastack_retries;
63633+int grsec_enable_tpe_all;
63634+int grsec_enable_tpe_invert;
63635+int grsec_enable_socket_all;
63636+kgid_t grsec_socket_all_gid;
63637+int grsec_enable_socket_client;
63638+kgid_t grsec_socket_client_gid;
63639+int grsec_enable_socket_server;
63640+kgid_t grsec_socket_server_gid;
63641+int grsec_resource_logging;
63642+int grsec_disable_privio;
63643+int grsec_enable_log_rwxmaps;
63644+int grsec_lock;
63645+
63646+DEFINE_SPINLOCK(grsec_alert_lock);
63647+unsigned long grsec_alert_wtime = 0;
63648+unsigned long grsec_alert_fyet = 0;
63649+
63650+DEFINE_SPINLOCK(grsec_audit_lock);
63651+
63652+DEFINE_RWLOCK(grsec_exec_file_lock);
63653+
63654+char *gr_shared_page[4];
63655+
63656+char *gr_alert_log_fmt;
63657+char *gr_audit_log_fmt;
63658+char *gr_alert_log_buf;
63659+char *gr_audit_log_buf;
63660+
63661+extern struct gr_arg *gr_usermode;
63662+extern unsigned char *gr_system_salt;
63663+extern unsigned char *gr_system_sum;
63664+
63665+void __init
63666+grsecurity_init(void)
63667+{
63668+ int j;
63669+ /* create the per-cpu shared pages */
63670+
63671+#ifdef CONFIG_X86
63672+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
63673+#endif
63674+
63675+ for (j = 0; j < 4; j++) {
63676+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
63677+ if (gr_shared_page[j] == NULL) {
63678+ panic("Unable to allocate grsecurity shared page");
63679+ return;
63680+ }
63681+ }
63682+
63683+ /* allocate log buffers */
63684+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
63685+ if (!gr_alert_log_fmt) {
63686+ panic("Unable to allocate grsecurity alert log format buffer");
63687+ return;
63688+ }
63689+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
63690+ if (!gr_audit_log_fmt) {
63691+ panic("Unable to allocate grsecurity audit log format buffer");
63692+ return;
63693+ }
63694+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63695+ if (!gr_alert_log_buf) {
63696+ panic("Unable to allocate grsecurity alert log buffer");
63697+ return;
63698+ }
63699+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63700+ if (!gr_audit_log_buf) {
63701+ panic("Unable to allocate grsecurity audit log buffer");
63702+ return;
63703+ }
63704+
63705+ /* allocate memory for authentication structure */
63706+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
63707+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
63708+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
63709+
63710+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
63711+ panic("Unable to allocate grsecurity authentication structure");
63712+ return;
63713+ }
63714+
63715+
63716+#ifdef CONFIG_GRKERNSEC_IO
63717+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
63718+ grsec_disable_privio = 1;
63719+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63720+ grsec_disable_privio = 1;
63721+#else
63722+ grsec_disable_privio = 0;
63723+#endif
63724+#endif
63725+
63726+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63727+ /* for backward compatibility, tpe_invert always defaults to on if
63728+ enabled in the kernel
63729+ */
63730+ grsec_enable_tpe_invert = 1;
63731+#endif
63732+
63733+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63734+#ifndef CONFIG_GRKERNSEC_SYSCTL
63735+ grsec_lock = 1;
63736+#endif
63737+
63738+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63739+ grsec_enable_audit_textrel = 1;
63740+#endif
63741+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63742+ grsec_enable_log_rwxmaps = 1;
63743+#endif
63744+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
63745+ grsec_enable_group = 1;
63746+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
63747+#endif
63748+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
63749+ grsec_enable_ptrace_readexec = 1;
63750+#endif
63751+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63752+ grsec_enable_chdir = 1;
63753+#endif
63754+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63755+ grsec_enable_harden_ptrace = 1;
63756+#endif
63757+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63758+ grsec_enable_mount = 1;
63759+#endif
63760+#ifdef CONFIG_GRKERNSEC_LINK
63761+ grsec_enable_link = 1;
63762+#endif
63763+#ifdef CONFIG_GRKERNSEC_BRUTE
63764+ grsec_enable_brute = 1;
63765+#endif
63766+#ifdef CONFIG_GRKERNSEC_DMESG
63767+ grsec_enable_dmesg = 1;
63768+#endif
63769+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63770+ grsec_enable_blackhole = 1;
63771+ grsec_lastack_retries = 4;
63772+#endif
63773+#ifdef CONFIG_GRKERNSEC_FIFO
63774+ grsec_enable_fifo = 1;
63775+#endif
63776+#ifdef CONFIG_GRKERNSEC_EXECLOG
63777+ grsec_enable_execlog = 1;
63778+#endif
63779+#ifdef CONFIG_GRKERNSEC_SETXID
63780+ grsec_enable_setxid = 1;
63781+#endif
63782+#ifdef CONFIG_GRKERNSEC_SIGNAL
63783+ grsec_enable_signal = 1;
63784+#endif
63785+#ifdef CONFIG_GRKERNSEC_FORKFAIL
63786+ grsec_enable_forkfail = 1;
63787+#endif
63788+#ifdef CONFIG_GRKERNSEC_TIME
63789+ grsec_enable_time = 1;
63790+#endif
63791+#ifdef CONFIG_GRKERNSEC_RESLOG
63792+ grsec_resource_logging = 1;
63793+#endif
63794+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63795+ grsec_enable_chroot_findtask = 1;
63796+#endif
63797+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63798+ grsec_enable_chroot_unix = 1;
63799+#endif
63800+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63801+ grsec_enable_chroot_mount = 1;
63802+#endif
63803+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63804+ grsec_enable_chroot_fchdir = 1;
63805+#endif
63806+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63807+ grsec_enable_chroot_shmat = 1;
63808+#endif
63809+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63810+ grsec_enable_audit_ptrace = 1;
63811+#endif
63812+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63813+ grsec_enable_chroot_double = 1;
63814+#endif
63815+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63816+ grsec_enable_chroot_pivot = 1;
63817+#endif
63818+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63819+ grsec_enable_chroot_chdir = 1;
63820+#endif
63821+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63822+ grsec_enable_chroot_chmod = 1;
63823+#endif
63824+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63825+ grsec_enable_chroot_mknod = 1;
63826+#endif
63827+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63828+ grsec_enable_chroot_nice = 1;
63829+#endif
63830+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63831+ grsec_enable_chroot_execlog = 1;
63832+#endif
63833+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63834+ grsec_enable_chroot_caps = 1;
63835+#endif
63836+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63837+ grsec_enable_chroot_sysctl = 1;
63838+#endif
63839+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63840+ grsec_enable_symlinkown = 1;
63841+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
63842+#endif
63843+#ifdef CONFIG_GRKERNSEC_TPE
63844+ grsec_enable_tpe = 1;
63845+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
63846+#ifdef CONFIG_GRKERNSEC_TPE_ALL
63847+ grsec_enable_tpe_all = 1;
63848+#endif
63849+#endif
63850+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63851+ grsec_enable_socket_all = 1;
63852+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
63853+#endif
63854+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63855+ grsec_enable_socket_client = 1;
63856+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
63857+#endif
63858+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63859+ grsec_enable_socket_server = 1;
63860+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
63861+#endif
63862+#endif
63863+
63864+ return;
63865+}
63866diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
63867new file mode 100644
63868index 0000000..5e05e20
63869--- /dev/null
63870+++ b/grsecurity/grsec_link.c
63871@@ -0,0 +1,58 @@
63872+#include <linux/kernel.h>
63873+#include <linux/sched.h>
63874+#include <linux/fs.h>
63875+#include <linux/file.h>
63876+#include <linux/grinternal.h>
63877+
63878+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
63879+{
63880+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63881+ const struct inode *link_inode = link->dentry->d_inode;
63882+
63883+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
63884+ /* ignore root-owned links, e.g. /proc/self */
63885+ gr_is_global_nonroot(link_inode->i_uid) && target &&
63886+ !uid_eq(link_inode->i_uid, target->i_uid)) {
63887+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
63888+ return 1;
63889+ }
63890+#endif
63891+ return 0;
63892+}
63893+
63894+int
63895+gr_handle_follow_link(const struct inode *parent,
63896+ const struct inode *inode,
63897+ const struct dentry *dentry, const struct vfsmount *mnt)
63898+{
63899+#ifdef CONFIG_GRKERNSEC_LINK
63900+ const struct cred *cred = current_cred();
63901+
63902+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
63903+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
63904+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
63905+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
63906+ return -EACCES;
63907+ }
63908+#endif
63909+ return 0;
63910+}
63911+
63912+int
63913+gr_handle_hardlink(const struct dentry *dentry,
63914+ const struct vfsmount *mnt,
63915+ struct inode *inode, const int mode, const struct filename *to)
63916+{
63917+#ifdef CONFIG_GRKERNSEC_LINK
63918+ const struct cred *cred = current_cred();
63919+
63920+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
63921+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
63922+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
63923+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
63924+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
63925+ return -EPERM;
63926+ }
63927+#endif
63928+ return 0;
63929+}
63930diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
63931new file mode 100644
63932index 0000000..7c06085
63933--- /dev/null
63934+++ b/grsecurity/grsec_log.c
63935@@ -0,0 +1,326 @@
63936+#include <linux/kernel.h>
63937+#include <linux/sched.h>
63938+#include <linux/file.h>
63939+#include <linux/tty.h>
63940+#include <linux/fs.h>
63941+#include <linux/grinternal.h>
63942+
63943+#ifdef CONFIG_TREE_PREEMPT_RCU
63944+#define DISABLE_PREEMPT() preempt_disable()
63945+#define ENABLE_PREEMPT() preempt_enable()
63946+#else
63947+#define DISABLE_PREEMPT()
63948+#define ENABLE_PREEMPT()
63949+#endif
63950+
63951+#define BEGIN_LOCKS(x) \
63952+ DISABLE_PREEMPT(); \
63953+ rcu_read_lock(); \
63954+ read_lock(&tasklist_lock); \
63955+ read_lock(&grsec_exec_file_lock); \
63956+ if (x != GR_DO_AUDIT) \
63957+ spin_lock(&grsec_alert_lock); \
63958+ else \
63959+ spin_lock(&grsec_audit_lock)
63960+
63961+#define END_LOCKS(x) \
63962+ if (x != GR_DO_AUDIT) \
63963+ spin_unlock(&grsec_alert_lock); \
63964+ else \
63965+ spin_unlock(&grsec_audit_lock); \
63966+ read_unlock(&grsec_exec_file_lock); \
63967+ read_unlock(&tasklist_lock); \
63968+ rcu_read_unlock(); \
63969+ ENABLE_PREEMPT(); \
63970+ if (x == GR_DONT_AUDIT) \
63971+ gr_handle_alertkill(current)
63972+
63973+enum {
63974+ FLOODING,
63975+ NO_FLOODING
63976+};
63977+
63978+extern char *gr_alert_log_fmt;
63979+extern char *gr_audit_log_fmt;
63980+extern char *gr_alert_log_buf;
63981+extern char *gr_audit_log_buf;
63982+
63983+static int gr_log_start(int audit)
63984+{
63985+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
63986+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
63987+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63988+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
63989+ unsigned long curr_secs = get_seconds();
63990+
63991+ if (audit == GR_DO_AUDIT)
63992+ goto set_fmt;
63993+
63994+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
63995+ grsec_alert_wtime = curr_secs;
63996+ grsec_alert_fyet = 0;
63997+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
63998+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
63999+ grsec_alert_fyet++;
64000+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64001+ grsec_alert_wtime = curr_secs;
64002+ grsec_alert_fyet++;
64003+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64004+ return FLOODING;
64005+ }
64006+ else return FLOODING;
64007+
64008+set_fmt:
64009+#endif
64010+ memset(buf, 0, PAGE_SIZE);
64011+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
64012+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64013+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64014+ } else if (current->signal->curr_ip) {
64015+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64016+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64017+ } else if (gr_acl_is_enabled()) {
64018+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64019+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64020+ } else {
64021+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
64022+ strcpy(buf, fmt);
64023+ }
64024+
64025+ return NO_FLOODING;
64026+}
64027+
64028+static void gr_log_middle(int audit, const char *msg, va_list ap)
64029+ __attribute__ ((format (printf, 2, 0)));
64030+
64031+static void gr_log_middle(int audit, const char *msg, va_list ap)
64032+{
64033+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64034+ unsigned int len = strlen(buf);
64035+
64036+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64037+
64038+ return;
64039+}
64040+
64041+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64042+ __attribute__ ((format (printf, 2, 3)));
64043+
64044+static void gr_log_middle_varargs(int audit, const char *msg, ...)
64045+{
64046+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64047+ unsigned int len = strlen(buf);
64048+ va_list ap;
64049+
64050+ va_start(ap, msg);
64051+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64052+ va_end(ap);
64053+
64054+ return;
64055+}
64056+
64057+static void gr_log_end(int audit, int append_default)
64058+{
64059+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64060+ if (append_default) {
64061+ struct task_struct *task = current;
64062+ struct task_struct *parent = task->real_parent;
64063+ const struct cred *cred = __task_cred(task);
64064+ const struct cred *pcred = __task_cred(parent);
64065+ unsigned int len = strlen(buf);
64066+
64067+ 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));
64068+ }
64069+
64070+ printk("%s\n", buf);
64071+
64072+ return;
64073+}
64074+
64075+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64076+{
64077+ int logtype;
64078+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64079+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64080+ void *voidptr = NULL;
64081+ int num1 = 0, num2 = 0;
64082+ unsigned long ulong1 = 0, ulong2 = 0;
64083+ struct dentry *dentry = NULL;
64084+ struct vfsmount *mnt = NULL;
64085+ struct file *file = NULL;
64086+ struct task_struct *task = NULL;
64087+ const struct cred *cred, *pcred;
64088+ va_list ap;
64089+
64090+ BEGIN_LOCKS(audit);
64091+ logtype = gr_log_start(audit);
64092+ if (logtype == FLOODING) {
64093+ END_LOCKS(audit);
64094+ return;
64095+ }
64096+ va_start(ap, argtypes);
64097+ switch (argtypes) {
64098+ case GR_TTYSNIFF:
64099+ task = va_arg(ap, struct task_struct *);
64100+ 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));
64101+ break;
64102+ case GR_SYSCTL_HIDDEN:
64103+ str1 = va_arg(ap, char *);
64104+ gr_log_middle_varargs(audit, msg, result, str1);
64105+ break;
64106+ case GR_RBAC:
64107+ dentry = va_arg(ap, struct dentry *);
64108+ mnt = va_arg(ap, struct vfsmount *);
64109+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64110+ break;
64111+ case GR_RBAC_STR:
64112+ dentry = va_arg(ap, struct dentry *);
64113+ mnt = va_arg(ap, struct vfsmount *);
64114+ str1 = va_arg(ap, char *);
64115+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64116+ break;
64117+ case GR_STR_RBAC:
64118+ str1 = va_arg(ap, char *);
64119+ dentry = va_arg(ap, struct dentry *);
64120+ mnt = va_arg(ap, struct vfsmount *);
64121+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64122+ break;
64123+ case GR_RBAC_MODE2:
64124+ dentry = va_arg(ap, struct dentry *);
64125+ mnt = va_arg(ap, struct vfsmount *);
64126+ str1 = va_arg(ap, char *);
64127+ str2 = va_arg(ap, char *);
64128+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64129+ break;
64130+ case GR_RBAC_MODE3:
64131+ dentry = va_arg(ap, struct dentry *);
64132+ mnt = va_arg(ap, struct vfsmount *);
64133+ str1 = va_arg(ap, char *);
64134+ str2 = va_arg(ap, char *);
64135+ str3 = va_arg(ap, char *);
64136+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64137+ break;
64138+ case GR_FILENAME:
64139+ dentry = va_arg(ap, struct dentry *);
64140+ mnt = va_arg(ap, struct vfsmount *);
64141+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64142+ break;
64143+ case GR_STR_FILENAME:
64144+ str1 = va_arg(ap, char *);
64145+ dentry = va_arg(ap, struct dentry *);
64146+ mnt = va_arg(ap, struct vfsmount *);
64147+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64148+ break;
64149+ case GR_FILENAME_STR:
64150+ dentry = va_arg(ap, struct dentry *);
64151+ mnt = va_arg(ap, struct vfsmount *);
64152+ str1 = va_arg(ap, char *);
64153+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64154+ break;
64155+ case GR_FILENAME_TWO_INT:
64156+ dentry = va_arg(ap, struct dentry *);
64157+ mnt = va_arg(ap, struct vfsmount *);
64158+ num1 = va_arg(ap, int);
64159+ num2 = va_arg(ap, int);
64160+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64161+ break;
64162+ case GR_FILENAME_TWO_INT_STR:
64163+ dentry = va_arg(ap, struct dentry *);
64164+ mnt = va_arg(ap, struct vfsmount *);
64165+ num1 = va_arg(ap, int);
64166+ num2 = va_arg(ap, int);
64167+ str1 = va_arg(ap, char *);
64168+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64169+ break;
64170+ case GR_TEXTREL:
64171+ file = va_arg(ap, struct file *);
64172+ ulong1 = va_arg(ap, unsigned long);
64173+ ulong2 = va_arg(ap, unsigned long);
64174+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64175+ break;
64176+ case GR_PTRACE:
64177+ task = va_arg(ap, struct task_struct *);
64178+ 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));
64179+ break;
64180+ case GR_RESOURCE:
64181+ task = va_arg(ap, struct task_struct *);
64182+ cred = __task_cred(task);
64183+ pcred = __task_cred(task->real_parent);
64184+ ulong1 = va_arg(ap, unsigned long);
64185+ str1 = va_arg(ap, char *);
64186+ ulong2 = va_arg(ap, unsigned long);
64187+ 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));
64188+ break;
64189+ case GR_CAP:
64190+ task = va_arg(ap, struct task_struct *);
64191+ cred = __task_cred(task);
64192+ pcred = __task_cred(task->real_parent);
64193+ str1 = va_arg(ap, char *);
64194+ 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));
64195+ break;
64196+ case GR_SIG:
64197+ str1 = va_arg(ap, char *);
64198+ voidptr = va_arg(ap, void *);
64199+ gr_log_middle_varargs(audit, msg, str1, voidptr);
64200+ break;
64201+ case GR_SIG2:
64202+ task = va_arg(ap, struct task_struct *);
64203+ cred = __task_cred(task);
64204+ pcred = __task_cred(task->real_parent);
64205+ num1 = va_arg(ap, int);
64206+ 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));
64207+ break;
64208+ case GR_CRASH1:
64209+ task = va_arg(ap, struct task_struct *);
64210+ cred = __task_cred(task);
64211+ pcred = __task_cred(task->real_parent);
64212+ ulong1 = va_arg(ap, unsigned long);
64213+ 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);
64214+ break;
64215+ case GR_CRASH2:
64216+ task = va_arg(ap, struct task_struct *);
64217+ cred = __task_cred(task);
64218+ pcred = __task_cred(task->real_parent);
64219+ ulong1 = va_arg(ap, unsigned long);
64220+ 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);
64221+ break;
64222+ case GR_RWXMAP:
64223+ file = va_arg(ap, struct file *);
64224+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64225+ break;
64226+ case GR_PSACCT:
64227+ {
64228+ unsigned int wday, cday;
64229+ __u8 whr, chr;
64230+ __u8 wmin, cmin;
64231+ __u8 wsec, csec;
64232+ char cur_tty[64] = { 0 };
64233+ char parent_tty[64] = { 0 };
64234+
64235+ task = va_arg(ap, struct task_struct *);
64236+ wday = va_arg(ap, unsigned int);
64237+ cday = va_arg(ap, unsigned int);
64238+ whr = va_arg(ap, int);
64239+ chr = va_arg(ap, int);
64240+ wmin = va_arg(ap, int);
64241+ cmin = va_arg(ap, int);
64242+ wsec = va_arg(ap, int);
64243+ csec = va_arg(ap, int);
64244+ ulong1 = va_arg(ap, unsigned long);
64245+ cred = __task_cred(task);
64246+ pcred = __task_cred(task->real_parent);
64247+
64248+ 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));
64249+ }
64250+ break;
64251+ default:
64252+ gr_log_middle(audit, msg, ap);
64253+ }
64254+ va_end(ap);
64255+ // these don't need DEFAULTSECARGS printed on the end
64256+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64257+ gr_log_end(audit, 0);
64258+ else
64259+ gr_log_end(audit, 1);
64260+ END_LOCKS(audit);
64261+}
64262diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64263new file mode 100644
64264index 0000000..f536303
64265--- /dev/null
64266+++ b/grsecurity/grsec_mem.c
64267@@ -0,0 +1,40 @@
64268+#include <linux/kernel.h>
64269+#include <linux/sched.h>
64270+#include <linux/mm.h>
64271+#include <linux/mman.h>
64272+#include <linux/grinternal.h>
64273+
64274+void
64275+gr_handle_ioperm(void)
64276+{
64277+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64278+ return;
64279+}
64280+
64281+void
64282+gr_handle_iopl(void)
64283+{
64284+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64285+ return;
64286+}
64287+
64288+void
64289+gr_handle_mem_readwrite(u64 from, u64 to)
64290+{
64291+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64292+ return;
64293+}
64294+
64295+void
64296+gr_handle_vm86(void)
64297+{
64298+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64299+ return;
64300+}
64301+
64302+void
64303+gr_log_badprocpid(const char *entry)
64304+{
64305+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64306+ return;
64307+}
64308diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64309new file mode 100644
64310index 0000000..2131422
64311--- /dev/null
64312+++ b/grsecurity/grsec_mount.c
64313@@ -0,0 +1,62 @@
64314+#include <linux/kernel.h>
64315+#include <linux/sched.h>
64316+#include <linux/mount.h>
64317+#include <linux/grsecurity.h>
64318+#include <linux/grinternal.h>
64319+
64320+void
64321+gr_log_remount(const char *devname, const int retval)
64322+{
64323+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64324+ if (grsec_enable_mount && (retval >= 0))
64325+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64326+#endif
64327+ return;
64328+}
64329+
64330+void
64331+gr_log_unmount(const char *devname, const int retval)
64332+{
64333+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64334+ if (grsec_enable_mount && (retval >= 0))
64335+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64336+#endif
64337+ return;
64338+}
64339+
64340+void
64341+gr_log_mount(const char *from, const char *to, const int retval)
64342+{
64343+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64344+ if (grsec_enable_mount && (retval >= 0))
64345+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64346+#endif
64347+ return;
64348+}
64349+
64350+int
64351+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64352+{
64353+#ifdef CONFIG_GRKERNSEC_ROFS
64354+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64355+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64356+ return -EPERM;
64357+ } else
64358+ return 0;
64359+#endif
64360+ return 0;
64361+}
64362+
64363+int
64364+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64365+{
64366+#ifdef CONFIG_GRKERNSEC_ROFS
64367+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64368+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64369+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64370+ return -EPERM;
64371+ } else
64372+ return 0;
64373+#endif
64374+ return 0;
64375+}
64376diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64377new file mode 100644
64378index 0000000..a3b12a0
64379--- /dev/null
64380+++ b/grsecurity/grsec_pax.c
64381@@ -0,0 +1,36 @@
64382+#include <linux/kernel.h>
64383+#include <linux/sched.h>
64384+#include <linux/mm.h>
64385+#include <linux/file.h>
64386+#include <linux/grinternal.h>
64387+#include <linux/grsecurity.h>
64388+
64389+void
64390+gr_log_textrel(struct vm_area_struct * vma)
64391+{
64392+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64393+ if (grsec_enable_audit_textrel)
64394+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64395+#endif
64396+ return;
64397+}
64398+
64399+void
64400+gr_log_rwxmmap(struct file *file)
64401+{
64402+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64403+ if (grsec_enable_log_rwxmaps)
64404+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64405+#endif
64406+ return;
64407+}
64408+
64409+void
64410+gr_log_rwxmprotect(struct file *file)
64411+{
64412+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64413+ if (grsec_enable_log_rwxmaps)
64414+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64415+#endif
64416+ return;
64417+}
64418diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64419new file mode 100644
64420index 0000000..f7f29aa
64421--- /dev/null
64422+++ b/grsecurity/grsec_ptrace.c
64423@@ -0,0 +1,30 @@
64424+#include <linux/kernel.h>
64425+#include <linux/sched.h>
64426+#include <linux/grinternal.h>
64427+#include <linux/security.h>
64428+
64429+void
64430+gr_audit_ptrace(struct task_struct *task)
64431+{
64432+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64433+ if (grsec_enable_audit_ptrace)
64434+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64435+#endif
64436+ return;
64437+}
64438+
64439+int
64440+gr_ptrace_readexec(struct file *file, int unsafe_flags)
64441+{
64442+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64443+ const struct dentry *dentry = file->f_path.dentry;
64444+ const struct vfsmount *mnt = file->f_path.mnt;
64445+
64446+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64447+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64448+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64449+ return -EACCES;
64450+ }
64451+#endif
64452+ return 0;
64453+}
64454diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64455new file mode 100644
64456index 0000000..e09715a
64457--- /dev/null
64458+++ b/grsecurity/grsec_sig.c
64459@@ -0,0 +1,222 @@
64460+#include <linux/kernel.h>
64461+#include <linux/sched.h>
64462+#include <linux/delay.h>
64463+#include <linux/grsecurity.h>
64464+#include <linux/grinternal.h>
64465+#include <linux/hardirq.h>
64466+
64467+char *signames[] = {
64468+ [SIGSEGV] = "Segmentation fault",
64469+ [SIGILL] = "Illegal instruction",
64470+ [SIGABRT] = "Abort",
64471+ [SIGBUS] = "Invalid alignment/Bus error"
64472+};
64473+
64474+void
64475+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64476+{
64477+#ifdef CONFIG_GRKERNSEC_SIGNAL
64478+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64479+ (sig == SIGABRT) || (sig == SIGBUS))) {
64480+ if (task_pid_nr(t) == task_pid_nr(current)) {
64481+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64482+ } else {
64483+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64484+ }
64485+ }
64486+#endif
64487+ return;
64488+}
64489+
64490+int
64491+gr_handle_signal(const struct task_struct *p, const int sig)
64492+{
64493+#ifdef CONFIG_GRKERNSEC
64494+ /* ignore the 0 signal for protected task checks */
64495+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64496+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64497+ return -EPERM;
64498+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64499+ return -EPERM;
64500+ }
64501+#endif
64502+ return 0;
64503+}
64504+
64505+#ifdef CONFIG_GRKERNSEC
64506+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64507+
64508+int gr_fake_force_sig(int sig, struct task_struct *t)
64509+{
64510+ unsigned long int flags;
64511+ int ret, blocked, ignored;
64512+ struct k_sigaction *action;
64513+
64514+ spin_lock_irqsave(&t->sighand->siglock, flags);
64515+ action = &t->sighand->action[sig-1];
64516+ ignored = action->sa.sa_handler == SIG_IGN;
64517+ blocked = sigismember(&t->blocked, sig);
64518+ if (blocked || ignored) {
64519+ action->sa.sa_handler = SIG_DFL;
64520+ if (blocked) {
64521+ sigdelset(&t->blocked, sig);
64522+ recalc_sigpending_and_wake(t);
64523+ }
64524+ }
64525+ if (action->sa.sa_handler == SIG_DFL)
64526+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
64527+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64528+
64529+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
64530+
64531+ return ret;
64532+}
64533+#endif
64534+
64535+#ifdef CONFIG_GRKERNSEC_BRUTE
64536+#define GR_USER_BAN_TIME (15 * 60)
64537+#define GR_DAEMON_BRUTE_TIME (30 * 60)
64538+
64539+static int __get_dumpable(unsigned long mm_flags)
64540+{
64541+ int ret;
64542+
64543+ ret = mm_flags & MMF_DUMPABLE_MASK;
64544+ return (ret >= 2) ? 2 : ret;
64545+}
64546+#endif
64547+
64548+void gr_handle_brute_attach(unsigned long mm_flags)
64549+{
64550+#ifdef CONFIG_GRKERNSEC_BRUTE
64551+ struct task_struct *p = current;
64552+ kuid_t uid = GLOBAL_ROOT_UID;
64553+ int daemon = 0;
64554+
64555+ if (!grsec_enable_brute)
64556+ return;
64557+
64558+ rcu_read_lock();
64559+ read_lock(&tasklist_lock);
64560+ read_lock(&grsec_exec_file_lock);
64561+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
64562+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
64563+ p->real_parent->brute = 1;
64564+ daemon = 1;
64565+ } else {
64566+ const struct cred *cred = __task_cred(p), *cred2;
64567+ struct task_struct *tsk, *tsk2;
64568+
64569+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
64570+ struct user_struct *user;
64571+
64572+ uid = cred->uid;
64573+
64574+ /* this is put upon execution past expiration */
64575+ user = find_user(uid);
64576+ if (user == NULL)
64577+ goto unlock;
64578+ user->banned = 1;
64579+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
64580+ if (user->ban_expires == ~0UL)
64581+ user->ban_expires--;
64582+
64583+ do_each_thread(tsk2, tsk) {
64584+ cred2 = __task_cred(tsk);
64585+ if (tsk != p && uid_eq(cred2->uid, uid))
64586+ gr_fake_force_sig(SIGKILL, tsk);
64587+ } while_each_thread(tsk2, tsk);
64588+ }
64589+ }
64590+unlock:
64591+ read_unlock(&grsec_exec_file_lock);
64592+ read_unlock(&tasklist_lock);
64593+ rcu_read_unlock();
64594+
64595+ if (gr_is_global_nonroot(uid))
64596+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
64597+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
64598+ else if (daemon)
64599+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
64600+
64601+#endif
64602+ return;
64603+}
64604+
64605+void gr_handle_brute_check(void)
64606+{
64607+#ifdef CONFIG_GRKERNSEC_BRUTE
64608+ struct task_struct *p = current;
64609+
64610+ if (unlikely(p->brute)) {
64611+ if (!grsec_enable_brute)
64612+ p->brute = 0;
64613+ else if (time_before(get_seconds(), p->brute_expires))
64614+ msleep(30 * 1000);
64615+ }
64616+#endif
64617+ return;
64618+}
64619+
64620+void gr_handle_kernel_exploit(void)
64621+{
64622+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
64623+ const struct cred *cred;
64624+ struct task_struct *tsk, *tsk2;
64625+ struct user_struct *user;
64626+ kuid_t uid;
64627+
64628+ if (in_irq() || in_serving_softirq() || in_nmi())
64629+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
64630+
64631+ uid = current_uid();
64632+
64633+ if (gr_is_global_root(uid))
64634+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
64635+ else {
64636+ /* kill all the processes of this user, hold a reference
64637+ to their creds struct, and prevent them from creating
64638+ another process until system reset
64639+ */
64640+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
64641+ GR_GLOBAL_UID(uid));
64642+ /* we intentionally leak this ref */
64643+ user = get_uid(current->cred->user);
64644+ if (user) {
64645+ user->banned = 1;
64646+ user->ban_expires = ~0UL;
64647+ }
64648+
64649+ read_lock(&tasklist_lock);
64650+ do_each_thread(tsk2, tsk) {
64651+ cred = __task_cred(tsk);
64652+ if (uid_eq(cred->uid, uid))
64653+ gr_fake_force_sig(SIGKILL, tsk);
64654+ } while_each_thread(tsk2, tsk);
64655+ read_unlock(&tasklist_lock);
64656+ }
64657+#endif
64658+}
64659+
64660+int __gr_process_user_ban(struct user_struct *user)
64661+{
64662+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64663+ if (unlikely(user->banned)) {
64664+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
64665+ user->banned = 0;
64666+ user->ban_expires = 0;
64667+ free_uid(user);
64668+ } else
64669+ return -EPERM;
64670+ }
64671+#endif
64672+ return 0;
64673+}
64674+
64675+int gr_process_user_ban(void)
64676+{
64677+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64678+ return __gr_process_user_ban(current->cred->user);
64679+#endif
64680+ return 0;
64681+}
64682diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
64683new file mode 100644
64684index 0000000..4030d57
64685--- /dev/null
64686+++ b/grsecurity/grsec_sock.c
64687@@ -0,0 +1,244 @@
64688+#include <linux/kernel.h>
64689+#include <linux/module.h>
64690+#include <linux/sched.h>
64691+#include <linux/file.h>
64692+#include <linux/net.h>
64693+#include <linux/in.h>
64694+#include <linux/ip.h>
64695+#include <net/sock.h>
64696+#include <net/inet_sock.h>
64697+#include <linux/grsecurity.h>
64698+#include <linux/grinternal.h>
64699+#include <linux/gracl.h>
64700+
64701+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
64702+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
64703+
64704+EXPORT_SYMBOL(gr_search_udp_recvmsg);
64705+EXPORT_SYMBOL(gr_search_udp_sendmsg);
64706+
64707+#ifdef CONFIG_UNIX_MODULE
64708+EXPORT_SYMBOL(gr_acl_handle_unix);
64709+EXPORT_SYMBOL(gr_acl_handle_mknod);
64710+EXPORT_SYMBOL(gr_handle_chroot_unix);
64711+EXPORT_SYMBOL(gr_handle_create);
64712+#endif
64713+
64714+#ifdef CONFIG_GRKERNSEC
64715+#define gr_conn_table_size 32749
64716+struct conn_table_entry {
64717+ struct conn_table_entry *next;
64718+ struct signal_struct *sig;
64719+};
64720+
64721+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
64722+DEFINE_SPINLOCK(gr_conn_table_lock);
64723+
64724+extern const char * gr_socktype_to_name(unsigned char type);
64725+extern const char * gr_proto_to_name(unsigned char proto);
64726+extern const char * gr_sockfamily_to_name(unsigned char family);
64727+
64728+static __inline__ int
64729+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
64730+{
64731+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
64732+}
64733+
64734+static __inline__ int
64735+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
64736+ __u16 sport, __u16 dport)
64737+{
64738+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
64739+ sig->gr_sport == sport && sig->gr_dport == dport))
64740+ return 1;
64741+ else
64742+ return 0;
64743+}
64744+
64745+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
64746+{
64747+ struct conn_table_entry **match;
64748+ unsigned int index;
64749+
64750+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64751+ sig->gr_sport, sig->gr_dport,
64752+ gr_conn_table_size);
64753+
64754+ newent->sig = sig;
64755+
64756+ match = &gr_conn_table[index];
64757+ newent->next = *match;
64758+ *match = newent;
64759+
64760+ return;
64761+}
64762+
64763+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
64764+{
64765+ struct conn_table_entry *match, *last = NULL;
64766+ unsigned int index;
64767+
64768+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64769+ sig->gr_sport, sig->gr_dport,
64770+ gr_conn_table_size);
64771+
64772+ match = gr_conn_table[index];
64773+ while (match && !conn_match(match->sig,
64774+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
64775+ sig->gr_dport)) {
64776+ last = match;
64777+ match = match->next;
64778+ }
64779+
64780+ if (match) {
64781+ if (last)
64782+ last->next = match->next;
64783+ else
64784+ gr_conn_table[index] = NULL;
64785+ kfree(match);
64786+ }
64787+
64788+ return;
64789+}
64790+
64791+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
64792+ __u16 sport, __u16 dport)
64793+{
64794+ struct conn_table_entry *match;
64795+ unsigned int index;
64796+
64797+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
64798+
64799+ match = gr_conn_table[index];
64800+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
64801+ match = match->next;
64802+
64803+ if (match)
64804+ return match->sig;
64805+ else
64806+ return NULL;
64807+}
64808+
64809+#endif
64810+
64811+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
64812+{
64813+#ifdef CONFIG_GRKERNSEC
64814+ struct signal_struct *sig = task->signal;
64815+ struct conn_table_entry *newent;
64816+
64817+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
64818+ if (newent == NULL)
64819+ return;
64820+ /* no bh lock needed since we are called with bh disabled */
64821+ spin_lock(&gr_conn_table_lock);
64822+ gr_del_task_from_ip_table_nolock(sig);
64823+ sig->gr_saddr = inet->inet_rcv_saddr;
64824+ sig->gr_daddr = inet->inet_daddr;
64825+ sig->gr_sport = inet->inet_sport;
64826+ sig->gr_dport = inet->inet_dport;
64827+ gr_add_to_task_ip_table_nolock(sig, newent);
64828+ spin_unlock(&gr_conn_table_lock);
64829+#endif
64830+ return;
64831+}
64832+
64833+void gr_del_task_from_ip_table(struct task_struct *task)
64834+{
64835+#ifdef CONFIG_GRKERNSEC
64836+ spin_lock_bh(&gr_conn_table_lock);
64837+ gr_del_task_from_ip_table_nolock(task->signal);
64838+ spin_unlock_bh(&gr_conn_table_lock);
64839+#endif
64840+ return;
64841+}
64842+
64843+void
64844+gr_attach_curr_ip(const struct sock *sk)
64845+{
64846+#ifdef CONFIG_GRKERNSEC
64847+ struct signal_struct *p, *set;
64848+ const struct inet_sock *inet = inet_sk(sk);
64849+
64850+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
64851+ return;
64852+
64853+ set = current->signal;
64854+
64855+ spin_lock_bh(&gr_conn_table_lock);
64856+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
64857+ inet->inet_dport, inet->inet_sport);
64858+ if (unlikely(p != NULL)) {
64859+ set->curr_ip = p->curr_ip;
64860+ set->used_accept = 1;
64861+ gr_del_task_from_ip_table_nolock(p);
64862+ spin_unlock_bh(&gr_conn_table_lock);
64863+ return;
64864+ }
64865+ spin_unlock_bh(&gr_conn_table_lock);
64866+
64867+ set->curr_ip = inet->inet_daddr;
64868+ set->used_accept = 1;
64869+#endif
64870+ return;
64871+}
64872+
64873+int
64874+gr_handle_sock_all(const int family, const int type, const int protocol)
64875+{
64876+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64877+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
64878+ (family != AF_UNIX)) {
64879+ if (family == AF_INET)
64880+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
64881+ else
64882+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
64883+ return -EACCES;
64884+ }
64885+#endif
64886+ return 0;
64887+}
64888+
64889+int
64890+gr_handle_sock_server(const struct sockaddr *sck)
64891+{
64892+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64893+ if (grsec_enable_socket_server &&
64894+ in_group_p(grsec_socket_server_gid) &&
64895+ sck && (sck->sa_family != AF_UNIX) &&
64896+ (sck->sa_family != AF_LOCAL)) {
64897+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64898+ return -EACCES;
64899+ }
64900+#endif
64901+ return 0;
64902+}
64903+
64904+int
64905+gr_handle_sock_server_other(const struct sock *sck)
64906+{
64907+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64908+ if (grsec_enable_socket_server &&
64909+ in_group_p(grsec_socket_server_gid) &&
64910+ sck && (sck->sk_family != AF_UNIX) &&
64911+ (sck->sk_family != AF_LOCAL)) {
64912+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64913+ return -EACCES;
64914+ }
64915+#endif
64916+ return 0;
64917+}
64918+
64919+int
64920+gr_handle_sock_client(const struct sockaddr *sck)
64921+{
64922+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64923+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
64924+ sck && (sck->sa_family != AF_UNIX) &&
64925+ (sck->sa_family != AF_LOCAL)) {
64926+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
64927+ return -EACCES;
64928+ }
64929+#endif
64930+ return 0;
64931+}
64932diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
64933new file mode 100644
64934index 0000000..f55ef0f
64935--- /dev/null
64936+++ b/grsecurity/grsec_sysctl.c
64937@@ -0,0 +1,469 @@
64938+#include <linux/kernel.h>
64939+#include <linux/sched.h>
64940+#include <linux/sysctl.h>
64941+#include <linux/grsecurity.h>
64942+#include <linux/grinternal.h>
64943+
64944+int
64945+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
64946+{
64947+#ifdef CONFIG_GRKERNSEC_SYSCTL
64948+ if (dirname == NULL || name == NULL)
64949+ return 0;
64950+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
64951+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
64952+ return -EACCES;
64953+ }
64954+#endif
64955+ return 0;
64956+}
64957+
64958+#ifdef CONFIG_GRKERNSEC_ROFS
64959+static int __maybe_unused one = 1;
64960+#endif
64961+
64962+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
64963+struct ctl_table grsecurity_table[] = {
64964+#ifdef CONFIG_GRKERNSEC_SYSCTL
64965+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
64966+#ifdef CONFIG_GRKERNSEC_IO
64967+ {
64968+ .procname = "disable_priv_io",
64969+ .data = &grsec_disable_privio,
64970+ .maxlen = sizeof(int),
64971+ .mode = 0600,
64972+ .proc_handler = &proc_dointvec,
64973+ },
64974+#endif
64975+#endif
64976+#ifdef CONFIG_GRKERNSEC_LINK
64977+ {
64978+ .procname = "linking_restrictions",
64979+ .data = &grsec_enable_link,
64980+ .maxlen = sizeof(int),
64981+ .mode = 0600,
64982+ .proc_handler = &proc_dointvec,
64983+ },
64984+#endif
64985+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64986+ {
64987+ .procname = "enforce_symlinksifowner",
64988+ .data = &grsec_enable_symlinkown,
64989+ .maxlen = sizeof(int),
64990+ .mode = 0600,
64991+ .proc_handler = &proc_dointvec,
64992+ },
64993+ {
64994+ .procname = "symlinkown_gid",
64995+ .data = &grsec_symlinkown_gid,
64996+ .maxlen = sizeof(int),
64997+ .mode = 0600,
64998+ .proc_handler = &proc_dointvec,
64999+ },
65000+#endif
65001+#ifdef CONFIG_GRKERNSEC_BRUTE
65002+ {
65003+ .procname = "deter_bruteforce",
65004+ .data = &grsec_enable_brute,
65005+ .maxlen = sizeof(int),
65006+ .mode = 0600,
65007+ .proc_handler = &proc_dointvec,
65008+ },
65009+#endif
65010+#ifdef CONFIG_GRKERNSEC_FIFO
65011+ {
65012+ .procname = "fifo_restrictions",
65013+ .data = &grsec_enable_fifo,
65014+ .maxlen = sizeof(int),
65015+ .mode = 0600,
65016+ .proc_handler = &proc_dointvec,
65017+ },
65018+#endif
65019+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65020+ {
65021+ .procname = "ptrace_readexec",
65022+ .data = &grsec_enable_ptrace_readexec,
65023+ .maxlen = sizeof(int),
65024+ .mode = 0600,
65025+ .proc_handler = &proc_dointvec,
65026+ },
65027+#endif
65028+#ifdef CONFIG_GRKERNSEC_SETXID
65029+ {
65030+ .procname = "consistent_setxid",
65031+ .data = &grsec_enable_setxid,
65032+ .maxlen = sizeof(int),
65033+ .mode = 0600,
65034+ .proc_handler = &proc_dointvec,
65035+ },
65036+#endif
65037+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65038+ {
65039+ .procname = "ip_blackhole",
65040+ .data = &grsec_enable_blackhole,
65041+ .maxlen = sizeof(int),
65042+ .mode = 0600,
65043+ .proc_handler = &proc_dointvec,
65044+ },
65045+ {
65046+ .procname = "lastack_retries",
65047+ .data = &grsec_lastack_retries,
65048+ .maxlen = sizeof(int),
65049+ .mode = 0600,
65050+ .proc_handler = &proc_dointvec,
65051+ },
65052+#endif
65053+#ifdef CONFIG_GRKERNSEC_EXECLOG
65054+ {
65055+ .procname = "exec_logging",
65056+ .data = &grsec_enable_execlog,
65057+ .maxlen = sizeof(int),
65058+ .mode = 0600,
65059+ .proc_handler = &proc_dointvec,
65060+ },
65061+#endif
65062+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65063+ {
65064+ .procname = "rwxmap_logging",
65065+ .data = &grsec_enable_log_rwxmaps,
65066+ .maxlen = sizeof(int),
65067+ .mode = 0600,
65068+ .proc_handler = &proc_dointvec,
65069+ },
65070+#endif
65071+#ifdef CONFIG_GRKERNSEC_SIGNAL
65072+ {
65073+ .procname = "signal_logging",
65074+ .data = &grsec_enable_signal,
65075+ .maxlen = sizeof(int),
65076+ .mode = 0600,
65077+ .proc_handler = &proc_dointvec,
65078+ },
65079+#endif
65080+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65081+ {
65082+ .procname = "forkfail_logging",
65083+ .data = &grsec_enable_forkfail,
65084+ .maxlen = sizeof(int),
65085+ .mode = 0600,
65086+ .proc_handler = &proc_dointvec,
65087+ },
65088+#endif
65089+#ifdef CONFIG_GRKERNSEC_TIME
65090+ {
65091+ .procname = "timechange_logging",
65092+ .data = &grsec_enable_time,
65093+ .maxlen = sizeof(int),
65094+ .mode = 0600,
65095+ .proc_handler = &proc_dointvec,
65096+ },
65097+#endif
65098+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65099+ {
65100+ .procname = "chroot_deny_shmat",
65101+ .data = &grsec_enable_chroot_shmat,
65102+ .maxlen = sizeof(int),
65103+ .mode = 0600,
65104+ .proc_handler = &proc_dointvec,
65105+ },
65106+#endif
65107+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65108+ {
65109+ .procname = "chroot_deny_unix",
65110+ .data = &grsec_enable_chroot_unix,
65111+ .maxlen = sizeof(int),
65112+ .mode = 0600,
65113+ .proc_handler = &proc_dointvec,
65114+ },
65115+#endif
65116+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65117+ {
65118+ .procname = "chroot_deny_mount",
65119+ .data = &grsec_enable_chroot_mount,
65120+ .maxlen = sizeof(int),
65121+ .mode = 0600,
65122+ .proc_handler = &proc_dointvec,
65123+ },
65124+#endif
65125+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65126+ {
65127+ .procname = "chroot_deny_fchdir",
65128+ .data = &grsec_enable_chroot_fchdir,
65129+ .maxlen = sizeof(int),
65130+ .mode = 0600,
65131+ .proc_handler = &proc_dointvec,
65132+ },
65133+#endif
65134+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65135+ {
65136+ .procname = "chroot_deny_chroot",
65137+ .data = &grsec_enable_chroot_double,
65138+ .maxlen = sizeof(int),
65139+ .mode = 0600,
65140+ .proc_handler = &proc_dointvec,
65141+ },
65142+#endif
65143+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65144+ {
65145+ .procname = "chroot_deny_pivot",
65146+ .data = &grsec_enable_chroot_pivot,
65147+ .maxlen = sizeof(int),
65148+ .mode = 0600,
65149+ .proc_handler = &proc_dointvec,
65150+ },
65151+#endif
65152+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65153+ {
65154+ .procname = "chroot_enforce_chdir",
65155+ .data = &grsec_enable_chroot_chdir,
65156+ .maxlen = sizeof(int),
65157+ .mode = 0600,
65158+ .proc_handler = &proc_dointvec,
65159+ },
65160+#endif
65161+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65162+ {
65163+ .procname = "chroot_deny_chmod",
65164+ .data = &grsec_enable_chroot_chmod,
65165+ .maxlen = sizeof(int),
65166+ .mode = 0600,
65167+ .proc_handler = &proc_dointvec,
65168+ },
65169+#endif
65170+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65171+ {
65172+ .procname = "chroot_deny_mknod",
65173+ .data = &grsec_enable_chroot_mknod,
65174+ .maxlen = sizeof(int),
65175+ .mode = 0600,
65176+ .proc_handler = &proc_dointvec,
65177+ },
65178+#endif
65179+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65180+ {
65181+ .procname = "chroot_restrict_nice",
65182+ .data = &grsec_enable_chroot_nice,
65183+ .maxlen = sizeof(int),
65184+ .mode = 0600,
65185+ .proc_handler = &proc_dointvec,
65186+ },
65187+#endif
65188+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65189+ {
65190+ .procname = "chroot_execlog",
65191+ .data = &grsec_enable_chroot_execlog,
65192+ .maxlen = sizeof(int),
65193+ .mode = 0600,
65194+ .proc_handler = &proc_dointvec,
65195+ },
65196+#endif
65197+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65198+ {
65199+ .procname = "chroot_caps",
65200+ .data = &grsec_enable_chroot_caps,
65201+ .maxlen = sizeof(int),
65202+ .mode = 0600,
65203+ .proc_handler = &proc_dointvec,
65204+ },
65205+#endif
65206+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65207+ {
65208+ .procname = "chroot_deny_sysctl",
65209+ .data = &grsec_enable_chroot_sysctl,
65210+ .maxlen = sizeof(int),
65211+ .mode = 0600,
65212+ .proc_handler = &proc_dointvec,
65213+ },
65214+#endif
65215+#ifdef CONFIG_GRKERNSEC_TPE
65216+ {
65217+ .procname = "tpe",
65218+ .data = &grsec_enable_tpe,
65219+ .maxlen = sizeof(int),
65220+ .mode = 0600,
65221+ .proc_handler = &proc_dointvec,
65222+ },
65223+ {
65224+ .procname = "tpe_gid",
65225+ .data = &grsec_tpe_gid,
65226+ .maxlen = sizeof(int),
65227+ .mode = 0600,
65228+ .proc_handler = &proc_dointvec,
65229+ },
65230+#endif
65231+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65232+ {
65233+ .procname = "tpe_invert",
65234+ .data = &grsec_enable_tpe_invert,
65235+ .maxlen = sizeof(int),
65236+ .mode = 0600,
65237+ .proc_handler = &proc_dointvec,
65238+ },
65239+#endif
65240+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65241+ {
65242+ .procname = "tpe_restrict_all",
65243+ .data = &grsec_enable_tpe_all,
65244+ .maxlen = sizeof(int),
65245+ .mode = 0600,
65246+ .proc_handler = &proc_dointvec,
65247+ },
65248+#endif
65249+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65250+ {
65251+ .procname = "socket_all",
65252+ .data = &grsec_enable_socket_all,
65253+ .maxlen = sizeof(int),
65254+ .mode = 0600,
65255+ .proc_handler = &proc_dointvec,
65256+ },
65257+ {
65258+ .procname = "socket_all_gid",
65259+ .data = &grsec_socket_all_gid,
65260+ .maxlen = sizeof(int),
65261+ .mode = 0600,
65262+ .proc_handler = &proc_dointvec,
65263+ },
65264+#endif
65265+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65266+ {
65267+ .procname = "socket_client",
65268+ .data = &grsec_enable_socket_client,
65269+ .maxlen = sizeof(int),
65270+ .mode = 0600,
65271+ .proc_handler = &proc_dointvec,
65272+ },
65273+ {
65274+ .procname = "socket_client_gid",
65275+ .data = &grsec_socket_client_gid,
65276+ .maxlen = sizeof(int),
65277+ .mode = 0600,
65278+ .proc_handler = &proc_dointvec,
65279+ },
65280+#endif
65281+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65282+ {
65283+ .procname = "socket_server",
65284+ .data = &grsec_enable_socket_server,
65285+ .maxlen = sizeof(int),
65286+ .mode = 0600,
65287+ .proc_handler = &proc_dointvec,
65288+ },
65289+ {
65290+ .procname = "socket_server_gid",
65291+ .data = &grsec_socket_server_gid,
65292+ .maxlen = sizeof(int),
65293+ .mode = 0600,
65294+ .proc_handler = &proc_dointvec,
65295+ },
65296+#endif
65297+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65298+ {
65299+ .procname = "audit_group",
65300+ .data = &grsec_enable_group,
65301+ .maxlen = sizeof(int),
65302+ .mode = 0600,
65303+ .proc_handler = &proc_dointvec,
65304+ },
65305+ {
65306+ .procname = "audit_gid",
65307+ .data = &grsec_audit_gid,
65308+ .maxlen = sizeof(int),
65309+ .mode = 0600,
65310+ .proc_handler = &proc_dointvec,
65311+ },
65312+#endif
65313+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65314+ {
65315+ .procname = "audit_chdir",
65316+ .data = &grsec_enable_chdir,
65317+ .maxlen = sizeof(int),
65318+ .mode = 0600,
65319+ .proc_handler = &proc_dointvec,
65320+ },
65321+#endif
65322+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65323+ {
65324+ .procname = "audit_mount",
65325+ .data = &grsec_enable_mount,
65326+ .maxlen = sizeof(int),
65327+ .mode = 0600,
65328+ .proc_handler = &proc_dointvec,
65329+ },
65330+#endif
65331+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65332+ {
65333+ .procname = "audit_textrel",
65334+ .data = &grsec_enable_audit_textrel,
65335+ .maxlen = sizeof(int),
65336+ .mode = 0600,
65337+ .proc_handler = &proc_dointvec,
65338+ },
65339+#endif
65340+#ifdef CONFIG_GRKERNSEC_DMESG
65341+ {
65342+ .procname = "dmesg",
65343+ .data = &grsec_enable_dmesg,
65344+ .maxlen = sizeof(int),
65345+ .mode = 0600,
65346+ .proc_handler = &proc_dointvec,
65347+ },
65348+#endif
65349+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65350+ {
65351+ .procname = "chroot_findtask",
65352+ .data = &grsec_enable_chroot_findtask,
65353+ .maxlen = sizeof(int),
65354+ .mode = 0600,
65355+ .proc_handler = &proc_dointvec,
65356+ },
65357+#endif
65358+#ifdef CONFIG_GRKERNSEC_RESLOG
65359+ {
65360+ .procname = "resource_logging",
65361+ .data = &grsec_resource_logging,
65362+ .maxlen = sizeof(int),
65363+ .mode = 0600,
65364+ .proc_handler = &proc_dointvec,
65365+ },
65366+#endif
65367+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65368+ {
65369+ .procname = "audit_ptrace",
65370+ .data = &grsec_enable_audit_ptrace,
65371+ .maxlen = sizeof(int),
65372+ .mode = 0600,
65373+ .proc_handler = &proc_dointvec,
65374+ },
65375+#endif
65376+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65377+ {
65378+ .procname = "harden_ptrace",
65379+ .data = &grsec_enable_harden_ptrace,
65380+ .maxlen = sizeof(int),
65381+ .mode = 0600,
65382+ .proc_handler = &proc_dointvec,
65383+ },
65384+#endif
65385+ {
65386+ .procname = "grsec_lock",
65387+ .data = &grsec_lock,
65388+ .maxlen = sizeof(int),
65389+ .mode = 0600,
65390+ .proc_handler = &proc_dointvec,
65391+ },
65392+#endif
65393+#ifdef CONFIG_GRKERNSEC_ROFS
65394+ {
65395+ .procname = "romount_protect",
65396+ .data = &grsec_enable_rofs,
65397+ .maxlen = sizeof(int),
65398+ .mode = 0600,
65399+ .proc_handler = &proc_dointvec_minmax,
65400+ .extra1 = &one,
65401+ .extra2 = &one,
65402+ },
65403+#endif
65404+ { }
65405+};
65406+#endif
65407diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65408new file mode 100644
65409index 0000000..0dc13c3
65410--- /dev/null
65411+++ b/grsecurity/grsec_time.c
65412@@ -0,0 +1,16 @@
65413+#include <linux/kernel.h>
65414+#include <linux/sched.h>
65415+#include <linux/grinternal.h>
65416+#include <linux/module.h>
65417+
65418+void
65419+gr_log_timechange(void)
65420+{
65421+#ifdef CONFIG_GRKERNSEC_TIME
65422+ if (grsec_enable_time)
65423+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65424+#endif
65425+ return;
65426+}
65427+
65428+EXPORT_SYMBOL(gr_log_timechange);
65429diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65430new file mode 100644
65431index 0000000..ee57dcf
65432--- /dev/null
65433+++ b/grsecurity/grsec_tpe.c
65434@@ -0,0 +1,73 @@
65435+#include <linux/kernel.h>
65436+#include <linux/sched.h>
65437+#include <linux/file.h>
65438+#include <linux/fs.h>
65439+#include <linux/grinternal.h>
65440+
65441+extern int gr_acl_tpe_check(void);
65442+
65443+int
65444+gr_tpe_allow(const struct file *file)
65445+{
65446+#ifdef CONFIG_GRKERNSEC
65447+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65448+ const struct cred *cred = current_cred();
65449+ char *msg = NULL;
65450+ char *msg2 = NULL;
65451+
65452+ // never restrict root
65453+ if (gr_is_global_root(cred->uid))
65454+ return 1;
65455+
65456+ if (grsec_enable_tpe) {
65457+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65458+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65459+ msg = "not being in trusted group";
65460+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65461+ msg = "being in untrusted group";
65462+#else
65463+ if (in_group_p(grsec_tpe_gid))
65464+ msg = "being in untrusted group";
65465+#endif
65466+ }
65467+ if (!msg && gr_acl_tpe_check())
65468+ msg = "being in untrusted role";
65469+
65470+ // not in any affected group/role
65471+ if (!msg)
65472+ goto next_check;
65473+
65474+ if (gr_is_global_nonroot(inode->i_uid))
65475+ msg2 = "file in non-root-owned directory";
65476+ else if (inode->i_mode & S_IWOTH)
65477+ msg2 = "file in world-writable directory";
65478+ else if (inode->i_mode & S_IWGRP)
65479+ msg2 = "file in group-writable directory";
65480+
65481+ if (msg && msg2) {
65482+ char fullmsg[70] = {0};
65483+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65484+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65485+ return 0;
65486+ }
65487+ msg = NULL;
65488+next_check:
65489+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65490+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65491+ return 1;
65492+
65493+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65494+ msg = "directory not owned by user";
65495+ else if (inode->i_mode & S_IWOTH)
65496+ msg = "file in world-writable directory";
65497+ else if (inode->i_mode & S_IWGRP)
65498+ msg = "file in group-writable directory";
65499+
65500+ if (msg) {
65501+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65502+ return 0;
65503+ }
65504+#endif
65505+#endif
65506+ return 1;
65507+}
65508diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65509new file mode 100644
65510index 0000000..9f7b1ac
65511--- /dev/null
65512+++ b/grsecurity/grsum.c
65513@@ -0,0 +1,61 @@
65514+#include <linux/err.h>
65515+#include <linux/kernel.h>
65516+#include <linux/sched.h>
65517+#include <linux/mm.h>
65518+#include <linux/scatterlist.h>
65519+#include <linux/crypto.h>
65520+#include <linux/gracl.h>
65521+
65522+
65523+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65524+#error "crypto and sha256 must be built into the kernel"
65525+#endif
65526+
65527+int
65528+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65529+{
65530+ char *p;
65531+ struct crypto_hash *tfm;
65532+ struct hash_desc desc;
65533+ struct scatterlist sg;
65534+ unsigned char temp_sum[GR_SHA_LEN];
65535+ volatile int retval = 0;
65536+ volatile int dummy = 0;
65537+ unsigned int i;
65538+
65539+ sg_init_table(&sg, 1);
65540+
65541+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
65542+ if (IS_ERR(tfm)) {
65543+ /* should never happen, since sha256 should be built in */
65544+ return 1;
65545+ }
65546+
65547+ desc.tfm = tfm;
65548+ desc.flags = 0;
65549+
65550+ crypto_hash_init(&desc);
65551+
65552+ p = salt;
65553+ sg_set_buf(&sg, p, GR_SALT_LEN);
65554+ crypto_hash_update(&desc, &sg, sg.length);
65555+
65556+ p = entry->pw;
65557+ sg_set_buf(&sg, p, strlen(p));
65558+
65559+ crypto_hash_update(&desc, &sg, sg.length);
65560+
65561+ crypto_hash_final(&desc, temp_sum);
65562+
65563+ memset(entry->pw, 0, GR_PW_LEN);
65564+
65565+ for (i = 0; i < GR_SHA_LEN; i++)
65566+ if (sum[i] != temp_sum[i])
65567+ retval = 1;
65568+ else
65569+ dummy = 1; // waste a cycle
65570+
65571+ crypto_free_hash(tfm);
65572+
65573+ return retval;
65574+}
65575diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
65576index 77ff547..181834f 100644
65577--- a/include/asm-generic/4level-fixup.h
65578+++ b/include/asm-generic/4level-fixup.h
65579@@ -13,8 +13,10 @@
65580 #define pmd_alloc(mm, pud, address) \
65581 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
65582 NULL: pmd_offset(pud, address))
65583+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
65584
65585 #define pud_alloc(mm, pgd, address) (pgd)
65586+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
65587 #define pud_offset(pgd, start) (pgd)
65588 #define pud_none(pud) 0
65589 #define pud_bad(pud) 0
65590diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
65591index b7babf0..04ad282 100644
65592--- a/include/asm-generic/atomic-long.h
65593+++ b/include/asm-generic/atomic-long.h
65594@@ -22,6 +22,12 @@
65595
65596 typedef atomic64_t atomic_long_t;
65597
65598+#ifdef CONFIG_PAX_REFCOUNT
65599+typedef atomic64_unchecked_t atomic_long_unchecked_t;
65600+#else
65601+typedef atomic64_t atomic_long_unchecked_t;
65602+#endif
65603+
65604 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
65605
65606 static inline long atomic_long_read(atomic_long_t *l)
65607@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65608 return (long)atomic64_read(v);
65609 }
65610
65611+#ifdef CONFIG_PAX_REFCOUNT
65612+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65613+{
65614+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65615+
65616+ return (long)atomic64_read_unchecked(v);
65617+}
65618+#endif
65619+
65620 static inline void atomic_long_set(atomic_long_t *l, long i)
65621 {
65622 atomic64_t *v = (atomic64_t *)l;
65623@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65624 atomic64_set(v, i);
65625 }
65626
65627+#ifdef CONFIG_PAX_REFCOUNT
65628+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65629+{
65630+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65631+
65632+ atomic64_set_unchecked(v, i);
65633+}
65634+#endif
65635+
65636 static inline void atomic_long_inc(atomic_long_t *l)
65637 {
65638 atomic64_t *v = (atomic64_t *)l;
65639@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65640 atomic64_inc(v);
65641 }
65642
65643+#ifdef CONFIG_PAX_REFCOUNT
65644+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65645+{
65646+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65647+
65648+ atomic64_inc_unchecked(v);
65649+}
65650+#endif
65651+
65652 static inline void atomic_long_dec(atomic_long_t *l)
65653 {
65654 atomic64_t *v = (atomic64_t *)l;
65655@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65656 atomic64_dec(v);
65657 }
65658
65659+#ifdef CONFIG_PAX_REFCOUNT
65660+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65661+{
65662+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65663+
65664+ atomic64_dec_unchecked(v);
65665+}
65666+#endif
65667+
65668 static inline void atomic_long_add(long i, atomic_long_t *l)
65669 {
65670 atomic64_t *v = (atomic64_t *)l;
65671@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65672 atomic64_add(i, v);
65673 }
65674
65675+#ifdef CONFIG_PAX_REFCOUNT
65676+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65677+{
65678+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65679+
65680+ atomic64_add_unchecked(i, v);
65681+}
65682+#endif
65683+
65684 static inline void atomic_long_sub(long i, atomic_long_t *l)
65685 {
65686 atomic64_t *v = (atomic64_t *)l;
65687@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65688 atomic64_sub(i, v);
65689 }
65690
65691+#ifdef CONFIG_PAX_REFCOUNT
65692+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65693+{
65694+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65695+
65696+ atomic64_sub_unchecked(i, v);
65697+}
65698+#endif
65699+
65700 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65701 {
65702 atomic64_t *v = (atomic64_t *)l;
65703@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65704 return (long)atomic64_add_return(i, v);
65705 }
65706
65707+#ifdef CONFIG_PAX_REFCOUNT
65708+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65709+{
65710+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65711+
65712+ return (long)atomic64_add_return_unchecked(i, v);
65713+}
65714+#endif
65715+
65716 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65717 {
65718 atomic64_t *v = (atomic64_t *)l;
65719@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65720 return (long)atomic64_inc_return(v);
65721 }
65722
65723+#ifdef CONFIG_PAX_REFCOUNT
65724+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65725+{
65726+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65727+
65728+ return (long)atomic64_inc_return_unchecked(v);
65729+}
65730+#endif
65731+
65732 static inline long atomic_long_dec_return(atomic_long_t *l)
65733 {
65734 atomic64_t *v = (atomic64_t *)l;
65735@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65736
65737 typedef atomic_t atomic_long_t;
65738
65739+#ifdef CONFIG_PAX_REFCOUNT
65740+typedef atomic_unchecked_t atomic_long_unchecked_t;
65741+#else
65742+typedef atomic_t atomic_long_unchecked_t;
65743+#endif
65744+
65745 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
65746 static inline long atomic_long_read(atomic_long_t *l)
65747 {
65748@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65749 return (long)atomic_read(v);
65750 }
65751
65752+#ifdef CONFIG_PAX_REFCOUNT
65753+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65754+{
65755+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65756+
65757+ return (long)atomic_read_unchecked(v);
65758+}
65759+#endif
65760+
65761 static inline void atomic_long_set(atomic_long_t *l, long i)
65762 {
65763 atomic_t *v = (atomic_t *)l;
65764@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65765 atomic_set(v, i);
65766 }
65767
65768+#ifdef CONFIG_PAX_REFCOUNT
65769+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65770+{
65771+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65772+
65773+ atomic_set_unchecked(v, i);
65774+}
65775+#endif
65776+
65777 static inline void atomic_long_inc(atomic_long_t *l)
65778 {
65779 atomic_t *v = (atomic_t *)l;
65780@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65781 atomic_inc(v);
65782 }
65783
65784+#ifdef CONFIG_PAX_REFCOUNT
65785+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65786+{
65787+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65788+
65789+ atomic_inc_unchecked(v);
65790+}
65791+#endif
65792+
65793 static inline void atomic_long_dec(atomic_long_t *l)
65794 {
65795 atomic_t *v = (atomic_t *)l;
65796@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65797 atomic_dec(v);
65798 }
65799
65800+#ifdef CONFIG_PAX_REFCOUNT
65801+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65802+{
65803+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65804+
65805+ atomic_dec_unchecked(v);
65806+}
65807+#endif
65808+
65809 static inline void atomic_long_add(long i, atomic_long_t *l)
65810 {
65811 atomic_t *v = (atomic_t *)l;
65812@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65813 atomic_add(i, v);
65814 }
65815
65816+#ifdef CONFIG_PAX_REFCOUNT
65817+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65818+{
65819+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65820+
65821+ atomic_add_unchecked(i, v);
65822+}
65823+#endif
65824+
65825 static inline void atomic_long_sub(long i, atomic_long_t *l)
65826 {
65827 atomic_t *v = (atomic_t *)l;
65828@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65829 atomic_sub(i, v);
65830 }
65831
65832+#ifdef CONFIG_PAX_REFCOUNT
65833+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65834+{
65835+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65836+
65837+ atomic_sub_unchecked(i, v);
65838+}
65839+#endif
65840+
65841 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65842 {
65843 atomic_t *v = (atomic_t *)l;
65844@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65845 return (long)atomic_add_return(i, v);
65846 }
65847
65848+#ifdef CONFIG_PAX_REFCOUNT
65849+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65850+{
65851+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65852+
65853+ return (long)atomic_add_return_unchecked(i, v);
65854+}
65855+
65856+#endif
65857+
65858 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65859 {
65860 atomic_t *v = (atomic_t *)l;
65861@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65862 return (long)atomic_inc_return(v);
65863 }
65864
65865+#ifdef CONFIG_PAX_REFCOUNT
65866+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65867+{
65868+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65869+
65870+ return (long)atomic_inc_return_unchecked(v);
65871+}
65872+#endif
65873+
65874 static inline long atomic_long_dec_return(atomic_long_t *l)
65875 {
65876 atomic_t *v = (atomic_t *)l;
65877@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65878
65879 #endif /* BITS_PER_LONG == 64 */
65880
65881+#ifdef CONFIG_PAX_REFCOUNT
65882+static inline void pax_refcount_needs_these_functions(void)
65883+{
65884+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
65885+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
65886+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
65887+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
65888+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
65889+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
65890+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
65891+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
65892+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
65893+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
65894+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
65895+#ifdef CONFIG_X86
65896+ atomic_clear_mask_unchecked(0, NULL);
65897+ atomic_set_mask_unchecked(0, NULL);
65898+#endif
65899+
65900+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
65901+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
65902+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
65903+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
65904+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
65905+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
65906+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
65907+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
65908+}
65909+#else
65910+#define atomic_read_unchecked(v) atomic_read(v)
65911+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
65912+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
65913+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
65914+#define atomic_inc_unchecked(v) atomic_inc(v)
65915+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
65916+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
65917+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
65918+#define atomic_dec_unchecked(v) atomic_dec(v)
65919+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
65920+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
65921+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
65922+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
65923+
65924+#define atomic_long_read_unchecked(v) atomic_long_read(v)
65925+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
65926+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
65927+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
65928+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
65929+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
65930+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
65931+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
65932+#endif
65933+
65934 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
65935diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
65936index 1ced641..c896ee8 100644
65937--- a/include/asm-generic/atomic.h
65938+++ b/include/asm-generic/atomic.h
65939@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
65940 * Atomically clears the bits set in @mask from @v
65941 */
65942 #ifndef atomic_clear_mask
65943-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
65944+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
65945 {
65946 unsigned long flags;
65947
65948diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
65949index b18ce4f..2ee2843 100644
65950--- a/include/asm-generic/atomic64.h
65951+++ b/include/asm-generic/atomic64.h
65952@@ -16,6 +16,8 @@ typedef struct {
65953 long long counter;
65954 } atomic64_t;
65955
65956+typedef atomic64_t atomic64_unchecked_t;
65957+
65958 #define ATOMIC64_INIT(i) { (i) }
65959
65960 extern long long atomic64_read(const atomic64_t *v);
65961@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
65962 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
65963 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
65964
65965+#define atomic64_read_unchecked(v) atomic64_read(v)
65966+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
65967+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
65968+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
65969+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
65970+#define atomic64_inc_unchecked(v) atomic64_inc(v)
65971+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
65972+#define atomic64_dec_unchecked(v) atomic64_dec(v)
65973+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
65974+
65975 #endif /* _ASM_GENERIC_ATOMIC64_H */
65976diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
65977index 1bfcfe5..e04c5c9 100644
65978--- a/include/asm-generic/cache.h
65979+++ b/include/asm-generic/cache.h
65980@@ -6,7 +6,7 @@
65981 * cache lines need to provide their own cache.h.
65982 */
65983
65984-#define L1_CACHE_SHIFT 5
65985-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
65986+#define L1_CACHE_SHIFT 5UL
65987+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
65988
65989 #endif /* __ASM_GENERIC_CACHE_H */
65990diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65991index 0d68a1e..b74a761 100644
65992--- a/include/asm-generic/emergency-restart.h
65993+++ b/include/asm-generic/emergency-restart.h
65994@@ -1,7 +1,7 @@
65995 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65996 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65997
65998-static inline void machine_emergency_restart(void)
65999+static inline __noreturn void machine_emergency_restart(void)
66000 {
66001 machine_restart(NULL);
66002 }
66003diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66004index 90f99c7..00ce236 100644
66005--- a/include/asm-generic/kmap_types.h
66006+++ b/include/asm-generic/kmap_types.h
66007@@ -2,9 +2,9 @@
66008 #define _ASM_GENERIC_KMAP_TYPES_H
66009
66010 #ifdef __WITH_KM_FENCE
66011-# define KM_TYPE_NR 41
66012+# define KM_TYPE_NR 42
66013 #else
66014-# define KM_TYPE_NR 20
66015+# define KM_TYPE_NR 21
66016 #endif
66017
66018 #endif
66019diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66020index 9ceb03b..62b0b8f 100644
66021--- a/include/asm-generic/local.h
66022+++ b/include/asm-generic/local.h
66023@@ -23,24 +23,37 @@ typedef struct
66024 atomic_long_t a;
66025 } local_t;
66026
66027+typedef struct {
66028+ atomic_long_unchecked_t a;
66029+} local_unchecked_t;
66030+
66031 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66032
66033 #define local_read(l) atomic_long_read(&(l)->a)
66034+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66035 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66036+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66037 #define local_inc(l) atomic_long_inc(&(l)->a)
66038+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66039 #define local_dec(l) atomic_long_dec(&(l)->a)
66040+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66041 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66042+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66043 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66044+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66045
66046 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66047 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66048 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66049 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66050 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66051+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66052 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66053 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66054+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66055
66056 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66057+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66058 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66059 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66060 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66061diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66062index 725612b..9cc513a 100644
66063--- a/include/asm-generic/pgtable-nopmd.h
66064+++ b/include/asm-generic/pgtable-nopmd.h
66065@@ -1,14 +1,19 @@
66066 #ifndef _PGTABLE_NOPMD_H
66067 #define _PGTABLE_NOPMD_H
66068
66069-#ifndef __ASSEMBLY__
66070-
66071 #include <asm-generic/pgtable-nopud.h>
66072
66073-struct mm_struct;
66074-
66075 #define __PAGETABLE_PMD_FOLDED
66076
66077+#define PMD_SHIFT PUD_SHIFT
66078+#define PTRS_PER_PMD 1
66079+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66080+#define PMD_MASK (~(PMD_SIZE-1))
66081+
66082+#ifndef __ASSEMBLY__
66083+
66084+struct mm_struct;
66085+
66086 /*
66087 * Having the pmd type consist of a pud gets the size right, and allows
66088 * us to conceptually access the pud entry that this pmd is folded into
66089@@ -16,11 +21,6 @@ struct mm_struct;
66090 */
66091 typedef struct { pud_t pud; } pmd_t;
66092
66093-#define PMD_SHIFT PUD_SHIFT
66094-#define PTRS_PER_PMD 1
66095-#define PMD_SIZE (1UL << PMD_SHIFT)
66096-#define PMD_MASK (~(PMD_SIZE-1))
66097-
66098 /*
66099 * The "pud_xxx()" functions here are trivial for a folded two-level
66100 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66101diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66102index 810431d..0ec4804f 100644
66103--- a/include/asm-generic/pgtable-nopud.h
66104+++ b/include/asm-generic/pgtable-nopud.h
66105@@ -1,10 +1,15 @@
66106 #ifndef _PGTABLE_NOPUD_H
66107 #define _PGTABLE_NOPUD_H
66108
66109-#ifndef __ASSEMBLY__
66110-
66111 #define __PAGETABLE_PUD_FOLDED
66112
66113+#define PUD_SHIFT PGDIR_SHIFT
66114+#define PTRS_PER_PUD 1
66115+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66116+#define PUD_MASK (~(PUD_SIZE-1))
66117+
66118+#ifndef __ASSEMBLY__
66119+
66120 /*
66121 * Having the pud type consist of a pgd gets the size right, and allows
66122 * us to conceptually access the pgd entry that this pud is folded into
66123@@ -12,11 +17,6 @@
66124 */
66125 typedef struct { pgd_t pgd; } pud_t;
66126
66127-#define PUD_SHIFT PGDIR_SHIFT
66128-#define PTRS_PER_PUD 1
66129-#define PUD_SIZE (1UL << PUD_SHIFT)
66130-#define PUD_MASK (~(PUD_SIZE-1))
66131-
66132 /*
66133 * The "pgd_xxx()" functions here are trivial for a folded two-level
66134 * setup: the pud is never bad, and a pud always exists (as it's folded
66135@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66136 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66137
66138 #define pgd_populate(mm, pgd, pud) do { } while (0)
66139+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66140 /*
66141 * (puds are folded into pgds so this doesn't get actually called,
66142 * but the define is needed for a generic inline function.)
66143diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66144index 5cf680a..4b74d62 100644
66145--- a/include/asm-generic/pgtable.h
66146+++ b/include/asm-generic/pgtable.h
66147@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66148 }
66149 #endif /* CONFIG_NUMA_BALANCING */
66150
66151+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66152+static inline unsigned long pax_open_kernel(void) { return 0; }
66153+#endif
66154+
66155+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66156+static inline unsigned long pax_close_kernel(void) { return 0; }
66157+#endif
66158+
66159 #endif /* CONFIG_MMU */
66160
66161 #endif /* !__ASSEMBLY__ */
66162diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66163index d1ea7ce..b1ebf2a 100644
66164--- a/include/asm-generic/vmlinux.lds.h
66165+++ b/include/asm-generic/vmlinux.lds.h
66166@@ -218,6 +218,7 @@
66167 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66168 VMLINUX_SYMBOL(__start_rodata) = .; \
66169 *(.rodata) *(.rodata.*) \
66170+ *(.data..read_only) \
66171 *(__vermagic) /* Kernel version magic */ \
66172 . = ALIGN(8); \
66173 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66174@@ -725,17 +726,18 @@
66175 * section in the linker script will go there too. @phdr should have
66176 * a leading colon.
66177 *
66178- * Note that this macros defines __per_cpu_load as an absolute symbol.
66179+ * Note that this macros defines per_cpu_load as an absolute symbol.
66180 * If there is no need to put the percpu section at a predetermined
66181 * address, use PERCPU_SECTION.
66182 */
66183 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66184- VMLINUX_SYMBOL(__per_cpu_load) = .; \
66185- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66186+ per_cpu_load = .; \
66187+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66188 - LOAD_OFFSET) { \
66189+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66190 PERCPU_INPUT(cacheline) \
66191 } phdr \
66192- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66193+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66194
66195 /**
66196 * PERCPU_SECTION - define output section for percpu area, simple version
66197diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66198index 418d270..bfd2794 100644
66199--- a/include/crypto/algapi.h
66200+++ b/include/crypto/algapi.h
66201@@ -34,7 +34,7 @@ struct crypto_type {
66202 unsigned int maskclear;
66203 unsigned int maskset;
66204 unsigned int tfmsize;
66205-};
66206+} __do_const;
66207
66208 struct crypto_instance {
66209 struct crypto_alg alg;
66210diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66211index fad21c9..ab858bc 100644
66212--- a/include/drm/drmP.h
66213+++ b/include/drm/drmP.h
66214@@ -72,6 +72,7 @@
66215 #include <linux/workqueue.h>
66216 #include <linux/poll.h>
66217 #include <asm/pgalloc.h>
66218+#include <asm/local.h>
66219 #include <drm/drm.h>
66220 #include <drm/drm_sarea.h>
66221
66222@@ -293,10 +294,12 @@ do { \
66223 * \param cmd command.
66224 * \param arg argument.
66225 */
66226-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66227+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66228+ struct drm_file *file_priv);
66229+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66230 struct drm_file *file_priv);
66231
66232-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66233+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66234 unsigned long arg);
66235
66236 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66237@@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66238 struct drm_ioctl_desc {
66239 unsigned int cmd;
66240 int flags;
66241- drm_ioctl_t *func;
66242+ drm_ioctl_t func;
66243 unsigned int cmd_drv;
66244-};
66245+} __do_const;
66246
66247 /**
66248 * Creates a driver or general drm_ioctl_desc array entry for the given
66249@@ -995,7 +998,7 @@ struct drm_info_list {
66250 int (*show)(struct seq_file*, void*); /** show callback */
66251 u32 driver_features; /**< Required driver features for this entry */
66252 void *data;
66253-};
66254+} __do_const;
66255
66256 /**
66257 * debugfs node structure. This structure represents a debugfs file.
66258@@ -1068,7 +1071,7 @@ struct drm_device {
66259
66260 /** \name Usage Counters */
66261 /*@{ */
66262- int open_count; /**< Outstanding files open */
66263+ local_t open_count; /**< Outstanding files open */
66264 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66265 atomic_t vma_count; /**< Outstanding vma areas open */
66266 int buf_use; /**< Buffers in use -- cannot alloc */
66267@@ -1079,7 +1082,7 @@ struct drm_device {
66268 /*@{ */
66269 unsigned long counters;
66270 enum drm_stat_type types[15];
66271- atomic_t counts[15];
66272+ atomic_unchecked_t counts[15];
66273 /*@} */
66274
66275 struct list_head filelist;
66276diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66277index f43d556..94d9343 100644
66278--- a/include/drm/drm_crtc_helper.h
66279+++ b/include/drm/drm_crtc_helper.h
66280@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66281 struct drm_connector *connector);
66282 /* disable encoder when not in use - more explicit than dpms off */
66283 void (*disable)(struct drm_encoder *encoder);
66284-};
66285+} __no_const;
66286
66287 /**
66288 * drm_connector_helper_funcs - helper operations for connectors
66289diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66290index 72dcbe8..8db58d7 100644
66291--- a/include/drm/ttm/ttm_memory.h
66292+++ b/include/drm/ttm/ttm_memory.h
66293@@ -48,7 +48,7 @@
66294
66295 struct ttm_mem_shrink {
66296 int (*do_shrink) (struct ttm_mem_shrink *);
66297-};
66298+} __no_const;
66299
66300 /**
66301 * struct ttm_mem_global - Global memory accounting structure.
66302diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66303index 4b840e8..155d235 100644
66304--- a/include/keys/asymmetric-subtype.h
66305+++ b/include/keys/asymmetric-subtype.h
66306@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66307 /* Verify the signature on a key of this subtype (optional) */
66308 int (*verify_signature)(const struct key *key,
66309 const struct public_key_signature *sig);
66310-};
66311+} __do_const;
66312
66313 /**
66314 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66315diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66316index c1da539..1dcec55 100644
66317--- a/include/linux/atmdev.h
66318+++ b/include/linux/atmdev.h
66319@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66320 #endif
66321
66322 struct k_atm_aal_stats {
66323-#define __HANDLE_ITEM(i) atomic_t i
66324+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66325 __AAL_STAT_ITEMS
66326 #undef __HANDLE_ITEM
66327 };
66328@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66329 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66330 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66331 struct module *owner;
66332-};
66333+} __do_const ;
66334
66335 struct atmphy_ops {
66336 int (*start)(struct atm_dev *dev);
66337diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66338index 0530b98..96a8ac0 100644
66339--- a/include/linux/binfmts.h
66340+++ b/include/linux/binfmts.h
66341@@ -73,8 +73,9 @@ struct linux_binfmt {
66342 int (*load_binary)(struct linux_binprm *);
66343 int (*load_shlib)(struct file *);
66344 int (*core_dump)(struct coredump_params *cprm);
66345+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66346 unsigned long min_coredump; /* minimal dump size */
66347-};
66348+} __do_const;
66349
66350 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66351
66352diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66353index f94bc83..62b9cfe 100644
66354--- a/include/linux/blkdev.h
66355+++ b/include/linux/blkdev.h
66356@@ -1498,7 +1498,7 @@ struct block_device_operations {
66357 /* this callback is with swap_lock and sometimes page table lock held */
66358 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66359 struct module *owner;
66360-};
66361+} __do_const;
66362
66363 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66364 unsigned long);
66365diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66366index 7c2e030..b72475d 100644
66367--- a/include/linux/blktrace_api.h
66368+++ b/include/linux/blktrace_api.h
66369@@ -23,7 +23,7 @@ struct blk_trace {
66370 struct dentry *dir;
66371 struct dentry *dropped_file;
66372 struct dentry *msg_file;
66373- atomic_t dropped;
66374+ atomic_unchecked_t dropped;
66375 };
66376
66377 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66378diff --git a/include/linux/cache.h b/include/linux/cache.h
66379index 4c57065..4307975 100644
66380--- a/include/linux/cache.h
66381+++ b/include/linux/cache.h
66382@@ -16,6 +16,10 @@
66383 #define __read_mostly
66384 #endif
66385
66386+#ifndef __read_only
66387+#define __read_only __read_mostly
66388+#endif
66389+
66390 #ifndef ____cacheline_aligned
66391 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66392 #endif
66393diff --git a/include/linux/capability.h b/include/linux/capability.h
66394index 98503b7..cc36d18 100644
66395--- a/include/linux/capability.h
66396+++ b/include/linux/capability.h
66397@@ -211,8 +211,13 @@ extern bool capable(int cap);
66398 extern bool ns_capable(struct user_namespace *ns, int cap);
66399 extern bool nsown_capable(int cap);
66400 extern bool inode_capable(const struct inode *inode, int cap);
66401+extern bool capable_nolog(int cap);
66402+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66403+extern bool inode_capable_nolog(const struct inode *inode, int cap);
66404
66405 /* audit system wants to get cap info from files as well */
66406 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66407
66408+extern int is_privileged_binary(const struct dentry *dentry);
66409+
66410 #endif /* !_LINUX_CAPABILITY_H */
66411diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66412index 8609d57..86e4d79 100644
66413--- a/include/linux/cdrom.h
66414+++ b/include/linux/cdrom.h
66415@@ -87,7 +87,6 @@ struct cdrom_device_ops {
66416
66417 /* driver specifications */
66418 const int capability; /* capability flags */
66419- int n_minors; /* number of active minor devices */
66420 /* handle uniform packets for scsi type devices (scsi,atapi) */
66421 int (*generic_packet) (struct cdrom_device_info *,
66422 struct packet_command *);
66423diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66424index 42e55de..1cd0e66 100644
66425--- a/include/linux/cleancache.h
66426+++ b/include/linux/cleancache.h
66427@@ -31,7 +31,7 @@ struct cleancache_ops {
66428 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66429 void (*invalidate_inode)(int, struct cleancache_filekey);
66430 void (*invalidate_fs)(int);
66431-};
66432+} __no_const;
66433
66434 extern struct cleancache_ops
66435 cleancache_register_ops(struct cleancache_ops *ops);
66436diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66437index 662fd1b..e801992 100644
66438--- a/include/linux/compiler-gcc4.h
66439+++ b/include/linux/compiler-gcc4.h
66440@@ -34,6 +34,21 @@
66441 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66442
66443 #if __GNUC_MINOR__ >= 5
66444+
66445+#ifdef CONSTIFY_PLUGIN
66446+#define __no_const __attribute__((no_const))
66447+#define __do_const __attribute__((do_const))
66448+#endif
66449+
66450+#ifdef SIZE_OVERFLOW_PLUGIN
66451+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66452+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66453+#endif
66454+
66455+#ifdef LATENT_ENTROPY_PLUGIN
66456+#define __latent_entropy __attribute__((latent_entropy))
66457+#endif
66458+
66459 /*
66460 * Mark a position in code as unreachable. This can be used to
66461 * suppress control flow warnings after asm blocks that transfer
66462@@ -49,6 +64,11 @@
66463 #define __noclone __attribute__((__noclone__))
66464
66465 #endif
66466+
66467+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66468+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66469+#define __bos0(ptr) __bos((ptr), 0)
66470+#define __bos1(ptr) __bos((ptr), 1)
66471 #endif
66472
66473 #if __GNUC_MINOR__ >= 6
66474diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66475index dd852b7..72924c0 100644
66476--- a/include/linux/compiler.h
66477+++ b/include/linux/compiler.h
66478@@ -5,11 +5,14 @@
66479
66480 #ifdef __CHECKER__
66481 # define __user __attribute__((noderef, address_space(1)))
66482+# define __force_user __force __user
66483 # define __kernel __attribute__((address_space(0)))
66484+# define __force_kernel __force __kernel
66485 # define __safe __attribute__((safe))
66486 # define __force __attribute__((force))
66487 # define __nocast __attribute__((nocast))
66488 # define __iomem __attribute__((noderef, address_space(2)))
66489+# define __force_iomem __force __iomem
66490 # define __must_hold(x) __attribute__((context(x,1,1)))
66491 # define __acquires(x) __attribute__((context(x,0,1)))
66492 # define __releases(x) __attribute__((context(x,1,0)))
66493@@ -17,20 +20,48 @@
66494 # define __release(x) __context__(x,-1)
66495 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66496 # define __percpu __attribute__((noderef, address_space(3)))
66497+# define __force_percpu __force __percpu
66498 #ifdef CONFIG_SPARSE_RCU_POINTER
66499 # define __rcu __attribute__((noderef, address_space(4)))
66500+# define __force_rcu __force __rcu
66501 #else
66502 # define __rcu
66503+# define __force_rcu
66504 #endif
66505 extern void __chk_user_ptr(const volatile void __user *);
66506 extern void __chk_io_ptr(const volatile void __iomem *);
66507+#elif defined(CHECKER_PLUGIN)
66508+//# define __user
66509+//# define __force_user
66510+//# define __kernel
66511+//# define __force_kernel
66512+# define __safe
66513+# define __force
66514+# define __nocast
66515+# define __iomem
66516+# define __force_iomem
66517+# define __chk_user_ptr(x) (void)0
66518+# define __chk_io_ptr(x) (void)0
66519+# define __builtin_warning(x, y...) (1)
66520+# define __acquires(x)
66521+# define __releases(x)
66522+# define __acquire(x) (void)0
66523+# define __release(x) (void)0
66524+# define __cond_lock(x,c) (c)
66525+# define __percpu
66526+# define __force_percpu
66527+# define __rcu
66528+# define __force_rcu
66529 #else
66530 # define __user
66531+# define __force_user
66532 # define __kernel
66533+# define __force_kernel
66534 # define __safe
66535 # define __force
66536 # define __nocast
66537 # define __iomem
66538+# define __force_iomem
66539 # define __chk_user_ptr(x) (void)0
66540 # define __chk_io_ptr(x) (void)0
66541 # define __builtin_warning(x, y...) (1)
66542@@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
66543 # define __release(x) (void)0
66544 # define __cond_lock(x,c) (c)
66545 # define __percpu
66546+# define __force_percpu
66547 # define __rcu
66548+# define __force_rcu
66549 #endif
66550
66551 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
66552@@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66553 # define __attribute_const__ /* unimplemented */
66554 #endif
66555
66556+#ifndef __no_const
66557+# define __no_const
66558+#endif
66559+
66560+#ifndef __do_const
66561+# define __do_const
66562+#endif
66563+
66564+#ifndef __size_overflow
66565+# define __size_overflow(...)
66566+#endif
66567+
66568+#ifndef __intentional_overflow
66569+# define __intentional_overflow(...)
66570+#endif
66571+
66572+#ifndef __latent_entropy
66573+# define __latent_entropy
66574+#endif
66575+
66576 /*
66577 * Tell gcc if a function is cold. The compiler will assume any path
66578 * directly leading to the call is unlikely.
66579@@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66580 #define __cold
66581 #endif
66582
66583+#ifndef __alloc_size
66584+#define __alloc_size(...)
66585+#endif
66586+
66587+#ifndef __bos
66588+#define __bos(ptr, arg)
66589+#endif
66590+
66591+#ifndef __bos0
66592+#define __bos0(ptr)
66593+#endif
66594+
66595+#ifndef __bos1
66596+#define __bos1(ptr)
66597+#endif
66598+
66599 /* Simple shorthand for a section definition */
66600 #ifndef __section
66601 # define __section(S) __attribute__ ((__section__(#S)))
66602@@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66603 * use is to mediate communication between process-level code and irq/NMI
66604 * handlers, all running on the same CPU.
66605 */
66606-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
66607+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
66608+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
66609
66610 #endif /* __LINUX_COMPILER_H */
66611diff --git a/include/linux/configfs.h b/include/linux/configfs.h
66612index 34025df..d94bbbc 100644
66613--- a/include/linux/configfs.h
66614+++ b/include/linux/configfs.h
66615@@ -125,7 +125,7 @@ struct configfs_attribute {
66616 const char *ca_name;
66617 struct module *ca_owner;
66618 umode_t ca_mode;
66619-};
66620+} __do_const;
66621
66622 /*
66623 * Users often need to create attribute structures for their configurable
66624diff --git a/include/linux/cpu.h b/include/linux/cpu.h
66625index ce7a074..01ab8ac 100644
66626--- a/include/linux/cpu.h
66627+++ b/include/linux/cpu.h
66628@@ -115,7 +115,7 @@ enum {
66629 /* Need to know about CPUs going up/down? */
66630 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
66631 #define cpu_notifier(fn, pri) { \
66632- static struct notifier_block fn##_nb __cpuinitdata = \
66633+ static struct notifier_block fn##_nb = \
66634 { .notifier_call = fn, .priority = pri }; \
66635 register_cpu_notifier(&fn##_nb); \
66636 }
66637diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
66638index a55b88e..fba90c5 100644
66639--- a/include/linux/cpufreq.h
66640+++ b/include/linux/cpufreq.h
66641@@ -240,7 +240,7 @@ struct cpufreq_driver {
66642 int (*suspend) (struct cpufreq_policy *policy);
66643 int (*resume) (struct cpufreq_policy *policy);
66644 struct freq_attr **attr;
66645-};
66646+} __do_const;
66647
66648 /* flags */
66649
66650@@ -299,6 +299,7 @@ struct global_attr {
66651 ssize_t (*store)(struct kobject *a, struct attribute *b,
66652 const char *c, size_t count);
66653 };
66654+typedef struct global_attr __no_const global_attr_no_const;
66655
66656 #define define_one_global_ro(_name) \
66657 static struct global_attr _name = \
66658diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
66659index 24cd1037..20a63aae 100644
66660--- a/include/linux/cpuidle.h
66661+++ b/include/linux/cpuidle.h
66662@@ -54,7 +54,8 @@ struct cpuidle_state {
66663 int index);
66664
66665 int (*enter_dead) (struct cpuidle_device *dev, int index);
66666-};
66667+} __do_const;
66668+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
66669
66670 /* Idle State Flags */
66671 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
66672@@ -216,7 +217,7 @@ struct cpuidle_governor {
66673 void (*reflect) (struct cpuidle_device *dev, int index);
66674
66675 struct module *owner;
66676-};
66677+} __do_const;
66678
66679 #ifdef CONFIG_CPU_IDLE
66680
66681diff --git a/include/linux/cred.h b/include/linux/cred.h
66682index 04421e8..6bce4ef 100644
66683--- a/include/linux/cred.h
66684+++ b/include/linux/cred.h
66685@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
66686 static inline void validate_process_creds(void)
66687 {
66688 }
66689+static inline void validate_task_creds(struct task_struct *task)
66690+{
66691+}
66692 #endif
66693
66694 /**
66695diff --git a/include/linux/crypto.h b/include/linux/crypto.h
66696index b92eadf..b4ecdc1 100644
66697--- a/include/linux/crypto.h
66698+++ b/include/linux/crypto.h
66699@@ -373,7 +373,7 @@ struct cipher_tfm {
66700 const u8 *key, unsigned int keylen);
66701 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66702 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66703-};
66704+} __no_const;
66705
66706 struct hash_tfm {
66707 int (*init)(struct hash_desc *desc);
66708@@ -394,13 +394,13 @@ struct compress_tfm {
66709 int (*cot_decompress)(struct crypto_tfm *tfm,
66710 const u8 *src, unsigned int slen,
66711 u8 *dst, unsigned int *dlen);
66712-};
66713+} __no_const;
66714
66715 struct rng_tfm {
66716 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
66717 unsigned int dlen);
66718 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
66719-};
66720+} __no_const;
66721
66722 #define crt_ablkcipher crt_u.ablkcipher
66723 #define crt_aead crt_u.aead
66724diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
66725index 7925bf0..d5143d2 100644
66726--- a/include/linux/decompress/mm.h
66727+++ b/include/linux/decompress/mm.h
66728@@ -77,7 +77,7 @@ static void free(void *where)
66729 * warnings when not needed (indeed large_malloc / large_free are not
66730 * needed by inflate */
66731
66732-#define malloc(a) kmalloc(a, GFP_KERNEL)
66733+#define malloc(a) kmalloc((a), GFP_KERNEL)
66734 #define free(a) kfree(a)
66735
66736 #define large_malloc(a) vmalloc(a)
66737diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
66738index e83ef39..33e0eb3 100644
66739--- a/include/linux/devfreq.h
66740+++ b/include/linux/devfreq.h
66741@@ -114,7 +114,7 @@ struct devfreq_governor {
66742 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
66743 int (*event_handler)(struct devfreq *devfreq,
66744 unsigned int event, void *data);
66745-};
66746+} __do_const;
66747
66748 /**
66749 * struct devfreq - Device devfreq structure
66750diff --git a/include/linux/device.h b/include/linux/device.h
66751index 43dcda9..7a1fb65 100644
66752--- a/include/linux/device.h
66753+++ b/include/linux/device.h
66754@@ -294,7 +294,7 @@ struct subsys_interface {
66755 struct list_head node;
66756 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
66757 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
66758-};
66759+} __do_const;
66760
66761 int subsys_interface_register(struct subsys_interface *sif);
66762 void subsys_interface_unregister(struct subsys_interface *sif);
66763@@ -474,7 +474,7 @@ struct device_type {
66764 void (*release)(struct device *dev);
66765
66766 const struct dev_pm_ops *pm;
66767-};
66768+} __do_const;
66769
66770 /* interface for exporting device attributes */
66771 struct device_attribute {
66772@@ -484,11 +484,12 @@ struct device_attribute {
66773 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
66774 const char *buf, size_t count);
66775 };
66776+typedef struct device_attribute __no_const device_attribute_no_const;
66777
66778 struct dev_ext_attribute {
66779 struct device_attribute attr;
66780 void *var;
66781-};
66782+} __do_const;
66783
66784 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
66785 char *buf);
66786diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
66787index 94af418..b1ca7a2 100644
66788--- a/include/linux/dma-mapping.h
66789+++ b/include/linux/dma-mapping.h
66790@@ -54,7 +54,7 @@ struct dma_map_ops {
66791 u64 (*get_required_mask)(struct device *dev);
66792 #endif
66793 int is_phys;
66794-};
66795+} __do_const;
66796
66797 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
66798
66799diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
66800index d3201e4..8281e63 100644
66801--- a/include/linux/dmaengine.h
66802+++ b/include/linux/dmaengine.h
66803@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
66804 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
66805 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
66806
66807-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66808+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66809 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
66810-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66811+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66812 struct dma_pinned_list *pinned_list, struct page *page,
66813 unsigned int offset, size_t len);
66814
66815diff --git a/include/linux/efi.h b/include/linux/efi.h
66816index 7a9498a..155713d 100644
66817--- a/include/linux/efi.h
66818+++ b/include/linux/efi.h
66819@@ -733,6 +733,7 @@ struct efivar_operations {
66820 efi_set_variable_t *set_variable;
66821 efi_query_variable_info_t *query_variable_info;
66822 };
66823+typedef struct efivar_operations __no_const efivar_operations_no_const;
66824
66825 struct efivars {
66826 /*
66827diff --git a/include/linux/elf.h b/include/linux/elf.h
66828index 8c9048e..16a4665 100644
66829--- a/include/linux/elf.h
66830+++ b/include/linux/elf.h
66831@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
66832 #define elf_note elf32_note
66833 #define elf_addr_t Elf32_Off
66834 #define Elf_Half Elf32_Half
66835+#define elf_dyn Elf32_Dyn
66836
66837 #else
66838
66839@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
66840 #define elf_note elf64_note
66841 #define elf_addr_t Elf64_Off
66842 #define Elf_Half Elf64_Half
66843+#define elf_dyn Elf64_Dyn
66844
66845 #endif
66846
66847diff --git a/include/linux/extcon.h b/include/linux/extcon.h
66848index fcb51c8..bdafcf6 100644
66849--- a/include/linux/extcon.h
66850+++ b/include/linux/extcon.h
66851@@ -134,7 +134,7 @@ struct extcon_dev {
66852 /* /sys/class/extcon/.../mutually_exclusive/... */
66853 struct attribute_group attr_g_muex;
66854 struct attribute **attrs_muex;
66855- struct device_attribute *d_attrs_muex;
66856+ device_attribute_no_const *d_attrs_muex;
66857 };
66858
66859 /**
66860diff --git a/include/linux/fb.h b/include/linux/fb.h
66861index c7a9571..02eeffe 100644
66862--- a/include/linux/fb.h
66863+++ b/include/linux/fb.h
66864@@ -302,7 +302,7 @@ struct fb_ops {
66865 /* called at KDB enter and leave time to prepare the console */
66866 int (*fb_debug_enter)(struct fb_info *info);
66867 int (*fb_debug_leave)(struct fb_info *info);
66868-};
66869+} __do_const;
66870
66871 #ifdef CONFIG_FB_TILEBLITTING
66872 #define FB_TILE_CURSOR_NONE 0
66873diff --git a/include/linux/filter.h b/include/linux/filter.h
66874index c45eabc..baa0be5 100644
66875--- a/include/linux/filter.h
66876+++ b/include/linux/filter.h
66877@@ -20,6 +20,7 @@ struct compat_sock_fprog {
66878
66879 struct sk_buff;
66880 struct sock;
66881+struct bpf_jit_work;
66882
66883 struct sk_filter
66884 {
66885@@ -27,6 +28,9 @@ struct sk_filter
66886 unsigned int len; /* Number of filter blocks */
66887 unsigned int (*bpf_func)(const struct sk_buff *skb,
66888 const struct sock_filter *filter);
66889+#ifdef CONFIG_BPF_JIT
66890+ struct bpf_jit_work *work;
66891+#endif
66892 struct rcu_head rcu;
66893 struct sock_filter insns[0];
66894 };
66895diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
66896index 3044254..9767f41 100644
66897--- a/include/linux/frontswap.h
66898+++ b/include/linux/frontswap.h
66899@@ -11,7 +11,7 @@ struct frontswap_ops {
66900 int (*load)(unsigned, pgoff_t, struct page *);
66901 void (*invalidate_page)(unsigned, pgoff_t);
66902 void (*invalidate_area)(unsigned);
66903-};
66904+} __no_const;
66905
66906 extern bool frontswap_enabled;
66907 extern struct frontswap_ops
66908diff --git a/include/linux/fs.h b/include/linux/fs.h
66909index 7617ee0..b575199 100644
66910--- a/include/linux/fs.h
66911+++ b/include/linux/fs.h
66912@@ -1541,7 +1541,8 @@ struct file_operations {
66913 long (*fallocate)(struct file *file, int mode, loff_t offset,
66914 loff_t len);
66915 int (*show_fdinfo)(struct seq_file *m, struct file *f);
66916-};
66917+} __do_const;
66918+typedef struct file_operations __no_const file_operations_no_const;
66919
66920 struct inode_operations {
66921 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
66922@@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
66923 inode->i_flags |= S_NOSEC;
66924 }
66925
66926+static inline bool is_sidechannel_device(const struct inode *inode)
66927+{
66928+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
66929+ umode_t mode = inode->i_mode;
66930+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
66931+#else
66932+ return false;
66933+#endif
66934+}
66935+
66936 #endif /* _LINUX_FS_H */
66937diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66938index d0ae3a8..0244b34 100644
66939--- a/include/linux/fs_struct.h
66940+++ b/include/linux/fs_struct.h
66941@@ -6,7 +6,7 @@
66942 #include <linux/seqlock.h>
66943
66944 struct fs_struct {
66945- int users;
66946+ atomic_t users;
66947 spinlock_t lock;
66948 seqcount_t seq;
66949 int umask;
66950diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66951index 5dfa0aa..6acf322 100644
66952--- a/include/linux/fscache-cache.h
66953+++ b/include/linux/fscache-cache.h
66954@@ -112,7 +112,7 @@ struct fscache_operation {
66955 fscache_operation_release_t release;
66956 };
66957
66958-extern atomic_t fscache_op_debug_id;
66959+extern atomic_unchecked_t fscache_op_debug_id;
66960 extern void fscache_op_work_func(struct work_struct *work);
66961
66962 extern void fscache_enqueue_operation(struct fscache_operation *);
66963@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66964 INIT_WORK(&op->work, fscache_op_work_func);
66965 atomic_set(&op->usage, 1);
66966 op->state = FSCACHE_OP_ST_INITIALISED;
66967- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66968+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66969 op->processor = processor;
66970 op->release = release;
66971 INIT_LIST_HEAD(&op->pend_link);
66972diff --git a/include/linux/fscache.h b/include/linux/fscache.h
66973index 7a08623..4c07b0f 100644
66974--- a/include/linux/fscache.h
66975+++ b/include/linux/fscache.h
66976@@ -152,7 +152,7 @@ struct fscache_cookie_def {
66977 * - this is mandatory for any object that may have data
66978 */
66979 void (*now_uncached)(void *cookie_netfs_data);
66980-};
66981+} __do_const;
66982
66983 /*
66984 * fscache cached network filesystem type
66985diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
66986index 0fbfb46..508eb0d 100644
66987--- a/include/linux/fsnotify.h
66988+++ b/include/linux/fsnotify.h
66989@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
66990 struct inode *inode = path->dentry->d_inode;
66991 __u32 mask = FS_ACCESS;
66992
66993+ if (is_sidechannel_device(inode))
66994+ return;
66995+
66996 if (S_ISDIR(inode->i_mode))
66997 mask |= FS_ISDIR;
66998
66999@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67000 struct inode *inode = path->dentry->d_inode;
67001 __u32 mask = FS_MODIFY;
67002
67003+ if (is_sidechannel_device(inode))
67004+ return;
67005+
67006 if (S_ISDIR(inode->i_mode))
67007 mask |= FS_ISDIR;
67008
67009@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67010 */
67011 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67012 {
67013- return kstrdup(name, GFP_KERNEL);
67014+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67015 }
67016
67017 /*
67018diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67019index a3d4895..ddd2a50 100644
67020--- a/include/linux/ftrace_event.h
67021+++ b/include/linux/ftrace_event.h
67022@@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67023 extern int trace_add_event_call(struct ftrace_event_call *call);
67024 extern void trace_remove_event_call(struct ftrace_event_call *call);
67025
67026-#define is_signed_type(type) (((type)(-1)) < 0)
67027+#define is_signed_type(type) (((type)(-1)) < (type)1)
67028
67029 int trace_set_clr_event(const char *system, const char *event, int set);
67030
67031diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67032index 79b8bba..86b539e 100644
67033--- a/include/linux/genhd.h
67034+++ b/include/linux/genhd.h
67035@@ -194,7 +194,7 @@ struct gendisk {
67036 struct kobject *slave_dir;
67037
67038 struct timer_rand_state *random;
67039- atomic_t sync_io; /* RAID */
67040+ atomic_unchecked_t sync_io; /* RAID */
67041 struct disk_events *ev;
67042 #ifdef CONFIG_BLK_DEV_INTEGRITY
67043 struct blk_integrity *integrity;
67044diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67045index 023bc34..b02b46a 100644
67046--- a/include/linux/genl_magic_func.h
67047+++ b/include/linux/genl_magic_func.h
67048@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67049 },
67050
67051 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67052-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67053+static struct genl_ops ZZZ_genl_ops[] = {
67054 #include GENL_MAGIC_INCLUDE_FILE
67055 };
67056
67057diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67058index 0f615eb..5c3832f 100644
67059--- a/include/linux/gfp.h
67060+++ b/include/linux/gfp.h
67061@@ -35,6 +35,13 @@ struct vm_area_struct;
67062 #define ___GFP_NO_KSWAPD 0x400000u
67063 #define ___GFP_OTHER_NODE 0x800000u
67064 #define ___GFP_WRITE 0x1000000u
67065+
67066+#ifdef CONFIG_PAX_USERCOPY_SLABS
67067+#define ___GFP_USERCOPY 0x2000000u
67068+#else
67069+#define ___GFP_USERCOPY 0
67070+#endif
67071+
67072 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67073
67074 /*
67075@@ -92,6 +99,7 @@ struct vm_area_struct;
67076 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67077 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67078 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67079+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67080
67081 /*
67082 * This may seem redundant, but it's a way of annotating false positives vs.
67083@@ -99,7 +107,7 @@ struct vm_area_struct;
67084 */
67085 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67086
67087-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67088+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67089 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67090
67091 /* This equals 0, but use constants in case they ever change */
67092@@ -153,6 +161,8 @@ struct vm_area_struct;
67093 /* 4GB DMA on some platforms */
67094 #define GFP_DMA32 __GFP_DMA32
67095
67096+#define GFP_USERCOPY __GFP_USERCOPY
67097+
67098 /* Convert GFP flags to their corresponding migrate type */
67099 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67100 {
67101diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67102new file mode 100644
67103index 0000000..ebe6d72
67104--- /dev/null
67105+++ b/include/linux/gracl.h
67106@@ -0,0 +1,319 @@
67107+#ifndef GR_ACL_H
67108+#define GR_ACL_H
67109+
67110+#include <linux/grdefs.h>
67111+#include <linux/resource.h>
67112+#include <linux/capability.h>
67113+#include <linux/dcache.h>
67114+#include <asm/resource.h>
67115+
67116+/* Major status information */
67117+
67118+#define GR_VERSION "grsecurity 2.9.1"
67119+#define GRSECURITY_VERSION 0x2901
67120+
67121+enum {
67122+ GR_SHUTDOWN = 0,
67123+ GR_ENABLE = 1,
67124+ GR_SPROLE = 2,
67125+ GR_RELOAD = 3,
67126+ GR_SEGVMOD = 4,
67127+ GR_STATUS = 5,
67128+ GR_UNSPROLE = 6,
67129+ GR_PASSSET = 7,
67130+ GR_SPROLEPAM = 8,
67131+};
67132+
67133+/* Password setup definitions
67134+ * kernel/grhash.c */
67135+enum {
67136+ GR_PW_LEN = 128,
67137+ GR_SALT_LEN = 16,
67138+ GR_SHA_LEN = 32,
67139+};
67140+
67141+enum {
67142+ GR_SPROLE_LEN = 64,
67143+};
67144+
67145+enum {
67146+ GR_NO_GLOB = 0,
67147+ GR_REG_GLOB,
67148+ GR_CREATE_GLOB
67149+};
67150+
67151+#define GR_NLIMITS 32
67152+
67153+/* Begin Data Structures */
67154+
67155+struct sprole_pw {
67156+ unsigned char *rolename;
67157+ unsigned char salt[GR_SALT_LEN];
67158+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67159+};
67160+
67161+struct name_entry {
67162+ __u32 key;
67163+ ino_t inode;
67164+ dev_t device;
67165+ char *name;
67166+ __u16 len;
67167+ __u8 deleted;
67168+ struct name_entry *prev;
67169+ struct name_entry *next;
67170+};
67171+
67172+struct inodev_entry {
67173+ struct name_entry *nentry;
67174+ struct inodev_entry *prev;
67175+ struct inodev_entry *next;
67176+};
67177+
67178+struct acl_role_db {
67179+ struct acl_role_label **r_hash;
67180+ __u32 r_size;
67181+};
67182+
67183+struct inodev_db {
67184+ struct inodev_entry **i_hash;
67185+ __u32 i_size;
67186+};
67187+
67188+struct name_db {
67189+ struct name_entry **n_hash;
67190+ __u32 n_size;
67191+};
67192+
67193+struct crash_uid {
67194+ uid_t uid;
67195+ unsigned long expires;
67196+};
67197+
67198+struct gr_hash_struct {
67199+ void **table;
67200+ void **nametable;
67201+ void *first;
67202+ __u32 table_size;
67203+ __u32 used_size;
67204+ int type;
67205+};
67206+
67207+/* Userspace Grsecurity ACL data structures */
67208+
67209+struct acl_subject_label {
67210+ char *filename;
67211+ ino_t inode;
67212+ dev_t device;
67213+ __u32 mode;
67214+ kernel_cap_t cap_mask;
67215+ kernel_cap_t cap_lower;
67216+ kernel_cap_t cap_invert_audit;
67217+
67218+ struct rlimit res[GR_NLIMITS];
67219+ __u32 resmask;
67220+
67221+ __u8 user_trans_type;
67222+ __u8 group_trans_type;
67223+ uid_t *user_transitions;
67224+ gid_t *group_transitions;
67225+ __u16 user_trans_num;
67226+ __u16 group_trans_num;
67227+
67228+ __u32 sock_families[2];
67229+ __u32 ip_proto[8];
67230+ __u32 ip_type;
67231+ struct acl_ip_label **ips;
67232+ __u32 ip_num;
67233+ __u32 inaddr_any_override;
67234+
67235+ __u32 crashes;
67236+ unsigned long expires;
67237+
67238+ struct acl_subject_label *parent_subject;
67239+ struct gr_hash_struct *hash;
67240+ struct acl_subject_label *prev;
67241+ struct acl_subject_label *next;
67242+
67243+ struct acl_object_label **obj_hash;
67244+ __u32 obj_hash_size;
67245+ __u16 pax_flags;
67246+};
67247+
67248+struct role_allowed_ip {
67249+ __u32 addr;
67250+ __u32 netmask;
67251+
67252+ struct role_allowed_ip *prev;
67253+ struct role_allowed_ip *next;
67254+};
67255+
67256+struct role_transition {
67257+ char *rolename;
67258+
67259+ struct role_transition *prev;
67260+ struct role_transition *next;
67261+};
67262+
67263+struct acl_role_label {
67264+ char *rolename;
67265+ uid_t uidgid;
67266+ __u16 roletype;
67267+
67268+ __u16 auth_attempts;
67269+ unsigned long expires;
67270+
67271+ struct acl_subject_label *root_label;
67272+ struct gr_hash_struct *hash;
67273+
67274+ struct acl_role_label *prev;
67275+ struct acl_role_label *next;
67276+
67277+ struct role_transition *transitions;
67278+ struct role_allowed_ip *allowed_ips;
67279+ uid_t *domain_children;
67280+ __u16 domain_child_num;
67281+
67282+ umode_t umask;
67283+
67284+ struct acl_subject_label **subj_hash;
67285+ __u32 subj_hash_size;
67286+};
67287+
67288+struct user_acl_role_db {
67289+ struct acl_role_label **r_table;
67290+ __u32 num_pointers; /* Number of allocations to track */
67291+ __u32 num_roles; /* Number of roles */
67292+ __u32 num_domain_children; /* Number of domain children */
67293+ __u32 num_subjects; /* Number of subjects */
67294+ __u32 num_objects; /* Number of objects */
67295+};
67296+
67297+struct acl_object_label {
67298+ char *filename;
67299+ ino_t inode;
67300+ dev_t device;
67301+ __u32 mode;
67302+
67303+ struct acl_subject_label *nested;
67304+ struct acl_object_label *globbed;
67305+
67306+ /* next two structures not used */
67307+
67308+ struct acl_object_label *prev;
67309+ struct acl_object_label *next;
67310+};
67311+
67312+struct acl_ip_label {
67313+ char *iface;
67314+ __u32 addr;
67315+ __u32 netmask;
67316+ __u16 low, high;
67317+ __u8 mode;
67318+ __u32 type;
67319+ __u32 proto[8];
67320+
67321+ /* next two structures not used */
67322+
67323+ struct acl_ip_label *prev;
67324+ struct acl_ip_label *next;
67325+};
67326+
67327+struct gr_arg {
67328+ struct user_acl_role_db role_db;
67329+ unsigned char pw[GR_PW_LEN];
67330+ unsigned char salt[GR_SALT_LEN];
67331+ unsigned char sum[GR_SHA_LEN];
67332+ unsigned char sp_role[GR_SPROLE_LEN];
67333+ struct sprole_pw *sprole_pws;
67334+ dev_t segv_device;
67335+ ino_t segv_inode;
67336+ uid_t segv_uid;
67337+ __u16 num_sprole_pws;
67338+ __u16 mode;
67339+};
67340+
67341+struct gr_arg_wrapper {
67342+ struct gr_arg *arg;
67343+ __u32 version;
67344+ __u32 size;
67345+};
67346+
67347+struct subject_map {
67348+ struct acl_subject_label *user;
67349+ struct acl_subject_label *kernel;
67350+ struct subject_map *prev;
67351+ struct subject_map *next;
67352+};
67353+
67354+struct acl_subj_map_db {
67355+ struct subject_map **s_hash;
67356+ __u32 s_size;
67357+};
67358+
67359+/* End Data Structures Section */
67360+
67361+/* Hash functions generated by empirical testing by Brad Spengler
67362+ Makes good use of the low bits of the inode. Generally 0-1 times
67363+ in loop for successful match. 0-3 for unsuccessful match.
67364+ Shift/add algorithm with modulus of table size and an XOR*/
67365+
67366+static __inline__ unsigned int
67367+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67368+{
67369+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
67370+}
67371+
67372+ static __inline__ unsigned int
67373+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67374+{
67375+ return ((const unsigned long)userp % sz);
67376+}
67377+
67378+static __inline__ unsigned int
67379+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67380+{
67381+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67382+}
67383+
67384+static __inline__ unsigned int
67385+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67386+{
67387+ return full_name_hash((const unsigned char *)name, len) % sz;
67388+}
67389+
67390+#define FOR_EACH_ROLE_START(role) \
67391+ role = role_list; \
67392+ while (role) {
67393+
67394+#define FOR_EACH_ROLE_END(role) \
67395+ role = role->prev; \
67396+ }
67397+
67398+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
67399+ subj = NULL; \
67400+ iter = 0; \
67401+ while (iter < role->subj_hash_size) { \
67402+ if (subj == NULL) \
67403+ subj = role->subj_hash[iter]; \
67404+ if (subj == NULL) { \
67405+ iter++; \
67406+ continue; \
67407+ }
67408+
67409+#define FOR_EACH_SUBJECT_END(subj,iter) \
67410+ subj = subj->next; \
67411+ if (subj == NULL) \
67412+ iter++; \
67413+ }
67414+
67415+
67416+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
67417+ subj = role->hash->first; \
67418+ while (subj != NULL) {
67419+
67420+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
67421+ subj = subj->next; \
67422+ }
67423+
67424+#endif
67425+
67426diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
67427new file mode 100644
67428index 0000000..323ecf2
67429--- /dev/null
67430+++ b/include/linux/gralloc.h
67431@@ -0,0 +1,9 @@
67432+#ifndef __GRALLOC_H
67433+#define __GRALLOC_H
67434+
67435+void acl_free_all(void);
67436+int acl_alloc_stack_init(unsigned long size);
67437+void *acl_alloc(unsigned long len);
67438+void *acl_alloc_num(unsigned long num, unsigned long len);
67439+
67440+#endif
67441diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
67442new file mode 100644
67443index 0000000..be66033
67444--- /dev/null
67445+++ b/include/linux/grdefs.h
67446@@ -0,0 +1,140 @@
67447+#ifndef GRDEFS_H
67448+#define GRDEFS_H
67449+
67450+/* Begin grsecurity status declarations */
67451+
67452+enum {
67453+ GR_READY = 0x01,
67454+ GR_STATUS_INIT = 0x00 // disabled state
67455+};
67456+
67457+/* Begin ACL declarations */
67458+
67459+/* Role flags */
67460+
67461+enum {
67462+ GR_ROLE_USER = 0x0001,
67463+ GR_ROLE_GROUP = 0x0002,
67464+ GR_ROLE_DEFAULT = 0x0004,
67465+ GR_ROLE_SPECIAL = 0x0008,
67466+ GR_ROLE_AUTH = 0x0010,
67467+ GR_ROLE_NOPW = 0x0020,
67468+ GR_ROLE_GOD = 0x0040,
67469+ GR_ROLE_LEARN = 0x0080,
67470+ GR_ROLE_TPE = 0x0100,
67471+ GR_ROLE_DOMAIN = 0x0200,
67472+ GR_ROLE_PAM = 0x0400,
67473+ GR_ROLE_PERSIST = 0x0800
67474+};
67475+
67476+/* ACL Subject and Object mode flags */
67477+enum {
67478+ GR_DELETED = 0x80000000
67479+};
67480+
67481+/* ACL Object-only mode flags */
67482+enum {
67483+ GR_READ = 0x00000001,
67484+ GR_APPEND = 0x00000002,
67485+ GR_WRITE = 0x00000004,
67486+ GR_EXEC = 0x00000008,
67487+ GR_FIND = 0x00000010,
67488+ GR_INHERIT = 0x00000020,
67489+ GR_SETID = 0x00000040,
67490+ GR_CREATE = 0x00000080,
67491+ GR_DELETE = 0x00000100,
67492+ GR_LINK = 0x00000200,
67493+ GR_AUDIT_READ = 0x00000400,
67494+ GR_AUDIT_APPEND = 0x00000800,
67495+ GR_AUDIT_WRITE = 0x00001000,
67496+ GR_AUDIT_EXEC = 0x00002000,
67497+ GR_AUDIT_FIND = 0x00004000,
67498+ GR_AUDIT_INHERIT= 0x00008000,
67499+ GR_AUDIT_SETID = 0x00010000,
67500+ GR_AUDIT_CREATE = 0x00020000,
67501+ GR_AUDIT_DELETE = 0x00040000,
67502+ GR_AUDIT_LINK = 0x00080000,
67503+ GR_PTRACERD = 0x00100000,
67504+ GR_NOPTRACE = 0x00200000,
67505+ GR_SUPPRESS = 0x00400000,
67506+ GR_NOLEARN = 0x00800000,
67507+ GR_INIT_TRANSFER= 0x01000000
67508+};
67509+
67510+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
67511+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
67512+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
67513+
67514+/* ACL subject-only mode flags */
67515+enum {
67516+ GR_KILL = 0x00000001,
67517+ GR_VIEW = 0x00000002,
67518+ GR_PROTECTED = 0x00000004,
67519+ GR_LEARN = 0x00000008,
67520+ GR_OVERRIDE = 0x00000010,
67521+ /* just a placeholder, this mode is only used in userspace */
67522+ GR_DUMMY = 0x00000020,
67523+ GR_PROTSHM = 0x00000040,
67524+ GR_KILLPROC = 0x00000080,
67525+ GR_KILLIPPROC = 0x00000100,
67526+ /* just a placeholder, this mode is only used in userspace */
67527+ GR_NOTROJAN = 0x00000200,
67528+ GR_PROTPROCFD = 0x00000400,
67529+ GR_PROCACCT = 0x00000800,
67530+ GR_RELAXPTRACE = 0x00001000,
67531+ //GR_NESTED = 0x00002000,
67532+ GR_INHERITLEARN = 0x00004000,
67533+ GR_PROCFIND = 0x00008000,
67534+ GR_POVERRIDE = 0x00010000,
67535+ GR_KERNELAUTH = 0x00020000,
67536+ GR_ATSECURE = 0x00040000,
67537+ GR_SHMEXEC = 0x00080000
67538+};
67539+
67540+enum {
67541+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
67542+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
67543+ GR_PAX_ENABLE_MPROTECT = 0x0004,
67544+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
67545+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
67546+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
67547+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
67548+ GR_PAX_DISABLE_MPROTECT = 0x0400,
67549+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
67550+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
67551+};
67552+
67553+enum {
67554+ GR_ID_USER = 0x01,
67555+ GR_ID_GROUP = 0x02,
67556+};
67557+
67558+enum {
67559+ GR_ID_ALLOW = 0x01,
67560+ GR_ID_DENY = 0x02,
67561+};
67562+
67563+#define GR_CRASH_RES 31
67564+#define GR_UIDTABLE_MAX 500
67565+
67566+/* begin resource learning section */
67567+enum {
67568+ GR_RLIM_CPU_BUMP = 60,
67569+ GR_RLIM_FSIZE_BUMP = 50000,
67570+ GR_RLIM_DATA_BUMP = 10000,
67571+ GR_RLIM_STACK_BUMP = 1000,
67572+ GR_RLIM_CORE_BUMP = 10000,
67573+ GR_RLIM_RSS_BUMP = 500000,
67574+ GR_RLIM_NPROC_BUMP = 1,
67575+ GR_RLIM_NOFILE_BUMP = 5,
67576+ GR_RLIM_MEMLOCK_BUMP = 50000,
67577+ GR_RLIM_AS_BUMP = 500000,
67578+ GR_RLIM_LOCKS_BUMP = 2,
67579+ GR_RLIM_SIGPENDING_BUMP = 5,
67580+ GR_RLIM_MSGQUEUE_BUMP = 10000,
67581+ GR_RLIM_NICE_BUMP = 1,
67582+ GR_RLIM_RTPRIO_BUMP = 1,
67583+ GR_RLIM_RTTIME_BUMP = 1000000
67584+};
67585+
67586+#endif
67587diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
67588new file mode 100644
67589index 0000000..9bb6662
67590--- /dev/null
67591+++ b/include/linux/grinternal.h
67592@@ -0,0 +1,215 @@
67593+#ifndef __GRINTERNAL_H
67594+#define __GRINTERNAL_H
67595+
67596+#ifdef CONFIG_GRKERNSEC
67597+
67598+#include <linux/fs.h>
67599+#include <linux/mnt_namespace.h>
67600+#include <linux/nsproxy.h>
67601+#include <linux/gracl.h>
67602+#include <linux/grdefs.h>
67603+#include <linux/grmsg.h>
67604+
67605+void gr_add_learn_entry(const char *fmt, ...)
67606+ __attribute__ ((format (printf, 1, 2)));
67607+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
67608+ const struct vfsmount *mnt);
67609+__u32 gr_check_create(const struct dentry *new_dentry,
67610+ const struct dentry *parent,
67611+ const struct vfsmount *mnt, const __u32 mode);
67612+int gr_check_protected_task(const struct task_struct *task);
67613+__u32 to_gr_audit(const __u32 reqmode);
67614+int gr_set_acls(const int type);
67615+int gr_apply_subject_to_task(struct task_struct *task);
67616+int gr_acl_is_enabled(void);
67617+char gr_roletype_to_char(void);
67618+
67619+void gr_handle_alertkill(struct task_struct *task);
67620+char *gr_to_filename(const struct dentry *dentry,
67621+ const struct vfsmount *mnt);
67622+char *gr_to_filename1(const struct dentry *dentry,
67623+ const struct vfsmount *mnt);
67624+char *gr_to_filename2(const struct dentry *dentry,
67625+ const struct vfsmount *mnt);
67626+char *gr_to_filename3(const struct dentry *dentry,
67627+ const struct vfsmount *mnt);
67628+
67629+extern int grsec_enable_ptrace_readexec;
67630+extern int grsec_enable_harden_ptrace;
67631+extern int grsec_enable_link;
67632+extern int grsec_enable_fifo;
67633+extern int grsec_enable_execve;
67634+extern int grsec_enable_shm;
67635+extern int grsec_enable_execlog;
67636+extern int grsec_enable_signal;
67637+extern int grsec_enable_audit_ptrace;
67638+extern int grsec_enable_forkfail;
67639+extern int grsec_enable_time;
67640+extern int grsec_enable_rofs;
67641+extern int grsec_enable_chroot_shmat;
67642+extern int grsec_enable_chroot_mount;
67643+extern int grsec_enable_chroot_double;
67644+extern int grsec_enable_chroot_pivot;
67645+extern int grsec_enable_chroot_chdir;
67646+extern int grsec_enable_chroot_chmod;
67647+extern int grsec_enable_chroot_mknod;
67648+extern int grsec_enable_chroot_fchdir;
67649+extern int grsec_enable_chroot_nice;
67650+extern int grsec_enable_chroot_execlog;
67651+extern int grsec_enable_chroot_caps;
67652+extern int grsec_enable_chroot_sysctl;
67653+extern int grsec_enable_chroot_unix;
67654+extern int grsec_enable_symlinkown;
67655+extern kgid_t grsec_symlinkown_gid;
67656+extern int grsec_enable_tpe;
67657+extern kgid_t grsec_tpe_gid;
67658+extern int grsec_enable_tpe_all;
67659+extern int grsec_enable_tpe_invert;
67660+extern int grsec_enable_socket_all;
67661+extern kgid_t grsec_socket_all_gid;
67662+extern int grsec_enable_socket_client;
67663+extern kgid_t grsec_socket_client_gid;
67664+extern int grsec_enable_socket_server;
67665+extern kgid_t grsec_socket_server_gid;
67666+extern kgid_t grsec_audit_gid;
67667+extern int grsec_enable_group;
67668+extern int grsec_enable_audit_textrel;
67669+extern int grsec_enable_log_rwxmaps;
67670+extern int grsec_enable_mount;
67671+extern int grsec_enable_chdir;
67672+extern int grsec_resource_logging;
67673+extern int grsec_enable_blackhole;
67674+extern int grsec_lastack_retries;
67675+extern int grsec_enable_brute;
67676+extern int grsec_lock;
67677+
67678+extern spinlock_t grsec_alert_lock;
67679+extern unsigned long grsec_alert_wtime;
67680+extern unsigned long grsec_alert_fyet;
67681+
67682+extern spinlock_t grsec_audit_lock;
67683+
67684+extern rwlock_t grsec_exec_file_lock;
67685+
67686+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
67687+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
67688+ (tsk)->exec_file->f_vfsmnt) : "/")
67689+
67690+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
67691+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
67692+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67693+
67694+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
67695+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
67696+ (tsk)->exec_file->f_vfsmnt) : "/")
67697+
67698+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
67699+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
67700+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67701+
67702+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
67703+
67704+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
67705+
67706+#define GR_CHROOT_CAPS {{ \
67707+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
67708+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
67709+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
67710+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
67711+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
67712+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
67713+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
67714+
67715+#define security_learn(normal_msg,args...) \
67716+({ \
67717+ read_lock(&grsec_exec_file_lock); \
67718+ gr_add_learn_entry(normal_msg "\n", ## args); \
67719+ read_unlock(&grsec_exec_file_lock); \
67720+})
67721+
67722+enum {
67723+ GR_DO_AUDIT,
67724+ GR_DONT_AUDIT,
67725+ /* used for non-audit messages that we shouldn't kill the task on */
67726+ GR_DONT_AUDIT_GOOD
67727+};
67728+
67729+enum {
67730+ GR_TTYSNIFF,
67731+ GR_RBAC,
67732+ GR_RBAC_STR,
67733+ GR_STR_RBAC,
67734+ GR_RBAC_MODE2,
67735+ GR_RBAC_MODE3,
67736+ GR_FILENAME,
67737+ GR_SYSCTL_HIDDEN,
67738+ GR_NOARGS,
67739+ GR_ONE_INT,
67740+ GR_ONE_INT_TWO_STR,
67741+ GR_ONE_STR,
67742+ GR_STR_INT,
67743+ GR_TWO_STR_INT,
67744+ GR_TWO_INT,
67745+ GR_TWO_U64,
67746+ GR_THREE_INT,
67747+ GR_FIVE_INT_TWO_STR,
67748+ GR_TWO_STR,
67749+ GR_THREE_STR,
67750+ GR_FOUR_STR,
67751+ GR_STR_FILENAME,
67752+ GR_FILENAME_STR,
67753+ GR_FILENAME_TWO_INT,
67754+ GR_FILENAME_TWO_INT_STR,
67755+ GR_TEXTREL,
67756+ GR_PTRACE,
67757+ GR_RESOURCE,
67758+ GR_CAP,
67759+ GR_SIG,
67760+ GR_SIG2,
67761+ GR_CRASH1,
67762+ GR_CRASH2,
67763+ GR_PSACCT,
67764+ GR_RWXMAP
67765+};
67766+
67767+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
67768+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
67769+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
67770+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
67771+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
67772+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
67773+#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)
67774+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
67775+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
67776+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
67777+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
67778+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
67779+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
67780+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
67781+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
67782+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
67783+#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)
67784+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
67785+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
67786+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
67787+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
67788+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
67789+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
67790+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
67791+#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)
67792+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
67793+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
67794+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
67795+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
67796+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
67797+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
67798+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
67799+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
67800+#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)
67801+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
67802+
67803+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
67804+
67805+#endif
67806+
67807+#endif
67808diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
67809new file mode 100644
67810index 0000000..2bd4c8d
67811--- /dev/null
67812+++ b/include/linux/grmsg.h
67813@@ -0,0 +1,111 @@
67814+#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"
67815+#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"
67816+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
67817+#define GR_STOPMOD_MSG "denied modification of module state by "
67818+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
67819+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
67820+#define GR_IOPERM_MSG "denied use of ioperm() by "
67821+#define GR_IOPL_MSG "denied use of iopl() by "
67822+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
67823+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
67824+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
67825+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
67826+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
67827+#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"
67828+#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"
67829+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
67830+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
67831+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
67832+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
67833+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
67834+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
67835+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
67836+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
67837+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
67838+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
67839+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
67840+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
67841+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
67842+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
67843+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
67844+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
67845+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
67846+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
67847+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
67848+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
67849+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
67850+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
67851+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
67852+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
67853+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
67854+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
67855+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
67856+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
67857+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
67858+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
67859+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
67860+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
67861+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
67862+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
67863+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
67864+#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"
67865+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
67866+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
67867+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
67868+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
67869+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
67870+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
67871+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
67872+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
67873+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
67874+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
67875+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
67876+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
67877+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
67878+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
67879+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
67880+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
67881+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
67882+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
67883+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
67884+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
67885+#define GR_FAILFORK_MSG "failed fork with errno %s by "
67886+#define GR_NICE_CHROOT_MSG "denied priority change by "
67887+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
67888+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
67889+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
67890+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
67891+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
67892+#define GR_TIME_MSG "time set by "
67893+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
67894+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
67895+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
67896+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
67897+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
67898+#define GR_BIND_MSG "denied bind() by "
67899+#define GR_CONNECT_MSG "denied connect() by "
67900+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
67901+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
67902+#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"
67903+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
67904+#define GR_CAP_ACL_MSG "use of %s denied for "
67905+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
67906+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
67907+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
67908+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
67909+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
67910+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
67911+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
67912+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
67913+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
67914+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
67915+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
67916+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
67917+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
67918+#define GR_VM86_MSG "denied use of vm86 by "
67919+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
67920+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
67921+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
67922+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
67923+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
67924+#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 "
67925diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
67926new file mode 100644
67927index 0000000..1ae241a
67928--- /dev/null
67929+++ b/include/linux/grsecurity.h
67930@@ -0,0 +1,257 @@
67931+#ifndef GR_SECURITY_H
67932+#define GR_SECURITY_H
67933+#include <linux/fs.h>
67934+#include <linux/fs_struct.h>
67935+#include <linux/binfmts.h>
67936+#include <linux/gracl.h>
67937+
67938+/* notify of brain-dead configs */
67939+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67940+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
67941+#endif
67942+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
67943+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
67944+#endif
67945+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
67946+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
67947+#endif
67948+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
67949+#error "CONFIG_PAX enabled, but no PaX options are enabled."
67950+#endif
67951+
67952+#include <linux/compat.h>
67953+
67954+struct user_arg_ptr {
67955+#ifdef CONFIG_COMPAT
67956+ bool is_compat;
67957+#endif
67958+ union {
67959+ const char __user *const __user *native;
67960+#ifdef CONFIG_COMPAT
67961+ const compat_uptr_t __user *compat;
67962+#endif
67963+ } ptr;
67964+};
67965+
67966+void gr_handle_brute_attach(unsigned long mm_flags);
67967+void gr_handle_brute_check(void);
67968+void gr_handle_kernel_exploit(void);
67969+int gr_process_user_ban(void);
67970+
67971+char gr_roletype_to_char(void);
67972+
67973+int gr_acl_enable_at_secure(void);
67974+
67975+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
67976+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
67977+
67978+void gr_del_task_from_ip_table(struct task_struct *p);
67979+
67980+int gr_pid_is_chrooted(struct task_struct *p);
67981+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
67982+int gr_handle_chroot_nice(void);
67983+int gr_handle_chroot_sysctl(const int op);
67984+int gr_handle_chroot_setpriority(struct task_struct *p,
67985+ const int niceval);
67986+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
67987+int gr_handle_chroot_chroot(const struct dentry *dentry,
67988+ const struct vfsmount *mnt);
67989+void gr_handle_chroot_chdir(struct path *path);
67990+int gr_handle_chroot_chmod(const struct dentry *dentry,
67991+ const struct vfsmount *mnt, const int mode);
67992+int gr_handle_chroot_mknod(const struct dentry *dentry,
67993+ const struct vfsmount *mnt, const int mode);
67994+int gr_handle_chroot_mount(const struct dentry *dentry,
67995+ const struct vfsmount *mnt,
67996+ const char *dev_name);
67997+int gr_handle_chroot_pivot(void);
67998+int gr_handle_chroot_unix(const pid_t pid);
67999+
68000+int gr_handle_rawio(const struct inode *inode);
68001+
68002+void gr_handle_ioperm(void);
68003+void gr_handle_iopl(void);
68004+
68005+umode_t gr_acl_umask(void);
68006+
68007+int gr_tpe_allow(const struct file *file);
68008+
68009+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68010+void gr_clear_chroot_entries(struct task_struct *task);
68011+
68012+void gr_log_forkfail(const int retval);
68013+void gr_log_timechange(void);
68014+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68015+void gr_log_chdir(const struct dentry *dentry,
68016+ const struct vfsmount *mnt);
68017+void gr_log_chroot_exec(const struct dentry *dentry,
68018+ const struct vfsmount *mnt);
68019+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
68020+void gr_log_remount(const char *devname, const int retval);
68021+void gr_log_unmount(const char *devname, const int retval);
68022+void gr_log_mount(const char *from, const char *to, const int retval);
68023+void gr_log_textrel(struct vm_area_struct *vma);
68024+void gr_log_rwxmmap(struct file *file);
68025+void gr_log_rwxmprotect(struct file *file);
68026+
68027+int gr_handle_follow_link(const struct inode *parent,
68028+ const struct inode *inode,
68029+ const struct dentry *dentry,
68030+ const struct vfsmount *mnt);
68031+int gr_handle_fifo(const struct dentry *dentry,
68032+ const struct vfsmount *mnt,
68033+ const struct dentry *dir, const int flag,
68034+ const int acc_mode);
68035+int gr_handle_hardlink(const struct dentry *dentry,
68036+ const struct vfsmount *mnt,
68037+ struct inode *inode,
68038+ const int mode, const struct filename *to);
68039+
68040+int gr_is_capable(const int cap);
68041+int gr_is_capable_nolog(const int cap);
68042+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68043+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68044+
68045+void gr_copy_label(struct task_struct *tsk);
68046+void gr_handle_crash(struct task_struct *task, const int sig);
68047+int gr_handle_signal(const struct task_struct *p, const int sig);
68048+int gr_check_crash_uid(const kuid_t uid);
68049+int gr_check_protected_task(const struct task_struct *task);
68050+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68051+int gr_acl_handle_mmap(const struct file *file,
68052+ const unsigned long prot);
68053+int gr_acl_handle_mprotect(const struct file *file,
68054+ const unsigned long prot);
68055+int gr_check_hidden_task(const struct task_struct *tsk);
68056+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68057+ const struct vfsmount *mnt);
68058+__u32 gr_acl_handle_utime(const struct dentry *dentry,
68059+ const struct vfsmount *mnt);
68060+__u32 gr_acl_handle_access(const struct dentry *dentry,
68061+ const struct vfsmount *mnt, const int fmode);
68062+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68063+ const struct vfsmount *mnt, umode_t *mode);
68064+__u32 gr_acl_handle_chown(const struct dentry *dentry,
68065+ const struct vfsmount *mnt);
68066+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68067+ const struct vfsmount *mnt);
68068+int gr_handle_ptrace(struct task_struct *task, const long request);
68069+int gr_handle_proc_ptrace(struct task_struct *task);
68070+__u32 gr_acl_handle_execve(const struct dentry *dentry,
68071+ const struct vfsmount *mnt);
68072+int gr_check_crash_exec(const struct file *filp);
68073+int gr_acl_is_enabled(void);
68074+void gr_set_kernel_label(struct task_struct *task);
68075+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68076+ const kgid_t gid);
68077+int gr_set_proc_label(const struct dentry *dentry,
68078+ const struct vfsmount *mnt,
68079+ const int unsafe_flags);
68080+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68081+ const struct vfsmount *mnt);
68082+__u32 gr_acl_handle_open(const struct dentry *dentry,
68083+ const struct vfsmount *mnt, int acc_mode);
68084+__u32 gr_acl_handle_creat(const struct dentry *dentry,
68085+ const struct dentry *p_dentry,
68086+ const struct vfsmount *p_mnt,
68087+ int open_flags, int acc_mode, const int imode);
68088+void gr_handle_create(const struct dentry *dentry,
68089+ const struct vfsmount *mnt);
68090+void gr_handle_proc_create(const struct dentry *dentry,
68091+ const struct inode *inode);
68092+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68093+ const struct dentry *parent_dentry,
68094+ const struct vfsmount *parent_mnt,
68095+ const int mode);
68096+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68097+ const struct dentry *parent_dentry,
68098+ const struct vfsmount *parent_mnt);
68099+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68100+ const struct vfsmount *mnt);
68101+void gr_handle_delete(const ino_t ino, const dev_t dev);
68102+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68103+ const struct vfsmount *mnt);
68104+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68105+ const struct dentry *parent_dentry,
68106+ const struct vfsmount *parent_mnt,
68107+ const struct filename *from);
68108+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68109+ const struct dentry *parent_dentry,
68110+ const struct vfsmount *parent_mnt,
68111+ const struct dentry *old_dentry,
68112+ const struct vfsmount *old_mnt, const struct filename *to);
68113+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68114+int gr_acl_handle_rename(struct dentry *new_dentry,
68115+ struct dentry *parent_dentry,
68116+ const struct vfsmount *parent_mnt,
68117+ struct dentry *old_dentry,
68118+ struct inode *old_parent_inode,
68119+ struct vfsmount *old_mnt, const struct filename *newname);
68120+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68121+ struct dentry *old_dentry,
68122+ struct dentry *new_dentry,
68123+ struct vfsmount *mnt, const __u8 replace);
68124+__u32 gr_check_link(const struct dentry *new_dentry,
68125+ const struct dentry *parent_dentry,
68126+ const struct vfsmount *parent_mnt,
68127+ const struct dentry *old_dentry,
68128+ const struct vfsmount *old_mnt);
68129+int gr_acl_handle_filldir(const struct file *file, const char *name,
68130+ const unsigned int namelen, const ino_t ino);
68131+
68132+__u32 gr_acl_handle_unix(const struct dentry *dentry,
68133+ const struct vfsmount *mnt);
68134+void gr_acl_handle_exit(void);
68135+void gr_acl_handle_psacct(struct task_struct *task, const long code);
68136+int gr_acl_handle_procpidmem(const struct task_struct *task);
68137+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68138+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68139+void gr_audit_ptrace(struct task_struct *task);
68140+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68141+void gr_put_exec_file(struct task_struct *task);
68142+
68143+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68144+
68145+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68146+extern void gr_learn_resource(const struct task_struct *task, const int res,
68147+ const unsigned long wanted, const int gt);
68148+#else
68149+static inline void gr_learn_resource(const struct task_struct *task, const int res,
68150+ const unsigned long wanted, const int gt)
68151+{
68152+}
68153+#endif
68154+
68155+#ifdef CONFIG_GRKERNSEC_RESLOG
68156+extern void gr_log_resource(const struct task_struct *task, const int res,
68157+ const unsigned long wanted, const int gt);
68158+#else
68159+static inline void gr_log_resource(const struct task_struct *task, const int res,
68160+ const unsigned long wanted, const int gt)
68161+{
68162+}
68163+#endif
68164+
68165+#ifdef CONFIG_GRKERNSEC
68166+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68167+void gr_handle_vm86(void);
68168+void gr_handle_mem_readwrite(u64 from, u64 to);
68169+
68170+void gr_log_badprocpid(const char *entry);
68171+
68172+extern int grsec_enable_dmesg;
68173+extern int grsec_disable_privio;
68174+
68175+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68176+extern kgid_t grsec_proc_gid;
68177+#endif
68178+
68179+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68180+extern int grsec_enable_chroot_findtask;
68181+#endif
68182+#ifdef CONFIG_GRKERNSEC_SETXID
68183+extern int grsec_enable_setxid;
68184+#endif
68185+#endif
68186+
68187+#endif
68188diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68189new file mode 100644
68190index 0000000..e7ffaaf
68191--- /dev/null
68192+++ b/include/linux/grsock.h
68193@@ -0,0 +1,19 @@
68194+#ifndef __GRSOCK_H
68195+#define __GRSOCK_H
68196+
68197+extern void gr_attach_curr_ip(const struct sock *sk);
68198+extern int gr_handle_sock_all(const int family, const int type,
68199+ const int protocol);
68200+extern int gr_handle_sock_server(const struct sockaddr *sck);
68201+extern int gr_handle_sock_server_other(const struct sock *sck);
68202+extern int gr_handle_sock_client(const struct sockaddr *sck);
68203+extern int gr_search_connect(struct socket * sock,
68204+ struct sockaddr_in * addr);
68205+extern int gr_search_bind(struct socket * sock,
68206+ struct sockaddr_in * addr);
68207+extern int gr_search_listen(struct socket * sock);
68208+extern int gr_search_accept(struct socket * sock);
68209+extern int gr_search_socket(const int domain, const int type,
68210+ const int protocol);
68211+
68212+#endif
68213diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68214index ef788b5..ac41b7b 100644
68215--- a/include/linux/highmem.h
68216+++ b/include/linux/highmem.h
68217@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68218 kunmap_atomic(kaddr);
68219 }
68220
68221+static inline void sanitize_highpage(struct page *page)
68222+{
68223+ void *kaddr;
68224+ unsigned long flags;
68225+
68226+ local_irq_save(flags);
68227+ kaddr = kmap_atomic(page);
68228+ clear_page(kaddr);
68229+ kunmap_atomic(kaddr);
68230+ local_irq_restore(flags);
68231+}
68232+
68233 static inline void zero_user_segments(struct page *page,
68234 unsigned start1, unsigned end1,
68235 unsigned start2, unsigned end2)
68236diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68237index 1c7b89a..7f52502 100644
68238--- a/include/linux/hwmon-sysfs.h
68239+++ b/include/linux/hwmon-sysfs.h
68240@@ -25,7 +25,8 @@
68241 struct sensor_device_attribute{
68242 struct device_attribute dev_attr;
68243 int index;
68244-};
68245+} __do_const;
68246+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68247 #define to_sensor_dev_attr(_dev_attr) \
68248 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68249
68250@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68251 struct device_attribute dev_attr;
68252 u8 index;
68253 u8 nr;
68254-};
68255+} __do_const;
68256 #define to_sensor_dev_attr_2(_dev_attr) \
68257 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68258
68259diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68260index d0c4db7..61b3577 100644
68261--- a/include/linux/i2c.h
68262+++ b/include/linux/i2c.h
68263@@ -369,6 +369,7 @@ struct i2c_algorithm {
68264 /* To determine what the adapter supports */
68265 u32 (*functionality) (struct i2c_adapter *);
68266 };
68267+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68268
68269 /*
68270 * i2c_adapter is the structure used to identify a physical i2c bus along
68271diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68272index d23c3c2..eb63c81 100644
68273--- a/include/linux/i2o.h
68274+++ b/include/linux/i2o.h
68275@@ -565,7 +565,7 @@ struct i2o_controller {
68276 struct i2o_device *exec; /* Executive */
68277 #if BITS_PER_LONG == 64
68278 spinlock_t context_list_lock; /* lock for context_list */
68279- atomic_t context_list_counter; /* needed for unique contexts */
68280+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68281 struct list_head context_list; /* list of context id's
68282 and pointers */
68283 #endif
68284diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68285index aff7ad8..3942bbd 100644
68286--- a/include/linux/if_pppox.h
68287+++ b/include/linux/if_pppox.h
68288@@ -76,7 +76,7 @@ struct pppox_proto {
68289 int (*ioctl)(struct socket *sock, unsigned int cmd,
68290 unsigned long arg);
68291 struct module *owner;
68292-};
68293+} __do_const;
68294
68295 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68296 extern void unregister_pppox_proto(int proto_num);
68297diff --git a/include/linux/init.h b/include/linux/init.h
68298index 10ed4f4..8e8490d 100644
68299--- a/include/linux/init.h
68300+++ b/include/linux/init.h
68301@@ -39,9 +39,36 @@
68302 * Also note, that this data cannot be "const".
68303 */
68304
68305+#ifdef MODULE
68306+#define add_init_latent_entropy
68307+#define add_devinit_latent_entropy
68308+#define add_cpuinit_latent_entropy
68309+#define add_meminit_latent_entropy
68310+#else
68311+#define add_init_latent_entropy __latent_entropy
68312+
68313+#ifdef CONFIG_HOTPLUG
68314+#define add_devinit_latent_entropy
68315+#else
68316+#define add_devinit_latent_entropy __latent_entropy
68317+#endif
68318+
68319+#ifdef CONFIG_HOTPLUG_CPU
68320+#define add_cpuinit_latent_entropy
68321+#else
68322+#define add_cpuinit_latent_entropy __latent_entropy
68323+#endif
68324+
68325+#ifdef CONFIG_MEMORY_HOTPLUG
68326+#define add_meminit_latent_entropy
68327+#else
68328+#define add_meminit_latent_entropy __latent_entropy
68329+#endif
68330+#endif
68331+
68332 /* These are for everybody (although not all archs will actually
68333 discard it in modules) */
68334-#define __init __section(.init.text) __cold notrace
68335+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68336 #define __initdata __section(.init.data)
68337 #define __initconst __constsection(.init.rodata)
68338 #define __exitdata __section(.exit.data)
68339@@ -94,7 +121,7 @@
68340 #define __exit __section(.exit.text) __exitused __cold notrace
68341
68342 /* Used for HOTPLUG_CPU */
68343-#define __cpuinit __section(.cpuinit.text) __cold notrace
68344+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68345 #define __cpuinitdata __section(.cpuinit.data)
68346 #define __cpuinitconst __constsection(.cpuinit.rodata)
68347 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68348@@ -102,7 +129,7 @@
68349 #define __cpuexitconst __constsection(.cpuexit.rodata)
68350
68351 /* Used for MEMORY_HOTPLUG */
68352-#define __meminit __section(.meminit.text) __cold notrace
68353+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68354 #define __meminitdata __section(.meminit.data)
68355 #define __meminitconst __constsection(.meminit.rodata)
68356 #define __memexit __section(.memexit.text) __exitused __cold notrace
68357diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68358index 6d087c5..401cab8 100644
68359--- a/include/linux/init_task.h
68360+++ b/include/linux/init_task.h
68361@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68362
68363 #define INIT_TASK_COMM "swapper"
68364
68365+#ifdef CONFIG_X86
68366+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68367+#else
68368+#define INIT_TASK_THREAD_INFO
68369+#endif
68370+
68371 /*
68372 * INIT_TASK is used to set up the first task table, touch at
68373 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68374@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68375 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68376 .comm = INIT_TASK_COMM, \
68377 .thread = INIT_THREAD, \
68378+ INIT_TASK_THREAD_INFO \
68379 .fs = &init_fs, \
68380 .files = &init_files, \
68381 .signal = &init_signals, \
68382diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68383index 5fa5afe..ac55b25 100644
68384--- a/include/linux/interrupt.h
68385+++ b/include/linux/interrupt.h
68386@@ -430,7 +430,7 @@ enum
68387 /* map softirq index to softirq name. update 'softirq_to_name' in
68388 * kernel/softirq.c when adding a new softirq.
68389 */
68390-extern char *softirq_to_name[NR_SOFTIRQS];
68391+extern const char * const softirq_to_name[NR_SOFTIRQS];
68392
68393 /* softirq mask and active fields moved to irq_cpustat_t in
68394 * asm/hardirq.h to get better cache usage. KAO
68395@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68396
68397 struct softirq_action
68398 {
68399- void (*action)(struct softirq_action *);
68400-};
68401+ void (*action)(void);
68402+} __no_const;
68403
68404 asmlinkage void do_softirq(void);
68405 asmlinkage void __do_softirq(void);
68406-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68407+extern void open_softirq(int nr, void (*action)(void));
68408 extern void softirq_init(void);
68409 extern void __raise_softirq_irqoff(unsigned int nr);
68410
68411diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68412index f3b99e1..9b73cee 100644
68413--- a/include/linux/iommu.h
68414+++ b/include/linux/iommu.h
68415@@ -101,7 +101,7 @@ struct iommu_ops {
68416 int (*domain_set_attr)(struct iommu_domain *domain,
68417 enum iommu_attr attr, void *data);
68418 unsigned long pgsize_bitmap;
68419-};
68420+} __do_const;
68421
68422 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
68423 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
68424diff --git a/include/linux/irq.h b/include/linux/irq.h
68425index fdf2c4a..5332486 100644
68426--- a/include/linux/irq.h
68427+++ b/include/linux/irq.h
68428@@ -328,7 +328,8 @@ struct irq_chip {
68429 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
68430
68431 unsigned long flags;
68432-};
68433+} __do_const;
68434+typedef struct irq_chip __no_const irq_chip_no_const;
68435
68436 /*
68437 * irq_chip specific flags
68438diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
68439index 6883e19..06992b1 100644
68440--- a/include/linux/kallsyms.h
68441+++ b/include/linux/kallsyms.h
68442@@ -15,7 +15,8 @@
68443
68444 struct module;
68445
68446-#ifdef CONFIG_KALLSYMS
68447+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
68448+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68449 /* Lookup the address for a symbol. Returns 0 if not found. */
68450 unsigned long kallsyms_lookup_name(const char *name);
68451
68452@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
68453 /* Stupid that this does nothing, but I didn't create this mess. */
68454 #define __print_symbol(fmt, addr)
68455 #endif /*CONFIG_KALLSYMS*/
68456+#else /* when included by kallsyms.c, vsnprintf.c, or
68457+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
68458+extern void __print_symbol(const char *fmt, unsigned long address);
68459+extern int sprint_backtrace(char *buffer, unsigned long address);
68460+extern int sprint_symbol(char *buffer, unsigned long address);
68461+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
68462+const char *kallsyms_lookup(unsigned long addr,
68463+ unsigned long *symbolsize,
68464+ unsigned long *offset,
68465+ char **modname, char *namebuf);
68466+#endif
68467
68468 /* This macro allows us to keep printk typechecking */
68469 static __printf(1, 2)
68470diff --git a/include/linux/key-type.h b/include/linux/key-type.h
68471index 518a53a..5e28358 100644
68472--- a/include/linux/key-type.h
68473+++ b/include/linux/key-type.h
68474@@ -125,7 +125,7 @@ struct key_type {
68475 /* internal fields */
68476 struct list_head link; /* link in types list */
68477 struct lock_class_key lock_class; /* key->sem lock class */
68478-};
68479+} __do_const;
68480
68481 extern struct key_type key_type_keyring;
68482
68483diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
68484index 4dff0c6..1ca9b72 100644
68485--- a/include/linux/kgdb.h
68486+++ b/include/linux/kgdb.h
68487@@ -53,7 +53,7 @@ extern int kgdb_connected;
68488 extern int kgdb_io_module_registered;
68489
68490 extern atomic_t kgdb_setting_breakpoint;
68491-extern atomic_t kgdb_cpu_doing_single_step;
68492+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
68493
68494 extern struct task_struct *kgdb_usethread;
68495 extern struct task_struct *kgdb_contthread;
68496@@ -255,7 +255,7 @@ struct kgdb_arch {
68497 void (*correct_hw_break)(void);
68498
68499 void (*enable_nmi)(bool on);
68500-};
68501+} __do_const;
68502
68503 /**
68504 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
68505@@ -280,7 +280,7 @@ struct kgdb_io {
68506 void (*pre_exception) (void);
68507 void (*post_exception) (void);
68508 int is_console;
68509-};
68510+} __do_const;
68511
68512 extern struct kgdb_arch arch_kgdb_ops;
68513
68514diff --git a/include/linux/kmod.h b/include/linux/kmod.h
68515index 5398d58..5883a34 100644
68516--- a/include/linux/kmod.h
68517+++ b/include/linux/kmod.h
68518@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
68519 * usually useless though. */
68520 extern __printf(2, 3)
68521 int __request_module(bool wait, const char *name, ...);
68522+extern __printf(3, 4)
68523+int ___request_module(bool wait, char *param_name, const char *name, ...);
68524 #define request_module(mod...) __request_module(true, mod)
68525 #define request_module_nowait(mod...) __request_module(false, mod)
68526 #define try_then_request_module(x, mod...) \
68527diff --git a/include/linux/kobject.h b/include/linux/kobject.h
68528index 939b112..ed6ed51 100644
68529--- a/include/linux/kobject.h
68530+++ b/include/linux/kobject.h
68531@@ -111,7 +111,7 @@ struct kobj_type {
68532 struct attribute **default_attrs;
68533 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
68534 const void *(*namespace)(struct kobject *kobj);
68535-};
68536+} __do_const;
68537
68538 struct kobj_uevent_env {
68539 char *envp[UEVENT_NUM_ENVP];
68540@@ -134,6 +134,7 @@ struct kobj_attribute {
68541 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
68542 const char *buf, size_t count);
68543 };
68544+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
68545
68546 extern const struct sysfs_ops kobj_sysfs_ops;
68547
68548diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
68549index f66b065..c2c29b4 100644
68550--- a/include/linux/kobject_ns.h
68551+++ b/include/linux/kobject_ns.h
68552@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
68553 const void *(*netlink_ns)(struct sock *sk);
68554 const void *(*initial_ns)(void);
68555 void (*drop_ns)(void *);
68556-};
68557+} __do_const;
68558
68559 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
68560 int kobj_ns_type_registered(enum kobj_ns_type type);
68561diff --git a/include/linux/kref.h b/include/linux/kref.h
68562index 4972e6e..de4d19b 100644
68563--- a/include/linux/kref.h
68564+++ b/include/linux/kref.h
68565@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
68566 static inline int kref_sub(struct kref *kref, unsigned int count,
68567 void (*release)(struct kref *kref))
68568 {
68569- WARN_ON(release == NULL);
68570+ BUG_ON(release == NULL);
68571
68572 if (atomic_sub_and_test((int) count, &kref->refcount)) {
68573 release(kref);
68574diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
68575index 2c497ab..afe32f5 100644
68576--- a/include/linux/kvm_host.h
68577+++ b/include/linux/kvm_host.h
68578@@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
68579 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
68580 void vcpu_put(struct kvm_vcpu *vcpu);
68581
68582-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68583+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68584 struct module *module);
68585 void kvm_exit(void);
68586
68587@@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
68588 struct kvm_guest_debug *dbg);
68589 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
68590
68591-int kvm_arch_init(void *opaque);
68592+int kvm_arch_init(const void *opaque);
68593 void kvm_arch_exit(void);
68594
68595 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
68596diff --git a/include/linux/libata.h b/include/linux/libata.h
68597index 649e5f8..ead5194 100644
68598--- a/include/linux/libata.h
68599+++ b/include/linux/libata.h
68600@@ -915,7 +915,7 @@ struct ata_port_operations {
68601 * fields must be pointers.
68602 */
68603 const struct ata_port_operations *inherits;
68604-};
68605+} __do_const;
68606
68607 struct ata_port_info {
68608 unsigned long flags;
68609diff --git a/include/linux/list.h b/include/linux/list.h
68610index cc6d2aa..c10ee83 100644
68611--- a/include/linux/list.h
68612+++ b/include/linux/list.h
68613@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
68614 extern void list_del(struct list_head *entry);
68615 #endif
68616
68617+extern void __pax_list_add(struct list_head *new,
68618+ struct list_head *prev,
68619+ struct list_head *next);
68620+static inline void pax_list_add(struct list_head *new, struct list_head *head)
68621+{
68622+ __pax_list_add(new, head, head->next);
68623+}
68624+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
68625+{
68626+ __pax_list_add(new, head->prev, head);
68627+}
68628+extern void pax_list_del(struct list_head *entry);
68629+
68630 /**
68631 * list_replace - replace old entry by new one
68632 * @old : the element to be replaced
68633@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
68634 INIT_LIST_HEAD(entry);
68635 }
68636
68637+extern void pax_list_del_init(struct list_head *entry);
68638+
68639 /**
68640 * list_move - delete from one list and add as another's head
68641 * @list: the entry to move
68642diff --git a/include/linux/mm.h b/include/linux/mm.h
68643index 66e2f7c..ea88001 100644
68644--- a/include/linux/mm.h
68645+++ b/include/linux/mm.h
68646@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
68647 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
68648 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
68649 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
68650+
68651+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68652+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
68653+#endif
68654+
68655 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
68656
68657 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
68658@@ -231,6 +236,7 @@ struct vm_operations_struct {
68659 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
68660 unsigned long size, pgoff_t pgoff);
68661 };
68662+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
68663
68664 struct mmu_gather;
68665 struct inode;
68666@@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
68667 int set_page_dirty_lock(struct page *page);
68668 int clear_page_dirty_for_io(struct page *page);
68669
68670-/* Is the vma a continuation of the stack vma above it? */
68671-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
68672-{
68673- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
68674-}
68675-
68676-static inline int stack_guard_page_start(struct vm_area_struct *vma,
68677- unsigned long addr)
68678-{
68679- return (vma->vm_flags & VM_GROWSDOWN) &&
68680- (vma->vm_start == addr) &&
68681- !vma_growsdown(vma->vm_prev, addr);
68682-}
68683-
68684-/* Is the vma a continuation of the stack vma below it? */
68685-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
68686-{
68687- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
68688-}
68689-
68690-static inline int stack_guard_page_end(struct vm_area_struct *vma,
68691- unsigned long addr)
68692-{
68693- return (vma->vm_flags & VM_GROWSUP) &&
68694- (vma->vm_end == addr) &&
68695- !vma_growsup(vma->vm_next, addr);
68696-}
68697-
68698 extern pid_t
68699 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
68700
68701@@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
68702 }
68703 #endif
68704
68705+#ifdef CONFIG_MMU
68706+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
68707+#else
68708+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68709+{
68710+ return __pgprot(0);
68711+}
68712+#endif
68713+
68714 int vma_wants_writenotify(struct vm_area_struct *vma);
68715
68716 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
68717@@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
68718 {
68719 return 0;
68720 }
68721+
68722+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
68723+ unsigned long address)
68724+{
68725+ return 0;
68726+}
68727 #else
68728 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68729+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68730 #endif
68731
68732 #ifdef __PAGETABLE_PMD_FOLDED
68733@@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
68734 {
68735 return 0;
68736 }
68737+
68738+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
68739+ unsigned long address)
68740+{
68741+ return 0;
68742+}
68743 #else
68744 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
68745+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
68746 #endif
68747
68748 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
68749@@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
68750 NULL: pud_offset(pgd, address);
68751 }
68752
68753+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
68754+{
68755+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
68756+ NULL: pud_offset(pgd, address);
68757+}
68758+
68759 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
68760 {
68761 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
68762 NULL: pmd_offset(pud, address);
68763 }
68764+
68765+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
68766+{
68767+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
68768+ NULL: pmd_offset(pud, address);
68769+}
68770 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
68771
68772 #if USE_SPLIT_PTLOCKS
68773@@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
68774 unsigned long, unsigned long,
68775 unsigned long, unsigned long);
68776 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
68777+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
68778
68779 /* These take the mm semaphore themselves */
68780 extern unsigned long vm_brk(unsigned long, unsigned long);
68781@@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
68782 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
68783 struct vm_area_struct **pprev);
68784
68785+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
68786+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
68787+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
68788+
68789 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
68790 NULL if none. Assume start_addr < end_addr. */
68791 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
68792@@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
68793 return vma;
68794 }
68795
68796-#ifdef CONFIG_MMU
68797-pgprot_t vm_get_page_prot(unsigned long vm_flags);
68798-#else
68799-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
68800-{
68801- return __pgprot(0);
68802-}
68803-#endif
68804-
68805 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
68806 unsigned long change_prot_numa(struct vm_area_struct *vma,
68807 unsigned long start, unsigned long end);
68808@@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
68809 extern int sysctl_memory_failure_early_kill;
68810 extern int sysctl_memory_failure_recovery;
68811 extern void shake_page(struct page *p, int access);
68812-extern atomic_long_t mce_bad_pages;
68813+extern atomic_long_unchecked_t mce_bad_pages;
68814 extern int soft_offline_page(struct page *page, int flags);
68815
68816 extern void dump_page(struct page *page);
68817@@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
68818 static inline bool page_is_guard(struct page *page) { return false; }
68819 #endif /* CONFIG_DEBUG_PAGEALLOC */
68820
68821+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68822+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
68823+#else
68824+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
68825+#endif
68826+
68827 #endif /* __KERNEL__ */
68828 #endif /* _LINUX_MM_H */
68829diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
68830index f8f5162..a039af9 100644
68831--- a/include/linux/mm_types.h
68832+++ b/include/linux/mm_types.h
68833@@ -288,6 +288,8 @@ struct vm_area_struct {
68834 #ifdef CONFIG_NUMA
68835 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
68836 #endif
68837+
68838+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
68839 };
68840
68841 struct core_thread {
68842@@ -362,7 +364,7 @@ struct mm_struct {
68843 unsigned long def_flags;
68844 unsigned long nr_ptes; /* Page table pages */
68845 unsigned long start_code, end_code, start_data, end_data;
68846- unsigned long start_brk, brk, start_stack;
68847+ unsigned long aslr_gap, start_brk, brk, start_stack;
68848 unsigned long arg_start, arg_end, env_start, env_end;
68849
68850 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
68851@@ -436,6 +438,24 @@ struct mm_struct {
68852 int first_nid;
68853 #endif
68854 struct uprobes_state uprobes_state;
68855+
68856+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68857+ unsigned long pax_flags;
68858+#endif
68859+
68860+#ifdef CONFIG_PAX_DLRESOLVE
68861+ unsigned long call_dl_resolve;
68862+#endif
68863+
68864+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
68865+ unsigned long call_syscall;
68866+#endif
68867+
68868+#ifdef CONFIG_PAX_ASLR
68869+ unsigned long delta_mmap; /* randomized offset */
68870+ unsigned long delta_stack; /* randomized offset */
68871+#endif
68872+
68873 };
68874
68875 /* first nid will either be a valid NID or one of these values */
68876diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
68877index c5d5278..f0b68c8 100644
68878--- a/include/linux/mmiotrace.h
68879+++ b/include/linux/mmiotrace.h
68880@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
68881 /* Called from ioremap.c */
68882 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
68883 void __iomem *addr);
68884-extern void mmiotrace_iounmap(volatile void __iomem *addr);
68885+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
68886
68887 /* For anyone to insert markers. Remember trailing newline. */
68888 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
68889@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
68890 {
68891 }
68892
68893-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
68894+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
68895 {
68896 }
68897
68898diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
68899index 73b64a3..6562925 100644
68900--- a/include/linux/mmzone.h
68901+++ b/include/linux/mmzone.h
68902@@ -412,7 +412,7 @@ struct zone {
68903 unsigned long flags; /* zone flags, see below */
68904
68905 /* Zone statistics */
68906- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68907+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68908
68909 /*
68910 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
68911diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
68912index fed3def..c933f99 100644
68913--- a/include/linux/mod_devicetable.h
68914+++ b/include/linux/mod_devicetable.h
68915@@ -12,7 +12,7 @@
68916 typedef unsigned long kernel_ulong_t;
68917 #endif
68918
68919-#define PCI_ANY_ID (~0)
68920+#define PCI_ANY_ID ((__u16)~0)
68921
68922 struct pci_device_id {
68923 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
68924@@ -139,7 +139,7 @@ struct usb_device_id {
68925 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
68926 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
68927
68928-#define HID_ANY_ID (~0)
68929+#define HID_ANY_ID (~0U)
68930 #define HID_BUS_ANY 0xffff
68931 #define HID_GROUP_ANY 0x0000
68932
68933@@ -498,7 +498,7 @@ struct dmi_system_id {
68934 const char *ident;
68935 struct dmi_strmatch matches[4];
68936 void *driver_data;
68937-};
68938+} __do_const;
68939 /*
68940 * struct dmi_device_id appears during expansion of
68941 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
68942diff --git a/include/linux/module.h b/include/linux/module.h
68943index 1375ee3..ced8177 100644
68944--- a/include/linux/module.h
68945+++ b/include/linux/module.h
68946@@ -17,9 +17,11 @@
68947 #include <linux/moduleparam.h>
68948 #include <linux/tracepoint.h>
68949 #include <linux/export.h>
68950+#include <linux/fs.h>
68951
68952 #include <linux/percpu.h>
68953 #include <asm/module.h>
68954+#include <asm/pgtable.h>
68955
68956 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
68957 #define MODULE_SIG_STRING "~Module signature appended~\n"
68958@@ -54,12 +56,13 @@ struct module_attribute {
68959 int (*test)(struct module *);
68960 void (*free)(struct module *);
68961 };
68962+typedef struct module_attribute __no_const module_attribute_no_const;
68963
68964 struct module_version_attribute {
68965 struct module_attribute mattr;
68966 const char *module_name;
68967 const char *version;
68968-} __attribute__ ((__aligned__(sizeof(void *))));
68969+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
68970
68971 extern ssize_t __modver_version_show(struct module_attribute *,
68972 struct module_kobject *, char *);
68973@@ -232,7 +235,7 @@ struct module
68974
68975 /* Sysfs stuff. */
68976 struct module_kobject mkobj;
68977- struct module_attribute *modinfo_attrs;
68978+ module_attribute_no_const *modinfo_attrs;
68979 const char *version;
68980 const char *srcversion;
68981 struct kobject *holders_dir;
68982@@ -281,19 +284,16 @@ struct module
68983 int (*init)(void);
68984
68985 /* If this is non-NULL, vfree after init() returns */
68986- void *module_init;
68987+ void *module_init_rx, *module_init_rw;
68988
68989 /* Here is the actual code + data, vfree'd on unload. */
68990- void *module_core;
68991+ void *module_core_rx, *module_core_rw;
68992
68993 /* Here are the sizes of the init and core sections */
68994- unsigned int init_size, core_size;
68995+ unsigned int init_size_rw, core_size_rw;
68996
68997 /* The size of the executable code in each section. */
68998- unsigned int init_text_size, core_text_size;
68999-
69000- /* Size of RO sections of the module (text+rodata) */
69001- unsigned int init_ro_size, core_ro_size;
69002+ unsigned int init_size_rx, core_size_rx;
69003
69004 /* Arch-specific module values */
69005 struct mod_arch_specific arch;
69006@@ -349,6 +349,10 @@ struct module
69007 #ifdef CONFIG_EVENT_TRACING
69008 struct ftrace_event_call **trace_events;
69009 unsigned int num_trace_events;
69010+ struct file_operations trace_id;
69011+ struct file_operations trace_enable;
69012+ struct file_operations trace_format;
69013+ struct file_operations trace_filter;
69014 #endif
69015 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69016 unsigned int num_ftrace_callsites;
69017@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69018 bool is_module_percpu_address(unsigned long addr);
69019 bool is_module_text_address(unsigned long addr);
69020
69021+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69022+{
69023+
69024+#ifdef CONFIG_PAX_KERNEXEC
69025+ if (ktla_ktva(addr) >= (unsigned long)start &&
69026+ ktla_ktva(addr) < (unsigned long)start + size)
69027+ return 1;
69028+#endif
69029+
69030+ return ((void *)addr >= start && (void *)addr < start + size);
69031+}
69032+
69033+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69034+{
69035+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69036+}
69037+
69038+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69039+{
69040+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69041+}
69042+
69043+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69044+{
69045+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69046+}
69047+
69048+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69049+{
69050+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69051+}
69052+
69053 static inline int within_module_core(unsigned long addr, struct module *mod)
69054 {
69055- return (unsigned long)mod->module_core <= addr &&
69056- addr < (unsigned long)mod->module_core + mod->core_size;
69057+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69058 }
69059
69060 static inline int within_module_init(unsigned long addr, struct module *mod)
69061 {
69062- return (unsigned long)mod->module_init <= addr &&
69063- addr < (unsigned long)mod->module_init + mod->init_size;
69064+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69065 }
69066
69067 /* Search for module by name: must hold module_mutex. */
69068diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69069index 560ca53..5ee8d73 100644
69070--- a/include/linux/moduleloader.h
69071+++ b/include/linux/moduleloader.h
69072@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69073
69074 /* Allocator used for allocating struct module, core sections and init
69075 sections. Returns NULL on failure. */
69076-void *module_alloc(unsigned long size);
69077+void *module_alloc(unsigned long size) __size_overflow(1);
69078+
69079+#ifdef CONFIG_PAX_KERNEXEC
69080+void *module_alloc_exec(unsigned long size) __size_overflow(1);
69081+#else
69082+#define module_alloc_exec(x) module_alloc(x)
69083+#endif
69084
69085 /* Free memory returned from module_alloc. */
69086 void module_free(struct module *mod, void *module_region);
69087
69088+#ifdef CONFIG_PAX_KERNEXEC
69089+void module_free_exec(struct module *mod, void *module_region);
69090+#else
69091+#define module_free_exec(x, y) module_free((x), (y))
69092+#endif
69093+
69094 /*
69095 * Apply the given relocation to the (simplified) ELF. Return -error
69096 * or 0.
69097@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69098 unsigned int relsec,
69099 struct module *me)
69100 {
69101+#ifdef CONFIG_MODULES
69102 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69103+#endif
69104 return -ENOEXEC;
69105 }
69106 #endif
69107@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69108 unsigned int relsec,
69109 struct module *me)
69110 {
69111+#ifdef CONFIG_MODULES
69112 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69113+#endif
69114 return -ENOEXEC;
69115 }
69116 #endif
69117diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69118index 137b419..fe663ec 100644
69119--- a/include/linux/moduleparam.h
69120+++ b/include/linux/moduleparam.h
69121@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69122 * @len is usually just sizeof(string).
69123 */
69124 #define module_param_string(name, string, len, perm) \
69125- static const struct kparam_string __param_string_##name \
69126+ static const struct kparam_string __param_string_##name __used \
69127 = { len, string }; \
69128 __module_param_call(MODULE_PARAM_PREFIX, name, \
69129 &param_ops_string, \
69130@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69131 */
69132 #define module_param_array_named(name, array, type, nump, perm) \
69133 param_check_##type(name, &(array)[0]); \
69134- static const struct kparam_array __param_arr_##name \
69135+ static const struct kparam_array __param_arr_##name __used \
69136 = { .max = ARRAY_SIZE(array), .num = nump, \
69137 .ops = &param_ops_##type, \
69138 .elemsize = sizeof(array[0]), .elem = array }; \
69139diff --git a/include/linux/namei.h b/include/linux/namei.h
69140index 5a5ff57..5ae5070 100644
69141--- a/include/linux/namei.h
69142+++ b/include/linux/namei.h
69143@@ -19,7 +19,7 @@ struct nameidata {
69144 unsigned seq;
69145 int last_type;
69146 unsigned depth;
69147- char *saved_names[MAX_NESTED_LINKS + 1];
69148+ const char *saved_names[MAX_NESTED_LINKS + 1];
69149 };
69150
69151 /*
69152@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69153
69154 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69155
69156-static inline void nd_set_link(struct nameidata *nd, char *path)
69157+static inline void nd_set_link(struct nameidata *nd, const char *path)
69158 {
69159 nd->saved_names[nd->depth] = path;
69160 }
69161
69162-static inline char *nd_get_link(struct nameidata *nd)
69163+static inline const char *nd_get_link(const struct nameidata *nd)
69164 {
69165 return nd->saved_names[nd->depth];
69166 }
69167diff --git a/include/linux/net.h b/include/linux/net.h
69168index aa16731..514b875 100644
69169--- a/include/linux/net.h
69170+++ b/include/linux/net.h
69171@@ -183,7 +183,7 @@ struct net_proto_family {
69172 int (*create)(struct net *net, struct socket *sock,
69173 int protocol, int kern);
69174 struct module *owner;
69175-};
69176+} __do_const;
69177
69178 struct iovec;
69179 struct kvec;
69180diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69181index 9ef07d0..130a5d9 100644
69182--- a/include/linux/netdevice.h
69183+++ b/include/linux/netdevice.h
69184@@ -1012,6 +1012,7 @@ struct net_device_ops {
69185 u32 pid, u32 seq,
69186 struct net_device *dev);
69187 };
69188+typedef struct net_device_ops __no_const net_device_ops_no_const;
69189
69190 /*
69191 * The DEVICE structure.
69192@@ -1078,7 +1079,7 @@ struct net_device {
69193 int iflink;
69194
69195 struct net_device_stats stats;
69196- atomic_long_t rx_dropped; /* dropped packets by core network
69197+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69198 * Do not use this in drivers.
69199 */
69200
69201diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69202index ee14284..bc65d63 100644
69203--- a/include/linux/netfilter.h
69204+++ b/include/linux/netfilter.h
69205@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69206 #endif
69207 /* Use the module struct to lock set/get code in place */
69208 struct module *owner;
69209-};
69210+} __do_const;
69211
69212 /* Function to register/unregister hook points. */
69213 int nf_register_hook(struct nf_hook_ops *reg);
69214diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69215index 7958e84..ed74d7a 100644
69216--- a/include/linux/netfilter/ipset/ip_set.h
69217+++ b/include/linux/netfilter/ipset/ip_set.h
69218@@ -98,7 +98,7 @@ struct ip_set_type_variant {
69219 /* Return true if "b" set is the same as "a"
69220 * according to the create set parameters */
69221 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69222-};
69223+} __do_const;
69224
69225 /* The core set type structure */
69226 struct ip_set_type {
69227diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69228index 4966dde..7d8ce06 100644
69229--- a/include/linux/netfilter/nfnetlink.h
69230+++ b/include/linux/netfilter/nfnetlink.h
69231@@ -16,7 +16,7 @@ struct nfnl_callback {
69232 const struct nlattr * const cda[]);
69233 const struct nla_policy *policy; /* netlink attribute policy */
69234 const u_int16_t attr_count; /* number of nlattr's */
69235-};
69236+} __do_const;
69237
69238 struct nfnetlink_subsystem {
69239 const char *name;
69240diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69241new file mode 100644
69242index 0000000..33f4af8
69243--- /dev/null
69244+++ b/include/linux/netfilter/xt_gradm.h
69245@@ -0,0 +1,9 @@
69246+#ifndef _LINUX_NETFILTER_XT_GRADM_H
69247+#define _LINUX_NETFILTER_XT_GRADM_H 1
69248+
69249+struct xt_gradm_mtinfo {
69250+ __u16 flags;
69251+ __u16 invflags;
69252+};
69253+
69254+#endif
69255diff --git a/include/linux/nls.h b/include/linux/nls.h
69256index 5dc635f..35f5e11 100644
69257--- a/include/linux/nls.h
69258+++ b/include/linux/nls.h
69259@@ -31,7 +31,7 @@ struct nls_table {
69260 const unsigned char *charset2upper;
69261 struct module *owner;
69262 struct nls_table *next;
69263-};
69264+} __do_const;
69265
69266 /* this value hold the maximum octet of charset */
69267 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69268diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69269index d65746e..62e72c2 100644
69270--- a/include/linux/notifier.h
69271+++ b/include/linux/notifier.h
69272@@ -51,7 +51,8 @@ struct notifier_block {
69273 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69274 struct notifier_block __rcu *next;
69275 int priority;
69276-};
69277+} __do_const;
69278+typedef struct notifier_block __no_const notifier_block_no_const;
69279
69280 struct atomic_notifier_head {
69281 spinlock_t lock;
69282diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69283index a4c5624..79d6d88 100644
69284--- a/include/linux/oprofile.h
69285+++ b/include/linux/oprofile.h
69286@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69287 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69288 char const * name, ulong * val);
69289
69290-/** Create a file for read-only access to an atomic_t. */
69291+/** Create a file for read-only access to an atomic_unchecked_t. */
69292 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69293- char const * name, atomic_t * val);
69294+ char const * name, atomic_unchecked_t * val);
69295
69296 /** create a directory */
69297 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69298diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69299index 45fc162..01a4068 100644
69300--- a/include/linux/pci_hotplug.h
69301+++ b/include/linux/pci_hotplug.h
69302@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69303 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69304 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69305 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69306-};
69307+} __do_const;
69308+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69309
69310 /**
69311 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69312diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69313index 6bfb2faa..e5bc5e5 100644
69314--- a/include/linux/perf_event.h
69315+++ b/include/linux/perf_event.h
69316@@ -328,8 +328,8 @@ struct perf_event {
69317
69318 enum perf_event_active_state state;
69319 unsigned int attach_state;
69320- local64_t count;
69321- atomic64_t child_count;
69322+ local64_t count; /* PaX: fix it one day */
69323+ atomic64_unchecked_t child_count;
69324
69325 /*
69326 * These are the total time in nanoseconds that the event
69327@@ -380,8 +380,8 @@ struct perf_event {
69328 * These accumulate total time (in nanoseconds) that children
69329 * events have been enabled and running, respectively.
69330 */
69331- atomic64_t child_total_time_enabled;
69332- atomic64_t child_total_time_running;
69333+ atomic64_unchecked_t child_total_time_enabled;
69334+ atomic64_unchecked_t child_total_time_running;
69335
69336 /*
69337 * Protect attach/detach and child_list:
69338@@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
69339 */
69340 #define perf_cpu_notifier(fn) \
69341 do { \
69342- static struct notifier_block fn##_nb __cpuinitdata = \
69343+ static struct notifier_block fn##_nb = \
69344 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69345 unsigned long cpu = smp_processor_id(); \
69346 unsigned long flags; \
69347diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69348index ad1a427..6419649 100644
69349--- a/include/linux/pipe_fs_i.h
69350+++ b/include/linux/pipe_fs_i.h
69351@@ -45,9 +45,9 @@ struct pipe_buffer {
69352 struct pipe_inode_info {
69353 wait_queue_head_t wait;
69354 unsigned int nrbufs, curbuf, buffers;
69355- unsigned int readers;
69356- unsigned int writers;
69357- unsigned int waiting_writers;
69358+ atomic_t readers;
69359+ atomic_t writers;
69360+ atomic_t waiting_writers;
69361 unsigned int r_counter;
69362 unsigned int w_counter;
69363 struct page *tmp_page;
69364diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69365index 5f28cae..3d23723 100644
69366--- a/include/linux/platform_data/usb-ehci-s5p.h
69367+++ b/include/linux/platform_data/usb-ehci-s5p.h
69368@@ -14,7 +14,7 @@
69369 struct s5p_ehci_platdata {
69370 int (*phy_init)(struct platform_device *pdev, int type);
69371 int (*phy_exit)(struct platform_device *pdev, int type);
69372-};
69373+} __no_const;
69374
69375 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69376
69377diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69378index c256c59..8ea94c7 100644
69379--- a/include/linux/platform_data/usb-exynos.h
69380+++ b/include/linux/platform_data/usb-exynos.h
69381@@ -14,7 +14,7 @@
69382 struct exynos4_ohci_platdata {
69383 int (*phy_init)(struct platform_device *pdev, int type);
69384 int (*phy_exit)(struct platform_device *pdev, int type);
69385-};
69386+} __no_const;
69387
69388 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
69389
69390diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
69391index 7c1d252..c5c773e 100644
69392--- a/include/linux/pm_domain.h
69393+++ b/include/linux/pm_domain.h
69394@@ -48,7 +48,7 @@ struct gpd_dev_ops {
69395
69396 struct gpd_cpu_data {
69397 unsigned int saved_exit_latency;
69398- struct cpuidle_state *idle_state;
69399+ cpuidle_state_no_const *idle_state;
69400 };
69401
69402 struct generic_pm_domain {
69403diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
69404index f271860..6b3bec5 100644
69405--- a/include/linux/pm_runtime.h
69406+++ b/include/linux/pm_runtime.h
69407@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
69408
69409 static inline void pm_runtime_mark_last_busy(struct device *dev)
69410 {
69411- ACCESS_ONCE(dev->power.last_busy) = jiffies;
69412+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
69413 }
69414
69415 #else /* !CONFIG_PM_RUNTIME */
69416diff --git a/include/linux/pnp.h b/include/linux/pnp.h
69417index 195aafc..49a7bc2 100644
69418--- a/include/linux/pnp.h
69419+++ b/include/linux/pnp.h
69420@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
69421 struct pnp_fixup {
69422 char id[7];
69423 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
69424-};
69425+} __do_const;
69426
69427 /* config parameters */
69428 #define PNP_CONFIG_NORMAL 0x0001
69429diff --git a/include/linux/poison.h b/include/linux/poison.h
69430index 2110a81..13a11bb 100644
69431--- a/include/linux/poison.h
69432+++ b/include/linux/poison.h
69433@@ -19,8 +19,8 @@
69434 * under normal circumstances, used to verify that nobody uses
69435 * non-initialized list entries.
69436 */
69437-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
69438-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
69439+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
69440+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
69441
69442 /********** include/linux/timer.h **********/
69443 /*
69444diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
69445index c0f44c2..1572583 100644
69446--- a/include/linux/power/smartreflex.h
69447+++ b/include/linux/power/smartreflex.h
69448@@ -238,7 +238,7 @@ struct omap_sr_class_data {
69449 int (*notify)(struct omap_sr *sr, u32 status);
69450 u8 notify_flags;
69451 u8 class_type;
69452-};
69453+} __do_const;
69454
69455 /**
69456 * struct omap_sr_nvalue_table - Smartreflex n-target value info
69457diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
69458index 4ea1d37..80f4b33 100644
69459--- a/include/linux/ppp-comp.h
69460+++ b/include/linux/ppp-comp.h
69461@@ -84,7 +84,7 @@ struct compressor {
69462 struct module *owner;
69463 /* Extra skb space needed by the compressor algorithm */
69464 unsigned int comp_extra;
69465-};
69466+} __do_const;
69467
69468 /*
69469 * The return value from decompress routine is the length of the
69470diff --git a/include/linux/printk.h b/include/linux/printk.h
69471index 9afc01e..92c32e8 100644
69472--- a/include/linux/printk.h
69473+++ b/include/linux/printk.h
69474@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
69475 extern int printk_needs_cpu(int cpu);
69476 extern void printk_tick(void);
69477
69478+extern int kptr_restrict;
69479+
69480 #ifdef CONFIG_PRINTK
69481 asmlinkage __printf(5, 0)
69482 int vprintk_emit(int facility, int level,
69483@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
69484
69485 extern int printk_delay_msec;
69486 extern int dmesg_restrict;
69487-extern int kptr_restrict;
69488
69489 void log_buf_kexec_setup(void);
69490 void __init setup_log_buf(int early);
69491diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
69492index 32676b3..8f7a182 100644
69493--- a/include/linux/proc_fs.h
69494+++ b/include/linux/proc_fs.h
69495@@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
69496 return proc_create_data(name, mode, parent, proc_fops, NULL);
69497 }
69498
69499+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
69500+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
69501+{
69502+#ifdef CONFIG_GRKERNSEC_PROC_USER
69503+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
69504+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69505+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
69506+#else
69507+ return proc_create_data(name, mode, parent, proc_fops, NULL);
69508+#endif
69509+}
69510+
69511 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
69512 umode_t mode, struct proc_dir_entry *base,
69513 read_proc_t *read_proc, void * data)
69514diff --git a/include/linux/random.h b/include/linux/random.h
69515index d984608..d6f0042 100644
69516--- a/include/linux/random.h
69517+++ b/include/linux/random.h
69518@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
69519 u32 prandom_u32_state(struct rnd_state *);
69520 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
69521
69522+static inline unsigned long pax_get_random_long(void)
69523+{
69524+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
69525+}
69526+
69527 /*
69528 * Handle minimum values for seeds
69529 */
69530diff --git a/include/linux/rculist.h b/include/linux/rculist.h
69531index c92dd28..08f4eab 100644
69532--- a/include/linux/rculist.h
69533+++ b/include/linux/rculist.h
69534@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
69535 struct list_head *prev, struct list_head *next);
69536 #endif
69537
69538+extern void __pax_list_add_rcu(struct list_head *new,
69539+ struct list_head *prev, struct list_head *next);
69540+
69541 /**
69542 * list_add_rcu - add a new entry to rcu-protected list
69543 * @new: new entry to be added
69544@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
69545 __list_add_rcu(new, head, head->next);
69546 }
69547
69548+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
69549+{
69550+ __pax_list_add_rcu(new, head, head->next);
69551+}
69552+
69553 /**
69554 * list_add_tail_rcu - add a new entry to rcu-protected list
69555 * @new: new entry to be added
69556@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
69557 __list_add_rcu(new, head->prev, head);
69558 }
69559
69560+static inline void pax_list_add_tail_rcu(struct list_head *new,
69561+ struct list_head *head)
69562+{
69563+ __pax_list_add_rcu(new, head->prev, head);
69564+}
69565+
69566 /**
69567 * list_del_rcu - deletes entry from list without re-initialization
69568 * @entry: the element to delete from the list.
69569@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
69570 entry->prev = LIST_POISON2;
69571 }
69572
69573+extern void pax_list_del_rcu(struct list_head *entry);
69574+
69575 /**
69576 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
69577 * @n: the element to delete from the hash list.
69578diff --git a/include/linux/reboot.h b/include/linux/reboot.h
69579index 23b3630..e1bc12b 100644
69580--- a/include/linux/reboot.h
69581+++ b/include/linux/reboot.h
69582@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
69583 * Architecture-specific implementations of sys_reboot commands.
69584 */
69585
69586-extern void machine_restart(char *cmd);
69587-extern void machine_halt(void);
69588-extern void machine_power_off(void);
69589+extern void machine_restart(char *cmd) __noreturn;
69590+extern void machine_halt(void) __noreturn;
69591+extern void machine_power_off(void) __noreturn;
69592
69593 extern void machine_shutdown(void);
69594 struct pt_regs;
69595@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
69596 */
69597
69598 extern void kernel_restart_prepare(char *cmd);
69599-extern void kernel_restart(char *cmd);
69600-extern void kernel_halt(void);
69601-extern void kernel_power_off(void);
69602+extern void kernel_restart(char *cmd) __noreturn;
69603+extern void kernel_halt(void) __noreturn;
69604+extern void kernel_power_off(void) __noreturn;
69605
69606 extern int C_A_D; /* for sysctl */
69607 void ctrl_alt_del(void);
69608@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
69609 * Emergency restart, callable from an interrupt handler.
69610 */
69611
69612-extern void emergency_restart(void);
69613+extern void emergency_restart(void) __noreturn;
69614 #include <asm/emergency-restart.h>
69615
69616 #endif /* _LINUX_REBOOT_H */
69617diff --git a/include/linux/regset.h b/include/linux/regset.h
69618index 8e0c9fe..ac4d221 100644
69619--- a/include/linux/regset.h
69620+++ b/include/linux/regset.h
69621@@ -161,7 +161,8 @@ struct user_regset {
69622 unsigned int align;
69623 unsigned int bias;
69624 unsigned int core_note_type;
69625-};
69626+} __do_const;
69627+typedef struct user_regset __no_const user_regset_no_const;
69628
69629 /**
69630 * struct user_regset_view - available regsets
69631diff --git a/include/linux/relay.h b/include/linux/relay.h
69632index 91cacc3..b55ff74 100644
69633--- a/include/linux/relay.h
69634+++ b/include/linux/relay.h
69635@@ -160,7 +160,7 @@ struct rchan_callbacks
69636 * The callback should return 0 if successful, negative if not.
69637 */
69638 int (*remove_buf_file)(struct dentry *dentry);
69639-};
69640+} __no_const;
69641
69642 /*
69643 * CONFIG_RELAY kernel API, kernel/relay.c
69644diff --git a/include/linux/rio.h b/include/linux/rio.h
69645index a3e7842..d973ca6 100644
69646--- a/include/linux/rio.h
69647+++ b/include/linux/rio.h
69648@@ -339,7 +339,7 @@ struct rio_ops {
69649 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
69650 u64 rstart, u32 size, u32 flags);
69651 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
69652-};
69653+} __no_const;
69654
69655 #define RIO_RESOURCE_MEM 0x00000100
69656 #define RIO_RESOURCE_DOORBELL 0x00000200
69657diff --git a/include/linux/rmap.h b/include/linux/rmap.h
69658index c20635c..2f5def4 100644
69659--- a/include/linux/rmap.h
69660+++ b/include/linux/rmap.h
69661@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
69662 void anon_vma_init(void); /* create anon_vma_cachep */
69663 int anon_vma_prepare(struct vm_area_struct *);
69664 void unlink_anon_vmas(struct vm_area_struct *);
69665-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
69666-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
69667+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
69668+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
69669
69670 static inline void anon_vma_merge(struct vm_area_struct *vma,
69671 struct vm_area_struct *next)
69672diff --git a/include/linux/sched.h b/include/linux/sched.h
69673index d211247..a5cbf38b 100644
69674--- a/include/linux/sched.h
69675+++ b/include/linux/sched.h
69676@@ -61,6 +61,7 @@ struct bio_list;
69677 struct fs_struct;
69678 struct perf_event_context;
69679 struct blk_plug;
69680+struct linux_binprm;
69681
69682 /*
69683 * List of flags we want to share for kernel threads,
69684@@ -354,10 +355,23 @@ struct user_namespace;
69685 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
69686
69687 extern int sysctl_max_map_count;
69688+extern unsigned long sysctl_heap_stack_gap;
69689
69690 #include <linux/aio.h>
69691
69692 #ifdef CONFIG_MMU
69693+
69694+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
69695+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
69696+#else
69697+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
69698+{
69699+ return 0;
69700+}
69701+#endif
69702+
69703+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
69704+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
69705 extern void arch_pick_mmap_layout(struct mm_struct *mm);
69706 extern unsigned long
69707 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
69708@@ -639,6 +653,17 @@ struct signal_struct {
69709 #ifdef CONFIG_TASKSTATS
69710 struct taskstats *stats;
69711 #endif
69712+
69713+#ifdef CONFIG_GRKERNSEC
69714+ u32 curr_ip;
69715+ u32 saved_ip;
69716+ u32 gr_saddr;
69717+ u32 gr_daddr;
69718+ u16 gr_sport;
69719+ u16 gr_dport;
69720+ u8 used_accept:1;
69721+#endif
69722+
69723 #ifdef CONFIG_AUDIT
69724 unsigned audit_tty;
69725 struct tty_audit_buf *tty_audit_buf;
69726@@ -717,6 +742,11 @@ struct user_struct {
69727 struct key *session_keyring; /* UID's default session keyring */
69728 #endif
69729
69730+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
69731+ unsigned int banned;
69732+ unsigned long ban_expires;
69733+#endif
69734+
69735 /* Hash table maintenance information */
69736 struct hlist_node uidhash_node;
69737 kuid_t uid;
69738@@ -1116,7 +1146,7 @@ struct sched_class {
69739 #ifdef CONFIG_FAIR_GROUP_SCHED
69740 void (*task_move_group) (struct task_struct *p, int on_rq);
69741 #endif
69742-};
69743+} __do_const;
69744
69745 struct load_weight {
69746 unsigned long weight, inv_weight;
69747@@ -1360,8 +1390,8 @@ struct task_struct {
69748 struct list_head thread_group;
69749
69750 struct completion *vfork_done; /* for vfork() */
69751- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
69752- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69753+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
69754+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69755
69756 cputime_t utime, stime, utimescaled, stimescaled;
69757 cputime_t gtime;
69758@@ -1377,11 +1407,6 @@ struct task_struct {
69759 struct task_cputime cputime_expires;
69760 struct list_head cpu_timers[3];
69761
69762-/* process credentials */
69763- const struct cred __rcu *real_cred; /* objective and real subjective task
69764- * credentials (COW) */
69765- const struct cred __rcu *cred; /* effective (overridable) subjective task
69766- * credentials (COW) */
69767 char comm[TASK_COMM_LEN]; /* executable name excluding path
69768 - access with [gs]et_task_comm (which lock
69769 it with task_lock())
69770@@ -1398,6 +1423,10 @@ struct task_struct {
69771 #endif
69772 /* CPU-specific state of this task */
69773 struct thread_struct thread;
69774+/* thread_info moved to task_struct */
69775+#ifdef CONFIG_X86
69776+ struct thread_info tinfo;
69777+#endif
69778 /* filesystem information */
69779 struct fs_struct *fs;
69780 /* open file information */
69781@@ -1471,6 +1500,10 @@ struct task_struct {
69782 gfp_t lockdep_reclaim_gfp;
69783 #endif
69784
69785+/* process credentials */
69786+ const struct cred __rcu *real_cred; /* objective and real subjective task
69787+ * credentials (COW) */
69788+
69789 /* journalling filesystem info */
69790 void *journal_info;
69791
69792@@ -1509,6 +1542,10 @@ struct task_struct {
69793 /* cg_list protected by css_set_lock and tsk->alloc_lock */
69794 struct list_head cg_list;
69795 #endif
69796+
69797+ const struct cred __rcu *cred; /* effective (overridable) subjective task
69798+ * credentials (COW) */
69799+
69800 #ifdef CONFIG_FUTEX
69801 struct robust_list_head __user *robust_list;
69802 #ifdef CONFIG_COMPAT
69803@@ -1605,8 +1642,74 @@ struct task_struct {
69804 #ifdef CONFIG_UPROBES
69805 struct uprobe_task *utask;
69806 #endif
69807+
69808+#ifdef CONFIG_GRKERNSEC
69809+ /* grsecurity */
69810+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69811+ u64 exec_id;
69812+#endif
69813+#ifdef CONFIG_GRKERNSEC_SETXID
69814+ const struct cred *delayed_cred;
69815+#endif
69816+ struct dentry *gr_chroot_dentry;
69817+ struct acl_subject_label *acl;
69818+ struct acl_role_label *role;
69819+ struct file *exec_file;
69820+ unsigned long brute_expires;
69821+ u16 acl_role_id;
69822+ /* is this the task that authenticated to the special role */
69823+ u8 acl_sp_role;
69824+ u8 is_writable;
69825+ u8 brute;
69826+ u8 gr_is_chrooted;
69827+#endif
69828+
69829 };
69830
69831+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
69832+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
69833+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
69834+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
69835+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
69836+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
69837+
69838+#ifdef CONFIG_PAX_SOFTMODE
69839+extern int pax_softmode;
69840+#endif
69841+
69842+extern int pax_check_flags(unsigned long *);
69843+
69844+/* if tsk != current then task_lock must be held on it */
69845+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69846+static inline unsigned long pax_get_flags(struct task_struct *tsk)
69847+{
69848+ if (likely(tsk->mm))
69849+ return tsk->mm->pax_flags;
69850+ else
69851+ return 0UL;
69852+}
69853+
69854+/* if tsk != current then task_lock must be held on it */
69855+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
69856+{
69857+ if (likely(tsk->mm)) {
69858+ tsk->mm->pax_flags = flags;
69859+ return 0;
69860+ }
69861+ return -EINVAL;
69862+}
69863+#endif
69864+
69865+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69866+extern void pax_set_initial_flags(struct linux_binprm *bprm);
69867+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
69868+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
69869+#endif
69870+
69871+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
69872+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
69873+extern void pax_report_refcount_overflow(struct pt_regs *regs);
69874+
69875 /* Future-safe accessor for struct task_struct's cpus_allowed. */
69876 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
69877
69878@@ -1696,7 +1799,7 @@ struct pid_namespace;
69879 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
69880 struct pid_namespace *ns);
69881
69882-static inline pid_t task_pid_nr(struct task_struct *tsk)
69883+static inline pid_t task_pid_nr(const struct task_struct *tsk)
69884 {
69885 return tsk->pid;
69886 }
69887@@ -2155,7 +2258,9 @@ void yield(void);
69888 extern struct exec_domain default_exec_domain;
69889
69890 union thread_union {
69891+#ifndef CONFIG_X86
69892 struct thread_info thread_info;
69893+#endif
69894 unsigned long stack[THREAD_SIZE/sizeof(long)];
69895 };
69896
69897@@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
69898 */
69899
69900 extern struct task_struct *find_task_by_vpid(pid_t nr);
69901+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
69902 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
69903 struct pid_namespace *ns);
69904
69905@@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
69906 extern void exit_itimers(struct signal_struct *);
69907 extern void flush_itimer_signals(void);
69908
69909-extern void do_group_exit(int);
69910+extern __noreturn void do_group_exit(int);
69911
69912 extern int allow_signal(int);
69913 extern int disallow_signal(int);
69914@@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
69915
69916 #endif
69917
69918-static inline int object_is_on_stack(void *obj)
69919+static inline int object_starts_on_stack(void *obj)
69920 {
69921- void *stack = task_stack_page(current);
69922+ const void *stack = task_stack_page(current);
69923
69924 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
69925 }
69926diff --git a/include/linux/security.h b/include/linux/security.h
69927index eee7478..290f7ba 100644
69928--- a/include/linux/security.h
69929+++ b/include/linux/security.h
69930@@ -26,6 +26,7 @@
69931 #include <linux/capability.h>
69932 #include <linux/slab.h>
69933 #include <linux/err.h>
69934+#include <linux/grsecurity.h>
69935
69936 struct linux_binprm;
69937 struct cred;
69938diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
69939index 68a04a3..866e6a1 100644
69940--- a/include/linux/seq_file.h
69941+++ b/include/linux/seq_file.h
69942@@ -26,6 +26,9 @@ struct seq_file {
69943 struct mutex lock;
69944 const struct seq_operations *op;
69945 int poll_event;
69946+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69947+ u64 exec_id;
69948+#endif
69949 #ifdef CONFIG_USER_NS
69950 struct user_namespace *user_ns;
69951 #endif
69952@@ -38,6 +41,7 @@ struct seq_operations {
69953 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
69954 int (*show) (struct seq_file *m, void *v);
69955 };
69956+typedef struct seq_operations __no_const seq_operations_no_const;
69957
69958 #define SEQ_SKIP 1
69959
69960diff --git a/include/linux/shm.h b/include/linux/shm.h
69961index 429c199..4d42e38 100644
69962--- a/include/linux/shm.h
69963+++ b/include/linux/shm.h
69964@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
69965
69966 /* The task created the shm object. NULL if the task is dead. */
69967 struct task_struct *shm_creator;
69968+#ifdef CONFIG_GRKERNSEC
69969+ time_t shm_createtime;
69970+ pid_t shm_lapid;
69971+#endif
69972 };
69973
69974 /* shm_mode upper byte flags */
69975diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
69976index 320e976..fd52553 100644
69977--- a/include/linux/skbuff.h
69978+++ b/include/linux/skbuff.h
69979@@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
69980 extern struct sk_buff *__alloc_skb(unsigned int size,
69981 gfp_t priority, int flags, int node);
69982 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
69983-static inline struct sk_buff *alloc_skb(unsigned int size,
69984+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
69985 gfp_t priority)
69986 {
69987 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
69988@@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
69989 */
69990 static inline int skb_queue_empty(const struct sk_buff_head *list)
69991 {
69992- return list->next == (struct sk_buff *)list;
69993+ return list->next == (const struct sk_buff *)list;
69994 }
69995
69996 /**
69997@@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
69998 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69999 const struct sk_buff *skb)
70000 {
70001- return skb->next == (struct sk_buff *)list;
70002+ return skb->next == (const struct sk_buff *)list;
70003 }
70004
70005 /**
70006@@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70007 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70008 const struct sk_buff *skb)
70009 {
70010- return skb->prev == (struct sk_buff *)list;
70011+ return skb->prev == (const struct sk_buff *)list;
70012 }
70013
70014 /**
70015@@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70016 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70017 */
70018 #ifndef NET_SKB_PAD
70019-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70020+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70021 #endif
70022
70023 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70024@@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70025 int noblock, int *err);
70026 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70027 struct poll_table_struct *wait);
70028-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70029+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70030 int offset, struct iovec *to,
70031 int size);
70032 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70033diff --git a/include/linux/slab.h b/include/linux/slab.h
70034index 5d168d7..720bff3 100644
70035--- a/include/linux/slab.h
70036+++ b/include/linux/slab.h
70037@@ -12,13 +12,20 @@
70038 #include <linux/gfp.h>
70039 #include <linux/types.h>
70040 #include <linux/workqueue.h>
70041-
70042+#include <linux/err.h>
70043
70044 /*
70045 * Flags to pass to kmem_cache_create().
70046 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70047 */
70048 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70049+
70050+#ifdef CONFIG_PAX_USERCOPY_SLABS
70051+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70052+#else
70053+#define SLAB_USERCOPY 0x00000000UL
70054+#endif
70055+
70056 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70057 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70058 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70059@@ -89,10 +96,13 @@
70060 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70061 * Both make kfree a no-op.
70062 */
70063-#define ZERO_SIZE_PTR ((void *)16)
70064+#define ZERO_SIZE_PTR \
70065+({ \
70066+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70067+ (void *)(-MAX_ERRNO-1L); \
70068+})
70069
70070-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70071- (unsigned long)ZERO_SIZE_PTR)
70072+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70073
70074 /*
70075 * Common fields provided in kmem_cache by all slab allocators
70076@@ -112,7 +122,7 @@ struct kmem_cache {
70077 unsigned int align; /* Alignment as calculated */
70078 unsigned long flags; /* Active flags on the slab */
70079 const char *name; /* Slab name for sysfs */
70080- int refcount; /* Use counter */
70081+ atomic_t refcount; /* Use counter */
70082 void (*ctor)(void *); /* Called on object slot creation */
70083 struct list_head list; /* List of all slab caches on the system */
70084 };
70085@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70086 void kfree(const void *);
70087 void kzfree(const void *);
70088 size_t ksize(const void *);
70089+const char *check_heap_object(const void *ptr, unsigned long n);
70090+bool is_usercopy_object(const void *ptr);
70091
70092 /*
70093 * Allocator specific definitions. These are mainly used to establish optimized
70094@@ -311,6 +323,7 @@ size_t ksize(const void *);
70095 * for general use, and so are not documented here. For a full list of
70096 * potential flags, always refer to linux/gfp.h.
70097 */
70098+
70099 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70100 {
70101 if (size != 0 && n > SIZE_MAX / size)
70102@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70103 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70104 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70105 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70106-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70107+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70108 #define kmalloc_track_caller(size, flags) \
70109 __kmalloc_track_caller(size, flags, _RET_IP_)
70110 #else
70111@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70112 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70113 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70114 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70115-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70116+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70117 #define kmalloc_node_track_caller(size, flags, node) \
70118 __kmalloc_node_track_caller(size, flags, node, \
70119 _RET_IP_)
70120diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70121index 8bb6e0e..8eb0dbe 100644
70122--- a/include/linux/slab_def.h
70123+++ b/include/linux/slab_def.h
70124@@ -52,7 +52,7 @@ struct kmem_cache {
70125 /* 4) cache creation/removal */
70126 const char *name;
70127 struct list_head list;
70128- int refcount;
70129+ atomic_t refcount;
70130 int object_size;
70131 int align;
70132
70133@@ -68,10 +68,10 @@ struct kmem_cache {
70134 unsigned long node_allocs;
70135 unsigned long node_frees;
70136 unsigned long node_overflow;
70137- atomic_t allochit;
70138- atomic_t allocmiss;
70139- atomic_t freehit;
70140- atomic_t freemiss;
70141+ atomic_unchecked_t allochit;
70142+ atomic_unchecked_t allocmiss;
70143+ atomic_unchecked_t freehit;
70144+ atomic_unchecked_t freemiss;
70145
70146 /*
70147 * If debugging is enabled, then the allocator can add additional
70148@@ -111,11 +111,16 @@ struct cache_sizes {
70149 #ifdef CONFIG_ZONE_DMA
70150 struct kmem_cache *cs_dmacachep;
70151 #endif
70152+
70153+#ifdef CONFIG_PAX_USERCOPY_SLABS
70154+ struct kmem_cache *cs_usercopycachep;
70155+#endif
70156+
70157 };
70158 extern struct cache_sizes malloc_sizes[];
70159
70160 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70161-void *__kmalloc(size_t size, gfp_t flags);
70162+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70163
70164 #ifdef CONFIG_TRACING
70165 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70166@@ -152,6 +157,13 @@ found:
70167 cachep = malloc_sizes[i].cs_dmacachep;
70168 else
70169 #endif
70170+
70171+#ifdef CONFIG_PAX_USERCOPY_SLABS
70172+ if (flags & GFP_USERCOPY)
70173+ cachep = malloc_sizes[i].cs_usercopycachep;
70174+ else
70175+#endif
70176+
70177 cachep = malloc_sizes[i].cs_cachep;
70178
70179 ret = kmem_cache_alloc_trace(cachep, flags, size);
70180@@ -162,7 +174,7 @@ found:
70181 }
70182
70183 #ifdef CONFIG_NUMA
70184-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70185+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70186 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70187
70188 #ifdef CONFIG_TRACING
70189@@ -205,6 +217,13 @@ found:
70190 cachep = malloc_sizes[i].cs_dmacachep;
70191 else
70192 #endif
70193+
70194+#ifdef CONFIG_PAX_USERCOPY_SLABS
70195+ if (flags & GFP_USERCOPY)
70196+ cachep = malloc_sizes[i].cs_usercopycachep;
70197+ else
70198+#endif
70199+
70200 cachep = malloc_sizes[i].cs_cachep;
70201
70202 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70203diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70204index f28e14a..7831211 100644
70205--- a/include/linux/slob_def.h
70206+++ b/include/linux/slob_def.h
70207@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70208 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70209 }
70210
70211-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70212+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70213
70214 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70215 {
70216@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70217 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70218 }
70219
70220-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70221+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70222 {
70223 return kmalloc(size, flags);
70224 }
70225diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70226index 9db4825..ed42fb5 100644
70227--- a/include/linux/slub_def.h
70228+++ b/include/linux/slub_def.h
70229@@ -91,7 +91,7 @@ struct kmem_cache {
70230 struct kmem_cache_order_objects max;
70231 struct kmem_cache_order_objects min;
70232 gfp_t allocflags; /* gfp flags to use on each alloc */
70233- int refcount; /* Refcount for slab cache destroy */
70234+ atomic_t refcount; /* Refcount for slab cache destroy */
70235 void (*ctor)(void *);
70236 int inuse; /* Offset to metadata */
70237 int align; /* Alignment */
70238@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70239 * Sorry that the following has to be that ugly but some versions of GCC
70240 * have trouble with constant propagation and loops.
70241 */
70242-static __always_inline int kmalloc_index(size_t size)
70243+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70244 {
70245 if (!size)
70246 return 0;
70247@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70248 }
70249
70250 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70251-void *__kmalloc(size_t size, gfp_t flags);
70252+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70253
70254 static __always_inline void *
70255 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70256@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70257 }
70258 #endif
70259
70260-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70261+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70262 {
70263 unsigned int order = get_order(size);
70264 return kmalloc_order_trace(size, flags, order);
70265@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70266 }
70267
70268 #ifdef CONFIG_NUMA
70269-void *__kmalloc_node(size_t size, gfp_t flags, int node);
70270+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70271 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70272
70273 #ifdef CONFIG_TRACING
70274diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70275index e8d702e..0a56eb4 100644
70276--- a/include/linux/sock_diag.h
70277+++ b/include/linux/sock_diag.h
70278@@ -10,7 +10,7 @@ struct sock;
70279 struct sock_diag_handler {
70280 __u8 family;
70281 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70282-};
70283+} __do_const;
70284
70285 int sock_diag_register(const struct sock_diag_handler *h);
70286 void sock_diag_unregister(const struct sock_diag_handler *h);
70287diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70288index 680f9a3..f13aeb0 100644
70289--- a/include/linux/sonet.h
70290+++ b/include/linux/sonet.h
70291@@ -7,7 +7,7 @@
70292 #include <uapi/linux/sonet.h>
70293
70294 struct k_sonet_stats {
70295-#define __HANDLE_ITEM(i) atomic_t i
70296+#define __HANDLE_ITEM(i) atomic_unchecked_t i
70297 __SONET_ITEMS
70298 #undef __HANDLE_ITEM
70299 };
70300diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70301index 34206b8..3db7f1c 100644
70302--- a/include/linux/sunrpc/clnt.h
70303+++ b/include/linux/sunrpc/clnt.h
70304@@ -96,7 +96,7 @@ struct rpc_procinfo {
70305 unsigned int p_timer; /* Which RTT timer to use */
70306 u32 p_statidx; /* Which procedure to account */
70307 const char * p_name; /* name of procedure */
70308-};
70309+} __do_const;
70310
70311 #ifdef __KERNEL__
70312
70313@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70314 {
70315 switch (sap->sa_family) {
70316 case AF_INET:
70317- return ntohs(((struct sockaddr_in *)sap)->sin_port);
70318+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70319 case AF_INET6:
70320- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70321+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70322 }
70323 return 0;
70324 }
70325@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70326 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70327 const struct sockaddr *src)
70328 {
70329- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70330+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70331 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70332
70333 dsin->sin_family = ssin->sin_family;
70334@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70335 if (sa->sa_family != AF_INET6)
70336 return 0;
70337
70338- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70339+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70340 }
70341
70342 #endif /* __KERNEL__ */
70343diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70344index 676ddf5..4c519a1 100644
70345--- a/include/linux/sunrpc/svc.h
70346+++ b/include/linux/sunrpc/svc.h
70347@@ -410,7 +410,7 @@ struct svc_procedure {
70348 unsigned int pc_count; /* call count */
70349 unsigned int pc_cachetype; /* cache info (NFS) */
70350 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70351-};
70352+} __do_const;
70353
70354 /*
70355 * Function prototypes.
70356diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70357index 0b8e3e6..33e0a01 100644
70358--- a/include/linux/sunrpc/svc_rdma.h
70359+++ b/include/linux/sunrpc/svc_rdma.h
70360@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70361 extern unsigned int svcrdma_max_requests;
70362 extern unsigned int svcrdma_max_req_size;
70363
70364-extern atomic_t rdma_stat_recv;
70365-extern atomic_t rdma_stat_read;
70366-extern atomic_t rdma_stat_write;
70367-extern atomic_t rdma_stat_sq_starve;
70368-extern atomic_t rdma_stat_rq_starve;
70369-extern atomic_t rdma_stat_rq_poll;
70370-extern atomic_t rdma_stat_rq_prod;
70371-extern atomic_t rdma_stat_sq_poll;
70372-extern atomic_t rdma_stat_sq_prod;
70373+extern atomic_unchecked_t rdma_stat_recv;
70374+extern atomic_unchecked_t rdma_stat_read;
70375+extern atomic_unchecked_t rdma_stat_write;
70376+extern atomic_unchecked_t rdma_stat_sq_starve;
70377+extern atomic_unchecked_t rdma_stat_rq_starve;
70378+extern atomic_unchecked_t rdma_stat_rq_poll;
70379+extern atomic_unchecked_t rdma_stat_rq_prod;
70380+extern atomic_unchecked_t rdma_stat_sq_poll;
70381+extern atomic_unchecked_t rdma_stat_sq_prod;
70382
70383 #define RPCRDMA_VERSION 1
70384
70385diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
70386index dd74084a..7f509d5 100644
70387--- a/include/linux/sunrpc/svcauth.h
70388+++ b/include/linux/sunrpc/svcauth.h
70389@@ -109,7 +109,7 @@ struct auth_ops {
70390 int (*release)(struct svc_rqst *rq);
70391 void (*domain_release)(struct auth_domain *);
70392 int (*set_client)(struct svc_rqst *rq);
70393-};
70394+} __do_const;
70395
70396 #define SVC_GARBAGE 1
70397 #define SVC_SYSERR 2
70398diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
70399index 071d62c..4ccc7ac 100644
70400--- a/include/linux/swiotlb.h
70401+++ b/include/linux/swiotlb.h
70402@@ -59,7 +59,8 @@ extern void
70403
70404 extern void
70405 swiotlb_free_coherent(struct device *hwdev, size_t size,
70406- void *vaddr, dma_addr_t dma_handle);
70407+ void *vaddr, dma_addr_t dma_handle,
70408+ struct dma_attrs *attrs);
70409
70410 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
70411 unsigned long offset, size_t size,
70412diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
70413index 27b3b0b..e093dd9 100644
70414--- a/include/linux/syscore_ops.h
70415+++ b/include/linux/syscore_ops.h
70416@@ -16,7 +16,7 @@ struct syscore_ops {
70417 int (*suspend)(void);
70418 void (*resume)(void);
70419 void (*shutdown)(void);
70420-};
70421+} __do_const;
70422
70423 extern void register_syscore_ops(struct syscore_ops *ops);
70424 extern void unregister_syscore_ops(struct syscore_ops *ops);
70425diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
70426index 14a8ff2..af52bad 100644
70427--- a/include/linux/sysctl.h
70428+++ b/include/linux/sysctl.h
70429@@ -34,13 +34,13 @@ struct ctl_table_root;
70430 struct ctl_table_header;
70431 struct ctl_dir;
70432
70433-typedef struct ctl_table ctl_table;
70434-
70435 typedef int proc_handler (struct ctl_table *ctl, int write,
70436 void __user *buffer, size_t *lenp, loff_t *ppos);
70437
70438 extern int proc_dostring(struct ctl_table *, int,
70439 void __user *, size_t *, loff_t *);
70440+extern int proc_dostring_modpriv(struct ctl_table *, int,
70441+ void __user *, size_t *, loff_t *);
70442 extern int proc_dointvec(struct ctl_table *, int,
70443 void __user *, size_t *, loff_t *);
70444 extern int proc_dointvec_minmax(struct ctl_table *, int,
70445@@ -115,7 +115,9 @@ struct ctl_table
70446 struct ctl_table_poll *poll;
70447 void *extra1;
70448 void *extra2;
70449-};
70450+} __do_const;
70451+typedef struct ctl_table __no_const ctl_table_no_const;
70452+typedef struct ctl_table ctl_table;
70453
70454 struct ctl_node {
70455 struct rb_node node;
70456diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
70457index 381f06d..dc16cc7 100644
70458--- a/include/linux/sysfs.h
70459+++ b/include/linux/sysfs.h
70460@@ -31,7 +31,8 @@ struct attribute {
70461 struct lock_class_key *key;
70462 struct lock_class_key skey;
70463 #endif
70464-};
70465+} __do_const;
70466+typedef struct attribute __no_const attribute_no_const;
70467
70468 /**
70469 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
70470@@ -59,8 +60,8 @@ struct attribute_group {
70471 umode_t (*is_visible)(struct kobject *,
70472 struct attribute *, int);
70473 struct attribute **attrs;
70474-};
70475-
70476+} __do_const;
70477+typedef struct attribute_group __no_const attribute_group_no_const;
70478
70479
70480 /**
70481@@ -107,7 +108,8 @@ struct bin_attribute {
70482 char *, loff_t, size_t);
70483 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
70484 struct vm_area_struct *vma);
70485-};
70486+} __do_const;
70487+typedef struct bin_attribute __no_const bin_attribute_no_const;
70488
70489 /**
70490 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
70491diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
70492index 7faf933..4657127 100644
70493--- a/include/linux/sysrq.h
70494+++ b/include/linux/sysrq.h
70495@@ -15,7 +15,9 @@
70496 #define _LINUX_SYSRQ_H
70497
70498 #include <linux/errno.h>
70499+#include <linux/compiler.h>
70500 #include <linux/types.h>
70501+#include <linux/compiler.h>
70502
70503 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
70504 #define SYSRQ_DEFAULT_ENABLE 1
70505@@ -36,7 +38,7 @@ struct sysrq_key_op {
70506 char *help_msg;
70507 char *action_msg;
70508 int enable_mask;
70509-};
70510+} __do_const;
70511
70512 #ifdef CONFIG_MAGIC_SYSRQ
70513
70514diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
70515index e7e0473..39b7b52 100644
70516--- a/include/linux/thread_info.h
70517+++ b/include/linux/thread_info.h
70518@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
70519 #error "no set_restore_sigmask() provided and default one won't work"
70520 #endif
70521
70522+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
70523+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
70524+{
70525+#ifndef CONFIG_PAX_USERCOPY_DEBUG
70526+ if (!__builtin_constant_p(n))
70527+#endif
70528+ __check_object_size(ptr, n, to);
70529+}
70530+
70531 #endif /* __KERNEL__ */
70532
70533 #endif /* _LINUX_THREAD_INFO_H */
70534diff --git a/include/linux/tty.h b/include/linux/tty.h
70535index 8db1b56..c16a040 100644
70536--- a/include/linux/tty.h
70537+++ b/include/linux/tty.h
70538@@ -194,7 +194,7 @@ struct tty_port {
70539 const struct tty_port_operations *ops; /* Port operations */
70540 spinlock_t lock; /* Lock protecting tty field */
70541 int blocked_open; /* Waiting to open */
70542- int count; /* Usage count */
70543+ atomic_t count; /* Usage count */
70544 wait_queue_head_t open_wait; /* Open waiters */
70545 wait_queue_head_t close_wait; /* Close waiters */
70546 wait_queue_head_t delta_msr_wait; /* Modem status change */
70547@@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
70548 struct tty_struct *tty, struct file *filp);
70549 static inline int tty_port_users(struct tty_port *port)
70550 {
70551- return port->count + port->blocked_open;
70552+ return atomic_read(&port->count) + port->blocked_open;
70553 }
70554
70555 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
70556diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
70557index dd976cf..e272742 100644
70558--- a/include/linux/tty_driver.h
70559+++ b/include/linux/tty_driver.h
70560@@ -284,7 +284,7 @@ struct tty_operations {
70561 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
70562 #endif
70563 const struct file_operations *proc_fops;
70564-};
70565+} __do_const;
70566
70567 struct tty_driver {
70568 int magic; /* magic number for this structure */
70569diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
70570index fb79dd8d..07d4773 100644
70571--- a/include/linux/tty_ldisc.h
70572+++ b/include/linux/tty_ldisc.h
70573@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
70574
70575 struct module *owner;
70576
70577- int refcount;
70578+ atomic_t refcount;
70579 };
70580
70581 struct tty_ldisc {
70582diff --git a/include/linux/types.h b/include/linux/types.h
70583index 4d118ba..c3ee9bf 100644
70584--- a/include/linux/types.h
70585+++ b/include/linux/types.h
70586@@ -176,10 +176,26 @@ typedef struct {
70587 int counter;
70588 } atomic_t;
70589
70590+#ifdef CONFIG_PAX_REFCOUNT
70591+typedef struct {
70592+ int counter;
70593+} atomic_unchecked_t;
70594+#else
70595+typedef atomic_t atomic_unchecked_t;
70596+#endif
70597+
70598 #ifdef CONFIG_64BIT
70599 typedef struct {
70600 long counter;
70601 } atomic64_t;
70602+
70603+#ifdef CONFIG_PAX_REFCOUNT
70604+typedef struct {
70605+ long counter;
70606+} atomic64_unchecked_t;
70607+#else
70608+typedef atomic64_t atomic64_unchecked_t;
70609+#endif
70610 #endif
70611
70612 struct list_head {
70613diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
70614index 5ca0951..ab496a5 100644
70615--- a/include/linux/uaccess.h
70616+++ b/include/linux/uaccess.h
70617@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
70618 long ret; \
70619 mm_segment_t old_fs = get_fs(); \
70620 \
70621- set_fs(KERNEL_DS); \
70622 pagefault_disable(); \
70623- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
70624- pagefault_enable(); \
70625+ set_fs(KERNEL_DS); \
70626+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
70627 set_fs(old_fs); \
70628+ pagefault_enable(); \
70629 ret; \
70630 })
70631
70632diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
70633index 8e522cbc..aa8572d 100644
70634--- a/include/linux/uidgid.h
70635+++ b/include/linux/uidgid.h
70636@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
70637
70638 #endif /* CONFIG_USER_NS */
70639
70640+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
70641+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
70642+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
70643+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
70644+
70645 #endif /* _LINUX_UIDGID_H */
70646diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
70647index 99c1b4d..bb94261 100644
70648--- a/include/linux/unaligned/access_ok.h
70649+++ b/include/linux/unaligned/access_ok.h
70650@@ -6,32 +6,32 @@
70651
70652 static inline u16 get_unaligned_le16(const void *p)
70653 {
70654- return le16_to_cpup((__le16 *)p);
70655+ return le16_to_cpup((const __le16 *)p);
70656 }
70657
70658 static inline u32 get_unaligned_le32(const void *p)
70659 {
70660- return le32_to_cpup((__le32 *)p);
70661+ return le32_to_cpup((const __le32 *)p);
70662 }
70663
70664 static inline u64 get_unaligned_le64(const void *p)
70665 {
70666- return le64_to_cpup((__le64 *)p);
70667+ return le64_to_cpup((const __le64 *)p);
70668 }
70669
70670 static inline u16 get_unaligned_be16(const void *p)
70671 {
70672- return be16_to_cpup((__be16 *)p);
70673+ return be16_to_cpup((const __be16 *)p);
70674 }
70675
70676 static inline u32 get_unaligned_be32(const void *p)
70677 {
70678- return be32_to_cpup((__be32 *)p);
70679+ return be32_to_cpup((const __be32 *)p);
70680 }
70681
70682 static inline u64 get_unaligned_be64(const void *p)
70683 {
70684- return be64_to_cpup((__be64 *)p);
70685+ return be64_to_cpup((const __be64 *)p);
70686 }
70687
70688 static inline void put_unaligned_le16(u16 val, void *p)
70689diff --git a/include/linux/usb.h b/include/linux/usb.h
70690index 4d22d0f..ac43c2f 100644
70691--- a/include/linux/usb.h
70692+++ b/include/linux/usb.h
70693@@ -554,7 +554,7 @@ struct usb_device {
70694 int maxchild;
70695
70696 u32 quirks;
70697- atomic_t urbnum;
70698+ atomic_unchecked_t urbnum;
70699
70700 unsigned long active_duration;
70701
70702diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
70703index c5d36c6..108f4f9 100644
70704--- a/include/linux/usb/renesas_usbhs.h
70705+++ b/include/linux/usb/renesas_usbhs.h
70706@@ -39,7 +39,7 @@ enum {
70707 */
70708 struct renesas_usbhs_driver_callback {
70709 int (*notify_hotplug)(struct platform_device *pdev);
70710-};
70711+} __no_const;
70712
70713 /*
70714 * callback functions for platform
70715diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
70716index b9bd2e6..4ce0093 100644
70717--- a/include/linux/user_namespace.h
70718+++ b/include/linux/user_namespace.h
70719@@ -21,7 +21,7 @@ struct user_namespace {
70720 struct uid_gid_map uid_map;
70721 struct uid_gid_map gid_map;
70722 struct uid_gid_map projid_map;
70723- struct kref kref;
70724+ atomic_t count;
70725 struct user_namespace *parent;
70726 kuid_t owner;
70727 kgid_t group;
70728@@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
70729 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
70730 {
70731 if (ns)
70732- kref_get(&ns->kref);
70733+ atomic_inc(&ns->count);
70734 return ns;
70735 }
70736
70737 extern int create_user_ns(struct cred *new);
70738 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
70739-extern void free_user_ns(struct kref *kref);
70740+extern void free_user_ns(struct user_namespace *ns);
70741
70742 static inline void put_user_ns(struct user_namespace *ns)
70743 {
70744- if (ns)
70745- kref_put(&ns->kref, free_user_ns);
70746+ if (ns && atomic_dec_and_test(&ns->count))
70747+ free_user_ns(ns);
70748 }
70749
70750 struct seq_operations;
70751diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
70752index 6f8fbcf..8259001 100644
70753--- a/include/linux/vermagic.h
70754+++ b/include/linux/vermagic.h
70755@@ -25,9 +25,35 @@
70756 #define MODULE_ARCH_VERMAGIC ""
70757 #endif
70758
70759+#ifdef CONFIG_PAX_REFCOUNT
70760+#define MODULE_PAX_REFCOUNT "REFCOUNT "
70761+#else
70762+#define MODULE_PAX_REFCOUNT ""
70763+#endif
70764+
70765+#ifdef CONSTIFY_PLUGIN
70766+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
70767+#else
70768+#define MODULE_CONSTIFY_PLUGIN ""
70769+#endif
70770+
70771+#ifdef STACKLEAK_PLUGIN
70772+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
70773+#else
70774+#define MODULE_STACKLEAK_PLUGIN ""
70775+#endif
70776+
70777+#ifdef CONFIG_GRKERNSEC
70778+#define MODULE_GRSEC "GRSEC "
70779+#else
70780+#define MODULE_GRSEC ""
70781+#endif
70782+
70783 #define VERMAGIC_STRING \
70784 UTS_RELEASE " " \
70785 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
70786 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
70787- MODULE_ARCH_VERMAGIC
70788+ MODULE_ARCH_VERMAGIC \
70789+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
70790+ MODULE_GRSEC
70791
70792diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
70793index 6071e91..ca6a489 100644
70794--- a/include/linux/vmalloc.h
70795+++ b/include/linux/vmalloc.h
70796@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
70797 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
70798 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
70799 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
70800+
70801+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70802+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
70803+#endif
70804+
70805 /* bits [20..32] reserved for arch specific ioremap internals */
70806
70807 /*
70808@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
70809 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
70810 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
70811 unsigned long start, unsigned long end, gfp_t gfp_mask,
70812- pgprot_t prot, int node, const void *caller);
70813+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
70814 extern void vfree(const void *addr);
70815
70816 extern void *vmap(struct page **pages, unsigned int count,
70817@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
70818 extern void free_vm_area(struct vm_struct *area);
70819
70820 /* for /dev/kmem */
70821-extern long vread(char *buf, char *addr, unsigned long count);
70822-extern long vwrite(char *buf, char *addr, unsigned long count);
70823+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
70824+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
70825
70826 /*
70827 * Internals. Dont't use..
70828diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
70829index a13291f..af51fa3 100644
70830--- a/include/linux/vmstat.h
70831+++ b/include/linux/vmstat.h
70832@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
70833 /*
70834 * Zone based page accounting with per cpu differentials.
70835 */
70836-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70837+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70838
70839 static inline void zone_page_state_add(long x, struct zone *zone,
70840 enum zone_stat_item item)
70841 {
70842- atomic_long_add(x, &zone->vm_stat[item]);
70843- atomic_long_add(x, &vm_stat[item]);
70844+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
70845+ atomic_long_add_unchecked(x, &vm_stat[item]);
70846 }
70847
70848 static inline unsigned long global_page_state(enum zone_stat_item item)
70849 {
70850- long x = atomic_long_read(&vm_stat[item]);
70851+ long x = atomic_long_read_unchecked(&vm_stat[item]);
70852 #ifdef CONFIG_SMP
70853 if (x < 0)
70854 x = 0;
70855@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
70856 static inline unsigned long zone_page_state(struct zone *zone,
70857 enum zone_stat_item item)
70858 {
70859- long x = atomic_long_read(&zone->vm_stat[item]);
70860+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70861 #ifdef CONFIG_SMP
70862 if (x < 0)
70863 x = 0;
70864@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
70865 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
70866 enum zone_stat_item item)
70867 {
70868- long x = atomic_long_read(&zone->vm_stat[item]);
70869+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70870
70871 #ifdef CONFIG_SMP
70872 int cpu;
70873@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
70874
70875 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
70876 {
70877- atomic_long_inc(&zone->vm_stat[item]);
70878- atomic_long_inc(&vm_stat[item]);
70879+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
70880+ atomic_long_inc_unchecked(&vm_stat[item]);
70881 }
70882
70883 static inline void __inc_zone_page_state(struct page *page,
70884@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
70885
70886 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
70887 {
70888- atomic_long_dec(&zone->vm_stat[item]);
70889- atomic_long_dec(&vm_stat[item]);
70890+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
70891+ atomic_long_dec_unchecked(&vm_stat[item]);
70892 }
70893
70894 static inline void __dec_zone_page_state(struct page *page,
70895diff --git a/include/linux/xattr.h b/include/linux/xattr.h
70896index fdbafc6..b7ffd47 100644
70897--- a/include/linux/xattr.h
70898+++ b/include/linux/xattr.h
70899@@ -28,7 +28,7 @@ struct xattr_handler {
70900 size_t size, int handler_flags);
70901 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
70902 size_t size, int flags, int handler_flags);
70903-};
70904+} __do_const;
70905
70906 struct xattr {
70907 char *name;
70908diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
70909index 95d1c91..6798cca 100644
70910--- a/include/media/v4l2-dev.h
70911+++ b/include/media/v4l2-dev.h
70912@@ -76,7 +76,7 @@ struct v4l2_file_operations {
70913 int (*mmap) (struct file *, struct vm_area_struct *);
70914 int (*open) (struct file *);
70915 int (*release) (struct file *);
70916-};
70917+} __do_const;
70918
70919 /*
70920 * Newer version of video_device, handled by videodev2.c
70921diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
70922index 4118ad1..cb7e25f 100644
70923--- a/include/media/v4l2-ioctl.h
70924+++ b/include/media/v4l2-ioctl.h
70925@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
70926 bool valid_prio, int cmd, void *arg);
70927 };
70928
70929-
70930 /* v4l debugging and diagnostics */
70931
70932 /* Debug bitmask flags to be used on V4L2 */
70933diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
70934index adcbb20..62c2559 100644
70935--- a/include/net/9p/transport.h
70936+++ b/include/net/9p/transport.h
70937@@ -57,7 +57,7 @@ struct p9_trans_module {
70938 int (*cancel) (struct p9_client *, struct p9_req_t *req);
70939 int (*zc_request)(struct p9_client *, struct p9_req_t *,
70940 char *, char *, int , int, int, int);
70941-};
70942+} __do_const;
70943
70944 void v9fs_register_trans(struct p9_trans_module *m);
70945 void v9fs_unregister_trans(struct p9_trans_module *m);
70946diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
70947index 7588ef4..e62d35f 100644
70948--- a/include/net/bluetooth/l2cap.h
70949+++ b/include/net/bluetooth/l2cap.h
70950@@ -552,7 +552,7 @@ struct l2cap_ops {
70951 void (*defer) (struct l2cap_chan *chan);
70952 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
70953 unsigned long len, int nb);
70954-};
70955+} __do_const;
70956
70957 struct l2cap_conn {
70958 struct hci_conn *hcon;
70959diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
70960index 9e5425b..8136ffc 100644
70961--- a/include/net/caif/cfctrl.h
70962+++ b/include/net/caif/cfctrl.h
70963@@ -52,7 +52,7 @@ struct cfctrl_rsp {
70964 void (*radioset_rsp)(void);
70965 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
70966 struct cflayer *client_layer);
70967-};
70968+} __no_const;
70969
70970 /* Link Setup Parameters for CAIF-Links. */
70971 struct cfctrl_link_param {
70972@@ -101,8 +101,8 @@ struct cfctrl_request_info {
70973 struct cfctrl {
70974 struct cfsrvl serv;
70975 struct cfctrl_rsp res;
70976- atomic_t req_seq_no;
70977- atomic_t rsp_seq_no;
70978+ atomic_unchecked_t req_seq_no;
70979+ atomic_unchecked_t rsp_seq_no;
70980 struct list_head list;
70981 /* Protects from simultaneous access to first_req list */
70982 spinlock_t info_list_lock;
70983diff --git a/include/net/flow.h b/include/net/flow.h
70984index 628e11b..4c475df 100644
70985--- a/include/net/flow.h
70986+++ b/include/net/flow.h
70987@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
70988
70989 extern void flow_cache_flush(void);
70990 extern void flow_cache_flush_deferred(void);
70991-extern atomic_t flow_cache_genid;
70992+extern atomic_unchecked_t flow_cache_genid;
70993
70994 #endif
70995diff --git a/include/net/genetlink.h b/include/net/genetlink.h
70996index bdfbe68..4402ebe 100644
70997--- a/include/net/genetlink.h
70998+++ b/include/net/genetlink.h
70999@@ -118,7 +118,7 @@ struct genl_ops {
71000 struct netlink_callback *cb);
71001 int (*done)(struct netlink_callback *cb);
71002 struct list_head ops_list;
71003-};
71004+} __do_const;
71005
71006 extern int genl_register_family(struct genl_family *family);
71007 extern int genl_register_family_with_ops(struct genl_family *family,
71008diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71009index e5062c9..48a9a4b 100644
71010--- a/include/net/gro_cells.h
71011+++ b/include/net/gro_cells.h
71012@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71013 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71014
71015 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71016- atomic_long_inc(&dev->rx_dropped);
71017+ atomic_long_inc_unchecked(&dev->rx_dropped);
71018 kfree_skb(skb);
71019 return;
71020 }
71021@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71022 int i;
71023
71024 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71025- gcells->cells = kcalloc(sizeof(struct gro_cell),
71026- gcells->gro_cells_mask + 1,
71027+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71028+ sizeof(struct gro_cell),
71029 GFP_KERNEL);
71030 if (!gcells->cells)
71031 return -ENOMEM;
71032diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71033index 1832927..ce39aea 100644
71034--- a/include/net/inet_connection_sock.h
71035+++ b/include/net/inet_connection_sock.h
71036@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71037 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71038 int (*bind_conflict)(const struct sock *sk,
71039 const struct inet_bind_bucket *tb, bool relax);
71040-};
71041+} __do_const;
71042
71043 /** inet_connection_sock - INET connection oriented sock
71044 *
71045diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71046index 53f464d..ba76aaa 100644
71047--- a/include/net/inetpeer.h
71048+++ b/include/net/inetpeer.h
71049@@ -47,8 +47,8 @@ struct inet_peer {
71050 */
71051 union {
71052 struct {
71053- atomic_t rid; /* Frag reception counter */
71054- atomic_t ip_id_count; /* IP ID for the next packet */
71055+ atomic_unchecked_t rid; /* Frag reception counter */
71056+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71057 };
71058 struct rcu_head rcu;
71059 struct inet_peer *gc_next;
71060@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71061 more++;
71062 inet_peer_refcheck(p);
71063 do {
71064- old = atomic_read(&p->ip_id_count);
71065+ old = atomic_read_unchecked(&p->ip_id_count);
71066 new = old + more;
71067 if (!new)
71068 new = 1;
71069- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71070+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71071 return new;
71072 }
71073
71074diff --git a/include/net/ip.h b/include/net/ip.h
71075index a68f838..74518ab 100644
71076--- a/include/net/ip.h
71077+++ b/include/net/ip.h
71078@@ -202,7 +202,7 @@ extern struct local_ports {
71079 } sysctl_local_ports;
71080 extern void inet_get_local_port_range(int *low, int *high);
71081
71082-extern unsigned long *sysctl_local_reserved_ports;
71083+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71084 static inline int inet_is_reserved_local_port(int port)
71085 {
71086 return test_bit(port, sysctl_local_reserved_ports);
71087diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71088index 9497be1..5a4fafe 100644
71089--- a/include/net/ip_fib.h
71090+++ b/include/net/ip_fib.h
71091@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71092
71093 #define FIB_RES_SADDR(net, res) \
71094 ((FIB_RES_NH(res).nh_saddr_genid == \
71095- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71096+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71097 FIB_RES_NH(res).nh_saddr : \
71098 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71099 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71100diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71101index 68c69d5..bdab192 100644
71102--- a/include/net/ip_vs.h
71103+++ b/include/net/ip_vs.h
71104@@ -599,7 +599,7 @@ struct ip_vs_conn {
71105 struct ip_vs_conn *control; /* Master control connection */
71106 atomic_t n_control; /* Number of controlled ones */
71107 struct ip_vs_dest *dest; /* real server */
71108- atomic_t in_pkts; /* incoming packet counter */
71109+ atomic_unchecked_t in_pkts; /* incoming packet counter */
71110
71111 /* packet transmitter for different forwarding methods. If it
71112 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71113@@ -737,7 +737,7 @@ struct ip_vs_dest {
71114 __be16 port; /* port number of the server */
71115 union nf_inet_addr addr; /* IP address of the server */
71116 volatile unsigned int flags; /* dest status flags */
71117- atomic_t conn_flags; /* flags to copy to conn */
71118+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
71119 atomic_t weight; /* server weight */
71120
71121 atomic_t refcnt; /* reference counter */
71122@@ -980,11 +980,11 @@ struct netns_ipvs {
71123 /* ip_vs_lblc */
71124 int sysctl_lblc_expiration;
71125 struct ctl_table_header *lblc_ctl_header;
71126- struct ctl_table *lblc_ctl_table;
71127+ ctl_table_no_const *lblc_ctl_table;
71128 /* ip_vs_lblcr */
71129 int sysctl_lblcr_expiration;
71130 struct ctl_table_header *lblcr_ctl_header;
71131- struct ctl_table *lblcr_ctl_table;
71132+ ctl_table_no_const *lblcr_ctl_table;
71133 /* ip_vs_est */
71134 struct list_head est_list; /* estimator list */
71135 spinlock_t est_lock;
71136diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71137index 80ffde3..968b0f4 100644
71138--- a/include/net/irda/ircomm_tty.h
71139+++ b/include/net/irda/ircomm_tty.h
71140@@ -35,6 +35,7 @@
71141 #include <linux/termios.h>
71142 #include <linux/timer.h>
71143 #include <linux/tty.h> /* struct tty_struct */
71144+#include <asm/local.h>
71145
71146 #include <net/irda/irias_object.h>
71147 #include <net/irda/ircomm_core.h>
71148diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71149index cc7c197..9f2da2a 100644
71150--- a/include/net/iucv/af_iucv.h
71151+++ b/include/net/iucv/af_iucv.h
71152@@ -141,7 +141,7 @@ struct iucv_sock {
71153 struct iucv_sock_list {
71154 struct hlist_head head;
71155 rwlock_t lock;
71156- atomic_t autobind_name;
71157+ atomic_unchecked_t autobind_name;
71158 };
71159
71160 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71161diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71162index df83f69..9b640b8 100644
71163--- a/include/net/llc_c_ac.h
71164+++ b/include/net/llc_c_ac.h
71165@@ -87,7 +87,7 @@
71166 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71167 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71168
71169-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71170+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71171
71172 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71173 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71174diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71175index 6ca3113..f8026dd 100644
71176--- a/include/net/llc_c_ev.h
71177+++ b/include/net/llc_c_ev.h
71178@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71179 return (struct llc_conn_state_ev *)skb->cb;
71180 }
71181
71182-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71183-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71184+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71185+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71186
71187 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71188 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71189diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71190index 0e79cfb..f46db31 100644
71191--- a/include/net/llc_c_st.h
71192+++ b/include/net/llc_c_st.h
71193@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71194 u8 next_state;
71195 llc_conn_ev_qfyr_t *ev_qualifiers;
71196 llc_conn_action_t *ev_actions;
71197-};
71198+} __do_const;
71199
71200 struct llc_conn_state {
71201 u8 current_state;
71202diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71203index 37a3bbd..55a4241 100644
71204--- a/include/net/llc_s_ac.h
71205+++ b/include/net/llc_s_ac.h
71206@@ -23,7 +23,7 @@
71207 #define SAP_ACT_TEST_IND 9
71208
71209 /* All action functions must look like this */
71210-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71211+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71212
71213 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71214 struct sk_buff *skb);
71215diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71216index 567c681..cd73ac0 100644
71217--- a/include/net/llc_s_st.h
71218+++ b/include/net/llc_s_st.h
71219@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71220 llc_sap_ev_t ev;
71221 u8 next_state;
71222 llc_sap_action_t *ev_actions;
71223-};
71224+} __do_const;
71225
71226 struct llc_sap_state {
71227 u8 curr_state;
71228diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71229index ee50c5e..1bc3b1a 100644
71230--- a/include/net/mac80211.h
71231+++ b/include/net/mac80211.h
71232@@ -3996,7 +3996,7 @@ struct rate_control_ops {
71233 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71234 struct dentry *dir);
71235 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71236-};
71237+} __do_const;
71238
71239 static inline int rate_supported(struct ieee80211_sta *sta,
71240 enum ieee80211_band band,
71241diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71242index 0dab173..1b76af0 100644
71243--- a/include/net/neighbour.h
71244+++ b/include/net/neighbour.h
71245@@ -123,7 +123,7 @@ struct neigh_ops {
71246 void (*error_report)(struct neighbour *, struct sk_buff *);
71247 int (*output)(struct neighbour *, struct sk_buff *);
71248 int (*connected_output)(struct neighbour *, struct sk_buff *);
71249-};
71250+} __do_const;
71251
71252 struct pneigh_entry {
71253 struct pneigh_entry *next;
71254diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71255index de644bc..351fd4e 100644
71256--- a/include/net/net_namespace.h
71257+++ b/include/net/net_namespace.h
71258@@ -115,7 +115,7 @@ struct net {
71259 #endif
71260 struct netns_ipvs *ipvs;
71261 struct sock *diag_nlsk;
71262- atomic_t rt_genid;
71263+ atomic_unchecked_t rt_genid;
71264 };
71265
71266 /*
71267@@ -282,7 +282,7 @@ struct pernet_operations {
71268 void (*exit_batch)(struct list_head *net_exit_list);
71269 int *id;
71270 size_t size;
71271-};
71272+} __do_const;
71273
71274 /*
71275 * Use these carefully. If you implement a network device and it
71276@@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71277
71278 static inline int rt_genid(struct net *net)
71279 {
71280- return atomic_read(&net->rt_genid);
71281+ return atomic_read_unchecked(&net->rt_genid);
71282 }
71283
71284 static inline void rt_genid_bump(struct net *net)
71285 {
71286- atomic_inc(&net->rt_genid);
71287+ atomic_inc_unchecked(&net->rt_genid);
71288 }
71289
71290 #endif /* __NET_NET_NAMESPACE_H */
71291diff --git a/include/net/netdma.h b/include/net/netdma.h
71292index 8ba8ce2..99b7fff 100644
71293--- a/include/net/netdma.h
71294+++ b/include/net/netdma.h
71295@@ -24,7 +24,7 @@
71296 #include <linux/dmaengine.h>
71297 #include <linux/skbuff.h>
71298
71299-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71300+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71301 struct sk_buff *skb, int offset, struct iovec *to,
71302 size_t len, struct dma_pinned_list *pinned_list);
71303
71304diff --git a/include/net/netlink.h b/include/net/netlink.h
71305index 9690b0f..87aded7 100644
71306--- a/include/net/netlink.h
71307+++ b/include/net/netlink.h
71308@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71309 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71310 {
71311 if (mark)
71312- skb_trim(skb, (unsigned char *) mark - skb->data);
71313+ skb_trim(skb, (const unsigned char *) mark - skb->data);
71314 }
71315
71316 /**
71317diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71318index 923cb20..deae816 100644
71319--- a/include/net/netns/conntrack.h
71320+++ b/include/net/netns/conntrack.h
71321@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71322 struct nf_proto_net {
71323 #ifdef CONFIG_SYSCTL
71324 struct ctl_table_header *ctl_table_header;
71325- struct ctl_table *ctl_table;
71326+ ctl_table_no_const *ctl_table;
71327 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71328 struct ctl_table_header *ctl_compat_header;
71329- struct ctl_table *ctl_compat_table;
71330+ ctl_table_no_const *ctl_compat_table;
71331 #endif
71332 #endif
71333 unsigned int users;
71334@@ -58,7 +58,7 @@ struct nf_ip_net {
71335 struct nf_icmp_net icmpv6;
71336 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
71337 struct ctl_table_header *ctl_table_header;
71338- struct ctl_table *ctl_table;
71339+ ctl_table_no_const *ctl_table;
71340 #endif
71341 };
71342
71343diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
71344index 2ae2b83..dbdc85e 100644
71345--- a/include/net/netns/ipv4.h
71346+++ b/include/net/netns/ipv4.h
71347@@ -64,7 +64,7 @@ struct netns_ipv4 {
71348 kgid_t sysctl_ping_group_range[2];
71349 long sysctl_tcp_mem[3];
71350
71351- atomic_t dev_addr_genid;
71352+ atomic_unchecked_t dev_addr_genid;
71353
71354 #ifdef CONFIG_IP_MROUTE
71355 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
71356diff --git a/include/net/protocol.h b/include/net/protocol.h
71357index 047c047..b9dad15 100644
71358--- a/include/net/protocol.h
71359+++ b/include/net/protocol.h
71360@@ -44,7 +44,7 @@ struct net_protocol {
71361 void (*err_handler)(struct sk_buff *skb, u32 info);
71362 unsigned int no_policy:1,
71363 netns_ok:1;
71364-};
71365+} __do_const;
71366
71367 #if IS_ENABLED(CONFIG_IPV6)
71368 struct inet6_protocol {
71369@@ -57,7 +57,7 @@ struct inet6_protocol {
71370 u8 type, u8 code, int offset,
71371 __be32 info);
71372 unsigned int flags; /* INET6_PROTO_xxx */
71373-};
71374+} __do_const;
71375
71376 #define INET6_PROTO_NOPOLICY 0x1
71377 #define INET6_PROTO_FINAL 0x2
71378diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
71379index 5a15fab..d799ea7 100644
71380--- a/include/net/rtnetlink.h
71381+++ b/include/net/rtnetlink.h
71382@@ -81,7 +81,7 @@ struct rtnl_link_ops {
71383 const struct net_device *dev);
71384 unsigned int (*get_num_tx_queues)(void);
71385 unsigned int (*get_num_rx_queues)(void);
71386-};
71387+} __do_const;
71388
71389 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
71390 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
71391diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
71392index 7fdf298..197e9f7 100644
71393--- a/include/net/sctp/sctp.h
71394+++ b/include/net/sctp/sctp.h
71395@@ -330,9 +330,9 @@ do { \
71396
71397 #else /* SCTP_DEBUG */
71398
71399-#define SCTP_DEBUG_PRINTK(whatever...)
71400-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
71401-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
71402+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
71403+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
71404+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
71405 #define SCTP_ENABLE_DEBUG
71406 #define SCTP_DISABLE_DEBUG
71407 #define SCTP_ASSERT(expr, str, func)
71408diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
71409index 2a82d13..62a31c2 100644
71410--- a/include/net/sctp/sm.h
71411+++ b/include/net/sctp/sm.h
71412@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
71413 typedef struct {
71414 sctp_state_fn_t *fn;
71415 const char *name;
71416-} sctp_sm_table_entry_t;
71417+} __do_const sctp_sm_table_entry_t;
71418
71419 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
71420 * currently in use.
71421@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
71422 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
71423
71424 /* Extern declarations for major data structures. */
71425-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71426+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71427
71428
71429 /* Get the size of a DATA chunk payload. */
71430diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
71431index fdeb85a..1329d95 100644
71432--- a/include/net/sctp/structs.h
71433+++ b/include/net/sctp/structs.h
71434@@ -517,7 +517,7 @@ struct sctp_pf {
71435 struct sctp_association *asoc);
71436 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
71437 struct sctp_af *af;
71438-};
71439+} __do_const;
71440
71441
71442 /* Structure to track chunk fragments that have been acked, but peer
71443diff --git a/include/net/sock.h b/include/net/sock.h
71444index 25afaa0..8bb0070 100644
71445--- a/include/net/sock.h
71446+++ b/include/net/sock.h
71447@@ -322,7 +322,7 @@ struct sock {
71448 #ifdef CONFIG_RPS
71449 __u32 sk_rxhash;
71450 #endif
71451- atomic_t sk_drops;
71452+ atomic_unchecked_t sk_drops;
71453 int sk_rcvbuf;
71454
71455 struct sk_filter __rcu *sk_filter;
71456@@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
71457 }
71458
71459 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
71460- char __user *from, char *to,
71461+ char __user *from, unsigned char *to,
71462 int copy, int offset)
71463 {
71464 if (skb->ip_summed == CHECKSUM_NONE) {
71465@@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
71466 }
71467 }
71468
71469-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71470+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71471
71472 /**
71473 * sk_page_frag - return an appropriate page_frag
71474diff --git a/include/net/tcp.h b/include/net/tcp.h
71475index aed42c7..43890c6 100644
71476--- a/include/net/tcp.h
71477+++ b/include/net/tcp.h
71478@@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
71479 extern void tcp_xmit_retransmit_queue(struct sock *);
71480 extern void tcp_simple_retransmit(struct sock *);
71481 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
71482-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71483+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71484
71485 extern void tcp_send_probe0(struct sock *);
71486 extern void tcp_send_partial(struct sock *);
71487@@ -701,8 +701,8 @@ struct tcp_skb_cb {
71488 struct inet6_skb_parm h6;
71489 #endif
71490 } header; /* For incoming frames */
71491- __u32 seq; /* Starting sequence number */
71492- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
71493+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
71494+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
71495 __u32 when; /* used to compute rtt's */
71496 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
71497
71498@@ -716,7 +716,7 @@ struct tcp_skb_cb {
71499
71500 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
71501 /* 1 byte hole */
71502- __u32 ack_seq; /* Sequence number ACK'd */
71503+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
71504 };
71505
71506 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
71507diff --git a/include/net/xfrm.h b/include/net/xfrm.h
71508index 63445ed..d6fc34f 100644
71509--- a/include/net/xfrm.h
71510+++ b/include/net/xfrm.h
71511@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
71512 struct net_device *dev,
71513 const struct flowi *fl);
71514 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
71515-};
71516+} __do_const;
71517
71518 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
71519 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
71520@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
71521 struct sk_buff *skb);
71522 int (*transport_finish)(struct sk_buff *skb,
71523 int async);
71524-};
71525+} __do_const;
71526
71527 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
71528 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
71529@@ -423,7 +423,7 @@ struct xfrm_mode {
71530 struct module *owner;
71531 unsigned int encap;
71532 int flags;
71533-};
71534+} __do_const;
71535
71536 /* Flags for xfrm_mode. */
71537 enum {
71538@@ -514,7 +514,7 @@ struct xfrm_policy {
71539 struct timer_list timer;
71540
71541 struct flow_cache_object flo;
71542- atomic_t genid;
71543+ atomic_unchecked_t genid;
71544 u32 priority;
71545 u32 index;
71546 struct xfrm_mark mark;
71547diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
71548index 1a046b1..ee0bef0 100644
71549--- a/include/rdma/iw_cm.h
71550+++ b/include/rdma/iw_cm.h
71551@@ -122,7 +122,7 @@ struct iw_cm_verbs {
71552 int backlog);
71553
71554 int (*destroy_listen)(struct iw_cm_id *cm_id);
71555-};
71556+} __no_const;
71557
71558 /**
71559 * iw_create_cm_id - Create an IW CM identifier.
71560diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
71561index 399162b..b337f1a 100644
71562--- a/include/scsi/libfc.h
71563+++ b/include/scsi/libfc.h
71564@@ -762,6 +762,7 @@ struct libfc_function_template {
71565 */
71566 void (*disc_stop_final) (struct fc_lport *);
71567 };
71568+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
71569
71570 /**
71571 * struct fc_disc - Discovery context
71572@@ -866,7 +867,7 @@ struct fc_lport {
71573 struct fc_vport *vport;
71574
71575 /* Operational Information */
71576- struct libfc_function_template tt;
71577+ libfc_function_template_no_const tt;
71578 u8 link_up;
71579 u8 qfull;
71580 enum fc_lport_state state;
71581diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
71582index e65c62e..aa2e5a2 100644
71583--- a/include/scsi/scsi_device.h
71584+++ b/include/scsi/scsi_device.h
71585@@ -170,9 +170,9 @@ struct scsi_device {
71586 unsigned int max_device_blocked; /* what device_blocked counts down from */
71587 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
71588
71589- atomic_t iorequest_cnt;
71590- atomic_t iodone_cnt;
71591- atomic_t ioerr_cnt;
71592+ atomic_unchecked_t iorequest_cnt;
71593+ atomic_unchecked_t iodone_cnt;
71594+ atomic_unchecked_t ioerr_cnt;
71595
71596 struct device sdev_gendev,
71597 sdev_dev;
71598diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
71599index b797e8f..8e2c3aa 100644
71600--- a/include/scsi/scsi_transport_fc.h
71601+++ b/include/scsi/scsi_transport_fc.h
71602@@ -751,7 +751,8 @@ struct fc_function_template {
71603 unsigned long show_host_system_hostname:1;
71604
71605 unsigned long disable_target_scan:1;
71606-};
71607+} __do_const;
71608+typedef struct fc_function_template __no_const fc_function_template_no_const;
71609
71610
71611 /**
71612diff --git a/include/sound/soc.h b/include/sound/soc.h
71613index bc56738..a4be132 100644
71614--- a/include/sound/soc.h
71615+++ b/include/sound/soc.h
71616@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
71617 /* probe ordering - for components with runtime dependencies */
71618 int probe_order;
71619 int remove_order;
71620-};
71621+} __do_const;
71622
71623 /* SoC platform interface */
71624 struct snd_soc_platform_driver {
71625@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
71626 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
71627 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
71628 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
71629-};
71630+} __do_const;
71631
71632 struct snd_soc_platform {
71633 const char *name;
71634diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
71635index 663e34a..91b306a 100644
71636--- a/include/target/target_core_base.h
71637+++ b/include/target/target_core_base.h
71638@@ -654,7 +654,7 @@ struct se_device {
71639 spinlock_t stats_lock;
71640 /* Active commands on this virtual SE device */
71641 atomic_t simple_cmds;
71642- atomic_t dev_ordered_id;
71643+ atomic_unchecked_t dev_ordered_id;
71644 atomic_t dev_ordered_sync;
71645 atomic_t dev_qf_count;
71646 int export_count;
71647diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
71648new file mode 100644
71649index 0000000..fb634b7
71650--- /dev/null
71651+++ b/include/trace/events/fs.h
71652@@ -0,0 +1,53 @@
71653+#undef TRACE_SYSTEM
71654+#define TRACE_SYSTEM fs
71655+
71656+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
71657+#define _TRACE_FS_H
71658+
71659+#include <linux/fs.h>
71660+#include <linux/tracepoint.h>
71661+
71662+TRACE_EVENT(do_sys_open,
71663+
71664+ TP_PROTO(const char *filename, int flags, int mode),
71665+
71666+ TP_ARGS(filename, flags, mode),
71667+
71668+ TP_STRUCT__entry(
71669+ __string( filename, filename )
71670+ __field( int, flags )
71671+ __field( int, mode )
71672+ ),
71673+
71674+ TP_fast_assign(
71675+ __assign_str(filename, filename);
71676+ __entry->flags = flags;
71677+ __entry->mode = mode;
71678+ ),
71679+
71680+ TP_printk("\"%s\" %x %o",
71681+ __get_str(filename), __entry->flags, __entry->mode)
71682+);
71683+
71684+TRACE_EVENT(open_exec,
71685+
71686+ TP_PROTO(const char *filename),
71687+
71688+ TP_ARGS(filename),
71689+
71690+ TP_STRUCT__entry(
71691+ __string( filename, filename )
71692+ ),
71693+
71694+ TP_fast_assign(
71695+ __assign_str(filename, filename);
71696+ ),
71697+
71698+ TP_printk("\"%s\"",
71699+ __get_str(filename))
71700+);
71701+
71702+#endif /* _TRACE_FS_H */
71703+
71704+/* This part must be outside protection */
71705+#include <trace/define_trace.h>
71706diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
71707index 1c09820..7f5ec79 100644
71708--- a/include/trace/events/irq.h
71709+++ b/include/trace/events/irq.h
71710@@ -36,7 +36,7 @@ struct softirq_action;
71711 */
71712 TRACE_EVENT(irq_handler_entry,
71713
71714- TP_PROTO(int irq, struct irqaction *action),
71715+ TP_PROTO(int irq, const struct irqaction *action),
71716
71717 TP_ARGS(irq, action),
71718
71719@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
71720 */
71721 TRACE_EVENT(irq_handler_exit,
71722
71723- TP_PROTO(int irq, struct irqaction *action, int ret),
71724+ TP_PROTO(int irq, const struct irqaction *action, int ret),
71725
71726 TP_ARGS(irq, action, ret),
71727
71728diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
71729index 7caf44c..23c6f27 100644
71730--- a/include/uapi/linux/a.out.h
71731+++ b/include/uapi/linux/a.out.h
71732@@ -39,6 +39,14 @@ enum machine_type {
71733 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
71734 };
71735
71736+/* Constants for the N_FLAGS field */
71737+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71738+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
71739+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
71740+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
71741+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71742+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71743+
71744 #if !defined (N_MAGIC)
71745 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
71746 #endif
71747diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
71748index d876736..b36014e 100644
71749--- a/include/uapi/linux/byteorder/little_endian.h
71750+++ b/include/uapi/linux/byteorder/little_endian.h
71751@@ -42,51 +42,51 @@
71752
71753 static inline __le64 __cpu_to_le64p(const __u64 *p)
71754 {
71755- return (__force __le64)*p;
71756+ return (__force const __le64)*p;
71757 }
71758 static inline __u64 __le64_to_cpup(const __le64 *p)
71759 {
71760- return (__force __u64)*p;
71761+ return (__force const __u64)*p;
71762 }
71763 static inline __le32 __cpu_to_le32p(const __u32 *p)
71764 {
71765- return (__force __le32)*p;
71766+ return (__force const __le32)*p;
71767 }
71768 static inline __u32 __le32_to_cpup(const __le32 *p)
71769 {
71770- return (__force __u32)*p;
71771+ return (__force const __u32)*p;
71772 }
71773 static inline __le16 __cpu_to_le16p(const __u16 *p)
71774 {
71775- return (__force __le16)*p;
71776+ return (__force const __le16)*p;
71777 }
71778 static inline __u16 __le16_to_cpup(const __le16 *p)
71779 {
71780- return (__force __u16)*p;
71781+ return (__force const __u16)*p;
71782 }
71783 static inline __be64 __cpu_to_be64p(const __u64 *p)
71784 {
71785- return (__force __be64)__swab64p(p);
71786+ return (__force const __be64)__swab64p(p);
71787 }
71788 static inline __u64 __be64_to_cpup(const __be64 *p)
71789 {
71790- return __swab64p((__u64 *)p);
71791+ return __swab64p((const __u64 *)p);
71792 }
71793 static inline __be32 __cpu_to_be32p(const __u32 *p)
71794 {
71795- return (__force __be32)__swab32p(p);
71796+ return (__force const __be32)__swab32p(p);
71797 }
71798 static inline __u32 __be32_to_cpup(const __be32 *p)
71799 {
71800- return __swab32p((__u32 *)p);
71801+ return __swab32p((const __u32 *)p);
71802 }
71803 static inline __be16 __cpu_to_be16p(const __u16 *p)
71804 {
71805- return (__force __be16)__swab16p(p);
71806+ return (__force const __be16)__swab16p(p);
71807 }
71808 static inline __u16 __be16_to_cpup(const __be16 *p)
71809 {
71810- return __swab16p((__u16 *)p);
71811+ return __swab16p((const __u16 *)p);
71812 }
71813 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
71814 #define __le64_to_cpus(x) do { (void)(x); } while (0)
71815diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
71816index 126a817..d522bd1 100644
71817--- a/include/uapi/linux/elf.h
71818+++ b/include/uapi/linux/elf.h
71819@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
71820 #define PT_GNU_EH_FRAME 0x6474e550
71821
71822 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
71823+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
71824+
71825+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
71826+
71827+/* Constants for the e_flags field */
71828+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71829+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
71830+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
71831+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
71832+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71833+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71834
71835 /*
71836 * Extended Numbering
71837@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
71838 #define DT_DEBUG 21
71839 #define DT_TEXTREL 22
71840 #define DT_JMPREL 23
71841+#define DT_FLAGS 30
71842+ #define DF_TEXTREL 0x00000004
71843 #define DT_ENCODING 32
71844 #define OLD_DT_LOOS 0x60000000
71845 #define DT_LOOS 0x6000000d
71846@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
71847 #define PF_W 0x2
71848 #define PF_X 0x1
71849
71850+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
71851+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
71852+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
71853+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
71854+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
71855+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
71856+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
71857+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
71858+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
71859+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
71860+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
71861+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
71862+
71863 typedef struct elf32_phdr{
71864 Elf32_Word p_type;
71865 Elf32_Off p_offset;
71866@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
71867 #define EI_OSABI 7
71868 #define EI_PAD 8
71869
71870+#define EI_PAX 14
71871+
71872 #define ELFMAG0 0x7f /* EI_MAG */
71873 #define ELFMAG1 'E'
71874 #define ELFMAG2 'L'
71875diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
71876index aa169c4..6a2771d 100644
71877--- a/include/uapi/linux/personality.h
71878+++ b/include/uapi/linux/personality.h
71879@@ -30,6 +30,7 @@ enum {
71880 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
71881 ADDR_NO_RANDOMIZE | \
71882 ADDR_COMPAT_LAYOUT | \
71883+ ADDR_LIMIT_3GB | \
71884 MMAP_PAGE_ZERO)
71885
71886 /*
71887diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
71888index 7530e74..e714828 100644
71889--- a/include/uapi/linux/screen_info.h
71890+++ b/include/uapi/linux/screen_info.h
71891@@ -43,7 +43,8 @@ struct screen_info {
71892 __u16 pages; /* 0x32 */
71893 __u16 vesa_attributes; /* 0x34 */
71894 __u32 capabilities; /* 0x36 */
71895- __u8 _reserved[6]; /* 0x3a */
71896+ __u16 vesapm_size; /* 0x3a */
71897+ __u8 _reserved[4]; /* 0x3c */
71898 } __attribute__((packed));
71899
71900 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
71901diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
71902index 6d67213..8dab561 100644
71903--- a/include/uapi/linux/sysctl.h
71904+++ b/include/uapi/linux/sysctl.h
71905@@ -155,7 +155,11 @@ enum
71906 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
71907 };
71908
71909-
71910+#ifdef CONFIG_PAX_SOFTMODE
71911+enum {
71912+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
71913+};
71914+#endif
71915
71916 /* CTL_VM names: */
71917 enum
71918diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
71919index 26607bd..588b65f 100644
71920--- a/include/uapi/linux/xattr.h
71921+++ b/include/uapi/linux/xattr.h
71922@@ -60,5 +60,9 @@
71923 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
71924 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
71925
71926+/* User namespace */
71927+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
71928+#define XATTR_PAX_FLAGS_SUFFIX "flags"
71929+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
71930
71931 #endif /* _UAPI_LINUX_XATTR_H */
71932diff --git a/include/video/udlfb.h b/include/video/udlfb.h
71933index f9466fa..f4e2b81 100644
71934--- a/include/video/udlfb.h
71935+++ b/include/video/udlfb.h
71936@@ -53,10 +53,10 @@ struct dlfb_data {
71937 u32 pseudo_palette[256];
71938 int blank_mode; /*one of FB_BLANK_ */
71939 /* blit-only rendering path metrics, exposed through sysfs */
71940- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71941- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
71942- atomic_t bytes_sent; /* to usb, after compression including overhead */
71943- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
71944+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71945+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
71946+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
71947+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
71948 };
71949
71950 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
71951diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
71952index 0993a22..32ba2fe 100644
71953--- a/include/video/uvesafb.h
71954+++ b/include/video/uvesafb.h
71955@@ -177,6 +177,7 @@ struct uvesafb_par {
71956 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
71957 u8 pmi_setpal; /* PMI for palette changes */
71958 u16 *pmi_base; /* protected mode interface location */
71959+ u8 *pmi_code; /* protected mode code location */
71960 void *pmi_start;
71961 void *pmi_pal;
71962 u8 *vbe_state_orig; /*
71963diff --git a/init/Kconfig b/init/Kconfig
71964index be8b7f5..1eeca9b 100644
71965--- a/init/Kconfig
71966+++ b/init/Kconfig
71967@@ -990,6 +990,7 @@ endif # CGROUPS
71968
71969 config CHECKPOINT_RESTORE
71970 bool "Checkpoint/restore support" if EXPERT
71971+ depends on !GRKERNSEC
71972 default n
71973 help
71974 Enables additional kernel features in a sake of checkpoint/restore.
71975@@ -1468,7 +1469,7 @@ config SLUB_DEBUG
71976
71977 config COMPAT_BRK
71978 bool "Disable heap randomization"
71979- default y
71980+ default n
71981 help
71982 Randomizing heap placement makes heap exploits harder, but it
71983 also breaks ancient binaries (including anything libc5 based).
71984@@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
71985 config STOP_MACHINE
71986 bool
71987 default y
71988- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
71989+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
71990 help
71991 Need stop_machine() primitive.
71992
71993diff --git a/init/Makefile b/init/Makefile
71994index 7bc47ee..6da2dc7 100644
71995--- a/init/Makefile
71996+++ b/init/Makefile
71997@@ -2,6 +2,9 @@
71998 # Makefile for the linux kernel.
71999 #
72000
72001+ccflags-y := $(GCC_PLUGINS_CFLAGS)
72002+asflags-y := $(GCC_PLUGINS_AFLAGS)
72003+
72004 obj-y := main.o version.o mounts.o
72005 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72006 obj-y += noinitramfs.o
72007diff --git a/init/do_mounts.c b/init/do_mounts.c
72008index 1d1b634..a1c810f 100644
72009--- a/init/do_mounts.c
72010+++ b/init/do_mounts.c
72011@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72012 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72013 {
72014 struct super_block *s;
72015- int err = sys_mount(name, "/root", fs, flags, data);
72016+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72017 if (err)
72018 return err;
72019
72020- sys_chdir("/root");
72021+ sys_chdir((const char __force_user *)"/root");
72022 s = current->fs->pwd.dentry->d_sb;
72023 ROOT_DEV = s->s_dev;
72024 printk(KERN_INFO
72025@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72026 va_start(args, fmt);
72027 vsprintf(buf, fmt, args);
72028 va_end(args);
72029- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72030+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72031 if (fd >= 0) {
72032 sys_ioctl(fd, FDEJECT, 0);
72033 sys_close(fd);
72034 }
72035 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72036- fd = sys_open("/dev/console", O_RDWR, 0);
72037+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72038 if (fd >= 0) {
72039 sys_ioctl(fd, TCGETS, (long)&termios);
72040 termios.c_lflag &= ~ICANON;
72041 sys_ioctl(fd, TCSETSF, (long)&termios);
72042- sys_read(fd, &c, 1);
72043+ sys_read(fd, (char __user *)&c, 1);
72044 termios.c_lflag |= ICANON;
72045 sys_ioctl(fd, TCSETSF, (long)&termios);
72046 sys_close(fd);
72047@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72048 mount_root();
72049 out:
72050 devtmpfs_mount("dev");
72051- sys_mount(".", "/", NULL, MS_MOVE, NULL);
72052- sys_chroot(".");
72053+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72054+ sys_chroot((const char __force_user *)".");
72055 }
72056diff --git a/init/do_mounts.h b/init/do_mounts.h
72057index f5b978a..69dbfe8 100644
72058--- a/init/do_mounts.h
72059+++ b/init/do_mounts.h
72060@@ -15,15 +15,15 @@ extern int root_mountflags;
72061
72062 static inline int create_dev(char *name, dev_t dev)
72063 {
72064- sys_unlink(name);
72065- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72066+ sys_unlink((char __force_user *)name);
72067+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72068 }
72069
72070 #if BITS_PER_LONG == 32
72071 static inline u32 bstat(char *name)
72072 {
72073 struct stat64 stat;
72074- if (sys_stat64(name, &stat) != 0)
72075+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72076 return 0;
72077 if (!S_ISBLK(stat.st_mode))
72078 return 0;
72079@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72080 static inline u32 bstat(char *name)
72081 {
72082 struct stat stat;
72083- if (sys_newstat(name, &stat) != 0)
72084+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72085 return 0;
72086 if (!S_ISBLK(stat.st_mode))
72087 return 0;
72088diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72089index f9acf71..1e19144 100644
72090--- a/init/do_mounts_initrd.c
72091+++ b/init/do_mounts_initrd.c
72092@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72093 create_dev("/dev/root.old", Root_RAM0);
72094 /* mount initrd on rootfs' /root */
72095 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72096- sys_mkdir("/old", 0700);
72097- sys_chdir("/old");
72098+ sys_mkdir((const char __force_user *)"/old", 0700);
72099+ sys_chdir((const char __force_user *)"/old");
72100
72101 /*
72102 * In case that a resume from disk is carried out by linuxrc or one of
72103@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72104 current->flags &= ~PF_FREEZER_SKIP;
72105
72106 /* move initrd to rootfs' /old */
72107- sys_mount("..", ".", NULL, MS_MOVE, NULL);
72108+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72109 /* switch root and cwd back to / of rootfs */
72110- sys_chroot("..");
72111+ sys_chroot((const char __force_user *)"..");
72112
72113 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72114- sys_chdir("/old");
72115+ sys_chdir((const char __force_user *)"/old");
72116 return;
72117 }
72118
72119- sys_chdir("/");
72120+ sys_chdir((const char __force_user *)"/");
72121 ROOT_DEV = new_decode_dev(real_root_dev);
72122 mount_root();
72123
72124 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72125- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72126+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72127 if (!error)
72128 printk("okay\n");
72129 else {
72130- int fd = sys_open("/dev/root.old", O_RDWR, 0);
72131+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72132 if (error == -ENOENT)
72133 printk("/initrd does not exist. Ignored.\n");
72134 else
72135 printk("failed\n");
72136 printk(KERN_NOTICE "Unmounting old root\n");
72137- sys_umount("/old", MNT_DETACH);
72138+ sys_umount((char __force_user *)"/old", MNT_DETACH);
72139 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72140 if (fd < 0) {
72141 error = fd;
72142@@ -120,11 +120,11 @@ int __init initrd_load(void)
72143 * mounted in the normal path.
72144 */
72145 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72146- sys_unlink("/initrd.image");
72147+ sys_unlink((const char __force_user *)"/initrd.image");
72148 handle_initrd();
72149 return 1;
72150 }
72151 }
72152- sys_unlink("/initrd.image");
72153+ sys_unlink((const char __force_user *)"/initrd.image");
72154 return 0;
72155 }
72156diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72157index 8cb6db5..d729f50 100644
72158--- a/init/do_mounts_md.c
72159+++ b/init/do_mounts_md.c
72160@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72161 partitioned ? "_d" : "", minor,
72162 md_setup_args[ent].device_names);
72163
72164- fd = sys_open(name, 0, 0);
72165+ fd = sys_open((char __force_user *)name, 0, 0);
72166 if (fd < 0) {
72167 printk(KERN_ERR "md: open failed - cannot start "
72168 "array %s\n", name);
72169@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72170 * array without it
72171 */
72172 sys_close(fd);
72173- fd = sys_open(name, 0, 0);
72174+ fd = sys_open((char __force_user *)name, 0, 0);
72175 sys_ioctl(fd, BLKRRPART, 0);
72176 }
72177 sys_close(fd);
72178@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72179
72180 wait_for_device_probe();
72181
72182- fd = sys_open("/dev/md0", 0, 0);
72183+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72184 if (fd >= 0) {
72185 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72186 sys_close(fd);
72187diff --git a/init/init_task.c b/init/init_task.c
72188index 8b2f399..f0797c9 100644
72189--- a/init/init_task.c
72190+++ b/init/init_task.c
72191@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72192 * Initial thread structure. Alignment of this is handled by a special
72193 * linker map entry.
72194 */
72195+#ifdef CONFIG_X86
72196+union thread_union init_thread_union __init_task_data;
72197+#else
72198 union thread_union init_thread_union __init_task_data =
72199 { INIT_THREAD_INFO(init_task) };
72200+#endif
72201diff --git a/init/initramfs.c b/init/initramfs.c
72202index 84c6bf1..8899338 100644
72203--- a/init/initramfs.c
72204+++ b/init/initramfs.c
72205@@ -84,7 +84,7 @@ static void __init free_hash(void)
72206 }
72207 }
72208
72209-static long __init do_utime(char *filename, time_t mtime)
72210+static long __init do_utime(char __force_user *filename, time_t mtime)
72211 {
72212 struct timespec t[2];
72213
72214@@ -119,7 +119,7 @@ static void __init dir_utime(void)
72215 struct dir_entry *de, *tmp;
72216 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72217 list_del(&de->list);
72218- do_utime(de->name, de->mtime);
72219+ do_utime((char __force_user *)de->name, de->mtime);
72220 kfree(de->name);
72221 kfree(de);
72222 }
72223@@ -281,7 +281,7 @@ static int __init maybe_link(void)
72224 if (nlink >= 2) {
72225 char *old = find_link(major, minor, ino, mode, collected);
72226 if (old)
72227- return (sys_link(old, collected) < 0) ? -1 : 1;
72228+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72229 }
72230 return 0;
72231 }
72232@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72233 {
72234 struct stat st;
72235
72236- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72237+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72238 if (S_ISDIR(st.st_mode))
72239- sys_rmdir(path);
72240+ sys_rmdir((char __force_user *)path);
72241 else
72242- sys_unlink(path);
72243+ sys_unlink((char __force_user *)path);
72244 }
72245 }
72246
72247@@ -315,7 +315,7 @@ static int __init do_name(void)
72248 int openflags = O_WRONLY|O_CREAT;
72249 if (ml != 1)
72250 openflags |= O_TRUNC;
72251- wfd = sys_open(collected, openflags, mode);
72252+ wfd = sys_open((char __force_user *)collected, openflags, mode);
72253
72254 if (wfd >= 0) {
72255 sys_fchown(wfd, uid, gid);
72256@@ -327,17 +327,17 @@ static int __init do_name(void)
72257 }
72258 }
72259 } else if (S_ISDIR(mode)) {
72260- sys_mkdir(collected, mode);
72261- sys_chown(collected, uid, gid);
72262- sys_chmod(collected, mode);
72263+ sys_mkdir((char __force_user *)collected, mode);
72264+ sys_chown((char __force_user *)collected, uid, gid);
72265+ sys_chmod((char __force_user *)collected, mode);
72266 dir_add(collected, mtime);
72267 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72268 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72269 if (maybe_link() == 0) {
72270- sys_mknod(collected, mode, rdev);
72271- sys_chown(collected, uid, gid);
72272- sys_chmod(collected, mode);
72273- do_utime(collected, mtime);
72274+ sys_mknod((char __force_user *)collected, mode, rdev);
72275+ sys_chown((char __force_user *)collected, uid, gid);
72276+ sys_chmod((char __force_user *)collected, mode);
72277+ do_utime((char __force_user *)collected, mtime);
72278 }
72279 }
72280 return 0;
72281@@ -346,15 +346,15 @@ static int __init do_name(void)
72282 static int __init do_copy(void)
72283 {
72284 if (count >= body_len) {
72285- sys_write(wfd, victim, body_len);
72286+ sys_write(wfd, (char __force_user *)victim, body_len);
72287 sys_close(wfd);
72288- do_utime(vcollected, mtime);
72289+ do_utime((char __force_user *)vcollected, mtime);
72290 kfree(vcollected);
72291 eat(body_len);
72292 state = SkipIt;
72293 return 0;
72294 } else {
72295- sys_write(wfd, victim, count);
72296+ sys_write(wfd, (char __force_user *)victim, count);
72297 body_len -= count;
72298 eat(count);
72299 return 1;
72300@@ -365,9 +365,9 @@ static int __init do_symlink(void)
72301 {
72302 collected[N_ALIGN(name_len) + body_len] = '\0';
72303 clean_path(collected, 0);
72304- sys_symlink(collected + N_ALIGN(name_len), collected);
72305- sys_lchown(collected, uid, gid);
72306- do_utime(collected, mtime);
72307+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
72308+ sys_lchown((char __force_user *)collected, uid, gid);
72309+ do_utime((char __force_user *)collected, mtime);
72310 state = SkipIt;
72311 next_state = Reset;
72312 return 0;
72313diff --git a/init/main.c b/init/main.c
72314index cee4b5c..6a3402b 100644
72315--- a/init/main.c
72316+++ b/init/main.c
72317@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
72318 extern void tc_init(void);
72319 #endif
72320
72321+extern void grsecurity_init(void);
72322+
72323 /*
72324 * Debug helper: via this flag we know that we are in 'early bootup code'
72325 * where only the boot processor is running with IRQ disabled. This means
72326@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
72327
72328 __setup("reset_devices", set_reset_devices);
72329
72330+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72331+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
72332+static int __init setup_grsec_proc_gid(char *str)
72333+{
72334+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
72335+ return 1;
72336+}
72337+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
72338+#endif
72339+
72340+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
72341+extern char pax_enter_kernel_user[];
72342+extern char pax_exit_kernel_user[];
72343+extern pgdval_t clone_pgd_mask;
72344+#endif
72345+
72346+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
72347+static int __init setup_pax_nouderef(char *str)
72348+{
72349+#ifdef CONFIG_X86_32
72350+ unsigned int cpu;
72351+ struct desc_struct *gdt;
72352+
72353+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
72354+ gdt = get_cpu_gdt_table(cpu);
72355+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
72356+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
72357+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
72358+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
72359+ }
72360+ loadsegment(ds, __KERNEL_DS);
72361+ loadsegment(es, __KERNEL_DS);
72362+ loadsegment(ss, __KERNEL_DS);
72363+#else
72364+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
72365+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
72366+ clone_pgd_mask = ~(pgdval_t)0UL;
72367+#endif
72368+
72369+ return 0;
72370+}
72371+early_param("pax_nouderef", setup_pax_nouderef);
72372+#endif
72373+
72374+#ifdef CONFIG_PAX_SOFTMODE
72375+int pax_softmode;
72376+
72377+static int __init setup_pax_softmode(char *str)
72378+{
72379+ get_option(&str, &pax_softmode);
72380+ return 1;
72381+}
72382+__setup("pax_softmode=", setup_pax_softmode);
72383+#endif
72384+
72385 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
72386 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
72387 static const char *panic_later, *panic_param;
72388@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
72389 {
72390 int count = preempt_count();
72391 int ret;
72392+ const char *msg1 = "", *msg2 = "";
72393
72394 if (initcall_debug)
72395 ret = do_one_initcall_debug(fn);
72396@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
72397 sprintf(msgbuf, "error code %d ", ret);
72398
72399 if (preempt_count() != count) {
72400- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
72401+ msg1 = " preemption imbalance";
72402 preempt_count() = count;
72403 }
72404 if (irqs_disabled()) {
72405- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
72406+ msg2 = " disabled interrupts";
72407 local_irq_enable();
72408 }
72409- if (msgbuf[0]) {
72410- printk("initcall %pF returned with %s\n", fn, msgbuf);
72411+ if (msgbuf[0] || *msg1 || *msg2) {
72412+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
72413 }
72414
72415 return ret;
72416@@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
72417 level, level,
72418 &repair_env_string);
72419
72420- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
72421+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
72422 do_one_initcall(*fn);
72423+
72424+#ifdef CONFIG_PAX_LATENT_ENTROPY
72425+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
72426+#endif
72427+
72428+ }
72429 }
72430
72431 static void __init do_initcalls(void)
72432@@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
72433 {
72434 initcall_t *fn;
72435
72436- for (fn = __initcall_start; fn < __initcall0_start; fn++)
72437+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
72438 do_one_initcall(*fn);
72439+
72440+#ifdef CONFIG_PAX_LATENT_ENTROPY
72441+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
72442+#endif
72443+
72444+ }
72445 }
72446
72447 static int run_init_process(const char *init_filename)
72448@@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
72449 do_basic_setup();
72450
72451 /* Open the /dev/console on the rootfs, this should never fail */
72452- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
72453+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
72454 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
72455
72456 (void) sys_dup(0);
72457@@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
72458 if (!ramdisk_execute_command)
72459 ramdisk_execute_command = "/init";
72460
72461- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
72462+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
72463 ramdisk_execute_command = NULL;
72464 prepare_namespace();
72465 }
72466
72467+ grsecurity_init();
72468+
72469 /*
72470 * Ok, we have completed the initial bootup, and
72471 * we're essentially up and running. Get rid of the
72472diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
72473index 130dfec..cc88451 100644
72474--- a/ipc/ipc_sysctl.c
72475+++ b/ipc/ipc_sysctl.c
72476@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
72477 static int proc_ipc_dointvec(ctl_table *table, int write,
72478 void __user *buffer, size_t *lenp, loff_t *ppos)
72479 {
72480- struct ctl_table ipc_table;
72481+ ctl_table_no_const ipc_table;
72482
72483 memcpy(&ipc_table, table, sizeof(ipc_table));
72484 ipc_table.data = get_ipc(table);
72485@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
72486 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
72487 void __user *buffer, size_t *lenp, loff_t *ppos)
72488 {
72489- struct ctl_table ipc_table;
72490+ ctl_table_no_const ipc_table;
72491
72492 memcpy(&ipc_table, table, sizeof(ipc_table));
72493 ipc_table.data = get_ipc(table);
72494@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
72495 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72496 void __user *buffer, size_t *lenp, loff_t *ppos)
72497 {
72498- struct ctl_table ipc_table;
72499+ ctl_table_no_const ipc_table;
72500 size_t lenp_bef = *lenp;
72501 int rc;
72502
72503@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72504 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
72505 void __user *buffer, size_t *lenp, loff_t *ppos)
72506 {
72507- struct ctl_table ipc_table;
72508+ ctl_table_no_const ipc_table;
72509 memcpy(&ipc_table, table, sizeof(ipc_table));
72510 ipc_table.data = get_ipc(table);
72511
72512@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
72513 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
72514 void __user *buffer, size_t *lenp, loff_t *ppos)
72515 {
72516- struct ctl_table ipc_table;
72517+ ctl_table_no_const ipc_table;
72518 size_t lenp_bef = *lenp;
72519 int oldval;
72520 int rc;
72521diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
72522index 383d638..943fdbb 100644
72523--- a/ipc/mq_sysctl.c
72524+++ b/ipc/mq_sysctl.c
72525@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
72526 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
72527 void __user *buffer, size_t *lenp, loff_t *ppos)
72528 {
72529- struct ctl_table mq_table;
72530+ ctl_table_no_const mq_table;
72531 memcpy(&mq_table, table, sizeof(mq_table));
72532 mq_table.data = get_mq(table);
72533
72534diff --git a/ipc/mqueue.c b/ipc/mqueue.c
72535index 71a3ca1..cc330ee 100644
72536--- a/ipc/mqueue.c
72537+++ b/ipc/mqueue.c
72538@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
72539 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
72540 info->attr.mq_msgsize);
72541
72542+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
72543 spin_lock(&mq_lock);
72544 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
72545 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
72546diff --git a/ipc/msg.c b/ipc/msg.c
72547index 950572f..362ea07 100644
72548--- a/ipc/msg.c
72549+++ b/ipc/msg.c
72550@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
72551 return security_msg_queue_associate(msq, msgflg);
72552 }
72553
72554+static struct ipc_ops msg_ops = {
72555+ .getnew = newque,
72556+ .associate = msg_security,
72557+ .more_checks = NULL
72558+};
72559+
72560 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
72561 {
72562 struct ipc_namespace *ns;
72563- struct ipc_ops msg_ops;
72564 struct ipc_params msg_params;
72565
72566 ns = current->nsproxy->ipc_ns;
72567
72568- msg_ops.getnew = newque;
72569- msg_ops.associate = msg_security;
72570- msg_ops.more_checks = NULL;
72571-
72572 msg_params.key = key;
72573 msg_params.flg = msgflg;
72574
72575@@ -820,15 +821,17 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
72576 struct msg_msg *copy = NULL;
72577 unsigned long copy_number = 0;
72578
72579+ ns = current->nsproxy->ipc_ns;
72580+
72581 if (msqid < 0 || (long) bufsz < 0)
72582 return -EINVAL;
72583 if (msgflg & MSG_COPY) {
72584- copy = prepare_copy(buf, bufsz, msgflg, &msgtyp, &copy_number);
72585+ copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax),
72586+ msgflg, &msgtyp, &copy_number);
72587 if (IS_ERR(copy))
72588 return PTR_ERR(copy);
72589 }
72590 mode = convert_mode(&msgtyp, msgflg);
72591- ns = current->nsproxy->ipc_ns;
72592
72593 msq = msg_lock_check(ns, msqid);
72594 if (IS_ERR(msq)) {
72595diff --git a/ipc/msgutil.c b/ipc/msgutil.c
72596index ebfcbfa..5df8e4b 100644
72597--- a/ipc/msgutil.c
72598+++ b/ipc/msgutil.c
72599@@ -117,9 +117,6 @@ struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
72600 if (alen > DATALEN_MSG)
72601 alen = DATALEN_MSG;
72602
72603- dst->next = NULL;
72604- dst->security = NULL;
72605-
72606 memcpy(dst + 1, src + 1, alen);
72607
72608 len -= alen;
72609diff --git a/ipc/sem.c b/ipc/sem.c
72610index 58d31f1..cce7a55 100644
72611--- a/ipc/sem.c
72612+++ b/ipc/sem.c
72613@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
72614 return 0;
72615 }
72616
72617+static struct ipc_ops sem_ops = {
72618+ .getnew = newary,
72619+ .associate = sem_security,
72620+ .more_checks = sem_more_checks
72621+};
72622+
72623 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72624 {
72625 struct ipc_namespace *ns;
72626- struct ipc_ops sem_ops;
72627 struct ipc_params sem_params;
72628
72629 ns = current->nsproxy->ipc_ns;
72630@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72631 if (nsems < 0 || nsems > ns->sc_semmsl)
72632 return -EINVAL;
72633
72634- sem_ops.getnew = newary;
72635- sem_ops.associate = sem_security;
72636- sem_ops.more_checks = sem_more_checks;
72637-
72638 sem_params.key = key;
72639 sem_params.flg = semflg;
72640 sem_params.u.nsems = nsems;
72641diff --git a/ipc/shm.c b/ipc/shm.c
72642index 4fa6d8f..55cff14 100644
72643--- a/ipc/shm.c
72644+++ b/ipc/shm.c
72645@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
72646 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
72647 #endif
72648
72649+#ifdef CONFIG_GRKERNSEC
72650+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72651+ const time_t shm_createtime, const kuid_t cuid,
72652+ const int shmid);
72653+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72654+ const time_t shm_createtime);
72655+#endif
72656+
72657 void shm_init_ns(struct ipc_namespace *ns)
72658 {
72659 ns->shm_ctlmax = SHMMAX;
72660@@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
72661 shp->shm_lprid = 0;
72662 shp->shm_atim = shp->shm_dtim = 0;
72663 shp->shm_ctim = get_seconds();
72664+#ifdef CONFIG_GRKERNSEC
72665+ {
72666+ struct timespec timeval;
72667+ do_posix_clock_monotonic_gettime(&timeval);
72668+
72669+ shp->shm_createtime = timeval.tv_sec;
72670+ }
72671+#endif
72672 shp->shm_segsz = size;
72673 shp->shm_nattch = 0;
72674 shp->shm_file = file;
72675@@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
72676 return 0;
72677 }
72678
72679+static struct ipc_ops shm_ops = {
72680+ .getnew = newseg,
72681+ .associate = shm_security,
72682+ .more_checks = shm_more_checks
72683+};
72684+
72685 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
72686 {
72687 struct ipc_namespace *ns;
72688- struct ipc_ops shm_ops;
72689 struct ipc_params shm_params;
72690
72691 ns = current->nsproxy->ipc_ns;
72692
72693- shm_ops.getnew = newseg;
72694- shm_ops.associate = shm_security;
72695- shm_ops.more_checks = shm_more_checks;
72696-
72697 shm_params.key = key;
72698 shm_params.flg = shmflg;
72699 shm_params.u.size = size;
72700@@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72701 f_mode = FMODE_READ | FMODE_WRITE;
72702 }
72703 if (shmflg & SHM_EXEC) {
72704+
72705+#ifdef CONFIG_PAX_MPROTECT
72706+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
72707+ goto out;
72708+#endif
72709+
72710 prot |= PROT_EXEC;
72711 acc_mode |= S_IXUGO;
72712 }
72713@@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72714 if (err)
72715 goto out_unlock;
72716
72717+#ifdef CONFIG_GRKERNSEC
72718+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
72719+ shp->shm_perm.cuid, shmid) ||
72720+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
72721+ err = -EACCES;
72722+ goto out_unlock;
72723+ }
72724+#endif
72725+
72726 path = shp->shm_file->f_path;
72727 path_get(&path);
72728 shp->shm_nattch++;
72729+#ifdef CONFIG_GRKERNSEC
72730+ shp->shm_lapid = current->pid;
72731+#endif
72732 size = i_size_read(path.dentry->d_inode);
72733 shm_unlock(shp);
72734
72735diff --git a/kernel/acct.c b/kernel/acct.c
72736index 051e071..15e0920 100644
72737--- a/kernel/acct.c
72738+++ b/kernel/acct.c
72739@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
72740 */
72741 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
72742 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
72743- file->f_op->write(file, (char *)&ac,
72744+ file->f_op->write(file, (char __force_user *)&ac,
72745 sizeof(acct_t), &file->f_pos);
72746 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
72747 set_fs(fs);
72748diff --git a/kernel/audit.c b/kernel/audit.c
72749index d596e53..dbef3c3 100644
72750--- a/kernel/audit.c
72751+++ b/kernel/audit.c
72752@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
72753 3) suppressed due to audit_rate_limit
72754 4) suppressed due to audit_backlog_limit
72755 */
72756-static atomic_t audit_lost = ATOMIC_INIT(0);
72757+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
72758
72759 /* The netlink socket. */
72760 static struct sock *audit_sock;
72761@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
72762 unsigned long now;
72763 int print;
72764
72765- atomic_inc(&audit_lost);
72766+ atomic_inc_unchecked(&audit_lost);
72767
72768 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
72769
72770@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
72771 printk(KERN_WARNING
72772 "audit: audit_lost=%d audit_rate_limit=%d "
72773 "audit_backlog_limit=%d\n",
72774- atomic_read(&audit_lost),
72775+ atomic_read_unchecked(&audit_lost),
72776 audit_rate_limit,
72777 audit_backlog_limit);
72778 audit_panic(message);
72779@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
72780 status_set.pid = audit_pid;
72781 status_set.rate_limit = audit_rate_limit;
72782 status_set.backlog_limit = audit_backlog_limit;
72783- status_set.lost = atomic_read(&audit_lost);
72784+ status_set.lost = atomic_read_unchecked(&audit_lost);
72785 status_set.backlog = skb_queue_len(&audit_skb_queue);
72786 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
72787 &status_set, sizeof(status_set));
72788diff --git a/kernel/auditsc.c b/kernel/auditsc.c
72789index a371f85..da826c1 100644
72790--- a/kernel/auditsc.c
72791+++ b/kernel/auditsc.c
72792@@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
72793 }
72794
72795 /* global counter which is incremented every time something logs in */
72796-static atomic_t session_id = ATOMIC_INIT(0);
72797+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
72798
72799 /**
72800 * audit_set_loginuid - set current task's audit_context loginuid
72801@@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
72802 return -EPERM;
72803 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
72804
72805- sessionid = atomic_inc_return(&session_id);
72806+ sessionid = atomic_inc_return_unchecked(&session_id);
72807 if (context && context->in_syscall) {
72808 struct audit_buffer *ab;
72809
72810diff --git a/kernel/capability.c b/kernel/capability.c
72811index 493d972..f87dfbd 100644
72812--- a/kernel/capability.c
72813+++ b/kernel/capability.c
72814@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
72815 * before modification is attempted and the application
72816 * fails.
72817 */
72818+ if (tocopy > ARRAY_SIZE(kdata))
72819+ return -EFAULT;
72820+
72821 if (copy_to_user(dataptr, kdata, tocopy
72822 * sizeof(struct __user_cap_data_struct))) {
72823 return -EFAULT;
72824@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
72825 int ret;
72826
72827 rcu_read_lock();
72828- ret = security_capable(__task_cred(t), ns, cap);
72829+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
72830+ gr_task_is_capable(t, __task_cred(t), cap);
72831 rcu_read_unlock();
72832
72833- return (ret == 0);
72834+ return ret;
72835 }
72836
72837 /**
72838@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
72839 int ret;
72840
72841 rcu_read_lock();
72842- ret = security_capable_noaudit(__task_cred(t), ns, cap);
72843+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
72844 rcu_read_unlock();
72845
72846- return (ret == 0);
72847+ return ret;
72848 }
72849
72850 /**
72851@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
72852 BUG();
72853 }
72854
72855- if (security_capable(current_cred(), ns, cap) == 0) {
72856+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
72857 current->flags |= PF_SUPERPRIV;
72858 return true;
72859 }
72860@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
72861 }
72862 EXPORT_SYMBOL(ns_capable);
72863
72864+bool ns_capable_nolog(struct user_namespace *ns, int cap)
72865+{
72866+ if (unlikely(!cap_valid(cap))) {
72867+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
72868+ BUG();
72869+ }
72870+
72871+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
72872+ current->flags |= PF_SUPERPRIV;
72873+ return true;
72874+ }
72875+ return false;
72876+}
72877+EXPORT_SYMBOL(ns_capable_nolog);
72878+
72879 /**
72880 * capable - Determine if the current task has a superior capability in effect
72881 * @cap: The capability to be tested for
72882@@ -408,6 +427,12 @@ bool capable(int cap)
72883 }
72884 EXPORT_SYMBOL(capable);
72885
72886+bool capable_nolog(int cap)
72887+{
72888+ return ns_capable_nolog(&init_user_ns, cap);
72889+}
72890+EXPORT_SYMBOL(capable_nolog);
72891+
72892 /**
72893 * nsown_capable - Check superior capability to one's own user_ns
72894 * @cap: The capability in question
72895@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
72896
72897 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72898 }
72899+
72900+bool inode_capable_nolog(const struct inode *inode, int cap)
72901+{
72902+ struct user_namespace *ns = current_user_ns();
72903+
72904+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72905+}
72906diff --git a/kernel/cgroup.c b/kernel/cgroup.c
72907index 1e23664..570a83d 100644
72908--- a/kernel/cgroup.c
72909+++ b/kernel/cgroup.c
72910@@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
72911 struct css_set *cg = link->cg;
72912 struct task_struct *task;
72913 int count = 0;
72914- seq_printf(seq, "css_set %p\n", cg);
72915+ seq_printf(seq, "css_set %pK\n", cg);
72916 list_for_each_entry(task, &cg->tasks, cg_list) {
72917 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
72918 seq_puts(seq, " ...\n");
72919diff --git a/kernel/compat.c b/kernel/compat.c
72920index 36700e9..73d770c 100644
72921--- a/kernel/compat.c
72922+++ b/kernel/compat.c
72923@@ -13,6 +13,7 @@
72924
72925 #include <linux/linkage.h>
72926 #include <linux/compat.h>
72927+#include <linux/module.h>
72928 #include <linux/errno.h>
72929 #include <linux/time.h>
72930 #include <linux/signal.h>
72931@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
72932 mm_segment_t oldfs;
72933 long ret;
72934
72935- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
72936+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
72937 oldfs = get_fs();
72938 set_fs(KERNEL_DS);
72939 ret = hrtimer_nanosleep_restart(restart);
72940@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
72941 oldfs = get_fs();
72942 set_fs(KERNEL_DS);
72943 ret = hrtimer_nanosleep(&tu,
72944- rmtp ? (struct timespec __user *)&rmt : NULL,
72945+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
72946 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
72947 set_fs(oldfs);
72948
72949@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
72950 mm_segment_t old_fs = get_fs();
72951
72952 set_fs(KERNEL_DS);
72953- ret = sys_sigpending((old_sigset_t __user *) &s);
72954+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
72955 set_fs(old_fs);
72956 if (ret == 0)
72957 ret = put_user(s, set);
72958@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
72959 mm_segment_t old_fs = get_fs();
72960
72961 set_fs(KERNEL_DS);
72962- ret = sys_old_getrlimit(resource, &r);
72963+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
72964 set_fs(old_fs);
72965
72966 if (!ret) {
72967@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
72968 mm_segment_t old_fs = get_fs();
72969
72970 set_fs(KERNEL_DS);
72971- ret = sys_getrusage(who, (struct rusage __user *) &r);
72972+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
72973 set_fs(old_fs);
72974
72975 if (ret)
72976@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
72977 set_fs (KERNEL_DS);
72978 ret = sys_wait4(pid,
72979 (stat_addr ?
72980- (unsigned int __user *) &status : NULL),
72981- options, (struct rusage __user *) &r);
72982+ (unsigned int __force_user *) &status : NULL),
72983+ options, (struct rusage __force_user *) &r);
72984 set_fs (old_fs);
72985
72986 if (ret > 0) {
72987@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
72988 memset(&info, 0, sizeof(info));
72989
72990 set_fs(KERNEL_DS);
72991- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
72992- uru ? (struct rusage __user *)&ru : NULL);
72993+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
72994+ uru ? (struct rusage __force_user *)&ru : NULL);
72995 set_fs(old_fs);
72996
72997 if ((ret < 0) || (info.si_signo == 0))
72998@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
72999 oldfs = get_fs();
73000 set_fs(KERNEL_DS);
73001 err = sys_timer_settime(timer_id, flags,
73002- (struct itimerspec __user *) &newts,
73003- (struct itimerspec __user *) &oldts);
73004+ (struct itimerspec __force_user *) &newts,
73005+ (struct itimerspec __force_user *) &oldts);
73006 set_fs(oldfs);
73007 if (!err && old && put_compat_itimerspec(old, &oldts))
73008 return -EFAULT;
73009@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73010 oldfs = get_fs();
73011 set_fs(KERNEL_DS);
73012 err = sys_timer_gettime(timer_id,
73013- (struct itimerspec __user *) &ts);
73014+ (struct itimerspec __force_user *) &ts);
73015 set_fs(oldfs);
73016 if (!err && put_compat_itimerspec(setting, &ts))
73017 return -EFAULT;
73018@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73019 oldfs = get_fs();
73020 set_fs(KERNEL_DS);
73021 err = sys_clock_settime(which_clock,
73022- (struct timespec __user *) &ts);
73023+ (struct timespec __force_user *) &ts);
73024 set_fs(oldfs);
73025 return err;
73026 }
73027@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73028 oldfs = get_fs();
73029 set_fs(KERNEL_DS);
73030 err = sys_clock_gettime(which_clock,
73031- (struct timespec __user *) &ts);
73032+ (struct timespec __force_user *) &ts);
73033 set_fs(oldfs);
73034 if (!err && put_compat_timespec(&ts, tp))
73035 return -EFAULT;
73036@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73037
73038 oldfs = get_fs();
73039 set_fs(KERNEL_DS);
73040- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73041+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73042 set_fs(oldfs);
73043
73044 err = compat_put_timex(utp, &txc);
73045@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73046 oldfs = get_fs();
73047 set_fs(KERNEL_DS);
73048 err = sys_clock_getres(which_clock,
73049- (struct timespec __user *) &ts);
73050+ (struct timespec __force_user *) &ts);
73051 set_fs(oldfs);
73052 if (!err && tp && put_compat_timespec(&ts, tp))
73053 return -EFAULT;
73054@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73055 long err;
73056 mm_segment_t oldfs;
73057 struct timespec tu;
73058- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73059+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73060
73061- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73062+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73063 oldfs = get_fs();
73064 set_fs(KERNEL_DS);
73065 err = clock_nanosleep_restart(restart);
73066@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73067 oldfs = get_fs();
73068 set_fs(KERNEL_DS);
73069 err = sys_clock_nanosleep(which_clock, flags,
73070- (struct timespec __user *) &in,
73071- (struct timespec __user *) &out);
73072+ (struct timespec __force_user *) &in,
73073+ (struct timespec __force_user *) &out);
73074 set_fs(oldfs);
73075
73076 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73077diff --git a/kernel/configs.c b/kernel/configs.c
73078index 42e8fa0..9e7406b 100644
73079--- a/kernel/configs.c
73080+++ b/kernel/configs.c
73081@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73082 struct proc_dir_entry *entry;
73083
73084 /* create the current config file */
73085+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73086+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73087+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73088+ &ikconfig_file_ops);
73089+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73090+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73091+ &ikconfig_file_ops);
73092+#endif
73093+#else
73094 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73095 &ikconfig_file_ops);
73096+#endif
73097+
73098 if (!entry)
73099 return -ENOMEM;
73100
73101diff --git a/kernel/cred.c b/kernel/cred.c
73102index e0573a4..3874e41 100644
73103--- a/kernel/cred.c
73104+++ b/kernel/cred.c
73105@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73106 validate_creds(cred);
73107 alter_cred_subscribers(cred, -1);
73108 put_cred(cred);
73109+
73110+#ifdef CONFIG_GRKERNSEC_SETXID
73111+ cred = (struct cred *) tsk->delayed_cred;
73112+ if (cred != NULL) {
73113+ tsk->delayed_cred = NULL;
73114+ validate_creds(cred);
73115+ alter_cred_subscribers(cred, -1);
73116+ put_cred(cred);
73117+ }
73118+#endif
73119 }
73120
73121 /**
73122@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73123 * Always returns 0 thus allowing this function to be tail-called at the end
73124 * of, say, sys_setgid().
73125 */
73126-int commit_creds(struct cred *new)
73127+static int __commit_creds(struct cred *new)
73128 {
73129 struct task_struct *task = current;
73130 const struct cred *old = task->real_cred;
73131@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73132
73133 get_cred(new); /* we will require a ref for the subj creds too */
73134
73135+ gr_set_role_label(task, new->uid, new->gid);
73136+
73137 /* dumpability changes */
73138 if (!uid_eq(old->euid, new->euid) ||
73139 !gid_eq(old->egid, new->egid) ||
73140@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73141 put_cred(old);
73142 return 0;
73143 }
73144+#ifdef CONFIG_GRKERNSEC_SETXID
73145+extern int set_user(struct cred *new);
73146+
73147+void gr_delayed_cred_worker(void)
73148+{
73149+ const struct cred *new = current->delayed_cred;
73150+ struct cred *ncred;
73151+
73152+ current->delayed_cred = NULL;
73153+
73154+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73155+ // from doing get_cred on it when queueing this
73156+ put_cred(new);
73157+ return;
73158+ } else if (new == NULL)
73159+ return;
73160+
73161+ ncred = prepare_creds();
73162+ if (!ncred)
73163+ goto die;
73164+ // uids
73165+ ncred->uid = new->uid;
73166+ ncred->euid = new->euid;
73167+ ncred->suid = new->suid;
73168+ ncred->fsuid = new->fsuid;
73169+ // gids
73170+ ncred->gid = new->gid;
73171+ ncred->egid = new->egid;
73172+ ncred->sgid = new->sgid;
73173+ ncred->fsgid = new->fsgid;
73174+ // groups
73175+ if (set_groups(ncred, new->group_info) < 0) {
73176+ abort_creds(ncred);
73177+ goto die;
73178+ }
73179+ // caps
73180+ ncred->securebits = new->securebits;
73181+ ncred->cap_inheritable = new->cap_inheritable;
73182+ ncred->cap_permitted = new->cap_permitted;
73183+ ncred->cap_effective = new->cap_effective;
73184+ ncred->cap_bset = new->cap_bset;
73185+
73186+ if (set_user(ncred)) {
73187+ abort_creds(ncred);
73188+ goto die;
73189+ }
73190+
73191+ // from doing get_cred on it when queueing this
73192+ put_cred(new);
73193+
73194+ __commit_creds(ncred);
73195+ return;
73196+die:
73197+ // from doing get_cred on it when queueing this
73198+ put_cred(new);
73199+ do_group_exit(SIGKILL);
73200+}
73201+#endif
73202+
73203+int commit_creds(struct cred *new)
73204+{
73205+#ifdef CONFIG_GRKERNSEC_SETXID
73206+ int ret;
73207+ int schedule_it = 0;
73208+ struct task_struct *t;
73209+
73210+ /* we won't get called with tasklist_lock held for writing
73211+ and interrupts disabled as the cred struct in that case is
73212+ init_cred
73213+ */
73214+ if (grsec_enable_setxid && !current_is_single_threaded() &&
73215+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73216+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73217+ schedule_it = 1;
73218+ }
73219+ ret = __commit_creds(new);
73220+ if (schedule_it) {
73221+ rcu_read_lock();
73222+ read_lock(&tasklist_lock);
73223+ for (t = next_thread(current); t != current;
73224+ t = next_thread(t)) {
73225+ if (t->delayed_cred == NULL) {
73226+ t->delayed_cred = get_cred(new);
73227+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73228+ set_tsk_need_resched(t);
73229+ }
73230+ }
73231+ read_unlock(&tasklist_lock);
73232+ rcu_read_unlock();
73233+ }
73234+ return ret;
73235+#else
73236+ return __commit_creds(new);
73237+#endif
73238+}
73239+
73240 EXPORT_SYMBOL(commit_creds);
73241
73242 /**
73243diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73244index 9a61738..c5c8f3a 100644
73245--- a/kernel/debug/debug_core.c
73246+++ b/kernel/debug/debug_core.c
73247@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73248 */
73249 static atomic_t masters_in_kgdb;
73250 static atomic_t slaves_in_kgdb;
73251-static atomic_t kgdb_break_tasklet_var;
73252+static atomic_unchecked_t kgdb_break_tasklet_var;
73253 atomic_t kgdb_setting_breakpoint;
73254
73255 struct task_struct *kgdb_usethread;
73256@@ -132,7 +132,7 @@ int kgdb_single_step;
73257 static pid_t kgdb_sstep_pid;
73258
73259 /* to keep track of the CPU which is doing the single stepping*/
73260-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73261+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73262
73263 /*
73264 * If you are debugging a problem where roundup (the collection of
73265@@ -540,7 +540,7 @@ return_normal:
73266 * kernel will only try for the value of sstep_tries before
73267 * giving up and continuing on.
73268 */
73269- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73270+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73271 (kgdb_info[cpu].task &&
73272 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73273 atomic_set(&kgdb_active, -1);
73274@@ -634,8 +634,8 @@ cpu_master_loop:
73275 }
73276
73277 kgdb_restore:
73278- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73279- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73280+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73281+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73282 if (kgdb_info[sstep_cpu].task)
73283 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73284 else
73285@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73286 static void kgdb_tasklet_bpt(unsigned long ing)
73287 {
73288 kgdb_breakpoint();
73289- atomic_set(&kgdb_break_tasklet_var, 0);
73290+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73291 }
73292
73293 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73294
73295 void kgdb_schedule_breakpoint(void)
73296 {
73297- if (atomic_read(&kgdb_break_tasklet_var) ||
73298+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73299 atomic_read(&kgdb_active) != -1 ||
73300 atomic_read(&kgdb_setting_breakpoint))
73301 return;
73302- atomic_inc(&kgdb_break_tasklet_var);
73303+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
73304 tasklet_schedule(&kgdb_tasklet_breakpoint);
73305 }
73306 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73307diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73308index 8875254..7cf4928 100644
73309--- a/kernel/debug/kdb/kdb_main.c
73310+++ b/kernel/debug/kdb/kdb_main.c
73311@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73312 continue;
73313
73314 kdb_printf("%-20s%8u 0x%p ", mod->name,
73315- mod->core_size, (void *)mod);
73316+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
73317 #ifdef CONFIG_MODULE_UNLOAD
73318 kdb_printf("%4ld ", module_refcount(mod));
73319 #endif
73320@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73321 kdb_printf(" (Loading)");
73322 else
73323 kdb_printf(" (Live)");
73324- kdb_printf(" 0x%p", mod->module_core);
73325+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73326
73327 #ifdef CONFIG_MODULE_UNLOAD
73328 {
73329diff --git a/kernel/events/core.c b/kernel/events/core.c
73330index 7b6646a..3cb1135 100644
73331--- a/kernel/events/core.c
73332+++ b/kernel/events/core.c
73333@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
73334 return 0;
73335 }
73336
73337-static atomic64_t perf_event_id;
73338+static atomic64_unchecked_t perf_event_id;
73339
73340 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
73341 enum event_type_t event_type);
73342@@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
73343
73344 static inline u64 perf_event_count(struct perf_event *event)
73345 {
73346- return local64_read(&event->count) + atomic64_read(&event->child_count);
73347+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
73348 }
73349
73350 static u64 perf_event_read(struct perf_event *event)
73351@@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
73352 mutex_lock(&event->child_mutex);
73353 total += perf_event_read(event);
73354 *enabled += event->total_time_enabled +
73355- atomic64_read(&event->child_total_time_enabled);
73356+ atomic64_read_unchecked(&event->child_total_time_enabled);
73357 *running += event->total_time_running +
73358- atomic64_read(&event->child_total_time_running);
73359+ atomic64_read_unchecked(&event->child_total_time_running);
73360
73361 list_for_each_entry(child, &event->child_list, child_list) {
73362 total += perf_event_read(child);
73363@@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
73364 userpg->offset -= local64_read(&event->hw.prev_count);
73365
73366 userpg->time_enabled = enabled +
73367- atomic64_read(&event->child_total_time_enabled);
73368+ atomic64_read_unchecked(&event->child_total_time_enabled);
73369
73370 userpg->time_running = running +
73371- atomic64_read(&event->child_total_time_running);
73372+ atomic64_read_unchecked(&event->child_total_time_running);
73373
73374 arch_perf_update_userpage(userpg, now);
73375
73376@@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73377 values[n++] = perf_event_count(event);
73378 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73379 values[n++] = enabled +
73380- atomic64_read(&event->child_total_time_enabled);
73381+ atomic64_read_unchecked(&event->child_total_time_enabled);
73382 }
73383 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73384 values[n++] = running +
73385- atomic64_read(&event->child_total_time_running);
73386+ atomic64_read_unchecked(&event->child_total_time_running);
73387 }
73388 if (read_format & PERF_FORMAT_ID)
73389 values[n++] = primary_event_id(event);
73390@@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73391 * need to add enough zero bytes after the string to handle
73392 * the 64bit alignment we do later.
73393 */
73394- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73395+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
73396 if (!buf) {
73397 name = strncpy(tmp, "//enomem", sizeof(tmp));
73398 goto got_name;
73399 }
73400- name = d_path(&file->f_path, buf, PATH_MAX);
73401+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73402 if (IS_ERR(name)) {
73403 name = strncpy(tmp, "//toolong", sizeof(tmp));
73404 goto got_name;
73405@@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
73406 event->parent = parent_event;
73407
73408 event->ns = get_pid_ns(task_active_pid_ns(current));
73409- event->id = atomic64_inc_return(&perf_event_id);
73410+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
73411
73412 event->state = PERF_EVENT_STATE_INACTIVE;
73413
73414@@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
73415 /*
73416 * Add back the child's count to the parent's count:
73417 */
73418- atomic64_add(child_val, &parent_event->child_count);
73419- atomic64_add(child_event->total_time_enabled,
73420+ atomic64_add_unchecked(child_val, &parent_event->child_count);
73421+ atomic64_add_unchecked(child_event->total_time_enabled,
73422 &parent_event->child_total_time_enabled);
73423- atomic64_add(child_event->total_time_running,
73424+ atomic64_add_unchecked(child_event->total_time_running,
73425 &parent_event->child_total_time_running);
73426
73427 /*
73428diff --git a/kernel/exit.c b/kernel/exit.c
73429index b4df219..f13c02d 100644
73430--- a/kernel/exit.c
73431+++ b/kernel/exit.c
73432@@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
73433 struct task_struct *leader;
73434 int zap_leader;
73435 repeat:
73436+#ifdef CONFIG_NET
73437+ gr_del_task_from_ip_table(p);
73438+#endif
73439+
73440 /* don't need to get the RCU readlock here - the process is dead and
73441 * can't be modifying its own credentials. But shut RCU-lockdep up */
73442 rcu_read_lock();
73443@@ -338,7 +342,7 @@ int allow_signal(int sig)
73444 * know it'll be handled, so that they don't get converted to
73445 * SIGKILL or just silently dropped.
73446 */
73447- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
73448+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
73449 recalc_sigpending();
73450 spin_unlock_irq(&current->sighand->siglock);
73451 return 0;
73452@@ -708,6 +712,8 @@ void do_exit(long code)
73453 struct task_struct *tsk = current;
73454 int group_dead;
73455
73456+ set_fs(USER_DS);
73457+
73458 profile_task_exit(tsk);
73459
73460 WARN_ON(blk_needs_flush_plug(tsk));
73461@@ -724,7 +730,6 @@ void do_exit(long code)
73462 * mm_release()->clear_child_tid() from writing to a user-controlled
73463 * kernel address.
73464 */
73465- set_fs(USER_DS);
73466
73467 ptrace_event(PTRACE_EVENT_EXIT, code);
73468
73469@@ -783,6 +788,9 @@ void do_exit(long code)
73470 tsk->exit_code = code;
73471 taskstats_exit(tsk, group_dead);
73472
73473+ gr_acl_handle_psacct(tsk, code);
73474+ gr_acl_handle_exit();
73475+
73476 exit_mm(tsk);
73477
73478 if (group_dead)
73479@@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
73480 * Take down every thread in the group. This is called by fatal signals
73481 * as well as by sys_exit_group (below).
73482 */
73483-void
73484+__noreturn void
73485 do_group_exit(int exit_code)
73486 {
73487 struct signal_struct *sig = current->signal;
73488diff --git a/kernel/fork.c b/kernel/fork.c
73489index c535f33..1d768f9 100644
73490--- a/kernel/fork.c
73491+++ b/kernel/fork.c
73492@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
73493 *stackend = STACK_END_MAGIC; /* for overflow detection */
73494
73495 #ifdef CONFIG_CC_STACKPROTECTOR
73496- tsk->stack_canary = get_random_int();
73497+ tsk->stack_canary = pax_get_random_long();
73498 #endif
73499
73500 /*
73501@@ -344,13 +344,81 @@ free_tsk:
73502 }
73503
73504 #ifdef CONFIG_MMU
73505+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
73506+{
73507+ struct vm_area_struct *tmp;
73508+ unsigned long charge;
73509+ struct mempolicy *pol;
73510+ struct file *file;
73511+
73512+ charge = 0;
73513+ if (mpnt->vm_flags & VM_ACCOUNT) {
73514+ unsigned long len = vma_pages(mpnt);
73515+
73516+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73517+ goto fail_nomem;
73518+ charge = len;
73519+ }
73520+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73521+ if (!tmp)
73522+ goto fail_nomem;
73523+ *tmp = *mpnt;
73524+ tmp->vm_mm = mm;
73525+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
73526+ pol = mpol_dup(vma_policy(mpnt));
73527+ if (IS_ERR(pol))
73528+ goto fail_nomem_policy;
73529+ vma_set_policy(tmp, pol);
73530+ if (anon_vma_fork(tmp, mpnt))
73531+ goto fail_nomem_anon_vma_fork;
73532+ tmp->vm_flags &= ~VM_LOCKED;
73533+ tmp->vm_next = tmp->vm_prev = NULL;
73534+ tmp->vm_mirror = NULL;
73535+ file = tmp->vm_file;
73536+ if (file) {
73537+ struct inode *inode = file->f_path.dentry->d_inode;
73538+ struct address_space *mapping = file->f_mapping;
73539+
73540+ get_file(file);
73541+ if (tmp->vm_flags & VM_DENYWRITE)
73542+ atomic_dec(&inode->i_writecount);
73543+ mutex_lock(&mapping->i_mmap_mutex);
73544+ if (tmp->vm_flags & VM_SHARED)
73545+ mapping->i_mmap_writable++;
73546+ flush_dcache_mmap_lock(mapping);
73547+ /* insert tmp into the share list, just after mpnt */
73548+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73549+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
73550+ else
73551+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
73552+ flush_dcache_mmap_unlock(mapping);
73553+ mutex_unlock(&mapping->i_mmap_mutex);
73554+ }
73555+
73556+ /*
73557+ * Clear hugetlb-related page reserves for children. This only
73558+ * affects MAP_PRIVATE mappings. Faults generated by the child
73559+ * are not guaranteed to succeed, even if read-only
73560+ */
73561+ if (is_vm_hugetlb_page(tmp))
73562+ reset_vma_resv_huge_pages(tmp);
73563+
73564+ return tmp;
73565+
73566+fail_nomem_anon_vma_fork:
73567+ mpol_put(pol);
73568+fail_nomem_policy:
73569+ kmem_cache_free(vm_area_cachep, tmp);
73570+fail_nomem:
73571+ vm_unacct_memory(charge);
73572+ return NULL;
73573+}
73574+
73575 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73576 {
73577 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
73578 struct rb_node **rb_link, *rb_parent;
73579 int retval;
73580- unsigned long charge;
73581- struct mempolicy *pol;
73582
73583 uprobe_start_dup_mmap();
73584 down_write(&oldmm->mmap_sem);
73585@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73586 mm->locked_vm = 0;
73587 mm->mmap = NULL;
73588 mm->mmap_cache = NULL;
73589- mm->free_area_cache = oldmm->mmap_base;
73590- mm->cached_hole_size = ~0UL;
73591+ mm->free_area_cache = oldmm->free_area_cache;
73592+ mm->cached_hole_size = oldmm->cached_hole_size;
73593 mm->map_count = 0;
73594 cpumask_clear(mm_cpumask(mm));
73595 mm->mm_rb = RB_ROOT;
73596@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73597
73598 prev = NULL;
73599 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
73600- struct file *file;
73601-
73602 if (mpnt->vm_flags & VM_DONTCOPY) {
73603 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
73604 -vma_pages(mpnt));
73605 continue;
73606 }
73607- charge = 0;
73608- if (mpnt->vm_flags & VM_ACCOUNT) {
73609- unsigned long len = vma_pages(mpnt);
73610-
73611- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73612- goto fail_nomem;
73613- charge = len;
73614- }
73615- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73616- if (!tmp)
73617- goto fail_nomem;
73618- *tmp = *mpnt;
73619- INIT_LIST_HEAD(&tmp->anon_vma_chain);
73620- pol = mpol_dup(vma_policy(mpnt));
73621- retval = PTR_ERR(pol);
73622- if (IS_ERR(pol))
73623- goto fail_nomem_policy;
73624- vma_set_policy(tmp, pol);
73625- tmp->vm_mm = mm;
73626- if (anon_vma_fork(tmp, mpnt))
73627- goto fail_nomem_anon_vma_fork;
73628- tmp->vm_flags &= ~VM_LOCKED;
73629- tmp->vm_next = tmp->vm_prev = NULL;
73630- file = tmp->vm_file;
73631- if (file) {
73632- struct inode *inode = file->f_path.dentry->d_inode;
73633- struct address_space *mapping = file->f_mapping;
73634-
73635- get_file(file);
73636- if (tmp->vm_flags & VM_DENYWRITE)
73637- atomic_dec(&inode->i_writecount);
73638- mutex_lock(&mapping->i_mmap_mutex);
73639- if (tmp->vm_flags & VM_SHARED)
73640- mapping->i_mmap_writable++;
73641- flush_dcache_mmap_lock(mapping);
73642- /* insert tmp into the share list, just after mpnt */
73643- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73644- vma_nonlinear_insert(tmp,
73645- &mapping->i_mmap_nonlinear);
73646- else
73647- vma_interval_tree_insert_after(tmp, mpnt,
73648- &mapping->i_mmap);
73649- flush_dcache_mmap_unlock(mapping);
73650- mutex_unlock(&mapping->i_mmap_mutex);
73651+ tmp = dup_vma(mm, oldmm, mpnt);
73652+ if (!tmp) {
73653+ retval = -ENOMEM;
73654+ goto out;
73655 }
73656
73657 /*
73658@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73659 if (retval)
73660 goto out;
73661 }
73662+
73663+#ifdef CONFIG_PAX_SEGMEXEC
73664+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
73665+ struct vm_area_struct *mpnt_m;
73666+
73667+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
73668+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
73669+
73670+ if (!mpnt->vm_mirror)
73671+ continue;
73672+
73673+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
73674+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
73675+ mpnt->vm_mirror = mpnt_m;
73676+ } else {
73677+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
73678+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
73679+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
73680+ mpnt->vm_mirror->vm_mirror = mpnt;
73681+ }
73682+ }
73683+ BUG_ON(mpnt_m);
73684+ }
73685+#endif
73686+
73687 /* a new mm has just been created */
73688 arch_dup_mmap(oldmm, mm);
73689 retval = 0;
73690@@ -472,14 +523,6 @@ out:
73691 up_write(&oldmm->mmap_sem);
73692 uprobe_end_dup_mmap();
73693 return retval;
73694-fail_nomem_anon_vma_fork:
73695- mpol_put(pol);
73696-fail_nomem_policy:
73697- kmem_cache_free(vm_area_cachep, tmp);
73698-fail_nomem:
73699- retval = -ENOMEM;
73700- vm_unacct_memory(charge);
73701- goto out;
73702 }
73703
73704 static inline int mm_alloc_pgd(struct mm_struct *mm)
73705@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
73706 return ERR_PTR(err);
73707
73708 mm = get_task_mm(task);
73709- if (mm && mm != current->mm &&
73710- !ptrace_may_access(task, mode)) {
73711+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
73712+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
73713 mmput(mm);
73714 mm = ERR_PTR(-EACCES);
73715 }
73716@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
73717 spin_unlock(&fs->lock);
73718 return -EAGAIN;
73719 }
73720- fs->users++;
73721+ atomic_inc(&fs->users);
73722 spin_unlock(&fs->lock);
73723 return 0;
73724 }
73725 tsk->fs = copy_fs_struct(fs);
73726 if (!tsk->fs)
73727 return -ENOMEM;
73728+ /* Carry through gr_chroot_dentry and is_chrooted instead
73729+ of recomputing it here. Already copied when the task struct
73730+ is duplicated. This allows pivot_root to not be treated as
73731+ a chroot
73732+ */
73733+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
73734+
73735 return 0;
73736 }
73737
73738@@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73739 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
73740 #endif
73741 retval = -EAGAIN;
73742+
73743+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
73744+
73745 if (atomic_read(&p->real_cred->user->processes) >=
73746 task_rlimit(p, RLIMIT_NPROC)) {
73747 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
73748@@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73749 goto bad_fork_free_pid;
73750 }
73751
73752+ /* synchronizes with gr_set_acls()
73753+ we need to call this past the point of no return for fork()
73754+ */
73755+ gr_copy_label(p);
73756+
73757 if (clone_flags & CLONE_THREAD) {
73758 current->signal->nr_threads++;
73759 atomic_inc(&current->signal->live);
73760@@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
73761 bad_fork_free:
73762 free_task(p);
73763 fork_out:
73764+ gr_log_forkfail(retval);
73765+
73766 return ERR_PTR(retval);
73767 }
73768
73769@@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
73770 return -EINVAL;
73771 }
73772
73773+#ifdef CONFIG_GRKERNSEC
73774+ if (clone_flags & CLONE_NEWUSER) {
73775+ /*
73776+ * This doesn't really inspire confidence:
73777+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
73778+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
73779+ * Increases kernel attack surface in areas developers
73780+ * previously cared little about ("low importance due
73781+ * to requiring "root" capability")
73782+ * To be removed when this code receives *proper* review
73783+ */
73784+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
73785+ !capable(CAP_SETGID))
73786+ return -EPERM;
73787+ }
73788+#endif
73789+
73790 /*
73791 * Determine whether and which event to report to ptracer. When
73792 * called from kernel_thread or CLONE_UNTRACED is explicitly
73793@@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
73794 if (clone_flags & CLONE_PARENT_SETTID)
73795 put_user(nr, parent_tidptr);
73796
73797+ gr_handle_brute_check();
73798+
73799 if (clone_flags & CLONE_VFORK) {
73800 p->vfork_done = &vfork;
73801 init_completion(&vfork);
73802@@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
73803 return 0;
73804
73805 /* don't need lock here; in the worst case we'll do useless copy */
73806- if (fs->users == 1)
73807+ if (atomic_read(&fs->users) == 1)
73808 return 0;
73809
73810 *new_fsp = copy_fs_struct(fs);
73811@@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
73812 fs = current->fs;
73813 spin_lock(&fs->lock);
73814 current->fs = new_fs;
73815- if (--fs->users)
73816+ gr_set_chroot_entries(current, &current->fs->root);
73817+ if (atomic_dec_return(&fs->users))
73818 new_fs = NULL;
73819 else
73820 new_fs = fs;
73821diff --git a/kernel/futex.c b/kernel/futex.c
73822index 8879430..31696f1 100644
73823--- a/kernel/futex.c
73824+++ b/kernel/futex.c
73825@@ -54,6 +54,7 @@
73826 #include <linux/mount.h>
73827 #include <linux/pagemap.h>
73828 #include <linux/syscalls.h>
73829+#include <linux/ptrace.h>
73830 #include <linux/signal.h>
73831 #include <linux/export.h>
73832 #include <linux/magic.h>
73833@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
73834 struct page *page, *page_head;
73835 int err, ro = 0;
73836
73837+#ifdef CONFIG_PAX_SEGMEXEC
73838+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
73839+ return -EFAULT;
73840+#endif
73841+
73842 /*
73843 * The futex address must be "naturally" aligned.
73844 */
73845@@ -2731,6 +2737,7 @@ static int __init futex_init(void)
73846 {
73847 u32 curval;
73848 int i;
73849+ mm_segment_t oldfs;
73850
73851 /*
73852 * This will fail and we want it. Some arch implementations do
73853@@ -2742,8 +2749,11 @@ static int __init futex_init(void)
73854 * implementation, the non-functional ones will return
73855 * -ENOSYS.
73856 */
73857+ oldfs = get_fs();
73858+ set_fs(USER_DS);
73859 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
73860 futex_cmpxchg_enabled = 1;
73861+ set_fs(oldfs);
73862
73863 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
73864 plist_head_init(&futex_queues[i].chain);
73865diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
73866index 9b22d03..6295b62 100644
73867--- a/kernel/gcov/base.c
73868+++ b/kernel/gcov/base.c
73869@@ -102,11 +102,6 @@ void gcov_enable_events(void)
73870 }
73871
73872 #ifdef CONFIG_MODULES
73873-static inline int within(void *addr, void *start, unsigned long size)
73874-{
73875- return ((addr >= start) && (addr < start + size));
73876-}
73877-
73878 /* Update list and generate events when modules are unloaded. */
73879 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73880 void *data)
73881@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73882 prev = NULL;
73883 /* Remove entries located in module from linked list. */
73884 for (info = gcov_info_head; info; info = info->next) {
73885- if (within(info, mod->module_core, mod->core_size)) {
73886+ if (within_module_core_rw((unsigned long)info, mod)) {
73887 if (prev)
73888 prev->next = info->next;
73889 else
73890diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
73891index cdd5607..c3fc919 100644
73892--- a/kernel/hrtimer.c
73893+++ b/kernel/hrtimer.c
73894@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
73895 local_irq_restore(flags);
73896 }
73897
73898-static void run_hrtimer_softirq(struct softirq_action *h)
73899+static void run_hrtimer_softirq(void)
73900 {
73901 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
73902
73903@@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
73904 return NOTIFY_OK;
73905 }
73906
73907-static struct notifier_block __cpuinitdata hrtimers_nb = {
73908+static struct notifier_block hrtimers_nb = {
73909 .notifier_call = hrtimer_cpu_notify,
73910 };
73911
73912diff --git a/kernel/jump_label.c b/kernel/jump_label.c
73913index 60f48fa..7f3a770 100644
73914--- a/kernel/jump_label.c
73915+++ b/kernel/jump_label.c
73916@@ -13,6 +13,7 @@
73917 #include <linux/sort.h>
73918 #include <linux/err.h>
73919 #include <linux/static_key.h>
73920+#include <linux/mm.h>
73921
73922 #ifdef HAVE_JUMP_LABEL
73923
73924@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
73925
73926 size = (((unsigned long)stop - (unsigned long)start)
73927 / sizeof(struct jump_entry));
73928+ pax_open_kernel();
73929 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
73930+ pax_close_kernel();
73931 }
73932
73933 static void jump_label_update(struct static_key *key, int enable);
73934@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
73935 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
73936 struct jump_entry *iter;
73937
73938+ pax_open_kernel();
73939 for (iter = iter_start; iter < iter_stop; iter++) {
73940 if (within_module_init(iter->code, mod))
73941 iter->code = 0;
73942 }
73943+ pax_close_kernel();
73944 }
73945
73946 static int
73947diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
73948index 2169fee..706ccca 100644
73949--- a/kernel/kallsyms.c
73950+++ b/kernel/kallsyms.c
73951@@ -11,6 +11,9 @@
73952 * Changed the compression method from stem compression to "table lookup"
73953 * compression (see scripts/kallsyms.c for a more complete description)
73954 */
73955+#ifdef CONFIG_GRKERNSEC_HIDESYM
73956+#define __INCLUDED_BY_HIDESYM 1
73957+#endif
73958 #include <linux/kallsyms.h>
73959 #include <linux/module.h>
73960 #include <linux/init.h>
73961@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
73962
73963 static inline int is_kernel_inittext(unsigned long addr)
73964 {
73965+ if (system_state != SYSTEM_BOOTING)
73966+ return 0;
73967+
73968 if (addr >= (unsigned long)_sinittext
73969 && addr <= (unsigned long)_einittext)
73970 return 1;
73971 return 0;
73972 }
73973
73974+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73975+#ifdef CONFIG_MODULES
73976+static inline int is_module_text(unsigned long addr)
73977+{
73978+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
73979+ return 1;
73980+
73981+ addr = ktla_ktva(addr);
73982+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
73983+}
73984+#else
73985+static inline int is_module_text(unsigned long addr)
73986+{
73987+ return 0;
73988+}
73989+#endif
73990+#endif
73991+
73992 static inline int is_kernel_text(unsigned long addr)
73993 {
73994 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
73995@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
73996
73997 static inline int is_kernel(unsigned long addr)
73998 {
73999+
74000+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74001+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
74002+ return 1;
74003+
74004+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74005+#else
74006 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74007+#endif
74008+
74009 return 1;
74010 return in_gate_area_no_mm(addr);
74011 }
74012
74013 static int is_ksym_addr(unsigned long addr)
74014 {
74015+
74016+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74017+ if (is_module_text(addr))
74018+ return 0;
74019+#endif
74020+
74021 if (all_var)
74022 return is_kernel(addr);
74023
74024@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74025
74026 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74027 {
74028- iter->name[0] = '\0';
74029 iter->nameoff = get_symbol_offset(new_pos);
74030 iter->pos = new_pos;
74031 }
74032@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74033 {
74034 struct kallsym_iter *iter = m->private;
74035
74036+#ifdef CONFIG_GRKERNSEC_HIDESYM
74037+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74038+ return 0;
74039+#endif
74040+
74041 /* Some debugging symbols have no name. Ignore them. */
74042 if (!iter->name[0])
74043 return 0;
74044@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74045 */
74046 type = iter->exported ? toupper(iter->type) :
74047 tolower(iter->type);
74048+
74049 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74050 type, iter->name, iter->module_name);
74051 } else
74052@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74053 struct kallsym_iter *iter;
74054 int ret;
74055
74056- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74057+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74058 if (!iter)
74059 return -ENOMEM;
74060 reset_iter(iter, 0);
74061diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74062index e30ac0f..3528cac 100644
74063--- a/kernel/kcmp.c
74064+++ b/kernel/kcmp.c
74065@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74066 struct task_struct *task1, *task2;
74067 int ret;
74068
74069+#ifdef CONFIG_GRKERNSEC
74070+ return -ENOSYS;
74071+#endif
74072+
74073 rcu_read_lock();
74074
74075 /*
74076diff --git a/kernel/kexec.c b/kernel/kexec.c
74077index 5e4bd78..00c5b91 100644
74078--- a/kernel/kexec.c
74079+++ b/kernel/kexec.c
74080@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74081 unsigned long flags)
74082 {
74083 struct compat_kexec_segment in;
74084- struct kexec_segment out, __user *ksegments;
74085+ struct kexec_segment out;
74086+ struct kexec_segment __user *ksegments;
74087 unsigned long i, result;
74088
74089 /* Don't allow clients that don't understand the native
74090diff --git a/kernel/kmod.c b/kernel/kmod.c
74091index 0023a87..9c0c068 100644
74092--- a/kernel/kmod.c
74093+++ b/kernel/kmod.c
74094@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74095 kfree(info->argv);
74096 }
74097
74098-static int call_modprobe(char *module_name, int wait)
74099+static int call_modprobe(char *module_name, char *module_param, int wait)
74100 {
74101 static char *envp[] = {
74102 "HOME=/",
74103@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74104 NULL
74105 };
74106
74107- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74108+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74109 if (!argv)
74110 goto out;
74111
74112@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74113 argv[1] = "-q";
74114 argv[2] = "--";
74115 argv[3] = module_name; /* check free_modprobe_argv() */
74116- argv[4] = NULL;
74117+ argv[4] = module_param;
74118+ argv[5] = NULL;
74119
74120 return call_usermodehelper_fns(modprobe_path, argv, envp,
74121 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74122@@ -120,9 +121,8 @@ out:
74123 * If module auto-loading support is disabled then this function
74124 * becomes a no-operation.
74125 */
74126-int __request_module(bool wait, const char *fmt, ...)
74127+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74128 {
74129- va_list args;
74130 char module_name[MODULE_NAME_LEN];
74131 unsigned int max_modprobes;
74132 int ret;
74133@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74134 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74135 static int kmod_loop_msg;
74136
74137- va_start(args, fmt);
74138- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74139- va_end(args);
74140+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74141 if (ret >= MODULE_NAME_LEN)
74142 return -ENAMETOOLONG;
74143
74144@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74145 if (ret)
74146 return ret;
74147
74148+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74149+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74150+ /* hack to workaround consolekit/udisks stupidity */
74151+ read_lock(&tasklist_lock);
74152+ if (!strcmp(current->comm, "mount") &&
74153+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74154+ read_unlock(&tasklist_lock);
74155+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74156+ return -EPERM;
74157+ }
74158+ read_unlock(&tasklist_lock);
74159+ }
74160+#endif
74161+
74162 /* If modprobe needs a service that is in a module, we get a recursive
74163 * loop. Limit the number of running kmod threads to max_threads/2 or
74164 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74165@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74166
74167 trace_module_request(module_name, wait, _RET_IP_);
74168
74169- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74170+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74171
74172 atomic_dec(&kmod_concurrent);
74173 return ret;
74174 }
74175+
74176+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74177+{
74178+ va_list args;
74179+ int ret;
74180+
74181+ va_start(args, fmt);
74182+ ret = ____request_module(wait, module_param, fmt, args);
74183+ va_end(args);
74184+
74185+ return ret;
74186+}
74187+
74188+int __request_module(bool wait, const char *fmt, ...)
74189+{
74190+ va_list args;
74191+ int ret;
74192+
74193+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74194+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74195+ char module_param[MODULE_NAME_LEN];
74196+
74197+ memset(module_param, 0, sizeof(module_param));
74198+
74199+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74200+
74201+ va_start(args, fmt);
74202+ ret = ____request_module(wait, module_param, fmt, args);
74203+ va_end(args);
74204+
74205+ return ret;
74206+ }
74207+#endif
74208+
74209+ va_start(args, fmt);
74210+ ret = ____request_module(wait, NULL, fmt, args);
74211+ va_end(args);
74212+
74213+ return ret;
74214+}
74215+
74216 EXPORT_SYMBOL(__request_module);
74217 #endif /* CONFIG_MODULES */
74218
74219@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74220 *
74221 * Thus the __user pointer cast is valid here.
74222 */
74223- sys_wait4(pid, (int __user *)&ret, 0, NULL);
74224+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74225
74226 /*
74227 * If ret is 0, either ____call_usermodehelper failed and the
74228@@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74229 static int proc_cap_handler(struct ctl_table *table, int write,
74230 void __user *buffer, size_t *lenp, loff_t *ppos)
74231 {
74232- struct ctl_table t;
74233+ ctl_table_no_const t;
74234 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74235 kernel_cap_t new_cap;
74236 int err, i;
74237diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74238index 098f396..fe85ff1 100644
74239--- a/kernel/kprobes.c
74240+++ b/kernel/kprobes.c
74241@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74242 * kernel image and loaded module images reside. This is required
74243 * so x86_64 can correctly handle the %rip-relative fixups.
74244 */
74245- kip->insns = module_alloc(PAGE_SIZE);
74246+ kip->insns = module_alloc_exec(PAGE_SIZE);
74247 if (!kip->insns) {
74248 kfree(kip);
74249 return NULL;
74250@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74251 */
74252 if (!list_is_singular(&kip->list)) {
74253 list_del(&kip->list);
74254- module_free(NULL, kip->insns);
74255+ module_free_exec(NULL, kip->insns);
74256 kfree(kip);
74257 }
74258 return 1;
74259@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74260 {
74261 int i, err = 0;
74262 unsigned long offset = 0, size = 0;
74263- char *modname, namebuf[128];
74264+ char *modname, namebuf[KSYM_NAME_LEN];
74265 const char *symbol_name;
74266 void *addr;
74267 struct kprobe_blackpoint *kb;
74268@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74269 kprobe_type = "k";
74270
74271 if (sym)
74272- seq_printf(pi, "%p %s %s+0x%x %s ",
74273+ seq_printf(pi, "%pK %s %s+0x%x %s ",
74274 p->addr, kprobe_type, sym, offset,
74275 (modname ? modname : " "));
74276 else
74277- seq_printf(pi, "%p %s %p ",
74278+ seq_printf(pi, "%pK %s %pK ",
74279 p->addr, kprobe_type, p->addr);
74280
74281 if (!pp)
74282@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74283 const char *sym = NULL;
74284 unsigned int i = *(loff_t *) v;
74285 unsigned long offset = 0;
74286- char *modname, namebuf[128];
74287+ char *modname, namebuf[KSYM_NAME_LEN];
74288
74289 head = &kprobe_table[i];
74290 preempt_disable();
74291diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74292index 6ada93c..dce7d5d 100644
74293--- a/kernel/ksysfs.c
74294+++ b/kernel/ksysfs.c
74295@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74296 {
74297 if (count+1 > UEVENT_HELPER_PATH_LEN)
74298 return -ENOENT;
74299+ if (!capable(CAP_SYS_ADMIN))
74300+ return -EPERM;
74301 memcpy(uevent_helper, buf, count);
74302 uevent_helper[count] = '\0';
74303 if (count && uevent_helper[count-1] == '\n')
74304@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74305 return count;
74306 }
74307
74308-static struct bin_attribute notes_attr = {
74309+static bin_attribute_no_const notes_attr __read_only = {
74310 .attr = {
74311 .name = "notes",
74312 .mode = S_IRUGO,
74313diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74314index 7981e5b..7f2105c 100644
74315--- a/kernel/lockdep.c
74316+++ b/kernel/lockdep.c
74317@@ -590,6 +590,10 @@ static int static_obj(void *obj)
74318 end = (unsigned long) &_end,
74319 addr = (unsigned long) obj;
74320
74321+#ifdef CONFIG_PAX_KERNEXEC
74322+ start = ktla_ktva(start);
74323+#endif
74324+
74325 /*
74326 * static variable?
74327 */
74328@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74329 if (!static_obj(lock->key)) {
74330 debug_locks_off();
74331 printk("INFO: trying to register non-static key.\n");
74332+ printk("lock:%pS key:%pS.\n", lock, lock->key);
74333 printk("the code is fine but needs lockdep annotation.\n");
74334 printk("turning off the locking correctness validator.\n");
74335 dump_stack();
74336@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
74337 if (!class)
74338 return 0;
74339 }
74340- atomic_inc((atomic_t *)&class->ops);
74341+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
74342 if (very_verbose(class)) {
74343 printk("\nacquire class [%p] %s", class->key, class->name);
74344 if (class->name_version > 1)
74345diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
74346index b2c71c5..7b88d63 100644
74347--- a/kernel/lockdep_proc.c
74348+++ b/kernel/lockdep_proc.c
74349@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
74350 return 0;
74351 }
74352
74353- seq_printf(m, "%p", class->key);
74354+ seq_printf(m, "%pK", class->key);
74355 #ifdef CONFIG_DEBUG_LOCKDEP
74356 seq_printf(m, " OPS:%8ld", class->ops);
74357 #endif
74358@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
74359
74360 list_for_each_entry(entry, &class->locks_after, entry) {
74361 if (entry->distance == 1) {
74362- seq_printf(m, " -> [%p] ", entry->class->key);
74363+ seq_printf(m, " -> [%pK] ", entry->class->key);
74364 print_name(m, entry->class);
74365 seq_puts(m, "\n");
74366 }
74367@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
74368 if (!class->key)
74369 continue;
74370
74371- seq_printf(m, "[%p] ", class->key);
74372+ seq_printf(m, "[%pK] ", class->key);
74373 print_name(m, class);
74374 seq_puts(m, "\n");
74375 }
74376@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74377 if (!i)
74378 seq_line(m, '-', 40-namelen, namelen);
74379
74380- snprintf(ip, sizeof(ip), "[<%p>]",
74381+ snprintf(ip, sizeof(ip), "[<%pK>]",
74382 (void *)class->contention_point[i]);
74383 seq_printf(m, "%40s %14lu %29s %pS\n",
74384 name, stats->contention_point[i],
74385@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74386 if (!i)
74387 seq_line(m, '-', 40-namelen, namelen);
74388
74389- snprintf(ip, sizeof(ip), "[<%p>]",
74390+ snprintf(ip, sizeof(ip), "[<%pK>]",
74391 (void *)class->contending_point[i]);
74392 seq_printf(m, "%40s %14lu %29s %pS\n",
74393 name, stats->contending_point[i],
74394diff --git a/kernel/module.c b/kernel/module.c
74395index eab0827..f488603 100644
74396--- a/kernel/module.c
74397+++ b/kernel/module.c
74398@@ -61,6 +61,7 @@
74399 #include <linux/pfn.h>
74400 #include <linux/bsearch.h>
74401 #include <linux/fips.h>
74402+#include <linux/grsecurity.h>
74403 #include <uapi/linux/module.h>
74404 #include "module-internal.h"
74405
74406@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
74407
74408 /* Bounds of module allocation, for speeding __module_address.
74409 * Protected by module_mutex. */
74410-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
74411+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
74412+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
74413
74414 int register_module_notifier(struct notifier_block * nb)
74415 {
74416@@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74417 return true;
74418
74419 list_for_each_entry_rcu(mod, &modules, list) {
74420- struct symsearch arr[] = {
74421+ struct symsearch modarr[] = {
74422 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
74423 NOT_GPL_ONLY, false },
74424 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
74425@@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74426 if (mod->state == MODULE_STATE_UNFORMED)
74427 continue;
74428
74429- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
74430+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
74431 return true;
74432 }
74433 return false;
74434@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
74435 static int percpu_modalloc(struct module *mod,
74436 unsigned long size, unsigned long align)
74437 {
74438- if (align > PAGE_SIZE) {
74439+ if (align-1 >= PAGE_SIZE) {
74440 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
74441 mod->name, align, PAGE_SIZE);
74442 align = PAGE_SIZE;
74443@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
74444 static ssize_t show_coresize(struct module_attribute *mattr,
74445 struct module_kobject *mk, char *buffer)
74446 {
74447- return sprintf(buffer, "%u\n", mk->mod->core_size);
74448+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
74449 }
74450
74451 static struct module_attribute modinfo_coresize =
74452@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
74453 static ssize_t show_initsize(struct module_attribute *mattr,
74454 struct module_kobject *mk, char *buffer)
74455 {
74456- return sprintf(buffer, "%u\n", mk->mod->init_size);
74457+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
74458 }
74459
74460 static struct module_attribute modinfo_initsize =
74461@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
74462 */
74463 #ifdef CONFIG_SYSFS
74464
74465-#ifdef CONFIG_KALLSYMS
74466+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74467 static inline bool sect_empty(const Elf_Shdr *sect)
74468 {
74469 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
74470@@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
74471 {
74472 unsigned int notes, loaded, i;
74473 struct module_notes_attrs *notes_attrs;
74474- struct bin_attribute *nattr;
74475+ bin_attribute_no_const *nattr;
74476
74477 /* failed to create section attributes, so can't create notes */
74478 if (!mod->sect_attrs)
74479@@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
74480 static int module_add_modinfo_attrs(struct module *mod)
74481 {
74482 struct module_attribute *attr;
74483- struct module_attribute *temp_attr;
74484+ module_attribute_no_const *temp_attr;
74485 int error = 0;
74486 int i;
74487
74488@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
74489
74490 static void unset_module_core_ro_nx(struct module *mod)
74491 {
74492- set_page_attributes(mod->module_core + mod->core_text_size,
74493- mod->module_core + mod->core_size,
74494+ set_page_attributes(mod->module_core_rw,
74495+ mod->module_core_rw + mod->core_size_rw,
74496 set_memory_x);
74497- set_page_attributes(mod->module_core,
74498- mod->module_core + mod->core_ro_size,
74499+ set_page_attributes(mod->module_core_rx,
74500+ mod->module_core_rx + mod->core_size_rx,
74501 set_memory_rw);
74502 }
74503
74504 static void unset_module_init_ro_nx(struct module *mod)
74505 {
74506- set_page_attributes(mod->module_init + mod->init_text_size,
74507- mod->module_init + mod->init_size,
74508+ set_page_attributes(mod->module_init_rw,
74509+ mod->module_init_rw + mod->init_size_rw,
74510 set_memory_x);
74511- set_page_attributes(mod->module_init,
74512- mod->module_init + mod->init_ro_size,
74513+ set_page_attributes(mod->module_init_rx,
74514+ mod->module_init_rx + mod->init_size_rx,
74515 set_memory_rw);
74516 }
74517
74518@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
74519 list_for_each_entry_rcu(mod, &modules, list) {
74520 if (mod->state == MODULE_STATE_UNFORMED)
74521 continue;
74522- if ((mod->module_core) && (mod->core_text_size)) {
74523- set_page_attributes(mod->module_core,
74524- mod->module_core + mod->core_text_size,
74525+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
74526+ set_page_attributes(mod->module_core_rx,
74527+ mod->module_core_rx + mod->core_size_rx,
74528 set_memory_rw);
74529 }
74530- if ((mod->module_init) && (mod->init_text_size)) {
74531- set_page_attributes(mod->module_init,
74532- mod->module_init + mod->init_text_size,
74533+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
74534+ set_page_attributes(mod->module_init_rx,
74535+ mod->module_init_rx + mod->init_size_rx,
74536 set_memory_rw);
74537 }
74538 }
74539@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
74540 list_for_each_entry_rcu(mod, &modules, list) {
74541 if (mod->state == MODULE_STATE_UNFORMED)
74542 continue;
74543- if ((mod->module_core) && (mod->core_text_size)) {
74544- set_page_attributes(mod->module_core,
74545- mod->module_core + mod->core_text_size,
74546+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
74547+ set_page_attributes(mod->module_core_rx,
74548+ mod->module_core_rx + mod->core_size_rx,
74549 set_memory_ro);
74550 }
74551- if ((mod->module_init) && (mod->init_text_size)) {
74552- set_page_attributes(mod->module_init,
74553- mod->module_init + mod->init_text_size,
74554+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
74555+ set_page_attributes(mod->module_init_rx,
74556+ mod->module_init_rx + mod->init_size_rx,
74557 set_memory_ro);
74558 }
74559 }
74560@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
74561
74562 /* This may be NULL, but that's OK */
74563 unset_module_init_ro_nx(mod);
74564- module_free(mod, mod->module_init);
74565+ module_free(mod, mod->module_init_rw);
74566+ module_free_exec(mod, mod->module_init_rx);
74567 kfree(mod->args);
74568 percpu_modfree(mod);
74569
74570 /* Free lock-classes: */
74571- lockdep_free_key_range(mod->module_core, mod->core_size);
74572+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
74573+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
74574
74575 /* Finally, free the core (containing the module structure) */
74576 unset_module_core_ro_nx(mod);
74577- module_free(mod, mod->module_core);
74578+ module_free_exec(mod, mod->module_core_rx);
74579+ module_free(mod, mod->module_core_rw);
74580
74581 #ifdef CONFIG_MPU
74582 update_protections(current->mm);
74583@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74584 int ret = 0;
74585 const struct kernel_symbol *ksym;
74586
74587+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74588+ int is_fs_load = 0;
74589+ int register_filesystem_found = 0;
74590+ char *p;
74591+
74592+ p = strstr(mod->args, "grsec_modharden_fs");
74593+ if (p) {
74594+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
74595+ /* copy \0 as well */
74596+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
74597+ is_fs_load = 1;
74598+ }
74599+#endif
74600+
74601 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
74602 const char *name = info->strtab + sym[i].st_name;
74603
74604+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74605+ /* it's a real shame this will never get ripped and copied
74606+ upstream! ;(
74607+ */
74608+ if (is_fs_load && !strcmp(name, "register_filesystem"))
74609+ register_filesystem_found = 1;
74610+#endif
74611+
74612 switch (sym[i].st_shndx) {
74613 case SHN_COMMON:
74614 /* We compiled with -fno-common. These are not
74615@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74616 ksym = resolve_symbol_wait(mod, info, name);
74617 /* Ok if resolved. */
74618 if (ksym && !IS_ERR(ksym)) {
74619+ pax_open_kernel();
74620 sym[i].st_value = ksym->value;
74621+ pax_close_kernel();
74622 break;
74623 }
74624
74625@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74626 secbase = (unsigned long)mod_percpu(mod);
74627 else
74628 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
74629+ pax_open_kernel();
74630 sym[i].st_value += secbase;
74631+ pax_close_kernel();
74632 break;
74633 }
74634 }
74635
74636+#ifdef CONFIG_GRKERNSEC_MODHARDEN
74637+ if (is_fs_load && !register_filesystem_found) {
74638+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
74639+ ret = -EPERM;
74640+ }
74641+#endif
74642+
74643 return ret;
74644 }
74645
74646@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
74647 || s->sh_entsize != ~0UL
74648 || strstarts(sname, ".init"))
74649 continue;
74650- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
74651+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74652+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
74653+ else
74654+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
74655 pr_debug("\t%s\n", sname);
74656 }
74657- switch (m) {
74658- case 0: /* executable */
74659- mod->core_size = debug_align(mod->core_size);
74660- mod->core_text_size = mod->core_size;
74661- break;
74662- case 1: /* RO: text and ro-data */
74663- mod->core_size = debug_align(mod->core_size);
74664- mod->core_ro_size = mod->core_size;
74665- break;
74666- case 3: /* whole core */
74667- mod->core_size = debug_align(mod->core_size);
74668- break;
74669- }
74670 }
74671
74672 pr_debug("Init section allocation order:\n");
74673@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
74674 || s->sh_entsize != ~0UL
74675 || !strstarts(sname, ".init"))
74676 continue;
74677- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
74678- | INIT_OFFSET_MASK);
74679+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74680+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
74681+ else
74682+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
74683+ s->sh_entsize |= INIT_OFFSET_MASK;
74684 pr_debug("\t%s\n", sname);
74685 }
74686- switch (m) {
74687- case 0: /* executable */
74688- mod->init_size = debug_align(mod->init_size);
74689- mod->init_text_size = mod->init_size;
74690- break;
74691- case 1: /* RO: text and ro-data */
74692- mod->init_size = debug_align(mod->init_size);
74693- mod->init_ro_size = mod->init_size;
74694- break;
74695- case 3: /* whole init */
74696- mod->init_size = debug_align(mod->init_size);
74697- break;
74698- }
74699 }
74700 }
74701
74702@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74703
74704 /* Put symbol section at end of init part of module. */
74705 symsect->sh_flags |= SHF_ALLOC;
74706- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
74707+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
74708 info->index.sym) | INIT_OFFSET_MASK;
74709 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
74710
74711@@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74712 }
74713
74714 /* Append room for core symbols at end of core part. */
74715- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
74716- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
74717- mod->core_size += strtab_size;
74718+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
74719+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
74720+ mod->core_size_rx += strtab_size;
74721
74722 /* Put string table section at end of init part of module. */
74723 strsect->sh_flags |= SHF_ALLOC;
74724- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
74725+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
74726 info->index.str) | INIT_OFFSET_MASK;
74727 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
74728 }
74729@@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74730 /* Make sure we get permanent strtab: don't use info->strtab. */
74731 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
74732
74733+ pax_open_kernel();
74734+
74735 /* Set types up while we still have access to sections. */
74736 for (i = 0; i < mod->num_symtab; i++)
74737 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
74738
74739- mod->core_symtab = dst = mod->module_core + info->symoffs;
74740- mod->core_strtab = s = mod->module_core + info->stroffs;
74741+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
74742+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
74743 src = mod->symtab;
74744 for (ndst = i = 0; i < mod->num_symtab; i++) {
74745 if (i == 0 ||
74746@@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74747 }
74748 }
74749 mod->core_num_syms = ndst;
74750+
74751+ pax_close_kernel();
74752 }
74753 #else
74754 static inline void layout_symtab(struct module *mod, struct load_info *info)
74755@@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
74756 return vmalloc_exec(size);
74757 }
74758
74759-static void *module_alloc_update_bounds(unsigned long size)
74760+static void *module_alloc_update_bounds_rw(unsigned long size)
74761 {
74762 void *ret = module_alloc(size);
74763
74764 if (ret) {
74765 mutex_lock(&module_mutex);
74766 /* Update module bounds. */
74767- if ((unsigned long)ret < module_addr_min)
74768- module_addr_min = (unsigned long)ret;
74769- if ((unsigned long)ret + size > module_addr_max)
74770- module_addr_max = (unsigned long)ret + size;
74771+ if ((unsigned long)ret < module_addr_min_rw)
74772+ module_addr_min_rw = (unsigned long)ret;
74773+ if ((unsigned long)ret + size > module_addr_max_rw)
74774+ module_addr_max_rw = (unsigned long)ret + size;
74775+ mutex_unlock(&module_mutex);
74776+ }
74777+ return ret;
74778+}
74779+
74780+static void *module_alloc_update_bounds_rx(unsigned long size)
74781+{
74782+ void *ret = module_alloc_exec(size);
74783+
74784+ if (ret) {
74785+ mutex_lock(&module_mutex);
74786+ /* Update module bounds. */
74787+ if ((unsigned long)ret < module_addr_min_rx)
74788+ module_addr_min_rx = (unsigned long)ret;
74789+ if ((unsigned long)ret + size > module_addr_max_rx)
74790+ module_addr_max_rx = (unsigned long)ret + size;
74791 mutex_unlock(&module_mutex);
74792 }
74793 return ret;
74794@@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
74795 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74796 {
74797 const char *modmagic = get_modinfo(info, "vermagic");
74798+ const char *license = get_modinfo(info, "license");
74799 int err;
74800
74801+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
74802+ if (!license || !license_is_gpl_compatible(license))
74803+ return -ENOEXEC;
74804+#endif
74805+
74806 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
74807 modmagic = NULL;
74808
74809@@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74810 }
74811
74812 /* Set up license info based on the info section */
74813- set_license(mod, get_modinfo(info, "license"));
74814+ set_license(mod, license);
74815
74816 return 0;
74817 }
74818@@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
74819 void *ptr;
74820
74821 /* Do the allocs. */
74822- ptr = module_alloc_update_bounds(mod->core_size);
74823+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
74824 /*
74825 * The pointer to this block is stored in the module structure
74826 * which is inside the block. Just mark it as not being a
74827@@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
74828 if (!ptr)
74829 return -ENOMEM;
74830
74831- memset(ptr, 0, mod->core_size);
74832- mod->module_core = ptr;
74833+ memset(ptr, 0, mod->core_size_rw);
74834+ mod->module_core_rw = ptr;
74835
74836- if (mod->init_size) {
74837- ptr = module_alloc_update_bounds(mod->init_size);
74838+ if (mod->init_size_rw) {
74839+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
74840 /*
74841 * The pointer to this block is stored in the module structure
74842 * which is inside the block. This block doesn't need to be
74843@@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
74844 */
74845 kmemleak_ignore(ptr);
74846 if (!ptr) {
74847- module_free(mod, mod->module_core);
74848+ module_free(mod, mod->module_core_rw);
74849 return -ENOMEM;
74850 }
74851- memset(ptr, 0, mod->init_size);
74852- mod->module_init = ptr;
74853+ memset(ptr, 0, mod->init_size_rw);
74854+ mod->module_init_rw = ptr;
74855 } else
74856- mod->module_init = NULL;
74857+ mod->module_init_rw = NULL;
74858+
74859+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
74860+ kmemleak_not_leak(ptr);
74861+ if (!ptr) {
74862+ if (mod->module_init_rw)
74863+ module_free(mod, mod->module_init_rw);
74864+ module_free(mod, mod->module_core_rw);
74865+ return -ENOMEM;
74866+ }
74867+
74868+ pax_open_kernel();
74869+ memset(ptr, 0, mod->core_size_rx);
74870+ pax_close_kernel();
74871+ mod->module_core_rx = ptr;
74872+
74873+ if (mod->init_size_rx) {
74874+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
74875+ kmemleak_ignore(ptr);
74876+ if (!ptr && mod->init_size_rx) {
74877+ module_free_exec(mod, mod->module_core_rx);
74878+ if (mod->module_init_rw)
74879+ module_free(mod, mod->module_init_rw);
74880+ module_free(mod, mod->module_core_rw);
74881+ return -ENOMEM;
74882+ }
74883+
74884+ pax_open_kernel();
74885+ memset(ptr, 0, mod->init_size_rx);
74886+ pax_close_kernel();
74887+ mod->module_init_rx = ptr;
74888+ } else
74889+ mod->module_init_rx = NULL;
74890
74891 /* Transfer each section which specifies SHF_ALLOC */
74892 pr_debug("final section addresses:\n");
74893@@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
74894 if (!(shdr->sh_flags & SHF_ALLOC))
74895 continue;
74896
74897- if (shdr->sh_entsize & INIT_OFFSET_MASK)
74898- dest = mod->module_init
74899- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74900- else
74901- dest = mod->module_core + shdr->sh_entsize;
74902+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
74903+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74904+ dest = mod->module_init_rw
74905+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74906+ else
74907+ dest = mod->module_init_rx
74908+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74909+ } else {
74910+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74911+ dest = mod->module_core_rw + shdr->sh_entsize;
74912+ else
74913+ dest = mod->module_core_rx + shdr->sh_entsize;
74914+ }
74915+
74916+ if (shdr->sh_type != SHT_NOBITS) {
74917+
74918+#ifdef CONFIG_PAX_KERNEXEC
74919+#ifdef CONFIG_X86_64
74920+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
74921+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
74922+#endif
74923+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
74924+ pax_open_kernel();
74925+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74926+ pax_close_kernel();
74927+ } else
74928+#endif
74929
74930- if (shdr->sh_type != SHT_NOBITS)
74931 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74932+ }
74933 /* Update sh_addr to point to copy in image. */
74934- shdr->sh_addr = (unsigned long)dest;
74935+
74936+#ifdef CONFIG_PAX_KERNEXEC
74937+ if (shdr->sh_flags & SHF_EXECINSTR)
74938+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
74939+ else
74940+#endif
74941+
74942+ shdr->sh_addr = (unsigned long)dest;
74943 pr_debug("\t0x%lx %s\n",
74944 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
74945 }
74946@@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
74947 * Do it before processing of module parameters, so the module
74948 * can provide parameter accessor functions of its own.
74949 */
74950- if (mod->module_init)
74951- flush_icache_range((unsigned long)mod->module_init,
74952- (unsigned long)mod->module_init
74953- + mod->init_size);
74954- flush_icache_range((unsigned long)mod->module_core,
74955- (unsigned long)mod->module_core + mod->core_size);
74956+ if (mod->module_init_rx)
74957+ flush_icache_range((unsigned long)mod->module_init_rx,
74958+ (unsigned long)mod->module_init_rx
74959+ + mod->init_size_rx);
74960+ flush_icache_range((unsigned long)mod->module_core_rx,
74961+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
74962
74963 set_fs(old_fs);
74964 }
74965@@ -2983,8 +3088,10 @@ out:
74966 static void module_deallocate(struct module *mod, struct load_info *info)
74967 {
74968 percpu_modfree(mod);
74969- module_free(mod, mod->module_init);
74970- module_free(mod, mod->module_core);
74971+ module_free_exec(mod, mod->module_init_rx);
74972+ module_free_exec(mod, mod->module_core_rx);
74973+ module_free(mod, mod->module_init_rw);
74974+ module_free(mod, mod->module_core_rw);
74975 }
74976
74977 int __weak module_finalize(const Elf_Ehdr *hdr,
74978@@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
74979 static int post_relocation(struct module *mod, const struct load_info *info)
74980 {
74981 /* Sort exception table now relocations are done. */
74982+ pax_open_kernel();
74983 sort_extable(mod->extable, mod->extable + mod->num_exentries);
74984+ pax_close_kernel();
74985
74986 /* Copy relocated percpu area over. */
74987 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
74988@@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
74989 MODULE_STATE_COMING, mod);
74990
74991 /* Set RO and NX regions for core */
74992- set_section_ro_nx(mod->module_core,
74993- mod->core_text_size,
74994- mod->core_ro_size,
74995- mod->core_size);
74996+ set_section_ro_nx(mod->module_core_rx,
74997+ mod->core_size_rx,
74998+ mod->core_size_rx,
74999+ mod->core_size_rx);
75000
75001 /* Set RO and NX regions for init */
75002- set_section_ro_nx(mod->module_init,
75003- mod->init_text_size,
75004- mod->init_ro_size,
75005- mod->init_size);
75006+ set_section_ro_nx(mod->module_init_rx,
75007+ mod->init_size_rx,
75008+ mod->init_size_rx,
75009+ mod->init_size_rx);
75010
75011 do_mod_ctors(mod);
75012 /* Start the module */
75013@@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75014 mod->strtab = mod->core_strtab;
75015 #endif
75016 unset_module_init_ro_nx(mod);
75017- module_free(mod, mod->module_init);
75018- mod->module_init = NULL;
75019- mod->init_size = 0;
75020- mod->init_ro_size = 0;
75021- mod->init_text_size = 0;
75022+ module_free(mod, mod->module_init_rw);
75023+ module_free_exec(mod, mod->module_init_rx);
75024+ mod->module_init_rw = NULL;
75025+ mod->module_init_rx = NULL;
75026+ mod->init_size_rw = 0;
75027+ mod->init_size_rx = 0;
75028 mutex_unlock(&module_mutex);
75029 wake_up_all(&module_wq);
75030
75031@@ -3209,9 +3319,38 @@ again:
75032 if (err)
75033 goto free_unload;
75034
75035+ /* Now copy in args */
75036+ mod->args = strndup_user(uargs, ~0UL >> 1);
75037+ if (IS_ERR(mod->args)) {
75038+ err = PTR_ERR(mod->args);
75039+ goto free_unload;
75040+ }
75041+
75042 /* Set up MODINFO_ATTR fields */
75043 setup_modinfo(mod, info);
75044
75045+#ifdef CONFIG_GRKERNSEC_MODHARDEN
75046+ {
75047+ char *p, *p2;
75048+
75049+ if (strstr(mod->args, "grsec_modharden_netdev")) {
75050+ 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);
75051+ err = -EPERM;
75052+ goto free_modinfo;
75053+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75054+ p += sizeof("grsec_modharden_normal") - 1;
75055+ p2 = strstr(p, "_");
75056+ if (p2) {
75057+ *p2 = '\0';
75058+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75059+ *p2 = '_';
75060+ }
75061+ err = -EPERM;
75062+ goto free_modinfo;
75063+ }
75064+ }
75065+#endif
75066+
75067 /* Fix up syms, so that st_value is a pointer to location. */
75068 err = simplify_symbols(mod, info);
75069 if (err < 0)
75070@@ -3227,13 +3366,6 @@ again:
75071
75072 flush_module_icache(mod);
75073
75074- /* Now copy in args */
75075- mod->args = strndup_user(uargs, ~0UL >> 1);
75076- if (IS_ERR(mod->args)) {
75077- err = PTR_ERR(mod->args);
75078- goto free_arch_cleanup;
75079- }
75080-
75081 dynamic_debug_setup(info->debug, info->num_debug);
75082
75083 mutex_lock(&module_mutex);
75084@@ -3278,11 +3410,10 @@ again:
75085 mutex_unlock(&module_mutex);
75086 dynamic_debug_remove(info->debug);
75087 synchronize_sched();
75088- kfree(mod->args);
75089- free_arch_cleanup:
75090 module_arch_cleanup(mod);
75091 free_modinfo:
75092 free_modinfo(mod);
75093+ kfree(mod->args);
75094 free_unload:
75095 module_unload_free(mod);
75096 unlink_mod:
75097@@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75098 unsigned long nextval;
75099
75100 /* At worse, next value is at end of module */
75101- if (within_module_init(addr, mod))
75102- nextval = (unsigned long)mod->module_init+mod->init_text_size;
75103+ if (within_module_init_rx(addr, mod))
75104+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75105+ else if (within_module_init_rw(addr, mod))
75106+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75107+ else if (within_module_core_rx(addr, mod))
75108+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75109+ else if (within_module_core_rw(addr, mod))
75110+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75111 else
75112- nextval = (unsigned long)mod->module_core+mod->core_text_size;
75113+ return NULL;
75114
75115 /* Scan for closest preceding symbol, and next symbol. (ELF
75116 starts real symbols at 1). */
75117@@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75118 return 0;
75119
75120 seq_printf(m, "%s %u",
75121- mod->name, mod->init_size + mod->core_size);
75122+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75123 print_unload_info(m, mod);
75124
75125 /* Informative for users. */
75126@@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75127 mod->state == MODULE_STATE_COMING ? "Loading":
75128 "Live");
75129 /* Used by oprofile and other similar tools. */
75130- seq_printf(m, " 0x%pK", mod->module_core);
75131+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75132
75133 /* Taints info */
75134 if (mod->taints)
75135@@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75136
75137 static int __init proc_modules_init(void)
75138 {
75139+#ifndef CONFIG_GRKERNSEC_HIDESYM
75140+#ifdef CONFIG_GRKERNSEC_PROC_USER
75141+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75142+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75143+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75144+#else
75145 proc_create("modules", 0, NULL, &proc_modules_operations);
75146+#endif
75147+#else
75148+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75149+#endif
75150 return 0;
75151 }
75152 module_init(proc_modules_init);
75153@@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75154 {
75155 struct module *mod;
75156
75157- if (addr < module_addr_min || addr > module_addr_max)
75158+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75159+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
75160 return NULL;
75161
75162 list_for_each_entry_rcu(mod, &modules, list) {
75163 if (mod->state == MODULE_STATE_UNFORMED)
75164 continue;
75165- if (within_module_core(addr, mod)
75166- || within_module_init(addr, mod))
75167+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
75168 return mod;
75169 }
75170 return NULL;
75171@@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75172 */
75173 struct module *__module_text_address(unsigned long addr)
75174 {
75175- struct module *mod = __module_address(addr);
75176+ struct module *mod;
75177+
75178+#ifdef CONFIG_X86_32
75179+ addr = ktla_ktva(addr);
75180+#endif
75181+
75182+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75183+ return NULL;
75184+
75185+ mod = __module_address(addr);
75186+
75187 if (mod) {
75188 /* Make sure it's within the text section. */
75189- if (!within(addr, mod->module_init, mod->init_text_size)
75190- && !within(addr, mod->module_core, mod->core_text_size))
75191+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75192 mod = NULL;
75193 }
75194 return mod;
75195diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75196index 7e3443f..b2a1e6b 100644
75197--- a/kernel/mutex-debug.c
75198+++ b/kernel/mutex-debug.c
75199@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75200 }
75201
75202 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75203- struct thread_info *ti)
75204+ struct task_struct *task)
75205 {
75206 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75207
75208 /* Mark the current thread as blocked on the lock: */
75209- ti->task->blocked_on = waiter;
75210+ task->blocked_on = waiter;
75211 }
75212
75213 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75214- struct thread_info *ti)
75215+ struct task_struct *task)
75216 {
75217 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75218- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75219- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75220- ti->task->blocked_on = NULL;
75221+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
75222+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75223+ task->blocked_on = NULL;
75224
75225 list_del_init(&waiter->list);
75226 waiter->task = NULL;
75227diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75228index 0799fd3..d06ae3b 100644
75229--- a/kernel/mutex-debug.h
75230+++ b/kernel/mutex-debug.h
75231@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75232 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75233 extern void debug_mutex_add_waiter(struct mutex *lock,
75234 struct mutex_waiter *waiter,
75235- struct thread_info *ti);
75236+ struct task_struct *task);
75237 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75238- struct thread_info *ti);
75239+ struct task_struct *task);
75240 extern void debug_mutex_unlock(struct mutex *lock);
75241 extern void debug_mutex_init(struct mutex *lock, const char *name,
75242 struct lock_class_key *key);
75243diff --git a/kernel/mutex.c b/kernel/mutex.c
75244index a307cc9..27fd2e9 100644
75245--- a/kernel/mutex.c
75246+++ b/kernel/mutex.c
75247@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75248 spin_lock_mutex(&lock->wait_lock, flags);
75249
75250 debug_mutex_lock_common(lock, &waiter);
75251- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75252+ debug_mutex_add_waiter(lock, &waiter, task);
75253
75254 /* add waiting tasks to the end of the waitqueue (FIFO): */
75255 list_add_tail(&waiter.list, &lock->wait_list);
75256@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75257 * TASK_UNINTERRUPTIBLE case.)
75258 */
75259 if (unlikely(signal_pending_state(state, task))) {
75260- mutex_remove_waiter(lock, &waiter,
75261- task_thread_info(task));
75262+ mutex_remove_waiter(lock, &waiter, task);
75263 mutex_release(&lock->dep_map, 1, ip);
75264 spin_unlock_mutex(&lock->wait_lock, flags);
75265
75266@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75267 done:
75268 lock_acquired(&lock->dep_map, ip);
75269 /* got the lock - rejoice! */
75270- mutex_remove_waiter(lock, &waiter, current_thread_info());
75271+ mutex_remove_waiter(lock, &waiter, task);
75272 mutex_set_owner(lock);
75273
75274 /* set it to 0 if there are no waiters left: */
75275diff --git a/kernel/notifier.c b/kernel/notifier.c
75276index 2d5cc4c..d9ea600 100644
75277--- a/kernel/notifier.c
75278+++ b/kernel/notifier.c
75279@@ -5,6 +5,7 @@
75280 #include <linux/rcupdate.h>
75281 #include <linux/vmalloc.h>
75282 #include <linux/reboot.h>
75283+#include <linux/mm.h>
75284
75285 /*
75286 * Notifier list for kernel code which wants to be called
75287@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75288 while ((*nl) != NULL) {
75289 if (n->priority > (*nl)->priority)
75290 break;
75291- nl = &((*nl)->next);
75292+ nl = (struct notifier_block **)&((*nl)->next);
75293 }
75294- n->next = *nl;
75295+ pax_open_kernel();
75296+ *(const void **)&n->next = *nl;
75297 rcu_assign_pointer(*nl, n);
75298+ pax_close_kernel();
75299 return 0;
75300 }
75301
75302@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75303 return 0;
75304 if (n->priority > (*nl)->priority)
75305 break;
75306- nl = &((*nl)->next);
75307+ nl = (struct notifier_block **)&((*nl)->next);
75308 }
75309- n->next = *nl;
75310+ pax_open_kernel();
75311+ *(const void **)&n->next = *nl;
75312 rcu_assign_pointer(*nl, n);
75313+ pax_close_kernel();
75314 return 0;
75315 }
75316
75317@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75318 {
75319 while ((*nl) != NULL) {
75320 if ((*nl) == n) {
75321+ pax_open_kernel();
75322 rcu_assign_pointer(*nl, n->next);
75323+ pax_close_kernel();
75324 return 0;
75325 }
75326- nl = &((*nl)->next);
75327+ nl = (struct notifier_block **)&((*nl)->next);
75328 }
75329 return -ENOENT;
75330 }
75331diff --git a/kernel/panic.c b/kernel/panic.c
75332index e1b2822..5edc1d9 100644
75333--- a/kernel/panic.c
75334+++ b/kernel/panic.c
75335@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
75336 const char *board;
75337
75338 printk(KERN_WARNING "------------[ cut here ]------------\n");
75339- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
75340+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
75341 board = dmi_get_system_info(DMI_PRODUCT_NAME);
75342 if (board)
75343 printk(KERN_WARNING "Hardware name: %s\n", board);
75344@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
75345 */
75346 void __stack_chk_fail(void)
75347 {
75348- panic("stack-protector: Kernel stack is corrupted in: %p\n",
75349+ dump_stack();
75350+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
75351 __builtin_return_address(0));
75352 }
75353 EXPORT_SYMBOL(__stack_chk_fail);
75354diff --git a/kernel/pid.c b/kernel/pid.c
75355index f2c6a68..4922d97 100644
75356--- a/kernel/pid.c
75357+++ b/kernel/pid.c
75358@@ -33,6 +33,7 @@
75359 #include <linux/rculist.h>
75360 #include <linux/bootmem.h>
75361 #include <linux/hash.h>
75362+#include <linux/security.h>
75363 #include <linux/pid_namespace.h>
75364 #include <linux/init_task.h>
75365 #include <linux/syscalls.h>
75366@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
75367
75368 int pid_max = PID_MAX_DEFAULT;
75369
75370-#define RESERVED_PIDS 300
75371+#define RESERVED_PIDS 500
75372
75373 int pid_max_min = RESERVED_PIDS + 1;
75374 int pid_max_max = PID_MAX_LIMIT;
75375@@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
75376 */
75377 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
75378 {
75379+ struct task_struct *task;
75380+
75381 rcu_lockdep_assert(rcu_read_lock_held(),
75382 "find_task_by_pid_ns() needs rcu_read_lock()"
75383 " protection");
75384- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75385+
75386+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75387+
75388+ if (gr_pid_is_chrooted(task))
75389+ return NULL;
75390+
75391+ return task;
75392 }
75393
75394 struct task_struct *find_task_by_vpid(pid_t vnr)
75395@@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
75396 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
75397 }
75398
75399+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
75400+{
75401+ rcu_lockdep_assert(rcu_read_lock_held(),
75402+ "find_task_by_pid_ns() needs rcu_read_lock()"
75403+ " protection");
75404+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
75405+}
75406+
75407 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
75408 {
75409 struct pid *pid;
75410diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
75411index c1c3dc1..bbeaf31 100644
75412--- a/kernel/pid_namespace.c
75413+++ b/kernel/pid_namespace.c
75414@@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
75415 void __user *buffer, size_t *lenp, loff_t *ppos)
75416 {
75417 struct pid_namespace *pid_ns = task_active_pid_ns(current);
75418- struct ctl_table tmp = *table;
75419+ ctl_table_no_const tmp = *table;
75420
75421 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
75422 return -EPERM;
75423diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
75424index 942ca27..111e609 100644
75425--- a/kernel/posix-cpu-timers.c
75426+++ b/kernel/posix-cpu-timers.c
75427@@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
75428
75429 static __init int init_posix_cpu_timers(void)
75430 {
75431- struct k_clock process = {
75432+ static struct k_clock process = {
75433 .clock_getres = process_cpu_clock_getres,
75434 .clock_get = process_cpu_clock_get,
75435 .timer_create = process_cpu_timer_create,
75436 .nsleep = process_cpu_nsleep,
75437 .nsleep_restart = process_cpu_nsleep_restart,
75438 };
75439- struct k_clock thread = {
75440+ static struct k_clock thread = {
75441 .clock_getres = thread_cpu_clock_getres,
75442 .clock_get = thread_cpu_clock_get,
75443 .timer_create = thread_cpu_timer_create,
75444diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
75445index e885be1..380fe76 100644
75446--- a/kernel/posix-timers.c
75447+++ b/kernel/posix-timers.c
75448@@ -43,6 +43,7 @@
75449 #include <linux/idr.h>
75450 #include <linux/posix-clock.h>
75451 #include <linux/posix-timers.h>
75452+#include <linux/grsecurity.h>
75453 #include <linux/syscalls.h>
75454 #include <linux/wait.h>
75455 #include <linux/workqueue.h>
75456@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
75457 * which we beg off on and pass to do_sys_settimeofday().
75458 */
75459
75460-static struct k_clock posix_clocks[MAX_CLOCKS];
75461+static struct k_clock *posix_clocks[MAX_CLOCKS];
75462
75463 /*
75464 * These ones are defined below.
75465@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
75466 */
75467 static __init int init_posix_timers(void)
75468 {
75469- struct k_clock clock_realtime = {
75470+ static struct k_clock clock_realtime = {
75471 .clock_getres = hrtimer_get_res,
75472 .clock_get = posix_clock_realtime_get,
75473 .clock_set = posix_clock_realtime_set,
75474@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
75475 .timer_get = common_timer_get,
75476 .timer_del = common_timer_del,
75477 };
75478- struct k_clock clock_monotonic = {
75479+ static struct k_clock clock_monotonic = {
75480 .clock_getres = hrtimer_get_res,
75481 .clock_get = posix_ktime_get_ts,
75482 .nsleep = common_nsleep,
75483@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
75484 .timer_get = common_timer_get,
75485 .timer_del = common_timer_del,
75486 };
75487- struct k_clock clock_monotonic_raw = {
75488+ static struct k_clock clock_monotonic_raw = {
75489 .clock_getres = hrtimer_get_res,
75490 .clock_get = posix_get_monotonic_raw,
75491 };
75492- struct k_clock clock_realtime_coarse = {
75493+ static struct k_clock clock_realtime_coarse = {
75494 .clock_getres = posix_get_coarse_res,
75495 .clock_get = posix_get_realtime_coarse,
75496 };
75497- struct k_clock clock_monotonic_coarse = {
75498+ static struct k_clock clock_monotonic_coarse = {
75499 .clock_getres = posix_get_coarse_res,
75500 .clock_get = posix_get_monotonic_coarse,
75501 };
75502- struct k_clock clock_boottime = {
75503+ static struct k_clock clock_boottime = {
75504 .clock_getres = hrtimer_get_res,
75505 .clock_get = posix_get_boottime,
75506 .nsleep = common_nsleep,
75507@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
75508 return;
75509 }
75510
75511- posix_clocks[clock_id] = *new_clock;
75512+ posix_clocks[clock_id] = new_clock;
75513 }
75514 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
75515
75516@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
75517 return (id & CLOCKFD_MASK) == CLOCKFD ?
75518 &clock_posix_dynamic : &clock_posix_cpu;
75519
75520- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
75521+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
75522 return NULL;
75523- return &posix_clocks[id];
75524+ return posix_clocks[id];
75525 }
75526
75527 static int common_timer_create(struct k_itimer *new_timer)
75528@@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
75529 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
75530 return -EFAULT;
75531
75532+ /* only the CLOCK_REALTIME clock can be set, all other clocks
75533+ have their clock_set fptr set to a nosettime dummy function
75534+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
75535+ call common_clock_set, which calls do_sys_settimeofday, which
75536+ we hook
75537+ */
75538+
75539 return kc->clock_set(which_clock, &new_tp);
75540 }
75541
75542diff --git a/kernel/power/process.c b/kernel/power/process.c
75543index d5a258b..4271191 100644
75544--- a/kernel/power/process.c
75545+++ b/kernel/power/process.c
75546@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
75547 u64 elapsed_csecs64;
75548 unsigned int elapsed_csecs;
75549 bool wakeup = false;
75550+ bool timedout = false;
75551
75552 do_gettimeofday(&start);
75553
75554@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
75555
75556 while (true) {
75557 todo = 0;
75558+ if (time_after(jiffies, end_time))
75559+ timedout = true;
75560 read_lock(&tasklist_lock);
75561 do_each_thread(g, p) {
75562 if (p == current || !freeze_task(p))
75563 continue;
75564
75565- if (!freezer_should_skip(p))
75566+ if (!freezer_should_skip(p)) {
75567 todo++;
75568+ if (timedout) {
75569+ printk(KERN_ERR "Task refusing to freeze:\n");
75570+ sched_show_task(p);
75571+ }
75572+ }
75573 } while_each_thread(g, p);
75574 read_unlock(&tasklist_lock);
75575
75576@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
75577 todo += wq_busy;
75578 }
75579
75580- if (!todo || time_after(jiffies, end_time))
75581+ if (!todo || timedout)
75582 break;
75583
75584 if (pm_wakeup_pending()) {
75585diff --git a/kernel/printk.c b/kernel/printk.c
75586index 267ce78..2487112 100644
75587--- a/kernel/printk.c
75588+++ b/kernel/printk.c
75589@@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
75590 return ret;
75591 }
75592
75593+static int check_syslog_permissions(int type, bool from_file);
75594+
75595 static int devkmsg_open(struct inode *inode, struct file *file)
75596 {
75597 struct devkmsg_user *user;
75598 int err;
75599
75600+ err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
75601+ if (err)
75602+ return err;
75603+
75604 /* write-only does not need any file context */
75605 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
75606 return 0;
75607@@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
75608 if (dmesg_restrict)
75609 return 1;
75610 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
75611- return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75612+ return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75613 }
75614
75615 static int check_syslog_permissions(int type, bool from_file)
75616@@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
75617 if (from_file && type != SYSLOG_ACTION_OPEN)
75618 return 0;
75619
75620+#ifdef CONFIG_GRKERNSEC_DMESG
75621+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
75622+ return -EPERM;
75623+#endif
75624+
75625 if (syslog_action_restricted(type)) {
75626 if (capable(CAP_SYSLOG))
75627 return 0;
75628diff --git a/kernel/profile.c b/kernel/profile.c
75629index 1f39181..86093471 100644
75630--- a/kernel/profile.c
75631+++ b/kernel/profile.c
75632@@ -40,7 +40,7 @@ struct profile_hit {
75633 /* Oprofile timer tick hook */
75634 static int (*timer_hook)(struct pt_regs *) __read_mostly;
75635
75636-static atomic_t *prof_buffer;
75637+static atomic_unchecked_t *prof_buffer;
75638 static unsigned long prof_len, prof_shift;
75639
75640 int prof_on __read_mostly;
75641@@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
75642 hits[i].pc = 0;
75643 continue;
75644 }
75645- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75646+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75647 hits[i].hits = hits[i].pc = 0;
75648 }
75649 }
75650@@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75651 * Add the current hit(s) and flush the write-queue out
75652 * to the global buffer:
75653 */
75654- atomic_add(nr_hits, &prof_buffer[pc]);
75655+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
75656 for (i = 0; i < NR_PROFILE_HIT; ++i) {
75657- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75658+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75659 hits[i].pc = hits[i].hits = 0;
75660 }
75661 out:
75662@@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75663 {
75664 unsigned long pc;
75665 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
75666- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75667+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75668 }
75669 #endif /* !CONFIG_SMP */
75670
75671@@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
75672 return -EFAULT;
75673 buf++; p++; count--; read++;
75674 }
75675- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
75676+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
75677 if (copy_to_user(buf, (void *)pnt, count))
75678 return -EFAULT;
75679 read += count;
75680@@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
75681 }
75682 #endif
75683 profile_discard_flip_buffers();
75684- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
75685+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
75686 return count;
75687 }
75688
75689diff --git a/kernel/ptrace.c b/kernel/ptrace.c
75690index 6cbeaae..363c48a 100644
75691--- a/kernel/ptrace.c
75692+++ b/kernel/ptrace.c
75693@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
75694 if (seize)
75695 flags |= PT_SEIZED;
75696 rcu_read_lock();
75697- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75698+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75699 flags |= PT_PTRACE_CAP;
75700 rcu_read_unlock();
75701 task->ptrace = flags;
75702@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
75703 break;
75704 return -EIO;
75705 }
75706- if (copy_to_user(dst, buf, retval))
75707+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
75708 return -EFAULT;
75709 copied += retval;
75710 src += retval;
75711@@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
75712 bool seized = child->ptrace & PT_SEIZED;
75713 int ret = -EIO;
75714 siginfo_t siginfo, *si;
75715- void __user *datavp = (void __user *) data;
75716+ void __user *datavp = (__force void __user *) data;
75717 unsigned long __user *datalp = datavp;
75718 unsigned long flags;
75719
75720@@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
75721 goto out;
75722 }
75723
75724+ if (gr_handle_ptrace(child, request)) {
75725+ ret = -EPERM;
75726+ goto out_put_task_struct;
75727+ }
75728+
75729 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75730 ret = ptrace_attach(child, request, addr, data);
75731 /*
75732 * Some architectures need to do book-keeping after
75733 * a ptrace attach.
75734 */
75735- if (!ret)
75736+ if (!ret) {
75737 arch_ptrace_attach(child);
75738+ gr_audit_ptrace(child);
75739+ }
75740 goto out_put_task_struct;
75741 }
75742
75743@@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
75744 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
75745 if (copied != sizeof(tmp))
75746 return -EIO;
75747- return put_user(tmp, (unsigned long __user *)data);
75748+ return put_user(tmp, (__force unsigned long __user *)data);
75749 }
75750
75751 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
75752@@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75753 goto out;
75754 }
75755
75756+ if (gr_handle_ptrace(child, request)) {
75757+ ret = -EPERM;
75758+ goto out_put_task_struct;
75759+ }
75760+
75761 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75762 ret = ptrace_attach(child, request, addr, data);
75763 /*
75764 * Some architectures need to do book-keeping after
75765 * a ptrace attach.
75766 */
75767- if (!ret)
75768+ if (!ret) {
75769 arch_ptrace_attach(child);
75770+ gr_audit_ptrace(child);
75771+ }
75772 goto out_put_task_struct;
75773 }
75774
75775diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
75776index e7dce58..ad0d7b7 100644
75777--- a/kernel/rcutiny.c
75778+++ b/kernel/rcutiny.c
75779@@ -46,7 +46,7 @@
75780 struct rcu_ctrlblk;
75781 static void invoke_rcu_callbacks(void);
75782 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
75783-static void rcu_process_callbacks(struct softirq_action *unused);
75784+static void rcu_process_callbacks(void);
75785 static void __call_rcu(struct rcu_head *head,
75786 void (*func)(struct rcu_head *rcu),
75787 struct rcu_ctrlblk *rcp);
75788@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
75789 rcu_is_callbacks_kthread()));
75790 }
75791
75792-static void rcu_process_callbacks(struct softirq_action *unused)
75793+static void rcu_process_callbacks(void)
75794 {
75795 __rcu_process_callbacks(&rcu_sched_ctrlblk);
75796 __rcu_process_callbacks(&rcu_bh_ctrlblk);
75797diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
75798index f85016a..91cb03b 100644
75799--- a/kernel/rcutiny_plugin.h
75800+++ b/kernel/rcutiny_plugin.h
75801@@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
75802 have_rcu_kthread_work = morework;
75803 local_irq_restore(flags);
75804 if (work)
75805- rcu_process_callbacks(NULL);
75806+ rcu_process_callbacks();
75807 schedule_timeout_interruptible(1); /* Leave CPU for others. */
75808 }
75809
75810diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
75811index 31dea01..ad91ffb 100644
75812--- a/kernel/rcutorture.c
75813+++ b/kernel/rcutorture.c
75814@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
75815 { 0 };
75816 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
75817 { 0 };
75818-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75819-static atomic_t n_rcu_torture_alloc;
75820-static atomic_t n_rcu_torture_alloc_fail;
75821-static atomic_t n_rcu_torture_free;
75822-static atomic_t n_rcu_torture_mberror;
75823-static atomic_t n_rcu_torture_error;
75824+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75825+static atomic_unchecked_t n_rcu_torture_alloc;
75826+static atomic_unchecked_t n_rcu_torture_alloc_fail;
75827+static atomic_unchecked_t n_rcu_torture_free;
75828+static atomic_unchecked_t n_rcu_torture_mberror;
75829+static atomic_unchecked_t n_rcu_torture_error;
75830 static long n_rcu_torture_barrier_error;
75831 static long n_rcu_torture_boost_ktrerror;
75832 static long n_rcu_torture_boost_rterror;
75833@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
75834
75835 spin_lock_bh(&rcu_torture_lock);
75836 if (list_empty(&rcu_torture_freelist)) {
75837- atomic_inc(&n_rcu_torture_alloc_fail);
75838+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
75839 spin_unlock_bh(&rcu_torture_lock);
75840 return NULL;
75841 }
75842- atomic_inc(&n_rcu_torture_alloc);
75843+ atomic_inc_unchecked(&n_rcu_torture_alloc);
75844 p = rcu_torture_freelist.next;
75845 list_del_init(p);
75846 spin_unlock_bh(&rcu_torture_lock);
75847@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
75848 static void
75849 rcu_torture_free(struct rcu_torture *p)
75850 {
75851- atomic_inc(&n_rcu_torture_free);
75852+ atomic_inc_unchecked(&n_rcu_torture_free);
75853 spin_lock_bh(&rcu_torture_lock);
75854 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
75855 spin_unlock_bh(&rcu_torture_lock);
75856@@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
75857 i = rp->rtort_pipe_count;
75858 if (i > RCU_TORTURE_PIPE_LEN)
75859 i = RCU_TORTURE_PIPE_LEN;
75860- atomic_inc(&rcu_torture_wcount[i]);
75861+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
75862 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75863 rp->rtort_mbtest = 0;
75864 rcu_torture_free(rp);
75865@@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
75866 i = rp->rtort_pipe_count;
75867 if (i > RCU_TORTURE_PIPE_LEN)
75868 i = RCU_TORTURE_PIPE_LEN;
75869- atomic_inc(&rcu_torture_wcount[i]);
75870+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
75871 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75872 rp->rtort_mbtest = 0;
75873 list_del(&rp->rtort_free);
75874@@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
75875 i = old_rp->rtort_pipe_count;
75876 if (i > RCU_TORTURE_PIPE_LEN)
75877 i = RCU_TORTURE_PIPE_LEN;
75878- atomic_inc(&rcu_torture_wcount[i]);
75879+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
75880 old_rp->rtort_pipe_count++;
75881 cur_ops->deferred_free(old_rp);
75882 }
75883@@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
75884 }
75885 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75886 if (p->rtort_mbtest == 0)
75887- atomic_inc(&n_rcu_torture_mberror);
75888+ atomic_inc_unchecked(&n_rcu_torture_mberror);
75889 spin_lock(&rand_lock);
75890 cur_ops->read_delay(&rand);
75891 n_rcu_torture_timers++;
75892@@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
75893 }
75894 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75895 if (p->rtort_mbtest == 0)
75896- atomic_inc(&n_rcu_torture_mberror);
75897+ atomic_inc_unchecked(&n_rcu_torture_mberror);
75898 cur_ops->read_delay(&rand);
75899 preempt_disable();
75900 pipe_count = p->rtort_pipe_count;
75901@@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
75902 rcu_torture_current,
75903 rcu_torture_current_version,
75904 list_empty(&rcu_torture_freelist),
75905- atomic_read(&n_rcu_torture_alloc),
75906- atomic_read(&n_rcu_torture_alloc_fail),
75907- atomic_read(&n_rcu_torture_free));
75908+ atomic_read_unchecked(&n_rcu_torture_alloc),
75909+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
75910+ atomic_read_unchecked(&n_rcu_torture_free));
75911 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
75912- atomic_read(&n_rcu_torture_mberror),
75913+ atomic_read_unchecked(&n_rcu_torture_mberror),
75914 n_rcu_torture_boost_ktrerror,
75915 n_rcu_torture_boost_rterror);
75916 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
75917@@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
75918 n_barrier_attempts,
75919 n_rcu_torture_barrier_error);
75920 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
75921- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
75922+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
75923 n_rcu_torture_barrier_error != 0 ||
75924 n_rcu_torture_boost_ktrerror != 0 ||
75925 n_rcu_torture_boost_rterror != 0 ||
75926 n_rcu_torture_boost_failure != 0 ||
75927 i > 1) {
75928 cnt += sprintf(&page[cnt], "!!! ");
75929- atomic_inc(&n_rcu_torture_error);
75930+ atomic_inc_unchecked(&n_rcu_torture_error);
75931 WARN_ON_ONCE(1);
75932 }
75933 cnt += sprintf(&page[cnt], "Reader Pipe: ");
75934@@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
75935 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
75936 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75937 cnt += sprintf(&page[cnt], " %d",
75938- atomic_read(&rcu_torture_wcount[i]));
75939+ atomic_read_unchecked(&rcu_torture_wcount[i]));
75940 }
75941 cnt += sprintf(&page[cnt], "\n");
75942 if (cur_ops->stats)
75943@@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
75944
75945 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
75946
75947- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75948+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75949 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
75950 else if (n_online_successes != n_online_attempts ||
75951 n_offline_successes != n_offline_attempts)
75952@@ -1989,18 +1989,18 @@ rcu_torture_init(void)
75953
75954 rcu_torture_current = NULL;
75955 rcu_torture_current_version = 0;
75956- atomic_set(&n_rcu_torture_alloc, 0);
75957- atomic_set(&n_rcu_torture_alloc_fail, 0);
75958- atomic_set(&n_rcu_torture_free, 0);
75959- atomic_set(&n_rcu_torture_mberror, 0);
75960- atomic_set(&n_rcu_torture_error, 0);
75961+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
75962+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
75963+ atomic_set_unchecked(&n_rcu_torture_free, 0);
75964+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
75965+ atomic_set_unchecked(&n_rcu_torture_error, 0);
75966 n_rcu_torture_barrier_error = 0;
75967 n_rcu_torture_boost_ktrerror = 0;
75968 n_rcu_torture_boost_rterror = 0;
75969 n_rcu_torture_boost_failure = 0;
75970 n_rcu_torture_boosts = 0;
75971 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
75972- atomic_set(&rcu_torture_wcount[i], 0);
75973+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
75974 for_each_possible_cpu(cpu) {
75975 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75976 per_cpu(rcu_torture_count, cpu)[i] = 0;
75977diff --git a/kernel/rcutree.c b/kernel/rcutree.c
75978index e441b77..dd54f17 100644
75979--- a/kernel/rcutree.c
75980+++ b/kernel/rcutree.c
75981@@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
75982 rcu_prepare_for_idle(smp_processor_id());
75983 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75984 smp_mb__before_atomic_inc(); /* See above. */
75985- atomic_inc(&rdtp->dynticks);
75986+ atomic_inc_unchecked(&rdtp->dynticks);
75987 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
75988- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75989+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75990
75991 /*
75992 * It is illegal to enter an extended quiescent state while
75993@@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
75994 int user)
75995 {
75996 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
75997- atomic_inc(&rdtp->dynticks);
75998+ atomic_inc_unchecked(&rdtp->dynticks);
75999 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76000 smp_mb__after_atomic_inc(); /* See above. */
76001- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76002+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76003 rcu_cleanup_after_idle(smp_processor_id());
76004 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76005 if (!user && !is_idle_task(current)) {
76006@@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76007 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76008
76009 if (rdtp->dynticks_nmi_nesting == 0 &&
76010- (atomic_read(&rdtp->dynticks) & 0x1))
76011+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76012 return;
76013 rdtp->dynticks_nmi_nesting++;
76014 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76015- atomic_inc(&rdtp->dynticks);
76016+ atomic_inc_unchecked(&rdtp->dynticks);
76017 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76018 smp_mb__after_atomic_inc(); /* See above. */
76019- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76020+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76021 }
76022
76023 /**
76024@@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76025 return;
76026 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76027 smp_mb__before_atomic_inc(); /* See above. */
76028- atomic_inc(&rdtp->dynticks);
76029+ atomic_inc_unchecked(&rdtp->dynticks);
76030 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76031- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76032+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76033 }
76034
76035 /**
76036@@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76037 int ret;
76038
76039 preempt_disable();
76040- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76041+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76042 preempt_enable();
76043 return ret;
76044 }
76045@@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76046 */
76047 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76048 {
76049- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76050+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76051 return (rdp->dynticks_snap & 0x1) == 0;
76052 }
76053
76054@@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76055 unsigned int curr;
76056 unsigned int snap;
76057
76058- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76059+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76060 snap = (unsigned int)rdp->dynticks_snap;
76061
76062 /*
76063@@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76064 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76065 */
76066 if (till_stall_check < 3) {
76067- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76068+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76069 till_stall_check = 3;
76070 } else if (till_stall_check > 300) {
76071- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76072+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76073 till_stall_check = 300;
76074 }
76075 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76076@@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76077 rsp->qlen += rdp->qlen;
76078 rdp->n_cbs_orphaned += rdp->qlen;
76079 rdp->qlen_lazy = 0;
76080- ACCESS_ONCE(rdp->qlen) = 0;
76081+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76082 }
76083
76084 /*
76085@@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76086 }
76087 smp_mb(); /* List handling before counting for rcu_barrier(). */
76088 rdp->qlen_lazy -= count_lazy;
76089- ACCESS_ONCE(rdp->qlen) -= count;
76090+ ACCESS_ONCE_RW(rdp->qlen) -= count;
76091 rdp->n_cbs_invoked += count;
76092
76093 /* Reinstate batch limit if we have worked down the excess. */
76094@@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76095 /*
76096 * Do RCU core processing for the current CPU.
76097 */
76098-static void rcu_process_callbacks(struct softirq_action *unused)
76099+static void rcu_process_callbacks(void)
76100 {
76101 struct rcu_state *rsp;
76102
76103@@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76104 local_irq_restore(flags);
76105 return;
76106 }
76107- ACCESS_ONCE(rdp->qlen)++;
76108+ ACCESS_ONCE_RW(rdp->qlen)++;
76109 if (lazy)
76110 rdp->qlen_lazy++;
76111 else
76112@@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76113 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76114 * course be required on a 64-bit system.
76115 */
76116- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76117+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76118 (ulong)atomic_long_read(&rsp->expedited_done) +
76119 ULONG_MAX / 8)) {
76120 synchronize_sched();
76121- atomic_long_inc(&rsp->expedited_wrap);
76122+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
76123 return;
76124 }
76125
76126@@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76127 * Take a ticket. Note that atomic_inc_return() implies a
76128 * full memory barrier.
76129 */
76130- snap = atomic_long_inc_return(&rsp->expedited_start);
76131+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76132 firstsnap = snap;
76133 get_online_cpus();
76134 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76135@@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76136 synchronize_sched_expedited_cpu_stop,
76137 NULL) == -EAGAIN) {
76138 put_online_cpus();
76139- atomic_long_inc(&rsp->expedited_tryfail);
76140+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76141
76142 /* Check to see if someone else did our work for us. */
76143 s = atomic_long_read(&rsp->expedited_done);
76144 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76145 /* ensure test happens before caller kfree */
76146 smp_mb__before_atomic_inc(); /* ^^^ */
76147- atomic_long_inc(&rsp->expedited_workdone1);
76148+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76149 return;
76150 }
76151
76152@@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76153 udelay(trycount * num_online_cpus());
76154 } else {
76155 wait_rcu_gp(call_rcu_sched);
76156- atomic_long_inc(&rsp->expedited_normal);
76157+ atomic_long_inc_unchecked(&rsp->expedited_normal);
76158 return;
76159 }
76160
76161@@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76162 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76163 /* ensure test happens before caller kfree */
76164 smp_mb__before_atomic_inc(); /* ^^^ */
76165- atomic_long_inc(&rsp->expedited_workdone2);
76166+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76167 return;
76168 }
76169
76170@@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76171 * period works for us.
76172 */
76173 get_online_cpus();
76174- snap = atomic_long_read(&rsp->expedited_start);
76175+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
76176 smp_mb(); /* ensure read is before try_stop_cpus(). */
76177 }
76178- atomic_long_inc(&rsp->expedited_stoppedcpus);
76179+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76180
76181 /*
76182 * Everyone up to our most recent fetch is covered by our grace
76183@@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76184 * than we did already did their update.
76185 */
76186 do {
76187- atomic_long_inc(&rsp->expedited_done_tries);
76188+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76189 s = atomic_long_read(&rsp->expedited_done);
76190 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76191 /* ensure test happens before caller kfree */
76192 smp_mb__before_atomic_inc(); /* ^^^ */
76193- atomic_long_inc(&rsp->expedited_done_lost);
76194+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76195 break;
76196 }
76197 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76198- atomic_long_inc(&rsp->expedited_done_exit);
76199+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76200
76201 put_online_cpus();
76202 }
76203@@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76204 * ACCESS_ONCE() to prevent the compiler from speculating
76205 * the increment to precede the early-exit check.
76206 */
76207- ACCESS_ONCE(rsp->n_barrier_done)++;
76208+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76209 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76210 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76211 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76212@@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76213
76214 /* Increment ->n_barrier_done to prevent duplicate work. */
76215 smp_mb(); /* Keep increment after above mechanism. */
76216- ACCESS_ONCE(rsp->n_barrier_done)++;
76217+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76218 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76219 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76220 smp_mb(); /* Keep increment before caller's subsequent code. */
76221@@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76222 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76223 init_callback_list(rdp);
76224 rdp->qlen_lazy = 0;
76225- ACCESS_ONCE(rdp->qlen) = 0;
76226+ ACCESS_ONCE_RW(rdp->qlen) = 0;
76227 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76228 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76229- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76230+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76231 #ifdef CONFIG_RCU_USER_QS
76232 WARN_ON_ONCE(rdp->dynticks->in_user);
76233 #endif
76234@@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76235 rdp->blimit = blimit;
76236 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76237 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76238- atomic_set(&rdp->dynticks->dynticks,
76239- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76240+ atomic_set_unchecked(&rdp->dynticks->dynticks,
76241+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76242 rcu_prepare_for_idle_init(cpu);
76243 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76244
76245diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76246index 4b69291..704c92e 100644
76247--- a/kernel/rcutree.h
76248+++ b/kernel/rcutree.h
76249@@ -86,7 +86,7 @@ struct rcu_dynticks {
76250 long long dynticks_nesting; /* Track irq/process nesting level. */
76251 /* Process level is worth LLONG_MAX/2. */
76252 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76253- atomic_t dynticks; /* Even value for idle, else odd. */
76254+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76255 #ifdef CONFIG_RCU_FAST_NO_HZ
76256 int dyntick_drain; /* Prepare-for-idle state variable. */
76257 unsigned long dyntick_holdoff;
76258@@ -423,17 +423,17 @@ struct rcu_state {
76259 /* _rcu_barrier(). */
76260 /* End of fields guarded by barrier_mutex. */
76261
76262- atomic_long_t expedited_start; /* Starting ticket. */
76263- atomic_long_t expedited_done; /* Done ticket. */
76264- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76265- atomic_long_t expedited_tryfail; /* # acquisition failures. */
76266- atomic_long_t expedited_workdone1; /* # done by others #1. */
76267- atomic_long_t expedited_workdone2; /* # done by others #2. */
76268- atomic_long_t expedited_normal; /* # fallbacks to normal. */
76269- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76270- atomic_long_t expedited_done_tries; /* # tries to update _done. */
76271- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76272- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76273+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76274+ atomic_long_t expedited_done; /* Done ticket. */
76275+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76276+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76277+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76278+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76279+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76280+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76281+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76282+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76283+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76284
76285 unsigned long jiffies_force_qs; /* Time at which to invoke */
76286 /* force_quiescent_state(). */
76287diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76288index c1cc7e1..f62e436 100644
76289--- a/kernel/rcutree_plugin.h
76290+++ b/kernel/rcutree_plugin.h
76291@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76292
76293 /* Clean up and exit. */
76294 smp_mb(); /* ensure expedited GP seen before counter increment. */
76295- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76296+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76297 unlock_mb_ret:
76298 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76299 mb_ret:
76300@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76301 free_cpumask_var(cm);
76302 }
76303
76304-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76305+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76306 .store = &rcu_cpu_kthread_task,
76307 .thread_should_run = rcu_cpu_kthread_should_run,
76308 .thread_fn = rcu_cpu_kthread,
76309@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76310 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76311 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76312 cpu, ticks_value, ticks_title,
76313- atomic_read(&rdtp->dynticks) & 0xfff,
76314+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76315 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76316 fast_no_hz);
76317 }
76318@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76319
76320 /* Enqueue the callback on the nocb list and update counts. */
76321 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76322- ACCESS_ONCE(*old_rhpp) = rhp;
76323+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
76324 atomic_long_add(rhcount, &rdp->nocb_q_count);
76325 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
76326
76327@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
76328 * Extract queued callbacks, update counts, and wait
76329 * for a grace period to elapse.
76330 */
76331- ACCESS_ONCE(rdp->nocb_head) = NULL;
76332+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
76333 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
76334 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
76335 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
76336- ACCESS_ONCE(rdp->nocb_p_count) += c;
76337- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
76338+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
76339+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
76340 wait_rcu_gp(rdp->rsp->call_remote);
76341
76342 /* Each pass through the following loop invokes a callback. */
76343@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
76344 list = next;
76345 }
76346 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
76347- ACCESS_ONCE(rdp->nocb_p_count) -= c;
76348- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
76349+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
76350+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
76351 rdp->n_nocbs_invoked += c;
76352 }
76353 return 0;
76354@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
76355 rdp = per_cpu_ptr(rsp->rda, cpu);
76356 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
76357 BUG_ON(IS_ERR(t));
76358- ACCESS_ONCE(rdp->nocb_kthread) = t;
76359+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
76360 }
76361 }
76362
76363diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
76364index 0d095dc..1985b19 100644
76365--- a/kernel/rcutree_trace.c
76366+++ b/kernel/rcutree_trace.c
76367@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
76368 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
76369 rdp->passed_quiesce, rdp->qs_pending);
76370 seq_printf(m, " dt=%d/%llx/%d df=%lu",
76371- atomic_read(&rdp->dynticks->dynticks),
76372+ atomic_read_unchecked(&rdp->dynticks->dynticks),
76373 rdp->dynticks->dynticks_nesting,
76374 rdp->dynticks->dynticks_nmi_nesting,
76375 rdp->dynticks_fqs);
76376@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
76377 struct rcu_state *rsp = (struct rcu_state *)m->private;
76378
76379 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",
76380- atomic_long_read(&rsp->expedited_start),
76381+ atomic_long_read_unchecked(&rsp->expedited_start),
76382 atomic_long_read(&rsp->expedited_done),
76383- atomic_long_read(&rsp->expedited_wrap),
76384- atomic_long_read(&rsp->expedited_tryfail),
76385- atomic_long_read(&rsp->expedited_workdone1),
76386- atomic_long_read(&rsp->expedited_workdone2),
76387- atomic_long_read(&rsp->expedited_normal),
76388- atomic_long_read(&rsp->expedited_stoppedcpus),
76389- atomic_long_read(&rsp->expedited_done_tries),
76390- atomic_long_read(&rsp->expedited_done_lost),
76391- atomic_long_read(&rsp->expedited_done_exit));
76392+ atomic_long_read_unchecked(&rsp->expedited_wrap),
76393+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
76394+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
76395+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
76396+ atomic_long_read_unchecked(&rsp->expedited_normal),
76397+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
76398+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
76399+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
76400+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
76401 return 0;
76402 }
76403
76404diff --git a/kernel/resource.c b/kernel/resource.c
76405index 73f35d4..4684fc4 100644
76406--- a/kernel/resource.c
76407+++ b/kernel/resource.c
76408@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
76409
76410 static int __init ioresources_init(void)
76411 {
76412+#ifdef CONFIG_GRKERNSEC_PROC_ADD
76413+#ifdef CONFIG_GRKERNSEC_PROC_USER
76414+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
76415+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
76416+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76417+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
76418+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
76419+#endif
76420+#else
76421 proc_create("ioports", 0, NULL, &proc_ioports_operations);
76422 proc_create("iomem", 0, NULL, &proc_iomem_operations);
76423+#endif
76424 return 0;
76425 }
76426 __initcall(ioresources_init);
76427diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
76428index 98ec494..4241d6d 100644
76429--- a/kernel/rtmutex-tester.c
76430+++ b/kernel/rtmutex-tester.c
76431@@ -20,7 +20,7 @@
76432 #define MAX_RT_TEST_MUTEXES 8
76433
76434 static spinlock_t rttest_lock;
76435-static atomic_t rttest_event;
76436+static atomic_unchecked_t rttest_event;
76437
76438 struct test_thread_data {
76439 int opcode;
76440@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76441
76442 case RTTEST_LOCKCONT:
76443 td->mutexes[td->opdata] = 1;
76444- td->event = atomic_add_return(1, &rttest_event);
76445+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76446 return 0;
76447
76448 case RTTEST_RESET:
76449@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76450 return 0;
76451
76452 case RTTEST_RESETEVENT:
76453- atomic_set(&rttest_event, 0);
76454+ atomic_set_unchecked(&rttest_event, 0);
76455 return 0;
76456
76457 default:
76458@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76459 return ret;
76460
76461 td->mutexes[id] = 1;
76462- td->event = atomic_add_return(1, &rttest_event);
76463+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76464 rt_mutex_lock(&mutexes[id]);
76465- td->event = atomic_add_return(1, &rttest_event);
76466+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76467 td->mutexes[id] = 4;
76468 return 0;
76469
76470@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76471 return ret;
76472
76473 td->mutexes[id] = 1;
76474- td->event = atomic_add_return(1, &rttest_event);
76475+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76476 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
76477- td->event = atomic_add_return(1, &rttest_event);
76478+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76479 td->mutexes[id] = ret ? 0 : 4;
76480 return ret ? -EINTR : 0;
76481
76482@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76483 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
76484 return ret;
76485
76486- td->event = atomic_add_return(1, &rttest_event);
76487+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76488 rt_mutex_unlock(&mutexes[id]);
76489- td->event = atomic_add_return(1, &rttest_event);
76490+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76491 td->mutexes[id] = 0;
76492 return 0;
76493
76494@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76495 break;
76496
76497 td->mutexes[dat] = 2;
76498- td->event = atomic_add_return(1, &rttest_event);
76499+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76500 break;
76501
76502 default:
76503@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76504 return;
76505
76506 td->mutexes[dat] = 3;
76507- td->event = atomic_add_return(1, &rttest_event);
76508+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76509 break;
76510
76511 case RTTEST_LOCKNOWAIT:
76512@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76513 return;
76514
76515 td->mutexes[dat] = 1;
76516- td->event = atomic_add_return(1, &rttest_event);
76517+ td->event = atomic_add_return_unchecked(1, &rttest_event);
76518 return;
76519
76520 default:
76521diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
76522index 0984a21..939f183 100644
76523--- a/kernel/sched/auto_group.c
76524+++ b/kernel/sched/auto_group.c
76525@@ -11,7 +11,7 @@
76526
76527 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
76528 static struct autogroup autogroup_default;
76529-static atomic_t autogroup_seq_nr;
76530+static atomic_unchecked_t autogroup_seq_nr;
76531
76532 void __init autogroup_init(struct task_struct *init_task)
76533 {
76534@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
76535
76536 kref_init(&ag->kref);
76537 init_rwsem(&ag->lock);
76538- ag->id = atomic_inc_return(&autogroup_seq_nr);
76539+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
76540 ag->tg = tg;
76541 #ifdef CONFIG_RT_GROUP_SCHED
76542 /*
76543diff --git a/kernel/sched/core.c b/kernel/sched/core.c
76544index 26058d0..f9d3c76 100644
76545--- a/kernel/sched/core.c
76546+++ b/kernel/sched/core.c
76547@@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
76548 /* convert nice value [19,-20] to rlimit style value [1,40] */
76549 int nice_rlim = 20 - nice;
76550
76551+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
76552+
76553 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
76554 capable(CAP_SYS_NICE));
76555 }
76556@@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
76557 if (nice > 19)
76558 nice = 19;
76559
76560- if (increment < 0 && !can_nice(current, nice))
76561+ if (increment < 0 && (!can_nice(current, nice) ||
76562+ gr_handle_chroot_nice()))
76563 return -EPERM;
76564
76565 retval = security_task_setnice(current, nice);
76566@@ -3818,6 +3821,7 @@ recheck:
76567 unsigned long rlim_rtprio =
76568 task_rlimit(p, RLIMIT_RTPRIO);
76569
76570+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
76571 /* can't set/change the rt policy */
76572 if (policy != p->policy && !rlim_rtprio)
76573 return -EPERM;
76574@@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
76575
76576 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
76577
76578-static struct ctl_table sd_ctl_dir[] = {
76579+static ctl_table_no_const sd_ctl_dir[] __read_only = {
76580 {
76581 .procname = "sched_domain",
76582 .mode = 0555,
76583@@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
76584 {}
76585 };
76586
76587-static struct ctl_table *sd_alloc_ctl_entry(int n)
76588+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
76589 {
76590- struct ctl_table *entry =
76591+ ctl_table_no_const *entry =
76592 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
76593
76594 return entry;
76595 }
76596
76597-static void sd_free_ctl_entry(struct ctl_table **tablep)
76598+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
76599 {
76600- struct ctl_table *entry;
76601+ ctl_table_no_const *entry;
76602
76603 /*
76604 * In the intermediate directories, both the child directory and
76605@@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
76606 * will always be set. In the lowest directory the names are
76607 * static strings and all have proc handlers.
76608 */
76609- for (entry = *tablep; entry->mode; entry++) {
76610- if (entry->child)
76611- sd_free_ctl_entry(&entry->child);
76612+ for (entry = tablep; entry->mode; entry++) {
76613+ if (entry->child) {
76614+ sd_free_ctl_entry(entry->child);
76615+ pax_open_kernel();
76616+ entry->child = NULL;
76617+ pax_close_kernel();
76618+ }
76619 if (entry->proc_handler == NULL)
76620 kfree(entry->procname);
76621 }
76622
76623- kfree(*tablep);
76624- *tablep = NULL;
76625+ kfree(tablep);
76626 }
76627
76628 static int min_load_idx = 0;
76629 static int max_load_idx = CPU_LOAD_IDX_MAX;
76630
76631 static void
76632-set_table_entry(struct ctl_table *entry,
76633+set_table_entry(ctl_table_no_const *entry,
76634 const char *procname, void *data, int maxlen,
76635 umode_t mode, proc_handler *proc_handler,
76636 bool load_idx)
76637@@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
76638 static struct ctl_table *
76639 sd_alloc_ctl_domain_table(struct sched_domain *sd)
76640 {
76641- struct ctl_table *table = sd_alloc_ctl_entry(13);
76642+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
76643
76644 if (table == NULL)
76645 return NULL;
76646@@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
76647 return table;
76648 }
76649
76650-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
76651+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
76652 {
76653- struct ctl_table *entry, *table;
76654+ ctl_table_no_const *entry, *table;
76655 struct sched_domain *sd;
76656 int domain_num = 0, i;
76657 char buf[32];
76658@@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
76659 static void register_sched_domain_sysctl(void)
76660 {
76661 int i, cpu_num = num_possible_cpus();
76662- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
76663+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
76664 char buf[32];
76665
76666 WARN_ON(sd_ctl_dir[0].child);
76667+ pax_open_kernel();
76668 sd_ctl_dir[0].child = entry;
76669+ pax_close_kernel();
76670
76671 if (entry == NULL)
76672 return;
76673@@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
76674 if (sd_sysctl_header)
76675 unregister_sysctl_table(sd_sysctl_header);
76676 sd_sysctl_header = NULL;
76677- if (sd_ctl_dir[0].child)
76678- sd_free_ctl_entry(&sd_ctl_dir[0].child);
76679+ if (sd_ctl_dir[0].child) {
76680+ sd_free_ctl_entry(sd_ctl_dir[0].child);
76681+ pax_open_kernel();
76682+ sd_ctl_dir[0].child = NULL;
76683+ pax_close_kernel();
76684+ }
76685 }
76686 #else
76687 static void register_sched_domain_sysctl(void)
76688@@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
76689 * happens before everything else. This has to be lower priority than
76690 * the notifier in the perf_event subsystem, though.
76691 */
76692-static struct notifier_block __cpuinitdata migration_notifier = {
76693+static struct notifier_block migration_notifier = {
76694 .notifier_call = migration_call,
76695 .priority = CPU_PRI_MIGRATION,
76696 };
76697diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
76698index 81fa536..6ccf96a 100644
76699--- a/kernel/sched/fair.c
76700+++ b/kernel/sched/fair.c
76701@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
76702
76703 static void reset_ptenuma_scan(struct task_struct *p)
76704 {
76705- ACCESS_ONCE(p->mm->numa_scan_seq)++;
76706+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
76707 p->mm->numa_scan_offset = 0;
76708 }
76709
76710@@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
76711 */
76712 static int select_idle_sibling(struct task_struct *p, int target)
76713 {
76714- int cpu = smp_processor_id();
76715- int prev_cpu = task_cpu(p);
76716 struct sched_domain *sd;
76717 struct sched_group *sg;
76718- int i;
76719+ int i = task_cpu(p);
76720
76721- /*
76722- * If the task is going to be woken-up on this cpu and if it is
76723- * already idle, then it is the right target.
76724- */
76725- if (target == cpu && idle_cpu(cpu))
76726- return cpu;
76727+ if (idle_cpu(target))
76728+ return target;
76729
76730 /*
76731- * If the task is going to be woken-up on the cpu where it previously
76732- * ran and if it is currently idle, then it the right target.
76733+ * If the prevous cpu is cache affine and idle, don't be stupid.
76734 */
76735- if (target == prev_cpu && idle_cpu(prev_cpu))
76736- return prev_cpu;
76737+ if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
76738+ return i;
76739
76740 /*
76741 * Otherwise, iterate the domains and find an elegible idle cpu.
76742@@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
76743 goto next;
76744
76745 for_each_cpu(i, sched_group_cpus(sg)) {
76746- if (!idle_cpu(i))
76747+ if (i == target || !idle_cpu(i))
76748 goto next;
76749 }
76750
76751@@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
76752 * run_rebalance_domains is triggered when needed from the scheduler tick.
76753 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
76754 */
76755-static void run_rebalance_domains(struct softirq_action *h)
76756+static void run_rebalance_domains(void)
76757 {
76758 int this_cpu = smp_processor_id();
76759 struct rq *this_rq = cpu_rq(this_cpu);
76760diff --git a/kernel/signal.c b/kernel/signal.c
76761index 3d09cf6..8988390 100644
76762--- a/kernel/signal.c
76763+++ b/kernel/signal.c
76764@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
76765
76766 int print_fatal_signals __read_mostly;
76767
76768-static void __user *sig_handler(struct task_struct *t, int sig)
76769+static __sighandler_t sig_handler(struct task_struct *t, int sig)
76770 {
76771 return t->sighand->action[sig - 1].sa.sa_handler;
76772 }
76773
76774-static int sig_handler_ignored(void __user *handler, int sig)
76775+static int sig_handler_ignored(__sighandler_t handler, int sig)
76776 {
76777 /* Is it explicitly or implicitly ignored? */
76778 return handler == SIG_IGN ||
76779@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
76780
76781 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
76782 {
76783- void __user *handler;
76784+ __sighandler_t handler;
76785
76786 handler = sig_handler(t, sig);
76787
76788@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
76789 atomic_inc(&user->sigpending);
76790 rcu_read_unlock();
76791
76792+ if (!override_rlimit)
76793+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
76794+
76795 if (override_rlimit ||
76796 atomic_read(&user->sigpending) <=
76797 task_rlimit(t, RLIMIT_SIGPENDING)) {
76798@@ -485,6 +488,9 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76799 if (force_default || ka->sa.sa_handler != SIG_IGN)
76800 ka->sa.sa_handler = SIG_DFL;
76801 ka->sa.sa_flags = 0;
76802+#ifdef SA_RESTORER
76803+ ka->sa.sa_restorer = NULL;
76804+#endif
76805 sigemptyset(&ka->sa.sa_mask);
76806 ka++;
76807 }
76808@@ -492,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76809
76810 int unhandled_signal(struct task_struct *tsk, int sig)
76811 {
76812- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
76813+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
76814 if (is_global_init(tsk))
76815 return 1;
76816 if (handler != SIG_IGN && handler != SIG_DFL)
76817@@ -812,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
76818 }
76819 }
76820
76821+ /* allow glibc communication via tgkill to other threads in our
76822+ thread group */
76823+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
76824+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
76825+ && gr_handle_signal(t, sig))
76826+ return -EPERM;
76827+
76828 return security_task_kill(t, info, sig, 0);
76829 }
76830
76831@@ -1194,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76832 return send_signal(sig, info, p, 1);
76833 }
76834
76835-static int
76836+int
76837 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76838 {
76839 return send_signal(sig, info, t, 0);
76840@@ -1231,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76841 unsigned long int flags;
76842 int ret, blocked, ignored;
76843 struct k_sigaction *action;
76844+ int is_unhandled = 0;
76845
76846 spin_lock_irqsave(&t->sighand->siglock, flags);
76847 action = &t->sighand->action[sig-1];
76848@@ -1245,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76849 }
76850 if (action->sa.sa_handler == SIG_DFL)
76851 t->signal->flags &= ~SIGNAL_UNKILLABLE;
76852+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
76853+ is_unhandled = 1;
76854 ret = specific_send_sig_info(sig, info, t);
76855 spin_unlock_irqrestore(&t->sighand->siglock, flags);
76856
76857+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
76858+ normal operation */
76859+ if (is_unhandled) {
76860+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
76861+ gr_handle_crash(t, sig);
76862+ }
76863+
76864 return ret;
76865 }
76866
76867@@ -1314,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76868 ret = check_kill_permission(sig, info, p);
76869 rcu_read_unlock();
76870
76871- if (!ret && sig)
76872+ if (!ret && sig) {
76873 ret = do_send_sig_info(sig, info, p, true);
76874+ if (!ret)
76875+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
76876+ }
76877
76878 return ret;
76879 }
76880@@ -2852,7 +2878,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
76881 int error = -ESRCH;
76882
76883 rcu_read_lock();
76884- p = find_task_by_vpid(pid);
76885+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76886+ /* allow glibc communication via tgkill to other threads in our
76887+ thread group */
76888+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
76889+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
76890+ p = find_task_by_vpid_unrestricted(pid);
76891+ else
76892+#endif
76893+ p = find_task_by_vpid(pid);
76894 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
76895 error = check_kill_permission(sig, info, p);
76896 /*
76897@@ -3135,8 +3169,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
76898 }
76899 seg = get_fs();
76900 set_fs(KERNEL_DS);
76901- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
76902- (stack_t __force __user *) &uoss,
76903+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
76904+ (stack_t __force_user *) &uoss,
76905 compat_user_stack_pointer());
76906 set_fs(seg);
76907 if (ret >= 0 && uoss_ptr) {
76908diff --git a/kernel/smp.c b/kernel/smp.c
76909index 69f38bd..77bbf12 100644
76910--- a/kernel/smp.c
76911+++ b/kernel/smp.c
76912@@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
76913 return NOTIFY_OK;
76914 }
76915
76916-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
76917+static struct notifier_block hotplug_cfd_notifier = {
76918 .notifier_call = hotplug_cfd,
76919 };
76920
76921diff --git a/kernel/smpboot.c b/kernel/smpboot.c
76922index d6c5fc0..530560c 100644
76923--- a/kernel/smpboot.c
76924+++ b/kernel/smpboot.c
76925@@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
76926 }
76927 smpboot_unpark_thread(plug_thread, cpu);
76928 }
76929- list_add(&plug_thread->list, &hotplug_threads);
76930+ pax_list_add(&plug_thread->list, &hotplug_threads);
76931 out:
76932 mutex_unlock(&smpboot_threads_lock);
76933 return ret;
76934@@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
76935 {
76936 get_online_cpus();
76937 mutex_lock(&smpboot_threads_lock);
76938- list_del(&plug_thread->list);
76939+ pax_list_del(&plug_thread->list);
76940 smpboot_destroy_threads(plug_thread);
76941 mutex_unlock(&smpboot_threads_lock);
76942 put_online_cpus();
76943diff --git a/kernel/softirq.c b/kernel/softirq.c
76944index ed567ba..e71dabf 100644
76945--- a/kernel/softirq.c
76946+++ b/kernel/softirq.c
76947@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
76948 EXPORT_SYMBOL(irq_stat);
76949 #endif
76950
76951-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
76952+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
76953
76954 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
76955
76956-char *softirq_to_name[NR_SOFTIRQS] = {
76957+const char * const softirq_to_name[NR_SOFTIRQS] = {
76958 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
76959 "TASKLET", "SCHED", "HRTIMER", "RCU"
76960 };
76961@@ -244,7 +244,7 @@ restart:
76962 kstat_incr_softirqs_this_cpu(vec_nr);
76963
76964 trace_softirq_entry(vec_nr);
76965- h->action(h);
76966+ h->action();
76967 trace_softirq_exit(vec_nr);
76968 if (unlikely(prev_count != preempt_count())) {
76969 printk(KERN_ERR "huh, entered softirq %u %s %p"
76970@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
76971 or_softirq_pending(1UL << nr);
76972 }
76973
76974-void open_softirq(int nr, void (*action)(struct softirq_action *))
76975+void __init open_softirq(int nr, void (*action)(void))
76976 {
76977 softirq_vec[nr].action = action;
76978 }
76979@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
76980
76981 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
76982
76983-static void tasklet_action(struct softirq_action *a)
76984+static void tasklet_action(void)
76985 {
76986 struct tasklet_struct *list;
76987
76988@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
76989 }
76990 }
76991
76992-static void tasklet_hi_action(struct softirq_action *a)
76993+static void tasklet_hi_action(void)
76994 {
76995 struct tasklet_struct *list;
76996
76997@@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
76998 return NOTIFY_OK;
76999 }
77000
77001-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
77002+static struct notifier_block remote_softirq_cpu_notifier = {
77003 .notifier_call = remote_softirq_cpu_notify,
77004 };
77005
77006@@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
77007 return NOTIFY_OK;
77008 }
77009
77010-static struct notifier_block __cpuinitdata cpu_nfb = {
77011+static struct notifier_block cpu_nfb = {
77012 .notifier_call = cpu_callback
77013 };
77014
77015-static struct smp_hotplug_thread softirq_threads = {
77016+static struct smp_hotplug_thread softirq_threads __read_only = {
77017 .store = &ksoftirqd,
77018 .thread_should_run = ksoftirqd_should_run,
77019 .thread_fn = run_ksoftirqd,
77020diff --git a/kernel/srcu.c b/kernel/srcu.c
77021index 2b85982..d52ab26 100644
77022--- a/kernel/srcu.c
77023+++ b/kernel/srcu.c
77024@@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77025 preempt_disable();
77026 idx = rcu_dereference_index_check(sp->completed,
77027 rcu_read_lock_sched_held()) & 0x1;
77028- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77029+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77030 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77031- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77032+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77033 preempt_enable();
77034 return idx;
77035 }
77036@@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77037 {
77038 preempt_disable();
77039 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77040- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77041+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77042 preempt_enable();
77043 }
77044 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77045diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77046index 2f194e9..2c05ea9 100644
77047--- a/kernel/stop_machine.c
77048+++ b/kernel/stop_machine.c
77049@@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77050 * cpu notifiers. It currently shares the same priority as sched
77051 * migration_notifier.
77052 */
77053-static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77054+static struct notifier_block cpu_stop_cpu_notifier = {
77055 .notifier_call = cpu_stop_cpu_callback,
77056 .priority = 10,
77057 };
77058diff --git a/kernel/sys.c b/kernel/sys.c
77059index 265b376..4e42ef5 100644
77060--- a/kernel/sys.c
77061+++ b/kernel/sys.c
77062@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77063 error = -EACCES;
77064 goto out;
77065 }
77066+
77067+ if (gr_handle_chroot_setpriority(p, niceval)) {
77068+ error = -EACCES;
77069+ goto out;
77070+ }
77071+
77072 no_nice = security_task_setnice(p, niceval);
77073 if (no_nice) {
77074 error = no_nice;
77075@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77076 goto error;
77077 }
77078
77079+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77080+ goto error;
77081+
77082 if (rgid != (gid_t) -1 ||
77083 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77084 new->sgid = new->egid;
77085@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77086 old = current_cred();
77087
77088 retval = -EPERM;
77089+
77090+ if (gr_check_group_change(kgid, kgid, kgid))
77091+ goto error;
77092+
77093 if (nsown_capable(CAP_SETGID))
77094 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77095 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77096@@ -647,7 +660,7 @@ error:
77097 /*
77098 * change the user struct in a credentials set to match the new UID
77099 */
77100-static int set_user(struct cred *new)
77101+int set_user(struct cred *new)
77102 {
77103 struct user_struct *new_user;
77104
77105@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77106 goto error;
77107 }
77108
77109+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77110+ goto error;
77111+
77112 if (!uid_eq(new->uid, old->uid)) {
77113 retval = set_user(new);
77114 if (retval < 0)
77115@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77116 old = current_cred();
77117
77118 retval = -EPERM;
77119+
77120+ if (gr_check_crash_uid(kuid))
77121+ goto error;
77122+ if (gr_check_user_change(kuid, kuid, kuid))
77123+ goto error;
77124+
77125 if (nsown_capable(CAP_SETUID)) {
77126 new->suid = new->uid = kuid;
77127 if (!uid_eq(kuid, old->uid)) {
77128@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77129 goto error;
77130 }
77131
77132+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
77133+ goto error;
77134+
77135 if (ruid != (uid_t) -1) {
77136 new->uid = kruid;
77137 if (!uid_eq(kruid, old->uid)) {
77138@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77139 goto error;
77140 }
77141
77142+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
77143+ goto error;
77144+
77145 if (rgid != (gid_t) -1)
77146 new->gid = krgid;
77147 if (egid != (gid_t) -1)
77148@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77149 if (!uid_valid(kuid))
77150 return old_fsuid;
77151
77152+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77153+ goto error;
77154+
77155 new = prepare_creds();
77156 if (!new)
77157 return old_fsuid;
77158@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77159 }
77160 }
77161
77162+error:
77163 abort_creds(new);
77164 return old_fsuid;
77165
77166@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77167 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77168 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77169 nsown_capable(CAP_SETGID)) {
77170+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77171+ goto error;
77172+
77173 if (!gid_eq(kgid, old->fsgid)) {
77174 new->fsgid = kgid;
77175 goto change_okay;
77176 }
77177 }
77178
77179+error:
77180 abort_creds(new);
77181 return old_fsgid;
77182
77183@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77184 return -EFAULT;
77185
77186 down_read(&uts_sem);
77187- error = __copy_to_user(&name->sysname, &utsname()->sysname,
77188+ error = __copy_to_user(name->sysname, &utsname()->sysname,
77189 __OLD_UTS_LEN);
77190 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77191- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77192+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
77193 __OLD_UTS_LEN);
77194 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77195- error |= __copy_to_user(&name->release, &utsname()->release,
77196+ error |= __copy_to_user(name->release, &utsname()->release,
77197 __OLD_UTS_LEN);
77198 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77199- error |= __copy_to_user(&name->version, &utsname()->version,
77200+ error |= __copy_to_user(name->version, &utsname()->version,
77201 __OLD_UTS_LEN);
77202 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77203- error |= __copy_to_user(&name->machine, &utsname()->machine,
77204+ error |= __copy_to_user(name->machine, &utsname()->machine,
77205 __OLD_UTS_LEN);
77206 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77207 up_read(&uts_sem);
77208@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77209 error = get_dumpable(me->mm);
77210 break;
77211 case PR_SET_DUMPABLE:
77212- if (arg2 < 0 || arg2 > 1) {
77213+ if (arg2 > 1) {
77214 error = -EINVAL;
77215 break;
77216 }
77217diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77218index c88878d..e4fa5d1 100644
77219--- a/kernel/sysctl.c
77220+++ b/kernel/sysctl.c
77221@@ -92,7 +92,6 @@
77222
77223
77224 #if defined(CONFIG_SYSCTL)
77225-
77226 /* External variables not in a header file. */
77227 extern int sysctl_overcommit_memory;
77228 extern int sysctl_overcommit_ratio;
77229@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77230 void __user *buffer, size_t *lenp, loff_t *ppos);
77231 #endif
77232
77233-#ifdef CONFIG_PRINTK
77234 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77235 void __user *buffer, size_t *lenp, loff_t *ppos);
77236-#endif
77237
77238 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77239 void __user *buffer, size_t *lenp, loff_t *ppos);
77240@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77241
77242 #endif
77243
77244+extern struct ctl_table grsecurity_table[];
77245+
77246 static struct ctl_table kern_table[];
77247 static struct ctl_table vm_table[];
77248 static struct ctl_table fs_table[];
77249@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77250 int sysctl_legacy_va_layout;
77251 #endif
77252
77253+#ifdef CONFIG_PAX_SOFTMODE
77254+static ctl_table pax_table[] = {
77255+ {
77256+ .procname = "softmode",
77257+ .data = &pax_softmode,
77258+ .maxlen = sizeof(unsigned int),
77259+ .mode = 0600,
77260+ .proc_handler = &proc_dointvec,
77261+ },
77262+
77263+ { }
77264+};
77265+#endif
77266+
77267 /* The default sysctl tables: */
77268
77269 static struct ctl_table sysctl_base_table[] = {
77270@@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77271 #endif
77272
77273 static struct ctl_table kern_table[] = {
77274+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77275+ {
77276+ .procname = "grsecurity",
77277+ .mode = 0500,
77278+ .child = grsecurity_table,
77279+ },
77280+#endif
77281+
77282+#ifdef CONFIG_PAX_SOFTMODE
77283+ {
77284+ .procname = "pax",
77285+ .mode = 0500,
77286+ .child = pax_table,
77287+ },
77288+#endif
77289+
77290 {
77291 .procname = "sched_child_runs_first",
77292 .data = &sysctl_sched_child_runs_first,
77293@@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77294 .data = &modprobe_path,
77295 .maxlen = KMOD_PATH_LEN,
77296 .mode = 0644,
77297- .proc_handler = proc_dostring,
77298+ .proc_handler = proc_dostring_modpriv,
77299 },
77300 {
77301 .procname = "modules_disabled",
77302@@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77303 .extra1 = &zero,
77304 .extra2 = &one,
77305 },
77306+#endif
77307 {
77308 .procname = "kptr_restrict",
77309 .data = &kptr_restrict,
77310 .maxlen = sizeof(int),
77311 .mode = 0644,
77312 .proc_handler = proc_dointvec_minmax_sysadmin,
77313+#ifdef CONFIG_GRKERNSEC_HIDESYM
77314+ .extra1 = &two,
77315+#else
77316 .extra1 = &zero,
77317+#endif
77318 .extra2 = &two,
77319 },
77320-#endif
77321 {
77322 .procname = "ngroups_max",
77323 .data = &ngroups_max,
77324@@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
77325 .proc_handler = proc_dointvec_minmax,
77326 .extra1 = &zero,
77327 },
77328+ {
77329+ .procname = "heap_stack_gap",
77330+ .data = &sysctl_heap_stack_gap,
77331+ .maxlen = sizeof(sysctl_heap_stack_gap),
77332+ .mode = 0644,
77333+ .proc_handler = proc_doulongvec_minmax,
77334+ },
77335 #else
77336 {
77337 .procname = "nr_trim_pages",
77338@@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
77339 buffer, lenp, ppos);
77340 }
77341
77342+int proc_dostring_modpriv(struct ctl_table *table, int write,
77343+ void __user *buffer, size_t *lenp, loff_t *ppos)
77344+{
77345+ if (write && !capable(CAP_SYS_MODULE))
77346+ return -EPERM;
77347+
77348+ return _proc_do_string(table->data, table->maxlen, write,
77349+ buffer, lenp, ppos);
77350+}
77351+
77352 static size_t proc_skip_spaces(char **buf)
77353 {
77354 size_t ret;
77355@@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
77356 len = strlen(tmp);
77357 if (len > *size)
77358 len = *size;
77359+ if (len > sizeof(tmp))
77360+ len = sizeof(tmp);
77361 if (copy_to_user(*buf, tmp, len))
77362 return -EFAULT;
77363 *size -= len;
77364@@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
77365 static int proc_taint(struct ctl_table *table, int write,
77366 void __user *buffer, size_t *lenp, loff_t *ppos)
77367 {
77368- struct ctl_table t;
77369+ ctl_table_no_const t;
77370 unsigned long tmptaint = get_taint();
77371 int err;
77372
77373@@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
77374 return err;
77375 }
77376
77377-#ifdef CONFIG_PRINTK
77378 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77379 void __user *buffer, size_t *lenp, loff_t *ppos)
77380 {
77381@@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77382
77383 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
77384 }
77385-#endif
77386
77387 struct do_proc_dointvec_minmax_conv_param {
77388 int *min;
77389@@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
77390 *i = val;
77391 } else {
77392 val = convdiv * (*i) / convmul;
77393- if (!first)
77394+ if (!first) {
77395 err = proc_put_char(&buffer, &left, '\t');
77396+ if (err)
77397+ break;
77398+ }
77399 err = proc_put_long(&buffer, &left, val, false);
77400 if (err)
77401 break;
77402@@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
77403 return -ENOSYS;
77404 }
77405
77406+int proc_dostring_modpriv(struct ctl_table *table, int write,
77407+ void __user *buffer, size_t *lenp, loff_t *ppos)
77408+{
77409+ return -ENOSYS;
77410+}
77411+
77412 int proc_dointvec(struct ctl_table *table, int write,
77413 void __user *buffer, size_t *lenp, loff_t *ppos)
77414 {
77415@@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
77416 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
77417 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
77418 EXPORT_SYMBOL(proc_dostring);
77419+EXPORT_SYMBOL(proc_dostring_modpriv);
77420 EXPORT_SYMBOL(proc_doulongvec_minmax);
77421 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
77422diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
77423index 0ddf3a0..a199f50 100644
77424--- a/kernel/sysctl_binary.c
77425+++ b/kernel/sysctl_binary.c
77426@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
77427 int i;
77428
77429 set_fs(KERNEL_DS);
77430- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77431+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77432 set_fs(old_fs);
77433 if (result < 0)
77434 goto out_kfree;
77435@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
77436 }
77437
77438 set_fs(KERNEL_DS);
77439- result = vfs_write(file, buffer, str - buffer, &pos);
77440+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77441 set_fs(old_fs);
77442 if (result < 0)
77443 goto out_kfree;
77444@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
77445 int i;
77446
77447 set_fs(KERNEL_DS);
77448- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77449+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77450 set_fs(old_fs);
77451 if (result < 0)
77452 goto out_kfree;
77453@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
77454 }
77455
77456 set_fs(KERNEL_DS);
77457- result = vfs_write(file, buffer, str - buffer, &pos);
77458+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77459 set_fs(old_fs);
77460 if (result < 0)
77461 goto out_kfree;
77462@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
77463 int i;
77464
77465 set_fs(KERNEL_DS);
77466- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77467+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77468 set_fs(old_fs);
77469 if (result < 0)
77470 goto out;
77471@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77472 __le16 dnaddr;
77473
77474 set_fs(KERNEL_DS);
77475- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77476+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77477 set_fs(old_fs);
77478 if (result < 0)
77479 goto out;
77480@@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77481 le16_to_cpu(dnaddr) & 0x3ff);
77482
77483 set_fs(KERNEL_DS);
77484- result = vfs_write(file, buf, len, &pos);
77485+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
77486 set_fs(old_fs);
77487 if (result < 0)
77488 goto out;
77489diff --git a/kernel/taskstats.c b/kernel/taskstats.c
77490index 145bb4d..b2aa969 100644
77491--- a/kernel/taskstats.c
77492+++ b/kernel/taskstats.c
77493@@ -28,9 +28,12 @@
77494 #include <linux/fs.h>
77495 #include <linux/file.h>
77496 #include <linux/pid_namespace.h>
77497+#include <linux/grsecurity.h>
77498 #include <net/genetlink.h>
77499 #include <linux/atomic.h>
77500
77501+extern int gr_is_taskstats_denied(int pid);
77502+
77503 /*
77504 * Maximum length of a cpumask that can be specified in
77505 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
77506@@ -570,6 +573,9 @@ err:
77507
77508 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
77509 {
77510+ if (gr_is_taskstats_denied(current->pid))
77511+ return -EACCES;
77512+
77513 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
77514 return cmd_attr_register_cpumask(info);
77515 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
77516diff --git a/kernel/time.c b/kernel/time.c
77517index d226c6a..c7c0960 100644
77518--- a/kernel/time.c
77519+++ b/kernel/time.c
77520@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
77521 return error;
77522
77523 if (tz) {
77524+ /* we log in do_settimeofday called below, so don't log twice
77525+ */
77526+ if (!tv)
77527+ gr_log_timechange();
77528+
77529 sys_tz = *tz;
77530 update_vsyscall_tz();
77531 if (firsttime) {
77532diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
77533index f11d83b..d016d91 100644
77534--- a/kernel/time/alarmtimer.c
77535+++ b/kernel/time/alarmtimer.c
77536@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
77537 struct platform_device *pdev;
77538 int error = 0;
77539 int i;
77540- struct k_clock alarm_clock = {
77541+ static struct k_clock alarm_clock = {
77542 .clock_getres = alarm_clock_getres,
77543 .clock_get = alarm_clock_get,
77544 .timer_create = alarm_timer_create,
77545diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
77546index f113755..ec24223 100644
77547--- a/kernel/time/tick-broadcast.c
77548+++ b/kernel/time/tick-broadcast.c
77549@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
77550 * then clear the broadcast bit.
77551 */
77552 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
77553- int cpu = smp_processor_id();
77554+ cpu = smp_processor_id();
77555
77556 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
77557 tick_broadcast_clear_oneshot(cpu);
77558diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
77559index cbc6acb..3a77191 100644
77560--- a/kernel/time/timekeeping.c
77561+++ b/kernel/time/timekeeping.c
77562@@ -15,6 +15,7 @@
77563 #include <linux/init.h>
77564 #include <linux/mm.h>
77565 #include <linux/sched.h>
77566+#include <linux/grsecurity.h>
77567 #include <linux/syscore_ops.h>
77568 #include <linux/clocksource.h>
77569 #include <linux/jiffies.h>
77570@@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
77571 if (!timespec_valid_strict(tv))
77572 return -EINVAL;
77573
77574+ gr_log_timechange();
77575+
77576 write_seqlock_irqsave(&tk->lock, flags);
77577
77578 timekeeping_forward_now(tk);
77579diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
77580index af5a7e9..715611a 100644
77581--- a/kernel/time/timer_list.c
77582+++ b/kernel/time/timer_list.c
77583@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
77584
77585 static void print_name_offset(struct seq_file *m, void *sym)
77586 {
77587+#ifdef CONFIG_GRKERNSEC_HIDESYM
77588+ SEQ_printf(m, "<%p>", NULL);
77589+#else
77590 char symname[KSYM_NAME_LEN];
77591
77592 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
77593 SEQ_printf(m, "<%pK>", sym);
77594 else
77595 SEQ_printf(m, "%s", symname);
77596+#endif
77597 }
77598
77599 static void
77600@@ -112,7 +116,11 @@ next_one:
77601 static void
77602 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
77603 {
77604+#ifdef CONFIG_GRKERNSEC_HIDESYM
77605+ SEQ_printf(m, " .base: %p\n", NULL);
77606+#else
77607 SEQ_printf(m, " .base: %pK\n", base);
77608+#endif
77609 SEQ_printf(m, " .index: %d\n",
77610 base->index);
77611 SEQ_printf(m, " .resolution: %Lu nsecs\n",
77612@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
77613 {
77614 struct proc_dir_entry *pe;
77615
77616+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77617+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
77618+#else
77619 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
77620+#endif
77621 if (!pe)
77622 return -ENOMEM;
77623 return 0;
77624diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
77625index 0b537f2..40d6c20 100644
77626--- a/kernel/time/timer_stats.c
77627+++ b/kernel/time/timer_stats.c
77628@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
77629 static unsigned long nr_entries;
77630 static struct entry entries[MAX_ENTRIES];
77631
77632-static atomic_t overflow_count;
77633+static atomic_unchecked_t overflow_count;
77634
77635 /*
77636 * The entries are in a hash-table, for fast lookup:
77637@@ -140,7 +140,7 @@ static void reset_entries(void)
77638 nr_entries = 0;
77639 memset(entries, 0, sizeof(entries));
77640 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
77641- atomic_set(&overflow_count, 0);
77642+ atomic_set_unchecked(&overflow_count, 0);
77643 }
77644
77645 static struct entry *alloc_entry(void)
77646@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77647 if (likely(entry))
77648 entry->count++;
77649 else
77650- atomic_inc(&overflow_count);
77651+ atomic_inc_unchecked(&overflow_count);
77652
77653 out_unlock:
77654 raw_spin_unlock_irqrestore(lock, flags);
77655@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77656
77657 static void print_name_offset(struct seq_file *m, unsigned long addr)
77658 {
77659+#ifdef CONFIG_GRKERNSEC_HIDESYM
77660+ seq_printf(m, "<%p>", NULL);
77661+#else
77662 char symname[KSYM_NAME_LEN];
77663
77664 if (lookup_symbol_name(addr, symname) < 0)
77665- seq_printf(m, "<%p>", (void *)addr);
77666+ seq_printf(m, "<%pK>", (void *)addr);
77667 else
77668 seq_printf(m, "%s", symname);
77669+#endif
77670 }
77671
77672 static int tstats_show(struct seq_file *m, void *v)
77673@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
77674
77675 seq_puts(m, "Timer Stats Version: v0.2\n");
77676 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
77677- if (atomic_read(&overflow_count))
77678+ if (atomic_read_unchecked(&overflow_count))
77679 seq_printf(m, "Overflow: %d entries\n",
77680- atomic_read(&overflow_count));
77681+ atomic_read_unchecked(&overflow_count));
77682
77683 for (i = 0; i < nr_entries; i++) {
77684 entry = entries + i;
77685@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
77686 {
77687 struct proc_dir_entry *pe;
77688
77689+#ifdef CONFIG_GRKERNSEC_PROC_ADD
77690+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
77691+#else
77692 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
77693+#endif
77694 if (!pe)
77695 return -ENOMEM;
77696 return 0;
77697diff --git a/kernel/timer.c b/kernel/timer.c
77698index 367d008..1ee9ed9 100644
77699--- a/kernel/timer.c
77700+++ b/kernel/timer.c
77701@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
77702 /*
77703 * This function runs timers and the timer-tq in bottom half context.
77704 */
77705-static void run_timer_softirq(struct softirq_action *h)
77706+static void run_timer_softirq(void)
77707 {
77708 struct tvec_base *base = __this_cpu_read(tvec_bases);
77709
77710@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
77711 return NOTIFY_OK;
77712 }
77713
77714-static struct notifier_block __cpuinitdata timers_nb = {
77715+static struct notifier_block timers_nb = {
77716 .notifier_call = timer_cpu_notify,
77717 };
77718
77719diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
77720index c0bd030..62a1927 100644
77721--- a/kernel/trace/blktrace.c
77722+++ b/kernel/trace/blktrace.c
77723@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
77724 struct blk_trace *bt = filp->private_data;
77725 char buf[16];
77726
77727- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
77728+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
77729
77730 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
77731 }
77732@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
77733 return 1;
77734
77735 bt = buf->chan->private_data;
77736- atomic_inc(&bt->dropped);
77737+ atomic_inc_unchecked(&bt->dropped);
77738 return 0;
77739 }
77740
77741@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
77742
77743 bt->dir = dir;
77744 bt->dev = dev;
77745- atomic_set(&bt->dropped, 0);
77746+ atomic_set_unchecked(&bt->dropped, 0);
77747
77748 ret = -EIO;
77749 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
77750diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
77751index 43defd1..76da436 100644
77752--- a/kernel/trace/ftrace.c
77753+++ b/kernel/trace/ftrace.c
77754@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
77755 if (unlikely(ftrace_disabled))
77756 return 0;
77757
77758+ ret = ftrace_arch_code_modify_prepare();
77759+ FTRACE_WARN_ON(ret);
77760+ if (ret)
77761+ return 0;
77762+
77763 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
77764+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
77765 if (ret) {
77766 ftrace_bug(ret, ip);
77767- return 0;
77768 }
77769- return 1;
77770+ return ret ? 0 : 1;
77771 }
77772
77773 /*
77774@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
77775
77776 int
77777 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
77778- void *data)
77779+ void *data)
77780 {
77781 struct ftrace_func_probe *entry;
77782 struct ftrace_page *pg;
77783@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
77784 if (!count)
77785 return 0;
77786
77787+ pax_open_kernel();
77788 sort(start, count, sizeof(*start),
77789 ftrace_cmp_ips, ftrace_swap_ips);
77790+ pax_close_kernel();
77791
77792 start_pg = ftrace_allocate_pages(count);
77793 if (!start_pg)
77794@@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
77795 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
77796
77797 static int ftrace_graph_active;
77798-static struct notifier_block ftrace_suspend_notifier;
77799-
77800 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
77801 {
77802 return 0;
77803@@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
77804 return NOTIFY_DONE;
77805 }
77806
77807+static struct notifier_block ftrace_suspend_notifier = {
77808+ .notifier_call = ftrace_suspend_notifier_call
77809+};
77810+
77811 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77812 trace_func_graph_ent_t entryfunc)
77813 {
77814@@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77815 goto out;
77816 }
77817
77818- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
77819 register_pm_notifier(&ftrace_suspend_notifier);
77820
77821 ftrace_graph_active++;
77822diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
77823index ce8514f..8233573 100644
77824--- a/kernel/trace/ring_buffer.c
77825+++ b/kernel/trace/ring_buffer.c
77826@@ -346,9 +346,9 @@ struct buffer_data_page {
77827 */
77828 struct buffer_page {
77829 struct list_head list; /* list of buffer pages */
77830- local_t write; /* index for next write */
77831+ local_unchecked_t write; /* index for next write */
77832 unsigned read; /* index for next read */
77833- local_t entries; /* entries on this page */
77834+ local_unchecked_t entries; /* entries on this page */
77835 unsigned long real_end; /* real end of data */
77836 struct buffer_data_page *page; /* Actual data page */
77837 };
77838@@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
77839 unsigned long last_overrun;
77840 local_t entries_bytes;
77841 local_t entries;
77842- local_t overrun;
77843- local_t commit_overrun;
77844+ local_unchecked_t overrun;
77845+ local_unchecked_t commit_overrun;
77846 local_t dropped_events;
77847 local_t committing;
77848 local_t commits;
77849@@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77850 *
77851 * We add a counter to the write field to denote this.
77852 */
77853- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
77854- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
77855+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
77856+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
77857
77858 /*
77859 * Just make sure we have seen our old_write and synchronize
77860@@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77861 * cmpxchg to only update if an interrupt did not already
77862 * do it for us. If the cmpxchg fails, we don't care.
77863 */
77864- (void)local_cmpxchg(&next_page->write, old_write, val);
77865- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
77866+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
77867+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
77868
77869 /*
77870 * No need to worry about races with clearing out the commit.
77871@@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
77872
77873 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
77874 {
77875- return local_read(&bpage->entries) & RB_WRITE_MASK;
77876+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
77877 }
77878
77879 static inline unsigned long rb_page_write(struct buffer_page *bpage)
77880 {
77881- return local_read(&bpage->write) & RB_WRITE_MASK;
77882+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
77883 }
77884
77885 static int
77886@@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
77887 * bytes consumed in ring buffer from here.
77888 * Increment overrun to account for the lost events.
77889 */
77890- local_add(page_entries, &cpu_buffer->overrun);
77891+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
77892 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77893 }
77894
77895@@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
77896 * it is our responsibility to update
77897 * the counters.
77898 */
77899- local_add(entries, &cpu_buffer->overrun);
77900+ local_add_unchecked(entries, &cpu_buffer->overrun);
77901 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77902
77903 /*
77904@@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77905 if (tail == BUF_PAGE_SIZE)
77906 tail_page->real_end = 0;
77907
77908- local_sub(length, &tail_page->write);
77909+ local_sub_unchecked(length, &tail_page->write);
77910 return;
77911 }
77912
77913@@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77914 rb_event_set_padding(event);
77915
77916 /* Set the write back to the previous setting */
77917- local_sub(length, &tail_page->write);
77918+ local_sub_unchecked(length, &tail_page->write);
77919 return;
77920 }
77921
77922@@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77923
77924 /* Set write to end of buffer */
77925 length = (tail + length) - BUF_PAGE_SIZE;
77926- local_sub(length, &tail_page->write);
77927+ local_sub_unchecked(length, &tail_page->write);
77928 }
77929
77930 /*
77931@@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77932 * about it.
77933 */
77934 if (unlikely(next_page == commit_page)) {
77935- local_inc(&cpu_buffer->commit_overrun);
77936+ local_inc_unchecked(&cpu_buffer->commit_overrun);
77937 goto out_reset;
77938 }
77939
77940@@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77941 cpu_buffer->tail_page) &&
77942 (cpu_buffer->commit_page ==
77943 cpu_buffer->reader_page))) {
77944- local_inc(&cpu_buffer->commit_overrun);
77945+ local_inc_unchecked(&cpu_buffer->commit_overrun);
77946 goto out_reset;
77947 }
77948 }
77949@@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77950 length += RB_LEN_TIME_EXTEND;
77951
77952 tail_page = cpu_buffer->tail_page;
77953- write = local_add_return(length, &tail_page->write);
77954+ write = local_add_return_unchecked(length, &tail_page->write);
77955
77956 /* set write to only the index of the write */
77957 write &= RB_WRITE_MASK;
77958@@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77959 kmemcheck_annotate_bitfield(event, bitfield);
77960 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
77961
77962- local_inc(&tail_page->entries);
77963+ local_inc_unchecked(&tail_page->entries);
77964
77965 /*
77966 * If this is the first commit on the page, then update
77967@@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77968
77969 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
77970 unsigned long write_mask =
77971- local_read(&bpage->write) & ~RB_WRITE_MASK;
77972+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
77973 unsigned long event_length = rb_event_length(event);
77974 /*
77975 * This is on the tail page. It is possible that
77976@@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77977 */
77978 old_index += write_mask;
77979 new_index += write_mask;
77980- index = local_cmpxchg(&bpage->write, old_index, new_index);
77981+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
77982 if (index == old_index) {
77983 /* update counters */
77984 local_sub(event_length, &cpu_buffer->entries_bytes);
77985@@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77986
77987 /* Do the likely case first */
77988 if (likely(bpage->page == (void *)addr)) {
77989- local_dec(&bpage->entries);
77990+ local_dec_unchecked(&bpage->entries);
77991 return;
77992 }
77993
77994@@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77995 start = bpage;
77996 do {
77997 if (bpage->page == (void *)addr) {
77998- local_dec(&bpage->entries);
77999+ local_dec_unchecked(&bpage->entries);
78000 return;
78001 }
78002 rb_inc_page(cpu_buffer, &bpage);
78003@@ -2926,7 +2926,7 @@ static inline unsigned long
78004 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
78005 {
78006 return local_read(&cpu_buffer->entries) -
78007- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
78008+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
78009 }
78010
78011 /**
78012@@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78013 return 0;
78014
78015 cpu_buffer = buffer->buffers[cpu];
78016- ret = local_read(&cpu_buffer->overrun);
78017+ ret = local_read_unchecked(&cpu_buffer->overrun);
78018
78019 return ret;
78020 }
78021@@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78022 return 0;
78023
78024 cpu_buffer = buffer->buffers[cpu];
78025- ret = local_read(&cpu_buffer->commit_overrun);
78026+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78027
78028 return ret;
78029 }
78030@@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78031 /* if you care about this being correct, lock the buffer */
78032 for_each_buffer_cpu(buffer, cpu) {
78033 cpu_buffer = buffer->buffers[cpu];
78034- overruns += local_read(&cpu_buffer->overrun);
78035+ overruns += local_read_unchecked(&cpu_buffer->overrun);
78036 }
78037
78038 return overruns;
78039@@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78040 /*
78041 * Reset the reader page to size zero.
78042 */
78043- local_set(&cpu_buffer->reader_page->write, 0);
78044- local_set(&cpu_buffer->reader_page->entries, 0);
78045+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78046+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78047 local_set(&cpu_buffer->reader_page->page->commit, 0);
78048 cpu_buffer->reader_page->real_end = 0;
78049
78050@@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78051 * want to compare with the last_overrun.
78052 */
78053 smp_mb();
78054- overwrite = local_read(&(cpu_buffer->overrun));
78055+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78056
78057 /*
78058 * Here's the tricky part.
78059@@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78060
78061 cpu_buffer->head_page
78062 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78063- local_set(&cpu_buffer->head_page->write, 0);
78064- local_set(&cpu_buffer->head_page->entries, 0);
78065+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
78066+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78067 local_set(&cpu_buffer->head_page->page->commit, 0);
78068
78069 cpu_buffer->head_page->read = 0;
78070@@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78071
78072 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78073 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78074- local_set(&cpu_buffer->reader_page->write, 0);
78075- local_set(&cpu_buffer->reader_page->entries, 0);
78076+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78077+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78078 local_set(&cpu_buffer->reader_page->page->commit, 0);
78079 cpu_buffer->reader_page->read = 0;
78080
78081 local_set(&cpu_buffer->entries_bytes, 0);
78082- local_set(&cpu_buffer->overrun, 0);
78083- local_set(&cpu_buffer->commit_overrun, 0);
78084+ local_set_unchecked(&cpu_buffer->overrun, 0);
78085+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78086 local_set(&cpu_buffer->dropped_events, 0);
78087 local_set(&cpu_buffer->entries, 0);
78088 local_set(&cpu_buffer->committing, 0);
78089@@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78090 rb_init_page(bpage);
78091 bpage = reader->page;
78092 reader->page = *data_page;
78093- local_set(&reader->write, 0);
78094- local_set(&reader->entries, 0);
78095+ local_set_unchecked(&reader->write, 0);
78096+ local_set_unchecked(&reader->entries, 0);
78097 reader->read = 0;
78098 *data_page = bpage;
78099
78100diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78101index 3c13e46..883d039 100644
78102--- a/kernel/trace/trace.c
78103+++ b/kernel/trace/trace.c
78104@@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78105 };
78106 #endif
78107
78108-static struct dentry *d_tracer;
78109-
78110 struct dentry *tracing_init_dentry(void)
78111 {
78112+ static struct dentry *d_tracer;
78113 static int once;
78114
78115 if (d_tracer)
78116@@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78117 return d_tracer;
78118 }
78119
78120-static struct dentry *d_percpu;
78121-
78122 struct dentry *tracing_dentry_percpu(void)
78123 {
78124+ static struct dentry *d_percpu;
78125 static int once;
78126 struct dentry *d_tracer;
78127
78128diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78129index 880073d..42db7c3 100644
78130--- a/kernel/trace/trace_events.c
78131+++ b/kernel/trace/trace_events.c
78132@@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78133 struct ftrace_module_file_ops {
78134 struct list_head list;
78135 struct module *mod;
78136- struct file_operations id;
78137- struct file_operations enable;
78138- struct file_operations format;
78139- struct file_operations filter;
78140 };
78141
78142 static struct ftrace_module_file_ops *
78143@@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78144
78145 file_ops->mod = mod;
78146
78147- file_ops->id = ftrace_event_id_fops;
78148- file_ops->id.owner = mod;
78149-
78150- file_ops->enable = ftrace_enable_fops;
78151- file_ops->enable.owner = mod;
78152-
78153- file_ops->filter = ftrace_event_filter_fops;
78154- file_ops->filter.owner = mod;
78155-
78156- file_ops->format = ftrace_event_format_fops;
78157- file_ops->format.owner = mod;
78158+ pax_open_kernel();
78159+ mod->trace_id.owner = mod;
78160+ mod->trace_enable.owner = mod;
78161+ mod->trace_filter.owner = mod;
78162+ mod->trace_format.owner = mod;
78163+ pax_close_kernel();
78164
78165 list_add(&file_ops->list, &ftrace_module_file_list);
78166
78167@@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78168
78169 for_each_event(call, start, end) {
78170 __trace_add_event_call(*call, mod,
78171- &file_ops->id, &file_ops->enable,
78172- &file_ops->filter, &file_ops->format);
78173+ &mod->trace_id, &mod->trace_enable,
78174+ &mod->trace_filter, &mod->trace_format);
78175 }
78176 }
78177
78178diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78179index fd3c8aa..5f324a6 100644
78180--- a/kernel/trace/trace_mmiotrace.c
78181+++ b/kernel/trace/trace_mmiotrace.c
78182@@ -24,7 +24,7 @@ struct header_iter {
78183 static struct trace_array *mmio_trace_array;
78184 static bool overrun_detected;
78185 static unsigned long prev_overruns;
78186-static atomic_t dropped_count;
78187+static atomic_unchecked_t dropped_count;
78188
78189 static void mmio_reset_data(struct trace_array *tr)
78190 {
78191@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78192
78193 static unsigned long count_overruns(struct trace_iterator *iter)
78194 {
78195- unsigned long cnt = atomic_xchg(&dropped_count, 0);
78196+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78197 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78198
78199 if (over > prev_overruns)
78200@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78201 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78202 sizeof(*entry), 0, pc);
78203 if (!event) {
78204- atomic_inc(&dropped_count);
78205+ atomic_inc_unchecked(&dropped_count);
78206 return;
78207 }
78208 entry = ring_buffer_event_data(event);
78209@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78210 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78211 sizeof(*entry), 0, pc);
78212 if (!event) {
78213- atomic_inc(&dropped_count);
78214+ atomic_inc_unchecked(&dropped_count);
78215 return;
78216 }
78217 entry = ring_buffer_event_data(event);
78218diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78219index 194d796..76edb8f 100644
78220--- a/kernel/trace/trace_output.c
78221+++ b/kernel/trace/trace_output.c
78222@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78223
78224 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78225 if (!IS_ERR(p)) {
78226- p = mangle_path(s->buffer + s->len, p, "\n");
78227+ p = mangle_path(s->buffer + s->len, p, "\n\\");
78228 if (p) {
78229 s->len = p - s->buffer;
78230 return 1;
78231@@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78232 goto out;
78233 }
78234
78235+ pax_open_kernel();
78236 if (event->funcs->trace == NULL)
78237- event->funcs->trace = trace_nop_print;
78238+ *(void **)&event->funcs->trace = trace_nop_print;
78239 if (event->funcs->raw == NULL)
78240- event->funcs->raw = trace_nop_print;
78241+ *(void **)&event->funcs->raw = trace_nop_print;
78242 if (event->funcs->hex == NULL)
78243- event->funcs->hex = trace_nop_print;
78244+ *(void **)&event->funcs->hex = trace_nop_print;
78245 if (event->funcs->binary == NULL)
78246- event->funcs->binary = trace_nop_print;
78247+ *(void **)&event->funcs->binary = trace_nop_print;
78248+ pax_close_kernel();
78249
78250 key = event->type & (EVENT_HASHSIZE - 1);
78251
78252diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78253index 42ca822..cdcacc6 100644
78254--- a/kernel/trace/trace_stack.c
78255+++ b/kernel/trace/trace_stack.c
78256@@ -52,7 +52,7 @@ static inline void check_stack(void)
78257 return;
78258
78259 /* we do not handle interrupt stacks yet */
78260- if (!object_is_on_stack(&this_size))
78261+ if (!object_starts_on_stack(&this_size))
78262 return;
78263
78264 local_irq_save(flags);
78265diff --git a/kernel/user.c b/kernel/user.c
78266index 33acb5e..57ebfd4 100644
78267--- a/kernel/user.c
78268+++ b/kernel/user.c
78269@@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78270 .count = 4294967295U,
78271 },
78272 },
78273- .kref = {
78274- .refcount = ATOMIC_INIT(3),
78275- },
78276+ .count = ATOMIC_INIT(3),
78277 .owner = GLOBAL_ROOT_UID,
78278 .group = GLOBAL_ROOT_GID,
78279 .proc_inum = PROC_USER_INIT_INO,
78280diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78281index 2b042c4..24f8ec3 100644
78282--- a/kernel/user_namespace.c
78283+++ b/kernel/user_namespace.c
78284@@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
78285 return ret;
78286 }
78287
78288- kref_init(&ns->kref);
78289+ atomic_set(&ns->count, 1);
78290 /* Leave the new->user_ns reference with the new user namespace. */
78291 ns->parent = parent_ns;
78292 ns->owner = owner;
78293@@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
78294 return create_user_ns(cred);
78295 }
78296
78297-void free_user_ns(struct kref *kref)
78298+void free_user_ns(struct user_namespace *ns)
78299 {
78300- struct user_namespace *parent, *ns =
78301- container_of(kref, struct user_namespace, kref);
78302+ struct user_namespace *parent;
78303
78304- parent = ns->parent;
78305- proc_free_inum(ns->proc_inum);
78306- kmem_cache_free(user_ns_cachep, ns);
78307- put_user_ns(parent);
78308+ do {
78309+ parent = ns->parent;
78310+ proc_free_inum(ns->proc_inum);
78311+ kmem_cache_free(user_ns_cachep, ns);
78312+ ns = parent;
78313+ } while (atomic_dec_and_test(&parent->count));
78314 }
78315 EXPORT_SYMBOL(free_user_ns);
78316
78317diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
78318index 63da38c..639904e 100644
78319--- a/kernel/utsname_sysctl.c
78320+++ b/kernel/utsname_sysctl.c
78321@@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
78322 static int proc_do_uts_string(ctl_table *table, int write,
78323 void __user *buffer, size_t *lenp, loff_t *ppos)
78324 {
78325- struct ctl_table uts_table;
78326+ ctl_table_no_const uts_table;
78327 int r;
78328 memcpy(&uts_table, table, sizeof(uts_table));
78329 uts_table.data = get_uts(table, write);
78330diff --git a/kernel/watchdog.c b/kernel/watchdog.c
78331index 75a2ab3..5961da7 100644
78332--- a/kernel/watchdog.c
78333+++ b/kernel/watchdog.c
78334@@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
78335 }
78336 #endif /* CONFIG_SYSCTL */
78337
78338-static struct smp_hotplug_thread watchdog_threads = {
78339+static struct smp_hotplug_thread watchdog_threads __read_only = {
78340 .store = &softlockup_watchdog,
78341 .thread_should_run = watchdog_should_run,
78342 .thread_fn = watchdog,
78343diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
78344index 67604e5..fe94fb1 100644
78345--- a/lib/Kconfig.debug
78346+++ b/lib/Kconfig.debug
78347@@ -550,7 +550,7 @@ config DEBUG_MUTEXES
78348
78349 config DEBUG_LOCK_ALLOC
78350 bool "Lock debugging: detect incorrect freeing of live locks"
78351- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78352+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78353 select DEBUG_SPINLOCK
78354 select DEBUG_MUTEXES
78355 select LOCKDEP
78356@@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
78357
78358 config PROVE_LOCKING
78359 bool "Lock debugging: prove locking correctness"
78360- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78361+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78362 select LOCKDEP
78363 select DEBUG_SPINLOCK
78364 select DEBUG_MUTEXES
78365@@ -670,7 +670,7 @@ config LOCKDEP
78366
78367 config LOCK_STAT
78368 bool "Lock usage statistics"
78369- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78370+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78371 select LOCKDEP
78372 select DEBUG_SPINLOCK
78373 select DEBUG_MUTEXES
78374@@ -1278,6 +1278,7 @@ config LATENCYTOP
78375 depends on DEBUG_KERNEL
78376 depends on STACKTRACE_SUPPORT
78377 depends on PROC_FS
78378+ depends on !GRKERNSEC_HIDESYM
78379 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
78380 select KALLSYMS
78381 select KALLSYMS_ALL
78382@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
78383
78384 config PROVIDE_OHCI1394_DMA_INIT
78385 bool "Remote debugging over FireWire early on boot"
78386- depends on PCI && X86
78387+ depends on PCI && X86 && !GRKERNSEC
78388 help
78389 If you want to debug problems which hang or crash the kernel early
78390 on boot and the crashing machine has a FireWire port, you can use
78391@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
78392
78393 config FIREWIRE_OHCI_REMOTE_DMA
78394 bool "Remote debugging over FireWire with firewire-ohci"
78395- depends on FIREWIRE_OHCI
78396+ depends on FIREWIRE_OHCI && !GRKERNSEC
78397 help
78398 This option lets you use the FireWire bus for remote debugging
78399 with help of the firewire-ohci driver. It enables unfiltered
78400diff --git a/lib/Makefile b/lib/Makefile
78401index 02ed6c0..bd243da 100644
78402--- a/lib/Makefile
78403+++ b/lib/Makefile
78404@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
78405
78406 obj-$(CONFIG_BTREE) += btree.o
78407 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
78408-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
78409+obj-y += list_debug.o
78410 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
78411
78412 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
78413diff --git a/lib/bitmap.c b/lib/bitmap.c
78414index 06f7e4f..f3cf2b0 100644
78415--- a/lib/bitmap.c
78416+++ b/lib/bitmap.c
78417@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
78418 {
78419 int c, old_c, totaldigits, ndigits, nchunks, nbits;
78420 u32 chunk;
78421- const char __user __force *ubuf = (const char __user __force *)buf;
78422+ const char __user *ubuf = (const char __force_user *)buf;
78423
78424 bitmap_zero(maskp, nmaskbits);
78425
78426@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
78427 {
78428 if (!access_ok(VERIFY_READ, ubuf, ulen))
78429 return -EFAULT;
78430- return __bitmap_parse((const char __force *)ubuf,
78431+ return __bitmap_parse((const char __force_kernel *)ubuf,
78432 ulen, 1, maskp, nmaskbits);
78433
78434 }
78435@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
78436 {
78437 unsigned a, b;
78438 int c, old_c, totaldigits;
78439- const char __user __force *ubuf = (const char __user __force *)buf;
78440+ const char __user *ubuf = (const char __force_user *)buf;
78441 int exp_digit, in_range;
78442
78443 totaldigits = c = 0;
78444@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
78445 {
78446 if (!access_ok(VERIFY_READ, ubuf, ulen))
78447 return -EFAULT;
78448- return __bitmap_parselist((const char __force *)ubuf,
78449+ return __bitmap_parselist((const char __force_kernel *)ubuf,
78450 ulen, 1, maskp, nmaskbits);
78451 }
78452 EXPORT_SYMBOL(bitmap_parselist_user);
78453diff --git a/lib/bug.c b/lib/bug.c
78454index d0cdf14..4d07bd2 100644
78455--- a/lib/bug.c
78456+++ b/lib/bug.c
78457@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
78458 return BUG_TRAP_TYPE_NONE;
78459
78460 bug = find_bug(bugaddr);
78461+ if (!bug)
78462+ return BUG_TRAP_TYPE_NONE;
78463
78464 file = NULL;
78465 line = 0;
78466diff --git a/lib/debugobjects.c b/lib/debugobjects.c
78467index d11808c..dc2d6f8 100644
78468--- a/lib/debugobjects.c
78469+++ b/lib/debugobjects.c
78470@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
78471 if (limit > 4)
78472 return;
78473
78474- is_on_stack = object_is_on_stack(addr);
78475+ is_on_stack = object_starts_on_stack(addr);
78476 if (is_on_stack == onstack)
78477 return;
78478
78479diff --git a/lib/devres.c b/lib/devres.c
78480index 80b9c76..9e32279 100644
78481--- a/lib/devres.c
78482+++ b/lib/devres.c
78483@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
78484 void devm_iounmap(struct device *dev, void __iomem *addr)
78485 {
78486 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
78487- (void *)addr));
78488+ (void __force *)addr));
78489 iounmap(addr);
78490 }
78491 EXPORT_SYMBOL(devm_iounmap);
78492@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
78493 {
78494 ioport_unmap(addr);
78495 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
78496- devm_ioport_map_match, (void *)addr));
78497+ devm_ioport_map_match, (void __force *)addr));
78498 }
78499 EXPORT_SYMBOL(devm_ioport_unmap);
78500
78501diff --git a/lib/dma-debug.c b/lib/dma-debug.c
78502index 5e396ac..58d5de1 100644
78503--- a/lib/dma-debug.c
78504+++ b/lib/dma-debug.c
78505@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
78506
78507 void dma_debug_add_bus(struct bus_type *bus)
78508 {
78509- struct notifier_block *nb;
78510+ notifier_block_no_const *nb;
78511
78512 if (global_disable)
78513 return;
78514@@ -942,7 +942,7 @@ out:
78515
78516 static void check_for_stack(struct device *dev, void *addr)
78517 {
78518- if (object_is_on_stack(addr))
78519+ if (object_starts_on_stack(addr))
78520 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
78521 "stack [addr=%p]\n", addr);
78522 }
78523diff --git a/lib/inflate.c b/lib/inflate.c
78524index 013a761..c28f3fc 100644
78525--- a/lib/inflate.c
78526+++ b/lib/inflate.c
78527@@ -269,7 +269,7 @@ static void free(void *where)
78528 malloc_ptr = free_mem_ptr;
78529 }
78530 #else
78531-#define malloc(a) kmalloc(a, GFP_KERNEL)
78532+#define malloc(a) kmalloc((a), GFP_KERNEL)
78533 #define free(a) kfree(a)
78534 #endif
78535
78536diff --git a/lib/ioremap.c b/lib/ioremap.c
78537index 0c9216c..863bd89 100644
78538--- a/lib/ioremap.c
78539+++ b/lib/ioremap.c
78540@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
78541 unsigned long next;
78542
78543 phys_addr -= addr;
78544- pmd = pmd_alloc(&init_mm, pud, addr);
78545+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78546 if (!pmd)
78547 return -ENOMEM;
78548 do {
78549@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
78550 unsigned long next;
78551
78552 phys_addr -= addr;
78553- pud = pud_alloc(&init_mm, pgd, addr);
78554+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
78555 if (!pud)
78556 return -ENOMEM;
78557 do {
78558diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
78559index bd2bea9..6b3c95e 100644
78560--- a/lib/is_single_threaded.c
78561+++ b/lib/is_single_threaded.c
78562@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
78563 struct task_struct *p, *t;
78564 bool ret;
78565
78566+ if (!mm)
78567+ return true;
78568+
78569 if (atomic_read(&task->signal->live) != 1)
78570 return false;
78571
78572diff --git a/lib/kobject.c b/lib/kobject.c
78573index e07ee1f..998489d 100644
78574--- a/lib/kobject.c
78575+++ b/lib/kobject.c
78576@@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
78577
78578
78579 static DEFINE_SPINLOCK(kobj_ns_type_lock);
78580-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
78581+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
78582
78583-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78584+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78585 {
78586 enum kobj_ns_type type = ops->type;
78587 int error;
78588diff --git a/lib/list_debug.c b/lib/list_debug.c
78589index c24c2f7..0475b78 100644
78590--- a/lib/list_debug.c
78591+++ b/lib/list_debug.c
78592@@ -11,7 +11,9 @@
78593 #include <linux/bug.h>
78594 #include <linux/kernel.h>
78595 #include <linux/rculist.h>
78596+#include <linux/mm.h>
78597
78598+#ifdef CONFIG_DEBUG_LIST
78599 /*
78600 * Insert a new entry between two known consecutive entries.
78601 *
78602@@ -19,21 +21,32 @@
78603 * the prev/next entries already!
78604 */
78605
78606-void __list_add(struct list_head *new,
78607- struct list_head *prev,
78608- struct list_head *next)
78609+static bool __list_add_debug(struct list_head *new,
78610+ struct list_head *prev,
78611+ struct list_head *next)
78612 {
78613- WARN(next->prev != prev,
78614+ if (WARN(next->prev != prev,
78615 "list_add corruption. next->prev should be "
78616 "prev (%p), but was %p. (next=%p).\n",
78617- prev, next->prev, next);
78618- WARN(prev->next != next,
78619+ prev, next->prev, next) ||
78620+ WARN(prev->next != next,
78621 "list_add corruption. prev->next should be "
78622 "next (%p), but was %p. (prev=%p).\n",
78623- next, prev->next, prev);
78624- WARN(new == prev || new == next,
78625+ next, prev->next, prev) ||
78626+ WARN(new == prev || new == next,
78627 "list_add double add: new=%p, prev=%p, next=%p.\n",
78628- new, prev, next);
78629+ new, prev, next))
78630+ return false;
78631+ return true;
78632+}
78633+
78634+void __list_add(struct list_head *new,
78635+ struct list_head *prev,
78636+ struct list_head *next)
78637+{
78638+ if (!__list_add_debug(new, prev, next))
78639+ return;
78640+
78641 next->prev = new;
78642 new->next = next;
78643 new->prev = prev;
78644@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
78645 }
78646 EXPORT_SYMBOL(__list_add);
78647
78648-void __list_del_entry(struct list_head *entry)
78649+static bool __list_del_entry_debug(struct list_head *entry)
78650 {
78651 struct list_head *prev, *next;
78652
78653@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
78654 WARN(next->prev != entry,
78655 "list_del corruption. next->prev should be %p, "
78656 "but was %p\n", entry, next->prev))
78657+ return false;
78658+ return true;
78659+}
78660+
78661+void __list_del_entry(struct list_head *entry)
78662+{
78663+ if (!__list_del_entry_debug(entry))
78664 return;
78665
78666- __list_del(prev, next);
78667+ __list_del(entry->prev, entry->next);
78668 }
78669 EXPORT_SYMBOL(__list_del_entry);
78670
78671@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
78672 void __list_add_rcu(struct list_head *new,
78673 struct list_head *prev, struct list_head *next)
78674 {
78675- WARN(next->prev != prev,
78676- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
78677- prev, next->prev, next);
78678- WARN(prev->next != next,
78679- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
78680- next, prev->next, prev);
78681+ if (!__list_add_debug(new, prev, next))
78682+ return;
78683+
78684 new->next = next;
78685 new->prev = prev;
78686 rcu_assign_pointer(list_next_rcu(prev), new);
78687 next->prev = new;
78688 }
78689 EXPORT_SYMBOL(__list_add_rcu);
78690+#endif
78691+
78692+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
78693+{
78694+#ifdef CONFIG_DEBUG_LIST
78695+ if (!__list_add_debug(new, prev, next))
78696+ return;
78697+#endif
78698+
78699+ pax_open_kernel();
78700+ next->prev = new;
78701+ new->next = next;
78702+ new->prev = prev;
78703+ prev->next = new;
78704+ pax_close_kernel();
78705+}
78706+EXPORT_SYMBOL(__pax_list_add);
78707+
78708+void pax_list_del(struct list_head *entry)
78709+{
78710+#ifdef CONFIG_DEBUG_LIST
78711+ if (!__list_del_entry_debug(entry))
78712+ return;
78713+#endif
78714+
78715+ pax_open_kernel();
78716+ __list_del(entry->prev, entry->next);
78717+ entry->next = LIST_POISON1;
78718+ entry->prev = LIST_POISON2;
78719+ pax_close_kernel();
78720+}
78721+EXPORT_SYMBOL(pax_list_del);
78722+
78723+void pax_list_del_init(struct list_head *entry)
78724+{
78725+ pax_open_kernel();
78726+ __list_del(entry->prev, entry->next);
78727+ INIT_LIST_HEAD(entry);
78728+ pax_close_kernel();
78729+}
78730+EXPORT_SYMBOL(pax_list_del_init);
78731+
78732+void __pax_list_add_rcu(struct list_head *new,
78733+ struct list_head *prev, struct list_head *next)
78734+{
78735+#ifdef CONFIG_DEBUG_LIST
78736+ if (!__list_add_debug(new, prev, next))
78737+ return;
78738+#endif
78739+
78740+ pax_open_kernel();
78741+ new->next = next;
78742+ new->prev = prev;
78743+ rcu_assign_pointer(list_next_rcu(prev), new);
78744+ next->prev = new;
78745+ pax_close_kernel();
78746+}
78747+EXPORT_SYMBOL(__pax_list_add_rcu);
78748+
78749+void pax_list_del_rcu(struct list_head *entry)
78750+{
78751+#ifdef CONFIG_DEBUG_LIST
78752+ if (!__list_del_entry_debug(entry))
78753+ return;
78754+#endif
78755+
78756+ pax_open_kernel();
78757+ __list_del(entry->prev, entry->next);
78758+ entry->next = LIST_POISON1;
78759+ entry->prev = LIST_POISON2;
78760+ pax_close_kernel();
78761+}
78762+EXPORT_SYMBOL(pax_list_del_rcu);
78763diff --git a/lib/radix-tree.c b/lib/radix-tree.c
78764index e796429..6e38f9f 100644
78765--- a/lib/radix-tree.c
78766+++ b/lib/radix-tree.c
78767@@ -92,7 +92,7 @@ struct radix_tree_preload {
78768 int nr;
78769 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
78770 };
78771-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
78772+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
78773
78774 static inline void *ptr_to_indirect(void *ptr)
78775 {
78776diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
78777index bb2b201..46abaf9 100644
78778--- a/lib/strncpy_from_user.c
78779+++ b/lib/strncpy_from_user.c
78780@@ -21,7 +21,7 @@
78781 */
78782 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
78783 {
78784- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78785+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78786 long res = 0;
78787
78788 /*
78789diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
78790index a28df52..3d55877 100644
78791--- a/lib/strnlen_user.c
78792+++ b/lib/strnlen_user.c
78793@@ -26,7 +26,7 @@
78794 */
78795 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
78796 {
78797- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78798+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78799 long align, res = 0;
78800 unsigned long c;
78801
78802diff --git a/lib/swiotlb.c b/lib/swiotlb.c
78803index 196b069..358f342 100644
78804--- a/lib/swiotlb.c
78805+++ b/lib/swiotlb.c
78806@@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
78807
78808 void
78809 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
78810- dma_addr_t dev_addr)
78811+ dma_addr_t dev_addr, struct dma_attrs *attrs)
78812 {
78813 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
78814
78815diff --git a/lib/vsprintf.c b/lib/vsprintf.c
78816index fab33a9..3b5fe68 100644
78817--- a/lib/vsprintf.c
78818+++ b/lib/vsprintf.c
78819@@ -16,6 +16,9 @@
78820 * - scnprintf and vscnprintf
78821 */
78822
78823+#ifdef CONFIG_GRKERNSEC_HIDESYM
78824+#define __INCLUDED_BY_HIDESYM 1
78825+#endif
78826 #include <stdarg.h>
78827 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
78828 #include <linux/types.h>
78829@@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
78830 char sym[KSYM_SYMBOL_LEN];
78831 if (ext == 'B')
78832 sprint_backtrace(sym, value);
78833- else if (ext != 'f' && ext != 's')
78834+ else if (ext != 'f' && ext != 's' && ext != 'a')
78835 sprint_symbol(sym, value);
78836 else
78837 sprint_symbol_no_offset(sym, value);
78838@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
78839 return number(buf, end, *(const netdev_features_t *)addr, spec);
78840 }
78841
78842+#ifdef CONFIG_GRKERNSEC_HIDESYM
78843+int kptr_restrict __read_mostly = 2;
78844+#else
78845 int kptr_restrict __read_mostly;
78846+#endif
78847
78848 /*
78849 * Show a '%p' thing. A kernel extension is that the '%p' is followed
78850@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
78851 * - 'S' For symbolic direct pointers with offset
78852 * - 's' For symbolic direct pointers without offset
78853 * - 'B' For backtraced symbolic direct pointers with offset
78854+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
78855+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
78856 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
78857 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
78858 * - 'M' For a 6-byte MAC address, it prints the address in the
78859@@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78860
78861 if (!ptr && *fmt != 'K') {
78862 /*
78863- * Print (null) with the same width as a pointer so it makes
78864+ * Print (nil) with the same width as a pointer so it makes
78865 * tabular output look nice.
78866 */
78867 if (spec.field_width == -1)
78868 spec.field_width = default_width;
78869- return string(buf, end, "(null)", spec);
78870+ return string(buf, end, "(nil)", spec);
78871 }
78872
78873 switch (*fmt) {
78874@@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78875 /* Fallthrough */
78876 case 'S':
78877 case 's':
78878+#ifdef CONFIG_GRKERNSEC_HIDESYM
78879+ break;
78880+#else
78881+ return symbol_string(buf, end, ptr, spec, *fmt);
78882+#endif
78883+ case 'A':
78884+ case 'a':
78885 case 'B':
78886 return symbol_string(buf, end, ptr, spec, *fmt);
78887 case 'R':
78888@@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78889 va_end(va);
78890 return buf;
78891 }
78892+ case 'P':
78893+ break;
78894 case 'K':
78895 /*
78896 * %pK cannot be used in IRQ context because its test
78897@@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78898 }
78899 break;
78900 }
78901+
78902+#ifdef CONFIG_GRKERNSEC_HIDESYM
78903+ /* 'P' = approved pointers to copy to userland,
78904+ as in the /proc/kallsyms case, as we make it display nothing
78905+ for non-root users, and the real contents for root users
78906+ Also ignore 'K' pointers, since we force their NULLing for non-root users
78907+ above
78908+ */
78909+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
78910+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
78911+ dump_stack();
78912+ ptr = NULL;
78913+ }
78914+#endif
78915+
78916 spec.flags |= SMALL;
78917 if (spec.field_width == -1) {
78918 spec.field_width = default_width;
78919@@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78920 typeof(type) value; \
78921 if (sizeof(type) == 8) { \
78922 args = PTR_ALIGN(args, sizeof(u32)); \
78923- *(u32 *)&value = *(u32 *)args; \
78924- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
78925+ *(u32 *)&value = *(const u32 *)args; \
78926+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
78927 } else { \
78928 args = PTR_ALIGN(args, sizeof(type)); \
78929- value = *(typeof(type) *)args; \
78930+ value = *(const typeof(type) *)args; \
78931 } \
78932 args += sizeof(type); \
78933 value; \
78934@@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78935 case FORMAT_TYPE_STR: {
78936 const char *str_arg = args;
78937 args += strlen(str_arg) + 1;
78938- str = string(str, end, (char *)str_arg, spec);
78939+ str = string(str, end, str_arg, spec);
78940 break;
78941 }
78942
78943diff --git a/localversion-grsec b/localversion-grsec
78944new file mode 100644
78945index 0000000..7cd6065
78946--- /dev/null
78947+++ b/localversion-grsec
78948@@ -0,0 +1 @@
78949+-grsec
78950diff --git a/mm/Kconfig b/mm/Kconfig
78951index 278e3ab..87c384d 100644
78952--- a/mm/Kconfig
78953+++ b/mm/Kconfig
78954@@ -286,10 +286,10 @@ config KSM
78955 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
78956
78957 config DEFAULT_MMAP_MIN_ADDR
78958- int "Low address space to protect from user allocation"
78959+ int "Low address space to protect from user allocation"
78960 depends on MMU
78961- default 4096
78962- help
78963+ default 65536
78964+ help
78965 This is the portion of low virtual memory which should be protected
78966 from userspace allocation. Keeping a user from writing to low pages
78967 can help reduce the impact of kernel NULL pointer bugs.
78968@@ -320,7 +320,7 @@ config MEMORY_FAILURE
78969
78970 config HWPOISON_INJECT
78971 tristate "HWPoison pages injector"
78972- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
78973+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
78974 select PROC_PAGE_MONITOR
78975
78976 config NOMMU_INITIAL_TRIM_EXCESS
78977diff --git a/mm/filemap.c b/mm/filemap.c
78978index 83efee7..3f99381 100644
78979--- a/mm/filemap.c
78980+++ b/mm/filemap.c
78981@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
78982 struct address_space *mapping = file->f_mapping;
78983
78984 if (!mapping->a_ops->readpage)
78985- return -ENOEXEC;
78986+ return -ENODEV;
78987 file_accessed(file);
78988 vma->vm_ops = &generic_file_vm_ops;
78989 return 0;
78990@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
78991 *pos = i_size_read(inode);
78992
78993 if (limit != RLIM_INFINITY) {
78994+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
78995 if (*pos >= limit) {
78996 send_sig(SIGXFSZ, current, 0);
78997 return -EFBIG;
78998diff --git a/mm/fremap.c b/mm/fremap.c
78999index a0aaf0e..20325c3 100644
79000--- a/mm/fremap.c
79001+++ b/mm/fremap.c
79002@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
79003 retry:
79004 vma = find_vma(mm, start);
79005
79006+#ifdef CONFIG_PAX_SEGMEXEC
79007+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
79008+ goto out;
79009+#endif
79010+
79011 /*
79012 * Make sure the vma is shared, that it supports prefaulting,
79013 * and that the remapped range is valid and fully within
79014diff --git a/mm/highmem.c b/mm/highmem.c
79015index b32b70c..e512eb0 100644
79016--- a/mm/highmem.c
79017+++ b/mm/highmem.c
79018@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79019 * So no dangers, even with speculative execution.
79020 */
79021 page = pte_page(pkmap_page_table[i]);
79022+ pax_open_kernel();
79023 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79024-
79025+ pax_close_kernel();
79026 set_page_address(page, NULL);
79027 need_flush = 1;
79028 }
79029@@ -198,9 +199,11 @@ start:
79030 }
79031 }
79032 vaddr = PKMAP_ADDR(last_pkmap_nr);
79033+
79034+ pax_open_kernel();
79035 set_pte_at(&init_mm, vaddr,
79036 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79037-
79038+ pax_close_kernel();
79039 pkmap_count[last_pkmap_nr] = 1;
79040 set_page_address(page, (void *)vaddr);
79041
79042diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79043index 546db81..34830af 100644
79044--- a/mm/hugetlb.c
79045+++ b/mm/hugetlb.c
79046@@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79047 struct hstate *h = &default_hstate;
79048 unsigned long tmp;
79049 int ret;
79050+ ctl_table_no_const hugetlb_table;
79051
79052 tmp = h->max_huge_pages;
79053
79054 if (write && h->order >= MAX_ORDER)
79055 return -EINVAL;
79056
79057- table->data = &tmp;
79058- table->maxlen = sizeof(unsigned long);
79059- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79060+ hugetlb_table = *table;
79061+ hugetlb_table.data = &tmp;
79062+ hugetlb_table.maxlen = sizeof(unsigned long);
79063+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79064 if (ret)
79065 goto out;
79066
79067@@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79068 struct hstate *h = &default_hstate;
79069 unsigned long tmp;
79070 int ret;
79071+ ctl_table_no_const hugetlb_table;
79072
79073 tmp = h->nr_overcommit_huge_pages;
79074
79075 if (write && h->order >= MAX_ORDER)
79076 return -EINVAL;
79077
79078- table->data = &tmp;
79079- table->maxlen = sizeof(unsigned long);
79080- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79081+ hugetlb_table = *table;
79082+ hugetlb_table.data = &tmp;
79083+ hugetlb_table.maxlen = sizeof(unsigned long);
79084+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79085 if (ret)
79086 goto out;
79087
79088@@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79089 return 1;
79090 }
79091
79092+#ifdef CONFIG_PAX_SEGMEXEC
79093+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79094+{
79095+ struct mm_struct *mm = vma->vm_mm;
79096+ struct vm_area_struct *vma_m;
79097+ unsigned long address_m;
79098+ pte_t *ptep_m;
79099+
79100+ vma_m = pax_find_mirror_vma(vma);
79101+ if (!vma_m)
79102+ return;
79103+
79104+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79105+ address_m = address + SEGMEXEC_TASK_SIZE;
79106+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79107+ get_page(page_m);
79108+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
79109+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79110+}
79111+#endif
79112+
79113 /*
79114 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79115 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79116@@ -2629,6 +2654,11 @@ retry_avoidcopy:
79117 make_huge_pte(vma, new_page, 1));
79118 page_remove_rmap(old_page);
79119 hugepage_add_new_anon_rmap(new_page, vma, address);
79120+
79121+#ifdef CONFIG_PAX_SEGMEXEC
79122+ pax_mirror_huge_pte(vma, address, new_page);
79123+#endif
79124+
79125 /* Make the old page be freed below */
79126 new_page = old_page;
79127 }
79128@@ -2788,6 +2818,10 @@ retry:
79129 && (vma->vm_flags & VM_SHARED)));
79130 set_huge_pte_at(mm, address, ptep, new_pte);
79131
79132+#ifdef CONFIG_PAX_SEGMEXEC
79133+ pax_mirror_huge_pte(vma, address, page);
79134+#endif
79135+
79136 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79137 /* Optimization, do the COW without a second fault */
79138 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79139@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79140 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79141 struct hstate *h = hstate_vma(vma);
79142
79143+#ifdef CONFIG_PAX_SEGMEXEC
79144+ struct vm_area_struct *vma_m;
79145+#endif
79146+
79147 address &= huge_page_mask(h);
79148
79149 ptep = huge_pte_offset(mm, address);
79150@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79151 VM_FAULT_SET_HINDEX(hstate_index(h));
79152 }
79153
79154+#ifdef CONFIG_PAX_SEGMEXEC
79155+ vma_m = pax_find_mirror_vma(vma);
79156+ if (vma_m) {
79157+ unsigned long address_m;
79158+
79159+ if (vma->vm_start > vma_m->vm_start) {
79160+ address_m = address;
79161+ address -= SEGMEXEC_TASK_SIZE;
79162+ vma = vma_m;
79163+ h = hstate_vma(vma);
79164+ } else
79165+ address_m = address + SEGMEXEC_TASK_SIZE;
79166+
79167+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79168+ return VM_FAULT_OOM;
79169+ address_m &= HPAGE_MASK;
79170+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79171+ }
79172+#endif
79173+
79174 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79175 if (!ptep)
79176 return VM_FAULT_OOM;
79177diff --git a/mm/internal.h b/mm/internal.h
79178index 9ba2110..eaf0674 100644
79179--- a/mm/internal.h
79180+++ b/mm/internal.h
79181@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79182 * in mm/page_alloc.c
79183 */
79184 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79185+extern void free_compound_page(struct page *page);
79186 extern void prep_compound_page(struct page *page, unsigned long order);
79187 #ifdef CONFIG_MEMORY_FAILURE
79188 extern bool is_free_buddy_page(struct page *page);
79189diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79190index 752a705..6c3102e 100644
79191--- a/mm/kmemleak.c
79192+++ b/mm/kmemleak.c
79193@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79194
79195 for (i = 0; i < object->trace_len; i++) {
79196 void *ptr = (void *)object->trace[i];
79197- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79198+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79199 }
79200 }
79201
79202@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79203 return -ENOMEM;
79204 }
79205
79206- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79207+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79208 &kmemleak_fops);
79209 if (!dentry)
79210 pr_warning("Failed to create the debugfs kmemleak file\n");
79211diff --git a/mm/maccess.c b/mm/maccess.c
79212index d53adf9..03a24bf 100644
79213--- a/mm/maccess.c
79214+++ b/mm/maccess.c
79215@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79216 set_fs(KERNEL_DS);
79217 pagefault_disable();
79218 ret = __copy_from_user_inatomic(dst,
79219- (__force const void __user *)src, size);
79220+ (const void __force_user *)src, size);
79221 pagefault_enable();
79222 set_fs(old_fs);
79223
79224@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79225
79226 set_fs(KERNEL_DS);
79227 pagefault_disable();
79228- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79229+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79230 pagefault_enable();
79231 set_fs(old_fs);
79232
79233diff --git a/mm/madvise.c b/mm/madvise.c
79234index 03dfa5c..b032917 100644
79235--- a/mm/madvise.c
79236+++ b/mm/madvise.c
79237@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79238 pgoff_t pgoff;
79239 unsigned long new_flags = vma->vm_flags;
79240
79241+#ifdef CONFIG_PAX_SEGMEXEC
79242+ struct vm_area_struct *vma_m;
79243+#endif
79244+
79245 switch (behavior) {
79246 case MADV_NORMAL:
79247 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79248@@ -123,6 +127,13 @@ success:
79249 /*
79250 * vm_flags is protected by the mmap_sem held in write mode.
79251 */
79252+
79253+#ifdef CONFIG_PAX_SEGMEXEC
79254+ vma_m = pax_find_mirror_vma(vma);
79255+ if (vma_m)
79256+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79257+#endif
79258+
79259 vma->vm_flags = new_flags;
79260
79261 out:
79262@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79263 struct vm_area_struct ** prev,
79264 unsigned long start, unsigned long end)
79265 {
79266+
79267+#ifdef CONFIG_PAX_SEGMEXEC
79268+ struct vm_area_struct *vma_m;
79269+#endif
79270+
79271 *prev = vma;
79272 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
79273 return -EINVAL;
79274@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79275 zap_page_range(vma, start, end - start, &details);
79276 } else
79277 zap_page_range(vma, start, end - start, NULL);
79278+
79279+#ifdef CONFIG_PAX_SEGMEXEC
79280+ vma_m = pax_find_mirror_vma(vma);
79281+ if (vma_m) {
79282+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
79283+ struct zap_details details = {
79284+ .nonlinear_vma = vma_m,
79285+ .last_index = ULONG_MAX,
79286+ };
79287+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
79288+ } else
79289+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
79290+ }
79291+#endif
79292+
79293 return 0;
79294 }
79295
79296@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
79297 if (end < start)
79298 goto out;
79299
79300+#ifdef CONFIG_PAX_SEGMEXEC
79301+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
79302+ if (end > SEGMEXEC_TASK_SIZE)
79303+ goto out;
79304+ } else
79305+#endif
79306+
79307+ if (end > TASK_SIZE)
79308+ goto out;
79309+
79310 error = 0;
79311 if (end == start)
79312 goto out;
79313diff --git a/mm/memory-failure.c b/mm/memory-failure.c
79314index c6e4dd3..1f41988 100644
79315--- a/mm/memory-failure.c
79316+++ b/mm/memory-failure.c
79317@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
79318
79319 int sysctl_memory_failure_recovery __read_mostly = 1;
79320
79321-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79322+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79323
79324 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
79325
79326@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
79327 pfn, t->comm, t->pid);
79328 si.si_signo = SIGBUS;
79329 si.si_errno = 0;
79330- si.si_addr = (void *)addr;
79331+ si.si_addr = (void __user *)addr;
79332 #ifdef __ARCH_SI_TRAPNO
79333 si.si_trapno = trapno;
79334 #endif
79335@@ -760,7 +760,7 @@ static struct page_state {
79336 unsigned long res;
79337 char *msg;
79338 int (*action)(struct page *p, unsigned long pfn);
79339-} error_states[] = {
79340+} __do_const error_states[] = {
79341 { reserved, reserved, "reserved kernel", me_kernel },
79342 /*
79343 * free pages are specially detected outside this table:
79344@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79345 }
79346
79347 nr_pages = 1 << compound_trans_order(hpage);
79348- atomic_long_add(nr_pages, &mce_bad_pages);
79349+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
79350
79351 /*
79352 * We need/can do nothing about count=0 pages.
79353@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79354 if (!PageHWPoison(hpage)
79355 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
79356 || (p != hpage && TestSetPageHWPoison(hpage))) {
79357- atomic_long_sub(nr_pages, &mce_bad_pages);
79358+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79359 return 0;
79360 }
79361 set_page_hwpoison_huge_page(hpage);
79362@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79363 }
79364 if (hwpoison_filter(p)) {
79365 if (TestClearPageHWPoison(p))
79366- atomic_long_sub(nr_pages, &mce_bad_pages);
79367+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79368 unlock_page(hpage);
79369 put_page(hpage);
79370 return 0;
79371@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
79372 return 0;
79373 }
79374 if (TestClearPageHWPoison(p))
79375- atomic_long_sub(nr_pages, &mce_bad_pages);
79376+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79377 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
79378 return 0;
79379 }
79380@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
79381 */
79382 if (TestClearPageHWPoison(page)) {
79383 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
79384- atomic_long_sub(nr_pages, &mce_bad_pages);
79385+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79386 freeit = 1;
79387 if (PageHuge(page))
79388 clear_page_hwpoison_huge_page(page);
79389@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
79390 }
79391 done:
79392 if (!PageHWPoison(hpage))
79393- atomic_long_add(1 << compound_trans_order(hpage),
79394+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
79395 &mce_bad_pages);
79396 set_page_hwpoison_huge_page(hpage);
79397 dequeue_hwpoisoned_huge_page(hpage);
79398@@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
79399 return ret;
79400
79401 done:
79402- atomic_long_add(1, &mce_bad_pages);
79403+ atomic_long_add_unchecked(1, &mce_bad_pages);
79404 SetPageHWPoison(page);
79405 /* keep elevated page count for bad page */
79406 return ret;
79407diff --git a/mm/memory.c b/mm/memory.c
79408index bb1369f..efb96b5 100644
79409--- a/mm/memory.c
79410+++ b/mm/memory.c
79411@@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79412 free_pte_range(tlb, pmd, addr);
79413 } while (pmd++, addr = next, addr != end);
79414
79415+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
79416 start &= PUD_MASK;
79417 if (start < floor)
79418 return;
79419@@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79420 pmd = pmd_offset(pud, start);
79421 pud_clear(pud);
79422 pmd_free_tlb(tlb, pmd, start);
79423+#endif
79424+
79425 }
79426
79427 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79428@@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79429 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
79430 } while (pud++, addr = next, addr != end);
79431
79432+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
79433 start &= PGDIR_MASK;
79434 if (start < floor)
79435 return;
79436@@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79437 pud = pud_offset(pgd, start);
79438 pgd_clear(pgd);
79439 pud_free_tlb(tlb, pud, start);
79440+#endif
79441+
79442 }
79443
79444 /*
79445@@ -1618,12 +1624,6 @@ no_page_table:
79446 return page;
79447 }
79448
79449-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
79450-{
79451- return stack_guard_page_start(vma, addr) ||
79452- stack_guard_page_end(vma, addr+PAGE_SIZE);
79453-}
79454-
79455 /**
79456 * __get_user_pages() - pin user pages in memory
79457 * @tsk: task_struct of target task
79458@@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79459
79460 i = 0;
79461
79462- do {
79463+ while (nr_pages) {
79464 struct vm_area_struct *vma;
79465
79466- vma = find_extend_vma(mm, start);
79467+ vma = find_vma(mm, start);
79468 if (!vma && in_gate_area(mm, start)) {
79469 unsigned long pg = start & PAGE_MASK;
79470 pgd_t *pgd;
79471@@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79472 goto next_page;
79473 }
79474
79475- if (!vma ||
79476+ if (!vma || start < vma->vm_start ||
79477 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
79478 !(vm_flags & vma->vm_flags))
79479 return i ? : -EFAULT;
79480@@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79481 int ret;
79482 unsigned int fault_flags = 0;
79483
79484- /* For mlock, just skip the stack guard page. */
79485- if (foll_flags & FOLL_MLOCK) {
79486- if (stack_guard_page(vma, start))
79487- goto next_page;
79488- }
79489 if (foll_flags & FOLL_WRITE)
79490 fault_flags |= FAULT_FLAG_WRITE;
79491 if (nonblocking)
79492@@ -1865,7 +1860,7 @@ next_page:
79493 start += PAGE_SIZE;
79494 nr_pages--;
79495 } while (nr_pages && start < vma->vm_end);
79496- } while (nr_pages);
79497+ }
79498 return i;
79499 }
79500 EXPORT_SYMBOL(__get_user_pages);
79501@@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
79502 page_add_file_rmap(page);
79503 set_pte_at(mm, addr, pte, mk_pte(page, prot));
79504
79505+#ifdef CONFIG_PAX_SEGMEXEC
79506+ pax_mirror_file_pte(vma, addr, page, ptl);
79507+#endif
79508+
79509 retval = 0;
79510 pte_unmap_unlock(pte, ptl);
79511 return retval;
79512@@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
79513 if (!page_count(page))
79514 return -EINVAL;
79515 if (!(vma->vm_flags & VM_MIXEDMAP)) {
79516+
79517+#ifdef CONFIG_PAX_SEGMEXEC
79518+ struct vm_area_struct *vma_m;
79519+#endif
79520+
79521 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
79522 BUG_ON(vma->vm_flags & VM_PFNMAP);
79523 vma->vm_flags |= VM_MIXEDMAP;
79524+
79525+#ifdef CONFIG_PAX_SEGMEXEC
79526+ vma_m = pax_find_mirror_vma(vma);
79527+ if (vma_m)
79528+ vma_m->vm_flags |= VM_MIXEDMAP;
79529+#endif
79530+
79531 }
79532 return insert_page(vma, addr, page, vma->vm_page_prot);
79533 }
79534@@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
79535 unsigned long pfn)
79536 {
79537 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
79538+ BUG_ON(vma->vm_mirror);
79539
79540 if (addr < vma->vm_start || addr >= vma->vm_end)
79541 return -EFAULT;
79542@@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
79543
79544 BUG_ON(pud_huge(*pud));
79545
79546- pmd = pmd_alloc(mm, pud, addr);
79547+ pmd = (mm == &init_mm) ?
79548+ pmd_alloc_kernel(mm, pud, addr) :
79549+ pmd_alloc(mm, pud, addr);
79550 if (!pmd)
79551 return -ENOMEM;
79552 do {
79553@@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
79554 unsigned long next;
79555 int err;
79556
79557- pud = pud_alloc(mm, pgd, addr);
79558+ pud = (mm == &init_mm) ?
79559+ pud_alloc_kernel(mm, pgd, addr) :
79560+ pud_alloc(mm, pgd, addr);
79561 if (!pud)
79562 return -ENOMEM;
79563 do {
79564@@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
79565 copy_user_highpage(dst, src, va, vma);
79566 }
79567
79568+#ifdef CONFIG_PAX_SEGMEXEC
79569+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
79570+{
79571+ struct mm_struct *mm = vma->vm_mm;
79572+ spinlock_t *ptl;
79573+ pte_t *pte, entry;
79574+
79575+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
79576+ entry = *pte;
79577+ if (!pte_present(entry)) {
79578+ if (!pte_none(entry)) {
79579+ BUG_ON(pte_file(entry));
79580+ free_swap_and_cache(pte_to_swp_entry(entry));
79581+ pte_clear_not_present_full(mm, address, pte, 0);
79582+ }
79583+ } else {
79584+ struct page *page;
79585+
79586+ flush_cache_page(vma, address, pte_pfn(entry));
79587+ entry = ptep_clear_flush(vma, address, pte);
79588+ BUG_ON(pte_dirty(entry));
79589+ page = vm_normal_page(vma, address, entry);
79590+ if (page) {
79591+ update_hiwater_rss(mm);
79592+ if (PageAnon(page))
79593+ dec_mm_counter_fast(mm, MM_ANONPAGES);
79594+ else
79595+ dec_mm_counter_fast(mm, MM_FILEPAGES);
79596+ page_remove_rmap(page);
79597+ page_cache_release(page);
79598+ }
79599+ }
79600+ pte_unmap_unlock(pte, ptl);
79601+}
79602+
79603+/* PaX: if vma is mirrored, synchronize the mirror's PTE
79604+ *
79605+ * the ptl of the lower mapped page is held on entry and is not released on exit
79606+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
79607+ */
79608+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79609+{
79610+ struct mm_struct *mm = vma->vm_mm;
79611+ unsigned long address_m;
79612+ spinlock_t *ptl_m;
79613+ struct vm_area_struct *vma_m;
79614+ pmd_t *pmd_m;
79615+ pte_t *pte_m, entry_m;
79616+
79617+ BUG_ON(!page_m || !PageAnon(page_m));
79618+
79619+ vma_m = pax_find_mirror_vma(vma);
79620+ if (!vma_m)
79621+ return;
79622+
79623+ BUG_ON(!PageLocked(page_m));
79624+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79625+ address_m = address + SEGMEXEC_TASK_SIZE;
79626+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79627+ pte_m = pte_offset_map(pmd_m, address_m);
79628+ ptl_m = pte_lockptr(mm, pmd_m);
79629+ if (ptl != ptl_m) {
79630+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79631+ if (!pte_none(*pte_m))
79632+ goto out;
79633+ }
79634+
79635+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79636+ page_cache_get(page_m);
79637+ page_add_anon_rmap(page_m, vma_m, address_m);
79638+ inc_mm_counter_fast(mm, MM_ANONPAGES);
79639+ set_pte_at(mm, address_m, pte_m, entry_m);
79640+ update_mmu_cache(vma_m, address_m, entry_m);
79641+out:
79642+ if (ptl != ptl_m)
79643+ spin_unlock(ptl_m);
79644+ pte_unmap(pte_m);
79645+ unlock_page(page_m);
79646+}
79647+
79648+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79649+{
79650+ struct mm_struct *mm = vma->vm_mm;
79651+ unsigned long address_m;
79652+ spinlock_t *ptl_m;
79653+ struct vm_area_struct *vma_m;
79654+ pmd_t *pmd_m;
79655+ pte_t *pte_m, entry_m;
79656+
79657+ BUG_ON(!page_m || PageAnon(page_m));
79658+
79659+ vma_m = pax_find_mirror_vma(vma);
79660+ if (!vma_m)
79661+ return;
79662+
79663+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79664+ address_m = address + SEGMEXEC_TASK_SIZE;
79665+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79666+ pte_m = pte_offset_map(pmd_m, address_m);
79667+ ptl_m = pte_lockptr(mm, pmd_m);
79668+ if (ptl != ptl_m) {
79669+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79670+ if (!pte_none(*pte_m))
79671+ goto out;
79672+ }
79673+
79674+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79675+ page_cache_get(page_m);
79676+ page_add_file_rmap(page_m);
79677+ inc_mm_counter_fast(mm, MM_FILEPAGES);
79678+ set_pte_at(mm, address_m, pte_m, entry_m);
79679+ update_mmu_cache(vma_m, address_m, entry_m);
79680+out:
79681+ if (ptl != ptl_m)
79682+ spin_unlock(ptl_m);
79683+ pte_unmap(pte_m);
79684+}
79685+
79686+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
79687+{
79688+ struct mm_struct *mm = vma->vm_mm;
79689+ unsigned long address_m;
79690+ spinlock_t *ptl_m;
79691+ struct vm_area_struct *vma_m;
79692+ pmd_t *pmd_m;
79693+ pte_t *pte_m, entry_m;
79694+
79695+ vma_m = pax_find_mirror_vma(vma);
79696+ if (!vma_m)
79697+ return;
79698+
79699+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79700+ address_m = address + SEGMEXEC_TASK_SIZE;
79701+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79702+ pte_m = pte_offset_map(pmd_m, address_m);
79703+ ptl_m = pte_lockptr(mm, pmd_m);
79704+ if (ptl != ptl_m) {
79705+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79706+ if (!pte_none(*pte_m))
79707+ goto out;
79708+ }
79709+
79710+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
79711+ set_pte_at(mm, address_m, pte_m, entry_m);
79712+out:
79713+ if (ptl != ptl_m)
79714+ spin_unlock(ptl_m);
79715+ pte_unmap(pte_m);
79716+}
79717+
79718+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
79719+{
79720+ struct page *page_m;
79721+ pte_t entry;
79722+
79723+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
79724+ goto out;
79725+
79726+ entry = *pte;
79727+ page_m = vm_normal_page(vma, address, entry);
79728+ if (!page_m)
79729+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
79730+ else if (PageAnon(page_m)) {
79731+ if (pax_find_mirror_vma(vma)) {
79732+ pte_unmap_unlock(pte, ptl);
79733+ lock_page(page_m);
79734+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
79735+ if (pte_same(entry, *pte))
79736+ pax_mirror_anon_pte(vma, address, page_m, ptl);
79737+ else
79738+ unlock_page(page_m);
79739+ }
79740+ } else
79741+ pax_mirror_file_pte(vma, address, page_m, ptl);
79742+
79743+out:
79744+ pte_unmap_unlock(pte, ptl);
79745+}
79746+#endif
79747+
79748 /*
79749 * This routine handles present pages, when users try to write
79750 * to a shared page. It is done by copying the page to a new address
79751@@ -2725,6 +2921,12 @@ gotten:
79752 */
79753 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79754 if (likely(pte_same(*page_table, orig_pte))) {
79755+
79756+#ifdef CONFIG_PAX_SEGMEXEC
79757+ if (pax_find_mirror_vma(vma))
79758+ BUG_ON(!trylock_page(new_page));
79759+#endif
79760+
79761 if (old_page) {
79762 if (!PageAnon(old_page)) {
79763 dec_mm_counter_fast(mm, MM_FILEPAGES);
79764@@ -2776,6 +2978,10 @@ gotten:
79765 page_remove_rmap(old_page);
79766 }
79767
79768+#ifdef CONFIG_PAX_SEGMEXEC
79769+ pax_mirror_anon_pte(vma, address, new_page, ptl);
79770+#endif
79771+
79772 /* Free the old page.. */
79773 new_page = old_page;
79774 ret |= VM_FAULT_WRITE;
79775@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79776 swap_free(entry);
79777 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
79778 try_to_free_swap(page);
79779+
79780+#ifdef CONFIG_PAX_SEGMEXEC
79781+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
79782+#endif
79783+
79784 unlock_page(page);
79785 if (swapcache) {
79786 /*
79787@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79788
79789 /* No need to invalidate - it was non-present before */
79790 update_mmu_cache(vma, address, page_table);
79791+
79792+#ifdef CONFIG_PAX_SEGMEXEC
79793+ pax_mirror_anon_pte(vma, address, page, ptl);
79794+#endif
79795+
79796 unlock:
79797 pte_unmap_unlock(page_table, ptl);
79798 out:
79799@@ -3093,40 +3309,6 @@ out_release:
79800 }
79801
79802 /*
79803- * This is like a special single-page "expand_{down|up}wards()",
79804- * except we must first make sure that 'address{-|+}PAGE_SIZE'
79805- * doesn't hit another vma.
79806- */
79807-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
79808-{
79809- address &= PAGE_MASK;
79810- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
79811- struct vm_area_struct *prev = vma->vm_prev;
79812-
79813- /*
79814- * Is there a mapping abutting this one below?
79815- *
79816- * That's only ok if it's the same stack mapping
79817- * that has gotten split..
79818- */
79819- if (prev && prev->vm_end == address)
79820- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
79821-
79822- expand_downwards(vma, address - PAGE_SIZE);
79823- }
79824- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
79825- struct vm_area_struct *next = vma->vm_next;
79826-
79827- /* As VM_GROWSDOWN but s/below/above/ */
79828- if (next && next->vm_start == address + PAGE_SIZE)
79829- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
79830-
79831- expand_upwards(vma, address + PAGE_SIZE);
79832- }
79833- return 0;
79834-}
79835-
79836-/*
79837 * We enter with non-exclusive mmap_sem (to exclude vma changes,
79838 * but allow concurrent faults), and pte mapped but not yet locked.
79839 * We return with mmap_sem still held, but pte unmapped and unlocked.
79840@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79841 unsigned long address, pte_t *page_table, pmd_t *pmd,
79842 unsigned int flags)
79843 {
79844- struct page *page;
79845+ struct page *page = NULL;
79846 spinlock_t *ptl;
79847 pte_t entry;
79848
79849- pte_unmap(page_table);
79850-
79851- /* Check if we need to add a guard page to the stack */
79852- if (check_stack_guard_page(vma, address) < 0)
79853- return VM_FAULT_SIGBUS;
79854-
79855- /* Use the zero-page for reads */
79856 if (!(flags & FAULT_FLAG_WRITE)) {
79857 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
79858 vma->vm_page_prot));
79859- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79860+ ptl = pte_lockptr(mm, pmd);
79861+ spin_lock(ptl);
79862 if (!pte_none(*page_table))
79863 goto unlock;
79864 goto setpte;
79865 }
79866
79867 /* Allocate our own private page. */
79868+ pte_unmap(page_table);
79869+
79870 if (unlikely(anon_vma_prepare(vma)))
79871 goto oom;
79872 page = alloc_zeroed_user_highpage_movable(vma, address);
79873@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79874 if (!pte_none(*page_table))
79875 goto release;
79876
79877+#ifdef CONFIG_PAX_SEGMEXEC
79878+ if (pax_find_mirror_vma(vma))
79879+ BUG_ON(!trylock_page(page));
79880+#endif
79881+
79882 inc_mm_counter_fast(mm, MM_ANONPAGES);
79883 page_add_new_anon_rmap(page, vma, address);
79884 setpte:
79885@@ -3181,6 +3364,12 @@ setpte:
79886
79887 /* No need to invalidate - it was non-present before */
79888 update_mmu_cache(vma, address, page_table);
79889+
79890+#ifdef CONFIG_PAX_SEGMEXEC
79891+ if (page)
79892+ pax_mirror_anon_pte(vma, address, page, ptl);
79893+#endif
79894+
79895 unlock:
79896 pte_unmap_unlock(page_table, ptl);
79897 return 0;
79898@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79899 */
79900 /* Only go through if we didn't race with anybody else... */
79901 if (likely(pte_same(*page_table, orig_pte))) {
79902+
79903+#ifdef CONFIG_PAX_SEGMEXEC
79904+ if (anon && pax_find_mirror_vma(vma))
79905+ BUG_ON(!trylock_page(page));
79906+#endif
79907+
79908 flush_icache_page(vma, page);
79909 entry = mk_pte(page, vma->vm_page_prot);
79910 if (flags & FAULT_FLAG_WRITE)
79911@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79912
79913 /* no need to invalidate: a not-present page won't be cached */
79914 update_mmu_cache(vma, address, page_table);
79915+
79916+#ifdef CONFIG_PAX_SEGMEXEC
79917+ if (anon)
79918+ pax_mirror_anon_pte(vma, address, page, ptl);
79919+ else
79920+ pax_mirror_file_pte(vma, address, page, ptl);
79921+#endif
79922+
79923 } else {
79924 if (cow_page)
79925 mem_cgroup_uncharge_page(cow_page);
79926@@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
79927 if (flags & FAULT_FLAG_WRITE)
79928 flush_tlb_fix_spurious_fault(vma, address);
79929 }
79930+
79931+#ifdef CONFIG_PAX_SEGMEXEC
79932+ pax_mirror_pte(vma, address, pte, pmd, ptl);
79933+ return 0;
79934+#endif
79935+
79936 unlock:
79937 pte_unmap_unlock(pte, ptl);
79938 return 0;
79939@@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79940 pmd_t *pmd;
79941 pte_t *pte;
79942
79943+#ifdef CONFIG_PAX_SEGMEXEC
79944+ struct vm_area_struct *vma_m;
79945+#endif
79946+
79947 __set_current_state(TASK_RUNNING);
79948
79949 count_vm_event(PGFAULT);
79950@@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79951 if (unlikely(is_vm_hugetlb_page(vma)))
79952 return hugetlb_fault(mm, vma, address, flags);
79953
79954+#ifdef CONFIG_PAX_SEGMEXEC
79955+ vma_m = pax_find_mirror_vma(vma);
79956+ if (vma_m) {
79957+ unsigned long address_m;
79958+ pgd_t *pgd_m;
79959+ pud_t *pud_m;
79960+ pmd_t *pmd_m;
79961+
79962+ if (vma->vm_start > vma_m->vm_start) {
79963+ address_m = address;
79964+ address -= SEGMEXEC_TASK_SIZE;
79965+ vma = vma_m;
79966+ } else
79967+ address_m = address + SEGMEXEC_TASK_SIZE;
79968+
79969+ pgd_m = pgd_offset(mm, address_m);
79970+ pud_m = pud_alloc(mm, pgd_m, address_m);
79971+ if (!pud_m)
79972+ return VM_FAULT_OOM;
79973+ pmd_m = pmd_alloc(mm, pud_m, address_m);
79974+ if (!pmd_m)
79975+ return VM_FAULT_OOM;
79976+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
79977+ return VM_FAULT_OOM;
79978+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
79979+ }
79980+#endif
79981+
79982 retry:
79983 pgd = pgd_offset(mm, address);
79984 pud = pud_alloc(mm, pgd, address);
79985@@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79986 spin_unlock(&mm->page_table_lock);
79987 return 0;
79988 }
79989+
79990+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79991+{
79992+ pud_t *new = pud_alloc_one(mm, address);
79993+ if (!new)
79994+ return -ENOMEM;
79995+
79996+ smp_wmb(); /* See comment in __pte_alloc */
79997+
79998+ spin_lock(&mm->page_table_lock);
79999+ if (pgd_present(*pgd)) /* Another has populated it */
80000+ pud_free(mm, new);
80001+ else
80002+ pgd_populate_kernel(mm, pgd, new);
80003+ spin_unlock(&mm->page_table_lock);
80004+ return 0;
80005+}
80006 #endif /* __PAGETABLE_PUD_FOLDED */
80007
80008 #ifndef __PAGETABLE_PMD_FOLDED
80009@@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80010 spin_unlock(&mm->page_table_lock);
80011 return 0;
80012 }
80013+
80014+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80015+{
80016+ pmd_t *new = pmd_alloc_one(mm, address);
80017+ if (!new)
80018+ return -ENOMEM;
80019+
80020+ smp_wmb(); /* See comment in __pte_alloc */
80021+
80022+ spin_lock(&mm->page_table_lock);
80023+#ifndef __ARCH_HAS_4LEVEL_HACK
80024+ if (pud_present(*pud)) /* Another has populated it */
80025+ pmd_free(mm, new);
80026+ else
80027+ pud_populate_kernel(mm, pud, new);
80028+#else
80029+ if (pgd_present(*pud)) /* Another has populated it */
80030+ pmd_free(mm, new);
80031+ else
80032+ pgd_populate_kernel(mm, pud, new);
80033+#endif /* __ARCH_HAS_4LEVEL_HACK */
80034+ spin_unlock(&mm->page_table_lock);
80035+ return 0;
80036+}
80037 #endif /* __PAGETABLE_PMD_FOLDED */
80038
80039 int make_pages_present(unsigned long addr, unsigned long end)
80040@@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80041 gate_vma.vm_start = FIXADDR_USER_START;
80042 gate_vma.vm_end = FIXADDR_USER_END;
80043 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80044- gate_vma.vm_page_prot = __P101;
80045+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80046
80047 return 0;
80048 }
80049diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80050index e2df1c1..1e31d57 100644
80051--- a/mm/mempolicy.c
80052+++ b/mm/mempolicy.c
80053@@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80054 unsigned long vmstart;
80055 unsigned long vmend;
80056
80057+#ifdef CONFIG_PAX_SEGMEXEC
80058+ struct vm_area_struct *vma_m;
80059+#endif
80060+
80061 vma = find_vma(mm, start);
80062 if (!vma || vma->vm_start > start)
80063 return -EFAULT;
80064@@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80065 if (err)
80066 goto out;
80067 }
80068+
80069 err = vma_replace_policy(vma, new_pol);
80070 if (err)
80071 goto out;
80072+
80073+#ifdef CONFIG_PAX_SEGMEXEC
80074+ vma_m = pax_find_mirror_vma(vma);
80075+ if (vma_m) {
80076+ err = vma_replace_policy(vma_m, new_pol);
80077+ if (err)
80078+ goto out;
80079+ }
80080+#endif
80081+
80082 }
80083
80084 out:
80085@@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80086
80087 if (end < start)
80088 return -EINVAL;
80089+
80090+#ifdef CONFIG_PAX_SEGMEXEC
80091+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80092+ if (end > SEGMEXEC_TASK_SIZE)
80093+ return -EINVAL;
80094+ } else
80095+#endif
80096+
80097+ if (end > TASK_SIZE)
80098+ return -EINVAL;
80099+
80100 if (end == start)
80101 return 0;
80102
80103@@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80104 */
80105 tcred = __task_cred(task);
80106 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80107- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80108- !capable(CAP_SYS_NICE)) {
80109+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80110 rcu_read_unlock();
80111 err = -EPERM;
80112 goto out_put;
80113@@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80114 goto out;
80115 }
80116
80117+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80118+ if (mm != current->mm &&
80119+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80120+ mmput(mm);
80121+ err = -EPERM;
80122+ goto out;
80123+ }
80124+#endif
80125+
80126 err = do_migrate_pages(mm, old, new,
80127 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80128
80129diff --git a/mm/migrate.c b/mm/migrate.c
80130index 2fd8b4a..d70358f 100644
80131--- a/mm/migrate.c
80132+++ b/mm/migrate.c
80133@@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80134 */
80135 tcred = __task_cred(task);
80136 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80137- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80138- !capable(CAP_SYS_NICE)) {
80139+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80140 rcu_read_unlock();
80141 err = -EPERM;
80142 goto out;
80143diff --git a/mm/mlock.c b/mm/mlock.c
80144index c9bd528..da8d069 100644
80145--- a/mm/mlock.c
80146+++ b/mm/mlock.c
80147@@ -13,6 +13,7 @@
80148 #include <linux/pagemap.h>
80149 #include <linux/mempolicy.h>
80150 #include <linux/syscalls.h>
80151+#include <linux/security.h>
80152 #include <linux/sched.h>
80153 #include <linux/export.h>
80154 #include <linux/rmap.h>
80155@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80156 {
80157 unsigned long nstart, end, tmp;
80158 struct vm_area_struct * vma, * prev;
80159- int error;
80160+ int error = 0;
80161
80162 VM_BUG_ON(start & ~PAGE_MASK);
80163 VM_BUG_ON(len != PAGE_ALIGN(len));
80164@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80165 return -EINVAL;
80166 if (end == start)
80167 return 0;
80168+ if (end > TASK_SIZE)
80169+ return -EINVAL;
80170+
80171 vma = find_vma(current->mm, start);
80172 if (!vma || vma->vm_start > start)
80173 return -ENOMEM;
80174@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80175 for (nstart = start ; ; ) {
80176 vm_flags_t newflags;
80177
80178+#ifdef CONFIG_PAX_SEGMEXEC
80179+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80180+ break;
80181+#endif
80182+
80183 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80184
80185 newflags = vma->vm_flags | VM_LOCKED;
80186@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80187 lock_limit >>= PAGE_SHIFT;
80188
80189 /* check against resource limits */
80190+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80191 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80192 error = do_mlock(start, len, 1);
80193 up_write(&current->mm->mmap_sem);
80194@@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80195 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80196 vm_flags_t newflags;
80197
80198+#ifdef CONFIG_PAX_SEGMEXEC
80199+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80200+ break;
80201+#endif
80202+
80203+ BUG_ON(vma->vm_end > TASK_SIZE);
80204 newflags = vma->vm_flags | VM_LOCKED;
80205 if (!(flags & MCL_CURRENT))
80206 newflags &= ~VM_LOCKED;
80207@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80208 lock_limit >>= PAGE_SHIFT;
80209
80210 ret = -ENOMEM;
80211+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80212 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80213 capable(CAP_IPC_LOCK))
80214 ret = do_mlockall(flags);
80215diff --git a/mm/mmap.c b/mm/mmap.c
80216index 8832b87..20500c1 100644
80217--- a/mm/mmap.c
80218+++ b/mm/mmap.c
80219@@ -32,6 +32,7 @@
80220 #include <linux/khugepaged.h>
80221 #include <linux/uprobes.h>
80222 #include <linux/rbtree_augmented.h>
80223+#include <linux/random.h>
80224
80225 #include <asm/uaccess.h>
80226 #include <asm/cacheflush.h>
80227@@ -48,6 +49,16 @@
80228 #define arch_rebalance_pgtables(addr, len) (addr)
80229 #endif
80230
80231+static inline void verify_mm_writelocked(struct mm_struct *mm)
80232+{
80233+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80234+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80235+ up_read(&mm->mmap_sem);
80236+ BUG();
80237+ }
80238+#endif
80239+}
80240+
80241 static void unmap_region(struct mm_struct *mm,
80242 struct vm_area_struct *vma, struct vm_area_struct *prev,
80243 unsigned long start, unsigned long end);
80244@@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80245 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80246 *
80247 */
80248-pgprot_t protection_map[16] = {
80249+pgprot_t protection_map[16] __read_only = {
80250 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80251 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80252 };
80253
80254-pgprot_t vm_get_page_prot(unsigned long vm_flags)
80255+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80256 {
80257- return __pgprot(pgprot_val(protection_map[vm_flags &
80258+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
80259 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
80260 pgprot_val(arch_vm_get_page_prot(vm_flags)));
80261+
80262+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80263+ if (!(__supported_pte_mask & _PAGE_NX) &&
80264+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
80265+ (vm_flags & (VM_READ | VM_WRITE)))
80266+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
80267+#endif
80268+
80269+ return prot;
80270 }
80271 EXPORT_SYMBOL(vm_get_page_prot);
80272
80273 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
80274 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
80275 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
80276+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
80277 /*
80278 * Make sure vm_committed_as in one cacheline and not cacheline shared with
80279 * other variables. It can be updated by several CPUs frequently.
80280@@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
80281 struct vm_area_struct *next = vma->vm_next;
80282
80283 might_sleep();
80284+ BUG_ON(vma->vm_mirror);
80285 if (vma->vm_ops && vma->vm_ops->close)
80286 vma->vm_ops->close(vma);
80287 if (vma->vm_file)
80288@@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
80289 * not page aligned -Ram Gupta
80290 */
80291 rlim = rlimit(RLIMIT_DATA);
80292+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
80293 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
80294 (mm->end_data - mm->start_data) > rlim)
80295 goto out;
80296@@ -888,6 +911,12 @@ static int
80297 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
80298 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80299 {
80300+
80301+#ifdef CONFIG_PAX_SEGMEXEC
80302+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
80303+ return 0;
80304+#endif
80305+
80306 if (is_mergeable_vma(vma, file, vm_flags) &&
80307 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80308 if (vma->vm_pgoff == vm_pgoff)
80309@@ -907,6 +936,12 @@ static int
80310 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80311 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80312 {
80313+
80314+#ifdef CONFIG_PAX_SEGMEXEC
80315+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
80316+ return 0;
80317+#endif
80318+
80319 if (is_mergeable_vma(vma, file, vm_flags) &&
80320 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80321 pgoff_t vm_pglen;
80322@@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80323 struct vm_area_struct *vma_merge(struct mm_struct *mm,
80324 struct vm_area_struct *prev, unsigned long addr,
80325 unsigned long end, unsigned long vm_flags,
80326- struct anon_vma *anon_vma, struct file *file,
80327+ struct anon_vma *anon_vma, struct file *file,
80328 pgoff_t pgoff, struct mempolicy *policy)
80329 {
80330 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
80331 struct vm_area_struct *area, *next;
80332 int err;
80333
80334+#ifdef CONFIG_PAX_SEGMEXEC
80335+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
80336+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
80337+
80338+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
80339+#endif
80340+
80341 /*
80342 * We later require that vma->vm_flags == vm_flags,
80343 * so this tests vma->vm_flags & VM_SPECIAL, too.
80344@@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80345 if (next && next->vm_end == end) /* cases 6, 7, 8 */
80346 next = next->vm_next;
80347
80348+#ifdef CONFIG_PAX_SEGMEXEC
80349+ if (prev)
80350+ prev_m = pax_find_mirror_vma(prev);
80351+ if (area)
80352+ area_m = pax_find_mirror_vma(area);
80353+ if (next)
80354+ next_m = pax_find_mirror_vma(next);
80355+#endif
80356+
80357 /*
80358 * Can it merge with the predecessor?
80359 */
80360@@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80361 /* cases 1, 6 */
80362 err = vma_adjust(prev, prev->vm_start,
80363 next->vm_end, prev->vm_pgoff, NULL);
80364- } else /* cases 2, 5, 7 */
80365+
80366+#ifdef CONFIG_PAX_SEGMEXEC
80367+ if (!err && prev_m)
80368+ err = vma_adjust(prev_m, prev_m->vm_start,
80369+ next_m->vm_end, prev_m->vm_pgoff, NULL);
80370+#endif
80371+
80372+ } else { /* cases 2, 5, 7 */
80373 err = vma_adjust(prev, prev->vm_start,
80374 end, prev->vm_pgoff, NULL);
80375+
80376+#ifdef CONFIG_PAX_SEGMEXEC
80377+ if (!err && prev_m)
80378+ err = vma_adjust(prev_m, prev_m->vm_start,
80379+ end_m, prev_m->vm_pgoff, NULL);
80380+#endif
80381+
80382+ }
80383 if (err)
80384 return NULL;
80385 khugepaged_enter_vma_merge(prev);
80386@@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80387 mpol_equal(policy, vma_policy(next)) &&
80388 can_vma_merge_before(next, vm_flags,
80389 anon_vma, file, pgoff+pglen)) {
80390- if (prev && addr < prev->vm_end) /* case 4 */
80391+ if (prev && addr < prev->vm_end) { /* case 4 */
80392 err = vma_adjust(prev, prev->vm_start,
80393 addr, prev->vm_pgoff, NULL);
80394- else /* cases 3, 8 */
80395+
80396+#ifdef CONFIG_PAX_SEGMEXEC
80397+ if (!err && prev_m)
80398+ err = vma_adjust(prev_m, prev_m->vm_start,
80399+ addr_m, prev_m->vm_pgoff, NULL);
80400+#endif
80401+
80402+ } else { /* cases 3, 8 */
80403 err = vma_adjust(area, addr, next->vm_end,
80404 next->vm_pgoff - pglen, NULL);
80405+
80406+#ifdef CONFIG_PAX_SEGMEXEC
80407+ if (!err && area_m)
80408+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
80409+ next_m->vm_pgoff - pglen, NULL);
80410+#endif
80411+
80412+ }
80413 if (err)
80414 return NULL;
80415 khugepaged_enter_vma_merge(area);
80416@@ -1120,16 +1201,13 @@ none:
80417 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
80418 struct file *file, long pages)
80419 {
80420- const unsigned long stack_flags
80421- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
80422-
80423 mm->total_vm += pages;
80424
80425 if (file) {
80426 mm->shared_vm += pages;
80427 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
80428 mm->exec_vm += pages;
80429- } else if (flags & stack_flags)
80430+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
80431 mm->stack_vm += pages;
80432 }
80433 #endif /* CONFIG_PROC_FS */
80434@@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80435 * (the exception is when the underlying filesystem is noexec
80436 * mounted, in which case we dont add PROT_EXEC.)
80437 */
80438- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
80439+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
80440 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
80441 prot |= PROT_EXEC;
80442
80443@@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80444 /* Obtain the address to map to. we verify (or select) it and ensure
80445 * that it represents a valid section of the address space.
80446 */
80447- addr = get_unmapped_area(file, addr, len, pgoff, flags);
80448+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
80449 if (addr & ~PAGE_MASK)
80450 return addr;
80451
80452@@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80453 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
80454 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
80455
80456+#ifdef CONFIG_PAX_MPROTECT
80457+ if (mm->pax_flags & MF_PAX_MPROTECT) {
80458+#ifndef CONFIG_PAX_MPROTECT_COMPAT
80459+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
80460+ gr_log_rwxmmap(file);
80461+
80462+#ifdef CONFIG_PAX_EMUPLT
80463+ vm_flags &= ~VM_EXEC;
80464+#else
80465+ return -EPERM;
80466+#endif
80467+
80468+ }
80469+
80470+ if (!(vm_flags & VM_EXEC))
80471+ vm_flags &= ~VM_MAYEXEC;
80472+#else
80473+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
80474+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
80475+#endif
80476+ else
80477+ vm_flags &= ~VM_MAYWRITE;
80478+ }
80479+#endif
80480+
80481+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80482+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
80483+ vm_flags &= ~VM_PAGEEXEC;
80484+#endif
80485+
80486 if (flags & MAP_LOCKED)
80487 if (!can_do_mlock())
80488 return -EPERM;
80489@@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80490 locked += mm->locked_vm;
80491 lock_limit = rlimit(RLIMIT_MEMLOCK);
80492 lock_limit >>= PAGE_SHIFT;
80493+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80494 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
80495 return -EAGAIN;
80496 }
80497@@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80498 }
80499 }
80500
80501+ if (!gr_acl_handle_mmap(file, prot))
80502+ return -EACCES;
80503+
80504 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
80505 }
80506
80507@@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
80508 vm_flags_t vm_flags = vma->vm_flags;
80509
80510 /* If it was private or non-writable, the write bit is already clear */
80511- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
80512+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
80513 return 0;
80514
80515 /* The backer wishes to know when pages are first written to? */
80516@@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
80517 unsigned long charged = 0;
80518 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
80519
80520+#ifdef CONFIG_PAX_SEGMEXEC
80521+ struct vm_area_struct *vma_m = NULL;
80522+#endif
80523+
80524+ /*
80525+ * mm->mmap_sem is required to protect against another thread
80526+ * changing the mappings in case we sleep.
80527+ */
80528+ verify_mm_writelocked(mm);
80529+
80530 /* Clear old maps */
80531 error = -ENOMEM;
80532-munmap_back:
80533 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
80534 if (do_munmap(mm, addr, len))
80535 return -ENOMEM;
80536- goto munmap_back;
80537+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
80538 }
80539
80540 /* Check against address space limit. */
80541@@ -1460,6 +1581,16 @@ munmap_back:
80542 goto unacct_error;
80543 }
80544
80545+#ifdef CONFIG_PAX_SEGMEXEC
80546+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
80547+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
80548+ if (!vma_m) {
80549+ error = -ENOMEM;
80550+ goto free_vma;
80551+ }
80552+ }
80553+#endif
80554+
80555 vma->vm_mm = mm;
80556 vma->vm_start = addr;
80557 vma->vm_end = addr + len;
80558@@ -1484,6 +1615,13 @@ munmap_back:
80559 if (error)
80560 goto unmap_and_free_vma;
80561
80562+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80563+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
80564+ vma->vm_flags |= VM_PAGEEXEC;
80565+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
80566+ }
80567+#endif
80568+
80569 /* Can addr have changed??
80570 *
80571 * Answer: Yes, several device drivers can do it in their
80572@@ -1522,6 +1660,11 @@ munmap_back:
80573 vma_link(mm, vma, prev, rb_link, rb_parent);
80574 file = vma->vm_file;
80575
80576+#ifdef CONFIG_PAX_SEGMEXEC
80577+ if (vma_m)
80578+ BUG_ON(pax_mirror_vma(vma_m, vma));
80579+#endif
80580+
80581 /* Once vma denies write, undo our temporary denial count */
80582 if (correct_wcount)
80583 atomic_inc(&inode->i_writecount);
80584@@ -1529,6 +1672,7 @@ out:
80585 perf_event_mmap(vma);
80586
80587 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
80588+ track_exec_limit(mm, addr, addr + len, vm_flags);
80589 if (vm_flags & VM_LOCKED) {
80590 if (!mlock_vma_pages_range(vma, addr, addr + len))
80591 mm->locked_vm += (len >> PAGE_SHIFT);
80592@@ -1550,6 +1694,12 @@ unmap_and_free_vma:
80593 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
80594 charged = 0;
80595 free_vma:
80596+
80597+#ifdef CONFIG_PAX_SEGMEXEC
80598+ if (vma_m)
80599+ kmem_cache_free(vm_area_cachep, vma_m);
80600+#endif
80601+
80602 kmem_cache_free(vm_area_cachep, vma);
80603 unacct_error:
80604 if (charged)
80605@@ -1557,6 +1707,62 @@ unacct_error:
80606 return error;
80607 }
80608
80609+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80610+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80611+{
80612+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
80613+ return (random32() & 0xFF) << PAGE_SHIFT;
80614+
80615+ return 0;
80616+}
80617+#endif
80618+
80619+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
80620+{
80621+ if (!vma) {
80622+#ifdef CONFIG_STACK_GROWSUP
80623+ if (addr > sysctl_heap_stack_gap)
80624+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
80625+ else
80626+ vma = find_vma(current->mm, 0);
80627+ if (vma && (vma->vm_flags & VM_GROWSUP))
80628+ return false;
80629+#endif
80630+ return true;
80631+ }
80632+
80633+ if (addr + len > vma->vm_start)
80634+ return false;
80635+
80636+ if (vma->vm_flags & VM_GROWSDOWN)
80637+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
80638+#ifdef CONFIG_STACK_GROWSUP
80639+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
80640+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
80641+#endif
80642+ else if (offset)
80643+ return offset <= vma->vm_start - addr - len;
80644+
80645+ return true;
80646+}
80647+
80648+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
80649+{
80650+ if (vma->vm_start < len)
80651+ return -ENOMEM;
80652+
80653+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
80654+ if (offset <= vma->vm_start - len)
80655+ return vma->vm_start - len - offset;
80656+ else
80657+ return -ENOMEM;
80658+ }
80659+
80660+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
80661+ return vma->vm_start - len - sysctl_heap_stack_gap;
80662+ return -ENOMEM;
80663+}
80664+
80665 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
80666 {
80667 /*
80668@@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80669 struct mm_struct *mm = current->mm;
80670 struct vm_area_struct *vma;
80671 struct vm_unmapped_area_info info;
80672+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80673
80674 if (len > TASK_SIZE)
80675 return -ENOMEM;
80676@@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80677 if (flags & MAP_FIXED)
80678 return addr;
80679
80680+#ifdef CONFIG_PAX_RANDMMAP
80681+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80682+#endif
80683+
80684 if (addr) {
80685 addr = PAGE_ALIGN(addr);
80686 vma = find_vma(mm, addr);
80687- if (TASK_SIZE - len >= addr &&
80688- (!vma || addr + len <= vma->vm_start))
80689+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80690 return addr;
80691 }
80692
80693 info.flags = 0;
80694 info.length = len;
80695 info.low_limit = TASK_UNMAPPED_BASE;
80696+
80697+#ifdef CONFIG_PAX_RANDMMAP
80698+ if (mm->pax_flags & MF_PAX_RANDMMAP)
80699+ info.low_limit += mm->delta_mmap;
80700+#endif
80701+
80702 info.high_limit = TASK_SIZE;
80703 info.align_mask = 0;
80704 return vm_unmapped_area(&info);
80705@@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80706
80707 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
80708 {
80709+
80710+#ifdef CONFIG_PAX_SEGMEXEC
80711+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80712+ return;
80713+#endif
80714+
80715 /*
80716 * Is this a new hole at the lowest possible address?
80717 */
80718- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
80719+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
80720 mm->free_area_cache = addr;
80721 }
80722
80723@@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80724 struct mm_struct *mm = current->mm;
80725 unsigned long addr = addr0;
80726 struct vm_unmapped_area_info info;
80727+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80728
80729 /* requested length too big for entire address space */
80730 if (len > TASK_SIZE)
80731@@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80732 if (flags & MAP_FIXED)
80733 return addr;
80734
80735+#ifdef CONFIG_PAX_RANDMMAP
80736+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80737+#endif
80738+
80739 /* requesting a specific address */
80740 if (addr) {
80741 addr = PAGE_ALIGN(addr);
80742 vma = find_vma(mm, addr);
80743- if (TASK_SIZE - len >= addr &&
80744- (!vma || addr + len <= vma->vm_start))
80745+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80746 return addr;
80747 }
80748
80749@@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80750 VM_BUG_ON(addr != -ENOMEM);
80751 info.flags = 0;
80752 info.low_limit = TASK_UNMAPPED_BASE;
80753+
80754+#ifdef CONFIG_PAX_RANDMMAP
80755+ if (mm->pax_flags & MF_PAX_RANDMMAP)
80756+ info.low_limit += mm->delta_mmap;
80757+#endif
80758+
80759 info.high_limit = TASK_SIZE;
80760 addr = vm_unmapped_area(&info);
80761 }
80762@@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80763
80764 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80765 {
80766+
80767+#ifdef CONFIG_PAX_SEGMEXEC
80768+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80769+ return;
80770+#endif
80771+
80772 /*
80773 * Is this a new hole at the highest possible address?
80774 */
80775@@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80776 mm->free_area_cache = addr;
80777
80778 /* dont allow allocations above current base */
80779- if (mm->free_area_cache > mm->mmap_base)
80780+ if (mm->free_area_cache > mm->mmap_base) {
80781 mm->free_area_cache = mm->mmap_base;
80782+ mm->cached_hole_size = ~0UL;
80783+ }
80784 }
80785
80786 unsigned long
80787@@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
80788 return vma;
80789 }
80790
80791+#ifdef CONFIG_PAX_SEGMEXEC
80792+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
80793+{
80794+ struct vm_area_struct *vma_m;
80795+
80796+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
80797+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
80798+ BUG_ON(vma->vm_mirror);
80799+ return NULL;
80800+ }
80801+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
80802+ vma_m = vma->vm_mirror;
80803+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
80804+ BUG_ON(vma->vm_file != vma_m->vm_file);
80805+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
80806+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
80807+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
80808+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
80809+ return vma_m;
80810+}
80811+#endif
80812+
80813 /*
80814 * Verify that the stack growth is acceptable and
80815 * update accounting. This is shared with both the
80816@@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80817 return -ENOMEM;
80818
80819 /* Stack limit test */
80820+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
80821 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
80822 return -ENOMEM;
80823
80824@@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80825 locked = mm->locked_vm + grow;
80826 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
80827 limit >>= PAGE_SHIFT;
80828+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80829 if (locked > limit && !capable(CAP_IPC_LOCK))
80830 return -ENOMEM;
80831 }
80832@@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80833 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
80834 * vma is the last one with address > vma->vm_end. Have to extend vma.
80835 */
80836+#ifndef CONFIG_IA64
80837+static
80838+#endif
80839 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80840 {
80841 int error;
80842+ bool locknext;
80843
80844 if (!(vma->vm_flags & VM_GROWSUP))
80845 return -EFAULT;
80846
80847+ /* Also guard against wrapping around to address 0. */
80848+ if (address < PAGE_ALIGN(address+1))
80849+ address = PAGE_ALIGN(address+1);
80850+ else
80851+ return -ENOMEM;
80852+
80853 /*
80854 * We must make sure the anon_vma is allocated
80855 * so that the anon_vma locking is not a noop.
80856 */
80857 if (unlikely(anon_vma_prepare(vma)))
80858 return -ENOMEM;
80859+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
80860+ if (locknext && anon_vma_prepare(vma->vm_next))
80861+ return -ENOMEM;
80862 vma_lock_anon_vma(vma);
80863+ if (locknext)
80864+ vma_lock_anon_vma(vma->vm_next);
80865
80866 /*
80867 * vma->vm_start/vm_end cannot change under us because the caller
80868 * is required to hold the mmap_sem in read mode. We need the
80869- * anon_vma lock to serialize against concurrent expand_stacks.
80870- * Also guard against wrapping around to address 0.
80871+ * anon_vma locks to serialize against concurrent expand_stacks
80872+ * and expand_upwards.
80873 */
80874- if (address < PAGE_ALIGN(address+4))
80875- address = PAGE_ALIGN(address+4);
80876- else {
80877- vma_unlock_anon_vma(vma);
80878- return -ENOMEM;
80879- }
80880 error = 0;
80881
80882 /* Somebody else might have raced and expanded it already */
80883- if (address > vma->vm_end) {
80884+ 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)
80885+ error = -ENOMEM;
80886+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
80887 unsigned long size, grow;
80888
80889 size = address - vma->vm_start;
80890@@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80891 }
80892 }
80893 }
80894+ if (locknext)
80895+ vma_unlock_anon_vma(vma->vm_next);
80896 vma_unlock_anon_vma(vma);
80897 khugepaged_enter_vma_merge(vma);
80898 validate_mm(vma->vm_mm);
80899@@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
80900 unsigned long address)
80901 {
80902 int error;
80903+ bool lockprev = false;
80904+ struct vm_area_struct *prev;
80905
80906 /*
80907 * We must make sure the anon_vma is allocated
80908@@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
80909 if (error)
80910 return error;
80911
80912+ prev = vma->vm_prev;
80913+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
80914+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
80915+#endif
80916+ if (lockprev && anon_vma_prepare(prev))
80917+ return -ENOMEM;
80918+ if (lockprev)
80919+ vma_lock_anon_vma(prev);
80920+
80921 vma_lock_anon_vma(vma);
80922
80923 /*
80924@@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
80925 */
80926
80927 /* Somebody else might have raced and expanded it already */
80928- if (address < vma->vm_start) {
80929+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
80930+ error = -ENOMEM;
80931+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
80932 unsigned long size, grow;
80933
80934+#ifdef CONFIG_PAX_SEGMEXEC
80935+ struct vm_area_struct *vma_m;
80936+
80937+ vma_m = pax_find_mirror_vma(vma);
80938+#endif
80939+
80940 size = vma->vm_end - address;
80941 grow = (vma->vm_start - address) >> PAGE_SHIFT;
80942
80943@@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
80944 vma->vm_pgoff -= grow;
80945 anon_vma_interval_tree_post_update_vma(vma);
80946 vma_gap_update(vma);
80947+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
80948+
80949+#ifdef CONFIG_PAX_SEGMEXEC
80950+ if (vma_m) {
80951+ anon_vma_interval_tree_pre_update_vma(vma_m);
80952+ vma_m->vm_start -= grow << PAGE_SHIFT;
80953+ vma_m->vm_pgoff -= grow;
80954+ anon_vma_interval_tree_post_update_vma(vma_m);
80955+ vma_gap_update(vma_m);
80956+ }
80957+#endif
80958+
80959 spin_unlock(&vma->vm_mm->page_table_lock);
80960
80961 perf_event_mmap(vma);
80962@@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
80963 do {
80964 long nrpages = vma_pages(vma);
80965
80966+#ifdef CONFIG_PAX_SEGMEXEC
80967+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
80968+ vma = remove_vma(vma);
80969+ continue;
80970+ }
80971+#endif
80972+
80973 if (vma->vm_flags & VM_ACCOUNT)
80974 nr_accounted += nrpages;
80975 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
80976@@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
80977 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
80978 vma->vm_prev = NULL;
80979 do {
80980+
80981+#ifdef CONFIG_PAX_SEGMEXEC
80982+ if (vma->vm_mirror) {
80983+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
80984+ vma->vm_mirror->vm_mirror = NULL;
80985+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
80986+ vma->vm_mirror = NULL;
80987+ }
80988+#endif
80989+
80990 vma_rb_erase(vma, &mm->mm_rb);
80991 mm->map_count--;
80992 tail_vma = vma;
80993@@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80994 struct vm_area_struct *new;
80995 int err = -ENOMEM;
80996
80997+#ifdef CONFIG_PAX_SEGMEXEC
80998+ struct vm_area_struct *vma_m, *new_m = NULL;
80999+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
81000+#endif
81001+
81002 if (is_vm_hugetlb_page(vma) && (addr &
81003 ~(huge_page_mask(hstate_vma(vma)))))
81004 return -EINVAL;
81005
81006+#ifdef CONFIG_PAX_SEGMEXEC
81007+ vma_m = pax_find_mirror_vma(vma);
81008+#endif
81009+
81010 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81011 if (!new)
81012 goto out_err;
81013
81014+#ifdef CONFIG_PAX_SEGMEXEC
81015+ if (vma_m) {
81016+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81017+ if (!new_m) {
81018+ kmem_cache_free(vm_area_cachep, new);
81019+ goto out_err;
81020+ }
81021+ }
81022+#endif
81023+
81024 /* most fields are the same, copy all, and then fixup */
81025 *new = *vma;
81026
81027@@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81028 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81029 }
81030
81031+#ifdef CONFIG_PAX_SEGMEXEC
81032+ if (vma_m) {
81033+ *new_m = *vma_m;
81034+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
81035+ new_m->vm_mirror = new;
81036+ new->vm_mirror = new_m;
81037+
81038+ if (new_below)
81039+ new_m->vm_end = addr_m;
81040+ else {
81041+ new_m->vm_start = addr_m;
81042+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81043+ }
81044+ }
81045+#endif
81046+
81047 pol = mpol_dup(vma_policy(vma));
81048 if (IS_ERR(pol)) {
81049 err = PTR_ERR(pol);
81050@@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81051 else
81052 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81053
81054+#ifdef CONFIG_PAX_SEGMEXEC
81055+ if (!err && vma_m) {
81056+ if (anon_vma_clone(new_m, vma_m))
81057+ goto out_free_mpol;
81058+
81059+ mpol_get(pol);
81060+ vma_set_policy(new_m, pol);
81061+
81062+ if (new_m->vm_file)
81063+ get_file(new_m->vm_file);
81064+
81065+ if (new_m->vm_ops && new_m->vm_ops->open)
81066+ new_m->vm_ops->open(new_m);
81067+
81068+ if (new_below)
81069+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81070+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81071+ else
81072+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81073+
81074+ if (err) {
81075+ if (new_m->vm_ops && new_m->vm_ops->close)
81076+ new_m->vm_ops->close(new_m);
81077+ if (new_m->vm_file)
81078+ fput(new_m->vm_file);
81079+ mpol_put(pol);
81080+ }
81081+ }
81082+#endif
81083+
81084 /* Success. */
81085 if (!err)
81086 return 0;
81087@@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81088 new->vm_ops->close(new);
81089 if (new->vm_file)
81090 fput(new->vm_file);
81091- unlink_anon_vmas(new);
81092 out_free_mpol:
81093 mpol_put(pol);
81094 out_free_vma:
81095+
81096+#ifdef CONFIG_PAX_SEGMEXEC
81097+ if (new_m) {
81098+ unlink_anon_vmas(new_m);
81099+ kmem_cache_free(vm_area_cachep, new_m);
81100+ }
81101+#endif
81102+
81103+ unlink_anon_vmas(new);
81104 kmem_cache_free(vm_area_cachep, new);
81105 out_err:
81106 return err;
81107@@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81108 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81109 unsigned long addr, int new_below)
81110 {
81111+
81112+#ifdef CONFIG_PAX_SEGMEXEC
81113+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81114+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81115+ if (mm->map_count >= sysctl_max_map_count-1)
81116+ return -ENOMEM;
81117+ } else
81118+#endif
81119+
81120 if (mm->map_count >= sysctl_max_map_count)
81121 return -ENOMEM;
81122
81123@@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81124 * work. This now handles partial unmappings.
81125 * Jeremy Fitzhardinge <jeremy@goop.org>
81126 */
81127+#ifdef CONFIG_PAX_SEGMEXEC
81128 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81129 {
81130+ int ret = __do_munmap(mm, start, len);
81131+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81132+ return ret;
81133+
81134+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81135+}
81136+
81137+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81138+#else
81139+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81140+#endif
81141+{
81142 unsigned long end;
81143 struct vm_area_struct *vma, *prev, *last;
81144
81145+ /*
81146+ * mm->mmap_sem is required to protect against another thread
81147+ * changing the mappings in case we sleep.
81148+ */
81149+ verify_mm_writelocked(mm);
81150+
81151 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81152 return -EINVAL;
81153
81154@@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81155 /* Fix up all other VM information */
81156 remove_vma_list(mm, vma);
81157
81158+ track_exec_limit(mm, start, end, 0UL);
81159+
81160 return 0;
81161 }
81162
81163@@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
81164 int ret;
81165 struct mm_struct *mm = current->mm;
81166
81167+
81168+#ifdef CONFIG_PAX_SEGMEXEC
81169+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81170+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81171+ return -EINVAL;
81172+#endif
81173+
81174 down_write(&mm->mmap_sem);
81175 ret = do_munmap(mm, start, len);
81176 up_write(&mm->mmap_sem);
81177@@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81178 return vm_munmap(addr, len);
81179 }
81180
81181-static inline void verify_mm_writelocked(struct mm_struct *mm)
81182-{
81183-#ifdef CONFIG_DEBUG_VM
81184- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81185- WARN_ON(1);
81186- up_read(&mm->mmap_sem);
81187- }
81188-#endif
81189-}
81190-
81191 /*
81192 * this is really a simplified "do_mmap". it only handles
81193 * anonymous maps. eventually we may be able to do some
81194@@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81195 struct rb_node ** rb_link, * rb_parent;
81196 pgoff_t pgoff = addr >> PAGE_SHIFT;
81197 int error;
81198+ unsigned long charged;
81199
81200 len = PAGE_ALIGN(len);
81201 if (!len)
81202@@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81203
81204 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81205
81206+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81207+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81208+ flags &= ~VM_EXEC;
81209+
81210+#ifdef CONFIG_PAX_MPROTECT
81211+ if (mm->pax_flags & MF_PAX_MPROTECT)
81212+ flags &= ~VM_MAYEXEC;
81213+#endif
81214+
81215+ }
81216+#endif
81217+
81218 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81219 if (error & ~PAGE_MASK)
81220 return error;
81221
81222+ charged = len >> PAGE_SHIFT;
81223+
81224 /*
81225 * mlock MCL_FUTURE?
81226 */
81227 if (mm->def_flags & VM_LOCKED) {
81228 unsigned long locked, lock_limit;
81229- locked = len >> PAGE_SHIFT;
81230+ locked = charged;
81231 locked += mm->locked_vm;
81232 lock_limit = rlimit(RLIMIT_MEMLOCK);
81233 lock_limit >>= PAGE_SHIFT;
81234@@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81235 /*
81236 * Clear old maps. this also does some error checking for us
81237 */
81238- munmap_back:
81239 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81240 if (do_munmap(mm, addr, len))
81241 return -ENOMEM;
81242- goto munmap_back;
81243+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81244 }
81245
81246 /* Check against address space limits *after* clearing old maps... */
81247- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81248+ if (!may_expand_vm(mm, charged))
81249 return -ENOMEM;
81250
81251 if (mm->map_count > sysctl_max_map_count)
81252 return -ENOMEM;
81253
81254- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
81255+ if (security_vm_enough_memory_mm(mm, charged))
81256 return -ENOMEM;
81257
81258 /* Can we just expand an old private anonymous mapping? */
81259@@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81260 */
81261 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81262 if (!vma) {
81263- vm_unacct_memory(len >> PAGE_SHIFT);
81264+ vm_unacct_memory(charged);
81265 return -ENOMEM;
81266 }
81267
81268@@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81269 vma_link(mm, vma, prev, rb_link, rb_parent);
81270 out:
81271 perf_event_mmap(vma);
81272- mm->total_vm += len >> PAGE_SHIFT;
81273+ mm->total_vm += charged;
81274 if (flags & VM_LOCKED) {
81275 if (!mlock_vma_pages_range(vma, addr, addr + len))
81276- mm->locked_vm += (len >> PAGE_SHIFT);
81277+ mm->locked_vm += charged;
81278 }
81279+ track_exec_limit(mm, addr, addr + len, flags);
81280 return addr;
81281 }
81282
81283@@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
81284 while (vma) {
81285 if (vma->vm_flags & VM_ACCOUNT)
81286 nr_accounted += vma_pages(vma);
81287+ vma->vm_mirror = NULL;
81288 vma = remove_vma(vma);
81289 }
81290 vm_unacct_memory(nr_accounted);
81291@@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81292 struct vm_area_struct *prev;
81293 struct rb_node **rb_link, *rb_parent;
81294
81295+#ifdef CONFIG_PAX_SEGMEXEC
81296+ struct vm_area_struct *vma_m = NULL;
81297+#endif
81298+
81299+ if (security_mmap_addr(vma->vm_start))
81300+ return -EPERM;
81301+
81302 /*
81303 * The vm_pgoff of a purely anonymous vma should be irrelevant
81304 * until its first write fault, when page's anon_vma and index
81305@@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81306 security_vm_enough_memory_mm(mm, vma_pages(vma)))
81307 return -ENOMEM;
81308
81309+#ifdef CONFIG_PAX_SEGMEXEC
81310+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
81311+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81312+ if (!vma_m)
81313+ return -ENOMEM;
81314+ }
81315+#endif
81316+
81317 vma_link(mm, vma, prev, rb_link, rb_parent);
81318+
81319+#ifdef CONFIG_PAX_SEGMEXEC
81320+ if (vma_m)
81321+ BUG_ON(pax_mirror_vma(vma_m, vma));
81322+#endif
81323+
81324 return 0;
81325 }
81326
81327@@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81328 struct mempolicy *pol;
81329 bool faulted_in_anon_vma = true;
81330
81331+ BUG_ON(vma->vm_mirror);
81332+
81333 /*
81334 * If anonymous vma has not yet been faulted, update new pgoff
81335 * to match new location, to increase its chance of merging.
81336@@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81337 return NULL;
81338 }
81339
81340+#ifdef CONFIG_PAX_SEGMEXEC
81341+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
81342+{
81343+ struct vm_area_struct *prev_m;
81344+ struct rb_node **rb_link_m, *rb_parent_m;
81345+ struct mempolicy *pol_m;
81346+
81347+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
81348+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
81349+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
81350+ *vma_m = *vma;
81351+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
81352+ if (anon_vma_clone(vma_m, vma))
81353+ return -ENOMEM;
81354+ pol_m = vma_policy(vma_m);
81355+ mpol_get(pol_m);
81356+ vma_set_policy(vma_m, pol_m);
81357+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
81358+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
81359+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
81360+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
81361+ if (vma_m->vm_file)
81362+ get_file(vma_m->vm_file);
81363+ if (vma_m->vm_ops && vma_m->vm_ops->open)
81364+ vma_m->vm_ops->open(vma_m);
81365+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
81366+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
81367+ vma_m->vm_mirror = vma;
81368+ vma->vm_mirror = vma_m;
81369+ return 0;
81370+}
81371+#endif
81372+
81373 /*
81374 * Return true if the calling process may expand its vm space by the passed
81375 * number of pages
81376@@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
81377
81378 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
81379
81380+#ifdef CONFIG_PAX_RANDMMAP
81381+ if (mm->pax_flags & MF_PAX_RANDMMAP)
81382+ cur -= mm->aslr_gap;
81383+#endif
81384+
81385+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
81386 if (cur + npages > lim)
81387 return 0;
81388 return 1;
81389@@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
81390 vma->vm_start = addr;
81391 vma->vm_end = addr + len;
81392
81393+#ifdef CONFIG_PAX_MPROTECT
81394+ if (mm->pax_flags & MF_PAX_MPROTECT) {
81395+#ifndef CONFIG_PAX_MPROTECT_COMPAT
81396+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
81397+ return -EPERM;
81398+ if (!(vm_flags & VM_EXEC))
81399+ vm_flags &= ~VM_MAYEXEC;
81400+#else
81401+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81402+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81403+#endif
81404+ else
81405+ vm_flags &= ~VM_MAYWRITE;
81406+ }
81407+#endif
81408+
81409 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
81410 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81411
81412diff --git a/mm/mprotect.c b/mm/mprotect.c
81413index 94722a4..9837984 100644
81414--- a/mm/mprotect.c
81415+++ b/mm/mprotect.c
81416@@ -23,10 +23,17 @@
81417 #include <linux/mmu_notifier.h>
81418 #include <linux/migrate.h>
81419 #include <linux/perf_event.h>
81420+
81421+#ifdef CONFIG_PAX_MPROTECT
81422+#include <linux/elf.h>
81423+#include <linux/binfmts.h>
81424+#endif
81425+
81426 #include <asm/uaccess.h>
81427 #include <asm/pgtable.h>
81428 #include <asm/cacheflush.h>
81429 #include <asm/tlbflush.h>
81430+#include <asm/mmu_context.h>
81431
81432 #ifndef pgprot_modify
81433 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
81434@@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
81435 return pages;
81436 }
81437
81438+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81439+/* called while holding the mmap semaphor for writing except stack expansion */
81440+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
81441+{
81442+ unsigned long oldlimit, newlimit = 0UL;
81443+
81444+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
81445+ return;
81446+
81447+ spin_lock(&mm->page_table_lock);
81448+ oldlimit = mm->context.user_cs_limit;
81449+ if ((prot & VM_EXEC) && oldlimit < end)
81450+ /* USER_CS limit moved up */
81451+ newlimit = end;
81452+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
81453+ /* USER_CS limit moved down */
81454+ newlimit = start;
81455+
81456+ if (newlimit) {
81457+ mm->context.user_cs_limit = newlimit;
81458+
81459+#ifdef CONFIG_SMP
81460+ wmb();
81461+ cpus_clear(mm->context.cpu_user_cs_mask);
81462+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
81463+#endif
81464+
81465+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
81466+ }
81467+ spin_unlock(&mm->page_table_lock);
81468+ if (newlimit == end) {
81469+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
81470+
81471+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
81472+ if (is_vm_hugetlb_page(vma))
81473+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
81474+ else
81475+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
81476+ }
81477+}
81478+#endif
81479+
81480 int
81481 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81482 unsigned long start, unsigned long end, unsigned long newflags)
81483@@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81484 int error;
81485 int dirty_accountable = 0;
81486
81487+#ifdef CONFIG_PAX_SEGMEXEC
81488+ struct vm_area_struct *vma_m = NULL;
81489+ unsigned long start_m, end_m;
81490+
81491+ start_m = start + SEGMEXEC_TASK_SIZE;
81492+ end_m = end + SEGMEXEC_TASK_SIZE;
81493+#endif
81494+
81495 if (newflags == oldflags) {
81496 *pprev = vma;
81497 return 0;
81498 }
81499
81500+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
81501+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
81502+
81503+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
81504+ return -ENOMEM;
81505+
81506+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
81507+ return -ENOMEM;
81508+ }
81509+
81510 /*
81511 * If we make a private mapping writable we increase our commit;
81512 * but (without finer accounting) cannot reduce our commit if we
81513@@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81514 }
81515 }
81516
81517+#ifdef CONFIG_PAX_SEGMEXEC
81518+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
81519+ if (start != vma->vm_start) {
81520+ error = split_vma(mm, vma, start, 1);
81521+ if (error)
81522+ goto fail;
81523+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
81524+ *pprev = (*pprev)->vm_next;
81525+ }
81526+
81527+ if (end != vma->vm_end) {
81528+ error = split_vma(mm, vma, end, 0);
81529+ if (error)
81530+ goto fail;
81531+ }
81532+
81533+ if (pax_find_mirror_vma(vma)) {
81534+ error = __do_munmap(mm, start_m, end_m - start_m);
81535+ if (error)
81536+ goto fail;
81537+ } else {
81538+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81539+ if (!vma_m) {
81540+ error = -ENOMEM;
81541+ goto fail;
81542+ }
81543+ vma->vm_flags = newflags;
81544+ error = pax_mirror_vma(vma_m, vma);
81545+ if (error) {
81546+ vma->vm_flags = oldflags;
81547+ goto fail;
81548+ }
81549+ }
81550+ }
81551+#endif
81552+
81553 /*
81554 * First try to merge with previous and/or next vma.
81555 */
81556@@ -296,9 +399,21 @@ success:
81557 * vm_flags and vm_page_prot are protected by the mmap_sem
81558 * held in write mode.
81559 */
81560+
81561+#ifdef CONFIG_PAX_SEGMEXEC
81562+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
81563+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
81564+#endif
81565+
81566 vma->vm_flags = newflags;
81567+
81568+#ifdef CONFIG_PAX_MPROTECT
81569+ if (mm->binfmt && mm->binfmt->handle_mprotect)
81570+ mm->binfmt->handle_mprotect(vma, newflags);
81571+#endif
81572+
81573 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
81574- vm_get_page_prot(newflags));
81575+ vm_get_page_prot(vma->vm_flags));
81576
81577 if (vma_wants_writenotify(vma)) {
81578 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
81579@@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81580 end = start + len;
81581 if (end <= start)
81582 return -ENOMEM;
81583+
81584+#ifdef CONFIG_PAX_SEGMEXEC
81585+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81586+ if (end > SEGMEXEC_TASK_SIZE)
81587+ return -EINVAL;
81588+ } else
81589+#endif
81590+
81591+ if (end > TASK_SIZE)
81592+ return -EINVAL;
81593+
81594 if (!arch_validate_prot(prot))
81595 return -EINVAL;
81596
81597@@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81598 /*
81599 * Does the application expect PROT_READ to imply PROT_EXEC:
81600 */
81601- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81602+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81603 prot |= PROT_EXEC;
81604
81605 vm_flags = calc_vm_prot_bits(prot);
81606@@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81607 if (start > vma->vm_start)
81608 prev = vma;
81609
81610+#ifdef CONFIG_PAX_MPROTECT
81611+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
81612+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
81613+#endif
81614+
81615 for (nstart = start ; ; ) {
81616 unsigned long newflags;
81617
81618@@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81619
81620 /* newflags >> 4 shift VM_MAY% in place of VM_% */
81621 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
81622+ if (prot & (PROT_WRITE | PROT_EXEC))
81623+ gr_log_rwxmprotect(vma->vm_file);
81624+
81625+ error = -EACCES;
81626+ goto out;
81627+ }
81628+
81629+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
81630 error = -EACCES;
81631 goto out;
81632 }
81633@@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81634 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
81635 if (error)
81636 goto out;
81637+
81638+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
81639+
81640 nstart = tmp;
81641
81642 if (nstart < prev->vm_end)
81643diff --git a/mm/mremap.c b/mm/mremap.c
81644index e1031e1..1f2a0a1 100644
81645--- a/mm/mremap.c
81646+++ b/mm/mremap.c
81647@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
81648 continue;
81649 pte = ptep_get_and_clear(mm, old_addr, old_pte);
81650 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
81651+
81652+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81653+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
81654+ pte = pte_exprotect(pte);
81655+#endif
81656+
81657 set_pte_at(mm, new_addr, new_pte, pte);
81658 }
81659
81660@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
81661 if (is_vm_hugetlb_page(vma))
81662 goto Einval;
81663
81664+#ifdef CONFIG_PAX_SEGMEXEC
81665+ if (pax_find_mirror_vma(vma))
81666+ goto Einval;
81667+#endif
81668+
81669 /* We can't remap across vm area boundaries */
81670 if (old_len > vma->vm_end - addr)
81671 goto Efault;
81672@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
81673 unsigned long ret = -EINVAL;
81674 unsigned long charged = 0;
81675 unsigned long map_flags;
81676+ unsigned long pax_task_size = TASK_SIZE;
81677
81678 if (new_addr & ~PAGE_MASK)
81679 goto out;
81680
81681- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
81682+#ifdef CONFIG_PAX_SEGMEXEC
81683+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
81684+ pax_task_size = SEGMEXEC_TASK_SIZE;
81685+#endif
81686+
81687+ pax_task_size -= PAGE_SIZE;
81688+
81689+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
81690 goto out;
81691
81692 /* Check if the location we're moving into overlaps the
81693 * old location at all, and fail if it does.
81694 */
81695- if ((new_addr <= addr) && (new_addr+new_len) > addr)
81696- goto out;
81697-
81698- if ((addr <= new_addr) && (addr+old_len) > new_addr)
81699+ if (addr + old_len > new_addr && new_addr + new_len > addr)
81700 goto out;
81701
81702 ret = do_munmap(mm, new_addr, new_len);
81703@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81704 struct vm_area_struct *vma;
81705 unsigned long ret = -EINVAL;
81706 unsigned long charged = 0;
81707+ unsigned long pax_task_size = TASK_SIZE;
81708
81709 down_write(&current->mm->mmap_sem);
81710
81711@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81712 if (!new_len)
81713 goto out;
81714
81715+#ifdef CONFIG_PAX_SEGMEXEC
81716+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
81717+ pax_task_size = SEGMEXEC_TASK_SIZE;
81718+#endif
81719+
81720+ pax_task_size -= PAGE_SIZE;
81721+
81722+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
81723+ old_len > pax_task_size || addr > pax_task_size-old_len)
81724+ goto out;
81725+
81726 if (flags & MREMAP_FIXED) {
81727 if (flags & MREMAP_MAYMOVE)
81728 ret = mremap_to(addr, old_len, new_addr, new_len);
81729@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81730 addr + new_len);
81731 }
81732 ret = addr;
81733+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
81734 goto out;
81735 }
81736 }
81737@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81738 goto out;
81739 }
81740
81741+ map_flags = vma->vm_flags;
81742 ret = move_vma(vma, addr, old_len, new_len, new_addr);
81743+ if (!(ret & ~PAGE_MASK)) {
81744+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
81745+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
81746+ }
81747 }
81748 out:
81749 if (ret & ~PAGE_MASK)
81750diff --git a/mm/nommu.c b/mm/nommu.c
81751index 79c3cac..4d357e0 100644
81752--- a/mm/nommu.c
81753+++ b/mm/nommu.c
81754@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
81755 int sysctl_overcommit_ratio = 50; /* default is 50% */
81756 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
81757 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
81758-int heap_stack_gap = 0;
81759
81760 atomic_long_t mmap_pages_allocated;
81761
81762@@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
81763 EXPORT_SYMBOL(find_vma);
81764
81765 /*
81766- * find a VMA
81767- * - we don't extend stack VMAs under NOMMU conditions
81768- */
81769-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
81770-{
81771- return find_vma(mm, addr);
81772-}
81773-
81774-/*
81775 * expand a stack to a given address
81776 * - not supported under NOMMU conditions
81777 */
81778@@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81779
81780 /* most fields are the same, copy all, and then fixup */
81781 *new = *vma;
81782+ INIT_LIST_HEAD(&new->anon_vma_chain);
81783 *region = *vma->vm_region;
81784 new->vm_region = region;
81785
81786diff --git a/mm/page-writeback.c b/mm/page-writeback.c
81787index 0713bfb..e3774e0 100644
81788--- a/mm/page-writeback.c
81789+++ b/mm/page-writeback.c
81790@@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
81791 }
81792 }
81793
81794-static struct notifier_block __cpuinitdata ratelimit_nb = {
81795+static struct notifier_block ratelimit_nb = {
81796 .notifier_call = ratelimit_handler,
81797 .next = NULL,
81798 };
81799diff --git a/mm/page_alloc.c b/mm/page_alloc.c
81800index 6a83cd3..3ab04ef 100644
81801--- a/mm/page_alloc.c
81802+++ b/mm/page_alloc.c
81803@@ -58,6 +58,7 @@
81804 #include <linux/prefetch.h>
81805 #include <linux/migrate.h>
81806 #include <linux/page-debug-flags.h>
81807+#include <linux/random.h>
81808
81809 #include <asm/tlbflush.h>
81810 #include <asm/div64.h>
81811@@ -338,7 +339,7 @@ out:
81812 * This usage means that zero-order pages may not be compound.
81813 */
81814
81815-static void free_compound_page(struct page *page)
81816+void free_compound_page(struct page *page)
81817 {
81818 __free_pages_ok(page, compound_order(page));
81819 }
81820@@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81821 int i;
81822 int bad = 0;
81823
81824+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81825+ unsigned long index = 1UL << order;
81826+#endif
81827+
81828 trace_mm_page_free(page, order);
81829 kmemcheck_free_shadow(page, order);
81830
81831@@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81832 debug_check_no_obj_freed(page_address(page),
81833 PAGE_SIZE << order);
81834 }
81835+
81836+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81837+ for (; index; --index)
81838+ sanitize_highpage(page + index - 1);
81839+#endif
81840+
81841 arch_free_page(page, order);
81842 kernel_map_pages(page, 1 << order, 0);
81843
81844@@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
81845 local_irq_restore(flags);
81846 }
81847
81848+#ifdef CONFIG_PAX_LATENT_ENTROPY
81849+bool __meminitdata extra_latent_entropy;
81850+
81851+static int __init setup_pax_extra_latent_entropy(char *str)
81852+{
81853+ extra_latent_entropy = true;
81854+ return 0;
81855+}
81856+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
81857+
81858+volatile u64 latent_entropy;
81859+#endif
81860+
81861 /*
81862 * Read access to zone->managed_pages is safe because it's unsigned long,
81863 * but we still need to serialize writers. Currently all callers of
81864@@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
81865 set_page_count(p, 0);
81866 }
81867
81868+#ifdef CONFIG_PAX_LATENT_ENTROPY
81869+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
81870+ u64 hash = 0;
81871+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
81872+ const u64 *data = lowmem_page_address(page);
81873+
81874+ for (index = 0; index < end; index++)
81875+ hash ^= hash + data[index];
81876+ latent_entropy ^= hash;
81877+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81878+ }
81879+#endif
81880+
81881 page_zone(page)->managed_pages += 1 << order;
81882 set_page_refcounted(page);
81883 __free_pages(page, order);
81884@@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
81885 arch_alloc_page(page, order);
81886 kernel_map_pages(page, 1 << order, 1);
81887
81888+#ifndef CONFIG_PAX_MEMORY_SANITIZE
81889 if (gfp_flags & __GFP_ZERO)
81890 prep_zero_page(page, order, gfp_flags);
81891+#endif
81892
81893 if (order && (gfp_flags & __GFP_COMP))
81894 prep_compound_page(page, order);
81895@@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
81896 unsigned long pfn;
81897
81898 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
81899+#ifdef CONFIG_X86_32
81900+ /* boot failures in VMware 8 on 32bit vanilla since
81901+ this change */
81902+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
81903+#else
81904 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
81905+#endif
81906 return 1;
81907 }
81908 return 0;
81909diff --git a/mm/percpu.c b/mm/percpu.c
81910index 8c8e08f..73a5cda 100644
81911--- a/mm/percpu.c
81912+++ b/mm/percpu.c
81913@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
81914 static unsigned int pcpu_high_unit_cpu __read_mostly;
81915
81916 /* the address of the first chunk which starts with the kernel static area */
81917-void *pcpu_base_addr __read_mostly;
81918+void *pcpu_base_addr __read_only;
81919 EXPORT_SYMBOL_GPL(pcpu_base_addr);
81920
81921 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
81922diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
81923index 926b466..b23df53 100644
81924--- a/mm/process_vm_access.c
81925+++ b/mm/process_vm_access.c
81926@@ -13,6 +13,7 @@
81927 #include <linux/uio.h>
81928 #include <linux/sched.h>
81929 #include <linux/highmem.h>
81930+#include <linux/security.h>
81931 #include <linux/ptrace.h>
81932 #include <linux/slab.h>
81933 #include <linux/syscalls.h>
81934@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81935 size_t iov_l_curr_offset = 0;
81936 ssize_t iov_len;
81937
81938+ return -ENOSYS; // PaX: until properly audited
81939+
81940 /*
81941 * Work out how many pages of struct pages we're going to need
81942 * when eventually calling get_user_pages
81943 */
81944 for (i = 0; i < riovcnt; i++) {
81945 iov_len = rvec[i].iov_len;
81946- if (iov_len > 0) {
81947- nr_pages_iov = ((unsigned long)rvec[i].iov_base
81948- + iov_len)
81949- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
81950- / PAGE_SIZE + 1;
81951- nr_pages = max(nr_pages, nr_pages_iov);
81952- }
81953+ if (iov_len <= 0)
81954+ continue;
81955+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
81956+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
81957+ nr_pages = max(nr_pages, nr_pages_iov);
81958 }
81959
81960 if (nr_pages == 0)
81961@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81962 goto free_proc_pages;
81963 }
81964
81965+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
81966+ rc = -EPERM;
81967+ goto put_task_struct;
81968+ }
81969+
81970 mm = mm_access(task, PTRACE_MODE_ATTACH);
81971 if (!mm || IS_ERR(mm)) {
81972 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
81973diff --git a/mm/rmap.c b/mm/rmap.c
81974index 2c78f8c..9e9c624 100644
81975--- a/mm/rmap.c
81976+++ b/mm/rmap.c
81977@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81978 struct anon_vma *anon_vma = vma->anon_vma;
81979 struct anon_vma_chain *avc;
81980
81981+#ifdef CONFIG_PAX_SEGMEXEC
81982+ struct anon_vma_chain *avc_m = NULL;
81983+#endif
81984+
81985 might_sleep();
81986 if (unlikely(!anon_vma)) {
81987 struct mm_struct *mm = vma->vm_mm;
81988@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81989 if (!avc)
81990 goto out_enomem;
81991
81992+#ifdef CONFIG_PAX_SEGMEXEC
81993+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
81994+ if (!avc_m)
81995+ goto out_enomem_free_avc;
81996+#endif
81997+
81998 anon_vma = find_mergeable_anon_vma(vma);
81999 allocated = NULL;
82000 if (!anon_vma) {
82001@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82002 /* page_table_lock to protect against threads */
82003 spin_lock(&mm->page_table_lock);
82004 if (likely(!vma->anon_vma)) {
82005+
82006+#ifdef CONFIG_PAX_SEGMEXEC
82007+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
82008+
82009+ if (vma_m) {
82010+ BUG_ON(vma_m->anon_vma);
82011+ vma_m->anon_vma = anon_vma;
82012+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
82013+ avc_m = NULL;
82014+ }
82015+#endif
82016+
82017 vma->anon_vma = anon_vma;
82018 anon_vma_chain_link(vma, avc, anon_vma);
82019 allocated = NULL;
82020@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82021
82022 if (unlikely(allocated))
82023 put_anon_vma(allocated);
82024+
82025+#ifdef CONFIG_PAX_SEGMEXEC
82026+ if (unlikely(avc_m))
82027+ anon_vma_chain_free(avc_m);
82028+#endif
82029+
82030 if (unlikely(avc))
82031 anon_vma_chain_free(avc);
82032 }
82033 return 0;
82034
82035 out_enomem_free_avc:
82036+
82037+#ifdef CONFIG_PAX_SEGMEXEC
82038+ if (avc_m)
82039+ anon_vma_chain_free(avc_m);
82040+#endif
82041+
82042 anon_vma_chain_free(avc);
82043 out_enomem:
82044 return -ENOMEM;
82045@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82046 * Attach the anon_vmas from src to dst.
82047 * Returns 0 on success, -ENOMEM on failure.
82048 */
82049-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82050+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82051 {
82052 struct anon_vma_chain *avc, *pavc;
82053 struct anon_vma *root = NULL;
82054@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82055 * the corresponding VMA in the parent process is attached to.
82056 * Returns 0 on success, non-zero on failure.
82057 */
82058-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82059+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82060 {
82061 struct anon_vma_chain *avc;
82062 struct anon_vma *anon_vma;
82063diff --git a/mm/shmem.c b/mm/shmem.c
82064index efd0b3a..994b702 100644
82065--- a/mm/shmem.c
82066+++ b/mm/shmem.c
82067@@ -31,7 +31,7 @@
82068 #include <linux/export.h>
82069 #include <linux/swap.h>
82070
82071-static struct vfsmount *shm_mnt;
82072+struct vfsmount *shm_mnt;
82073
82074 #ifdef CONFIG_SHMEM
82075 /*
82076@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82077 #define BOGO_DIRENT_SIZE 20
82078
82079 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82080-#define SHORT_SYMLINK_LEN 128
82081+#define SHORT_SYMLINK_LEN 64
82082
82083 /*
82084 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82085@@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82086 static int shmem_xattr_validate(const char *name)
82087 {
82088 struct { const char *prefix; size_t len; } arr[] = {
82089+
82090+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82091+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82092+#endif
82093+
82094 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82095 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82096 };
82097@@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82098 if (err)
82099 return err;
82100
82101+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82102+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82103+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82104+ return -EOPNOTSUPP;
82105+ if (size > 8)
82106+ return -EINVAL;
82107+ }
82108+#endif
82109+
82110 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82111 }
82112
82113@@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82114 int err = -ENOMEM;
82115
82116 /* Round up to L1_CACHE_BYTES to resist false sharing */
82117- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82118- L1_CACHE_BYTES), GFP_KERNEL);
82119+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82120 if (!sbinfo)
82121 return -ENOMEM;
82122
82123diff --git a/mm/slab.c b/mm/slab.c
82124index e7667a3..b62c169 100644
82125--- a/mm/slab.c
82126+++ b/mm/slab.c
82127@@ -306,7 +306,7 @@ struct kmem_list3 {
82128 * Need this for bootstrapping a per node allocator.
82129 */
82130 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82131-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82132+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82133 #define CACHE_CACHE 0
82134 #define SIZE_AC MAX_NUMNODES
82135 #define SIZE_L3 (2 * MAX_NUMNODES)
82136@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82137 if ((x)->max_freeable < i) \
82138 (x)->max_freeable = i; \
82139 } while (0)
82140-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82141-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82142-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82143-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82144+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82145+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82146+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82147+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82148 #else
82149 #define STATS_INC_ACTIVE(x) do { } while (0)
82150 #define STATS_DEC_ACTIVE(x) do { } while (0)
82151@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82152 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82153 */
82154 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82155- const struct slab *slab, void *obj)
82156+ const struct slab *slab, const void *obj)
82157 {
82158 u32 offset = (obj - slab->s_mem);
82159 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82160@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82161 struct cache_names {
82162 char *name;
82163 char *name_dma;
82164+ char *name_usercopy;
82165 };
82166
82167 static struct cache_names __initdata cache_names[] = {
82168-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82169+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82170 #include <linux/kmalloc_sizes.h>
82171- {NULL,}
82172+ {NULL}
82173 #undef CACHE
82174 };
82175
82176@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82177 if (unlikely(gfpflags & GFP_DMA))
82178 return csizep->cs_dmacachep;
82179 #endif
82180+
82181+#ifdef CONFIG_PAX_USERCOPY_SLABS
82182+ if (unlikely(gfpflags & GFP_USERCOPY))
82183+ return csizep->cs_usercopycachep;
82184+#endif
82185+
82186 return csizep->cs_cachep;
82187 }
82188
82189@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82190 return notifier_from_errno(err);
82191 }
82192
82193-static struct notifier_block __cpuinitdata cpucache_notifier = {
82194+static struct notifier_block cpucache_notifier = {
82195 &cpuup_callback, NULL, 0
82196 };
82197
82198@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82199 */
82200
82201 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82202- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82203+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82204
82205 if (INDEX_AC != INDEX_L3)
82206 sizes[INDEX_L3].cs_cachep =
82207 create_kmalloc_cache(names[INDEX_L3].name,
82208- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82209+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82210
82211 slab_early_init = 0;
82212
82213@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82214 */
82215 if (!sizes->cs_cachep)
82216 sizes->cs_cachep = create_kmalloc_cache(names->name,
82217- sizes->cs_size, ARCH_KMALLOC_FLAGS);
82218+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82219
82220 #ifdef CONFIG_ZONE_DMA
82221 sizes->cs_dmacachep = create_kmalloc_cache(
82222 names->name_dma, sizes->cs_size,
82223 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82224 #endif
82225+
82226+#ifdef CONFIG_PAX_USERCOPY_SLABS
82227+ sizes->cs_usercopycachep = create_kmalloc_cache(
82228+ names->name_usercopy, sizes->cs_size,
82229+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82230+#endif
82231+
82232 sizes++;
82233 names++;
82234 }
82235@@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
82236 }
82237 /* cpu stats */
82238 {
82239- unsigned long allochit = atomic_read(&cachep->allochit);
82240- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
82241- unsigned long freehit = atomic_read(&cachep->freehit);
82242- unsigned long freemiss = atomic_read(&cachep->freemiss);
82243+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
82244+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
82245+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
82246+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
82247
82248 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
82249 allochit, allocmiss, freehit, freemiss);
82250@@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
82251 static int __init slab_proc_init(void)
82252 {
82253 #ifdef CONFIG_DEBUG_SLAB_LEAK
82254- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
82255+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
82256 #endif
82257 return 0;
82258 }
82259 module_init(slab_proc_init);
82260 #endif
82261
82262+bool is_usercopy_object(const void *ptr)
82263+{
82264+ struct page *page;
82265+ struct kmem_cache *cachep;
82266+
82267+ if (ZERO_OR_NULL_PTR(ptr))
82268+ return false;
82269+
82270+ if (!slab_is_available())
82271+ return false;
82272+
82273+ if (!virt_addr_valid(ptr))
82274+ return false;
82275+
82276+ page = virt_to_head_page(ptr);
82277+
82278+ if (!PageSlab(page))
82279+ return false;
82280+
82281+ cachep = page->slab_cache;
82282+ return cachep->flags & SLAB_USERCOPY;
82283+}
82284+
82285+#ifdef CONFIG_PAX_USERCOPY
82286+const char *check_heap_object(const void *ptr, unsigned long n)
82287+{
82288+ struct page *page;
82289+ struct kmem_cache *cachep;
82290+ struct slab *slabp;
82291+ unsigned int objnr;
82292+ unsigned long offset;
82293+
82294+ if (ZERO_OR_NULL_PTR(ptr))
82295+ return "<null>";
82296+
82297+ if (!virt_addr_valid(ptr))
82298+ return NULL;
82299+
82300+ page = virt_to_head_page(ptr);
82301+
82302+ if (!PageSlab(page))
82303+ return NULL;
82304+
82305+ cachep = page->slab_cache;
82306+ if (!(cachep->flags & SLAB_USERCOPY))
82307+ return cachep->name;
82308+
82309+ slabp = page->slab_page;
82310+ objnr = obj_to_index(cachep, slabp, ptr);
82311+ BUG_ON(objnr >= cachep->num);
82312+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
82313+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
82314+ return NULL;
82315+
82316+ return cachep->name;
82317+}
82318+#endif
82319+
82320 /**
82321 * ksize - get the actual amount of memory allocated for a given object
82322 * @objp: Pointer to the object
82323diff --git a/mm/slab.h b/mm/slab.h
82324index 34a98d6..73633d1 100644
82325--- a/mm/slab.h
82326+++ b/mm/slab.h
82327@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82328
82329 /* Legal flag mask for kmem_cache_create(), for various configurations */
82330 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
82331- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
82332+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
82333
82334 #if defined(CONFIG_DEBUG_SLAB)
82335 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
82336@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
82337 return s;
82338
82339 page = virt_to_head_page(x);
82340+
82341+ BUG_ON(!PageSlab(page));
82342+
82343 cachep = page->slab_cache;
82344 if (slab_equal_or_root(cachep, s))
82345 return cachep;
82346diff --git a/mm/slab_common.c b/mm/slab_common.c
82347index 3f3cd97..93b0236 100644
82348--- a/mm/slab_common.c
82349+++ b/mm/slab_common.c
82350@@ -22,7 +22,7 @@
82351
82352 #include "slab.h"
82353
82354-enum slab_state slab_state;
82355+enum slab_state slab_state __read_only;
82356 LIST_HEAD(slab_caches);
82357 DEFINE_MUTEX(slab_mutex);
82358 struct kmem_cache *kmem_cache;
82359@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
82360
82361 err = __kmem_cache_create(s, flags);
82362 if (!err) {
82363- s->refcount = 1;
82364+ atomic_set(&s->refcount, 1);
82365 list_add(&s->list, &slab_caches);
82366 memcg_cache_list_add(memcg, s);
82367 } else {
82368@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
82369
82370 get_online_cpus();
82371 mutex_lock(&slab_mutex);
82372- s->refcount--;
82373- if (!s->refcount) {
82374+ if (atomic_dec_and_test(&s->refcount)) {
82375 list_del(&s->list);
82376
82377 if (!__kmem_cache_shutdown(s)) {
82378@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
82379 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
82380 name, size, err);
82381
82382- s->refcount = -1; /* Exempt from merging for now */
82383+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
82384 }
82385
82386 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82387@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82388
82389 create_boot_cache(s, name, size, flags);
82390 list_add(&s->list, &slab_caches);
82391- s->refcount = 1;
82392+ atomic_set(&s->refcount, 1);
82393 return s;
82394 }
82395
82396diff --git a/mm/slob.c b/mm/slob.c
82397index a99fdf7..f5b6577 100644
82398--- a/mm/slob.c
82399+++ b/mm/slob.c
82400@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
82401 /*
82402 * Return the size of a slob block.
82403 */
82404-static slobidx_t slob_units(slob_t *s)
82405+static slobidx_t slob_units(const slob_t *s)
82406 {
82407 if (s->units > 0)
82408 return s->units;
82409@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
82410 /*
82411 * Return the next free slob block pointer after this one.
82412 */
82413-static slob_t *slob_next(slob_t *s)
82414+static slob_t *slob_next(const slob_t *s)
82415 {
82416 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
82417 slobidx_t next;
82418@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
82419 /*
82420 * Returns true if s is the last free block in its page.
82421 */
82422-static int slob_last(slob_t *s)
82423+static int slob_last(const slob_t *s)
82424 {
82425 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
82426 }
82427
82428-static void *slob_new_pages(gfp_t gfp, int order, int node)
82429+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
82430 {
82431- void *page;
82432+ struct page *page;
82433
82434 #ifdef CONFIG_NUMA
82435 if (node != NUMA_NO_NODE)
82436@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
82437 if (!page)
82438 return NULL;
82439
82440- return page_address(page);
82441+ __SetPageSlab(page);
82442+ return page;
82443 }
82444
82445-static void slob_free_pages(void *b, int order)
82446+static void slob_free_pages(struct page *sp, int order)
82447 {
82448 if (current->reclaim_state)
82449 current->reclaim_state->reclaimed_slab += 1 << order;
82450- free_pages((unsigned long)b, order);
82451+ __ClearPageSlab(sp);
82452+ reset_page_mapcount(sp);
82453+ sp->private = 0;
82454+ __free_pages(sp, order);
82455 }
82456
82457 /*
82458@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
82459
82460 /* Not enough space: must allocate a new page */
82461 if (!b) {
82462- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82463- if (!b)
82464+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82465+ if (!sp)
82466 return NULL;
82467- sp = virt_to_page(b);
82468- __SetPageSlab(sp);
82469+ b = page_address(sp);
82470
82471 spin_lock_irqsave(&slob_lock, flags);
82472 sp->units = SLOB_UNITS(PAGE_SIZE);
82473 sp->freelist = b;
82474+ sp->private = 0;
82475 INIT_LIST_HEAD(&sp->list);
82476 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
82477 set_slob_page_free(sp, slob_list);
82478@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
82479 if (slob_page_free(sp))
82480 clear_slob_page_free(sp);
82481 spin_unlock_irqrestore(&slob_lock, flags);
82482- __ClearPageSlab(sp);
82483- reset_page_mapcount(sp);
82484- slob_free_pages(b, 0);
82485+ slob_free_pages(sp, 0);
82486 return;
82487 }
82488
82489@@ -424,11 +426,10 @@ out:
82490 */
82491
82492 static __always_inline void *
82493-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82494+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
82495 {
82496- unsigned int *m;
82497- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82498- void *ret;
82499+ slob_t *m;
82500+ void *ret = NULL;
82501
82502 gfp &= gfp_allowed_mask;
82503
82504@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82505
82506 if (!m)
82507 return NULL;
82508- *m = size;
82509+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
82510+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
82511+ m[0].units = size;
82512+ m[1].units = align;
82513 ret = (void *)m + align;
82514
82515 trace_kmalloc_node(caller, ret,
82516 size, size + align, gfp, node);
82517 } else {
82518 unsigned int order = get_order(size);
82519+ struct page *page;
82520
82521 if (likely(order))
82522 gfp |= __GFP_COMP;
82523- ret = slob_new_pages(gfp, order, node);
82524+ page = slob_new_pages(gfp, order, node);
82525+ if (page) {
82526+ ret = page_address(page);
82527+ page->private = size;
82528+ }
82529
82530 trace_kmalloc_node(caller, ret,
82531 size, PAGE_SIZE << order, gfp, node);
82532 }
82533
82534- kmemleak_alloc(ret, size, 1, gfp);
82535+ return ret;
82536+}
82537+
82538+static __always_inline void *
82539+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82540+{
82541+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82542+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
82543+
82544+ if (!ZERO_OR_NULL_PTR(ret))
82545+ kmemleak_alloc(ret, size, 1, gfp);
82546 return ret;
82547 }
82548
82549@@ -494,33 +513,110 @@ void kfree(const void *block)
82550 kmemleak_free(block);
82551
82552 sp = virt_to_page(block);
82553- if (PageSlab(sp)) {
82554+ VM_BUG_ON(!PageSlab(sp));
82555+ if (!sp->private) {
82556 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82557- unsigned int *m = (unsigned int *)(block - align);
82558- slob_free(m, *m + align);
82559- } else
82560+ slob_t *m = (slob_t *)(block - align);
82561+ slob_free(m, m[0].units + align);
82562+ } else {
82563+ __ClearPageSlab(sp);
82564+ reset_page_mapcount(sp);
82565+ sp->private = 0;
82566 __free_pages(sp, compound_order(sp));
82567+ }
82568 }
82569 EXPORT_SYMBOL(kfree);
82570
82571+bool is_usercopy_object(const void *ptr)
82572+{
82573+ if (!slab_is_available())
82574+ return false;
82575+
82576+ // PAX: TODO
82577+
82578+ return false;
82579+}
82580+
82581+#ifdef CONFIG_PAX_USERCOPY
82582+const char *check_heap_object(const void *ptr, unsigned long n)
82583+{
82584+ struct page *page;
82585+ const slob_t *free;
82586+ const void *base;
82587+ unsigned long flags;
82588+
82589+ if (ZERO_OR_NULL_PTR(ptr))
82590+ return "<null>";
82591+
82592+ if (!virt_addr_valid(ptr))
82593+ return NULL;
82594+
82595+ page = virt_to_head_page(ptr);
82596+ if (!PageSlab(page))
82597+ return NULL;
82598+
82599+ if (page->private) {
82600+ base = page;
82601+ if (base <= ptr && n <= page->private - (ptr - base))
82602+ return NULL;
82603+ return "<slob>";
82604+ }
82605+
82606+ /* some tricky double walking to find the chunk */
82607+ spin_lock_irqsave(&slob_lock, flags);
82608+ base = (void *)((unsigned long)ptr & PAGE_MASK);
82609+ free = page->freelist;
82610+
82611+ while (!slob_last(free) && (void *)free <= ptr) {
82612+ base = free + slob_units(free);
82613+ free = slob_next(free);
82614+ }
82615+
82616+ while (base < (void *)free) {
82617+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
82618+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
82619+ int offset;
82620+
82621+ if (ptr < base + align)
82622+ break;
82623+
82624+ offset = ptr - base - align;
82625+ if (offset >= m) {
82626+ base += size;
82627+ continue;
82628+ }
82629+
82630+ if (n > m - offset)
82631+ break;
82632+
82633+ spin_unlock_irqrestore(&slob_lock, flags);
82634+ return NULL;
82635+ }
82636+
82637+ spin_unlock_irqrestore(&slob_lock, flags);
82638+ return "<slob>";
82639+}
82640+#endif
82641+
82642 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
82643 size_t ksize(const void *block)
82644 {
82645 struct page *sp;
82646 int align;
82647- unsigned int *m;
82648+ slob_t *m;
82649
82650 BUG_ON(!block);
82651 if (unlikely(block == ZERO_SIZE_PTR))
82652 return 0;
82653
82654 sp = virt_to_page(block);
82655- if (unlikely(!PageSlab(sp)))
82656- return PAGE_SIZE << compound_order(sp);
82657+ VM_BUG_ON(!PageSlab(sp));
82658+ if (sp->private)
82659+ return sp->private;
82660
82661 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82662- m = (unsigned int *)(block - align);
82663- return SLOB_UNITS(*m) * SLOB_UNIT;
82664+ m = (slob_t *)(block - align);
82665+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
82666 }
82667 EXPORT_SYMBOL(ksize);
82668
82669@@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
82670
82671 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
82672 {
82673- void *b;
82674+ void *b = NULL;
82675
82676 flags &= gfp_allowed_mask;
82677
82678 lockdep_trace_alloc(flags);
82679
82680+#ifdef CONFIG_PAX_USERCOPY_SLABS
82681+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
82682+#else
82683 if (c->size < PAGE_SIZE) {
82684 b = slob_alloc(c->size, flags, c->align, node);
82685 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82686 SLOB_UNITS(c->size) * SLOB_UNIT,
82687 flags, node);
82688 } else {
82689- b = slob_new_pages(flags, get_order(c->size), node);
82690+ struct page *sp;
82691+
82692+ sp = slob_new_pages(flags, get_order(c->size), node);
82693+ if (sp) {
82694+ b = page_address(sp);
82695+ sp->private = c->size;
82696+ }
82697 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82698 PAGE_SIZE << get_order(c->size),
82699 flags, node);
82700 }
82701+#endif
82702
82703 if (c->ctor)
82704 c->ctor(b);
82705@@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
82706
82707 static void __kmem_cache_free(void *b, int size)
82708 {
82709- if (size < PAGE_SIZE)
82710+ struct page *sp;
82711+
82712+ sp = virt_to_page(b);
82713+ BUG_ON(!PageSlab(sp));
82714+ if (!sp->private)
82715 slob_free(b, size);
82716 else
82717- slob_free_pages(b, get_order(size));
82718+ slob_free_pages(sp, get_order(size));
82719 }
82720
82721 static void kmem_rcu_free(struct rcu_head *head)
82722@@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
82723
82724 void kmem_cache_free(struct kmem_cache *c, void *b)
82725 {
82726+ int size = c->size;
82727+
82728+#ifdef CONFIG_PAX_USERCOPY_SLABS
82729+ if (size + c->align < PAGE_SIZE) {
82730+ size += c->align;
82731+ b -= c->align;
82732+ }
82733+#endif
82734+
82735 kmemleak_free_recursive(b, c->flags);
82736 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
82737 struct slob_rcu *slob_rcu;
82738- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
82739- slob_rcu->size = c->size;
82740+ slob_rcu = b + (size - sizeof(struct slob_rcu));
82741+ slob_rcu->size = size;
82742 call_rcu(&slob_rcu->head, kmem_rcu_free);
82743 } else {
82744- __kmem_cache_free(b, c->size);
82745+ __kmem_cache_free(b, size);
82746 }
82747
82748+#ifdef CONFIG_PAX_USERCOPY_SLABS
82749+ trace_kfree(_RET_IP_, b);
82750+#else
82751 trace_kmem_cache_free(_RET_IP_, b);
82752+#endif
82753+
82754 }
82755 EXPORT_SYMBOL(kmem_cache_free);
82756
82757diff --git a/mm/slub.c b/mm/slub.c
82758index ba2ca53..00b1f4e 100644
82759--- a/mm/slub.c
82760+++ b/mm/slub.c
82761@@ -197,7 +197,7 @@ struct track {
82762
82763 enum track_item { TRACK_ALLOC, TRACK_FREE };
82764
82765-#ifdef CONFIG_SYSFS
82766+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82767 static int sysfs_slab_add(struct kmem_cache *);
82768 static int sysfs_slab_alias(struct kmem_cache *, const char *);
82769 static void sysfs_slab_remove(struct kmem_cache *);
82770@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
82771 if (!t->addr)
82772 return;
82773
82774- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
82775+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
82776 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
82777 #ifdef CONFIG_STACKTRACE
82778 {
82779@@ -2653,7 +2653,7 @@ static int slub_min_objects;
82780 * Merge control. If this is set then no merging of slab caches will occur.
82781 * (Could be removed. This was introduced to pacify the merge skeptics.)
82782 */
82783-static int slub_nomerge;
82784+static int slub_nomerge = 1;
82785
82786 /*
82787 * Calculate the order of allocation given an slab object size.
82788@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
82789 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
82790 #endif
82791
82792+#ifdef CONFIG_PAX_USERCOPY_SLABS
82793+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
82794+#endif
82795+
82796 static int __init setup_slub_min_order(char *str)
82797 {
82798 get_option(&str, &slub_min_order);
82799@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
82800 return kmalloc_dma_caches[index];
82801
82802 #endif
82803+
82804+#ifdef CONFIG_PAX_USERCOPY_SLABS
82805+ if (flags & SLAB_USERCOPY)
82806+ return kmalloc_usercopy_caches[index];
82807+
82808+#endif
82809+
82810 return kmalloc_caches[index];
82811 }
82812
82813@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
82814 EXPORT_SYMBOL(__kmalloc_node);
82815 #endif
82816
82817+bool is_usercopy_object(const void *ptr)
82818+{
82819+ struct page *page;
82820+ struct kmem_cache *s;
82821+
82822+ if (ZERO_OR_NULL_PTR(ptr))
82823+ return false;
82824+
82825+ if (!slab_is_available())
82826+ return false;
82827+
82828+ if (!virt_addr_valid(ptr))
82829+ return false;
82830+
82831+ page = virt_to_head_page(ptr);
82832+
82833+ if (!PageSlab(page))
82834+ return false;
82835+
82836+ s = page->slab_cache;
82837+ return s->flags & SLAB_USERCOPY;
82838+}
82839+
82840+#ifdef CONFIG_PAX_USERCOPY
82841+const char *check_heap_object(const void *ptr, unsigned long n)
82842+{
82843+ struct page *page;
82844+ struct kmem_cache *s;
82845+ unsigned long offset;
82846+
82847+ if (ZERO_OR_NULL_PTR(ptr))
82848+ return "<null>";
82849+
82850+ if (!virt_addr_valid(ptr))
82851+ return NULL;
82852+
82853+ page = virt_to_head_page(ptr);
82854+
82855+ if (!PageSlab(page))
82856+ return NULL;
82857+
82858+ s = page->slab_cache;
82859+ if (!(s->flags & SLAB_USERCOPY))
82860+ return s->name;
82861+
82862+ offset = (ptr - page_address(page)) % s->size;
82863+ if (offset <= s->object_size && n <= s->object_size - offset)
82864+ return NULL;
82865+
82866+ return s->name;
82867+}
82868+#endif
82869+
82870 size_t ksize(const void *object)
82871 {
82872 struct page *page;
82873@@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
82874
82875 /* Caches that are not of the two-to-the-power-of size */
82876 if (KMALLOC_MIN_SIZE <= 32) {
82877- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
82878+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
82879 caches++;
82880 }
82881
82882 if (KMALLOC_MIN_SIZE <= 64) {
82883- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
82884+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
82885 caches++;
82886 }
82887
82888 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
82889- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
82890+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
82891 caches++;
82892 }
82893
82894@@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
82895 }
82896 }
82897 #endif
82898+
82899+#ifdef CONFIG_PAX_USERCOPY_SLABS
82900+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
82901+ struct kmem_cache *s = kmalloc_caches[i];
82902+
82903+ if (s && s->size) {
82904+ char *name = kasprintf(GFP_NOWAIT,
82905+ "usercopy-kmalloc-%d", s->object_size);
82906+
82907+ BUG_ON(!name);
82908+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
82909+ s->object_size, SLAB_USERCOPY);
82910+ }
82911+ }
82912+#endif
82913+
82914 printk(KERN_INFO
82915 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
82916 " CPUs=%d, Nodes=%d\n",
82917@@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
82918 /*
82919 * We may have set a slab to be unmergeable during bootstrap.
82920 */
82921- if (s->refcount < 0)
82922+ if (atomic_read(&s->refcount) < 0)
82923 return 1;
82924
82925 return 0;
82926@@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82927
82928 s = find_mergeable(memcg, size, align, flags, name, ctor);
82929 if (s) {
82930- s->refcount++;
82931+ atomic_inc(&s->refcount);
82932 /*
82933 * Adjust the object sizes so that we clear
82934 * the complete object on kzalloc.
82935@@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82936 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
82937
82938 if (sysfs_slab_alias(s, name)) {
82939- s->refcount--;
82940+ atomic_dec(&s->refcount);
82941 s = NULL;
82942 }
82943 }
82944@@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
82945 return NOTIFY_OK;
82946 }
82947
82948-static struct notifier_block __cpuinitdata slab_notifier = {
82949+static struct notifier_block slab_notifier = {
82950 .notifier_call = slab_cpuup_callback
82951 };
82952
82953@@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
82954 }
82955 #endif
82956
82957-#ifdef CONFIG_SYSFS
82958+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82959 static int count_inuse(struct page *page)
82960 {
82961 return page->inuse;
82962@@ -4364,12 +4444,12 @@ static void resiliency_test(void)
82963 validate_slab_cache(kmalloc_caches[9]);
82964 }
82965 #else
82966-#ifdef CONFIG_SYSFS
82967+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82968 static void resiliency_test(void) {};
82969 #endif
82970 #endif
82971
82972-#ifdef CONFIG_SYSFS
82973+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82974 enum slab_stat_type {
82975 SL_ALL, /* All slabs */
82976 SL_PARTIAL, /* Only partially allocated slabs */
82977@@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
82978
82979 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
82980 {
82981- return sprintf(buf, "%d\n", s->refcount - 1);
82982+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
82983 }
82984 SLAB_ATTR_RO(aliases);
82985
82986@@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
82987 return name;
82988 }
82989
82990+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82991 static int sysfs_slab_add(struct kmem_cache *s)
82992 {
82993 int err;
82994@@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
82995 kobject_del(&s->kobj);
82996 kobject_put(&s->kobj);
82997 }
82998+#endif
82999
83000 /*
83001 * Need to buffer aliases during bootup until sysfs becomes
83002@@ -5336,6 +5418,7 @@ struct saved_alias {
83003
83004 static struct saved_alias *alias_list;
83005
83006+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
83007 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83008 {
83009 struct saved_alias *al;
83010@@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83011 alias_list = al;
83012 return 0;
83013 }
83014+#endif
83015
83016 static int __init slab_sysfs_init(void)
83017 {
83018diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83019index 1b7e22a..3fcd4f3 100644
83020--- a/mm/sparse-vmemmap.c
83021+++ b/mm/sparse-vmemmap.c
83022@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83023 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83024 if (!p)
83025 return NULL;
83026- pud_populate(&init_mm, pud, p);
83027+ pud_populate_kernel(&init_mm, pud, p);
83028 }
83029 return pud;
83030 }
83031@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83032 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83033 if (!p)
83034 return NULL;
83035- pgd_populate(&init_mm, pgd, p);
83036+ pgd_populate_kernel(&init_mm, pgd, p);
83037 }
83038 return pgd;
83039 }
83040diff --git a/mm/sparse.c b/mm/sparse.c
83041index 6b5fb76..db0c190 100644
83042--- a/mm/sparse.c
83043+++ b/mm/sparse.c
83044@@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83045
83046 for (i = 0; i < PAGES_PER_SECTION; i++) {
83047 if (PageHWPoison(&memmap[i])) {
83048- atomic_long_sub(1, &mce_bad_pages);
83049+ atomic_long_sub_unchecked(1, &mce_bad_pages);
83050 ClearPageHWPoison(&memmap[i]);
83051 }
83052 }
83053diff --git a/mm/swap.c b/mm/swap.c
83054index 6310dc2..3662b3f 100644
83055--- a/mm/swap.c
83056+++ b/mm/swap.c
83057@@ -30,6 +30,7 @@
83058 #include <linux/backing-dev.h>
83059 #include <linux/memcontrol.h>
83060 #include <linux/gfp.h>
83061+#include <linux/hugetlb.h>
83062
83063 #include "internal.h"
83064
83065@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83066
83067 __page_cache_release(page);
83068 dtor = get_compound_page_dtor(page);
83069+ if (!PageHuge(page))
83070+ BUG_ON(dtor != free_compound_page);
83071 (*dtor)(page);
83072 }
83073
83074diff --git a/mm/swapfile.c b/mm/swapfile.c
83075index e97a0e5..b50e796 100644
83076--- a/mm/swapfile.c
83077+++ b/mm/swapfile.c
83078@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83079
83080 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83081 /* Activity counter to indicate that a swapon or swapoff has occurred */
83082-static atomic_t proc_poll_event = ATOMIC_INIT(0);
83083+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83084
83085 static inline unsigned char swap_count(unsigned char ent)
83086 {
83087@@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83088 }
83089 filp_close(swap_file, NULL);
83090 err = 0;
83091- atomic_inc(&proc_poll_event);
83092+ atomic_inc_unchecked(&proc_poll_event);
83093 wake_up_interruptible(&proc_poll_wait);
83094
83095 out_dput:
83096@@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83097
83098 poll_wait(file, &proc_poll_wait, wait);
83099
83100- if (seq->poll_event != atomic_read(&proc_poll_event)) {
83101- seq->poll_event = atomic_read(&proc_poll_event);
83102+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83103+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83104 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83105 }
83106
83107@@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83108 return ret;
83109
83110 seq = file->private_data;
83111- seq->poll_event = atomic_read(&proc_poll_event);
83112+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83113 return 0;
83114 }
83115
83116@@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83117 (frontswap_map) ? "FS" : "");
83118
83119 mutex_unlock(&swapon_mutex);
83120- atomic_inc(&proc_poll_event);
83121+ atomic_inc_unchecked(&proc_poll_event);
83122 wake_up_interruptible(&proc_poll_wait);
83123
83124 if (S_ISREG(inode->i_mode))
83125diff --git a/mm/util.c b/mm/util.c
83126index c55e26b..3f913a9 100644
83127--- a/mm/util.c
83128+++ b/mm/util.c
83129@@ -292,6 +292,12 @@ done:
83130 void arch_pick_mmap_layout(struct mm_struct *mm)
83131 {
83132 mm->mmap_base = TASK_UNMAPPED_BASE;
83133+
83134+#ifdef CONFIG_PAX_RANDMMAP
83135+ if (mm->pax_flags & MF_PAX_RANDMMAP)
83136+ mm->mmap_base += mm->delta_mmap;
83137+#endif
83138+
83139 mm->get_unmapped_area = arch_get_unmapped_area;
83140 mm->unmap_area = arch_unmap_area;
83141 }
83142diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83143index 5123a16..f234a48 100644
83144--- a/mm/vmalloc.c
83145+++ b/mm/vmalloc.c
83146@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83147
83148 pte = pte_offset_kernel(pmd, addr);
83149 do {
83150- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83151- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83152+
83153+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83154+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83155+ BUG_ON(!pte_exec(*pte));
83156+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83157+ continue;
83158+ }
83159+#endif
83160+
83161+ {
83162+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83163+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83164+ }
83165 } while (pte++, addr += PAGE_SIZE, addr != end);
83166 }
83167
83168@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83169 pte = pte_alloc_kernel(pmd, addr);
83170 if (!pte)
83171 return -ENOMEM;
83172+
83173+ pax_open_kernel();
83174 do {
83175 struct page *page = pages[*nr];
83176
83177- if (WARN_ON(!pte_none(*pte)))
83178+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83179+ if (pgprot_val(prot) & _PAGE_NX)
83180+#endif
83181+
83182+ if (!pte_none(*pte)) {
83183+ pax_close_kernel();
83184+ WARN_ON(1);
83185 return -EBUSY;
83186- if (WARN_ON(!page))
83187+ }
83188+ if (!page) {
83189+ pax_close_kernel();
83190+ WARN_ON(1);
83191 return -ENOMEM;
83192+ }
83193 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83194 (*nr)++;
83195 } while (pte++, addr += PAGE_SIZE, addr != end);
83196+ pax_close_kernel();
83197 return 0;
83198 }
83199
83200@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83201 pmd_t *pmd;
83202 unsigned long next;
83203
83204- pmd = pmd_alloc(&init_mm, pud, addr);
83205+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83206 if (!pmd)
83207 return -ENOMEM;
83208 do {
83209@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83210 pud_t *pud;
83211 unsigned long next;
83212
83213- pud = pud_alloc(&init_mm, pgd, addr);
83214+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
83215 if (!pud)
83216 return -ENOMEM;
83217 do {
83218@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83219 * and fall back on vmalloc() if that fails. Others
83220 * just put it in the vmalloc space.
83221 */
83222-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83223+#ifdef CONFIG_MODULES
83224+#ifdef MODULES_VADDR
83225 unsigned long addr = (unsigned long)x;
83226 if (addr >= MODULES_VADDR && addr < MODULES_END)
83227 return 1;
83228 #endif
83229+
83230+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83231+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
83232+ return 1;
83233+#endif
83234+
83235+#endif
83236+
83237 return is_vmalloc_addr(x);
83238 }
83239
83240@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
83241
83242 if (!pgd_none(*pgd)) {
83243 pud_t *pud = pud_offset(pgd, addr);
83244+#ifdef CONFIG_X86
83245+ if (!pud_large(*pud))
83246+#endif
83247 if (!pud_none(*pud)) {
83248 pmd_t *pmd = pmd_offset(pud, addr);
83249+#ifdef CONFIG_X86
83250+ if (!pmd_large(*pmd))
83251+#endif
83252 if (!pmd_none(*pmd)) {
83253 pte_t *ptep, pte;
83254
83255@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
83256 * Allocate a region of KVA of the specified size and alignment, within the
83257 * vstart and vend.
83258 */
83259-static struct vmap_area *alloc_vmap_area(unsigned long size,
83260+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
83261 unsigned long align,
83262 unsigned long vstart, unsigned long vend,
83263 int node, gfp_t gfp_mask)
83264@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
83265 struct vm_struct *area;
83266
83267 BUG_ON(in_interrupt());
83268+
83269+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83270+ if (flags & VM_KERNEXEC) {
83271+ if (start != VMALLOC_START || end != VMALLOC_END)
83272+ return NULL;
83273+ start = (unsigned long)MODULES_EXEC_VADDR;
83274+ end = (unsigned long)MODULES_EXEC_END;
83275+ }
83276+#endif
83277+
83278 if (flags & VM_IOREMAP) {
83279 int bit = fls(size);
83280
83281@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
83282 if (count > totalram_pages)
83283 return NULL;
83284
83285+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83286+ if (!(pgprot_val(prot) & _PAGE_NX))
83287+ flags |= VM_KERNEXEC;
83288+#endif
83289+
83290 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
83291 __builtin_return_address(0));
83292 if (!area)
83293@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
83294 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
83295 goto fail;
83296
83297+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83298+ if (!(pgprot_val(prot) & _PAGE_NX))
83299+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
83300+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
83301+ else
83302+#endif
83303+
83304 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
83305 start, end, node, gfp_mask, caller);
83306 if (!area)
83307@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
83308 * For tight control over page level allocator and protection flags
83309 * use __vmalloc() instead.
83310 */
83311-
83312 void *vmalloc_exec(unsigned long size)
83313 {
83314- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
83315+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
83316 -1, __builtin_return_address(0));
83317 }
83318
83319@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
83320 unsigned long uaddr = vma->vm_start;
83321 unsigned long usize = vma->vm_end - vma->vm_start;
83322
83323+ BUG_ON(vma->vm_mirror);
83324+
83325 if ((PAGE_SIZE-1) & (unsigned long)addr)
83326 return -EINVAL;
83327
83328@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
83329 v->addr, v->addr + v->size, v->size);
83330
83331 if (v->caller)
83332+#ifdef CONFIG_GRKERNSEC_HIDESYM
83333+ seq_printf(m, " %pK", v->caller);
83334+#else
83335 seq_printf(m, " %pS", v->caller);
83336+#endif
83337
83338 if (v->nr_pages)
83339 seq_printf(m, " pages=%d", v->nr_pages);
83340diff --git a/mm/vmstat.c b/mm/vmstat.c
83341index 9800306..76b4b27 100644
83342--- a/mm/vmstat.c
83343+++ b/mm/vmstat.c
83344@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
83345 *
83346 * vm_stat contains the global counters
83347 */
83348-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83349+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83350 EXPORT_SYMBOL(vm_stat);
83351
83352 #ifdef CONFIG_SMP
83353@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
83354 v = p->vm_stat_diff[i];
83355 p->vm_stat_diff[i] = 0;
83356 local_irq_restore(flags);
83357- atomic_long_add(v, &zone->vm_stat[i]);
83358+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83359 global_diff[i] += v;
83360 #ifdef CONFIG_NUMA
83361 /* 3 seconds idle till flush */
83362@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
83363
83364 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
83365 if (global_diff[i])
83366- atomic_long_add(global_diff[i], &vm_stat[i]);
83367+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
83368 }
83369
83370 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83371@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83372 if (pset->vm_stat_diff[i]) {
83373 int v = pset->vm_stat_diff[i];
83374 pset->vm_stat_diff[i] = 0;
83375- atomic_long_add(v, &zone->vm_stat[i]);
83376- atomic_long_add(v, &vm_stat[i]);
83377+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83378+ atomic_long_add_unchecked(v, &vm_stat[i]);
83379 }
83380 }
83381 #endif
83382@@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
83383 return NOTIFY_OK;
83384 }
83385
83386-static struct notifier_block __cpuinitdata vmstat_notifier =
83387+static struct notifier_block vmstat_notifier =
83388 { &vmstat_cpuup_callback, NULL, 0 };
83389 #endif
83390
83391@@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
83392 start_cpu_timer(cpu);
83393 #endif
83394 #ifdef CONFIG_PROC_FS
83395- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
83396- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
83397- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
83398- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
83399+ {
83400+ mode_t gr_mode = S_IRUGO;
83401+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83402+ gr_mode = S_IRUSR;
83403+#endif
83404+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
83405+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
83406+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83407+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
83408+#else
83409+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
83410+#endif
83411+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
83412+ }
83413 #endif
83414 return 0;
83415 }
83416diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
83417index a292e80..785ee68 100644
83418--- a/net/8021q/vlan.c
83419+++ b/net/8021q/vlan.c
83420@@ -485,7 +485,7 @@ out:
83421 return NOTIFY_DONE;
83422 }
83423
83424-static struct notifier_block vlan_notifier_block __read_mostly = {
83425+static struct notifier_block vlan_notifier_block = {
83426 .notifier_call = vlan_device_event,
83427 };
83428
83429@@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
83430 err = -EPERM;
83431 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
83432 break;
83433- if ((args.u.name_type >= 0) &&
83434- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
83435+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
83436 struct vlan_net *vn;
83437
83438 vn = net_generic(net, vlan_net_id);
83439diff --git a/net/9p/mod.c b/net/9p/mod.c
83440index 6ab36ae..6f1841b 100644
83441--- a/net/9p/mod.c
83442+++ b/net/9p/mod.c
83443@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
83444 void v9fs_register_trans(struct p9_trans_module *m)
83445 {
83446 spin_lock(&v9fs_trans_lock);
83447- list_add_tail(&m->list, &v9fs_trans_list);
83448+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
83449 spin_unlock(&v9fs_trans_lock);
83450 }
83451 EXPORT_SYMBOL(v9fs_register_trans);
83452@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
83453 void v9fs_unregister_trans(struct p9_trans_module *m)
83454 {
83455 spin_lock(&v9fs_trans_lock);
83456- list_del_init(&m->list);
83457+ pax_list_del_init((struct list_head *)&m->list);
83458 spin_unlock(&v9fs_trans_lock);
83459 }
83460 EXPORT_SYMBOL(v9fs_unregister_trans);
83461diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
83462index 02efb25..41541a9 100644
83463--- a/net/9p/trans_fd.c
83464+++ b/net/9p/trans_fd.c
83465@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
83466 oldfs = get_fs();
83467 set_fs(get_ds());
83468 /* The cast to a user pointer is valid due to the set_fs() */
83469- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
83470+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
83471 set_fs(oldfs);
83472
83473 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
83474diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
83475index 876fbe8..8bbea9f 100644
83476--- a/net/atm/atm_misc.c
83477+++ b/net/atm/atm_misc.c
83478@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
83479 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
83480 return 1;
83481 atm_return(vcc, truesize);
83482- atomic_inc(&vcc->stats->rx_drop);
83483+ atomic_inc_unchecked(&vcc->stats->rx_drop);
83484 return 0;
83485 }
83486 EXPORT_SYMBOL(atm_charge);
83487@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
83488 }
83489 }
83490 atm_return(vcc, guess);
83491- atomic_inc(&vcc->stats->rx_drop);
83492+ atomic_inc_unchecked(&vcc->stats->rx_drop);
83493 return NULL;
83494 }
83495 EXPORT_SYMBOL(atm_alloc_charge);
83496@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
83497
83498 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83499 {
83500-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83501+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83502 __SONET_ITEMS
83503 #undef __HANDLE_ITEM
83504 }
83505@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
83506
83507 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83508 {
83509-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83510+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
83511 __SONET_ITEMS
83512 #undef __HANDLE_ITEM
83513 }
83514diff --git a/net/atm/lec.h b/net/atm/lec.h
83515index a86aff9..3a0d6f6 100644
83516--- a/net/atm/lec.h
83517+++ b/net/atm/lec.h
83518@@ -48,7 +48,7 @@ struct lane2_ops {
83519 const u8 *tlvs, u32 sizeoftlvs);
83520 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
83521 const u8 *tlvs, u32 sizeoftlvs);
83522-};
83523+} __no_const;
83524
83525 /*
83526 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
83527diff --git a/net/atm/proc.c b/net/atm/proc.c
83528index 0d020de..011c7bb 100644
83529--- a/net/atm/proc.c
83530+++ b/net/atm/proc.c
83531@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
83532 const struct k_atm_aal_stats *stats)
83533 {
83534 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
83535- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
83536- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
83537- atomic_read(&stats->rx_drop));
83538+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
83539+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
83540+ atomic_read_unchecked(&stats->rx_drop));
83541 }
83542
83543 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
83544diff --git a/net/atm/resources.c b/net/atm/resources.c
83545index 0447d5d..3cf4728 100644
83546--- a/net/atm/resources.c
83547+++ b/net/atm/resources.c
83548@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
83549 static void copy_aal_stats(struct k_atm_aal_stats *from,
83550 struct atm_aal_stats *to)
83551 {
83552-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83553+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83554 __AAL_STAT_ITEMS
83555 #undef __HANDLE_ITEM
83556 }
83557@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
83558 static void subtract_aal_stats(struct k_atm_aal_stats *from,
83559 struct atm_aal_stats *to)
83560 {
83561-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83562+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
83563 __AAL_STAT_ITEMS
83564 #undef __HANDLE_ITEM
83565 }
83566diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
83567index d5744b7..506bae3 100644
83568--- a/net/ax25/sysctl_net_ax25.c
83569+++ b/net/ax25/sysctl_net_ax25.c
83570@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
83571 {
83572 char path[sizeof("net/ax25/") + IFNAMSIZ];
83573 int k;
83574- struct ctl_table *table;
83575+ ctl_table_no_const *table;
83576
83577 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
83578 if (!table)
83579diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
83580index 7d02ebd..4d4cc01 100644
83581--- a/net/batman-adv/bat_iv_ogm.c
83582+++ b/net/batman-adv/bat_iv_ogm.c
83583@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
83584
83585 /* randomize initial seqno to avoid collision */
83586 get_random_bytes(&random_seqno, sizeof(random_seqno));
83587- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83588+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83589
83590 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
83591 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
83592@@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
83593 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
83594
83595 /* change sequence number to network order */
83596- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
83597+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
83598 batadv_ogm_packet->seqno = htonl(seqno);
83599- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
83600+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
83601
83602 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
83603 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
83604@@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
83605 return;
83606
83607 /* could be changed by schedule_own_packet() */
83608- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
83609+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
83610
83611 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
83612 has_directlink_flag = 1;
83613diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
83614index f1d37cd..4190879 100644
83615--- a/net/batman-adv/hard-interface.c
83616+++ b/net/batman-adv/hard-interface.c
83617@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
83618 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
83619 dev_add_pack(&hard_iface->batman_adv_ptype);
83620
83621- atomic_set(&hard_iface->frag_seqno, 1);
83622+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
83623 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
83624 hard_iface->net_dev->name);
83625
83626@@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
83627 /* This can't be called via a bat_priv callback because
83628 * we have no bat_priv yet.
83629 */
83630- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
83631+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
83632 hard_iface->bat_iv.ogm_buff = NULL;
83633
83634 return hard_iface;
83635diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
83636index 6b548fd..fc32c8d 100644
83637--- a/net/batman-adv/soft-interface.c
83638+++ b/net/batman-adv/soft-interface.c
83639@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
83640 primary_if->net_dev->dev_addr, ETH_ALEN);
83641
83642 /* set broadcast sequence number */
83643- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
83644+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
83645 bcast_packet->seqno = htonl(seqno);
83646
83647 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
83648@@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
83649 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
83650
83651 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
83652- atomic_set(&bat_priv->bcast_seqno, 1);
83653+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
83654 atomic_set(&bat_priv->tt.vn, 0);
83655 atomic_set(&bat_priv->tt.local_changes, 0);
83656 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
83657diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
83658index ae9ac9a..11e0fe7 100644
83659--- a/net/batman-adv/types.h
83660+++ b/net/batman-adv/types.h
83661@@ -48,7 +48,7 @@
83662 struct batadv_hard_iface_bat_iv {
83663 unsigned char *ogm_buff;
83664 int ogm_buff_len;
83665- atomic_t ogm_seqno;
83666+ atomic_unchecked_t ogm_seqno;
83667 };
83668
83669 struct batadv_hard_iface {
83670@@ -56,7 +56,7 @@ struct batadv_hard_iface {
83671 int16_t if_num;
83672 char if_status;
83673 struct net_device *net_dev;
83674- atomic_t frag_seqno;
83675+ atomic_unchecked_t frag_seqno;
83676 struct kobject *hardif_obj;
83677 atomic_t refcount;
83678 struct packet_type batman_adv_ptype;
83679@@ -284,7 +284,7 @@ struct batadv_priv {
83680 atomic_t orig_interval; /* uint */
83681 atomic_t hop_penalty; /* uint */
83682 atomic_t log_level; /* uint */
83683- atomic_t bcast_seqno;
83684+ atomic_unchecked_t bcast_seqno;
83685 atomic_t bcast_queue_left;
83686 atomic_t batman_queue_left;
83687 char num_ifaces;
83688diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
83689index 10aff49..ea8e021 100644
83690--- a/net/batman-adv/unicast.c
83691+++ b/net/batman-adv/unicast.c
83692@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
83693 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
83694 frag2->flags = large_tail;
83695
83696- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
83697+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
83698 frag1->seqno = htons(seqno - 1);
83699 frag2->seqno = htons(seqno);
83700
83701diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
83702index 07f0739..3c42e34 100644
83703--- a/net/bluetooth/hci_sock.c
83704+++ b/net/bluetooth/hci_sock.c
83705@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
83706 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
83707 }
83708
83709- len = min_t(unsigned int, len, sizeof(uf));
83710+ len = min((size_t)len, sizeof(uf));
83711 if (copy_from_user(&uf, optval, len)) {
83712 err = -EFAULT;
83713 break;
83714diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
83715index 22e6583..426e2f3 100644
83716--- a/net/bluetooth/l2cap_core.c
83717+++ b/net/bluetooth/l2cap_core.c
83718@@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
83719 break;
83720
83721 case L2CAP_CONF_RFC:
83722- if (olen == sizeof(rfc))
83723- memcpy(&rfc, (void *)val, olen);
83724+ if (olen != sizeof(rfc))
83725+ break;
83726+
83727+ memcpy(&rfc, (void *)val, olen);
83728
83729 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
83730 rfc.mode != chan->mode)
83731diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
83732index 1bcfb84..dad9f98 100644
83733--- a/net/bluetooth/l2cap_sock.c
83734+++ b/net/bluetooth/l2cap_sock.c
83735@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83736 struct sock *sk = sock->sk;
83737 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
83738 struct l2cap_options opts;
83739- int len, err = 0;
83740+ int err = 0;
83741+ size_t len = optlen;
83742 u32 opt;
83743
83744 BT_DBG("sk %p", sk);
83745@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83746 opts.max_tx = chan->max_tx;
83747 opts.txwin_size = chan->tx_win;
83748
83749- len = min_t(unsigned int, sizeof(opts), optlen);
83750+ len = min(sizeof(opts), len);
83751 if (copy_from_user((char *) &opts, optval, len)) {
83752 err = -EFAULT;
83753 break;
83754@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83755 struct bt_security sec;
83756 struct bt_power pwr;
83757 struct l2cap_conn *conn;
83758- int len, err = 0;
83759+ int err = 0;
83760+ size_t len = optlen;
83761 u32 opt;
83762
83763 BT_DBG("sk %p", sk);
83764@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83765
83766 sec.level = BT_SECURITY_LOW;
83767
83768- len = min_t(unsigned int, sizeof(sec), optlen);
83769+ len = min(sizeof(sec), len);
83770 if (copy_from_user((char *) &sec, optval, len)) {
83771 err = -EFAULT;
83772 break;
83773@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83774
83775 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
83776
83777- len = min_t(unsigned int, sizeof(pwr), optlen);
83778+ len = min(sizeof(pwr), len);
83779 if (copy_from_user((char *) &pwr, optval, len)) {
83780 err = -EFAULT;
83781 break;
83782diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
83783index ce3f665..2c7d08f 100644
83784--- a/net/bluetooth/rfcomm/sock.c
83785+++ b/net/bluetooth/rfcomm/sock.c
83786@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83787 struct sock *sk = sock->sk;
83788 struct bt_security sec;
83789 int err = 0;
83790- size_t len;
83791+ size_t len = optlen;
83792 u32 opt;
83793
83794 BT_DBG("sk %p", sk);
83795@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83796
83797 sec.level = BT_SECURITY_LOW;
83798
83799- len = min_t(unsigned int, sizeof(sec), optlen);
83800+ len = min(sizeof(sec), len);
83801 if (copy_from_user((char *) &sec, optval, len)) {
83802 err = -EFAULT;
83803 break;
83804diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
83805index bd6fd0f..6492cba 100644
83806--- a/net/bluetooth/rfcomm/tty.c
83807+++ b/net/bluetooth/rfcomm/tty.c
83808@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
83809 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
83810
83811 spin_lock_irqsave(&dev->port.lock, flags);
83812- if (dev->port.count > 0) {
83813+ if (atomic_read(&dev->port.count) > 0) {
83814 spin_unlock_irqrestore(&dev->port.lock, flags);
83815 return;
83816 }
83817@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
83818 return -ENODEV;
83819
83820 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
83821- dev->channel, dev->port.count);
83822+ dev->channel, atomic_read(&dev->port.count));
83823
83824 spin_lock_irqsave(&dev->port.lock, flags);
83825- if (++dev->port.count > 1) {
83826+ if (atomic_inc_return(&dev->port.count) > 1) {
83827 spin_unlock_irqrestore(&dev->port.lock, flags);
83828 return 0;
83829 }
83830@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
83831 return;
83832
83833 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
83834- dev->port.count);
83835+ atomic_read(&dev->port.count));
83836
83837 spin_lock_irqsave(&dev->port.lock, flags);
83838- if (!--dev->port.count) {
83839+ if (!atomic_dec_return(&dev->port.count)) {
83840 spin_unlock_irqrestore(&dev->port.lock, flags);
83841 if (dev->tty_dev->parent)
83842 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
83843diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
83844index acc9f4c..2897e40 100644
83845--- a/net/bridge/br_mdb.c
83846+++ b/net/bridge/br_mdb.c
83847@@ -82,6 +82,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
83848 port = p->port;
83849 if (port) {
83850 struct br_mdb_entry e;
83851+ memset(&e, 0, sizeof(e));
83852 e.ifindex = port->dev->ifindex;
83853 e.state = p->state;
83854 if (p->addr.proto == htons(ETH_P_IP))
83855@@ -138,6 +139,7 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
83856 break;
83857
83858 bpm = nlmsg_data(nlh);
83859+ memset(bpm, 0, sizeof(*bpm));
83860 bpm->ifindex = dev->ifindex;
83861 if (br_mdb_fill_info(skb, cb, dev) < 0)
83862 goto out;
83863@@ -173,6 +175,7 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
83864 return -EMSGSIZE;
83865
83866 bpm = nlmsg_data(nlh);
83867+ memset(bpm, 0, sizeof(*bpm));
83868 bpm->family = AF_BRIDGE;
83869 bpm->ifindex = dev->ifindex;
83870 nest = nla_nest_start(skb, MDBA_MDB);
83871@@ -230,6 +233,7 @@ void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
83872 {
83873 struct br_mdb_entry entry;
83874
83875+ memset(&entry, 0, sizeof(entry));
83876 entry.ifindex = port->dev->ifindex;
83877 entry.addr.proto = group->proto;
83878 entry.addr.u.ip4 = group->u.ip4;
83879diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
83880index 5fe2ff3..121d696 100644
83881--- a/net/bridge/netfilter/ebtables.c
83882+++ b/net/bridge/netfilter/ebtables.c
83883@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
83884 tmp.valid_hooks = t->table->valid_hooks;
83885 }
83886 mutex_unlock(&ebt_mutex);
83887- if (copy_to_user(user, &tmp, *len) != 0){
83888+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
83889 BUGPRINT("c2u Didn't work\n");
83890 ret = -EFAULT;
83891 break;
83892@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83893 goto out;
83894 tmp.valid_hooks = t->valid_hooks;
83895
83896- if (copy_to_user(user, &tmp, *len) != 0) {
83897+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83898 ret = -EFAULT;
83899 break;
83900 }
83901@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83902 tmp.entries_size = t->table->entries_size;
83903 tmp.valid_hooks = t->table->valid_hooks;
83904
83905- if (copy_to_user(user, &tmp, *len) != 0) {
83906+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83907 ret = -EFAULT;
83908 break;
83909 }
83910diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
83911index a376ec1..1fbd6be 100644
83912--- a/net/caif/cfctrl.c
83913+++ b/net/caif/cfctrl.c
83914@@ -10,6 +10,7 @@
83915 #include <linux/spinlock.h>
83916 #include <linux/slab.h>
83917 #include <linux/pkt_sched.h>
83918+#include <linux/sched.h>
83919 #include <net/caif/caif_layer.h>
83920 #include <net/caif/cfpkt.h>
83921 #include <net/caif/cfctrl.h>
83922@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
83923 memset(&dev_info, 0, sizeof(dev_info));
83924 dev_info.id = 0xff;
83925 cfsrvl_init(&this->serv, 0, &dev_info, false);
83926- atomic_set(&this->req_seq_no, 1);
83927- atomic_set(&this->rsp_seq_no, 1);
83928+ atomic_set_unchecked(&this->req_seq_no, 1);
83929+ atomic_set_unchecked(&this->rsp_seq_no, 1);
83930 this->serv.layer.receive = cfctrl_recv;
83931 sprintf(this->serv.layer.name, "ctrl");
83932 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
83933@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
83934 struct cfctrl_request_info *req)
83935 {
83936 spin_lock_bh(&ctrl->info_list_lock);
83937- atomic_inc(&ctrl->req_seq_no);
83938- req->sequence_no = atomic_read(&ctrl->req_seq_no);
83939+ atomic_inc_unchecked(&ctrl->req_seq_no);
83940+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
83941 list_add_tail(&req->list, &ctrl->list);
83942 spin_unlock_bh(&ctrl->info_list_lock);
83943 }
83944@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
83945 if (p != first)
83946 pr_warn("Requests are not received in order\n");
83947
83948- atomic_set(&ctrl->rsp_seq_no,
83949+ atomic_set_unchecked(&ctrl->rsp_seq_no,
83950 p->sequence_no);
83951 list_del(&p->list);
83952 goto out;
83953diff --git a/net/can/af_can.c b/net/can/af_can.c
83954index ddac1ee..3ee0a78 100644
83955--- a/net/can/af_can.c
83956+++ b/net/can/af_can.c
83957@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
83958 };
83959
83960 /* notifier block for netdevice event */
83961-static struct notifier_block can_netdev_notifier __read_mostly = {
83962+static struct notifier_block can_netdev_notifier = {
83963 .notifier_call = can_notifier,
83964 };
83965
83966diff --git a/net/can/gw.c b/net/can/gw.c
83967index 574dda78e..3d2b3da 100644
83968--- a/net/can/gw.c
83969+++ b/net/can/gw.c
83970@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
83971 MODULE_ALIAS("can-gw");
83972
83973 static HLIST_HEAD(cgw_list);
83974-static struct notifier_block notifier;
83975
83976 static struct kmem_cache *cgw_cache __read_mostly;
83977
83978@@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
83979 return err;
83980 }
83981
83982+static struct notifier_block notifier = {
83983+ .notifier_call = cgw_notifier
83984+};
83985+
83986 static __init int cgw_module_init(void)
83987 {
83988 printk(banner);
83989@@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
83990 return -ENOMEM;
83991
83992 /* set notifier */
83993- notifier.notifier_call = cgw_notifier;
83994 register_netdevice_notifier(&notifier);
83995
83996 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
83997diff --git a/net/compat.c b/net/compat.c
83998index 79ae884..17c5c09 100644
83999--- a/net/compat.c
84000+++ b/net/compat.c
84001@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
84002 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
84003 __get_user(kmsg->msg_flags, &umsg->msg_flags))
84004 return -EFAULT;
84005- kmsg->msg_name = compat_ptr(tmp1);
84006- kmsg->msg_iov = compat_ptr(tmp2);
84007- kmsg->msg_control = compat_ptr(tmp3);
84008+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
84009+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84010+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84011 return 0;
84012 }
84013
84014@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84015
84016 if (kern_msg->msg_namelen) {
84017 if (mode == VERIFY_READ) {
84018- int err = move_addr_to_kernel(kern_msg->msg_name,
84019+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84020 kern_msg->msg_namelen,
84021 kern_address);
84022 if (err < 0)
84023@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84024 kern_msg->msg_name = NULL;
84025
84026 tot_len = iov_from_user_compat_to_kern(kern_iov,
84027- (struct compat_iovec __user *)kern_msg->msg_iov,
84028+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
84029 kern_msg->msg_iovlen);
84030 if (tot_len >= 0)
84031 kern_msg->msg_iov = kern_iov;
84032@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84033
84034 #define CMSG_COMPAT_FIRSTHDR(msg) \
84035 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84036- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84037+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84038 (struct compat_cmsghdr __user *)NULL)
84039
84040 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84041 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84042 (ucmlen) <= (unsigned long) \
84043 ((mhdr)->msg_controllen - \
84044- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84045+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84046
84047 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84048 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84049 {
84050 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84051- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84052+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84053 msg->msg_controllen)
84054 return NULL;
84055 return (struct compat_cmsghdr __user *)ptr;
84056@@ -219,7 +219,7 @@ Efault:
84057
84058 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84059 {
84060- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84061+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84062 struct compat_cmsghdr cmhdr;
84063 struct compat_timeval ctv;
84064 struct compat_timespec cts[3];
84065@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84066
84067 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84068 {
84069- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84070+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84071 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84072 int fdnum = scm->fp->count;
84073 struct file **fp = scm->fp->fp;
84074@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84075 return -EFAULT;
84076 old_fs = get_fs();
84077 set_fs(KERNEL_DS);
84078- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84079+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84080 set_fs(old_fs);
84081
84082 return err;
84083@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84084 len = sizeof(ktime);
84085 old_fs = get_fs();
84086 set_fs(KERNEL_DS);
84087- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84088+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84089 set_fs(old_fs);
84090
84091 if (!err) {
84092@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84093 case MCAST_JOIN_GROUP:
84094 case MCAST_LEAVE_GROUP:
84095 {
84096- struct compat_group_req __user *gr32 = (void *)optval;
84097+ struct compat_group_req __user *gr32 = (void __user *)optval;
84098 struct group_req __user *kgr =
84099 compat_alloc_user_space(sizeof(struct group_req));
84100 u32 interface;
84101@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84102 case MCAST_BLOCK_SOURCE:
84103 case MCAST_UNBLOCK_SOURCE:
84104 {
84105- struct compat_group_source_req __user *gsr32 = (void *)optval;
84106+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84107 struct group_source_req __user *kgsr = compat_alloc_user_space(
84108 sizeof(struct group_source_req));
84109 u32 interface;
84110@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84111 }
84112 case MCAST_MSFILTER:
84113 {
84114- struct compat_group_filter __user *gf32 = (void *)optval;
84115+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84116 struct group_filter __user *kgf;
84117 u32 interface, fmode, numsrc;
84118
84119@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84120 char __user *optval, int __user *optlen,
84121 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84122 {
84123- struct compat_group_filter __user *gf32 = (void *)optval;
84124+ struct compat_group_filter __user *gf32 = (void __user *)optval;
84125 struct group_filter __user *kgf;
84126 int __user *koptlen;
84127 u32 interface, fmode, numsrc;
84128@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84129
84130 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84131 return -EINVAL;
84132- if (copy_from_user(a, args, nas[call]))
84133+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84134 return -EFAULT;
84135 a0 = a[0];
84136 a1 = a[1];
84137diff --git a/net/core/datagram.c b/net/core/datagram.c
84138index 368f9c3..f82d4a3 100644
84139--- a/net/core/datagram.c
84140+++ b/net/core/datagram.c
84141@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84142 }
84143
84144 kfree_skb(skb);
84145- atomic_inc(&sk->sk_drops);
84146+ atomic_inc_unchecked(&sk->sk_drops);
84147 sk_mem_reclaim_partial(sk);
84148
84149 return err;
84150diff --git a/net/core/dev.c b/net/core/dev.c
84151index f64e439..8f959e6 100644
84152--- a/net/core/dev.c
84153+++ b/net/core/dev.c
84154@@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84155 if (no_module && capable(CAP_NET_ADMIN))
84156 no_module = request_module("netdev-%s", name);
84157 if (no_module && capable(CAP_SYS_MODULE)) {
84158+#ifdef CONFIG_GRKERNSEC_MODHARDEN
84159+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
84160+#else
84161 if (!request_module("%s", name))
84162 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84163 name);
84164+#endif
84165 }
84166 }
84167 EXPORT_SYMBOL(dev_load);
84168@@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84169 {
84170 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84171 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84172- atomic_long_inc(&dev->rx_dropped);
84173+ atomic_long_inc_unchecked(&dev->rx_dropped);
84174 kfree_skb(skb);
84175 return NET_RX_DROP;
84176 }
84177@@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84178 nf_reset(skb);
84179
84180 if (unlikely(!is_skb_forwardable(dev, skb))) {
84181- atomic_long_inc(&dev->rx_dropped);
84182+ atomic_long_inc_unchecked(&dev->rx_dropped);
84183 kfree_skb(skb);
84184 return NET_RX_DROP;
84185 }
84186@@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84187
84188 struct dev_gso_cb {
84189 void (*destructor)(struct sk_buff *skb);
84190-};
84191+} __no_const;
84192
84193 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84194
84195@@ -3053,7 +3057,7 @@ enqueue:
84196
84197 local_irq_restore(flags);
84198
84199- atomic_long_inc(&skb->dev->rx_dropped);
84200+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84201 kfree_skb(skb);
84202 return NET_RX_DROP;
84203 }
84204@@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84205 }
84206 EXPORT_SYMBOL(netif_rx_ni);
84207
84208-static void net_tx_action(struct softirq_action *h)
84209+static void net_tx_action(void)
84210 {
84211 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84212
84213@@ -3456,7 +3460,7 @@ ncls:
84214 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84215 } else {
84216 drop:
84217- atomic_long_inc(&skb->dev->rx_dropped);
84218+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84219 kfree_skb(skb);
84220 /* Jamal, now you will not able to escape explaining
84221 * me how you were going to use this. :-)
84222@@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
84223 }
84224 EXPORT_SYMBOL(netif_napi_del);
84225
84226-static void net_rx_action(struct softirq_action *h)
84227+static void net_rx_action(void)
84228 {
84229 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84230 unsigned long time_limit = jiffies + 2;
84231@@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84232 else
84233 seq_printf(seq, "%04x", ntohs(pt->type));
84234
84235+#ifdef CONFIG_GRKERNSEC_HIDESYM
84236+ seq_printf(seq, " %-8s %p\n",
84237+ pt->dev ? pt->dev->name : "", NULL);
84238+#else
84239 seq_printf(seq, " %-8s %pF\n",
84240 pt->dev ? pt->dev->name : "", pt->func);
84241+#endif
84242 }
84243
84244 return 0;
84245@@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84246 } else {
84247 netdev_stats_to_stats64(storage, &dev->stats);
84248 }
84249- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84250+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84251 return storage;
84252 }
84253 EXPORT_SYMBOL(dev_get_stats);
84254diff --git a/net/core/flow.c b/net/core/flow.c
84255index b0901ee..7d3c2ca 100644
84256--- a/net/core/flow.c
84257+++ b/net/core/flow.c
84258@@ -61,7 +61,7 @@ struct flow_cache {
84259 struct timer_list rnd_timer;
84260 };
84261
84262-atomic_t flow_cache_genid = ATOMIC_INIT(0);
84263+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
84264 EXPORT_SYMBOL(flow_cache_genid);
84265 static struct flow_cache flow_cache_global;
84266 static struct kmem_cache *flow_cachep __read_mostly;
84267@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
84268
84269 static int flow_entry_valid(struct flow_cache_entry *fle)
84270 {
84271- if (atomic_read(&flow_cache_genid) != fle->genid)
84272+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
84273 return 0;
84274 if (fle->object && !fle->object->ops->check(fle->object))
84275 return 0;
84276@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
84277 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
84278 fcp->hash_count++;
84279 }
84280- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
84281+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
84282 flo = fle->object;
84283 if (!flo)
84284 goto ret_object;
84285@@ -280,7 +280,7 @@ nocache:
84286 }
84287 flo = resolver(net, key, family, dir, flo, ctx);
84288 if (fle) {
84289- fle->genid = atomic_read(&flow_cache_genid);
84290+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
84291 if (!IS_ERR(flo))
84292 fle->object = flo;
84293 else
84294diff --git a/net/core/iovec.c b/net/core/iovec.c
84295index 7e7aeb0..2a998cb 100644
84296--- a/net/core/iovec.c
84297+++ b/net/core/iovec.c
84298@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84299 if (m->msg_namelen) {
84300 if (mode == VERIFY_READ) {
84301 void __user *namep;
84302- namep = (void __user __force *) m->msg_name;
84303+ namep = (void __force_user *) m->msg_name;
84304 err = move_addr_to_kernel(namep, m->msg_namelen,
84305 address);
84306 if (err < 0)
84307@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84308 }
84309
84310 size = m->msg_iovlen * sizeof(struct iovec);
84311- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
84312+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
84313 return -EFAULT;
84314
84315 m->msg_iov = iov;
84316diff --git a/net/core/neighbour.c b/net/core/neighbour.c
84317index c815f28..e6403f2 100644
84318--- a/net/core/neighbour.c
84319+++ b/net/core/neighbour.c
84320@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
84321 size_t *lenp, loff_t *ppos)
84322 {
84323 int size, ret;
84324- ctl_table tmp = *ctl;
84325+ ctl_table_no_const tmp = *ctl;
84326
84327 tmp.extra1 = &zero;
84328 tmp.extra2 = &unres_qlen_max;
84329diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
84330index 28c5f5a..7edf2e2 100644
84331--- a/net/core/net-sysfs.c
84332+++ b/net/core/net-sysfs.c
84333@@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
84334 }
84335 EXPORT_SYMBOL(netdev_class_remove_file);
84336
84337-int netdev_kobject_init(void)
84338+int __init netdev_kobject_init(void)
84339 {
84340 kobj_ns_type_register(&net_ns_type_operations);
84341 return class_register(&net_class);
84342diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
84343index 8acce01..2e306bb 100644
84344--- a/net/core/net_namespace.c
84345+++ b/net/core/net_namespace.c
84346@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
84347 int error;
84348 LIST_HEAD(net_exit_list);
84349
84350- list_add_tail(&ops->list, list);
84351+ pax_list_add_tail((struct list_head *)&ops->list, list);
84352 if (ops->init || (ops->id && ops->size)) {
84353 for_each_net(net) {
84354 error = ops_init(ops, net);
84355@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
84356
84357 out_undo:
84358 /* If I have an error cleanup all namespaces I initialized */
84359- list_del(&ops->list);
84360+ pax_list_del((struct list_head *)&ops->list);
84361 ops_exit_list(ops, &net_exit_list);
84362 ops_free_list(ops, &net_exit_list);
84363 return error;
84364@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
84365 struct net *net;
84366 LIST_HEAD(net_exit_list);
84367
84368- list_del(&ops->list);
84369+ pax_list_del((struct list_head *)&ops->list);
84370 for_each_net(net)
84371 list_add_tail(&net->exit_list, &net_exit_list);
84372 ops_exit_list(ops, &net_exit_list);
84373@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
84374 mutex_lock(&net_mutex);
84375 error = register_pernet_operations(&pernet_list, ops);
84376 if (!error && (first_device == &pernet_list))
84377- first_device = &ops->list;
84378+ first_device = (struct list_head *)&ops->list;
84379 mutex_unlock(&net_mutex);
84380 return error;
84381 }
84382diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
84383index 1868625..e2261f5 100644
84384--- a/net/core/rtnetlink.c
84385+++ b/net/core/rtnetlink.c
84386@@ -58,7 +58,7 @@ struct rtnl_link {
84387 rtnl_doit_func doit;
84388 rtnl_dumpit_func dumpit;
84389 rtnl_calcit_func calcit;
84390-};
84391+} __no_const;
84392
84393 static DEFINE_MUTEX(rtnl_mutex);
84394
84395@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
84396 if (rtnl_link_ops_get(ops->kind))
84397 return -EEXIST;
84398
84399- if (!ops->dellink)
84400- ops->dellink = unregister_netdevice_queue;
84401+ if (!ops->dellink) {
84402+ pax_open_kernel();
84403+ *(void **)&ops->dellink = unregister_netdevice_queue;
84404+ pax_close_kernel();
84405+ }
84406
84407- list_add_tail(&ops->list, &link_ops);
84408+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
84409 return 0;
84410 }
84411 EXPORT_SYMBOL_GPL(__rtnl_link_register);
84412@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
84413 for_each_net(net) {
84414 __rtnl_kill_links(net, ops);
84415 }
84416- list_del(&ops->list);
84417+ pax_list_del((struct list_head *)&ops->list);
84418 }
84419 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
84420
84421@@ -976,6 +979,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
84422 * report anything.
84423 */
84424 ivi.spoofchk = -1;
84425+ memset(ivi.mac, 0, sizeof(ivi.mac));
84426 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
84427 break;
84428 vf_mac.vf =
84429diff --git a/net/core/scm.c b/net/core/scm.c
84430index 905dcc6..14ee2d6 100644
84431--- a/net/core/scm.c
84432+++ b/net/core/scm.c
84433@@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
84434 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84435 {
84436 struct cmsghdr __user *cm
84437- = (__force struct cmsghdr __user *)msg->msg_control;
84438+ = (struct cmsghdr __force_user *)msg->msg_control;
84439 struct cmsghdr cmhdr;
84440 int cmlen = CMSG_LEN(len);
84441 int err;
84442@@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84443 err = -EFAULT;
84444 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
84445 goto out;
84446- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
84447+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
84448 goto out;
84449 cmlen = CMSG_SPACE(len);
84450 if (msg->msg_controllen < cmlen)
84451@@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
84452 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84453 {
84454 struct cmsghdr __user *cm
84455- = (__force struct cmsghdr __user*)msg->msg_control;
84456+ = (struct cmsghdr __force_user *)msg->msg_control;
84457
84458 int fdmax = 0;
84459 int fdnum = scm->fp->count;
84460@@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84461 if (fdnum < fdmax)
84462 fdmax = fdnum;
84463
84464- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
84465+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
84466 i++, cmfptr++)
84467 {
84468 struct socket *sock;
84469diff --git a/net/core/sock.c b/net/core/sock.c
84470index bc131d4..029e378 100644
84471--- a/net/core/sock.c
84472+++ b/net/core/sock.c
84473@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84474 struct sk_buff_head *list = &sk->sk_receive_queue;
84475
84476 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
84477- atomic_inc(&sk->sk_drops);
84478+ atomic_inc_unchecked(&sk->sk_drops);
84479 trace_sock_rcvqueue_full(sk, skb);
84480 return -ENOMEM;
84481 }
84482@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84483 return err;
84484
84485 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
84486- atomic_inc(&sk->sk_drops);
84487+ atomic_inc_unchecked(&sk->sk_drops);
84488 return -ENOBUFS;
84489 }
84490
84491@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84492 skb_dst_force(skb);
84493
84494 spin_lock_irqsave(&list->lock, flags);
84495- skb->dropcount = atomic_read(&sk->sk_drops);
84496+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
84497 __skb_queue_tail(list, skb);
84498 spin_unlock_irqrestore(&list->lock, flags);
84499
84500@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84501 skb->dev = NULL;
84502
84503 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
84504- atomic_inc(&sk->sk_drops);
84505+ atomic_inc_unchecked(&sk->sk_drops);
84506 goto discard_and_relse;
84507 }
84508 if (nested)
84509@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84510 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
84511 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
84512 bh_unlock_sock(sk);
84513- atomic_inc(&sk->sk_drops);
84514+ atomic_inc_unchecked(&sk->sk_drops);
84515 goto discard_and_relse;
84516 }
84517
84518@@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84519 struct timeval tm;
84520 } v;
84521
84522- int lv = sizeof(int);
84523- int len;
84524+ unsigned int lv = sizeof(int);
84525+ unsigned int len;
84526
84527 if (get_user(len, optlen))
84528 return -EFAULT;
84529- if (len < 0)
84530+ if (len > INT_MAX)
84531 return -EINVAL;
84532
84533 memset(&v, 0, sizeof(v));
84534@@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84535
84536 case SO_PEERNAME:
84537 {
84538- char address[128];
84539+ char address[_K_SS_MAXSIZE];
84540
84541 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
84542 return -ENOTCONN;
84543- if (lv < len)
84544+ if (lv < len || sizeof address < len)
84545 return -EINVAL;
84546 if (copy_to_user(optval, address, len))
84547 return -EFAULT;
84548@@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84549
84550 if (len > lv)
84551 len = lv;
84552- if (copy_to_user(optval, &v, len))
84553+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
84554 return -EFAULT;
84555 lenout:
84556 if (put_user(len, optlen))
84557@@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
84558 */
84559 smp_wmb();
84560 atomic_set(&sk->sk_refcnt, 1);
84561- atomic_set(&sk->sk_drops, 0);
84562+ atomic_set_unchecked(&sk->sk_drops, 0);
84563 }
84564 EXPORT_SYMBOL(sock_init_data);
84565
84566diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
84567index 750f44f..922399c 100644
84568--- a/net/core/sock_diag.c
84569+++ b/net/core/sock_diag.c
84570@@ -9,26 +9,33 @@
84571 #include <linux/inet_diag.h>
84572 #include <linux/sock_diag.h>
84573
84574-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
84575+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
84576 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
84577 static DEFINE_MUTEX(sock_diag_table_mutex);
84578
84579 int sock_diag_check_cookie(void *sk, __u32 *cookie)
84580 {
84581+#ifndef CONFIG_GRKERNSEC_HIDESYM
84582 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
84583 cookie[1] != INET_DIAG_NOCOOKIE) &&
84584 ((u32)(unsigned long)sk != cookie[0] ||
84585 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
84586 return -ESTALE;
84587 else
84588+#endif
84589 return 0;
84590 }
84591 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
84592
84593 void sock_diag_save_cookie(void *sk, __u32 *cookie)
84594 {
84595+#ifdef CONFIG_GRKERNSEC_HIDESYM
84596+ cookie[0] = 0;
84597+ cookie[1] = 0;
84598+#else
84599 cookie[0] = (u32)(unsigned long)sk;
84600 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
84601+#endif
84602 }
84603 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
84604
84605@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
84606 mutex_lock(&sock_diag_table_mutex);
84607 if (sock_diag_handlers[hndl->family])
84608 err = -EBUSY;
84609- else
84610+ else {
84611+ pax_open_kernel();
84612 sock_diag_handlers[hndl->family] = hndl;
84613+ pax_close_kernel();
84614+ }
84615 mutex_unlock(&sock_diag_table_mutex);
84616
84617 return err;
84618@@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
84619
84620 mutex_lock(&sock_diag_table_mutex);
84621 BUG_ON(sock_diag_handlers[family] != hnld);
84622+ pax_open_kernel();
84623 sock_diag_handlers[family] = NULL;
84624+ pax_close_kernel();
84625 mutex_unlock(&sock_diag_table_mutex);
84626 }
84627 EXPORT_SYMBOL_GPL(sock_diag_unregister);
84628
84629-static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
84630-{
84631- if (sock_diag_handlers[family] == NULL)
84632- request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84633- NETLINK_SOCK_DIAG, family);
84634-
84635- mutex_lock(&sock_diag_table_mutex);
84636- return sock_diag_handlers[family];
84637-}
84638-
84639-static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
84640-{
84641- mutex_unlock(&sock_diag_table_mutex);
84642-}
84643-
84644 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84645 {
84646 int err;
84647@@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84648 if (req->sdiag_family >= AF_MAX)
84649 return -EINVAL;
84650
84651- hndl = sock_diag_lock_handler(req->sdiag_family);
84652+ if (sock_diag_handlers[req->sdiag_family] == NULL)
84653+ request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84654+ NETLINK_SOCK_DIAG, req->sdiag_family);
84655+
84656+ mutex_lock(&sock_diag_table_mutex);
84657+ hndl = sock_diag_handlers[req->sdiag_family];
84658 if (hndl == NULL)
84659 err = -ENOENT;
84660 else
84661 err = hndl->dump(skb, nlh);
84662- sock_diag_unlock_handler(hndl);
84663+ mutex_unlock(&sock_diag_table_mutex);
84664
84665 return err;
84666 }
84667diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
84668index d1b0804..4aed0a5 100644
84669--- a/net/core/sysctl_net_core.c
84670+++ b/net/core/sysctl_net_core.c
84671@@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
84672 {
84673 unsigned int orig_size, size;
84674 int ret, i;
84675- ctl_table tmp = {
84676+ ctl_table_no_const tmp = {
84677 .data = &size,
84678 .maxlen = sizeof(size),
84679 .mode = table->mode
84680@@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
84681
84682 static __net_init int sysctl_core_net_init(struct net *net)
84683 {
84684- struct ctl_table *tbl;
84685+ ctl_table_no_const *tbl = NULL;
84686
84687 net->core.sysctl_somaxconn = SOMAXCONN;
84688
84689- tbl = netns_core_table;
84690 if (!net_eq(net, &init_net)) {
84691- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
84692+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
84693 if (tbl == NULL)
84694 goto err_dup;
84695
84696@@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
84697 if (net->user_ns != &init_user_ns) {
84698 tbl[0].procname = NULL;
84699 }
84700- }
84701-
84702- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84703+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84704+ } else
84705+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
84706 if (net->core.sysctl_hdr == NULL)
84707 goto err_reg;
84708
84709 return 0;
84710
84711 err_reg:
84712- if (tbl != netns_core_table)
84713+ if (tbl)
84714 kfree(tbl);
84715 err_dup:
84716 return -ENOMEM;
84717@@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
84718 kfree(tbl);
84719 }
84720
84721-static __net_initdata struct pernet_operations sysctl_core_ops = {
84722+static __net_initconst struct pernet_operations sysctl_core_ops = {
84723 .init = sysctl_core_net_init,
84724 .exit = sysctl_core_net_exit,
84725 };
84726diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
84727index 1b588e2..21291f1 100644
84728--- a/net/dcb/dcbnl.c
84729+++ b/net/dcb/dcbnl.c
84730@@ -284,6 +284,7 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
84731 if (!netdev->dcbnl_ops->getpermhwaddr)
84732 return -EOPNOTSUPP;
84733
84734+ memset(perm_addr, 0, sizeof(perm_addr));
84735 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
84736
84737 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
84738@@ -1042,6 +1043,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84739
84740 if (ops->ieee_getets) {
84741 struct ieee_ets ets;
84742+ memset(&ets, 0, sizeof(ets));
84743 err = ops->ieee_getets(netdev, &ets);
84744 if (!err &&
84745 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
84746@@ -1050,6 +1052,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84747
84748 if (ops->ieee_getmaxrate) {
84749 struct ieee_maxrate maxrate;
84750+ memset(&maxrate, 0, sizeof(maxrate));
84751 err = ops->ieee_getmaxrate(netdev, &maxrate);
84752 if (!err) {
84753 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
84754@@ -1061,6 +1064,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84755
84756 if (ops->ieee_getpfc) {
84757 struct ieee_pfc pfc;
84758+ memset(&pfc, 0, sizeof(pfc));
84759 err = ops->ieee_getpfc(netdev, &pfc);
84760 if (!err &&
84761 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
84762@@ -1094,6 +1098,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84763 /* get peer info if available */
84764 if (ops->ieee_peer_getets) {
84765 struct ieee_ets ets;
84766+ memset(&ets, 0, sizeof(ets));
84767 err = ops->ieee_peer_getets(netdev, &ets);
84768 if (!err &&
84769 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
84770@@ -1102,6 +1107,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84771
84772 if (ops->ieee_peer_getpfc) {
84773 struct ieee_pfc pfc;
84774+ memset(&pfc, 0, sizeof(pfc));
84775 err = ops->ieee_peer_getpfc(netdev, &pfc);
84776 if (!err &&
84777 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
84778@@ -1280,6 +1286,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84779 /* peer info if available */
84780 if (ops->cee_peer_getpg) {
84781 struct cee_pg pg;
84782+ memset(&pg, 0, sizeof(pg));
84783 err = ops->cee_peer_getpg(netdev, &pg);
84784 if (!err &&
84785 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
84786@@ -1288,6 +1295,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84787
84788 if (ops->cee_peer_getpfc) {
84789 struct cee_pfc pfc;
84790+ memset(&pfc, 0, sizeof(pfc));
84791 err = ops->cee_peer_getpfc(netdev, &pfc);
84792 if (!err &&
84793 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
84794diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
84795index 307c322..78a4c6f 100644
84796--- a/net/decnet/af_decnet.c
84797+++ b/net/decnet/af_decnet.c
84798@@ -468,6 +468,7 @@ static struct proto dn_proto = {
84799 .sysctl_rmem = sysctl_decnet_rmem,
84800 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
84801 .obj_size = sizeof(struct dn_sock),
84802+ .slab_flags = SLAB_USERCOPY,
84803 };
84804
84805 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
84806diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
84807index a55eecc..dd8428c 100644
84808--- a/net/decnet/sysctl_net_decnet.c
84809+++ b/net/decnet/sysctl_net_decnet.c
84810@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
84811
84812 if (len > *lenp) len = *lenp;
84813
84814- if (copy_to_user(buffer, addr, len))
84815+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
84816 return -EFAULT;
84817
84818 *lenp = len;
84819@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
84820
84821 if (len > *lenp) len = *lenp;
84822
84823- if (copy_to_user(buffer, devname, len))
84824+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
84825 return -EFAULT;
84826
84827 *lenp = len;
84828diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
84829index fcf104e..95552d4 100644
84830--- a/net/ipv4/af_inet.c
84831+++ b/net/ipv4/af_inet.c
84832@@ -1717,13 +1717,9 @@ static int __init inet_init(void)
84833
84834 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
84835
84836- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
84837- if (!sysctl_local_reserved_ports)
84838- goto out;
84839-
84840 rc = proto_register(&tcp_prot, 1);
84841 if (rc)
84842- goto out_free_reserved_ports;
84843+ goto out;
84844
84845 rc = proto_register(&udp_prot, 1);
84846 if (rc)
84847@@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
84848 proto_unregister(&udp_prot);
84849 out_unregister_tcp_proto:
84850 proto_unregister(&tcp_prot);
84851-out_free_reserved_ports:
84852- kfree(sysctl_local_reserved_ports);
84853 goto out;
84854 }
84855
84856diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
84857index a69b4e4..dbccba5 100644
84858--- a/net/ipv4/ah4.c
84859+++ b/net/ipv4/ah4.c
84860@@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
84861 return;
84862
84863 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84864- atomic_inc(&flow_cache_genid);
84865+ atomic_inc_unchecked(&flow_cache_genid);
84866 rt_genid_bump(net);
84867
84868 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
84869diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
84870index a8e4f26..25e5f40 100644
84871--- a/net/ipv4/devinet.c
84872+++ b/net/ipv4/devinet.c
84873@@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
84874 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
84875 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
84876
84877-static struct devinet_sysctl_table {
84878+static const struct devinet_sysctl_table {
84879 struct ctl_table_header *sysctl_header;
84880 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
84881 } devinet_sysctl = {
84882@@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
84883 int err;
84884 struct ipv4_devconf *all, *dflt;
84885 #ifdef CONFIG_SYSCTL
84886- struct ctl_table *tbl = ctl_forward_entry;
84887+ ctl_table_no_const *tbl = NULL;
84888 struct ctl_table_header *forw_hdr;
84889 #endif
84890
84891@@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
84892 goto err_alloc_dflt;
84893
84894 #ifdef CONFIG_SYSCTL
84895- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
84896+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
84897 if (tbl == NULL)
84898 goto err_alloc_ctl;
84899
84900@@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
84901 goto err_reg_dflt;
84902
84903 err = -ENOMEM;
84904- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84905+ if (!net_eq(net, &init_net))
84906+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84907+ else
84908+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
84909 if (forw_hdr == NULL)
84910 goto err_reg_ctl;
84911 net->ipv4.forw_hdr = forw_hdr;
84912@@ -1935,8 +1938,7 @@ err_reg_ctl:
84913 err_reg_dflt:
84914 __devinet_sysctl_unregister(all);
84915 err_reg_all:
84916- if (tbl != ctl_forward_entry)
84917- kfree(tbl);
84918+ kfree(tbl);
84919 err_alloc_ctl:
84920 #endif
84921 if (dflt != &ipv4_devconf_dflt)
84922diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
84923index 3b4f0cd..8cb864c 100644
84924--- a/net/ipv4/esp4.c
84925+++ b/net/ipv4/esp4.c
84926@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
84927 return;
84928
84929 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84930- atomic_inc(&flow_cache_genid);
84931+ atomic_inc_unchecked(&flow_cache_genid);
84932 rt_genid_bump(net);
84933
84934 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
84935diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
84936index 5cd75e2..f57ef39 100644
84937--- a/net/ipv4/fib_frontend.c
84938+++ b/net/ipv4/fib_frontend.c
84939@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
84940 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84941 fib_sync_up(dev);
84942 #endif
84943- atomic_inc(&net->ipv4.dev_addr_genid);
84944+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84945 rt_cache_flush(dev_net(dev));
84946 break;
84947 case NETDEV_DOWN:
84948 fib_del_ifaddr(ifa, NULL);
84949- atomic_inc(&net->ipv4.dev_addr_genid);
84950+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84951 if (ifa->ifa_dev->ifa_list == NULL) {
84952 /* Last address was deleted from this interface.
84953 * Disable IP.
84954@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
84955 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84956 fib_sync_up(dev);
84957 #endif
84958- atomic_inc(&net->ipv4.dev_addr_genid);
84959+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84960 rt_cache_flush(net);
84961 break;
84962 case NETDEV_DOWN:
84963diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
84964index 4797a80..2bd54e9 100644
84965--- a/net/ipv4/fib_semantics.c
84966+++ b/net/ipv4/fib_semantics.c
84967@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
84968 nh->nh_saddr = inet_select_addr(nh->nh_dev,
84969 nh->nh_gw,
84970 nh->nh_parent->fib_scope);
84971- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
84972+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
84973
84974 return nh->nh_saddr;
84975 }
84976diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
84977index d0670f0..744ac80 100644
84978--- a/net/ipv4/inet_connection_sock.c
84979+++ b/net/ipv4/inet_connection_sock.c
84980@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
84981 .range = { 32768, 61000 },
84982 };
84983
84984-unsigned long *sysctl_local_reserved_ports;
84985+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84986 EXPORT_SYMBOL(sysctl_local_reserved_ports);
84987
84988 void inet_get_local_port_range(int *low, int *high)
84989diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
84990index fa3ae81..0dbe6b8 100644
84991--- a/net/ipv4/inet_hashtables.c
84992+++ b/net/ipv4/inet_hashtables.c
84993@@ -18,12 +18,15 @@
84994 #include <linux/sched.h>
84995 #include <linux/slab.h>
84996 #include <linux/wait.h>
84997+#include <linux/security.h>
84998
84999 #include <net/inet_connection_sock.h>
85000 #include <net/inet_hashtables.h>
85001 #include <net/secure_seq.h>
85002 #include <net/ip.h>
85003
85004+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
85005+
85006 /*
85007 * Allocate and initialize a new local port bind bucket.
85008 * The bindhash mutex for snum's hash chain must be held here.
85009@@ -540,6 +543,8 @@ ok:
85010 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85011 spin_unlock(&head->lock);
85012
85013+ gr_update_task_in_ip_table(current, inet_sk(sk));
85014+
85015 if (tw) {
85016 inet_twsk_deschedule(tw, death_row);
85017 while (twrefcnt) {
85018diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85019index 000e3d2..5472da3 100644
85020--- a/net/ipv4/inetpeer.c
85021+++ b/net/ipv4/inetpeer.c
85022@@ -503,8 +503,8 @@ relookup:
85023 if (p) {
85024 p->daddr = *daddr;
85025 atomic_set(&p->refcnt, 1);
85026- atomic_set(&p->rid, 0);
85027- atomic_set(&p->ip_id_count,
85028+ atomic_set_unchecked(&p->rid, 0);
85029+ atomic_set_unchecked(&p->ip_id_count,
85030 (daddr->family == AF_INET) ?
85031 secure_ip_id(daddr->addr.a4) :
85032 secure_ipv6_id(daddr->addr.a6));
85033diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85034index eb9d63a..31c5372 100644
85035--- a/net/ipv4/ip_fragment.c
85036+++ b/net/ipv4/ip_fragment.c
85037@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85038 return 0;
85039
85040 start = qp->rid;
85041- end = atomic_inc_return(&peer->rid);
85042+ end = atomic_inc_return_unchecked(&peer->rid);
85043 qp->rid = end;
85044
85045 rc = qp->q.fragments && (end - start) > max;
85046@@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85047
85048 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85049 {
85050- struct ctl_table *table;
85051+ ctl_table_no_const *table = NULL;
85052 struct ctl_table_header *hdr;
85053
85054- table = ip4_frags_ns_ctl_table;
85055 if (!net_eq(net, &init_net)) {
85056- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85057+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85058 if (table == NULL)
85059 goto err_alloc;
85060
85061@@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85062 /* Don't export sysctls to unprivileged users */
85063 if (net->user_ns != &init_user_ns)
85064 table[0].procname = NULL;
85065- }
85066+ hdr = register_net_sysctl(net, "net/ipv4", table);
85067+ } else
85068+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85069
85070- hdr = register_net_sysctl(net, "net/ipv4", table);
85071 if (hdr == NULL)
85072 goto err_reg;
85073
85074@@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85075 return 0;
85076
85077 err_reg:
85078- if (!net_eq(net, &init_net))
85079- kfree(table);
85080+ kfree(table);
85081 err_alloc:
85082 return -ENOMEM;
85083 }
85084diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85085index e81b1ca..6f3b5b9 100644
85086--- a/net/ipv4/ip_gre.c
85087+++ b/net/ipv4/ip_gre.c
85088@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85089 module_param(log_ecn_error, bool, 0644);
85090 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85091
85092-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85093+static struct rtnl_link_ops ipgre_link_ops;
85094 static int ipgre_tunnel_init(struct net_device *dev);
85095 static void ipgre_tunnel_setup(struct net_device *dev);
85096 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85097@@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85098 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85099 };
85100
85101-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85102+static struct rtnl_link_ops ipgre_link_ops = {
85103 .kind = "gre",
85104 .maxtype = IFLA_GRE_MAX,
85105 .policy = ipgre_policy,
85106@@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85107 .fill_info = ipgre_fill_info,
85108 };
85109
85110-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85111+static struct rtnl_link_ops ipgre_tap_ops = {
85112 .kind = "gretap",
85113 .maxtype = IFLA_GRE_MAX,
85114 .policy = ipgre_policy,
85115diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85116index d9c4f11..02b82db 100644
85117--- a/net/ipv4/ip_sockglue.c
85118+++ b/net/ipv4/ip_sockglue.c
85119@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85120 len = min_t(unsigned int, len, opt->optlen);
85121 if (put_user(len, optlen))
85122 return -EFAULT;
85123- if (copy_to_user(optval, opt->__data, len))
85124+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85125+ copy_to_user(optval, opt->__data, len))
85126 return -EFAULT;
85127 return 0;
85128 }
85129@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85130 if (sk->sk_type != SOCK_STREAM)
85131 return -ENOPROTOOPT;
85132
85133- msg.msg_control = optval;
85134+ msg.msg_control = (void __force_kernel *)optval;
85135 msg.msg_controllen = len;
85136 msg.msg_flags = flags;
85137
85138diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85139index c3a4233..1412161 100644
85140--- a/net/ipv4/ip_vti.c
85141+++ b/net/ipv4/ip_vti.c
85142@@ -47,7 +47,7 @@
85143 #define HASH_SIZE 16
85144 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85145
85146-static struct rtnl_link_ops vti_link_ops __read_mostly;
85147+static struct rtnl_link_ops vti_link_ops;
85148
85149 static int vti_net_id __read_mostly;
85150 struct vti_net {
85151@@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85152 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85153 };
85154
85155-static struct rtnl_link_ops vti_link_ops __read_mostly = {
85156+static struct rtnl_link_ops vti_link_ops = {
85157 .kind = "vti",
85158 .maxtype = IFLA_VTI_MAX,
85159 .policy = vti_policy,
85160diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85161index 9a46dae..5f793a0 100644
85162--- a/net/ipv4/ipcomp.c
85163+++ b/net/ipv4/ipcomp.c
85164@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85165 return;
85166
85167 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85168- atomic_inc(&flow_cache_genid);
85169+ atomic_inc_unchecked(&flow_cache_genid);
85170 rt_genid_bump(net);
85171
85172 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85173diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85174index a2e50ae..e152b7c 100644
85175--- a/net/ipv4/ipconfig.c
85176+++ b/net/ipv4/ipconfig.c
85177@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85178
85179 mm_segment_t oldfs = get_fs();
85180 set_fs(get_ds());
85181- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85182+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85183 set_fs(oldfs);
85184 return res;
85185 }
85186@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85187
85188 mm_segment_t oldfs = get_fs();
85189 set_fs(get_ds());
85190- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85191+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85192 set_fs(oldfs);
85193 return res;
85194 }
85195@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85196
85197 mm_segment_t oldfs = get_fs();
85198 set_fs(get_ds());
85199- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85200+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85201 set_fs(oldfs);
85202 return res;
85203 }
85204diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85205index 191fc24..1b3b804 100644
85206--- a/net/ipv4/ipip.c
85207+++ b/net/ipv4/ipip.c
85208@@ -138,7 +138,7 @@ struct ipip_net {
85209 static int ipip_tunnel_init(struct net_device *dev);
85210 static void ipip_tunnel_setup(struct net_device *dev);
85211 static void ipip_dev_free(struct net_device *dev);
85212-static struct rtnl_link_ops ipip_link_ops __read_mostly;
85213+static struct rtnl_link_ops ipip_link_ops;
85214
85215 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85216 struct rtnl_link_stats64 *tot)
85217@@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85218 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85219 };
85220
85221-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85222+static struct rtnl_link_ops ipip_link_ops = {
85223 .kind = "ipip",
85224 .maxtype = IFLA_IPTUN_MAX,
85225 .policy = ipip_policy,
85226diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85227index 3ea4127..849297b 100644
85228--- a/net/ipv4/netfilter/arp_tables.c
85229+++ b/net/ipv4/netfilter/arp_tables.c
85230@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85231 #endif
85232
85233 static int get_info(struct net *net, void __user *user,
85234- const int *len, int compat)
85235+ int len, int compat)
85236 {
85237 char name[XT_TABLE_MAXNAMELEN];
85238 struct xt_table *t;
85239 int ret;
85240
85241- if (*len != sizeof(struct arpt_getinfo)) {
85242- duprintf("length %u != %Zu\n", *len,
85243+ if (len != sizeof(struct arpt_getinfo)) {
85244+ duprintf("length %u != %Zu\n", len,
85245 sizeof(struct arpt_getinfo));
85246 return -EINVAL;
85247 }
85248@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85249 info.size = private->size;
85250 strcpy(info.name, name);
85251
85252- if (copy_to_user(user, &info, *len) != 0)
85253+ if (copy_to_user(user, &info, len) != 0)
85254 ret = -EFAULT;
85255 else
85256 ret = 0;
85257@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85258
85259 switch (cmd) {
85260 case ARPT_SO_GET_INFO:
85261- ret = get_info(sock_net(sk), user, len, 1);
85262+ ret = get_info(sock_net(sk), user, *len, 1);
85263 break;
85264 case ARPT_SO_GET_ENTRIES:
85265 ret = compat_get_entries(sock_net(sk), user, len);
85266@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85267
85268 switch (cmd) {
85269 case ARPT_SO_GET_INFO:
85270- ret = get_info(sock_net(sk), user, len, 0);
85271+ ret = get_info(sock_net(sk), user, *len, 0);
85272 break;
85273
85274 case ARPT_SO_GET_ENTRIES:
85275diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85276index 17c5e06..1b91206 100644
85277--- a/net/ipv4/netfilter/ip_tables.c
85278+++ b/net/ipv4/netfilter/ip_tables.c
85279@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85280 #endif
85281
85282 static int get_info(struct net *net, void __user *user,
85283- const int *len, int compat)
85284+ int len, int compat)
85285 {
85286 char name[XT_TABLE_MAXNAMELEN];
85287 struct xt_table *t;
85288 int ret;
85289
85290- if (*len != sizeof(struct ipt_getinfo)) {
85291- duprintf("length %u != %zu\n", *len,
85292+ if (len != sizeof(struct ipt_getinfo)) {
85293+ duprintf("length %u != %zu\n", len,
85294 sizeof(struct ipt_getinfo));
85295 return -EINVAL;
85296 }
85297@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85298 info.size = private->size;
85299 strcpy(info.name, name);
85300
85301- if (copy_to_user(user, &info, *len) != 0)
85302+ if (copy_to_user(user, &info, len) != 0)
85303 ret = -EFAULT;
85304 else
85305 ret = 0;
85306@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85307
85308 switch (cmd) {
85309 case IPT_SO_GET_INFO:
85310- ret = get_info(sock_net(sk), user, len, 1);
85311+ ret = get_info(sock_net(sk), user, *len, 1);
85312 break;
85313 case IPT_SO_GET_ENTRIES:
85314 ret = compat_get_entries(sock_net(sk), user, len);
85315@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85316
85317 switch (cmd) {
85318 case IPT_SO_GET_INFO:
85319- ret = get_info(sock_net(sk), user, len, 0);
85320+ ret = get_info(sock_net(sk), user, *len, 0);
85321 break;
85322
85323 case IPT_SO_GET_ENTRIES:
85324diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
85325index dc454cc..5bb917f 100644
85326--- a/net/ipv4/ping.c
85327+++ b/net/ipv4/ping.c
85328@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
85329 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85330 0, sock_i_ino(sp),
85331 atomic_read(&sp->sk_refcnt), sp,
85332- atomic_read(&sp->sk_drops), len);
85333+ atomic_read_unchecked(&sp->sk_drops), len);
85334 }
85335
85336 static int ping_seq_show(struct seq_file *seq, void *v)
85337diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
85338index 6f08991..55867ad 100644
85339--- a/net/ipv4/raw.c
85340+++ b/net/ipv4/raw.c
85341@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
85342 int raw_rcv(struct sock *sk, struct sk_buff *skb)
85343 {
85344 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
85345- atomic_inc(&sk->sk_drops);
85346+ atomic_inc_unchecked(&sk->sk_drops);
85347 kfree_skb(skb);
85348 return NET_RX_DROP;
85349 }
85350@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
85351
85352 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
85353 {
85354+ struct icmp_filter filter;
85355+
85356 if (optlen > sizeof(struct icmp_filter))
85357 optlen = sizeof(struct icmp_filter);
85358- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
85359+ if (copy_from_user(&filter, optval, optlen))
85360 return -EFAULT;
85361+ raw_sk(sk)->filter = filter;
85362 return 0;
85363 }
85364
85365 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
85366 {
85367 int len, ret = -EFAULT;
85368+ struct icmp_filter filter;
85369
85370 if (get_user(len, optlen))
85371 goto out;
85372@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
85373 if (len > sizeof(struct icmp_filter))
85374 len = sizeof(struct icmp_filter);
85375 ret = -EFAULT;
85376- if (put_user(len, optlen) ||
85377- copy_to_user(optval, &raw_sk(sk)->filter, len))
85378+ filter = raw_sk(sk)->filter;
85379+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
85380 goto out;
85381 ret = 0;
85382 out: return ret;
85383@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
85384 0, 0L, 0,
85385 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
85386 0, sock_i_ino(sp),
85387- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
85388+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
85389 }
85390
85391 static int raw_seq_show(struct seq_file *seq, void *v)
85392diff --git a/net/ipv4/route.c b/net/ipv4/route.c
85393index a0fcc47..32e2c89 100644
85394--- a/net/ipv4/route.c
85395+++ b/net/ipv4/route.c
85396@@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
85397 .maxlen = sizeof(int),
85398 .mode = 0200,
85399 .proc_handler = ipv4_sysctl_rtcache_flush,
85400+ .extra1 = &init_net,
85401 },
85402 { },
85403 };
85404
85405 static __net_init int sysctl_route_net_init(struct net *net)
85406 {
85407- struct ctl_table *tbl;
85408+ ctl_table_no_const *tbl = NULL;
85409
85410- tbl = ipv4_route_flush_table;
85411 if (!net_eq(net, &init_net)) {
85412- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85413+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85414 if (tbl == NULL)
85415 goto err_dup;
85416
85417 /* Don't export sysctls to unprivileged users */
85418 if (net->user_ns != &init_user_ns)
85419 tbl[0].procname = NULL;
85420- }
85421- tbl[0].extra1 = net;
85422+ tbl[0].extra1 = net;
85423+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85424+ } else
85425+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
85426
85427- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85428 if (net->ipv4.route_hdr == NULL)
85429 goto err_reg;
85430 return 0;
85431
85432 err_reg:
85433- if (tbl != ipv4_route_flush_table)
85434- kfree(tbl);
85435+ kfree(tbl);
85436 err_dup:
85437 return -ENOMEM;
85438 }
85439@@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
85440
85441 static __net_init int rt_genid_init(struct net *net)
85442 {
85443- atomic_set(&net->rt_genid, 0);
85444+ atomic_set_unchecked(&net->rt_genid, 0);
85445 get_random_bytes(&net->ipv4.dev_addr_genid,
85446 sizeof(net->ipv4.dev_addr_genid));
85447 return 0;
85448diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
85449index d84400b..62e066e 100644
85450--- a/net/ipv4/sysctl_net_ipv4.c
85451+++ b/net/ipv4/sysctl_net_ipv4.c
85452@@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
85453 {
85454 int ret;
85455 int range[2];
85456- ctl_table tmp = {
85457+ ctl_table_no_const tmp = {
85458 .data = &range,
85459 .maxlen = sizeof(range),
85460 .mode = table->mode,
85461@@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
85462 int ret;
85463 gid_t urange[2];
85464 kgid_t low, high;
85465- ctl_table tmp = {
85466+ ctl_table_no_const tmp = {
85467 .data = &urange,
85468 .maxlen = sizeof(urange),
85469 .mode = table->mode,
85470@@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
85471 void __user *buffer, size_t *lenp, loff_t *ppos)
85472 {
85473 char val[TCP_CA_NAME_MAX];
85474- ctl_table tbl = {
85475+ ctl_table_no_const tbl = {
85476 .data = val,
85477 .maxlen = TCP_CA_NAME_MAX,
85478 };
85479@@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
85480 void __user *buffer, size_t *lenp,
85481 loff_t *ppos)
85482 {
85483- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
85484+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
85485 int ret;
85486
85487 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85488@@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
85489 void __user *buffer, size_t *lenp,
85490 loff_t *ppos)
85491 {
85492- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
85493+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
85494 int ret;
85495
85496 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85497@@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85498 struct mem_cgroup *memcg;
85499 #endif
85500
85501- ctl_table tmp = {
85502+ ctl_table_no_const tmp = {
85503 .data = &vec,
85504 .maxlen = sizeof(vec),
85505 .mode = ctl->mode,
85506 };
85507
85508 if (!write) {
85509- ctl->data = &net->ipv4.sysctl_tcp_mem;
85510- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
85511+ ctl_table_no_const tcp_mem = *ctl;
85512+
85513+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
85514+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
85515 }
85516
85517 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
85518@@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85519 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
85520 size_t *lenp, loff_t *ppos)
85521 {
85522- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85523+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85524 struct tcp_fastopen_context *ctxt;
85525 int ret;
85526 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
85527@@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
85528 },
85529 {
85530 .procname = "ip_local_reserved_ports",
85531- .data = NULL, /* initialized in sysctl_ipv4_init */
85532+ .data = sysctl_local_reserved_ports,
85533 .maxlen = 65536,
85534 .mode = 0644,
85535 .proc_handler = proc_do_large_bitmap,
85536@@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
85537
85538 static __net_init int ipv4_sysctl_init_net(struct net *net)
85539 {
85540- struct ctl_table *table;
85541+ ctl_table_no_const *table = NULL;
85542
85543- table = ipv4_net_table;
85544 if (!net_eq(net, &init_net)) {
85545- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
85546+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
85547 if (table == NULL)
85548 goto err_alloc;
85549
85550@@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
85551
85552 tcp_init_mem(net);
85553
85554- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85555+ if (!net_eq(net, &init_net))
85556+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85557+ else
85558+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
85559 if (net->ipv4.ipv4_hdr == NULL)
85560 goto err_reg;
85561
85562 return 0;
85563
85564 err_reg:
85565- if (!net_eq(net, &init_net))
85566- kfree(table);
85567+ kfree(table);
85568 err_alloc:
85569 return -ENOMEM;
85570 }
85571@@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
85572 static __init int sysctl_ipv4_init(void)
85573 {
85574 struct ctl_table_header *hdr;
85575- struct ctl_table *i;
85576-
85577- for (i = ipv4_table; i->procname; i++) {
85578- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
85579- i->data = sysctl_local_reserved_ports;
85580- break;
85581- }
85582- }
85583- if (!i->procname)
85584- return -EINVAL;
85585
85586 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
85587 if (hdr == NULL)
85588diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
85589index ad70a96..50cb55b 100644
85590--- a/net/ipv4/tcp_input.c
85591+++ b/net/ipv4/tcp_input.c
85592@@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
85593 * simplifies code)
85594 */
85595 static void
85596-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85597+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85598 struct sk_buff *head, struct sk_buff *tail,
85599 u32 start, u32 end)
85600 {
85601@@ -5850,6 +5850,7 @@ discard:
85602 tcp_paws_reject(&tp->rx_opt, 0))
85603 goto discard_and_undo;
85604
85605+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
85606 if (th->syn) {
85607 /* We see SYN without ACK. It is attempt of
85608 * simultaneous connect with crossed SYNs.
85609@@ -5900,6 +5901,7 @@ discard:
85610 goto discard;
85611 #endif
85612 }
85613+#endif
85614 /* "fifth, if neither of the SYN or RST bits is set then
85615 * drop the segment and return."
85616 */
85617@@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
85618 goto discard;
85619
85620 if (th->syn) {
85621- if (th->fin)
85622+ if (th->fin || th->urg || th->psh)
85623 goto discard;
85624 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
85625 return 1;
85626diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
85627index eadb693..e8f7251 100644
85628--- a/net/ipv4/tcp_ipv4.c
85629+++ b/net/ipv4/tcp_ipv4.c
85630@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
85631 EXPORT_SYMBOL(sysctl_tcp_low_latency);
85632
85633
85634+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85635+extern int grsec_enable_blackhole;
85636+#endif
85637+
85638 #ifdef CONFIG_TCP_MD5SIG
85639 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
85640 __be32 daddr, __be32 saddr, const struct tcphdr *th);
85641@@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
85642 return 0;
85643
85644 reset:
85645+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85646+ if (!grsec_enable_blackhole)
85647+#endif
85648 tcp_v4_send_reset(rsk, skb);
85649 discard:
85650 kfree_skb(skb);
85651@@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
85652 TCP_SKB_CB(skb)->sacked = 0;
85653
85654 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
85655- if (!sk)
85656+ if (!sk) {
85657+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85658+ ret = 1;
85659+#endif
85660 goto no_tcp_socket;
85661-
85662+ }
85663 process:
85664- if (sk->sk_state == TCP_TIME_WAIT)
85665+ if (sk->sk_state == TCP_TIME_WAIT) {
85666+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85667+ ret = 2;
85668+#endif
85669 goto do_time_wait;
85670+ }
85671
85672 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
85673 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
85674@@ -2050,6 +2064,10 @@ no_tcp_socket:
85675 bad_packet:
85676 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
85677 } else {
85678+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85679+ if (!grsec_enable_blackhole || (ret == 1 &&
85680+ (skb->dev->flags & IFF_LOOPBACK)))
85681+#endif
85682 tcp_v4_send_reset(NULL, skb);
85683 }
85684
85685diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
85686index f35f2df..ccb5ca6 100644
85687--- a/net/ipv4/tcp_minisocks.c
85688+++ b/net/ipv4/tcp_minisocks.c
85689@@ -27,6 +27,10 @@
85690 #include <net/inet_common.h>
85691 #include <net/xfrm.h>
85692
85693+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85694+extern int grsec_enable_blackhole;
85695+#endif
85696+
85697 int sysctl_tcp_syncookies __read_mostly = 1;
85698 EXPORT_SYMBOL(sysctl_tcp_syncookies);
85699
85700@@ -742,7 +746,10 @@ embryonic_reset:
85701 * avoid becoming vulnerable to outside attack aiming at
85702 * resetting legit local connections.
85703 */
85704- req->rsk_ops->send_reset(sk, skb);
85705+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85706+ if (!grsec_enable_blackhole)
85707+#endif
85708+ req->rsk_ops->send_reset(sk, skb);
85709 } else if (fastopen) { /* received a valid RST pkt */
85710 reqsk_fastopen_remove(sk, req, true);
85711 tcp_reset(sk);
85712diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
85713index 4526fe6..1a34e43 100644
85714--- a/net/ipv4/tcp_probe.c
85715+++ b/net/ipv4/tcp_probe.c
85716@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
85717 if (cnt + width >= len)
85718 break;
85719
85720- if (copy_to_user(buf + cnt, tbuf, width))
85721+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
85722 return -EFAULT;
85723 cnt += width;
85724 }
85725diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
85726index b78aac3..e18230b 100644
85727--- a/net/ipv4/tcp_timer.c
85728+++ b/net/ipv4/tcp_timer.c
85729@@ -22,6 +22,10 @@
85730 #include <linux/gfp.h>
85731 #include <net/tcp.h>
85732
85733+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85734+extern int grsec_lastack_retries;
85735+#endif
85736+
85737 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
85738 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
85739 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
85740@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
85741 }
85742 }
85743
85744+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85745+ if ((sk->sk_state == TCP_LAST_ACK) &&
85746+ (grsec_lastack_retries > 0) &&
85747+ (grsec_lastack_retries < retry_until))
85748+ retry_until = grsec_lastack_retries;
85749+#endif
85750+
85751 if (retransmits_timed_out(sk, retry_until,
85752 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
85753 /* Has it gone just too far? */
85754diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
85755index 1f4d405..3524677 100644
85756--- a/net/ipv4/udp.c
85757+++ b/net/ipv4/udp.c
85758@@ -87,6 +87,7 @@
85759 #include <linux/types.h>
85760 #include <linux/fcntl.h>
85761 #include <linux/module.h>
85762+#include <linux/security.h>
85763 #include <linux/socket.h>
85764 #include <linux/sockios.h>
85765 #include <linux/igmp.h>
85766@@ -111,6 +112,10 @@
85767 #include <trace/events/skb.h>
85768 #include "udp_impl.h"
85769
85770+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85771+extern int grsec_enable_blackhole;
85772+#endif
85773+
85774 struct udp_table udp_table __read_mostly;
85775 EXPORT_SYMBOL(udp_table);
85776
85777@@ -569,6 +574,9 @@ found:
85778 return s;
85779 }
85780
85781+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
85782+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
85783+
85784 /*
85785 * This routine is called by the ICMP module when it gets some
85786 * sort of error condition. If err < 0 then the socket should
85787@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
85788 dport = usin->sin_port;
85789 if (dport == 0)
85790 return -EINVAL;
85791+
85792+ err = gr_search_udp_sendmsg(sk, usin);
85793+ if (err)
85794+ return err;
85795 } else {
85796 if (sk->sk_state != TCP_ESTABLISHED)
85797 return -EDESTADDRREQ;
85798+
85799+ err = gr_search_udp_sendmsg(sk, NULL);
85800+ if (err)
85801+ return err;
85802+
85803 daddr = inet->inet_daddr;
85804 dport = inet->inet_dport;
85805 /* Open fast path for connected socket.
85806@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
85807 udp_lib_checksum_complete(skb)) {
85808 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85809 IS_UDPLITE(sk));
85810- atomic_inc(&sk->sk_drops);
85811+ atomic_inc_unchecked(&sk->sk_drops);
85812 __skb_unlink(skb, rcvq);
85813 __skb_queue_tail(&list_kill, skb);
85814 }
85815@@ -1194,6 +1211,10 @@ try_again:
85816 if (!skb)
85817 goto out;
85818
85819+ err = gr_search_udp_recvmsg(sk, skb);
85820+ if (err)
85821+ goto out_free;
85822+
85823 ulen = skb->len - sizeof(struct udphdr);
85824 copied = len;
85825 if (copied > ulen)
85826@@ -1227,7 +1248,7 @@ try_again:
85827 if (unlikely(err)) {
85828 trace_kfree_skb(skb, udp_recvmsg);
85829 if (!peeked) {
85830- atomic_inc(&sk->sk_drops);
85831+ atomic_inc_unchecked(&sk->sk_drops);
85832 UDP_INC_STATS_USER(sock_net(sk),
85833 UDP_MIB_INERRORS, is_udplite);
85834 }
85835@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85836
85837 drop:
85838 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
85839- atomic_inc(&sk->sk_drops);
85840+ atomic_inc_unchecked(&sk->sk_drops);
85841 kfree_skb(skb);
85842 return -1;
85843 }
85844@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
85845 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
85846
85847 if (!skb1) {
85848- atomic_inc(&sk->sk_drops);
85849+ atomic_inc_unchecked(&sk->sk_drops);
85850 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
85851 IS_UDPLITE(sk));
85852 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85853@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
85854 goto csum_error;
85855
85856 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
85857+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85858+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
85859+#endif
85860 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
85861
85862 /*
85863@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
85864 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85865 0, sock_i_ino(sp),
85866 atomic_read(&sp->sk_refcnt), sp,
85867- atomic_read(&sp->sk_drops), len);
85868+ atomic_read_unchecked(&sp->sk_drops), len);
85869 }
85870
85871 int udp4_seq_show(struct seq_file *seq, void *v)
85872diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
85873index 1b5d8cb..ffb0833 100644
85874--- a/net/ipv6/addrconf.c
85875+++ b/net/ipv6/addrconf.c
85876@@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
85877 p.iph.ihl = 5;
85878 p.iph.protocol = IPPROTO_IPV6;
85879 p.iph.ttl = 64;
85880- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
85881+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
85882
85883 if (ops->ndo_do_ioctl) {
85884 mm_segment_t oldfs = get_fs();
85885@@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
85886 int *valp = ctl->data;
85887 int val = *valp;
85888 loff_t pos = *ppos;
85889- ctl_table lctl;
85890+ ctl_table_no_const lctl;
85891 int ret;
85892
85893 /*
85894@@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
85895 int *valp = ctl->data;
85896 int val = *valp;
85897 loff_t pos = *ppos;
85898- ctl_table lctl;
85899+ ctl_table_no_const lctl;
85900 int ret;
85901
85902 /*
85903diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
85904index fff5bdd..15194fb 100644
85905--- a/net/ipv6/icmp.c
85906+++ b/net/ipv6/icmp.c
85907@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
85908
85909 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
85910 {
85911- struct ctl_table *table;
85912+ ctl_table_no_const *table;
85913
85914 table = kmemdup(ipv6_icmp_table_template,
85915 sizeof(ipv6_icmp_table_template),
85916diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
85917index 131dd09..f7ed64f 100644
85918--- a/net/ipv6/ip6_gre.c
85919+++ b/net/ipv6/ip6_gre.c
85920@@ -73,7 +73,7 @@ struct ip6gre_net {
85921 struct net_device *fb_tunnel_dev;
85922 };
85923
85924-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
85925+static struct rtnl_link_ops ip6gre_link_ops;
85926 static int ip6gre_tunnel_init(struct net_device *dev);
85927 static void ip6gre_tunnel_setup(struct net_device *dev);
85928 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
85929@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
85930 }
85931
85932
85933-static struct inet6_protocol ip6gre_protocol __read_mostly = {
85934+static struct inet6_protocol ip6gre_protocol = {
85935 .handler = ip6gre_rcv,
85936 .err_handler = ip6gre_err,
85937 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
85938@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
85939 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
85940 };
85941
85942-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85943+static struct rtnl_link_ops ip6gre_link_ops = {
85944 .kind = "ip6gre",
85945 .maxtype = IFLA_GRE_MAX,
85946 .policy = ip6gre_policy,
85947@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85948 .fill_info = ip6gre_fill_info,
85949 };
85950
85951-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
85952+static struct rtnl_link_ops ip6gre_tap_ops = {
85953 .kind = "ip6gretap",
85954 .maxtype = IFLA_GRE_MAX,
85955 .policy = ip6gre_policy,
85956diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
85957index a14f28b..b4b8956 100644
85958--- a/net/ipv6/ip6_tunnel.c
85959+++ b/net/ipv6/ip6_tunnel.c
85960@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
85961
85962 static int ip6_tnl_dev_init(struct net_device *dev);
85963 static void ip6_tnl_dev_setup(struct net_device *dev);
85964-static struct rtnl_link_ops ip6_link_ops __read_mostly;
85965+static struct rtnl_link_ops ip6_link_ops;
85966
85967 static int ip6_tnl_net_id __read_mostly;
85968 struct ip6_tnl_net {
85969@@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
85970 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
85971 };
85972
85973-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
85974+static struct rtnl_link_ops ip6_link_ops = {
85975 .kind = "ip6tnl",
85976 .maxtype = IFLA_IPTUN_MAX,
85977 .policy = ip6_tnl_policy,
85978diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
85979index d1e2e8e..51c19ae 100644
85980--- a/net/ipv6/ipv6_sockglue.c
85981+++ b/net/ipv6/ipv6_sockglue.c
85982@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
85983 if (sk->sk_type != SOCK_STREAM)
85984 return -ENOPROTOOPT;
85985
85986- msg.msg_control = optval;
85987+ msg.msg_control = (void __force_kernel *)optval;
85988 msg.msg_controllen = len;
85989 msg.msg_flags = flags;
85990
85991diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
85992index 125a90d..2a11f36 100644
85993--- a/net/ipv6/netfilter/ip6_tables.c
85994+++ b/net/ipv6/netfilter/ip6_tables.c
85995@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
85996 #endif
85997
85998 static int get_info(struct net *net, void __user *user,
85999- const int *len, int compat)
86000+ int len, int compat)
86001 {
86002 char name[XT_TABLE_MAXNAMELEN];
86003 struct xt_table *t;
86004 int ret;
86005
86006- if (*len != sizeof(struct ip6t_getinfo)) {
86007- duprintf("length %u != %zu\n", *len,
86008+ if (len != sizeof(struct ip6t_getinfo)) {
86009+ duprintf("length %u != %zu\n", len,
86010 sizeof(struct ip6t_getinfo));
86011 return -EINVAL;
86012 }
86013@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86014 info.size = private->size;
86015 strcpy(info.name, name);
86016
86017- if (copy_to_user(user, &info, *len) != 0)
86018+ if (copy_to_user(user, &info, len) != 0)
86019 ret = -EFAULT;
86020 else
86021 ret = 0;
86022@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86023
86024 switch (cmd) {
86025 case IP6T_SO_GET_INFO:
86026- ret = get_info(sock_net(sk), user, len, 1);
86027+ ret = get_info(sock_net(sk), user, *len, 1);
86028 break;
86029 case IP6T_SO_GET_ENTRIES:
86030 ret = compat_get_entries(sock_net(sk), user, len);
86031@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86032
86033 switch (cmd) {
86034 case IP6T_SO_GET_INFO:
86035- ret = get_info(sock_net(sk), user, len, 0);
86036+ ret = get_info(sock_net(sk), user, *len, 0);
86037 break;
86038
86039 case IP6T_SO_GET_ENTRIES:
86040diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86041index 3dacecc..2939087 100644
86042--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86043+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86044@@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86045
86046 static int nf_ct_frag6_sysctl_register(struct net *net)
86047 {
86048- struct ctl_table *table;
86049+ ctl_table_no_const *table = NULL;
86050 struct ctl_table_header *hdr;
86051
86052- table = nf_ct_frag6_sysctl_table;
86053 if (!net_eq(net, &init_net)) {
86054- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86055+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86056 GFP_KERNEL);
86057 if (table == NULL)
86058 goto err_alloc;
86059@@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86060 table[0].data = &net->ipv6.frags.high_thresh;
86061 table[1].data = &net->ipv6.frags.low_thresh;
86062 table[2].data = &net->ipv6.frags.timeout;
86063- }
86064-
86065- hdr = register_net_sysctl(net, "net/netfilter", table);
86066+ hdr = register_net_sysctl(net, "net/netfilter", table);
86067+ } else
86068+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86069 if (hdr == NULL)
86070 goto err_reg;
86071
86072@@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86073 return 0;
86074
86075 err_reg:
86076- if (!net_eq(net, &init_net))
86077- kfree(table);
86078+ kfree(table);
86079 err_alloc:
86080 return -ENOMEM;
86081 }
86082diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86083index 70fa814..d70c28c 100644
86084--- a/net/ipv6/raw.c
86085+++ b/net/ipv6/raw.c
86086@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86087 {
86088 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86089 skb_checksum_complete(skb)) {
86090- atomic_inc(&sk->sk_drops);
86091+ atomic_inc_unchecked(&sk->sk_drops);
86092 kfree_skb(skb);
86093 return NET_RX_DROP;
86094 }
86095@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86096 struct raw6_sock *rp = raw6_sk(sk);
86097
86098 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86099- atomic_inc(&sk->sk_drops);
86100+ atomic_inc_unchecked(&sk->sk_drops);
86101 kfree_skb(skb);
86102 return NET_RX_DROP;
86103 }
86104@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86105
86106 if (inet->hdrincl) {
86107 if (skb_checksum_complete(skb)) {
86108- atomic_inc(&sk->sk_drops);
86109+ atomic_inc_unchecked(&sk->sk_drops);
86110 kfree_skb(skb);
86111 return NET_RX_DROP;
86112 }
86113@@ -604,7 +604,7 @@ out:
86114 return err;
86115 }
86116
86117-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86118+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86119 struct flowi6 *fl6, struct dst_entry **dstp,
86120 unsigned int flags)
86121 {
86122@@ -916,12 +916,15 @@ do_confirm:
86123 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86124 char __user *optval, int optlen)
86125 {
86126+ struct icmp6_filter filter;
86127+
86128 switch (optname) {
86129 case ICMPV6_FILTER:
86130 if (optlen > sizeof(struct icmp6_filter))
86131 optlen = sizeof(struct icmp6_filter);
86132- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86133+ if (copy_from_user(&filter, optval, optlen))
86134 return -EFAULT;
86135+ raw6_sk(sk)->filter = filter;
86136 return 0;
86137 default:
86138 return -ENOPROTOOPT;
86139@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86140 char __user *optval, int __user *optlen)
86141 {
86142 int len;
86143+ struct icmp6_filter filter;
86144
86145 switch (optname) {
86146 case ICMPV6_FILTER:
86147@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86148 len = sizeof(struct icmp6_filter);
86149 if (put_user(len, optlen))
86150 return -EFAULT;
86151- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86152+ filter = raw6_sk(sk)->filter;
86153+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
86154 return -EFAULT;
86155 return 0;
86156 default:
86157@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86158 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86159 0,
86160 sock_i_ino(sp),
86161- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86162+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86163 }
86164
86165 static int raw6_seq_show(struct seq_file *seq, void *v)
86166diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86167index e5253ec..0410257 100644
86168--- a/net/ipv6/reassembly.c
86169+++ b/net/ipv6/reassembly.c
86170@@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86171
86172 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86173 {
86174- struct ctl_table *table;
86175+ ctl_table_no_const *table = NULL;
86176 struct ctl_table_header *hdr;
86177
86178- table = ip6_frags_ns_ctl_table;
86179 if (!net_eq(net, &init_net)) {
86180- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86181+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86182 if (table == NULL)
86183 goto err_alloc;
86184
86185@@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86186 /* Don't export sysctls to unprivileged users */
86187 if (net->user_ns != &init_user_ns)
86188 table[0].procname = NULL;
86189- }
86190+ hdr = register_net_sysctl(net, "net/ipv6", table);
86191+ } else
86192+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86193
86194- hdr = register_net_sysctl(net, "net/ipv6", table);
86195 if (hdr == NULL)
86196 goto err_reg;
86197
86198@@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86199 return 0;
86200
86201 err_reg:
86202- if (!net_eq(net, &init_net))
86203- kfree(table);
86204+ kfree(table);
86205 err_alloc:
86206 return -ENOMEM;
86207 }
86208diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86209index 6f9f7b6..2306d63 100644
86210--- a/net/ipv6/route.c
86211+++ b/net/ipv6/route.c
86212@@ -2965,7 +2965,7 @@ ctl_table ipv6_route_table_template[] = {
86213
86214 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86215 {
86216- struct ctl_table *table;
86217+ ctl_table_no_const *table;
86218
86219 table = kmemdup(ipv6_route_table_template,
86220 sizeof(ipv6_route_table_template),
86221diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86222index cfba99b..20ca511 100644
86223--- a/net/ipv6/sit.c
86224+++ b/net/ipv6/sit.c
86225@@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86226 static int ipip6_tunnel_init(struct net_device *dev);
86227 static void ipip6_tunnel_setup(struct net_device *dev);
86228 static void ipip6_dev_free(struct net_device *dev);
86229-static struct rtnl_link_ops sit_link_ops __read_mostly;
86230+static struct rtnl_link_ops sit_link_ops;
86231
86232 static int sit_net_id __read_mostly;
86233 struct sit_net {
86234@@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86235 #endif
86236 };
86237
86238-static struct rtnl_link_ops sit_link_ops __read_mostly = {
86239+static struct rtnl_link_ops sit_link_ops = {
86240 .kind = "sit",
86241 .maxtype = IFLA_IPTUN_MAX,
86242 .policy = ipip6_policy,
86243diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86244index e85c48b..b8268d3 100644
86245--- a/net/ipv6/sysctl_net_ipv6.c
86246+++ b/net/ipv6/sysctl_net_ipv6.c
86247@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86248
86249 static int __net_init ipv6_sysctl_net_init(struct net *net)
86250 {
86251- struct ctl_table *ipv6_table;
86252+ ctl_table_no_const *ipv6_table;
86253 struct ctl_table *ipv6_route_table;
86254 struct ctl_table *ipv6_icmp_table;
86255 int err;
86256diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86257index 4f435371..5de9da7 100644
86258--- a/net/ipv6/tcp_ipv6.c
86259+++ b/net/ipv6/tcp_ipv6.c
86260@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86261 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86262 }
86263
86264+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86265+extern int grsec_enable_blackhole;
86266+#endif
86267+
86268 static void tcp_v6_hash(struct sock *sk)
86269 {
86270 if (sk->sk_state != TCP_CLOSE) {
86271@@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86272 return 0;
86273
86274 reset:
86275+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86276+ if (!grsec_enable_blackhole)
86277+#endif
86278 tcp_v6_send_reset(sk, skb);
86279 discard:
86280 if (opt_skb)
86281@@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86282 TCP_SKB_CB(skb)->sacked = 0;
86283
86284 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86285- if (!sk)
86286+ if (!sk) {
86287+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86288+ ret = 1;
86289+#endif
86290 goto no_tcp_socket;
86291+ }
86292
86293 process:
86294- if (sk->sk_state == TCP_TIME_WAIT)
86295+ if (sk->sk_state == TCP_TIME_WAIT) {
86296+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86297+ ret = 2;
86298+#endif
86299 goto do_time_wait;
86300+ }
86301
86302 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86303 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86304@@ -1568,6 +1583,10 @@ no_tcp_socket:
86305 bad_packet:
86306 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86307 } else {
86308+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86309+ if (!grsec_enable_blackhole || (ret == 1 &&
86310+ (skb->dev->flags & IFF_LOOPBACK)))
86311+#endif
86312 tcp_v6_send_reset(NULL, skb);
86313 }
86314
86315diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86316index fb08329..2d6919e 100644
86317--- a/net/ipv6/udp.c
86318+++ b/net/ipv6/udp.c
86319@@ -51,6 +51,10 @@
86320 #include <trace/events/skb.h>
86321 #include "udp_impl.h"
86322
86323+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86324+extern int grsec_enable_blackhole;
86325+#endif
86326+
86327 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
86328 {
86329 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
86330@@ -395,7 +399,7 @@ try_again:
86331 if (unlikely(err)) {
86332 trace_kfree_skb(skb, udpv6_recvmsg);
86333 if (!peeked) {
86334- atomic_inc(&sk->sk_drops);
86335+ atomic_inc_unchecked(&sk->sk_drops);
86336 if (is_udp4)
86337 UDP_INC_STATS_USER(sock_net(sk),
86338 UDP_MIB_INERRORS,
86339@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86340 return rc;
86341 drop:
86342 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86343- atomic_inc(&sk->sk_drops);
86344+ atomic_inc_unchecked(&sk->sk_drops);
86345 kfree_skb(skb);
86346 return -1;
86347 }
86348@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86349 if (likely(skb1 == NULL))
86350 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86351 if (!skb1) {
86352- atomic_inc(&sk->sk_drops);
86353+ atomic_inc_unchecked(&sk->sk_drops);
86354 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86355 IS_UDPLITE(sk));
86356 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86357@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86358 goto discard;
86359
86360 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86361+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86362+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86363+#endif
86364 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
86365
86366 kfree_skb(skb);
86367@@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
86368 0,
86369 sock_i_ino(sp),
86370 atomic_read(&sp->sk_refcnt), sp,
86371- atomic_read(&sp->sk_drops));
86372+ atomic_read_unchecked(&sp->sk_drops));
86373 }
86374
86375 int udp6_seq_show(struct seq_file *seq, void *v)
86376diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
86377index a68c88c..d55b0c5 100644
86378--- a/net/irda/ircomm/ircomm_tty.c
86379+++ b/net/irda/ircomm/ircomm_tty.c
86380@@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86381 add_wait_queue(&port->open_wait, &wait);
86382
86383 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
86384- __FILE__, __LINE__, tty->driver->name, port->count);
86385+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86386
86387 spin_lock_irqsave(&port->lock, flags);
86388 if (!tty_hung_up_p(filp)) {
86389 extra_count = 1;
86390- port->count--;
86391+ atomic_dec(&port->count);
86392 }
86393 spin_unlock_irqrestore(&port->lock, flags);
86394 port->blocked_open++;
86395@@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86396 }
86397
86398 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
86399- __FILE__, __LINE__, tty->driver->name, port->count);
86400+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86401
86402 schedule();
86403 }
86404@@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86405 if (extra_count) {
86406 /* ++ is not atomic, so this should be protected - Jean II */
86407 spin_lock_irqsave(&port->lock, flags);
86408- port->count++;
86409+ atomic_inc(&port->count);
86410 spin_unlock_irqrestore(&port->lock, flags);
86411 }
86412 port->blocked_open--;
86413
86414 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
86415- __FILE__, __LINE__, tty->driver->name, port->count);
86416+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86417
86418 if (!retval)
86419 port->flags |= ASYNC_NORMAL_ACTIVE;
86420@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
86421
86422 /* ++ is not atomic, so this should be protected - Jean II */
86423 spin_lock_irqsave(&self->port.lock, flags);
86424- self->port.count++;
86425+ atomic_inc(&self->port.count);
86426 spin_unlock_irqrestore(&self->port.lock, flags);
86427 tty_port_tty_set(&self->port, tty);
86428
86429 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
86430- self->line, self->port.count);
86431+ self->line, atomic_read(&self->port.count));
86432
86433 /* Not really used by us, but lets do it anyway */
86434 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
86435@@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
86436 tty_kref_put(port->tty);
86437 }
86438 port->tty = NULL;
86439- port->count = 0;
86440+ atomic_set(&port->count, 0);
86441 spin_unlock_irqrestore(&port->lock, flags);
86442
86443 wake_up_interruptible(&port->open_wait);
86444@@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
86445 seq_putc(m, '\n');
86446
86447 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
86448- seq_printf(m, "Open count: %d\n", self->port.count);
86449+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
86450 seq_printf(m, "Max data size: %d\n", self->max_data_size);
86451 seq_printf(m, "Max header size: %d\n", self->max_header_size);
86452
86453diff --git a/net/irda/iriap.c b/net/irda/iriap.c
86454index e71e85b..29340a9 100644
86455--- a/net/irda/iriap.c
86456+++ b/net/irda/iriap.c
86457@@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
86458 /* case CS_ISO_8859_9: */
86459 /* case CS_UNICODE: */
86460 default:
86461- IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
86462- __func__, ias_charset_types[charset]);
86463+ IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
86464+ __func__, charset,
86465+ charset < ARRAY_SIZE(ias_charset_types) ?
86466+ ias_charset_types[charset] :
86467+ "(unknown)");
86468
86469 /* Aborting, close connection! */
86470 iriap_disconnect_request(self);
86471diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
86472index cd6f7a9..e63fe89 100644
86473--- a/net/iucv/af_iucv.c
86474+++ b/net/iucv/af_iucv.c
86475@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
86476
86477 write_lock_bh(&iucv_sk_list.lock);
86478
86479- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
86480+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86481 while (__iucv_get_sock_by_name(name)) {
86482 sprintf(name, "%08x",
86483- atomic_inc_return(&iucv_sk_list.autobind_name));
86484+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86485 }
86486
86487 write_unlock_bh(&iucv_sk_list.lock);
86488diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
86489index df08250..02021fe 100644
86490--- a/net/iucv/iucv.c
86491+++ b/net/iucv/iucv.c
86492@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
86493 return NOTIFY_OK;
86494 }
86495
86496-static struct notifier_block __refdata iucv_cpu_notifier = {
86497+static struct notifier_block iucv_cpu_notifier = {
86498 .notifier_call = iucv_cpu_notify,
86499 };
86500
86501diff --git a/net/key/af_key.c b/net/key/af_key.c
86502index 5b426a6..970032b 100644
86503--- a/net/key/af_key.c
86504+++ b/net/key/af_key.c
86505@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
86506 static u32 get_acqseq(void)
86507 {
86508 u32 res;
86509- static atomic_t acqseq;
86510+ static atomic_unchecked_t acqseq;
86511
86512 do {
86513- res = atomic_inc_return(&acqseq);
86514+ res = atomic_inc_return_unchecked(&acqseq);
86515 } while (!res);
86516 return res;
86517 }
86518diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
86519index 716605c..044e9e1 100644
86520--- a/net/l2tp/l2tp_ppp.c
86521+++ b/net/l2tp/l2tp_ppp.c
86522@@ -355,6 +355,7 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
86523 l2tp_xmit_skb(session, skb, session->hdr_len);
86524
86525 sock_put(ps->tunnel_sock);
86526+ sock_put(sk);
86527
86528 return error;
86529
86530diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
86531index 0479c64..d031db6 100644
86532--- a/net/mac80211/cfg.c
86533+++ b/net/mac80211/cfg.c
86534@@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
86535 ret = ieee80211_vif_use_channel(sdata, chandef,
86536 IEEE80211_CHANCTX_EXCLUSIVE);
86537 }
86538- } else if (local->open_count == local->monitors) {
86539+ } else if (local_read(&local->open_count) == local->monitors) {
86540 local->_oper_channel = chandef->chan;
86541 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
86542 ieee80211_hw_config(local, 0);
86543@@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
86544 else
86545 local->probe_req_reg--;
86546
86547- if (!local->open_count)
86548+ if (!local_read(&local->open_count))
86549 break;
86550
86551 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
86552diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
86553index 2ed065c..948177f 100644
86554--- a/net/mac80211/ieee80211_i.h
86555+++ b/net/mac80211/ieee80211_i.h
86556@@ -28,6 +28,7 @@
86557 #include <net/ieee80211_radiotap.h>
86558 #include <net/cfg80211.h>
86559 #include <net/mac80211.h>
86560+#include <asm/local.h>
86561 #include "key.h"
86562 #include "sta_info.h"
86563 #include "debug.h"
86564@@ -909,7 +910,7 @@ struct ieee80211_local {
86565 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
86566 spinlock_t queue_stop_reason_lock;
86567
86568- int open_count;
86569+ local_t open_count;
86570 int monitors, cooked_mntrs;
86571 /* number of interfaces with corresponding FIF_ flags */
86572 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
86573diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
86574index 8be854e..ad72a69 100644
86575--- a/net/mac80211/iface.c
86576+++ b/net/mac80211/iface.c
86577@@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86578 break;
86579 }
86580
86581- if (local->open_count == 0) {
86582+ if (local_read(&local->open_count) == 0) {
86583 res = drv_start(local);
86584 if (res)
86585 goto err_del_bss;
86586@@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86587 break;
86588 }
86589
86590- if (local->monitors == 0 && local->open_count == 0) {
86591+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
86592 res = ieee80211_add_virtual_monitor(local);
86593 if (res)
86594 goto err_stop;
86595@@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86596 mutex_unlock(&local->mtx);
86597
86598 if (coming_up)
86599- local->open_count++;
86600+ local_inc(&local->open_count);
86601
86602 if (hw_reconf_flags)
86603 ieee80211_hw_config(local, hw_reconf_flags);
86604@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86605 err_del_interface:
86606 drv_remove_interface(local, sdata);
86607 err_stop:
86608- if (!local->open_count)
86609+ if (!local_read(&local->open_count))
86610 drv_stop(local);
86611 err_del_bss:
86612 sdata->bss = NULL;
86613@@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86614 }
86615
86616 if (going_down)
86617- local->open_count--;
86618+ local_dec(&local->open_count);
86619
86620 switch (sdata->vif.type) {
86621 case NL80211_IFTYPE_AP_VLAN:
86622@@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86623
86624 ieee80211_recalc_ps(local, -1);
86625
86626- if (local->open_count == 0) {
86627+ if (local_read(&local->open_count) == 0) {
86628 if (local->ops->napi_poll)
86629 napi_disable(&local->napi);
86630 ieee80211_clear_tx_pending(local);
86631@@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86632 }
86633 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
86634
86635- if (local->monitors == local->open_count && local->monitors > 0)
86636+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
86637 ieee80211_add_virtual_monitor(local);
86638 }
86639
86640diff --git a/net/mac80211/main.c b/net/mac80211/main.c
86641index 1b087ff..bf600e9 100644
86642--- a/net/mac80211/main.c
86643+++ b/net/mac80211/main.c
86644@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
86645 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
86646 IEEE80211_CONF_CHANGE_POWER);
86647
86648- if (changed && local->open_count) {
86649+ if (changed && local_read(&local->open_count)) {
86650 ret = drv_config(local, changed);
86651 /*
86652 * Goal:
86653diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
86654index 79a48f3..5e185c9 100644
86655--- a/net/mac80211/pm.c
86656+++ b/net/mac80211/pm.c
86657@@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86658 struct sta_info *sta;
86659 struct ieee80211_chanctx *ctx;
86660
86661- if (!local->open_count)
86662+ if (!local_read(&local->open_count))
86663 goto suspend;
86664
86665 ieee80211_scan_cancel(local);
86666@@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86667 cancel_work_sync(&local->dynamic_ps_enable_work);
86668 del_timer_sync(&local->dynamic_ps_timer);
86669
86670- local->wowlan = wowlan && local->open_count;
86671+ local->wowlan = wowlan && local_read(&local->open_count);
86672 if (local->wowlan) {
86673 int err = drv_suspend(local, wowlan);
86674 if (err < 0) {
86675@@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86676 mutex_unlock(&local->chanctx_mtx);
86677
86678 /* stop hardware - this must stop RX */
86679- if (local->open_count)
86680+ if (local_read(&local->open_count))
86681 ieee80211_stop_device(local);
86682
86683 suspend:
86684diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
86685index dd88381..eef4dd6 100644
86686--- a/net/mac80211/rate.c
86687+++ b/net/mac80211/rate.c
86688@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
86689
86690 ASSERT_RTNL();
86691
86692- if (local->open_count)
86693+ if (local_read(&local->open_count))
86694 return -EBUSY;
86695
86696 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
86697diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
86698index c97a065..ff61928 100644
86699--- a/net/mac80211/rc80211_pid_debugfs.c
86700+++ b/net/mac80211/rc80211_pid_debugfs.c
86701@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
86702
86703 spin_unlock_irqrestore(&events->lock, status);
86704
86705- if (copy_to_user(buf, pb, p))
86706+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
86707 return -EFAULT;
86708
86709 return p;
86710diff --git a/net/mac80211/util.c b/net/mac80211/util.c
86711index f11e8c5..08d0013 100644
86712--- a/net/mac80211/util.c
86713+++ b/net/mac80211/util.c
86714@@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
86715 }
86716 #endif
86717 /* everything else happens only if HW was up & running */
86718- if (!local->open_count)
86719+ if (!local_read(&local->open_count))
86720 goto wake_up;
86721
86722 /*
86723diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
86724index 49e96df..63a51c3 100644
86725--- a/net/netfilter/Kconfig
86726+++ b/net/netfilter/Kconfig
86727@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
86728
86729 To compile it as a module, choose M here. If unsure, say N.
86730
86731+config NETFILTER_XT_MATCH_GRADM
86732+ tristate '"gradm" match support'
86733+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
86734+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
86735+ ---help---
86736+ The gradm match allows to match on grsecurity RBAC being enabled.
86737+ It is useful when iptables rules are applied early on bootup to
86738+ prevent connections to the machine (except from a trusted host)
86739+ while the RBAC system is disabled.
86740+
86741 config NETFILTER_XT_MATCH_HASHLIMIT
86742 tristate '"hashlimit" match support'
86743 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
86744diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
86745index 3259697..54d5393 100644
86746--- a/net/netfilter/Makefile
86747+++ b/net/netfilter/Makefile
86748@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
86749 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
86750 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
86751 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
86752+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
86753 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
86754 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
86755 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
86756diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
86757index 6d6d8f2..a676749 100644
86758--- a/net/netfilter/ipset/ip_set_core.c
86759+++ b/net/netfilter/ipset/ip_set_core.c
86760@@ -1800,7 +1800,7 @@ done:
86761 return ret;
86762 }
86763
86764-static struct nf_sockopt_ops so_set __read_mostly = {
86765+static struct nf_sockopt_ops so_set = {
86766 .pf = PF_INET,
86767 .get_optmin = SO_IP_SET,
86768 .get_optmax = SO_IP_SET + 1,
86769diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
86770index 30e764a..c3b6a9d 100644
86771--- a/net/netfilter/ipvs/ip_vs_conn.c
86772+++ b/net/netfilter/ipvs/ip_vs_conn.c
86773@@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
86774 /* Increase the refcnt counter of the dest */
86775 atomic_inc(&dest->refcnt);
86776
86777- conn_flags = atomic_read(&dest->conn_flags);
86778+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
86779 if (cp->protocol != IPPROTO_UDP)
86780 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
86781 flags = cp->flags;
86782@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
86783 atomic_set(&cp->refcnt, 1);
86784
86785 atomic_set(&cp->n_control, 0);
86786- atomic_set(&cp->in_pkts, 0);
86787+ atomic_set_unchecked(&cp->in_pkts, 0);
86788
86789 atomic_inc(&ipvs->conn_count);
86790 if (flags & IP_VS_CONN_F_NO_CPORT)
86791@@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
86792
86793 /* Don't drop the entry if its number of incoming packets is not
86794 located in [0, 8] */
86795- i = atomic_read(&cp->in_pkts);
86796+ i = atomic_read_unchecked(&cp->in_pkts);
86797 if (i > 8 || i < 0) return 0;
86798
86799 if (!todrop_rate[i]) return 0;
86800diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
86801index 47edf5a..235b07d 100644
86802--- a/net/netfilter/ipvs/ip_vs_core.c
86803+++ b/net/netfilter/ipvs/ip_vs_core.c
86804@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
86805 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
86806 /* do not touch skb anymore */
86807
86808- atomic_inc(&cp->in_pkts);
86809+ atomic_inc_unchecked(&cp->in_pkts);
86810 ip_vs_conn_put(cp);
86811 return ret;
86812 }
86813@@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
86814 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
86815 pkts = sysctl_sync_threshold(ipvs);
86816 else
86817- pkts = atomic_add_return(1, &cp->in_pkts);
86818+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86819
86820 if (ipvs->sync_state & IP_VS_STATE_MASTER)
86821 ip_vs_sync_conn(net, cp, pkts);
86822diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
86823index ec664cb..7f34a77 100644
86824--- a/net/netfilter/ipvs/ip_vs_ctl.c
86825+++ b/net/netfilter/ipvs/ip_vs_ctl.c
86826@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
86827 ip_vs_rs_hash(ipvs, dest);
86828 write_unlock_bh(&ipvs->rs_lock);
86829 }
86830- atomic_set(&dest->conn_flags, conn_flags);
86831+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
86832
86833 /* bind the service */
86834 if (!dest->svc) {
86835@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
86836 * align with netns init in ip_vs_control_net_init()
86837 */
86838
86839-static struct ctl_table vs_vars[] = {
86840+static ctl_table_no_const vs_vars[] __read_only = {
86841 {
86842 .procname = "amemthresh",
86843 .maxlen = sizeof(int),
86844@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86845 " %-7s %-6d %-10d %-10d\n",
86846 &dest->addr.in6,
86847 ntohs(dest->port),
86848- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86849+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86850 atomic_read(&dest->weight),
86851 atomic_read(&dest->activeconns),
86852 atomic_read(&dest->inactconns));
86853@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86854 "%-7s %-6d %-10d %-10d\n",
86855 ntohl(dest->addr.ip),
86856 ntohs(dest->port),
86857- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86858+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86859 atomic_read(&dest->weight),
86860 atomic_read(&dest->activeconns),
86861 atomic_read(&dest->inactconns));
86862@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
86863
86864 entry.addr = dest->addr.ip;
86865 entry.port = dest->port;
86866- entry.conn_flags = atomic_read(&dest->conn_flags);
86867+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
86868 entry.weight = atomic_read(&dest->weight);
86869 entry.u_threshold = dest->u_threshold;
86870 entry.l_threshold = dest->l_threshold;
86871@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
86872 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
86873 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
86874 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
86875- (atomic_read(&dest->conn_flags) &
86876+ (atomic_read_unchecked(&dest->conn_flags) &
86877 IP_VS_CONN_F_FWD_MASK)) ||
86878 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
86879 atomic_read(&dest->weight)) ||
86880@@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
86881 {
86882 int idx;
86883 struct netns_ipvs *ipvs = net_ipvs(net);
86884- struct ctl_table *tbl;
86885+ ctl_table_no_const *tbl;
86886
86887 atomic_set(&ipvs->dropentry, 0);
86888 spin_lock_init(&ipvs->dropentry_lock);
86889diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
86890index fdd89b9..bd96aa9 100644
86891--- a/net/netfilter/ipvs/ip_vs_lblc.c
86892+++ b/net/netfilter/ipvs/ip_vs_lblc.c
86893@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
86894 * IPVS LBLC sysctl table
86895 */
86896 #ifdef CONFIG_SYSCTL
86897-static ctl_table vs_vars_table[] = {
86898+static ctl_table_no_const vs_vars_table[] __read_only = {
86899 {
86900 .procname = "lblc_expiration",
86901 .data = NULL,
86902diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
86903index c03b6a3..8ce3681 100644
86904--- a/net/netfilter/ipvs/ip_vs_lblcr.c
86905+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
86906@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
86907 * IPVS LBLCR sysctl table
86908 */
86909
86910-static ctl_table vs_vars_table[] = {
86911+static ctl_table_no_const vs_vars_table[] __read_only = {
86912 {
86913 .procname = "lblcr_expiration",
86914 .data = NULL,
86915diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
86916index 44fd10c..2a163b3 100644
86917--- a/net/netfilter/ipvs/ip_vs_sync.c
86918+++ b/net/netfilter/ipvs/ip_vs_sync.c
86919@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
86920 cp = cp->control;
86921 if (cp) {
86922 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86923- pkts = atomic_add_return(1, &cp->in_pkts);
86924+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86925 else
86926 pkts = sysctl_sync_threshold(ipvs);
86927 ip_vs_sync_conn(net, cp->control, pkts);
86928@@ -758,7 +758,7 @@ control:
86929 if (!cp)
86930 return;
86931 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86932- pkts = atomic_add_return(1, &cp->in_pkts);
86933+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86934 else
86935 pkts = sysctl_sync_threshold(ipvs);
86936 goto sloop;
86937@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
86938
86939 if (opt)
86940 memcpy(&cp->in_seq, opt, sizeof(*opt));
86941- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86942+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86943 cp->state = state;
86944 cp->old_state = cp->state;
86945 /*
86946diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
86947index ee6b7a9..f9a89f6 100644
86948--- a/net/netfilter/ipvs/ip_vs_xmit.c
86949+++ b/net/netfilter/ipvs/ip_vs_xmit.c
86950@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
86951 else
86952 rc = NF_ACCEPT;
86953 /* do not touch skb anymore */
86954- atomic_inc(&cp->in_pkts);
86955+ atomic_inc_unchecked(&cp->in_pkts);
86956 goto out;
86957 }
86958
86959@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
86960 else
86961 rc = NF_ACCEPT;
86962 /* do not touch skb anymore */
86963- atomic_inc(&cp->in_pkts);
86964+ atomic_inc_unchecked(&cp->in_pkts);
86965 goto out;
86966 }
86967
86968diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
86969index 7df424e..a527b02 100644
86970--- a/net/netfilter/nf_conntrack_acct.c
86971+++ b/net/netfilter/nf_conntrack_acct.c
86972@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
86973 #ifdef CONFIG_SYSCTL
86974 static int nf_conntrack_acct_init_sysctl(struct net *net)
86975 {
86976- struct ctl_table *table;
86977+ ctl_table_no_const *table;
86978
86979 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
86980 GFP_KERNEL);
86981diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
86982index e4a0c4f..c263f28 100644
86983--- a/net/netfilter/nf_conntrack_core.c
86984+++ b/net/netfilter/nf_conntrack_core.c
86985@@ -1529,6 +1529,10 @@ err_extend:
86986 #define DYING_NULLS_VAL ((1<<30)+1)
86987 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
86988
86989+#ifdef CONFIG_GRKERNSEC_HIDESYM
86990+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
86991+#endif
86992+
86993 static int nf_conntrack_init_net(struct net *net)
86994 {
86995 int ret;
86996@@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
86997 goto err_stat;
86998 }
86999
87000+#ifdef CONFIG_GRKERNSEC_HIDESYM
87001+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
87002+#else
87003 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
87004+#endif
87005 if (!net->ct.slabname) {
87006 ret = -ENOMEM;
87007 goto err_slabname;
87008diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
87009index faa978f..1afb18f 100644
87010--- a/net/netfilter/nf_conntrack_ecache.c
87011+++ b/net/netfilter/nf_conntrack_ecache.c
87012@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87013 #ifdef CONFIG_SYSCTL
87014 static int nf_conntrack_event_init_sysctl(struct net *net)
87015 {
87016- struct ctl_table *table;
87017+ ctl_table_no_const *table;
87018
87019 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87020 GFP_KERNEL);
87021diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87022index 884f2b3..d53b33a 100644
87023--- a/net/netfilter/nf_conntrack_helper.c
87024+++ b/net/netfilter/nf_conntrack_helper.c
87025@@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87026
87027 static int nf_conntrack_helper_init_sysctl(struct net *net)
87028 {
87029- struct ctl_table *table;
87030+ ctl_table_no_const *table;
87031
87032 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87033 GFP_KERNEL);
87034diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87035index 51e928d..72a413a 100644
87036--- a/net/netfilter/nf_conntrack_proto.c
87037+++ b/net/netfilter/nf_conntrack_proto.c
87038@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87039
87040 static void
87041 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87042- struct ctl_table **table,
87043+ ctl_table_no_const **table,
87044 unsigned int users)
87045 {
87046 if (users > 0)
87047diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87048index e7185c6..4ad6c9c 100644
87049--- a/net/netfilter/nf_conntrack_standalone.c
87050+++ b/net/netfilter/nf_conntrack_standalone.c
87051@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87052
87053 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87054 {
87055- struct ctl_table *table;
87056+ ctl_table_no_const *table;
87057
87058 if (net_eq(net, &init_net)) {
87059 nf_ct_netfilter_header =
87060diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87061index 7ea8026..bc9512d 100644
87062--- a/net/netfilter/nf_conntrack_timestamp.c
87063+++ b/net/netfilter/nf_conntrack_timestamp.c
87064@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87065 #ifdef CONFIG_SYSCTL
87066 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87067 {
87068- struct ctl_table *table;
87069+ ctl_table_no_const *table;
87070
87071 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87072 GFP_KERNEL);
87073diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87074index 9e31269..bc4c1b7 100644
87075--- a/net/netfilter/nf_log.c
87076+++ b/net/netfilter/nf_log.c
87077@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87078
87079 #ifdef CONFIG_SYSCTL
87080 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87081-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87082+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87083 static struct ctl_table_header *nf_log_dir_header;
87084
87085 static int nf_log_proc_dostring(ctl_table *table, int write,
87086@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87087 rcu_assign_pointer(nf_loggers[tindex], logger);
87088 mutex_unlock(&nf_log_mutex);
87089 } else {
87090+ ctl_table_no_const nf_log_table = *table;
87091+
87092 mutex_lock(&nf_log_mutex);
87093 logger = rcu_dereference_protected(nf_loggers[tindex],
87094 lockdep_is_held(&nf_log_mutex));
87095 if (!logger)
87096- table->data = "NONE";
87097+ nf_log_table.data = "NONE";
87098 else
87099- table->data = logger->name;
87100- r = proc_dostring(table, write, buffer, lenp, ppos);
87101+ nf_log_table.data = logger->name;
87102+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87103 mutex_unlock(&nf_log_mutex);
87104 }
87105
87106diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87107index f042ae5..30ea486 100644
87108--- a/net/netfilter/nf_sockopt.c
87109+++ b/net/netfilter/nf_sockopt.c
87110@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87111 }
87112 }
87113
87114- list_add(&reg->list, &nf_sockopts);
87115+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87116 out:
87117 mutex_unlock(&nf_sockopt_mutex);
87118 return ret;
87119@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87120 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87121 {
87122 mutex_lock(&nf_sockopt_mutex);
87123- list_del(&reg->list);
87124+ pax_list_del((struct list_head *)&reg->list);
87125 mutex_unlock(&nf_sockopt_mutex);
87126 }
87127 EXPORT_SYMBOL(nf_unregister_sockopt);
87128diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87129index 92fd8ec..3f6ea4b 100644
87130--- a/net/netfilter/nfnetlink_log.c
87131+++ b/net/netfilter/nfnetlink_log.c
87132@@ -72,7 +72,7 @@ struct nfulnl_instance {
87133 };
87134
87135 static DEFINE_SPINLOCK(instances_lock);
87136-static atomic_t global_seq;
87137+static atomic_unchecked_t global_seq;
87138
87139 #define INSTANCE_BUCKETS 16
87140 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87141@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87142 /* global sequence number */
87143 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87144 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87145- htonl(atomic_inc_return(&global_seq))))
87146+ htonl(atomic_inc_return_unchecked(&global_seq))))
87147 goto nla_put_failure;
87148
87149 if (data_len) {
87150diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87151new file mode 100644
87152index 0000000..c566332
87153--- /dev/null
87154+++ b/net/netfilter/xt_gradm.c
87155@@ -0,0 +1,51 @@
87156+/*
87157+ * gradm match for netfilter
87158