]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.0-201302271810.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.0-201302271810.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..dba90c5 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,11 @@ series
176 setup
177 setup.bin
178 setup.elf
179 +size_overflow_hash.h
180 sImage
181 +slabinfo
182 sm_tbl*
183 +sortextable
184 split-include
185 syscalltab.h
186 tables.c
187 @@ -224,6 +252,7 @@ tftpboot.img
188 timeconst.h
189 times.h*
190 trix_boot.h
191 +user_constants.h
192 utsrelease.h*
193 vdso-syms.lds
194 vdso.lds
195 @@ -235,13 +264,17 @@ vdso32.lds
196 vdso32.so.dbg
197 vdso64.lds
198 vdso64.so.dbg
199 +vdsox32.lds
200 +vdsox32-syms.lds
201 version.h*
202 vmImage
203 vmlinux
204 vmlinux-*
205 vmlinux.aout
206 vmlinux.bin.all
207 +vmlinux.bin.bz2
208 vmlinux.lds
209 +vmlinux.relocs
210 vmlinuz
211 voffset.h
212 vsyscall.lds
213 @@ -249,9 +282,11 @@ vsyscall_32.lds
214 wanxlfw.inc
215 uImage
216 unifdef
217 +utsrelease.h
218 wakeup.bin
219 wakeup.elf
220 wakeup.lds
221 zImage*
222 zconf.hash.c
223 +zconf.lex.c
224 zoffset.h
225 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
226 index 6c72381..2fe9ae4 100644
227 --- a/Documentation/kernel-parameters.txt
228 +++ b/Documentation/kernel-parameters.txt
229 @@ -917,6 +917,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
230 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
231 Default: 1024
232
233 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
234 + ignore grsecurity's /proc restrictions
235 +
236 +
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240 @@ -2116,6 +2120,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245 + virtualization environments that don't cope well with the
246 + expand down segment used by UDEREF on X86-32 or the frequent
247 + page table updates on X86-64.
248 +
249 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250 +
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254 diff --git a/Makefile b/Makefile
255 index d69266c..e4f6593 100644
256 --- a/Makefile
257 +++ b/Makefile
258 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
259
260 HOSTCC = gcc
261 HOSTCXX = g++
262 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
263 -HOSTCXXFLAGS = -O2
264 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
265 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
266 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
267
268 # Decide whether to build built-in, modular, or both.
269 # Normally, just do built-in.
270 @@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
271 # Rules shared between *config targets and build targets
272
273 # Basic helpers built in scripts/
274 -PHONY += scripts_basic
275 -scripts_basic:
276 +PHONY += scripts_basic gcc-plugins
277 +scripts_basic: gcc-plugins
278 $(Q)$(MAKE) $(build)=scripts/basic
279 $(Q)rm -f .tmp_quiet_recordmcount
280
281 @@ -575,6 +576,64 @@ else
282 KBUILD_CFLAGS += -O2
283 endif
284
285 +ifndef DISABLE_PAX_PLUGINS
286 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
287 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
288 +else
289 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
290 +endif
291 +ifneq ($(PLUGINCC),)
292 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
293 +ifndef CONFIG_UML
294 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
295 +endif
296 +endif
297 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
298 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
299 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
300 +endif
301 +ifdef CONFIG_KALLOCSTAT_PLUGIN
302 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
303 +endif
304 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
305 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
306 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
307 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
308 +endif
309 +ifdef CONFIG_CHECKER_PLUGIN
310 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
311 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
312 +endif
313 +endif
314 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
315 +ifdef CONFIG_PAX_SIZE_OVERFLOW
316 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
317 +endif
318 +ifdef CONFIG_PAX_LATENT_ENTROPY
319 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
320 +endif
321 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
322 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
323 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
324 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
325 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
326 +ifeq ($(KBUILD_EXTMOD),)
327 +gcc-plugins:
328 + $(Q)$(MAKE) $(build)=tools/gcc
329 +else
330 +gcc-plugins: ;
331 +endif
332 +else
333 +gcc-plugins:
334 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
335 + $(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.))
336 +else
337 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
338 +endif
339 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
340 +endif
341 +endif
342 +
343 include $(srctree)/arch/$(SRCARCH)/Makefile
344
345 ifdef CONFIG_READABLE_ASM
346 @@ -731,7 +790,7 @@ export mod_sign_cmd
347
348
349 ifeq ($(KBUILD_EXTMOD),)
350 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
351 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
352
353 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
354 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
355 @@ -778,6 +837,8 @@ endif
356
357 # The actual objects are generated when descending,
358 # make sure no implicit rule kicks in
359 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
360 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
361 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
362
363 # Handle descending into subdirectories listed in $(vmlinux-dirs)
364 @@ -787,7 +848,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
365 # Error messages still appears in the original language
366
367 PHONY += $(vmlinux-dirs)
368 -$(vmlinux-dirs): prepare scripts
369 +$(vmlinux-dirs): gcc-plugins prepare scripts
370 $(Q)$(MAKE) $(build)=$@
371
372 # Store (new) KERNELRELASE string in include/config/kernel.release
373 @@ -831,6 +892,7 @@ prepare0: archprepare FORCE
374 $(Q)$(MAKE) $(build)=.
375
376 # All the preparing..
377 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
378 prepare: prepare0
379
380 # Generate some files
381 @@ -938,6 +1000,8 @@ all: modules
382 # using awk while concatenating to the final file.
383
384 PHONY += modules
385 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
386 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
387 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
388 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
389 @$(kecho) ' Building modules, stage 2.';
390 @@ -953,7 +1017,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
391
392 # Target to prepare building external modules
393 PHONY += modules_prepare
394 -modules_prepare: prepare scripts
395 +modules_prepare: gcc-plugins prepare scripts
396
397 # Target to install modules
398 PHONY += modules_install
399 @@ -1019,7 +1083,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
400 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
401 signing_key.priv signing_key.x509 x509.genkey \
402 extra_certificates signing_key.x509.keyid \
403 - signing_key.x509.signer
404 + signing_key.x509.signer tools/gcc/size_overflow_hash.h
405
406 # clean - Delete most, but leave enough to build external modules
407 #
408 @@ -1059,6 +1123,7 @@ distclean: mrproper
409 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
410 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
411 -o -name '.*.rej' \
412 + -o -name '.*.rej' -o -name '*.so' \
413 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
414 -type f -print | xargs rm -f
415
416 @@ -1219,6 +1284,8 @@ PHONY += $(module-dirs) modules
417 $(module-dirs): crmodverdir $(objtree)/Module.symvers
418 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
419
420 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
421 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
422 modules: $(module-dirs)
423 @$(kecho) ' Building modules, stage 2.';
424 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
425 @@ -1355,17 +1422,21 @@ else
426 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
427 endif
428
429 -%.s: %.c prepare scripts FORCE
430 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
431 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
432 +%.s: %.c gcc-plugins prepare scripts FORCE
433 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
434 %.i: %.c prepare scripts FORCE
435 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
436 -%.o: %.c prepare scripts FORCE
437 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
438 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
439 +%.o: %.c gcc-plugins prepare scripts FORCE
440 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
441 %.lst: %.c prepare scripts FORCE
442 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
443 -%.s: %.S prepare scripts FORCE
444 +%.s: %.S gcc-plugins prepare scripts FORCE
445 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
446 -%.o: %.S prepare scripts FORCE
447 +%.o: %.S gcc-plugins prepare scripts FORCE
448 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
449 %.symtypes: %.c prepare scripts FORCE
450 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
451 @@ -1375,11 +1446,15 @@ endif
452 $(cmd_crmodverdir)
453 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
454 $(build)=$(build-dir)
455 -%/: prepare scripts FORCE
456 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
457 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
458 +%/: gcc-plugins prepare scripts FORCE
459 $(cmd_crmodverdir)
460 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
461 $(build)=$(build-dir)
462 -%.ko: prepare scripts FORCE
463 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
464 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
465 +%.ko: gcc-plugins prepare scripts FORCE
466 $(cmd_crmodverdir)
467 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
468 $(build)=$(build-dir) $(@:.ko=.o)
469 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
470 index c2cbe4f..f7264b4 100644
471 --- a/arch/alpha/include/asm/atomic.h
472 +++ b/arch/alpha/include/asm/atomic.h
473 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
474 #define atomic_dec(v) atomic_sub(1,(v))
475 #define atomic64_dec(v) atomic64_sub(1,(v))
476
477 +#define atomic64_read_unchecked(v) atomic64_read(v)
478 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
479 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
480 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
481 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
482 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
483 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
484 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
485 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
486 +
487 #define smp_mb__before_atomic_dec() smp_mb()
488 #define smp_mb__after_atomic_dec() smp_mb()
489 #define smp_mb__before_atomic_inc() smp_mb()
490 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
491 index ad368a9..fbe0f25 100644
492 --- a/arch/alpha/include/asm/cache.h
493 +++ b/arch/alpha/include/asm/cache.h
494 @@ -4,19 +4,19 @@
495 #ifndef __ARCH_ALPHA_CACHE_H
496 #define __ARCH_ALPHA_CACHE_H
497
498 +#include <linux/const.h>
499
500 /* Bytes per L1 (data) cache line. */
501 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
502 -# define L1_CACHE_BYTES 64
503 # define L1_CACHE_SHIFT 6
504 #else
505 /* Both EV4 and EV5 are write-through, read-allocate,
506 direct-mapped, physical.
507 */
508 -# define L1_CACHE_BYTES 32
509 # define L1_CACHE_SHIFT 5
510 #endif
511
512 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
513 #define SMP_CACHE_BYTES L1_CACHE_BYTES
514
515 #endif
516 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
517 index 968d999..d36b2df 100644
518 --- a/arch/alpha/include/asm/elf.h
519 +++ b/arch/alpha/include/asm/elf.h
520 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
521
522 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
523
524 +#ifdef CONFIG_PAX_ASLR
525 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
526 +
527 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
528 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
529 +#endif
530 +
531 /* $0 is set by ld.so to a pointer to a function which might be
532 registered using atexit. This provides a mean for the dynamic
533 linker to call DT_FINI functions for shared libraries that have
534 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
535 index bc2a0da..8ad11ee 100644
536 --- a/arch/alpha/include/asm/pgalloc.h
537 +++ b/arch/alpha/include/asm/pgalloc.h
538 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
539 pgd_set(pgd, pmd);
540 }
541
542 +static inline void
543 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
544 +{
545 + pgd_populate(mm, pgd, pmd);
546 +}
547 +
548 extern pgd_t *pgd_alloc(struct mm_struct *mm);
549
550 static inline void
551 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
552 index 81a4342..348b927 100644
553 --- a/arch/alpha/include/asm/pgtable.h
554 +++ b/arch/alpha/include/asm/pgtable.h
555 @@ -102,6 +102,17 @@ struct vm_area_struct;
556 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
557 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
558 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
559 +
560 +#ifdef CONFIG_PAX_PAGEEXEC
561 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
562 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
563 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
564 +#else
565 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
566 +# define PAGE_COPY_NOEXEC PAGE_COPY
567 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
568 +#endif
569 +
570 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
571
572 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
573 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
574 index 2fd00b7..cfd5069 100644
575 --- a/arch/alpha/kernel/module.c
576 +++ b/arch/alpha/kernel/module.c
577 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
578
579 /* The small sections were sorted to the end of the segment.
580 The following should definitely cover them. */
581 - gp = (u64)me->module_core + me->core_size - 0x8000;
582 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
583 got = sechdrs[me->arch.gotsecindex].sh_addr;
584
585 for (i = 0; i < n; i++) {
586 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
587 index 14db93e..47bed62 100644
588 --- a/arch/alpha/kernel/osf_sys.c
589 +++ b/arch/alpha/kernel/osf_sys.c
590 @@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
591 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
592
593 static unsigned long
594 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
595 - unsigned long limit)
596 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
597 + unsigned long limit, unsigned long flags)
598 {
599 struct vm_area_struct *vma = find_vma(current->mm, addr);
600 -
601 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
602 while (1) {
603 /* At this point: (!vma || addr < vma->vm_end). */
604 if (limit - len < addr)
605 return -ENOMEM;
606 - if (!vma || addr + len <= vma->vm_start)
607 + if (check_heap_stack_gap(vma, addr, len, offset))
608 return addr;
609 addr = vma->vm_end;
610 vma = vma->vm_next;
611 @@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
612 merely specific addresses, but regions of memory -- perhaps
613 this feature should be incorporated into all ports? */
614
615 +#ifdef CONFIG_PAX_RANDMMAP
616 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
617 +#endif
618 +
619 if (addr) {
620 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
621 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
622 if (addr != (unsigned long) -ENOMEM)
623 return addr;
624 }
625
626 /* Next, try allocating at TASK_UNMAPPED_BASE. */
627 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
628 - len, limit);
629 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
630 +
631 if (addr != (unsigned long) -ENOMEM)
632 return addr;
633
634 /* Finally, try allocating in low memory. */
635 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
636 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
637
638 return addr;
639 }
640 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
641 index 0c4132d..88f0d53 100644
642 --- a/arch/alpha/mm/fault.c
643 +++ b/arch/alpha/mm/fault.c
644 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
645 __reload_thread(pcb);
646 }
647
648 +#ifdef CONFIG_PAX_PAGEEXEC
649 +/*
650 + * PaX: decide what to do with offenders (regs->pc = fault address)
651 + *
652 + * returns 1 when task should be killed
653 + * 2 when patched PLT trampoline was detected
654 + * 3 when unpatched PLT trampoline was detected
655 + */
656 +static int pax_handle_fetch_fault(struct pt_regs *regs)
657 +{
658 +
659 +#ifdef CONFIG_PAX_EMUPLT
660 + int err;
661 +
662 + do { /* PaX: patched PLT emulation #1 */
663 + unsigned int ldah, ldq, jmp;
664 +
665 + err = get_user(ldah, (unsigned int *)regs->pc);
666 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
667 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
668 +
669 + if (err)
670 + break;
671 +
672 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
673 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
674 + jmp == 0x6BFB0000U)
675 + {
676 + unsigned long r27, addr;
677 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
678 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
679 +
680 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
681 + err = get_user(r27, (unsigned long *)addr);
682 + if (err)
683 + break;
684 +
685 + regs->r27 = r27;
686 + regs->pc = r27;
687 + return 2;
688 + }
689 + } while (0);
690 +
691 + do { /* PaX: patched PLT emulation #2 */
692 + unsigned int ldah, lda, br;
693 +
694 + err = get_user(ldah, (unsigned int *)regs->pc);
695 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
696 + err |= get_user(br, (unsigned int *)(regs->pc+8));
697 +
698 + if (err)
699 + break;
700 +
701 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
702 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
703 + (br & 0xFFE00000U) == 0xC3E00000U)
704 + {
705 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
706 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
707 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
708 +
709 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
710 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
711 + return 2;
712 + }
713 + } while (0);
714 +
715 + do { /* PaX: unpatched PLT emulation */
716 + unsigned int br;
717 +
718 + err = get_user(br, (unsigned int *)regs->pc);
719 +
720 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
721 + unsigned int br2, ldq, nop, jmp;
722 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
723 +
724 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
725 + err = get_user(br2, (unsigned int *)addr);
726 + err |= get_user(ldq, (unsigned int *)(addr+4));
727 + err |= get_user(nop, (unsigned int *)(addr+8));
728 + err |= get_user(jmp, (unsigned int *)(addr+12));
729 + err |= get_user(resolver, (unsigned long *)(addr+16));
730 +
731 + if (err)
732 + break;
733 +
734 + if (br2 == 0xC3600000U &&
735 + ldq == 0xA77B000CU &&
736 + nop == 0x47FF041FU &&
737 + jmp == 0x6B7B0000U)
738 + {
739 + regs->r28 = regs->pc+4;
740 + regs->r27 = addr+16;
741 + regs->pc = resolver;
742 + return 3;
743 + }
744 + }
745 + } while (0);
746 +#endif
747 +
748 + return 1;
749 +}
750 +
751 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
752 +{
753 + unsigned long i;
754 +
755 + printk(KERN_ERR "PAX: bytes at PC: ");
756 + for (i = 0; i < 5; i++) {
757 + unsigned int c;
758 + if (get_user(c, (unsigned int *)pc+i))
759 + printk(KERN_CONT "???????? ");
760 + else
761 + printk(KERN_CONT "%08x ", c);
762 + }
763 + printk("\n");
764 +}
765 +#endif
766
767 /*
768 * This routine handles page faults. It determines the address,
769 @@ -133,8 +251,29 @@ retry:
770 good_area:
771 si_code = SEGV_ACCERR;
772 if (cause < 0) {
773 - if (!(vma->vm_flags & VM_EXEC))
774 + if (!(vma->vm_flags & VM_EXEC)) {
775 +
776 +#ifdef CONFIG_PAX_PAGEEXEC
777 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
778 + goto bad_area;
779 +
780 + up_read(&mm->mmap_sem);
781 + switch (pax_handle_fetch_fault(regs)) {
782 +
783 +#ifdef CONFIG_PAX_EMUPLT
784 + case 2:
785 + case 3:
786 + return;
787 +#endif
788 +
789 + }
790 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
791 + do_group_exit(SIGKILL);
792 +#else
793 goto bad_area;
794 +#endif
795 +
796 + }
797 } else if (!cause) {
798 /* Allow reads even for write-only mappings */
799 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
800 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
801 index 67874b8..0e40765 100644
802 --- a/arch/arm/Kconfig
803 +++ b/arch/arm/Kconfig
804 @@ -1813,7 +1813,7 @@ config ALIGNMENT_TRAP
805
806 config UACCESS_WITH_MEMCPY
807 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
808 - depends on MMU
809 + depends on MMU && !PAX_MEMORY_UDEREF
810 default y if CPU_FEROCEON
811 help
812 Implement faster copy_to_user and clear_user methods for CPU
813 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
814 index c79f61f..9ac0642 100644
815 --- a/arch/arm/include/asm/atomic.h
816 +++ b/arch/arm/include/asm/atomic.h
817 @@ -17,17 +17,35 @@
818 #include <asm/barrier.h>
819 #include <asm/cmpxchg.h>
820
821 +#ifdef CONFIG_GENERIC_ATOMIC64
822 +#include <asm-generic/atomic64.h>
823 +#endif
824 +
825 #define ATOMIC_INIT(i) { (i) }
826
827 #ifdef __KERNEL__
828
829 +#define _ASM_EXTABLE(from, to) \
830 +" .pushsection __ex_table,\"a\"\n"\
831 +" .align 3\n" \
832 +" .long " #from ", " #to"\n" \
833 +" .popsection"
834 +
835 /*
836 * On ARM, ordinary assignment (str instruction) doesn't clear the local
837 * strex/ldrex monitor on some implementations. The reason we can use it for
838 * atomic_set() is the clrex or dummy strex done on every exception return.
839 */
840 #define atomic_read(v) (*(volatile int *)&(v)->counter)
841 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
842 +{
843 + return v->counter;
844 +}
845 #define atomic_set(v,i) (((v)->counter) = (i))
846 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
847 +{
848 + v->counter = i;
849 +}
850
851 #if __LINUX_ARM_ARCH__ >= 6
852
853 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
854 int result;
855
856 __asm__ __volatile__("@ atomic_add\n"
857 +"1: ldrex %1, [%3]\n"
858 +" adds %0, %1, %4\n"
859 +
860 +#ifdef CONFIG_PAX_REFCOUNT
861 +" bvc 3f\n"
862 +"2: bkpt 0xf103\n"
863 +"3:\n"
864 +#endif
865 +
866 +" strex %1, %0, [%3]\n"
867 +" teq %1, #0\n"
868 +" bne 1b"
869 +
870 +#ifdef CONFIG_PAX_REFCOUNT
871 +"\n4:\n"
872 + _ASM_EXTABLE(2b, 4b)
873 +#endif
874 +
875 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
876 + : "r" (&v->counter), "Ir" (i)
877 + : "cc");
878 +}
879 +
880 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
881 +{
882 + unsigned long tmp;
883 + int result;
884 +
885 + __asm__ __volatile__("@ atomic_add_unchecked\n"
886 "1: ldrex %0, [%3]\n"
887 " add %0, %0, %4\n"
888 " strex %1, %0, [%3]\n"
889 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
890 smp_mb();
891
892 __asm__ __volatile__("@ atomic_add_return\n"
893 +"1: ldrex %1, [%3]\n"
894 +" adds %0, %1, %4\n"
895 +
896 +#ifdef CONFIG_PAX_REFCOUNT
897 +" bvc 3f\n"
898 +" mov %0, %1\n"
899 +"2: bkpt 0xf103\n"
900 +"3:\n"
901 +#endif
902 +
903 +" strex %1, %0, [%3]\n"
904 +" teq %1, #0\n"
905 +" bne 1b"
906 +
907 +#ifdef CONFIG_PAX_REFCOUNT
908 +"\n4:\n"
909 + _ASM_EXTABLE(2b, 4b)
910 +#endif
911 +
912 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
913 + : "r" (&v->counter), "Ir" (i)
914 + : "cc");
915 +
916 + smp_mb();
917 +
918 + return result;
919 +}
920 +
921 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
922 +{
923 + unsigned long tmp;
924 + int result;
925 +
926 + smp_mb();
927 +
928 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
929 "1: ldrex %0, [%3]\n"
930 " add %0, %0, %4\n"
931 " strex %1, %0, [%3]\n"
932 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
933 int result;
934
935 __asm__ __volatile__("@ atomic_sub\n"
936 +"1: ldrex %1, [%3]\n"
937 +" subs %0, %1, %4\n"
938 +
939 +#ifdef CONFIG_PAX_REFCOUNT
940 +" bvc 3f\n"
941 +"2: bkpt 0xf103\n"
942 +"3:\n"
943 +#endif
944 +
945 +" strex %1, %0, [%3]\n"
946 +" teq %1, #0\n"
947 +" bne 1b"
948 +
949 +#ifdef CONFIG_PAX_REFCOUNT
950 +"\n4:\n"
951 + _ASM_EXTABLE(2b, 4b)
952 +#endif
953 +
954 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
955 + : "r" (&v->counter), "Ir" (i)
956 + : "cc");
957 +}
958 +
959 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
960 +{
961 + unsigned long tmp;
962 + int result;
963 +
964 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
965 "1: ldrex %0, [%3]\n"
966 " sub %0, %0, %4\n"
967 " strex %1, %0, [%3]\n"
968 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
969 smp_mb();
970
971 __asm__ __volatile__("@ atomic_sub_return\n"
972 -"1: ldrex %0, [%3]\n"
973 -" sub %0, %0, %4\n"
974 +"1: ldrex %1, [%3]\n"
975 +" subs %0, %1, %4\n"
976 +
977 +#ifdef CONFIG_PAX_REFCOUNT
978 +" bvc 3f\n"
979 +" mov %0, %1\n"
980 +"2: bkpt 0xf103\n"
981 +"3:\n"
982 +#endif
983 +
984 " strex %1, %0, [%3]\n"
985 " teq %1, #0\n"
986 " bne 1b"
987 +
988 +#ifdef CONFIG_PAX_REFCOUNT
989 +"\n4:\n"
990 + _ASM_EXTABLE(2b, 4b)
991 +#endif
992 +
993 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
994 : "r" (&v->counter), "Ir" (i)
995 : "cc");
996 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
997 return oldval;
998 }
999
1000 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1001 +{
1002 + unsigned long oldval, res;
1003 +
1004 + smp_mb();
1005 +
1006 + do {
1007 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1008 + "ldrex %1, [%3]\n"
1009 + "mov %0, #0\n"
1010 + "teq %1, %4\n"
1011 + "strexeq %0, %5, [%3]\n"
1012 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1013 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1014 + : "cc");
1015 + } while (res);
1016 +
1017 + smp_mb();
1018 +
1019 + return oldval;
1020 +}
1021 +
1022 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1023 {
1024 unsigned long tmp, tmp2;
1025 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1026
1027 return val;
1028 }
1029 +
1030 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1031 +{
1032 + return atomic_add_return(i, v);
1033 +}
1034 +
1035 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1036 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1037 +{
1038 + (void) atomic_add_return(i, v);
1039 +}
1040
1041 static inline int atomic_sub_return(int i, atomic_t *v)
1042 {
1043 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1044 return val;
1045 }
1046 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1047 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1048 +{
1049 + (void) atomic_sub_return(i, v);
1050 +}
1051
1052 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1053 {
1054 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1055 return ret;
1056 }
1057
1058 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1059 +{
1060 + return atomic_cmpxchg(v, old, new);
1061 +}
1062 +
1063 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 {
1065 unsigned long flags;
1066 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1067 #endif /* __LINUX_ARM_ARCH__ */
1068
1069 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1070 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1071 +{
1072 + return xchg(&v->counter, new);
1073 +}
1074
1075 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1076 {
1077 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1078 }
1079
1080 #define atomic_inc(v) atomic_add(1, v)
1081 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1082 +{
1083 + atomic_add_unchecked(1, v);
1084 +}
1085 #define atomic_dec(v) atomic_sub(1, v)
1086 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1087 +{
1088 + atomic_sub_unchecked(1, v);
1089 +}
1090
1091 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1092 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1093 +{
1094 + return atomic_add_return_unchecked(1, v) == 0;
1095 +}
1096 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1097 #define atomic_inc_return(v) (atomic_add_return(1, v))
1098 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1099 +{
1100 + return atomic_add_return_unchecked(1, v);
1101 +}
1102 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1103 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1104
1105 @@ -241,6 +428,14 @@ typedef struct {
1106 u64 __aligned(8) counter;
1107 } atomic64_t;
1108
1109 +#ifdef CONFIG_PAX_REFCOUNT
1110 +typedef struct {
1111 + u64 __aligned(8) counter;
1112 +} atomic64_unchecked_t;
1113 +#else
1114 +typedef atomic64_t atomic64_unchecked_t;
1115 +#endif
1116 +
1117 #define ATOMIC64_INIT(i) { (i) }
1118
1119 static inline u64 atomic64_read(const atomic64_t *v)
1120 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1121 return result;
1122 }
1123
1124 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1125 +{
1126 + u64 result;
1127 +
1128 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1129 +" ldrexd %0, %H0, [%1]"
1130 + : "=&r" (result)
1131 + : "r" (&v->counter), "Qo" (v->counter)
1132 + );
1133 +
1134 + return result;
1135 +}
1136 +
1137 static inline void atomic64_set(atomic64_t *v, u64 i)
1138 {
1139 u64 tmp;
1140 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1141 : "cc");
1142 }
1143
1144 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1145 +{
1146 + u64 tmp;
1147 +
1148 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1149 +"1: ldrexd %0, %H0, [%2]\n"
1150 +" strexd %0, %3, %H3, [%2]\n"
1151 +" teq %0, #0\n"
1152 +" bne 1b"
1153 + : "=&r" (tmp), "=Qo" (v->counter)
1154 + : "r" (&v->counter), "r" (i)
1155 + : "cc");
1156 +}
1157 +
1158 static inline void atomic64_add(u64 i, atomic64_t *v)
1159 {
1160 u64 result;
1161 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1162 __asm__ __volatile__("@ atomic64_add\n"
1163 "1: ldrexd %0, %H0, [%3]\n"
1164 " adds %0, %0, %4\n"
1165 +" adcs %H0, %H0, %H4\n"
1166 +
1167 +#ifdef CONFIG_PAX_REFCOUNT
1168 +" bvc 3f\n"
1169 +"2: bkpt 0xf103\n"
1170 +"3:\n"
1171 +#endif
1172 +
1173 +" strexd %1, %0, %H0, [%3]\n"
1174 +" teq %1, #0\n"
1175 +" bne 1b"
1176 +
1177 +#ifdef CONFIG_PAX_REFCOUNT
1178 +"\n4:\n"
1179 + _ASM_EXTABLE(2b, 4b)
1180 +#endif
1181 +
1182 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1183 + : "r" (&v->counter), "r" (i)
1184 + : "cc");
1185 +}
1186 +
1187 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1188 +{
1189 + u64 result;
1190 + unsigned long tmp;
1191 +
1192 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1193 +"1: ldrexd %0, %H0, [%3]\n"
1194 +" adds %0, %0, %4\n"
1195 " adc %H0, %H0, %H4\n"
1196 " strexd %1, %0, %H0, [%3]\n"
1197 " teq %1, #0\n"
1198 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1199
1200 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1201 {
1202 - u64 result;
1203 - unsigned long tmp;
1204 + u64 result, tmp;
1205
1206 smp_mb();
1207
1208 __asm__ __volatile__("@ atomic64_add_return\n"
1209 +"1: ldrexd %1, %H1, [%3]\n"
1210 +" adds %0, %1, %4\n"
1211 +" adcs %H0, %H1, %H4\n"
1212 +
1213 +#ifdef CONFIG_PAX_REFCOUNT
1214 +" bvc 3f\n"
1215 +" mov %0, %1\n"
1216 +" mov %H0, %H1\n"
1217 +"2: bkpt 0xf103\n"
1218 +"3:\n"
1219 +#endif
1220 +
1221 +" strexd %1, %0, %H0, [%3]\n"
1222 +" teq %1, #0\n"
1223 +" bne 1b"
1224 +
1225 +#ifdef CONFIG_PAX_REFCOUNT
1226 +"\n4:\n"
1227 + _ASM_EXTABLE(2b, 4b)
1228 +#endif
1229 +
1230 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1231 + : "r" (&v->counter), "r" (i)
1232 + : "cc");
1233 +
1234 + smp_mb();
1235 +
1236 + return result;
1237 +}
1238 +
1239 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1240 +{
1241 + u64 result;
1242 + unsigned long tmp;
1243 +
1244 + smp_mb();
1245 +
1246 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1247 "1: ldrexd %0, %H0, [%3]\n"
1248 " adds %0, %0, %4\n"
1249 " adc %H0, %H0, %H4\n"
1250 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1251 __asm__ __volatile__("@ atomic64_sub\n"
1252 "1: ldrexd %0, %H0, [%3]\n"
1253 " subs %0, %0, %4\n"
1254 +" sbcs %H0, %H0, %H4\n"
1255 +
1256 +#ifdef CONFIG_PAX_REFCOUNT
1257 +" bvc 3f\n"
1258 +"2: bkpt 0xf103\n"
1259 +"3:\n"
1260 +#endif
1261 +
1262 +" strexd %1, %0, %H0, [%3]\n"
1263 +" teq %1, #0\n"
1264 +" bne 1b"
1265 +
1266 +#ifdef CONFIG_PAX_REFCOUNT
1267 +"\n4:\n"
1268 + _ASM_EXTABLE(2b, 4b)
1269 +#endif
1270 +
1271 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1272 + : "r" (&v->counter), "r" (i)
1273 + : "cc");
1274 +}
1275 +
1276 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1277 +{
1278 + u64 result;
1279 + unsigned long tmp;
1280 +
1281 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1282 +"1: ldrexd %0, %H0, [%3]\n"
1283 +" subs %0, %0, %4\n"
1284 " sbc %H0, %H0, %H4\n"
1285 " strexd %1, %0, %H0, [%3]\n"
1286 " teq %1, #0\n"
1287 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1288
1289 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1290 {
1291 - u64 result;
1292 - unsigned long tmp;
1293 + u64 result, tmp;
1294
1295 smp_mb();
1296
1297 __asm__ __volatile__("@ atomic64_sub_return\n"
1298 -"1: ldrexd %0, %H0, [%3]\n"
1299 -" subs %0, %0, %4\n"
1300 -" sbc %H0, %H0, %H4\n"
1301 +"1: ldrexd %1, %H1, [%3]\n"
1302 +" subs %0, %1, %4\n"
1303 +" sbcs %H0, %H1, %H4\n"
1304 +
1305 +#ifdef CONFIG_PAX_REFCOUNT
1306 +" bvc 3f\n"
1307 +" mov %0, %1\n"
1308 +" mov %H0, %H1\n"
1309 +"2: bkpt 0xf103\n"
1310 +"3:\n"
1311 +#endif
1312 +
1313 " strexd %1, %0, %H0, [%3]\n"
1314 " teq %1, #0\n"
1315 " bne 1b"
1316 +
1317 +#ifdef CONFIG_PAX_REFCOUNT
1318 +"\n4:\n"
1319 + _ASM_EXTABLE(2b, 4b)
1320 +#endif
1321 +
1322 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1323 : "r" (&v->counter), "r" (i)
1324 : "cc");
1325 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1326 return oldval;
1327 }
1328
1329 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1330 +{
1331 + u64 oldval;
1332 + unsigned long res;
1333 +
1334 + smp_mb();
1335 +
1336 + do {
1337 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1338 + "ldrexd %1, %H1, [%3]\n"
1339 + "mov %0, #0\n"
1340 + "teq %1, %4\n"
1341 + "teqeq %H1, %H4\n"
1342 + "strexdeq %0, %5, %H5, [%3]"
1343 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1344 + : "r" (&ptr->counter), "r" (old), "r" (new)
1345 + : "cc");
1346 + } while (res);
1347 +
1348 + smp_mb();
1349 +
1350 + return oldval;
1351 +}
1352 +
1353 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354 {
1355 u64 result;
1356 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1357
1358 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1359 {
1360 - u64 result;
1361 - unsigned long tmp;
1362 + u64 result, tmp;
1363
1364 smp_mb();
1365
1366 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1367 -"1: ldrexd %0, %H0, [%3]\n"
1368 -" subs %0, %0, #1\n"
1369 -" sbc %H0, %H0, #0\n"
1370 +"1: ldrexd %1, %H1, [%3]\n"
1371 +" subs %0, %1, #1\n"
1372 +" sbcs %H0, %H1, #0\n"
1373 +
1374 +#ifdef CONFIG_PAX_REFCOUNT
1375 +" bvc 3f\n"
1376 +" mov %0, %1\n"
1377 +" mov %H0, %H1\n"
1378 +"2: bkpt 0xf103\n"
1379 +"3:\n"
1380 +#endif
1381 +
1382 " teq %H0, #0\n"
1383 -" bmi 2f\n"
1384 +" bmi 4f\n"
1385 " strexd %1, %0, %H0, [%3]\n"
1386 " teq %1, #0\n"
1387 " bne 1b\n"
1388 -"2:"
1389 +"4:\n"
1390 +
1391 +#ifdef CONFIG_PAX_REFCOUNT
1392 + _ASM_EXTABLE(2b, 4b)
1393 +#endif
1394 +
1395 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1396 : "r" (&v->counter)
1397 : "cc");
1398 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1399 " teq %0, %5\n"
1400 " teqeq %H0, %H5\n"
1401 " moveq %1, #0\n"
1402 -" beq 2f\n"
1403 +" beq 4f\n"
1404 " adds %0, %0, %6\n"
1405 -" adc %H0, %H0, %H6\n"
1406 +" adcs %H0, %H0, %H6\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +"2: bkpt 0xf103\n"
1411 +"3:\n"
1412 +#endif
1413 +
1414 " strexd %2, %0, %H0, [%4]\n"
1415 " teq %2, #0\n"
1416 " bne 1b\n"
1417 -"2:"
1418 +"4:\n"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 + _ASM_EXTABLE(2b, 4b)
1422 +#endif
1423 +
1424 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1425 : "r" (&v->counter), "r" (u), "r" (a)
1426 : "cc");
1427 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1428
1429 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1430 #define atomic64_inc(v) atomic64_add(1LL, (v))
1431 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1432 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1433 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1434 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1435 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1436 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1437 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1438 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1439 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1440 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1441 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1442 index 75fe66b..ba3dee4 100644
1443 --- a/arch/arm/include/asm/cache.h
1444 +++ b/arch/arm/include/asm/cache.h
1445 @@ -4,8 +4,10 @@
1446 #ifndef __ASMARM_CACHE_H
1447 #define __ASMARM_CACHE_H
1448
1449 +#include <linux/const.h>
1450 +
1451 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1452 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1453 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1454
1455 /*
1456 * Memory returned by kmalloc() may be used for DMA, so we must make
1457 @@ -24,5 +26,6 @@
1458 #endif
1459
1460 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1461 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1462
1463 #endif
1464 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1465 index e1489c5..d418304 100644
1466 --- a/arch/arm/include/asm/cacheflush.h
1467 +++ b/arch/arm/include/asm/cacheflush.h
1468 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1469 void (*dma_unmap_area)(const void *, size_t, int);
1470
1471 void (*dma_flush_range)(const void *, const void *);
1472 -};
1473 +} __no_const;
1474
1475 /*
1476 * Select the calling method
1477 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1478 index 6dcc164..b14d917 100644
1479 --- a/arch/arm/include/asm/checksum.h
1480 +++ b/arch/arm/include/asm/checksum.h
1481 @@ -37,7 +37,19 @@ __wsum
1482 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1483
1484 __wsum
1485 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1486 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1487 +
1488 +static inline __wsum
1489 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1490 +{
1491 + __wsum ret;
1492 + pax_open_userland();
1493 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1494 + pax_close_userland();
1495 + return ret;
1496 +}
1497 +
1498 +
1499
1500 /*
1501 * Fold a partial checksum without adding pseudo headers
1502 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1503 index 7eb18c1..e38b6d2 100644
1504 --- a/arch/arm/include/asm/cmpxchg.h
1505 +++ b/arch/arm/include/asm/cmpxchg.h
1506 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1507
1508 #define xchg(ptr,x) \
1509 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1510 +#define xchg_unchecked(ptr,x) \
1511 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1512
1513 #include <asm-generic/cmpxchg-local.h>
1514
1515 diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1516 index ab98fdd..6b19938 100644
1517 --- a/arch/arm/include/asm/delay.h
1518 +++ b/arch/arm/include/asm/delay.h
1519 @@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1520 void (*delay)(unsigned long);
1521 void (*const_udelay)(unsigned long);
1522 void (*udelay)(unsigned long);
1523 -} arm_delay_ops;
1524 +} *arm_delay_ops;
1525
1526 -#define __delay(n) arm_delay_ops.delay(n)
1527 +#define __delay(n) arm_delay_ops->delay(n)
1528
1529 /*
1530 * This function intentionally does not exist; if you see references to
1531 @@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1532 * first constant multiplications gets optimized away if the delay is
1533 * a constant)
1534 */
1535 -#define __udelay(n) arm_delay_ops.udelay(n)
1536 -#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1537 +#define __udelay(n) arm_delay_ops->udelay(n)
1538 +#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1539
1540 #define udelay(n) \
1541 (__builtin_constant_p(n) ? \
1542 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1543 index 6ddbe44..758b5f2 100644
1544 --- a/arch/arm/include/asm/domain.h
1545 +++ b/arch/arm/include/asm/domain.h
1546 @@ -48,18 +48,37 @@
1547 * Domain types
1548 */
1549 #define DOMAIN_NOACCESS 0
1550 -#define DOMAIN_CLIENT 1
1551 #ifdef CONFIG_CPU_USE_DOMAINS
1552 +#define DOMAIN_USERCLIENT 1
1553 +#define DOMAIN_KERNELCLIENT 1
1554 #define DOMAIN_MANAGER 3
1555 +#define DOMAIN_VECTORS DOMAIN_USER
1556 #else
1557 +
1558 +#ifdef CONFIG_PAX_KERNEXEC
1559 #define DOMAIN_MANAGER 1
1560 +#define DOMAIN_KERNEXEC 3
1561 +#else
1562 +#define DOMAIN_MANAGER 1
1563 +#endif
1564 +
1565 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1566 +#define DOMAIN_USERCLIENT 0
1567 +#define DOMAIN_UDEREF 1
1568 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1569 +#else
1570 +#define DOMAIN_USERCLIENT 1
1571 +#define DOMAIN_VECTORS DOMAIN_USER
1572 +#endif
1573 +#define DOMAIN_KERNELCLIENT 1
1574 +
1575 #endif
1576
1577 #define domain_val(dom,type) ((type) << (2*(dom)))
1578
1579 #ifndef __ASSEMBLY__
1580
1581 -#ifdef CONFIG_CPU_USE_DOMAINS
1582 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1583 static inline void set_domain(unsigned val)
1584 {
1585 asm volatile(
1586 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1587 isb();
1588 }
1589
1590 -#define modify_domain(dom,type) \
1591 - do { \
1592 - struct thread_info *thread = current_thread_info(); \
1593 - unsigned int domain = thread->cpu_domain; \
1594 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1595 - thread->cpu_domain = domain | domain_val(dom, type); \
1596 - set_domain(thread->cpu_domain); \
1597 - } while (0)
1598 -
1599 +extern void modify_domain(unsigned int dom, unsigned int type);
1600 #else
1601 static inline void set_domain(unsigned val) { }
1602 static inline void modify_domain(unsigned dom, unsigned type) { }
1603 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1604 index 38050b1..9d90e8b 100644
1605 --- a/arch/arm/include/asm/elf.h
1606 +++ b/arch/arm/include/asm/elf.h
1607 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1608 the loader. We need to make sure that it is out of the way of the program
1609 that it will "exec", and that there is sufficient room for the brk. */
1610
1611 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1612 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1613 +
1614 +#ifdef CONFIG_PAX_ASLR
1615 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1616 +
1617 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1618 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1619 +#endif
1620
1621 /* When the program starts, a1 contains a pointer to a function to be
1622 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1623 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1624 extern void elf_set_personality(const struct elf32_hdr *);
1625 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1626
1627 -struct mm_struct;
1628 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1629 -#define arch_randomize_brk arch_randomize_brk
1630 -
1631 #endif
1632 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1633 index de53547..52b9a28 100644
1634 --- a/arch/arm/include/asm/fncpy.h
1635 +++ b/arch/arm/include/asm/fncpy.h
1636 @@ -81,7 +81,9 @@
1637 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1638 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1639 \
1640 + pax_open_kernel(); \
1641 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1642 + pax_close_kernel(); \
1643 flush_icache_range((unsigned long)(dest_buf), \
1644 (unsigned long)(dest_buf) + (size)); \
1645 \
1646 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1647 index e42cf59..7b94b8f 100644
1648 --- a/arch/arm/include/asm/futex.h
1649 +++ b/arch/arm/include/asm/futex.h
1650 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1651 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1652 return -EFAULT;
1653
1654 + pax_open_userland();
1655 +
1656 smp_mb();
1657 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1658 "1: ldrex %1, [%4]\n"
1659 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1660 : "cc", "memory");
1661 smp_mb();
1662
1663 + pax_close_userland();
1664 +
1665 *uval = val;
1666 return ret;
1667 }
1668 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1669 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1670 return -EFAULT;
1671
1672 + pax_open_userland();
1673 +
1674 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1675 "1: " TUSER(ldr) " %1, [%4]\n"
1676 " teq %1, %2\n"
1677 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1678 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1679 : "cc", "memory");
1680
1681 + pax_close_userland();
1682 +
1683 *uval = val;
1684 return ret;
1685 }
1686 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1687 return -EFAULT;
1688
1689 pagefault_disable(); /* implies preempt_disable() */
1690 + pax_open_userland();
1691
1692 switch (op) {
1693 case FUTEX_OP_SET:
1694 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1695 ret = -ENOSYS;
1696 }
1697
1698 + pax_close_userland();
1699 pagefault_enable(); /* subsumes preempt_enable() */
1700
1701 if (!ret) {
1702 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1703 index 83eb2f7..ed77159 100644
1704 --- a/arch/arm/include/asm/kmap_types.h
1705 +++ b/arch/arm/include/asm/kmap_types.h
1706 @@ -4,6 +4,6 @@
1707 /*
1708 * This is the "bare minimum". AIO seems to require this.
1709 */
1710 -#define KM_TYPE_NR 16
1711 +#define KM_TYPE_NR 17
1712
1713 #endif
1714 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1715 index 9e614a1..3302cca 100644
1716 --- a/arch/arm/include/asm/mach/dma.h
1717 +++ b/arch/arm/include/asm/mach/dma.h
1718 @@ -22,7 +22,7 @@ struct dma_ops {
1719 int (*residue)(unsigned int, dma_t *); /* optional */
1720 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1721 const char *type;
1722 -};
1723 +} __do_const;
1724
1725 struct dma_struct {
1726 void *addr; /* single DMA address */
1727 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1728 index 2fe141f..192dc01 100644
1729 --- a/arch/arm/include/asm/mach/map.h
1730 +++ b/arch/arm/include/asm/mach/map.h
1731 @@ -27,13 +27,16 @@ struct map_desc {
1732 #define MT_MINICLEAN 6
1733 #define MT_LOW_VECTORS 7
1734 #define MT_HIGH_VECTORS 8
1735 -#define MT_MEMORY 9
1736 +#define MT_MEMORY_RWX 9
1737 #define MT_ROM 10
1738 -#define MT_MEMORY_NONCACHED 11
1739 +#define MT_MEMORY_NONCACHED_RX 11
1740 #define MT_MEMORY_DTCM 12
1741 #define MT_MEMORY_ITCM 13
1742 #define MT_MEMORY_SO 14
1743 #define MT_MEMORY_DMA_READY 15
1744 +#define MT_MEMORY_RW 16
1745 +#define MT_MEMORY_RX 17
1746 +#define MT_MEMORY_NONCACHED_RW 18
1747
1748 #ifdef CONFIG_MMU
1749 extern void iotable_init(struct map_desc *, int);
1750 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1751 index 53426c6..c7baff3 100644
1752 --- a/arch/arm/include/asm/outercache.h
1753 +++ b/arch/arm/include/asm/outercache.h
1754 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1755 #endif
1756 void (*set_debug)(unsigned long);
1757 void (*resume)(void);
1758 -};
1759 +} __no_const;
1760
1761 #ifdef CONFIG_OUTER_CACHE
1762
1763 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1764 index 812a494..71fc0b6 100644
1765 --- a/arch/arm/include/asm/page.h
1766 +++ b/arch/arm/include/asm/page.h
1767 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1768 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1769 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1770 unsigned long vaddr, struct vm_area_struct *vma);
1771 -};
1772 +} __no_const;
1773
1774 #ifdef MULTI_USER
1775 extern struct cpu_user_fns cpu_user;
1776 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1777 index 943504f..c37a730 100644
1778 --- a/arch/arm/include/asm/pgalloc.h
1779 +++ b/arch/arm/include/asm/pgalloc.h
1780 @@ -17,6 +17,7 @@
1781 #include <asm/processor.h>
1782 #include <asm/cacheflush.h>
1783 #include <asm/tlbflush.h>
1784 +#include <asm/system_info.h>
1785
1786 #define check_pgt_cache() do { } while (0)
1787
1788 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1789 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1790 }
1791
1792 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1793 +{
1794 + pud_populate(mm, pud, pmd);
1795 +}
1796 +
1797 #else /* !CONFIG_ARM_LPAE */
1798
1799 /*
1800 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1801 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1802 #define pmd_free(mm, pmd) do { } while (0)
1803 #define pud_populate(mm,pmd,pte) BUG()
1804 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1805
1806 #endif /* CONFIG_ARM_LPAE */
1807
1808 @@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1809 __free_page(pte);
1810 }
1811
1812 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1813 +{
1814 +#ifdef CONFIG_ARM_LPAE
1815 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1816 +#else
1817 + if (addr & SECTION_SIZE)
1818 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1819 + else
1820 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1821 +#endif
1822 + flush_pmd_entry(pmdp);
1823 +}
1824 +
1825 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1826 pmdval_t prot)
1827 {
1828 @@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1829 static inline void
1830 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1831 {
1832 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1833 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1834 }
1835 #define pmd_pgtable(pmd) pmd_page(pmd)
1836
1837 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1838 index 5cfba15..f415e1a 100644
1839 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1840 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1841 @@ -20,12 +20,15 @@
1842 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1843 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1844 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1845 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1846 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1847 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1848 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1849 +
1850 /*
1851 * - section
1852 */
1853 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1854 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1855 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1856 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1857 @@ -37,6 +40,7 @@
1858 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1859 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1860 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1861 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1862
1863 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1864 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1865 @@ -66,6 +70,7 @@
1866 * - extended small page/tiny page
1867 */
1868 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1869 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1870 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1871 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1872 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1873 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1874 index f97ee02..07f1be5 100644
1875 --- a/arch/arm/include/asm/pgtable-2level.h
1876 +++ b/arch/arm/include/asm/pgtable-2level.h
1877 @@ -125,6 +125,7 @@
1878 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1879 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1880 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1881 +#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1882
1883 /*
1884 * These are the memory types, defined to be compatible with
1885 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1886 index d795282..a43ea90 100644
1887 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1888 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1889 @@ -32,15 +32,18 @@
1890 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1891 #define PMD_BIT4 (_AT(pmdval_t, 0))
1892 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1893 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1894
1895 /*
1896 * - section
1897 */
1898 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1899 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1900 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1901 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1902 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1903 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1904 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1905 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1906 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1907 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1908 @@ -66,6 +69,7 @@
1909 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1910 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1911 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1912 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1913 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1914
1915 /*
1916 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1917 index a3f3792..7b932a6 100644
1918 --- a/arch/arm/include/asm/pgtable-3level.h
1919 +++ b/arch/arm/include/asm/pgtable-3level.h
1920 @@ -74,6 +74,7 @@
1921 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1922 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1923 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1924 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1925 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1926 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1927 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1928 @@ -82,6 +83,7 @@
1929 /*
1930 * To be used in assembly code with the upper page attributes.
1931 */
1932 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
1933 #define L_PTE_XN_HIGH (1 << (54 - 32))
1934 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1935
1936 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1937 index 9c82f988..514705a 100644
1938 --- a/arch/arm/include/asm/pgtable.h
1939 +++ b/arch/arm/include/asm/pgtable.h
1940 @@ -30,6 +30,9 @@
1941 #include <asm/pgtable-2level.h>
1942 #endif
1943
1944 +#define ktla_ktva(addr) (addr)
1945 +#define ktva_ktla(addr) (addr)
1946 +
1947 /*
1948 * Just any arbitrary offset to the start of the vmalloc VM area: the
1949 * current 8MB value just means that there will be a 8MB "hole" after the
1950 @@ -45,6 +48,9 @@
1951 #define LIBRARY_TEXT_START 0x0c000000
1952
1953 #ifndef __ASSEMBLY__
1954 +extern pteval_t __supported_pte_mask;
1955 +extern pmdval_t __supported_pmd_mask;
1956 +
1957 extern void __pte_error(const char *file, int line, pte_t);
1958 extern void __pmd_error(const char *file, int line, pmd_t);
1959 extern void __pgd_error(const char *file, int line, pgd_t);
1960 @@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1961 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1962 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1963
1964 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
1965 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1966 +
1967 +#ifdef CONFIG_PAX_KERNEXEC
1968 +#include <asm/domain.h>
1969 +#include <linux/thread_info.h>
1970 +#include <linux/preempt.h>
1971 +#endif
1972 +
1973 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1974 +static inline int test_domain(int domain, int domaintype)
1975 +{
1976 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1977 +}
1978 +#endif
1979 +
1980 +#ifdef CONFIG_PAX_KERNEXEC
1981 +static inline unsigned long pax_open_kernel(void) {
1982 +#ifdef CONFIG_ARM_LPAE
1983 + /* TODO */
1984 +#else
1985 + preempt_disable();
1986 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1987 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1988 +#endif
1989 + return 0;
1990 +}
1991 +
1992 +static inline unsigned long pax_close_kernel(void) {
1993 +#ifdef CONFIG_ARM_LPAE
1994 + /* TODO */
1995 +#else
1996 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1997 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
1998 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1999 + preempt_enable_no_resched();
2000 +#endif
2001 + return 0;
2002 +}
2003 +#else
2004 +static inline unsigned long pax_open_kernel(void) { return 0; }
2005 +static inline unsigned long pax_close_kernel(void) { return 0; }
2006 +#endif
2007 +
2008 /*
2009 * This is the lowest virtual address we can permit any user space
2010 * mapping to be mapped at. This is particularly important for
2011 @@ -63,8 +113,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2012 /*
2013 * The pgprot_* and protection_map entries will be fixed up in runtime
2014 * to include the cachable and bufferable bits based on memory policy,
2015 - * as well as any architecture dependent bits like global/ASID and SMP
2016 - * shared mapping bits.
2017 + * as well as any architecture dependent bits like global/ASID, PXN,
2018 + * and SMP shared mapping bits.
2019 */
2020 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2021
2022 @@ -240,7 +290,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2023
2024 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2025 {
2026 - const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE;
2027 + const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | L_PTE_NONE | __supported_pte_mask;
2028 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2029 return pte;
2030 }
2031 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2032 index f3628fb..a0672dd 100644
2033 --- a/arch/arm/include/asm/proc-fns.h
2034 +++ b/arch/arm/include/asm/proc-fns.h
2035 @@ -75,7 +75,7 @@ extern struct processor {
2036 unsigned int suspend_size;
2037 void (*do_suspend)(void *);
2038 void (*do_resume)(void *);
2039 -} processor;
2040 +} __do_const processor;
2041
2042 #ifndef MULTI_CPU
2043 extern void cpu_proc_init(void);
2044 diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2045 index 06e7d50..8a8e251 100644
2046 --- a/arch/arm/include/asm/processor.h
2047 +++ b/arch/arm/include/asm/processor.h
2048 @@ -65,9 +65,8 @@ struct thread_struct {
2049 regs->ARM_cpsr |= PSR_ENDSTATE; \
2050 regs->ARM_pc = pc & ~1; /* pc */ \
2051 regs->ARM_sp = sp; /* sp */ \
2052 - regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2053 - regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2054 - regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2055 + /* r2 (envp), r1 (argv), r0 (argc) */ \
2056 + (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2057 nommu_start_thread(regs); \
2058 })
2059
2060 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2061 index d3a22be..3a69ad5 100644
2062 --- a/arch/arm/include/asm/smp.h
2063 +++ b/arch/arm/include/asm/smp.h
2064 @@ -107,7 +107,7 @@ struct smp_operations {
2065 int (*cpu_disable)(unsigned int cpu);
2066 #endif
2067 #endif
2068 -};
2069 +} __no_const;
2070
2071 /*
2072 * set platform specific SMP operations
2073 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2074 index cddda1f..ff357f7 100644
2075 --- a/arch/arm/include/asm/thread_info.h
2076 +++ b/arch/arm/include/asm/thread_info.h
2077 @@ -77,9 +77,9 @@ struct thread_info {
2078 .flags = 0, \
2079 .preempt_count = INIT_PREEMPT_COUNT, \
2080 .addr_limit = KERNEL_DS, \
2081 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2082 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2083 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2084 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2085 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2086 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2087 .restart_block = { \
2088 .fn = do_no_restart_syscall, \
2089 }, \
2090 @@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2091 #define TIF_SYSCALL_AUDIT 9
2092 #define TIF_SYSCALL_TRACEPOINT 10
2093 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2094 +
2095 +/* within 8 bits of TIF_SYSCALL_TRACE
2096 + * to meet flexible second operand requirements
2097 + */
2098 +#define TIF_GRSEC_SETXID 12
2099 +
2100 #define TIF_USING_IWMMXT 17
2101 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2102 #define TIF_RESTORE_SIGMASK 20
2103 @@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2104 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2105 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2106 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2107 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2108
2109 /* Checks for any syscall work in entry-common.S */
2110 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2111 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2112 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2113
2114 /*
2115 * Change these and you break ASM code in entry-common.S
2116 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2117 index 7e1f760..752fcb7 100644
2118 --- a/arch/arm/include/asm/uaccess.h
2119 +++ b/arch/arm/include/asm/uaccess.h
2120 @@ -18,6 +18,7 @@
2121 #include <asm/domain.h>
2122 #include <asm/unified.h>
2123 #include <asm/compiler.h>
2124 +#include <asm/pgtable.h>
2125
2126 #define VERIFY_READ 0
2127 #define VERIFY_WRITE 1
2128 @@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2129 #define USER_DS TASK_SIZE
2130 #define get_fs() (current_thread_info()->addr_limit)
2131
2132 +static inline void pax_open_userland(void)
2133 +{
2134 +
2135 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2136 + if (get_fs() == USER_DS) {
2137 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2138 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2139 + }
2140 +#endif
2141 +
2142 +}
2143 +
2144 +static inline void pax_close_userland(void)
2145 +{
2146 +
2147 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2148 + if (get_fs() == USER_DS) {
2149 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2150 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2151 + }
2152 +#endif
2153 +
2154 +}
2155 +
2156 static inline void set_fs(mm_segment_t fs)
2157 {
2158 current_thread_info()->addr_limit = fs;
2159 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2160 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2161 }
2162
2163 #define segment_eq(a,b) ((a) == (b))
2164 @@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2165
2166 #define get_user(x,p) \
2167 ({ \
2168 + int __e; \
2169 might_fault(); \
2170 - __get_user_check(x,p); \
2171 + pax_open_userland(); \
2172 + __e = __get_user_check(x,p); \
2173 + pax_close_userland(); \
2174 + __e; \
2175 })
2176
2177 extern int __put_user_1(void *, unsigned int);
2178 @@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2179
2180 #define put_user(x,p) \
2181 ({ \
2182 + int __e; \
2183 might_fault(); \
2184 - __put_user_check(x,p); \
2185 + pax_open_userland(); \
2186 + __e = __put_user_check(x,p); \
2187 + pax_close_userland(); \
2188 + __e; \
2189 })
2190
2191 #else /* CONFIG_MMU */
2192 @@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2193 #define __get_user(x,ptr) \
2194 ({ \
2195 long __gu_err = 0; \
2196 + pax_open_userland(); \
2197 __get_user_err((x),(ptr),__gu_err); \
2198 + pax_close_userland(); \
2199 __gu_err; \
2200 })
2201
2202 #define __get_user_error(x,ptr,err) \
2203 ({ \
2204 + pax_open_userland(); \
2205 __get_user_err((x),(ptr),err); \
2206 + pax_close_userland(); \
2207 (void) 0; \
2208 })
2209
2210 @@ -312,13 +349,17 @@ do { \
2211 #define __put_user(x,ptr) \
2212 ({ \
2213 long __pu_err = 0; \
2214 + pax_open_userland(); \
2215 __put_user_err((x),(ptr),__pu_err); \
2216 + pax_close_userland(); \
2217 __pu_err; \
2218 })
2219
2220 #define __put_user_error(x,ptr,err) \
2221 ({ \
2222 + pax_open_userland(); \
2223 __put_user_err((x),(ptr),err); \
2224 + pax_close_userland(); \
2225 (void) 0; \
2226 })
2227
2228 @@ -418,11 +459,44 @@ do { \
2229
2230
2231 #ifdef CONFIG_MMU
2232 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2233 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2234 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2235 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2236 +
2237 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2238 +{
2239 + unsigned long ret;
2240 +
2241 + check_object_size(to, n, false);
2242 + pax_open_userland();
2243 + ret = ___copy_from_user(to, from, n);
2244 + pax_close_userland();
2245 + return ret;
2246 +}
2247 +
2248 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2249 +{
2250 + unsigned long ret;
2251 +
2252 + check_object_size(from, n, true);
2253 + pax_open_userland();
2254 + ret = ___copy_to_user(to, from, n);
2255 + pax_close_userland();
2256 + return ret;
2257 +}
2258 +
2259 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2260 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2261 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2262 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2263 +
2264 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2265 +{
2266 + unsigned long ret;
2267 + pax_open_userland();
2268 + ret = ___clear_user(addr, n);
2269 + pax_close_userland();
2270 + return ret;
2271 +}
2272 +
2273 #else
2274 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2275 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2276 @@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2277
2278 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2279 {
2280 + if ((long)n < 0)
2281 + return n;
2282 +
2283 if (access_ok(VERIFY_READ, from, n))
2284 n = __copy_from_user(to, from, n);
2285 else /* security hole - plug it */
2286 @@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2287
2288 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2289 {
2290 + if ((long)n < 0)
2291 + return n;
2292 +
2293 if (access_ok(VERIFY_WRITE, to, n))
2294 n = __copy_to_user(to, from, n);
2295 return n;
2296 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2297 index 96ee092..37f1844 100644
2298 --- a/arch/arm/include/uapi/asm/ptrace.h
2299 +++ b/arch/arm/include/uapi/asm/ptrace.h
2300 @@ -73,7 +73,7 @@
2301 * ARMv7 groups of PSR bits
2302 */
2303 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2304 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2305 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2306 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2307 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2308
2309 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2310 index 60d3b73..9168db0 100644
2311 --- a/arch/arm/kernel/armksyms.c
2312 +++ b/arch/arm/kernel/armksyms.c
2313 @@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
2314 #ifdef CONFIG_MMU
2315 EXPORT_SYMBOL(copy_page);
2316
2317 -EXPORT_SYMBOL(__copy_from_user);
2318 -EXPORT_SYMBOL(__copy_to_user);
2319 +EXPORT_SYMBOL(___copy_from_user);
2320 +EXPORT_SYMBOL(___copy_to_user);
2321 EXPORT_SYMBOL(__clear_user);
2322
2323 EXPORT_SYMBOL(__get_user_1);
2324 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2325 index 0f82098..3dbd3ee 100644
2326 --- a/arch/arm/kernel/entry-armv.S
2327 +++ b/arch/arm/kernel/entry-armv.S
2328 @@ -47,6 +47,87 @@
2329 9997:
2330 .endm
2331
2332 + .macro pax_enter_kernel
2333 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2334 + @ make aligned space for saved DACR
2335 + sub sp, sp, #8
2336 + @ save regs
2337 + stmdb sp!, {r1, r2}
2338 + @ read DACR from cpu_domain into r1
2339 + mov r2, sp
2340 + @ assume 8K pages, since we have to split the immediate in two
2341 + bic r2, r2, #(0x1fc0)
2342 + bic r2, r2, #(0x3f)
2343 + ldr r1, [r2, #TI_CPU_DOMAIN]
2344 + @ store old DACR on stack
2345 + str r1, [sp, #8]
2346 +#ifdef CONFIG_PAX_KERNEXEC
2347 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2348 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2349 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2350 +#endif
2351 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2352 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2353 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2354 +#endif
2355 + @ write r1 to current_thread_info()->cpu_domain
2356 + str r1, [r2, #TI_CPU_DOMAIN]
2357 + @ write r1 to DACR
2358 + mcr p15, 0, r1, c3, c0, 0
2359 + @ instruction sync
2360 + instr_sync
2361 + @ restore regs
2362 + ldmia sp!, {r1, r2}
2363 +#endif
2364 + .endm
2365 +
2366 + .macro pax_open_userland
2367 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2368 + @ save regs
2369 + stmdb sp!, {r0, r1}
2370 + @ read DACR from cpu_domain into r1
2371 + mov r0, sp
2372 + @ assume 8K pages, since we have to split the immediate in two
2373 + bic r0, r0, #(0x1fc0)
2374 + bic r0, r0, #(0x3f)
2375 + ldr r1, [r0, #TI_CPU_DOMAIN]
2376 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2377 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2378 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2379 + @ write r1 to current_thread_info()->cpu_domain
2380 + str r1, [r0, #TI_CPU_DOMAIN]
2381 + @ write r1 to DACR
2382 + mcr p15, 0, r1, c3, c0, 0
2383 + @ instruction sync
2384 + instr_sync
2385 + @ restore regs
2386 + ldmia sp!, {r0, r1}
2387 +#endif
2388 + .endm
2389 +
2390 + .macro pax_close_userland
2391 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2392 + @ save regs
2393 + stmdb sp!, {r0, r1}
2394 + @ read DACR from cpu_domain into r1
2395 + mov r0, sp
2396 + @ assume 8K pages, since we have to split the immediate in two
2397 + bic r0, r0, #(0x1fc0)
2398 + bic r0, r0, #(0x3f)
2399 + ldr r1, [r0, #TI_CPU_DOMAIN]
2400 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2401 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2402 + @ write r1 to current_thread_info()->cpu_domain
2403 + str r1, [r0, #TI_CPU_DOMAIN]
2404 + @ write r1 to DACR
2405 + mcr p15, 0, r1, c3, c0, 0
2406 + @ instruction sync
2407 + instr_sync
2408 + @ restore regs
2409 + ldmia sp!, {r0, r1}
2410 +#endif
2411 + .endm
2412 +
2413 .macro pabt_helper
2414 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2415 #ifdef MULTI_PABORT
2416 @@ -89,11 +170,15 @@
2417 * Invalid mode handlers
2418 */
2419 .macro inv_entry, reason
2420 +
2421 + pax_enter_kernel
2422 +
2423 sub sp, sp, #S_FRAME_SIZE
2424 ARM( stmib sp, {r1 - lr} )
2425 THUMB( stmia sp, {r0 - r12} )
2426 THUMB( str sp, [sp, #S_SP] )
2427 THUMB( str lr, [sp, #S_LR] )
2428 +
2429 mov r1, #\reason
2430 .endm
2431
2432 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2433 .macro svc_entry, stack_hole=0
2434 UNWIND(.fnstart )
2435 UNWIND(.save {r0 - pc} )
2436 +
2437 + pax_enter_kernel
2438 +
2439 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2440 +
2441 #ifdef CONFIG_THUMB2_KERNEL
2442 SPFIX( str r0, [sp] ) @ temporarily saved
2443 SPFIX( mov r0, sp )
2444 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2445 ldmia r0, {r3 - r5}
2446 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2447 mov r6, #-1 @ "" "" "" ""
2448 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2449 + @ offset sp by 8 as done in pax_enter_kernel
2450 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2451 +#else
2452 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2453 +#endif
2454 SPFIX( addeq r2, r2, #4 )
2455 str r3, [sp, #-4]! @ save the "real" r0 copied
2456 @ from the exception stack
2457 @@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2458 .macro usr_entry
2459 UNWIND(.fnstart )
2460 UNWIND(.cantunwind ) @ don't unwind the user space
2461 +
2462 + pax_enter_kernel_user
2463 +
2464 sub sp, sp, #S_FRAME_SIZE
2465 ARM( stmib sp, {r1 - r12} )
2466 THUMB( stmia sp, {r0 - r12} )
2467 @@ -456,7 +553,9 @@ __und_usr:
2468 tst r3, #PSR_T_BIT @ Thumb mode?
2469 bne __und_usr_thumb
2470 sub r4, r2, #4 @ ARM instr at LR - 4
2471 + pax_open_userland
2472 1: ldrt r0, [r4]
2473 + pax_close_userland
2474 #ifdef CONFIG_CPU_ENDIAN_BE8
2475 rev r0, r0 @ little endian instruction
2476 #endif
2477 @@ -491,10 +590,14 @@ __und_usr_thumb:
2478 */
2479 .arch armv6t2
2480 #endif
2481 + pax_open_userland
2482 2: ldrht r5, [r4]
2483 + pax_close_userland
2484 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2485 blo __und_usr_fault_16 @ 16bit undefined instruction
2486 + pax_open_userland
2487 3: ldrht r0, [r2]
2488 + pax_close_userland
2489 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2490 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2491 orr r0, r0, r5, lsl #16
2492 @@ -733,7 +836,7 @@ ENTRY(__switch_to)
2493 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2494 THUMB( str sp, [ip], #4 )
2495 THUMB( str lr, [ip], #4 )
2496 -#ifdef CONFIG_CPU_USE_DOMAINS
2497 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2498 ldr r6, [r2, #TI_CPU_DOMAIN]
2499 #endif
2500 set_tls r3, r4, r5
2501 @@ -742,7 +845,7 @@ ENTRY(__switch_to)
2502 ldr r8, =__stack_chk_guard
2503 ldr r7, [r7, #TSK_STACK_CANARY]
2504 #endif
2505 -#ifdef CONFIG_CPU_USE_DOMAINS
2506 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC)
2507 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2508 #endif
2509 mov r5, r0
2510 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2511 index a6c301e..908821b 100644
2512 --- a/arch/arm/kernel/entry-common.S
2513 +++ b/arch/arm/kernel/entry-common.S
2514 @@ -10,18 +10,46 @@
2515
2516 #include <asm/unistd.h>
2517 #include <asm/ftrace.h>
2518 +#include <asm/domain.h>
2519 #include <asm/unwind.h>
2520
2521 +#include "entry-header.S"
2522 +
2523 #ifdef CONFIG_NEED_RET_TO_USER
2524 #include <mach/entry-macro.S>
2525 #else
2526 .macro arch_ret_to_user, tmp1, tmp2
2527 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2528 + @ save regs
2529 + stmdb sp!, {r1, r2}
2530 + @ read DACR from cpu_domain into r1
2531 + mov r2, sp
2532 + @ assume 8K pages, since we have to split the immediate in two
2533 + bic r2, r2, #(0x1fc0)
2534 + bic r2, r2, #(0x3f)
2535 + ldr r1, [r2, #TI_CPU_DOMAIN]
2536 +#ifdef CONFIG_PAX_KERNEXEC
2537 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2538 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2539 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2540 +#endif
2541 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2542 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2543 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2544 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2545 +#endif
2546 + @ write r1 to current_thread_info()->cpu_domain
2547 + str r1, [r2, #TI_CPU_DOMAIN]
2548 + @ write r1 to DACR
2549 + mcr p15, 0, r1, c3, c0, 0
2550 + @ instruction sync
2551 + instr_sync
2552 + @ restore regs
2553 + ldmia sp!, {r1, r2}
2554 +#endif
2555 .endm
2556 #endif
2557
2558 -#include "entry-header.S"
2559 -
2560 -
2561 .align 5
2562 /*
2563 * This is the fast syscall return path. We do as little as
2564 @@ -339,6 +367,7 @@ ENDPROC(ftrace_stub)
2565
2566 .align 5
2567 ENTRY(vector_swi)
2568 +
2569 sub sp, sp, #S_FRAME_SIZE
2570 stmia sp, {r0 - r12} @ Calling r0 - r12
2571 ARM( add r8, sp, #S_PC )
2572 @@ -388,6 +417,12 @@ ENTRY(vector_swi)
2573 ldr scno, [lr, #-4] @ get SWI instruction
2574 #endif
2575
2576 + /*
2577 + * do this here to avoid a performance hit of wrapping the code above
2578 + * that directly dereferences userland to parse the SWI instruction
2579 + */
2580 + pax_enter_kernel_user
2581 +
2582 #ifdef CONFIG_ALIGNMENT_TRAP
2583 ldr ip, __cr_alignment
2584 ldr ip, [ip]
2585 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2586 index 9a8531e..812e287 100644
2587 --- a/arch/arm/kernel/entry-header.S
2588 +++ b/arch/arm/kernel/entry-header.S
2589 @@ -73,9 +73,66 @@
2590 msr cpsr_c, \rtemp @ switch back to the SVC mode
2591 .endm
2592
2593 + .macro pax_enter_kernel_user
2594 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595 + @ save regs
2596 + stmdb sp!, {r0, r1}
2597 + @ read DACR from cpu_domain into r1
2598 + mov r0, sp
2599 + @ assume 8K pages, since we have to split the immediate in two
2600 + bic r0, r0, #(0x1fc0)
2601 + bic r0, r0, #(0x3f)
2602 + ldr r1, [r0, #TI_CPU_DOMAIN]
2603 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2604 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2605 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2606 +#endif
2607 +#ifdef CONFIG_PAX_KERNEXEC
2608 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2609 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2610 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2611 +#endif
2612 + @ write r1 to current_thread_info()->cpu_domain
2613 + str r1, [r0, #TI_CPU_DOMAIN]
2614 + @ write r1 to DACR
2615 + mcr p15, 0, r1, c3, c0, 0
2616 + @ instruction sync
2617 + instr_sync
2618 + @ restore regs
2619 + ldmia sp!, {r0, r1}
2620 +#endif
2621 + .endm
2622 +
2623 + .macro pax_exit_kernel
2624 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 + @ save regs
2626 + stmdb sp!, {r0, r1}
2627 + @ read old DACR from stack into r1
2628 + ldr r1, [sp, #(8 + S_SP)]
2629 + sub r1, r1, #8
2630 + ldr r1, [r1]
2631 +
2632 + @ write r1 to current_thread_info()->cpu_domain
2633 + mov r0, sp
2634 + @ assume 8K pages, since we have to split the immediate in two
2635 + bic r0, r0, #(0x1fc0)
2636 + bic r0, r0, #(0x3f)
2637 + str r1, [r0, #TI_CPU_DOMAIN]
2638 + @ write r1 to DACR
2639 + mcr p15, 0, r1, c3, c0, 0
2640 + @ instruction sync
2641 + instr_sync
2642 + @ restore regs
2643 + ldmia sp!, {r0, r1}
2644 +#endif
2645 + .endm
2646 +
2647 #ifndef CONFIG_THUMB2_KERNEL
2648 .macro svc_exit, rpsr
2649 msr spsr_cxsf, \rpsr
2650 +
2651 + pax_exit_kernel
2652 +
2653 #if defined(CONFIG_CPU_V6)
2654 ldr r0, [sp]
2655 strex r1, r2, [sp] @ clear the exclusive monitor
2656 @@ -121,6 +178,9 @@
2657 .endm
2658 #else /* CONFIG_THUMB2_KERNEL */
2659 .macro svc_exit, rpsr
2660 +
2661 + pax_exit_kernel
2662 +
2663 ldr lr, [sp, #S_SP] @ top of the stack
2664 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2665 clrex @ clear the exclusive monitor
2666 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2667 index 2adda11..7fbe958 100644
2668 --- a/arch/arm/kernel/fiq.c
2669 +++ b/arch/arm/kernel/fiq.c
2670 @@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2671 #if defined(CONFIG_CPU_USE_DOMAINS)
2672 memcpy((void *)0xffff001c, start, length);
2673 #else
2674 + pax_open_kernel();
2675 memcpy(vectors_page + 0x1c, start, length);
2676 + pax_close_kernel();
2677 #endif
2678 flush_icache_range(0xffff001c, 0xffff001c + length);
2679 if (!vectors_high())
2680 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2681 index 486a15a..2d6880e 100644
2682 --- a/arch/arm/kernel/head.S
2683 +++ b/arch/arm/kernel/head.S
2684 @@ -52,7 +52,9 @@
2685 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2686
2687 .macro pgtbl, rd, phys
2688 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2689 + mov \rd, #TEXT_OFFSET
2690 + sub \rd, #PG_DIR_SIZE
2691 + add \rd, \rd, \phys
2692 .endm
2693
2694 /*
2695 @@ -416,7 +418,7 @@ __enable_mmu:
2696 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2697 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2698 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2699 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2700 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2701 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2702 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2703 #endif
2704 diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2705 index 5ff2e77..556d030 100644
2706 --- a/arch/arm/kernel/hw_breakpoint.c
2707 +++ b/arch/arm/kernel/hw_breakpoint.c
2708 @@ -1011,7 +1011,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2709 return NOTIFY_OK;
2710 }
2711
2712 -static struct notifier_block __cpuinitdata dbg_reset_nb = {
2713 +static struct notifier_block dbg_reset_nb = {
2714 .notifier_call = dbg_reset_notify,
2715 };
2716
2717 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2718 index 1e9be5d..03edbc2 100644
2719 --- a/arch/arm/kernel/module.c
2720 +++ b/arch/arm/kernel/module.c
2721 @@ -37,12 +37,37 @@
2722 #endif
2723
2724 #ifdef CONFIG_MMU
2725 -void *module_alloc(unsigned long size)
2726 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2727 {
2728 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2729 + return NULL;
2730 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2731 - GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2732 + GFP_KERNEL, prot, -1,
2733 __builtin_return_address(0));
2734 }
2735 +
2736 +void *module_alloc(unsigned long size)
2737 +{
2738 +
2739 +#ifdef CONFIG_PAX_KERNEXEC
2740 + return __module_alloc(size, PAGE_KERNEL);
2741 +#else
2742 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2743 +#endif
2744 +
2745 +}
2746 +
2747 +#ifdef CONFIG_PAX_KERNEXEC
2748 +void module_free_exec(struct module *mod, void *module_region)
2749 +{
2750 + module_free(mod, module_region);
2751 +}
2752 +
2753 +void *module_alloc_exec(unsigned long size)
2754 +{
2755 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2756 +}
2757 +#endif
2758 #endif
2759
2760 int
2761 diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2762 index 5f66206..dce492f 100644
2763 --- a/arch/arm/kernel/perf_event_cpu.c
2764 +++ b/arch/arm/kernel/perf_event_cpu.c
2765 @@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2766 return NOTIFY_OK;
2767 }
2768
2769 -static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2770 +static struct notifier_block cpu_pmu_hotplug_notifier = {
2771 .notifier_call = cpu_pmu_notify,
2772 };
2773
2774 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2775 index c6dec5f..f853532 100644
2776 --- a/arch/arm/kernel/process.c
2777 +++ b/arch/arm/kernel/process.c
2778 @@ -28,7 +28,6 @@
2779 #include <linux/tick.h>
2780 #include <linux/utsname.h>
2781 #include <linux/uaccess.h>
2782 -#include <linux/random.h>
2783 #include <linux/hw_breakpoint.h>
2784 #include <linux/cpuidle.h>
2785 #include <linux/leds.h>
2786 @@ -256,9 +255,10 @@ void machine_power_off(void)
2787 machine_shutdown();
2788 if (pm_power_off)
2789 pm_power_off();
2790 + BUG();
2791 }
2792
2793 -void machine_restart(char *cmd)
2794 +__noreturn void machine_restart(char *cmd)
2795 {
2796 machine_shutdown();
2797
2798 @@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2799 init_utsname()->release,
2800 (int)strcspn(init_utsname()->version, " "),
2801 init_utsname()->version);
2802 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2803 - print_symbol("LR is at %s\n", regs->ARM_lr);
2804 + printk("PC is at %pA\n", instruction_pointer(regs));
2805 + printk("LR is at %pA\n", regs->ARM_lr);
2806 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2807 "sp : %08lx ip : %08lx fp : %08lx\n",
2808 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2809 @@ -452,12 +452,6 @@ unsigned long get_wchan(struct task_struct *p)
2810 return 0;
2811 }
2812
2813 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2814 -{
2815 - unsigned long range_end = mm->brk + 0x02000000;
2816 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2817 -}
2818 -
2819 #ifdef CONFIG_MMU
2820 /*
2821 * The vectors page is always readable from user space for the
2822 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2823 index 03deeff..741ce88 100644
2824 --- a/arch/arm/kernel/ptrace.c
2825 +++ b/arch/arm/kernel/ptrace.c
2826 @@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2827 return current_thread_info()->syscall;
2828 }
2829
2830 +#ifdef CONFIG_GRKERNSEC_SETXID
2831 +extern void gr_delayed_cred_worker(void);
2832 +#endif
2833 +
2834 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2835 {
2836 current_thread_info()->syscall = scno;
2837
2838 +#ifdef CONFIG_GRKERNSEC_SETXID
2839 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2840 + gr_delayed_cred_worker();
2841 +#endif
2842 +
2843 /* Do the secure computing check first; failures should be fast. */
2844 if (secure_computing(scno) == -1)
2845 return -1;
2846 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2847 index 3f6cbb2..6d856f5 100644
2848 --- a/arch/arm/kernel/setup.c
2849 +++ b/arch/arm/kernel/setup.c
2850 @@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2851 unsigned int elf_hwcap __read_mostly;
2852 EXPORT_SYMBOL(elf_hwcap);
2853
2854 +pteval_t __supported_pte_mask __read_only;
2855 +pmdval_t __supported_pmd_mask __read_only;
2856
2857 #ifdef MULTI_CPU
2858 -struct processor processor __read_mostly;
2859 +struct processor processor;
2860 #endif
2861 #ifdef MULTI_TLB
2862 -struct cpu_tlb_fns cpu_tlb __read_mostly;
2863 +struct cpu_tlb_fns cpu_tlb __read_only;
2864 #endif
2865 #ifdef MULTI_USER
2866 -struct cpu_user_fns cpu_user __read_mostly;
2867 +struct cpu_user_fns cpu_user __read_only;
2868 #endif
2869 #ifdef MULTI_CACHE
2870 -struct cpu_cache_fns cpu_cache __read_mostly;
2871 +struct cpu_cache_fns cpu_cache __read_only;
2872 #endif
2873 #ifdef CONFIG_OUTER_CACHE
2874 -struct outer_cache_fns outer_cache __read_mostly;
2875 +struct outer_cache_fns outer_cache __read_only;
2876 EXPORT_SYMBOL(outer_cache);
2877 #endif
2878
2879 @@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2880 asm("mrc p15, 0, %0, c0, c1, 4"
2881 : "=r" (mmfr0));
2882 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2883 - (mmfr0 & 0x000000f0) >= 0x00000030)
2884 + (mmfr0 & 0x000000f0) >= 0x00000030) {
2885 cpu_arch = CPU_ARCH_ARMv7;
2886 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2887 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2888 + __supported_pte_mask |= L_PTE_PXN;
2889 + __supported_pmd_mask |= PMD_PXNTABLE;
2890 + }
2891 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2892 (mmfr0 & 0x000000f0) == 0x00000020)
2893 cpu_arch = CPU_ARCH_ARMv6;
2894 else
2895 @@ -462,7 +468,7 @@ static void __init setup_processor(void)
2896 __cpu_architecture = __get_cpu_architecture();
2897
2898 #ifdef MULTI_CPU
2899 - processor = *list->proc;
2900 + memcpy((void *)&processor, list->proc, sizeof processor);
2901 #endif
2902 #ifdef MULTI_TLB
2903 cpu_tlb = *list->tlb;
2904 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2905 index 84f4cbf..672f5b8 100644
2906 --- a/arch/arm/kernel/smp.c
2907 +++ b/arch/arm/kernel/smp.c
2908 @@ -70,7 +70,7 @@ enum ipi_msg_type {
2909
2910 static DECLARE_COMPLETION(cpu_running);
2911
2912 -static struct smp_operations smp_ops;
2913 +static struct smp_operations smp_ops __read_only;
2914
2915 void __init smp_set_ops(struct smp_operations *ops)
2916 {
2917 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2918 index b0179b8..b7b16c7 100644
2919 --- a/arch/arm/kernel/traps.c
2920 +++ b/arch/arm/kernel/traps.c
2921 @@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2922 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2923 {
2924 #ifdef CONFIG_KALLSYMS
2925 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2926 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2927 #else
2928 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2929 #endif
2930 @@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2931 static int die_owner = -1;
2932 static unsigned int die_nest_count;
2933
2934 +extern void gr_handle_kernel_exploit(void);
2935 +
2936 static unsigned long oops_begin(void)
2937 {
2938 int cpu;
2939 @@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2940 panic("Fatal exception in interrupt");
2941 if (panic_on_oops)
2942 panic("Fatal exception");
2943 +
2944 + gr_handle_kernel_exploit();
2945 +
2946 if (signr)
2947 do_exit(signr);
2948 }
2949 @@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
2950 * The user helper at 0xffff0fe0 must be used instead.
2951 * (see entry-armv.S for details)
2952 */
2953 + pax_open_kernel();
2954 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
2955 + pax_close_kernel();
2956 }
2957 return 0;
2958
2959 @@ -849,5 +856,9 @@ void __init early_trap_init(void *vectors_base)
2960 sigreturn_codes, sizeof(sigreturn_codes));
2961
2962 flush_icache_range(vectors, vectors + PAGE_SIZE);
2963 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
2964 +
2965 +#ifndef CONFIG_PAX_MEMORY_UDEREF
2966 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
2967 +#endif
2968 +
2969 }
2970 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2971 index 11c1785..c67d54c 100644
2972 --- a/arch/arm/kernel/vmlinux.lds.S
2973 +++ b/arch/arm/kernel/vmlinux.lds.S
2974 @@ -8,7 +8,11 @@
2975 #include <asm/thread_info.h>
2976 #include <asm/memory.h>
2977 #include <asm/page.h>
2978 -
2979 +
2980 +#ifdef CONFIG_PAX_KERNEXEC
2981 +#include <asm/pgtable.h>
2982 +#endif
2983 +
2984 #define PROC_INFO \
2985 . = ALIGN(4); \
2986 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2987 @@ -90,6 +94,11 @@ SECTIONS
2988 _text = .;
2989 HEAD_TEXT
2990 }
2991 +
2992 +#ifdef CONFIG_PAX_KERNEXEC
2993 + . = ALIGN(1<<SECTION_SHIFT);
2994 +#endif
2995 +
2996 .text : { /* Real text segment */
2997 _stext = .; /* Text and read-only data */
2998 __exception_text_start = .;
2999 @@ -144,6 +153,10 @@ SECTIONS
3000
3001 _etext = .; /* End of text and rodata section */
3002
3003 +#ifdef CONFIG_PAX_KERNEXEC
3004 + . = ALIGN(1<<SECTION_SHIFT);
3005 +#endif
3006 +
3007 #ifndef CONFIG_XIP_KERNEL
3008 . = ALIGN(PAGE_SIZE);
3009 __init_begin = .;
3010 @@ -203,6 +216,11 @@ SECTIONS
3011 . = PAGE_OFFSET + TEXT_OFFSET;
3012 #else
3013 __init_end = .;
3014 +
3015 +#ifdef CONFIG_PAX_KERNEXEC
3016 + . = ALIGN(1<<SECTION_SHIFT);
3017 +#endif
3018 +
3019 . = ALIGN(THREAD_SIZE);
3020 __data_loc = .;
3021 #endif
3022 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3023 index 14a0d98..7771a7d 100644
3024 --- a/arch/arm/lib/clear_user.S
3025 +++ b/arch/arm/lib/clear_user.S
3026 @@ -12,14 +12,14 @@
3027
3028 .text
3029
3030 -/* Prototype: int __clear_user(void *addr, size_t sz)
3031 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3032 * Purpose : clear some user memory
3033 * Params : addr - user memory address to clear
3034 * : sz - number of bytes to clear
3035 * Returns : number of bytes NOT cleared
3036 */
3037 ENTRY(__clear_user_std)
3038 -WEAK(__clear_user)
3039 +WEAK(___clear_user)
3040 stmfd sp!, {r1, lr}
3041 mov r2, #0
3042 cmp r1, #4
3043 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3044 USER( strnebt r2, [r0])
3045 mov r0, #0
3046 ldmfd sp!, {r1, pc}
3047 -ENDPROC(__clear_user)
3048 +ENDPROC(___clear_user)
3049 ENDPROC(__clear_user_std)
3050
3051 .pushsection .fixup,"ax"
3052 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3053 index 66a477a..bee61d3 100644
3054 --- a/arch/arm/lib/copy_from_user.S
3055 +++ b/arch/arm/lib/copy_from_user.S
3056 @@ -16,7 +16,7 @@
3057 /*
3058 * Prototype:
3059 *
3060 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3061 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3062 *
3063 * Purpose:
3064 *
3065 @@ -84,11 +84,11 @@
3066
3067 .text
3068
3069 -ENTRY(__copy_from_user)
3070 +ENTRY(___copy_from_user)
3071
3072 #include "copy_template.S"
3073
3074 -ENDPROC(__copy_from_user)
3075 +ENDPROC(___copy_from_user)
3076
3077 .pushsection .fixup,"ax"
3078 .align 0
3079 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3080 index 6ee2f67..d1cce76 100644
3081 --- a/arch/arm/lib/copy_page.S
3082 +++ b/arch/arm/lib/copy_page.S
3083 @@ -10,6 +10,7 @@
3084 * ASM optimised string functions
3085 */
3086 #include <linux/linkage.h>
3087 +#include <linux/const.h>
3088 #include <asm/assembler.h>
3089 #include <asm/asm-offsets.h>
3090 #include <asm/cache.h>
3091 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3092 index d066df6..df28194 100644
3093 --- a/arch/arm/lib/copy_to_user.S
3094 +++ b/arch/arm/lib/copy_to_user.S
3095 @@ -16,7 +16,7 @@
3096 /*
3097 * Prototype:
3098 *
3099 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3100 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3101 *
3102 * Purpose:
3103 *
3104 @@ -88,11 +88,11 @@
3105 .text
3106
3107 ENTRY(__copy_to_user_std)
3108 -WEAK(__copy_to_user)
3109 +WEAK(___copy_to_user)
3110
3111 #include "copy_template.S"
3112
3113 -ENDPROC(__copy_to_user)
3114 +ENDPROC(___copy_to_user)
3115 ENDPROC(__copy_to_user_std)
3116
3117 .pushsection .fixup,"ax"
3118 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3119 index 7d08b43..f7ca7ea 100644
3120 --- a/arch/arm/lib/csumpartialcopyuser.S
3121 +++ b/arch/arm/lib/csumpartialcopyuser.S
3122 @@ -57,8 +57,8 @@
3123 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3124 */
3125
3126 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3127 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3128 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3129 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3130
3131 #include "csumpartialcopygeneric.S"
3132
3133 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3134 index 0dc5385..45833ef 100644
3135 --- a/arch/arm/lib/delay.c
3136 +++ b/arch/arm/lib/delay.c
3137 @@ -28,12 +28,14 @@
3138 /*
3139 * Default to the loop-based delay implementation.
3140 */
3141 -struct arm_delay_ops arm_delay_ops = {
3142 +static struct arm_delay_ops arm_loop_delay_ops = {
3143 .delay = __loop_delay,
3144 .const_udelay = __loop_const_udelay,
3145 .udelay = __loop_udelay,
3146 };
3147
3148 +struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
3149 +
3150 static const struct delay_timer *delay_timer;
3151 static bool delay_calibrated;
3152
3153 @@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
3154 __timer_const_udelay(usecs * UDELAY_MULT);
3155 }
3156
3157 +static struct arm_delay_ops arm_timer_delay_ops = {
3158 + .delay = __timer_delay,
3159 + .const_udelay = __timer_const_udelay,
3160 + .udelay = __timer_udelay,
3161 +};
3162 +
3163 void __init register_current_timer_delay(const struct delay_timer *timer)
3164 {
3165 if (!delay_calibrated) {
3166 @@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
3167 delay_timer = timer;
3168 lpj_fine = timer->freq / HZ;
3169 loops_per_jiffy = lpj_fine;
3170 - arm_delay_ops.delay = __timer_delay;
3171 - arm_delay_ops.const_udelay = __timer_const_udelay;
3172 - arm_delay_ops.udelay = __timer_udelay;
3173 + arm_delay_ops = &arm_timer_delay_ops;
3174 delay_calibrated = true;
3175 } else {
3176 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
3177 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3178 index 025f742..8432b08 100644
3179 --- a/arch/arm/lib/uaccess_with_memcpy.c
3180 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3181 @@ -104,7 +104,7 @@ out:
3182 }
3183
3184 unsigned long
3185 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3186 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3187 {
3188 /*
3189 * This test is stubbed out of the main function above to keep
3190 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3191 index bac21a5..b67ef8e 100644
3192 --- a/arch/arm/mach-kirkwood/common.c
3193 +++ b/arch/arm/mach-kirkwood/common.c
3194 @@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3195 clk_gate_ops.disable(hw);
3196 }
3197
3198 -static struct clk_ops clk_gate_fn_ops;
3199 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3200 +{
3201 + return clk_gate_ops.is_enabled(hw);
3202 +}
3203 +
3204 +static struct clk_ops clk_gate_fn_ops = {
3205 + .enable = clk_gate_fn_enable,
3206 + .disable = clk_gate_fn_disable,
3207 + .is_enabled = clk_gate_fn_is_enabled,
3208 +};
3209
3210 static struct clk __init *clk_register_gate_fn(struct device *dev,
3211 const char *name,
3212 @@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3213 gate_fn->fn_en = fn_en;
3214 gate_fn->fn_dis = fn_dis;
3215
3216 - /* ops is the gate ops, but with our enable/disable functions */
3217 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3218 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3219 - clk_gate_fn_ops = clk_gate_ops;
3220 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3221 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3222 - }
3223 -
3224 clk = clk_register(dev, &gate_fn->gate.hw);
3225
3226 if (IS_ERR(clk))
3227 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3228 index 0abb30f..54064da 100644
3229 --- a/arch/arm/mach-omap2/board-n8x0.c
3230 +++ b/arch/arm/mach-omap2/board-n8x0.c
3231 @@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3232 }
3233 #endif
3234
3235 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3236 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3237 .late_init = n8x0_menelaus_late_init,
3238 };
3239
3240 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3241 index 5d3b4f4..ddba3c0 100644
3242 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3243 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3244 @@ -340,7 +340,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3245 return NOTIFY_OK;
3246 }
3247
3248 -static struct notifier_block __refdata irq_hotplug_notifier = {
3249 +static struct notifier_block irq_hotplug_notifier = {
3250 .notifier_call = irq_cpu_hotplug_notify,
3251 };
3252
3253 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3254 index 4653efb..8c60bf7 100644
3255 --- a/arch/arm/mach-omap2/omap_hwmod.c
3256 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3257 @@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
3258 int (*init_clkdm)(struct omap_hwmod *oh);
3259 void (*update_context_lost)(struct omap_hwmod *oh);
3260 int (*get_context_lost)(struct omap_hwmod *oh);
3261 -};
3262 +} __no_const;
3263
3264 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3265 -static struct omap_hwmod_soc_ops soc_ops;
3266 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3267
3268 /* omap_hwmod_list contains all registered struct omap_hwmods */
3269 static LIST_HEAD(omap_hwmod_list);
3270 diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3271 index 6be4c4d..32ac32a 100644
3272 --- a/arch/arm/mach-ux500/include/mach/setup.h
3273 +++ b/arch/arm/mach-ux500/include/mach/setup.h
3274 @@ -38,13 +38,6 @@ extern struct sys_timer ux500_timer;
3275 .type = MT_DEVICE, \
3276 }
3277
3278 -#define __MEM_DEV_DESC(x, sz) { \
3279 - .virtual = IO_ADDRESS(x), \
3280 - .pfn = __phys_to_pfn(x), \
3281 - .length = sz, \
3282 - .type = MT_MEMORY, \
3283 -}
3284 -
3285 extern struct smp_operations ux500_smp_ops;
3286 extern void ux500_cpu_die(unsigned int cpu);
3287
3288 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3289 index 3fd629d..8b1aca9 100644
3290 --- a/arch/arm/mm/Kconfig
3291 +++ b/arch/arm/mm/Kconfig
3292 @@ -425,7 +425,7 @@ config CPU_32v5
3293
3294 config CPU_32v6
3295 bool
3296 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3297 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3298 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3299
3300 config CPU_32v6K
3301 @@ -577,6 +577,7 @@ config CPU_CP15_MPU
3302
3303 config CPU_USE_DOMAINS
3304 bool
3305 + depends on !ARM_LPAE && !PAX_KERNEXEC
3306 help
3307 This option enables or disables the use of domain switching
3308 via the set_fs() function.
3309 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3310 index 5dbf13f..6393f55 100644
3311 --- a/arch/arm/mm/fault.c
3312 +++ b/arch/arm/mm/fault.c
3313 @@ -25,6 +25,7 @@
3314 #include <asm/system_misc.h>
3315 #include <asm/system_info.h>
3316 #include <asm/tlbflush.h>
3317 +#include <asm/sections.h>
3318
3319 #include "fault.h"
3320
3321 @@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3322 if (fixup_exception(regs))
3323 return;
3324
3325 +#ifdef CONFIG_PAX_KERNEXEC
3326 + if ((fsr & FSR_WRITE) &&
3327 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3328 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3329 + {
3330 + if (current->signal->curr_ip)
3331 + 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),
3332 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3333 + else
3334 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3335 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
3336 + }
3337 +#endif
3338 +
3339 /*
3340 * No handler, we'll have to terminate things with extreme prejudice.
3341 */
3342 @@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3343 }
3344 #endif
3345
3346 +#ifdef CONFIG_PAX_PAGEEXEC
3347 + if (fsr & FSR_LNX_PF) {
3348 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3349 + do_group_exit(SIGKILL);
3350 + }
3351 +#endif
3352 +
3353 tsk->thread.address = addr;
3354 tsk->thread.error_code = fsr;
3355 tsk->thread.trap_no = 14;
3356 @@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3357 }
3358 #endif /* CONFIG_MMU */
3359
3360 +#ifdef CONFIG_PAX_PAGEEXEC
3361 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3362 +{
3363 + long i;
3364 +
3365 + printk(KERN_ERR "PAX: bytes at PC: ");
3366 + for (i = 0; i < 20; i++) {
3367 + unsigned char c;
3368 + if (get_user(c, (__force unsigned char __user *)pc+i))
3369 + printk(KERN_CONT "?? ");
3370 + else
3371 + printk(KERN_CONT "%02x ", c);
3372 + }
3373 + printk("\n");
3374 +
3375 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3376 + for (i = -1; i < 20; i++) {
3377 + unsigned long c;
3378 + if (get_user(c, (__force unsigned long __user *)sp+i))
3379 + printk(KERN_CONT "???????? ");
3380 + else
3381 + printk(KERN_CONT "%08lx ", c);
3382 + }
3383 + printk("\n");
3384 +}
3385 +#endif
3386 +
3387 /*
3388 * First Level Translation Fault Handler
3389 *
3390 @@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3391 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3392 struct siginfo info;
3393
3394 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3395 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3396 + if (current->signal->curr_ip)
3397 + 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),
3398 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3399 + else
3400 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3401 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()), addr);
3402 + goto die;
3403 + }
3404 +#endif
3405 +
3406 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3407 return;
3408
3409 +die:
3410 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3411 inf->name, fsr, addr);
3412
3413 @@ -575,9 +637,38 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3414 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3415 struct siginfo info;
3416
3417 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3418 + if (!user_mode(regs) && (is_domain_fault(ifsr) || is_xn_fault(ifsr))) {
3419 + if (current->signal->curr_ip)
3420 + 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),
3421 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3422 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3423 + else
3424 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3425 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()),
3426 + addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3427 + goto die;
3428 + }
3429 +#endif
3430 +
3431 +#ifdef CONFIG_PAX_REFCOUNT
3432 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3433 + unsigned int bkpt;
3434 +
3435 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3436 + current->thread.error_code = ifsr;
3437 + current->thread.trap_no = 0;
3438 + pax_report_refcount_overflow(regs);
3439 + fixup_exception(regs);
3440 + return;
3441 + }
3442 + }
3443 +#endif
3444 +
3445 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3446 return;
3447
3448 +die:
3449 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3450 inf->name, ifsr, addr);
3451
3452 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3453 index cf08bdf..772656c 100644
3454 --- a/arch/arm/mm/fault.h
3455 +++ b/arch/arm/mm/fault.h
3456 @@ -3,6 +3,7 @@
3457
3458 /*
3459 * Fault status register encodings. We steal bit 31 for our own purposes.
3460 + * Set when the FSR value is from an instruction fault.
3461 */
3462 #define FSR_LNX_PF (1 << 31)
3463 #define FSR_WRITE (1 << 11)
3464 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3465 }
3466 #endif
3467
3468 +/* valid for LPAE and !LPAE */
3469 +static inline int is_xn_fault(unsigned int fsr)
3470 +{
3471 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
3472 +}
3473 +
3474 +static inline int is_domain_fault(unsigned int fsr)
3475 +{
3476 + return ((fsr_fs(fsr) & 0xD) == 0x9);
3477 +}
3478 +
3479 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3480 unsigned long search_exception_table(unsigned long addr);
3481
3482 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3483 index ad722f1..763fdd3 100644
3484 --- a/arch/arm/mm/init.c
3485 +++ b/arch/arm/mm/init.c
3486 @@ -30,6 +30,8 @@
3487 #include <asm/setup.h>
3488 #include <asm/tlb.h>
3489 #include <asm/fixmap.h>
3490 +#include <asm/system_info.h>
3491 +#include <asm/cp15.h>
3492
3493 #include <asm/mach/arch.h>
3494 #include <asm/mach/map.h>
3495 @@ -736,7 +738,46 @@ void free_initmem(void)
3496 {
3497 #ifdef CONFIG_HAVE_TCM
3498 extern char __tcm_start, __tcm_end;
3499 +#endif
3500
3501 +#ifdef CONFIG_PAX_KERNEXEC
3502 + unsigned long addr;
3503 + pgd_t *pgd;
3504 + pud_t *pud;
3505 + pmd_t *pmd;
3506 + int cpu_arch = cpu_architecture();
3507 + unsigned int cr = get_cr();
3508 +
3509 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3510 + /* make pages tables, etc before .text NX */
3511 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3512 + pgd = pgd_offset_k(addr);
3513 + pud = pud_offset(pgd, addr);
3514 + pmd = pmd_offset(pud, addr);
3515 + __section_update(pmd, addr, PMD_SECT_XN);
3516 + }
3517 + /* make init NX */
3518 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3519 + pgd = pgd_offset_k(addr);
3520 + pud = pud_offset(pgd, addr);
3521 + pmd = pmd_offset(pud, addr);
3522 + __section_update(pmd, addr, PMD_SECT_XN);
3523 + }
3524 + /* make kernel code/rodata RX */
3525 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3526 + pgd = pgd_offset_k(addr);
3527 + pud = pud_offset(pgd, addr);
3528 + pmd = pmd_offset(pud, addr);
3529 +#ifdef CONFIG_ARM_LPAE
3530 + __section_update(pmd, addr, PMD_SECT_RDONLY);
3531 +#else
3532 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3533 +#endif
3534 + }
3535 + }
3536 +#endif
3537 +
3538 +#ifdef CONFIG_HAVE_TCM
3539 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3540 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3541 __phys_to_pfn(__pa(&__tcm_end)),
3542 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3543 index 88fd86c..7a224ce 100644
3544 --- a/arch/arm/mm/ioremap.c
3545 +++ b/arch/arm/mm/ioremap.c
3546 @@ -335,9 +335,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3547 unsigned int mtype;
3548
3549 if (cached)
3550 - mtype = MT_MEMORY;
3551 + mtype = MT_MEMORY_RX;
3552 else
3553 - mtype = MT_MEMORY_NONCACHED;
3554 + mtype = MT_MEMORY_NONCACHED_RX;
3555
3556 return __arm_ioremap_caller(phys_addr, size, mtype,
3557 __builtin_return_address(0));
3558 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3559 index 10062ce..aa96dd7 100644
3560 --- a/arch/arm/mm/mmap.c
3561 +++ b/arch/arm/mm/mmap.c
3562 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3563 struct vm_area_struct *vma;
3564 int do_align = 0;
3565 int aliasing = cache_is_vipt_aliasing();
3566 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3567 struct vm_unmapped_area_info info;
3568
3569 /*
3570 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3571 if (len > TASK_SIZE)
3572 return -ENOMEM;
3573
3574 +#ifdef CONFIG_PAX_RANDMMAP
3575 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3576 +#endif
3577 +
3578 if (addr) {
3579 if (do_align)
3580 addr = COLOUR_ALIGN(addr, pgoff);
3581 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3582 addr = PAGE_ALIGN(addr);
3583
3584 vma = find_vma(mm, addr);
3585 - if (TASK_SIZE - len >= addr &&
3586 - (!vma || addr + len <= vma->vm_start))
3587 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3588 return addr;
3589 }
3590
3591 @@ -112,6 +116,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3592 unsigned long addr = addr0;
3593 int do_align = 0;
3594 int aliasing = cache_is_vipt_aliasing();
3595 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3596 struct vm_unmapped_area_info info;
3597
3598 /*
3599 @@ -132,6 +137,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3600 return addr;
3601 }
3602
3603 +#ifdef CONFIG_PAX_RANDMMAP
3604 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3605 +#endif
3606 +
3607 /* requesting a specific address */
3608 if (addr) {
3609 if (do_align)
3610 @@ -139,8 +148,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3611 else
3612 addr = PAGE_ALIGN(addr);
3613 vma = find_vma(mm, addr);
3614 - if (TASK_SIZE - len >= addr &&
3615 - (!vma || addr + len <= vma->vm_start))
3616 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3617 return addr;
3618 }
3619
3620 @@ -162,6 +170,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3621 VM_BUG_ON(addr != -ENOMEM);
3622 info.flags = 0;
3623 info.low_limit = mm->mmap_base;
3624 +
3625 +#ifdef CONFIG_PAX_RANDMMAP
3626 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3627 + info.low_limit += mm->delta_mmap;
3628 +#endif
3629 +
3630 info.high_limit = TASK_SIZE;
3631 addr = vm_unmapped_area(&info);
3632 }
3633 @@ -173,6 +187,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3634 {
3635 unsigned long random_factor = 0UL;
3636
3637 +#ifdef CONFIG_PAX_RANDMMAP
3638 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3639 +#endif
3640 +
3641 /* 8 bits of randomness in 20 address space bits */
3642 if ((current->flags & PF_RANDOMIZE) &&
3643 !(current->personality & ADDR_NO_RANDOMIZE))
3644 @@ -180,10 +198,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3645
3646 if (mmap_is_legacy()) {
3647 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3648 +
3649 +#ifdef CONFIG_PAX_RANDMMAP
3650 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3651 + mm->mmap_base += mm->delta_mmap;
3652 +#endif
3653 +
3654 mm->get_unmapped_area = arch_get_unmapped_area;
3655 mm->unmap_area = arch_unmap_area;
3656 } else {
3657 mm->mmap_base = mmap_base(random_factor);
3658 +
3659 +#ifdef CONFIG_PAX_RANDMMAP
3660 + if (mm->pax_flags & MF_PAX_RANDMMAP)
3661 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3662 +#endif
3663 +
3664 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3665 mm->unmap_area = arch_unmap_area_topdown;
3666 }
3667 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3668 index ce328c7..f82bebb 100644
3669 --- a/arch/arm/mm/mmu.c
3670 +++ b/arch/arm/mm/mmu.c
3671 @@ -35,6 +35,23 @@
3672
3673 #include "mm.h"
3674
3675 +
3676 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3677 +void modify_domain(unsigned int dom, unsigned int type)
3678 +{
3679 + struct thread_info *thread = current_thread_info();
3680 + unsigned int domain = thread->cpu_domain;
3681 + /*
3682 + * DOMAIN_MANAGER might be defined to some other value,
3683 + * use the arch-defined constant
3684 + */
3685 + domain &= ~domain_val(dom, 3);
3686 + thread->cpu_domain = domain | domain_val(dom, type);
3687 + set_domain(thread->cpu_domain);
3688 +}
3689 +EXPORT_SYMBOL(modify_domain);
3690 +#endif
3691 +
3692 /*
3693 * empty_zero_page is a special page that is used for
3694 * zero-initialized data and COW.
3695 @@ -195,10 +212,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3696 }
3697 #endif
3698
3699 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3700 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3701 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3702
3703 -static struct mem_type mem_types[] = {
3704 +#ifdef CONFIG_PAX_KERNEXEC
3705 +#define L_PTE_KERNEXEC L_PTE_RDONLY
3706 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3707 +#else
3708 +#define L_PTE_KERNEXEC L_PTE_DIRTY
3709 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3710 +#endif
3711 +
3712 +static struct mem_type mem_types[] __read_only = {
3713 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3714 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3715 L_PTE_SHARED,
3716 @@ -227,16 +252,16 @@ static struct mem_type mem_types[] = {
3717 [MT_UNCACHED] = {
3718 .prot_pte = PROT_PTE_DEVICE,
3719 .prot_l1 = PMD_TYPE_TABLE,
3720 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3721 + .prot_sect = PROT_SECT_DEVICE,
3722 .domain = DOMAIN_IO,
3723 },
3724 [MT_CACHECLEAN] = {
3725 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3726 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3727 .domain = DOMAIN_KERNEL,
3728 },
3729 #ifndef CONFIG_ARM_LPAE
3730 [MT_MINICLEAN] = {
3731 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3732 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3733 .domain = DOMAIN_KERNEL,
3734 },
3735 #endif
3736 @@ -244,36 +269,54 @@ static struct mem_type mem_types[] = {
3737 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3738 L_PTE_RDONLY,
3739 .prot_l1 = PMD_TYPE_TABLE,
3740 - .domain = DOMAIN_USER,
3741 + .domain = DOMAIN_VECTORS,
3742 },
3743 [MT_HIGH_VECTORS] = {
3744 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3745 L_PTE_USER | L_PTE_RDONLY,
3746 .prot_l1 = PMD_TYPE_TABLE,
3747 - .domain = DOMAIN_USER,
3748 + .domain = DOMAIN_VECTORS,
3749 },
3750 - [MT_MEMORY] = {
3751 + [MT_MEMORY_RWX] = {
3752 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3753 .prot_l1 = PMD_TYPE_TABLE,
3754 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3755 .domain = DOMAIN_KERNEL,
3756 },
3757 + [MT_MEMORY_RW] = {
3758 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3759 + .prot_l1 = PMD_TYPE_TABLE,
3760 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3761 + .domain = DOMAIN_KERNEL,
3762 + },
3763 + [MT_MEMORY_RX] = {
3764 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
3765 + .prot_l1 = PMD_TYPE_TABLE,
3766 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3767 + .domain = DOMAIN_KERNEL,
3768 + },
3769 [MT_ROM] = {
3770 - .prot_sect = PMD_TYPE_SECT,
3771 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3772 .domain = DOMAIN_KERNEL,
3773 },
3774 - [MT_MEMORY_NONCACHED] = {
3775 + [MT_MEMORY_NONCACHED_RW] = {
3776 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3777 L_PTE_MT_BUFFERABLE,
3778 .prot_l1 = PMD_TYPE_TABLE,
3779 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
3780 .domain = DOMAIN_KERNEL,
3781 },
3782 + [MT_MEMORY_NONCACHED_RX] = {
3783 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
3784 + L_PTE_MT_BUFFERABLE,
3785 + .prot_l1 = PMD_TYPE_TABLE,
3786 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
3787 + .domain = DOMAIN_KERNEL,
3788 + },
3789 [MT_MEMORY_DTCM] = {
3790 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3791 - L_PTE_XN,
3792 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3793 .prot_l1 = PMD_TYPE_TABLE,
3794 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3795 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3796 .domain = DOMAIN_KERNEL,
3797 },
3798 [MT_MEMORY_ITCM] = {
3799 @@ -283,10 +326,10 @@ static struct mem_type mem_types[] = {
3800 },
3801 [MT_MEMORY_SO] = {
3802 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3803 - L_PTE_MT_UNCACHED | L_PTE_XN,
3804 + L_PTE_MT_UNCACHED,
3805 .prot_l1 = PMD_TYPE_TABLE,
3806 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
3807 - PMD_SECT_UNCACHED | PMD_SECT_XN,
3808 + PMD_SECT_UNCACHED,
3809 .domain = DOMAIN_KERNEL,
3810 },
3811 [MT_MEMORY_DMA_READY] = {
3812 @@ -371,9 +414,35 @@ static void __init build_mem_type_table(void)
3813 * to prevent speculative instruction fetches.
3814 */
3815 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
3816 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
3817 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
3818 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
3819 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
3820 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
3821 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
3822 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
3823 +
3824 + /* Mark other regions on ARMv6+ as execute-never */
3825 +
3826 +#ifdef CONFIG_PAX_KERNEXEC
3827 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
3828 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
3829 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
3830 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
3831 +#ifndef CONFIG_ARM_LPAE
3832 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
3833 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
3834 +#endif
3835 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
3836 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
3837 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
3838 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
3839 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
3840 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
3841 +#endif
3842 +
3843 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
3844 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
3845 }
3846 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3847 /*
3848 @@ -432,6 +501,9 @@ static void __init build_mem_type_table(void)
3849 * from SVC mode and no access from userspace.
3850 */
3851 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3852 +#ifdef CONFIG_PAX_KERNEXEC
3853 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3854 +#endif
3855 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3856 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
3857 #endif
3858 @@ -448,11 +520,17 @@ static void __init build_mem_type_table(void)
3859 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
3860 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
3861 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
3862 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
3863 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
3864 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
3865 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
3866 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
3867 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
3868 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
3869 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
3870 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
3871 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
3872 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
3873 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
3874 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
3875 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
3876 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
3877 }
3878 }
3879
3880 @@ -463,15 +541,20 @@ static void __init build_mem_type_table(void)
3881 if (cpu_arch >= CPU_ARCH_ARMv6) {
3882 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
3883 /* Non-cacheable Normal is XCB = 001 */
3884 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3885 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3886 + PMD_SECT_BUFFERED;
3887 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3888 PMD_SECT_BUFFERED;
3889 } else {
3890 /* For both ARMv6 and non-TEX-remapping ARMv7 */
3891 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
3892 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
3893 + PMD_SECT_TEX(1);
3894 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
3895 PMD_SECT_TEX(1);
3896 }
3897 } else {
3898 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
3899 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
3900 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
3901 }
3902
3903 #ifdef CONFIG_ARM_LPAE
3904 @@ -487,6 +570,8 @@ static void __init build_mem_type_table(void)
3905 vecs_pgprot |= PTE_EXT_AF;
3906 #endif
3907
3908 + user_pgprot |= __supported_pte_mask;
3909 +
3910 for (i = 0; i < 16; i++) {
3911 pteval_t v = pgprot_val(protection_map[i]);
3912 protection_map[i] = __pgprot(v | user_pgprot);
3913 @@ -501,10 +586,15 @@ static void __init build_mem_type_table(void)
3914
3915 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
3916 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
3917 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
3918 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
3919 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
3920 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
3921 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
3922 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
3923 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
3924 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
3925 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
3926 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
3927 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
3928 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
3929 mem_types[MT_ROM].prot_sect |= cp->pmd;
3930
3931 switch (cp->pmd) {
3932 @@ -1105,18 +1195,15 @@ void __init arm_mm_memblock_reserve(void)
3933 * called function. This means you can't use any function or debugging
3934 * method which may touch any device, otherwise the kernel _will_ crash.
3935 */
3936 +
3937 +static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
3938 +
3939 static void __init devicemaps_init(struct machine_desc *mdesc)
3940 {
3941 struct map_desc map;
3942 unsigned long addr;
3943 - void *vectors;
3944
3945 - /*
3946 - * Allocate the vector page early.
3947 - */
3948 - vectors = early_alloc(PAGE_SIZE);
3949 -
3950 - early_trap_init(vectors);
3951 + early_trap_init(&vectors);
3952
3953 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
3954 pmd_clear(pmd_off_k(addr));
3955 @@ -1156,7 +1243,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
3956 * location (0xffff0000). If we aren't using high-vectors, also
3957 * create a mapping at the low-vectors virtual address.
3958 */
3959 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
3960 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
3961 map.virtual = 0xffff0000;
3962 map.length = PAGE_SIZE;
3963 map.type = MT_HIGH_VECTORS;
3964 @@ -1214,8 +1301,39 @@ static void __init map_lowmem(void)
3965 map.pfn = __phys_to_pfn(start);
3966 map.virtual = __phys_to_virt(start);
3967 map.length = end - start;
3968 - map.type = MT_MEMORY;
3969
3970 +#ifdef CONFIG_PAX_KERNEXEC
3971 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
3972 + struct map_desc kernel;
3973 + struct map_desc initmap;
3974 +
3975 + /* when freeing initmem we will make this RW */
3976 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
3977 + initmap.virtual = (unsigned long)__init_begin;
3978 + initmap.length = _sdata - __init_begin;
3979 + initmap.type = MT_MEMORY_RWX;
3980 + create_mapping(&initmap);
3981 +
3982 + /* when freeing initmem we will make this RX */
3983 + kernel.pfn = __phys_to_pfn(__pa(_stext));
3984 + kernel.virtual = (unsigned long)_stext;
3985 + kernel.length = __init_begin - _stext;
3986 + kernel.type = MT_MEMORY_RWX;
3987 + create_mapping(&kernel);
3988 +
3989 + if (map.virtual < (unsigned long)_stext) {
3990 + map.length = (unsigned long)_stext - map.virtual;
3991 + map.type = MT_MEMORY_RWX;
3992 + create_mapping(&map);
3993 + }
3994 +
3995 + map.pfn = __phys_to_pfn(__pa(_sdata));
3996 + map.virtual = (unsigned long)_sdata;
3997 + map.length = end - __pa(_sdata);
3998 + }
3999 +#endif
4000 +
4001 + map.type = MT_MEMORY_RW;
4002 create_mapping(&map);
4003 }
4004 }
4005 diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4006 index 6d98c13..3cfb174 100644
4007 --- a/arch/arm/mm/proc-v7-2level.S
4008 +++ b/arch/arm/mm/proc-v7-2level.S
4009 @@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4010 tst r1, #L_PTE_XN
4011 orrne r3, r3, #PTE_EXT_XN
4012
4013 + tst r1, #L_PTE_PXN
4014 + orrne r3, r3, #PTE_EXT_PXN
4015 +
4016 tst r1, #L_PTE_YOUNG
4017 tstne r1, #L_PTE_VALID
4018 #ifndef CONFIG_CPU_USE_DOMAINS
4019 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4020 index a5bc92d..0bb4730 100644
4021 --- a/arch/arm/plat-omap/sram.c
4022 +++ b/arch/arm/plat-omap/sram.c
4023 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4024 * Looks like we need to preserve some bootloader code at the
4025 * beginning of SRAM for jumping to flash for reboot to work...
4026 */
4027 + pax_open_kernel();
4028 memset_io(omap_sram_base + omap_sram_skip, 0,
4029 omap_sram_size - omap_sram_skip);
4030 + pax_close_kernel();
4031 }
4032 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
4033 index b76c065..b6e766b 100644
4034 --- a/arch/arm/plat-orion/include/plat/addr-map.h
4035 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
4036 @@ -27,7 +27,7 @@ struct orion_addr_map_cfg {
4037 value in bridge_virt_base */
4038 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
4039 const int win);
4040 -};
4041 +} __no_const;
4042
4043 /*
4044 * Information needed to setup one address mapping.
4045 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4046 index f5144cd..71f6d1f 100644
4047 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4048 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4049 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4050 int (*started)(unsigned ch);
4051 int (*flush)(unsigned ch);
4052 int (*stop)(unsigned ch);
4053 -};
4054 +} __no_const;
4055
4056 extern void *samsung_dmadev_get_ops(void);
4057 extern void *s3c_dma_get_ops(void);
4058 diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4059 index 0c3ba9f..95722b3 100644
4060 --- a/arch/arm64/kernel/debug-monitors.c
4061 +++ b/arch/arm64/kernel/debug-monitors.c
4062 @@ -151,7 +151,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4063 return NOTIFY_OK;
4064 }
4065
4066 -static struct notifier_block __cpuinitdata os_lock_nb = {
4067 +static struct notifier_block os_lock_nb = {
4068 .notifier_call = os_lock_notify,
4069 };
4070
4071 diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4072 index 5ab825c..96aaec8 100644
4073 --- a/arch/arm64/kernel/hw_breakpoint.c
4074 +++ b/arch/arm64/kernel/hw_breakpoint.c
4075 @@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4076 return NOTIFY_OK;
4077 }
4078
4079 -static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4080 +static struct notifier_block hw_breakpoint_reset_nb = {
4081 .notifier_call = hw_breakpoint_reset_notify,
4082 };
4083
4084 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4085 index c3a58a1..78fbf54 100644
4086 --- a/arch/avr32/include/asm/cache.h
4087 +++ b/arch/avr32/include/asm/cache.h
4088 @@ -1,8 +1,10 @@
4089 #ifndef __ASM_AVR32_CACHE_H
4090 #define __ASM_AVR32_CACHE_H
4091
4092 +#include <linux/const.h>
4093 +
4094 #define L1_CACHE_SHIFT 5
4095 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4096 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4097
4098 /*
4099 * Memory returned by kmalloc() may be used for DMA, so we must make
4100 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4101 index e2c3287..6c4f98c 100644
4102 --- a/arch/avr32/include/asm/elf.h
4103 +++ b/arch/avr32/include/asm/elf.h
4104 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4105 the loader. We need to make sure that it is out of the way of the program
4106 that it will "exec", and that there is sufficient room for the brk. */
4107
4108 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4109 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4110
4111 +#ifdef CONFIG_PAX_ASLR
4112 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4113 +
4114 +#define PAX_DELTA_MMAP_LEN 15
4115 +#define PAX_DELTA_STACK_LEN 15
4116 +#endif
4117
4118 /* This yields a mask that user programs can use to figure out what
4119 instruction set this CPU supports. This could be done in user space,
4120 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4121 index 479330b..53717a8 100644
4122 --- a/arch/avr32/include/asm/kmap_types.h
4123 +++ b/arch/avr32/include/asm/kmap_types.h
4124 @@ -2,9 +2,9 @@
4125 #define __ASM_AVR32_KMAP_TYPES_H
4126
4127 #ifdef CONFIG_DEBUG_HIGHMEM
4128 -# define KM_TYPE_NR 29
4129 +# define KM_TYPE_NR 30
4130 #else
4131 -# define KM_TYPE_NR 14
4132 +# define KM_TYPE_NR 15
4133 #endif
4134
4135 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4136 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4137 index b2f2d2d..d1c85cb 100644
4138 --- a/arch/avr32/mm/fault.c
4139 +++ b/arch/avr32/mm/fault.c
4140 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4141
4142 int exception_trace = 1;
4143
4144 +#ifdef CONFIG_PAX_PAGEEXEC
4145 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4146 +{
4147 + unsigned long i;
4148 +
4149 + printk(KERN_ERR "PAX: bytes at PC: ");
4150 + for (i = 0; i < 20; i++) {
4151 + unsigned char c;
4152 + if (get_user(c, (unsigned char *)pc+i))
4153 + printk(KERN_CONT "???????? ");
4154 + else
4155 + printk(KERN_CONT "%02x ", c);
4156 + }
4157 + printk("\n");
4158 +}
4159 +#endif
4160 +
4161 /*
4162 * This routine handles page faults. It determines the address and the
4163 * problem, and then passes it off to one of the appropriate routines.
4164 @@ -174,6 +191,16 @@ bad_area:
4165 up_read(&mm->mmap_sem);
4166
4167 if (user_mode(regs)) {
4168 +
4169 +#ifdef CONFIG_PAX_PAGEEXEC
4170 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4171 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4172 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4173 + do_group_exit(SIGKILL);
4174 + }
4175 + }
4176 +#endif
4177 +
4178 if (exception_trace && printk_ratelimit())
4179 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4180 "sp %08lx ecr %lu\n",
4181 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4182 index 568885a..f8008df 100644
4183 --- a/arch/blackfin/include/asm/cache.h
4184 +++ b/arch/blackfin/include/asm/cache.h
4185 @@ -7,6 +7,7 @@
4186 #ifndef __ARCH_BLACKFIN_CACHE_H
4187 #define __ARCH_BLACKFIN_CACHE_H
4188
4189 +#include <linux/const.h>
4190 #include <linux/linkage.h> /* for asmlinkage */
4191
4192 /*
4193 @@ -14,7 +15,7 @@
4194 * Blackfin loads 32 bytes for cache
4195 */
4196 #define L1_CACHE_SHIFT 5
4197 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4198 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4199 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4200
4201 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4202 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4203 index aea2718..3639a60 100644
4204 --- a/arch/cris/include/arch-v10/arch/cache.h
4205 +++ b/arch/cris/include/arch-v10/arch/cache.h
4206 @@ -1,8 +1,9 @@
4207 #ifndef _ASM_ARCH_CACHE_H
4208 #define _ASM_ARCH_CACHE_H
4209
4210 +#include <linux/const.h>
4211 /* Etrax 100LX have 32-byte cache-lines. */
4212 -#define L1_CACHE_BYTES 32
4213 #define L1_CACHE_SHIFT 5
4214 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4215
4216 #endif /* _ASM_ARCH_CACHE_H */
4217 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4218 index 7caf25d..ee65ac5 100644
4219 --- a/arch/cris/include/arch-v32/arch/cache.h
4220 +++ b/arch/cris/include/arch-v32/arch/cache.h
4221 @@ -1,11 +1,12 @@
4222 #ifndef _ASM_CRIS_ARCH_CACHE_H
4223 #define _ASM_CRIS_ARCH_CACHE_H
4224
4225 +#include <linux/const.h>
4226 #include <arch/hwregs/dma.h>
4227
4228 /* A cache-line is 32 bytes. */
4229 -#define L1_CACHE_BYTES 32
4230 #define L1_CACHE_SHIFT 5
4231 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4232
4233 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4234
4235 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4236 index b86329d..6709906 100644
4237 --- a/arch/frv/include/asm/atomic.h
4238 +++ b/arch/frv/include/asm/atomic.h
4239 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4240 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4241 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4242
4243 +#define atomic64_read_unchecked(v) atomic64_read(v)
4244 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4245 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4246 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4247 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4248 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4249 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4250 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4251 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4252 +
4253 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4254 {
4255 int c, old;
4256 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4257 index 2797163..c2a401d 100644
4258 --- a/arch/frv/include/asm/cache.h
4259 +++ b/arch/frv/include/asm/cache.h
4260 @@ -12,10 +12,11 @@
4261 #ifndef __ASM_CACHE_H
4262 #define __ASM_CACHE_H
4263
4264 +#include <linux/const.h>
4265
4266 /* bytes per L1 cache line */
4267 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4268 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4269 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4270
4271 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4272 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4273 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4274 index 43901f2..0d8b865 100644
4275 --- a/arch/frv/include/asm/kmap_types.h
4276 +++ b/arch/frv/include/asm/kmap_types.h
4277 @@ -2,6 +2,6 @@
4278 #ifndef _ASM_KMAP_TYPES_H
4279 #define _ASM_KMAP_TYPES_H
4280
4281 -#define KM_TYPE_NR 17
4282 +#define KM_TYPE_NR 18
4283
4284 #endif
4285 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4286 index 385fd30..3aaf4fe 100644
4287 --- a/arch/frv/mm/elf-fdpic.c
4288 +++ b/arch/frv/mm/elf-fdpic.c
4289 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4290 {
4291 struct vm_area_struct *vma;
4292 unsigned long limit;
4293 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4294
4295 if (len > TASK_SIZE)
4296 return -ENOMEM;
4297 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4298 if (addr) {
4299 addr = PAGE_ALIGN(addr);
4300 vma = find_vma(current->mm, addr);
4301 - if (TASK_SIZE - len >= addr &&
4302 - (!vma || addr + len <= vma->vm_start))
4303 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4304 goto success;
4305 }
4306
4307 @@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4308 for (; vma; vma = vma->vm_next) {
4309 if (addr > limit)
4310 break;
4311 - if (addr + len <= vma->vm_start)
4312 + if (check_heap_stack_gap(vma, addr, len, offset))
4313 goto success;
4314 addr = vma->vm_end;
4315 }
4316 @@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4317 for (; vma; vma = vma->vm_next) {
4318 if (addr > limit)
4319 break;
4320 - if (addr + len <= vma->vm_start)
4321 + if (check_heap_stack_gap(vma, addr, len, offset))
4322 goto success;
4323 addr = vma->vm_end;
4324 }
4325 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4326 index f4ca594..adc72fd6 100644
4327 --- a/arch/hexagon/include/asm/cache.h
4328 +++ b/arch/hexagon/include/asm/cache.h
4329 @@ -21,9 +21,11 @@
4330 #ifndef __ASM_CACHE_H
4331 #define __ASM_CACHE_H
4332
4333 +#include <linux/const.h>
4334 +
4335 /* Bytes per L1 cache line */
4336 -#define L1_CACHE_SHIFT (5)
4337 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4338 +#define L1_CACHE_SHIFT 5
4339 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4340
4341 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4342 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4343 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4344 index 6e6fe18..a6ae668 100644
4345 --- a/arch/ia64/include/asm/atomic.h
4346 +++ b/arch/ia64/include/asm/atomic.h
4347 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4348 #define atomic64_inc(v) atomic64_add(1, (v))
4349 #define atomic64_dec(v) atomic64_sub(1, (v))
4350
4351 +#define atomic64_read_unchecked(v) atomic64_read(v)
4352 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4353 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4354 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4355 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4356 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4357 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4358 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4359 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4360 +
4361 /* Atomic operations are already serializing */
4362 #define smp_mb__before_atomic_dec() barrier()
4363 #define smp_mb__after_atomic_dec() barrier()
4364 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4365 index 988254a..e1ee885 100644
4366 --- a/arch/ia64/include/asm/cache.h
4367 +++ b/arch/ia64/include/asm/cache.h
4368 @@ -1,6 +1,7 @@
4369 #ifndef _ASM_IA64_CACHE_H
4370 #define _ASM_IA64_CACHE_H
4371
4372 +#include <linux/const.h>
4373
4374 /*
4375 * Copyright (C) 1998-2000 Hewlett-Packard Co
4376 @@ -9,7 +10,7 @@
4377
4378 /* Bytes per L1 (data) cache line. */
4379 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4380 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4381 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4382
4383 #ifdef CONFIG_SMP
4384 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4385 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4386 index b5298eb..67c6e62 100644
4387 --- a/arch/ia64/include/asm/elf.h
4388 +++ b/arch/ia64/include/asm/elf.h
4389 @@ -42,6 +42,13 @@
4390 */
4391 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4392
4393 +#ifdef CONFIG_PAX_ASLR
4394 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4395 +
4396 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4397 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4398 +#endif
4399 +
4400 #define PT_IA_64_UNWIND 0x70000001
4401
4402 /* IA-64 relocations: */
4403 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4404 index 96a8d92..617a1cf 100644
4405 --- a/arch/ia64/include/asm/pgalloc.h
4406 +++ b/arch/ia64/include/asm/pgalloc.h
4407 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4408 pgd_val(*pgd_entry) = __pa(pud);
4409 }
4410
4411 +static inline void
4412 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4413 +{
4414 + pgd_populate(mm, pgd_entry, pud);
4415 +}
4416 +
4417 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4418 {
4419 return quicklist_alloc(0, GFP_KERNEL, NULL);
4420 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4421 pud_val(*pud_entry) = __pa(pmd);
4422 }
4423
4424 +static inline void
4425 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4426 +{
4427 + pud_populate(mm, pud_entry, pmd);
4428 +}
4429 +
4430 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4431 {
4432 return quicklist_alloc(0, GFP_KERNEL, NULL);
4433 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4434 index 815810c..d60bd4c 100644
4435 --- a/arch/ia64/include/asm/pgtable.h
4436 +++ b/arch/ia64/include/asm/pgtable.h
4437 @@ -12,7 +12,7 @@
4438 * David Mosberger-Tang <davidm@hpl.hp.com>
4439 */
4440
4441 -
4442 +#include <linux/const.h>
4443 #include <asm/mman.h>
4444 #include <asm/page.h>
4445 #include <asm/processor.h>
4446 @@ -142,6 +142,17 @@
4447 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4448 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4449 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4450 +
4451 +#ifdef CONFIG_PAX_PAGEEXEC
4452 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4453 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4454 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4455 +#else
4456 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
4457 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
4458 +# define PAGE_COPY_NOEXEC PAGE_COPY
4459 +#endif
4460 +
4461 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4462 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4463 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4464 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4465 index 54ff557..70c88b7 100644
4466 --- a/arch/ia64/include/asm/spinlock.h
4467 +++ b/arch/ia64/include/asm/spinlock.h
4468 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4469 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4470
4471 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4472 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4473 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4474 }
4475
4476 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4477 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4478 index 449c8c0..50cdf87 100644
4479 --- a/arch/ia64/include/asm/uaccess.h
4480 +++ b/arch/ia64/include/asm/uaccess.h
4481 @@ -42,6 +42,8 @@
4482 #include <asm/pgtable.h>
4483 #include <asm/io.h>
4484
4485 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
4486 +
4487 /*
4488 * For historical reasons, the following macros are grossly misnamed:
4489 */
4490 @@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4491 static inline unsigned long
4492 __copy_to_user (void __user *to, const void *from, unsigned long count)
4493 {
4494 + if (count > INT_MAX)
4495 + return count;
4496 +
4497 + if (!__builtin_constant_p(count))
4498 + check_object_size(from, count, true);
4499 +
4500 return __copy_user(to, (__force void __user *) from, count);
4501 }
4502
4503 static inline unsigned long
4504 __copy_from_user (void *to, const void __user *from, unsigned long count)
4505 {
4506 + if (count > INT_MAX)
4507 + return count;
4508 +
4509 + if (!__builtin_constant_p(count))
4510 + check_object_size(to, count, false);
4511 +
4512 return __copy_user((__force void __user *) to, from, count);
4513 }
4514
4515 @@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4516 ({ \
4517 void __user *__cu_to = (to); \
4518 const void *__cu_from = (from); \
4519 - long __cu_len = (n); \
4520 + unsigned long __cu_len = (n); \
4521 \
4522 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
4523 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4524 + if (!__builtin_constant_p(n)) \
4525 + check_object_size(__cu_from, __cu_len, true); \
4526 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4527 + } \
4528 __cu_len; \
4529 })
4530
4531 @@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4532 ({ \
4533 void *__cu_to = (to); \
4534 const void __user *__cu_from = (from); \
4535 - long __cu_len = (n); \
4536 + unsigned long __cu_len = (n); \
4537 \
4538 __chk_user_ptr(__cu_from); \
4539 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
4540 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4541 + if (!__builtin_constant_p(n)) \
4542 + check_object_size(__cu_to, __cu_len, false); \
4543 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4544 + } \
4545 __cu_len; \
4546 })
4547
4548 diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4549 index 2d67317..07d8bfa 100644
4550 --- a/arch/ia64/kernel/err_inject.c
4551 +++ b/arch/ia64/kernel/err_inject.c
4552 @@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4553 return NOTIFY_OK;
4554 }
4555
4556 -static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4557 +static struct notifier_block err_inject_cpu_notifier =
4558 {
4559 .notifier_call = err_inject_cpu_callback,
4560 };
4561 diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4562 index 65bf9cd..794f06b 100644
4563 --- a/arch/ia64/kernel/mca.c
4564 +++ b/arch/ia64/kernel/mca.c
4565 @@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4566 return NOTIFY_OK;
4567 }
4568
4569 -static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4570 +static struct notifier_block mca_cpu_notifier = {
4571 .notifier_call = mca_cpu_callback
4572 };
4573
4574 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4575 index 24603be..948052d 100644
4576 --- a/arch/ia64/kernel/module.c
4577 +++ b/arch/ia64/kernel/module.c
4578 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4579 void
4580 module_free (struct module *mod, void *module_region)
4581 {
4582 - if (mod && mod->arch.init_unw_table &&
4583 - module_region == mod->module_init) {
4584 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4585 unw_remove_unwind_table(mod->arch.init_unw_table);
4586 mod->arch.init_unw_table = NULL;
4587 }
4588 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4589 }
4590
4591 static inline int
4592 +in_init_rx (const struct module *mod, uint64_t addr)
4593 +{
4594 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4595 +}
4596 +
4597 +static inline int
4598 +in_init_rw (const struct module *mod, uint64_t addr)
4599 +{
4600 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4601 +}
4602 +
4603 +static inline int
4604 in_init (const struct module *mod, uint64_t addr)
4605 {
4606 - return addr - (uint64_t) mod->module_init < mod->init_size;
4607 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4608 +}
4609 +
4610 +static inline int
4611 +in_core_rx (const struct module *mod, uint64_t addr)
4612 +{
4613 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4614 +}
4615 +
4616 +static inline int
4617 +in_core_rw (const struct module *mod, uint64_t addr)
4618 +{
4619 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4620 }
4621
4622 static inline int
4623 in_core (const struct module *mod, uint64_t addr)
4624 {
4625 - return addr - (uint64_t) mod->module_core < mod->core_size;
4626 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4627 }
4628
4629 static inline int
4630 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4631 break;
4632
4633 case RV_BDREL:
4634 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4635 + if (in_init_rx(mod, val))
4636 + val -= (uint64_t) mod->module_init_rx;
4637 + else if (in_init_rw(mod, val))
4638 + val -= (uint64_t) mod->module_init_rw;
4639 + else if (in_core_rx(mod, val))
4640 + val -= (uint64_t) mod->module_core_rx;
4641 + else if (in_core_rw(mod, val))
4642 + val -= (uint64_t) mod->module_core_rw;
4643 break;
4644
4645 case RV_LTV:
4646 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4647 * addresses have been selected...
4648 */
4649 uint64_t gp;
4650 - if (mod->core_size > MAX_LTOFF)
4651 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4652 /*
4653 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4654 * at the end of the module.
4655 */
4656 - gp = mod->core_size - MAX_LTOFF / 2;
4657 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4658 else
4659 - gp = mod->core_size / 2;
4660 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4661 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4662 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4663 mod->arch.gp = gp;
4664 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4665 }
4666 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4667 index 77597e5..6f28f3f 100644
4668 --- a/arch/ia64/kernel/palinfo.c
4669 +++ b/arch/ia64/kernel/palinfo.c
4670 @@ -1045,7 +1045,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4671 return NOTIFY_OK;
4672 }
4673
4674 -static struct notifier_block __refdata palinfo_cpu_notifier =
4675 +static struct notifier_block palinfo_cpu_notifier =
4676 {
4677 .notifier_call = palinfo_cpu_callback,
4678 .priority = 0,
4679 diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4680 index 79802e5..1a89ec5 100644
4681 --- a/arch/ia64/kernel/salinfo.c
4682 +++ b/arch/ia64/kernel/salinfo.c
4683 @@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4684 return NOTIFY_OK;
4685 }
4686
4687 -static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4688 +static struct notifier_block salinfo_cpu_notifier =
4689 {
4690 .notifier_call = salinfo_cpu_callback,
4691 .priority = 0,
4692 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4693 index d9439ef..d0cac6b 100644
4694 --- a/arch/ia64/kernel/sys_ia64.c
4695 +++ b/arch/ia64/kernel/sys_ia64.c
4696 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4697 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
4698 struct mm_struct *mm = current->mm;
4699 struct vm_area_struct *vma;
4700 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4701
4702 if (len > RGN_MAP_LIMIT)
4703 return -ENOMEM;
4704 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4705 if (REGION_NUMBER(addr) == RGN_HPAGE)
4706 addr = 0;
4707 #endif
4708 +
4709 +#ifdef CONFIG_PAX_RANDMMAP
4710 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4711 + addr = mm->free_area_cache;
4712 + else
4713 +#endif
4714 +
4715 if (!addr)
4716 addr = mm->free_area_cache;
4717
4718 @@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4719 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
4720 /* At this point: (!vma || addr < vma->vm_end). */
4721 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
4722 - if (start_addr != TASK_UNMAPPED_BASE) {
4723 + if (start_addr != mm->mmap_base) {
4724 /* Start a new search --- just in case we missed some holes. */
4725 - addr = TASK_UNMAPPED_BASE;
4726 + addr = mm->mmap_base;
4727 goto full_search;
4728 }
4729 return -ENOMEM;
4730 }
4731 - if (!vma || addr + len <= vma->vm_start) {
4732 + if (check_heap_stack_gap(vma, addr, len, offset)) {
4733 /* Remember the address where we stopped this search: */
4734 mm->free_area_cache = addr + len;
4735 return addr;
4736 diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4737 index dc00b2c..cce53c2 100644
4738 --- a/arch/ia64/kernel/topology.c
4739 +++ b/arch/ia64/kernel/topology.c
4740 @@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4741 return NOTIFY_OK;
4742 }
4743
4744 -static struct notifier_block __cpuinitdata cache_cpu_notifier =
4745 +static struct notifier_block cache_cpu_notifier =
4746 {
4747 .notifier_call = cache_cpu_callback
4748 };
4749 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4750 index 0ccb28f..8992469 100644
4751 --- a/arch/ia64/kernel/vmlinux.lds.S
4752 +++ b/arch/ia64/kernel/vmlinux.lds.S
4753 @@ -198,7 +198,7 @@ SECTIONS {
4754 /* Per-cpu data: */
4755 . = ALIGN(PERCPU_PAGE_SIZE);
4756 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4757 - __phys_per_cpu_start = __per_cpu_load;
4758 + __phys_per_cpu_start = per_cpu_load;
4759 /*
4760 * ensure percpu data fits
4761 * into percpu page size
4762 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4763 index 6cf0341..d352594 100644
4764 --- a/arch/ia64/mm/fault.c
4765 +++ b/arch/ia64/mm/fault.c
4766 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4767 return pte_present(pte);
4768 }
4769
4770 +#ifdef CONFIG_PAX_PAGEEXEC
4771 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4772 +{
4773 + unsigned long i;
4774 +
4775 + printk(KERN_ERR "PAX: bytes at PC: ");
4776 + for (i = 0; i < 8; i++) {
4777 + unsigned int c;
4778 + if (get_user(c, (unsigned int *)pc+i))
4779 + printk(KERN_CONT "???????? ");
4780 + else
4781 + printk(KERN_CONT "%08x ", c);
4782 + }
4783 + printk("\n");
4784 +}
4785 +#endif
4786 +
4787 # define VM_READ_BIT 0
4788 # define VM_WRITE_BIT 1
4789 # define VM_EXEC_BIT 2
4790 @@ -149,8 +166,21 @@ retry:
4791 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4792 goto bad_area;
4793
4794 - if ((vma->vm_flags & mask) != mask)
4795 + if ((vma->vm_flags & mask) != mask) {
4796 +
4797 +#ifdef CONFIG_PAX_PAGEEXEC
4798 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
4799 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
4800 + goto bad_area;
4801 +
4802 + up_read(&mm->mmap_sem);
4803 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
4804 + do_group_exit(SIGKILL);
4805 + }
4806 +#endif
4807 +
4808 goto bad_area;
4809 + }
4810
4811 /*
4812 * If for any reason at all we couldn't handle the fault, make
4813 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
4814 index 5ca674b..127c3cb 100644
4815 --- a/arch/ia64/mm/hugetlbpage.c
4816 +++ b/arch/ia64/mm/hugetlbpage.c
4817 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4818 unsigned long pgoff, unsigned long flags)
4819 {
4820 struct vm_area_struct *vmm;
4821 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
4822
4823 if (len > RGN_MAP_LIMIT)
4824 return -ENOMEM;
4825 @@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
4826 /* At this point: (!vmm || addr < vmm->vm_end). */
4827 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
4828 return -ENOMEM;
4829 - if (!vmm || (addr + len) <= vmm->vm_start)
4830 + if (check_heap_stack_gap(vmm, addr, len, offset))
4831 return addr;
4832 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
4833 }
4834 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
4835 index b755ea9..b9a969e 100644
4836 --- a/arch/ia64/mm/init.c
4837 +++ b/arch/ia64/mm/init.c
4838 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
4839 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
4840 vma->vm_end = vma->vm_start + PAGE_SIZE;
4841 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
4842 +
4843 +#ifdef CONFIG_PAX_PAGEEXEC
4844 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
4845 + vma->vm_flags &= ~VM_EXEC;
4846 +
4847 +#ifdef CONFIG_PAX_MPROTECT
4848 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
4849 + vma->vm_flags &= ~VM_MAYEXEC;
4850 +#endif
4851 +
4852 + }
4853 +#endif
4854 +
4855 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4856 down_write(&current->mm->mmap_sem);
4857 if (insert_vm_struct(current->mm, vma)) {
4858 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
4859 index 40b3ee9..8c2c112 100644
4860 --- a/arch/m32r/include/asm/cache.h
4861 +++ b/arch/m32r/include/asm/cache.h
4862 @@ -1,8 +1,10 @@
4863 #ifndef _ASM_M32R_CACHE_H
4864 #define _ASM_M32R_CACHE_H
4865
4866 +#include <linux/const.h>
4867 +
4868 /* L1 cache line size */
4869 #define L1_CACHE_SHIFT 4
4870 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4871 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4872
4873 #endif /* _ASM_M32R_CACHE_H */
4874 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
4875 index 82abd15..d95ae5d 100644
4876 --- a/arch/m32r/lib/usercopy.c
4877 +++ b/arch/m32r/lib/usercopy.c
4878 @@ -14,6 +14,9 @@
4879 unsigned long
4880 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4881 {
4882 + if ((long)n < 0)
4883 + return n;
4884 +
4885 prefetch(from);
4886 if (access_ok(VERIFY_WRITE, to, n))
4887 __copy_user(to,from,n);
4888 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
4889 unsigned long
4890 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
4891 {
4892 + if ((long)n < 0)
4893 + return n;
4894 +
4895 prefetchw(to);
4896 if (access_ok(VERIFY_READ, from, n))
4897 __copy_user_zeroing(to,from,n);
4898 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
4899 index 0395c51..5f26031 100644
4900 --- a/arch/m68k/include/asm/cache.h
4901 +++ b/arch/m68k/include/asm/cache.h
4902 @@ -4,9 +4,11 @@
4903 #ifndef __ARCH_M68K_CACHE_H
4904 #define __ARCH_M68K_CACHE_H
4905
4906 +#include <linux/const.h>
4907 +
4908 /* bytes per L1 cache line */
4909 #define L1_CACHE_SHIFT 4
4910 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
4911 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4912
4913 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4914
4915 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
4916 index 4efe96a..60e8699 100644
4917 --- a/arch/microblaze/include/asm/cache.h
4918 +++ b/arch/microblaze/include/asm/cache.h
4919 @@ -13,11 +13,12 @@
4920 #ifndef _ASM_MICROBLAZE_CACHE_H
4921 #define _ASM_MICROBLAZE_CACHE_H
4922
4923 +#include <linux/const.h>
4924 #include <asm/registers.h>
4925
4926 #define L1_CACHE_SHIFT 5
4927 /* word-granular cache in microblaze */
4928 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4929 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4930
4931 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4932
4933 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
4934 index 01cc6ba..bcb7a5d 100644
4935 --- a/arch/mips/include/asm/atomic.h
4936 +++ b/arch/mips/include/asm/atomic.h
4937 @@ -21,6 +21,10 @@
4938 #include <asm/cmpxchg.h>
4939 #include <asm/war.h>
4940
4941 +#ifdef CONFIG_GENERIC_ATOMIC64
4942 +#include <asm-generic/atomic64.h>
4943 +#endif
4944 +
4945 #define ATOMIC_INIT(i) { (i) }
4946
4947 /*
4948 @@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4949 */
4950 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
4951
4952 +#define atomic64_read_unchecked(v) atomic64_read(v)
4953 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4954 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4955 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4956 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4957 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4958 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4959 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4960 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4961 +
4962 #endif /* CONFIG_64BIT */
4963
4964 /*
4965 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
4966 index b4db69f..8f3b093 100644
4967 --- a/arch/mips/include/asm/cache.h
4968 +++ b/arch/mips/include/asm/cache.h
4969 @@ -9,10 +9,11 @@
4970 #ifndef _ASM_CACHE_H
4971 #define _ASM_CACHE_H
4972
4973 +#include <linux/const.h>
4974 #include <kmalloc.h>
4975
4976 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
4977 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4978 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4979
4980 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4981 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4982 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
4983 index 455c0ac..ad65fbe 100644
4984 --- a/arch/mips/include/asm/elf.h
4985 +++ b/arch/mips/include/asm/elf.h
4986 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
4987 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4988 #endif
4989
4990 +#ifdef CONFIG_PAX_ASLR
4991 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
4992 +
4993 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4994 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
4995 +#endif
4996 +
4997 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4998 struct linux_binprm;
4999 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5000 int uses_interp);
5001
5002 -struct mm_struct;
5003 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5004 -#define arch_randomize_brk arch_randomize_brk
5005 -
5006 #endif /* _ASM_ELF_H */
5007 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5008 index c1f6afa..38cc6e9 100644
5009 --- a/arch/mips/include/asm/exec.h
5010 +++ b/arch/mips/include/asm/exec.h
5011 @@ -12,6 +12,6 @@
5012 #ifndef _ASM_EXEC_H
5013 #define _ASM_EXEC_H
5014
5015 -extern unsigned long arch_align_stack(unsigned long sp);
5016 +#define arch_align_stack(x) ((x) & ~0xfUL)
5017
5018 #endif /* _ASM_EXEC_H */
5019 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5020 index dbaec94..6a14935 100644
5021 --- a/arch/mips/include/asm/page.h
5022 +++ b/arch/mips/include/asm/page.h
5023 @@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5024 #ifdef CONFIG_CPU_MIPS32
5025 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5026 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5027 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5028 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5029 #else
5030 typedef struct { unsigned long long pte; } pte_t;
5031 #define pte_val(x) ((x).pte)
5032 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5033 index 881d18b..cea38bc 100644
5034 --- a/arch/mips/include/asm/pgalloc.h
5035 +++ b/arch/mips/include/asm/pgalloc.h
5036 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5037 {
5038 set_pud(pud, __pud((unsigned long)pmd));
5039 }
5040 +
5041 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5042 +{
5043 + pud_populate(mm, pud, pmd);
5044 +}
5045 #endif
5046
5047 /*
5048 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5049 index b2050b9..d71bb1b 100644
5050 --- a/arch/mips/include/asm/thread_info.h
5051 +++ b/arch/mips/include/asm/thread_info.h
5052 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5053 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5054 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5055 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5056 +/* li takes a 32bit immediate */
5057 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5058 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5059
5060 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5061 @@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5062 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5063 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5064 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5065 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5066 +
5067 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5068
5069 /* work to do in syscall_trace_leave() */
5070 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5071 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5072
5073 /* work to do on interrupt/exception return */
5074 #define _TIF_WORK_MASK \
5075 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5076 /* work to do on any return to u-space */
5077 -#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5078 +#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5079
5080 #endif /* __KERNEL__ */
5081
5082 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5083 index 9fdd8bc..4bd7f1a 100644
5084 --- a/arch/mips/kernel/binfmt_elfn32.c
5085 +++ b/arch/mips/kernel/binfmt_elfn32.c
5086 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5087 #undef ELF_ET_DYN_BASE
5088 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5089
5090 +#ifdef CONFIG_PAX_ASLR
5091 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5092 +
5093 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5094 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5095 +#endif
5096 +
5097 #include <asm/processor.h>
5098 #include <linux/module.h>
5099 #include <linux/elfcore.h>
5100 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5101 index ff44823..97f8906 100644
5102 --- a/arch/mips/kernel/binfmt_elfo32.c
5103 +++ b/arch/mips/kernel/binfmt_elfo32.c
5104 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5105 #undef ELF_ET_DYN_BASE
5106 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5107
5108 +#ifdef CONFIG_PAX_ASLR
5109 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5110 +
5111 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5112 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5113 +#endif
5114 +
5115 #include <asm/processor.h>
5116
5117 /*
5118 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5119 index a11c6f9..be5e164 100644
5120 --- a/arch/mips/kernel/process.c
5121 +++ b/arch/mips/kernel/process.c
5122 @@ -460,15 +460,3 @@ unsigned long get_wchan(struct task_struct *task)
5123 out:
5124 return pc;
5125 }
5126 -
5127 -/*
5128 - * Don't forget that the stack pointer must be aligned on a 8 bytes
5129 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5130 - */
5131 -unsigned long arch_align_stack(unsigned long sp)
5132 -{
5133 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5134 - sp -= get_random_int() & ~PAGE_MASK;
5135 -
5136 - return sp & ALMASK;
5137 -}
5138 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5139 index 4812c6d..2069554 100644
5140 --- a/arch/mips/kernel/ptrace.c
5141 +++ b/arch/mips/kernel/ptrace.c
5142 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
5143 return arch;
5144 }
5145
5146 +#ifdef CONFIG_GRKERNSEC_SETXID
5147 +extern void gr_delayed_cred_worker(void);
5148 +#endif
5149 +
5150 /*
5151 * Notification of system call entry/exit
5152 * - triggered by current->work.syscall_trace
5153 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5154 /* do the secure computing check first */
5155 secure_computing_strict(regs->regs[2]);
5156
5157 +#ifdef CONFIG_GRKERNSEC_SETXID
5158 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5159 + gr_delayed_cred_worker();
5160 +#endif
5161 +
5162 if (!(current->ptrace & PT_PTRACED))
5163 goto out;
5164
5165 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5166 index d20a4bc..7096ae5 100644
5167 --- a/arch/mips/kernel/scall32-o32.S
5168 +++ b/arch/mips/kernel/scall32-o32.S
5169 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5170
5171 stack_done:
5172 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5173 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5174 + li t1, _TIF_SYSCALL_WORK
5175 and t0, t1
5176 bnez t0, syscall_trace_entry # -> yes
5177
5178 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5179 index b64f642..0fe6eab 100644
5180 --- a/arch/mips/kernel/scall64-64.S
5181 +++ b/arch/mips/kernel/scall64-64.S
5182 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5183
5184 sd a3, PT_R26(sp) # save a3 for syscall restarting
5185
5186 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5187 + li t1, _TIF_SYSCALL_WORK
5188 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5189 and t0, t1, t0
5190 bnez t0, syscall_trace_entry
5191 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5192 index c29ac19..c592d05 100644
5193 --- a/arch/mips/kernel/scall64-n32.S
5194 +++ b/arch/mips/kernel/scall64-n32.S
5195 @@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5196
5197 sd a3, PT_R26(sp) # save a3 for syscall restarting
5198
5199 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5200 + li t1, _TIF_SYSCALL_WORK
5201 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5202 and t0, t1, t0
5203 bnez t0, n32_syscall_trace_entry
5204 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5205 index cf3e75e..72e93fe 100644
5206 --- a/arch/mips/kernel/scall64-o32.S
5207 +++ b/arch/mips/kernel/scall64-o32.S
5208 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5209 PTR 4b, bad_stack
5210 .previous
5211
5212 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5213 + li t1, _TIF_SYSCALL_WORK
5214 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5215 and t0, t1, t0
5216 bnez t0, trace_a_syscall
5217 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5218 index ddcec1e..c7f983e 100644
5219 --- a/arch/mips/mm/fault.c
5220 +++ b/arch/mips/mm/fault.c
5221 @@ -27,6 +27,23 @@
5222 #include <asm/highmem.h> /* For VMALLOC_END */
5223 #include <linux/kdebug.h>
5224
5225 +#ifdef CONFIG_PAX_PAGEEXEC
5226 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5227 +{
5228 + unsigned long i;
5229 +
5230 + printk(KERN_ERR "PAX: bytes at PC: ");
5231 + for (i = 0; i < 5; i++) {
5232 + unsigned int c;
5233 + if (get_user(c, (unsigned int *)pc+i))
5234 + printk(KERN_CONT "???????? ");
5235 + else
5236 + printk(KERN_CONT "%08x ", c);
5237 + }
5238 + printk("\n");
5239 +}
5240 +#endif
5241 +
5242 /*
5243 * This routine handles page faults. It determines the address,
5244 * and the problem, and then passes it off to one of the appropriate
5245 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5246 index 7e5fe27..479a219 100644
5247 --- a/arch/mips/mm/mmap.c
5248 +++ b/arch/mips/mm/mmap.c
5249 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5250 struct vm_area_struct *vma;
5251 unsigned long addr = addr0;
5252 int do_color_align;
5253 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5254 struct vm_unmapped_area_info info;
5255
5256 if (unlikely(len > TASK_SIZE))
5257 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5258 do_color_align = 1;
5259
5260 /* requesting a specific address */
5261 +
5262 +#ifdef CONFIG_PAX_RANDMMAP
5263 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5264 +#endif
5265 +
5266 if (addr) {
5267 if (do_color_align)
5268 addr = COLOUR_ALIGN(addr, pgoff);
5269 @@ -91,8 +97,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5270 addr = PAGE_ALIGN(addr);
5271
5272 vma = find_vma(mm, addr);
5273 - if (TASK_SIZE - len >= addr &&
5274 - (!vma || addr + len <= vma->vm_start))
5275 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5276 return addr;
5277 }
5278
5279 @@ -146,6 +151,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5280 {
5281 unsigned long random_factor = 0UL;
5282
5283 +#ifdef CONFIG_PAX_RANDMMAP
5284 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5285 +#endif
5286 +
5287 if (current->flags & PF_RANDOMIZE) {
5288 random_factor = get_random_int();
5289 random_factor = random_factor << PAGE_SHIFT;
5290 @@ -157,42 +166,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5291
5292 if (mmap_is_legacy()) {
5293 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5294 +
5295 +#ifdef CONFIG_PAX_RANDMMAP
5296 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5297 + mm->mmap_base += mm->delta_mmap;
5298 +#endif
5299 +
5300 mm->get_unmapped_area = arch_get_unmapped_area;
5301 mm->unmap_area = arch_unmap_area;
5302 } else {
5303 mm->mmap_base = mmap_base(random_factor);
5304 +
5305 +#ifdef CONFIG_PAX_RANDMMAP
5306 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5307 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5308 +#endif
5309 +
5310 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5311 mm->unmap_area = arch_unmap_area_topdown;
5312 }
5313 }
5314
5315 -static inline unsigned long brk_rnd(void)
5316 -{
5317 - unsigned long rnd = get_random_int();
5318 -
5319 - rnd = rnd << PAGE_SHIFT;
5320 - /* 8MB for 32bit, 256MB for 64bit */
5321 - if (TASK_IS_32BIT_ADDR)
5322 - rnd = rnd & 0x7ffffful;
5323 - else
5324 - rnd = rnd & 0xffffffful;
5325 -
5326 - return rnd;
5327 -}
5328 -
5329 -unsigned long arch_randomize_brk(struct mm_struct *mm)
5330 -{
5331 - unsigned long base = mm->brk;
5332 - unsigned long ret;
5333 -
5334 - ret = PAGE_ALIGN(base + brk_rnd());
5335 -
5336 - if (ret < mm->brk)
5337 - return mm->brk;
5338 -
5339 - return ret;
5340 -}
5341 -
5342 int __virt_addr_valid(const volatile void *kaddr)
5343 {
5344 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5345 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5346 index 967d144..db12197 100644
5347 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5348 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5349 @@ -11,12 +11,14 @@
5350 #ifndef _ASM_PROC_CACHE_H
5351 #define _ASM_PROC_CACHE_H
5352
5353 +#include <linux/const.h>
5354 +
5355 /* L1 cache */
5356
5357 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5358 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5359 -#define L1_CACHE_BYTES 16 /* bytes per entry */
5360 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5361 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5362 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5363
5364 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5365 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5366 index bcb5df2..84fabd2 100644
5367 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5368 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5369 @@ -16,13 +16,15 @@
5370 #ifndef _ASM_PROC_CACHE_H
5371 #define _ASM_PROC_CACHE_H
5372
5373 +#include <linux/const.h>
5374 +
5375 /*
5376 * L1 cache
5377 */
5378 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5379 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5380 -#define L1_CACHE_BYTES 32 /* bytes per entry */
5381 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5382 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5383 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5384
5385 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5386 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5387 index 4ce7a01..449202a 100644
5388 --- a/arch/openrisc/include/asm/cache.h
5389 +++ b/arch/openrisc/include/asm/cache.h
5390 @@ -19,11 +19,13 @@
5391 #ifndef __ASM_OPENRISC_CACHE_H
5392 #define __ASM_OPENRISC_CACHE_H
5393
5394 +#include <linux/const.h>
5395 +
5396 /* FIXME: How can we replace these with values from the CPU...
5397 * they shouldn't be hard-coded!
5398 */
5399
5400 -#define L1_CACHE_BYTES 16
5401 #define L1_CACHE_SHIFT 4
5402 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5403
5404 #endif /* __ASM_OPENRISC_CACHE_H */
5405 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5406 index af9cf30..2aae9b2 100644
5407 --- a/arch/parisc/include/asm/atomic.h
5408 +++ b/arch/parisc/include/asm/atomic.h
5409 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5410
5411 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5412
5413 +#define atomic64_read_unchecked(v) atomic64_read(v)
5414 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5415 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5416 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5417 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5418 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5419 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5420 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5421 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5422 +
5423 #endif /* !CONFIG_64BIT */
5424
5425
5426 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5427 index 47f11c7..3420df2 100644
5428 --- a/arch/parisc/include/asm/cache.h
5429 +++ b/arch/parisc/include/asm/cache.h
5430 @@ -5,6 +5,7 @@
5431 #ifndef __ARCH_PARISC_CACHE_H
5432 #define __ARCH_PARISC_CACHE_H
5433
5434 +#include <linux/const.h>
5435
5436 /*
5437 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5438 @@ -15,13 +16,13 @@
5439 * just ruin performance.
5440 */
5441 #ifdef CONFIG_PA20
5442 -#define L1_CACHE_BYTES 64
5443 #define L1_CACHE_SHIFT 6
5444 #else
5445 -#define L1_CACHE_BYTES 32
5446 #define L1_CACHE_SHIFT 5
5447 #endif
5448
5449 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5450 +
5451 #ifndef __ASSEMBLY__
5452
5453 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5454 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5455 index 19f6cb1..6c78cf2 100644
5456 --- a/arch/parisc/include/asm/elf.h
5457 +++ b/arch/parisc/include/asm/elf.h
5458 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5459
5460 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5461
5462 +#ifdef CONFIG_PAX_ASLR
5463 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5464 +
5465 +#define PAX_DELTA_MMAP_LEN 16
5466 +#define PAX_DELTA_STACK_LEN 16
5467 +#endif
5468 +
5469 /* This yields a mask that user programs can use to figure out what
5470 instruction set this CPU supports. This could be done in user space,
5471 but it's not easy, and we've already done it here. */
5472 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5473 index fc987a1..6e068ef 100644
5474 --- a/arch/parisc/include/asm/pgalloc.h
5475 +++ b/arch/parisc/include/asm/pgalloc.h
5476 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5477 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5478 }
5479
5480 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5481 +{
5482 + pgd_populate(mm, pgd, pmd);
5483 +}
5484 +
5485 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5486 {
5487 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5488 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5489 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5490 #define pmd_free(mm, x) do { } while (0)
5491 #define pgd_populate(mm, pmd, pte) BUG()
5492 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
5493
5494 #endif
5495
5496 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5497 index ee99f23..802b0a1 100644
5498 --- a/arch/parisc/include/asm/pgtable.h
5499 +++ b/arch/parisc/include/asm/pgtable.h
5500 @@ -212,6 +212,17 @@ struct vm_area_struct;
5501 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5502 #define PAGE_COPY PAGE_EXECREAD
5503 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5504 +
5505 +#ifdef CONFIG_PAX_PAGEEXEC
5506 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5507 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5508 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5509 +#else
5510 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5511 +# define PAGE_COPY_NOEXEC PAGE_COPY
5512 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5513 +#endif
5514 +
5515 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5516 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5517 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5518 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5519 index 4ba2c93..f5e3974 100644
5520 --- a/arch/parisc/include/asm/uaccess.h
5521 +++ b/arch/parisc/include/asm/uaccess.h
5522 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5523 const void __user *from,
5524 unsigned long n)
5525 {
5526 - int sz = __compiletime_object_size(to);
5527 + size_t sz = __compiletime_object_size(to);
5528 int ret = -EFAULT;
5529
5530 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5531 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5532 ret = __copy_from_user(to, from, n);
5533 else
5534 copy_from_user_overflow();
5535 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5536 index 2a625fb..9908930 100644
5537 --- a/arch/parisc/kernel/module.c
5538 +++ b/arch/parisc/kernel/module.c
5539 @@ -98,16 +98,38 @@
5540
5541 /* three functions to determine where in the module core
5542 * or init pieces the location is */
5543 +static inline int in_init_rx(struct module *me, void *loc)
5544 +{
5545 + return (loc >= me->module_init_rx &&
5546 + loc < (me->module_init_rx + me->init_size_rx));
5547 +}
5548 +
5549 +static inline int in_init_rw(struct module *me, void *loc)
5550 +{
5551 + return (loc >= me->module_init_rw &&
5552 + loc < (me->module_init_rw + me->init_size_rw));
5553 +}
5554 +
5555 static inline int in_init(struct module *me, void *loc)
5556 {
5557 - return (loc >= me->module_init &&
5558 - loc <= (me->module_init + me->init_size));
5559 + return in_init_rx(me, loc) || in_init_rw(me, loc);
5560 +}
5561 +
5562 +static inline int in_core_rx(struct module *me, void *loc)
5563 +{
5564 + return (loc >= me->module_core_rx &&
5565 + loc < (me->module_core_rx + me->core_size_rx));
5566 +}
5567 +
5568 +static inline int in_core_rw(struct module *me, void *loc)
5569 +{
5570 + return (loc >= me->module_core_rw &&
5571 + loc < (me->module_core_rw + me->core_size_rw));
5572 }
5573
5574 static inline int in_core(struct module *me, void *loc)
5575 {
5576 - return (loc >= me->module_core &&
5577 - loc <= (me->module_core + me->core_size));
5578 + return in_core_rx(me, loc) || in_core_rw(me, loc);
5579 }
5580
5581 static inline int in_local(struct module *me, void *loc)
5582 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5583 }
5584
5585 /* align things a bit */
5586 - me->core_size = ALIGN(me->core_size, 16);
5587 - me->arch.got_offset = me->core_size;
5588 - me->core_size += gots * sizeof(struct got_entry);
5589 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5590 + me->arch.got_offset = me->core_size_rw;
5591 + me->core_size_rw += gots * sizeof(struct got_entry);
5592
5593 - me->core_size = ALIGN(me->core_size, 16);
5594 - me->arch.fdesc_offset = me->core_size;
5595 - me->core_size += fdescs * sizeof(Elf_Fdesc);
5596 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
5597 + me->arch.fdesc_offset = me->core_size_rw;
5598 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5599
5600 me->arch.got_max = gots;
5601 me->arch.fdesc_max = fdescs;
5602 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5603
5604 BUG_ON(value == 0);
5605
5606 - got = me->module_core + me->arch.got_offset;
5607 + got = me->module_core_rw + me->arch.got_offset;
5608 for (i = 0; got[i].addr; i++)
5609 if (got[i].addr == value)
5610 goto out;
5611 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5612 #ifdef CONFIG_64BIT
5613 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5614 {
5615 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5616 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5617
5618 if (!value) {
5619 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5620 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5621
5622 /* Create new one */
5623 fdesc->addr = value;
5624 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5625 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5626 return (Elf_Addr)fdesc;
5627 }
5628 #endif /* CONFIG_64BIT */
5629 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5630
5631 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5632 end = table + sechdrs[me->arch.unwind_section].sh_size;
5633 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5634 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5635
5636 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5637 me->arch.unwind_section, table, end, gp);
5638 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5639 index f76c108..92bad82 100644
5640 --- a/arch/parisc/kernel/sys_parisc.c
5641 +++ b/arch/parisc/kernel/sys_parisc.c
5642 @@ -33,9 +33,11 @@
5643 #include <linux/utsname.h>
5644 #include <linux/personality.h>
5645
5646 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5647 +static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5648 + unsigned long flags)
5649 {
5650 struct vm_area_struct *vma;
5651 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5652
5653 addr = PAGE_ALIGN(addr);
5654
5655 @@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5656 /* At this point: (!vma || addr < vma->vm_end). */
5657 if (TASK_SIZE - len < addr)
5658 return -ENOMEM;
5659 - if (!vma || addr + len <= vma->vm_start)
5660 + if (check_heap_stack_gap(vma, addr, len, offset))
5661 return addr;
5662 addr = vma->vm_end;
5663 }
5664 @@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
5665 return offset & 0x3FF000;
5666 }
5667
5668 -static unsigned long get_shared_area(struct address_space *mapping,
5669 - unsigned long addr, unsigned long len, unsigned long pgoff)
5670 +static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5671 + unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5672 {
5673 struct vm_area_struct *vma;
5674 int offset = mapping ? get_offset(mapping) : 0;
5675 + unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5676
5677 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
5678
5679 @@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5680 /* At this point: (!vma || addr < vma->vm_end). */
5681 if (TASK_SIZE - len < addr)
5682 return -ENOMEM;
5683 - if (!vma || addr + len <= vma->vm_start)
5684 + if (check_heap_stack_gap(vma, addr, len, rand_offset))
5685 return addr;
5686 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
5687 if (addr < vma->vm_end) /* handle wraparound */
5688 @@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5689 if (flags & MAP_FIXED)
5690 return addr;
5691 if (!addr)
5692 - addr = TASK_UNMAPPED_BASE;
5693 + addr = current->mm->mmap_base;
5694
5695 if (filp) {
5696 - addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5697 + addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5698 } else if(flags & MAP_SHARED) {
5699 - addr = get_shared_area(NULL, addr, len, pgoff);
5700 + addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5701 } else {
5702 - addr = get_unshared_area(addr, len);
5703 + addr = get_unshared_area(filp, addr, len, flags);
5704 }
5705 return addr;
5706 }
5707 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5708 index 45ba99f..8e22c33 100644
5709 --- a/arch/parisc/kernel/traps.c
5710 +++ b/arch/parisc/kernel/traps.c
5711 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5712
5713 down_read(&current->mm->mmap_sem);
5714 vma = find_vma(current->mm,regs->iaoq[0]);
5715 - if (vma && (regs->iaoq[0] >= vma->vm_start)
5716 - && (vma->vm_flags & VM_EXEC)) {
5717 -
5718 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5719 fault_address = regs->iaoq[0];
5720 fault_space = regs->iasq[0];
5721
5722 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5723 index 18162ce..94de376 100644
5724 --- a/arch/parisc/mm/fault.c
5725 +++ b/arch/parisc/mm/fault.c
5726 @@ -15,6 +15,7 @@
5727 #include <linux/sched.h>
5728 #include <linux/interrupt.h>
5729 #include <linux/module.h>
5730 +#include <linux/unistd.h>
5731
5732 #include <asm/uaccess.h>
5733 #include <asm/traps.h>
5734 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5735 static unsigned long
5736 parisc_acctyp(unsigned long code, unsigned int inst)
5737 {
5738 - if (code == 6 || code == 16)
5739 + if (code == 6 || code == 7 || code == 16)
5740 return VM_EXEC;
5741
5742 switch (inst & 0xf0000000) {
5743 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5744 }
5745 #endif
5746
5747 +#ifdef CONFIG_PAX_PAGEEXEC
5748 +/*
5749 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5750 + *
5751 + * returns 1 when task should be killed
5752 + * 2 when rt_sigreturn trampoline was detected
5753 + * 3 when unpatched PLT trampoline was detected
5754 + */
5755 +static int pax_handle_fetch_fault(struct pt_regs *regs)
5756 +{
5757 +
5758 +#ifdef CONFIG_PAX_EMUPLT
5759 + int err;
5760 +
5761 + do { /* PaX: unpatched PLT emulation */
5762 + unsigned int bl, depwi;
5763 +
5764 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5765 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5766 +
5767 + if (err)
5768 + break;
5769 +
5770 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5771 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5772 +
5773 + err = get_user(ldw, (unsigned int *)addr);
5774 + err |= get_user(bv, (unsigned int *)(addr+4));
5775 + err |= get_user(ldw2, (unsigned int *)(addr+8));
5776 +
5777 + if (err)
5778 + break;
5779 +
5780 + if (ldw == 0x0E801096U &&
5781 + bv == 0xEAC0C000U &&
5782 + ldw2 == 0x0E881095U)
5783 + {
5784 + unsigned int resolver, map;
5785 +
5786 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
5787 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
5788 + if (err)
5789 + break;
5790 +
5791 + regs->gr[20] = instruction_pointer(regs)+8;
5792 + regs->gr[21] = map;
5793 + regs->gr[22] = resolver;
5794 + regs->iaoq[0] = resolver | 3UL;
5795 + regs->iaoq[1] = regs->iaoq[0] + 4;
5796 + return 3;
5797 + }
5798 + }
5799 + } while (0);
5800 +#endif
5801 +
5802 +#ifdef CONFIG_PAX_EMUTRAMP
5803 +
5804 +#ifndef CONFIG_PAX_EMUSIGRT
5805 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
5806 + return 1;
5807 +#endif
5808 +
5809 + do { /* PaX: rt_sigreturn emulation */
5810 + unsigned int ldi1, ldi2, bel, nop;
5811 +
5812 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
5813 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
5814 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
5815 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
5816 +
5817 + if (err)
5818 + break;
5819 +
5820 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
5821 + ldi2 == 0x3414015AU &&
5822 + bel == 0xE4008200U &&
5823 + nop == 0x08000240U)
5824 + {
5825 + regs->gr[25] = (ldi1 & 2) >> 1;
5826 + regs->gr[20] = __NR_rt_sigreturn;
5827 + regs->gr[31] = regs->iaoq[1] + 16;
5828 + regs->sr[0] = regs->iasq[1];
5829 + regs->iaoq[0] = 0x100UL;
5830 + regs->iaoq[1] = regs->iaoq[0] + 4;
5831 + regs->iasq[0] = regs->sr[2];
5832 + regs->iasq[1] = regs->sr[2];
5833 + return 2;
5834 + }
5835 + } while (0);
5836 +#endif
5837 +
5838 + return 1;
5839 +}
5840 +
5841 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5842 +{
5843 + unsigned long i;
5844 +
5845 + printk(KERN_ERR "PAX: bytes at PC: ");
5846 + for (i = 0; i < 5; i++) {
5847 + unsigned int c;
5848 + if (get_user(c, (unsigned int *)pc+i))
5849 + printk(KERN_CONT "???????? ");
5850 + else
5851 + printk(KERN_CONT "%08x ", c);
5852 + }
5853 + printk("\n");
5854 +}
5855 +#endif
5856 +
5857 int fixup_exception(struct pt_regs *regs)
5858 {
5859 const struct exception_table_entry *fix;
5860 @@ -192,8 +303,33 @@ good_area:
5861
5862 acc_type = parisc_acctyp(code,regs->iir);
5863
5864 - if ((vma->vm_flags & acc_type) != acc_type)
5865 + if ((vma->vm_flags & acc_type) != acc_type) {
5866 +
5867 +#ifdef CONFIG_PAX_PAGEEXEC
5868 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
5869 + (address & ~3UL) == instruction_pointer(regs))
5870 + {
5871 + up_read(&mm->mmap_sem);
5872 + switch (pax_handle_fetch_fault(regs)) {
5873 +
5874 +#ifdef CONFIG_PAX_EMUPLT
5875 + case 3:
5876 + return;
5877 +#endif
5878 +
5879 +#ifdef CONFIG_PAX_EMUTRAMP
5880 + case 2:
5881 + return;
5882 +#endif
5883 +
5884 + }
5885 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
5886 + do_group_exit(SIGKILL);
5887 + }
5888 +#endif
5889 +
5890 goto bad_area;
5891 + }
5892
5893 /*
5894 * If for any reason at all we couldn't handle the fault, make
5895 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
5896 index e3b1d41..8e81edf 100644
5897 --- a/arch/powerpc/include/asm/atomic.h
5898 +++ b/arch/powerpc/include/asm/atomic.h
5899 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
5900 return t1;
5901 }
5902
5903 +#define atomic64_read_unchecked(v) atomic64_read(v)
5904 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5905 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5906 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5907 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5908 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5909 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5910 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5911 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5912 +
5913 #endif /* __powerpc64__ */
5914
5915 #endif /* __KERNEL__ */
5916 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
5917 index 9e495c9..b6878e5 100644
5918 --- a/arch/powerpc/include/asm/cache.h
5919 +++ b/arch/powerpc/include/asm/cache.h
5920 @@ -3,6 +3,7 @@
5921
5922 #ifdef __KERNEL__
5923
5924 +#include <linux/const.h>
5925
5926 /* bytes per L1 cache line */
5927 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
5928 @@ -22,7 +23,7 @@
5929 #define L1_CACHE_SHIFT 7
5930 #endif
5931
5932 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5933 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5934
5935 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5936
5937 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
5938 index 6abf0a1..459d0f1 100644
5939 --- a/arch/powerpc/include/asm/elf.h
5940 +++ b/arch/powerpc/include/asm/elf.h
5941 @@ -28,8 +28,19 @@
5942 the loader. We need to make sure that it is out of the way of the program
5943 that it will "exec", and that there is sufficient room for the brk. */
5944
5945 -extern unsigned long randomize_et_dyn(unsigned long base);
5946 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
5947 +#define ELF_ET_DYN_BASE (0x20000000)
5948 +
5949 +#ifdef CONFIG_PAX_ASLR
5950 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
5951 +
5952 +#ifdef __powerpc64__
5953 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
5954 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
5955 +#else
5956 +#define PAX_DELTA_MMAP_LEN 15
5957 +#define PAX_DELTA_STACK_LEN 15
5958 +#endif
5959 +#endif
5960
5961 /*
5962 * Our registers are always unsigned longs, whether we're a 32 bit
5963 @@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5964 (0x7ff >> (PAGE_SHIFT - 12)) : \
5965 (0x3ffff >> (PAGE_SHIFT - 12)))
5966
5967 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5968 -#define arch_randomize_brk arch_randomize_brk
5969 -
5970 -
5971 #ifdef CONFIG_SPU_BASE
5972 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
5973 #define NT_SPU 1
5974 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
5975 index 8196e9c..d83a9f3 100644
5976 --- a/arch/powerpc/include/asm/exec.h
5977 +++ b/arch/powerpc/include/asm/exec.h
5978 @@ -4,6 +4,6 @@
5979 #ifndef _ASM_POWERPC_EXEC_H
5980 #define _ASM_POWERPC_EXEC_H
5981
5982 -extern unsigned long arch_align_stack(unsigned long sp);
5983 +#define arch_align_stack(x) ((x) & ~0xfUL)
5984
5985 #endif /* _ASM_POWERPC_EXEC_H */
5986 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
5987 index 5acabbd..7ea14fa 100644
5988 --- a/arch/powerpc/include/asm/kmap_types.h
5989 +++ b/arch/powerpc/include/asm/kmap_types.h
5990 @@ -10,7 +10,7 @@
5991 * 2 of the License, or (at your option) any later version.
5992 */
5993
5994 -#define KM_TYPE_NR 16
5995 +#define KM_TYPE_NR 17
5996
5997 #endif /* __KERNEL__ */
5998 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
5999 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6000 index 8565c25..2865190 100644
6001 --- a/arch/powerpc/include/asm/mman.h
6002 +++ b/arch/powerpc/include/asm/mman.h
6003 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6004 }
6005 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6006
6007 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6008 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6009 {
6010 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6011 }
6012 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6013 index f072e97..b436dee 100644
6014 --- a/arch/powerpc/include/asm/page.h
6015 +++ b/arch/powerpc/include/asm/page.h
6016 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6017 * and needs to be executable. This means the whole heap ends
6018 * up being executable.
6019 */
6020 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6021 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6022 +#define VM_DATA_DEFAULT_FLAGS32 \
6023 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6024 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6025
6026 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6027 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6028 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6029 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6030 #endif
6031
6032 +#define ktla_ktva(addr) (addr)
6033 +#define ktva_ktla(addr) (addr)
6034 +
6035 /*
6036 * Use the top bit of the higher-level page table entries to indicate whether
6037 * the entries we point to contain hugepages. This works because we know that
6038 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6039 index cd915d6..c10cee8 100644
6040 --- a/arch/powerpc/include/asm/page_64.h
6041 +++ b/arch/powerpc/include/asm/page_64.h
6042 @@ -154,15 +154,18 @@ do { \
6043 * stack by default, so in the absence of a PT_GNU_STACK program header
6044 * we turn execute permission off.
6045 */
6046 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6047 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6048 +#define VM_STACK_DEFAULT_FLAGS32 \
6049 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6050 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6051
6052 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6053 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6054
6055 +#ifndef CONFIG_PAX_PAGEEXEC
6056 #define VM_STACK_DEFAULT_FLAGS \
6057 (is_32bit_task() ? \
6058 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6059 +#endif
6060
6061 #include <asm-generic/getorder.h>
6062
6063 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6064 index 292725c..f87ae14 100644
6065 --- a/arch/powerpc/include/asm/pgalloc-64.h
6066 +++ b/arch/powerpc/include/asm/pgalloc-64.h
6067 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6068 #ifndef CONFIG_PPC_64K_PAGES
6069
6070 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6071 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6072
6073 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6074 {
6075 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6076 pud_set(pud, (unsigned long)pmd);
6077 }
6078
6079 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6080 +{
6081 + pud_populate(mm, pud, pmd);
6082 +}
6083 +
6084 #define pmd_populate(mm, pmd, pte_page) \
6085 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6086 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6087 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6088 #else /* CONFIG_PPC_64K_PAGES */
6089
6090 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6091 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6092
6093 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6094 pte_t *pte)
6095 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6096 index a9cbd3b..3b67efa 100644
6097 --- a/arch/powerpc/include/asm/pgtable.h
6098 +++ b/arch/powerpc/include/asm/pgtable.h
6099 @@ -2,6 +2,7 @@
6100 #define _ASM_POWERPC_PGTABLE_H
6101 #ifdef __KERNEL__
6102
6103 +#include <linux/const.h>
6104 #ifndef __ASSEMBLY__
6105 #include <asm/processor.h> /* For TASK_SIZE */
6106 #include <asm/mmu.h>
6107 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6108 index 4aad413..85d86bf 100644
6109 --- a/arch/powerpc/include/asm/pte-hash32.h
6110 +++ b/arch/powerpc/include/asm/pte-hash32.h
6111 @@ -21,6 +21,7 @@
6112 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6113 #define _PAGE_USER 0x004 /* usermode access allowed */
6114 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6115 +#define _PAGE_EXEC _PAGE_GUARDED
6116 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6117 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6118 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6119 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6120 index 3d5c9dc..62f8414 100644
6121 --- a/arch/powerpc/include/asm/reg.h
6122 +++ b/arch/powerpc/include/asm/reg.h
6123 @@ -215,6 +215,7 @@
6124 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6125 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6126 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6127 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6128 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6129 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6130 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6131 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6132 index 406b7b9..af63426 100644
6133 --- a/arch/powerpc/include/asm/thread_info.h
6134 +++ b/arch/powerpc/include/asm/thread_info.h
6135 @@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6136 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6137 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6138 #define TIF_SINGLESTEP 8 /* singlestepping active */
6139 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6140 #define TIF_SECCOMP 10 /* secure computing */
6141 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6142 #define TIF_NOERROR 12 /* Force successful syscall return */
6143 @@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6144 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6145 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6146 for stack store? */
6147 +#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6148 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6149 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6150
6151 /* as above, but as bit values */
6152 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6153 @@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6154 #define _TIF_UPROBE (1<<TIF_UPROBE)
6155 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6156 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6157 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6158 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6159 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6160 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6161 + _TIF_GRSEC_SETXID)
6162
6163 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6164 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6165 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6166 index 4db4959..335e00c 100644
6167 --- a/arch/powerpc/include/asm/uaccess.h
6168 +++ b/arch/powerpc/include/asm/uaccess.h
6169 @@ -13,6 +13,8 @@
6170 #define VERIFY_READ 0
6171 #define VERIFY_WRITE 1
6172
6173 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
6174 +
6175 /*
6176 * The fs value determines whether argument validity checking should be
6177 * performed or not. If get_fs() == USER_DS, checking is performed, with
6178 @@ -318,52 +320,6 @@ do { \
6179 extern unsigned long __copy_tofrom_user(void __user *to,
6180 const void __user *from, unsigned long size);
6181
6182 -#ifndef __powerpc64__
6183 -
6184 -static inline unsigned long copy_from_user(void *to,
6185 - const void __user *from, unsigned long n)
6186 -{
6187 - unsigned long over;
6188 -
6189 - if (access_ok(VERIFY_READ, from, n))
6190 - return __copy_tofrom_user((__force void __user *)to, from, n);
6191 - if ((unsigned long)from < TASK_SIZE) {
6192 - over = (unsigned long)from + n - TASK_SIZE;
6193 - return __copy_tofrom_user((__force void __user *)to, from,
6194 - n - over) + over;
6195 - }
6196 - return n;
6197 -}
6198 -
6199 -static inline unsigned long copy_to_user(void __user *to,
6200 - const void *from, unsigned long n)
6201 -{
6202 - unsigned long over;
6203 -
6204 - if (access_ok(VERIFY_WRITE, to, n))
6205 - return __copy_tofrom_user(to, (__force void __user *)from, n);
6206 - if ((unsigned long)to < TASK_SIZE) {
6207 - over = (unsigned long)to + n - TASK_SIZE;
6208 - return __copy_tofrom_user(to, (__force void __user *)from,
6209 - n - over) + over;
6210 - }
6211 - return n;
6212 -}
6213 -
6214 -#else /* __powerpc64__ */
6215 -
6216 -#define __copy_in_user(to, from, size) \
6217 - __copy_tofrom_user((to), (from), (size))
6218 -
6219 -extern unsigned long copy_from_user(void *to, const void __user *from,
6220 - unsigned long n);
6221 -extern unsigned long copy_to_user(void __user *to, const void *from,
6222 - unsigned long n);
6223 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
6224 - unsigned long n);
6225 -
6226 -#endif /* __powerpc64__ */
6227 -
6228 static inline unsigned long __copy_from_user_inatomic(void *to,
6229 const void __user *from, unsigned long n)
6230 {
6231 @@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6232 if (ret == 0)
6233 return 0;
6234 }
6235 +
6236 + if (!__builtin_constant_p(n))
6237 + check_object_size(to, n, false);
6238 +
6239 return __copy_tofrom_user((__force void __user *)to, from, n);
6240 }
6241
6242 @@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6243 if (ret == 0)
6244 return 0;
6245 }
6246 +
6247 + if (!__builtin_constant_p(n))
6248 + check_object_size(from, n, true);
6249 +
6250 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6251 }
6252
6253 @@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6254 return __copy_to_user_inatomic(to, from, size);
6255 }
6256
6257 +#ifndef __powerpc64__
6258 +
6259 +static inline unsigned long __must_check copy_from_user(void *to,
6260 + const void __user *from, unsigned long n)
6261 +{
6262 + unsigned long over;
6263 +
6264 + if ((long)n < 0)
6265 + return n;
6266 +
6267 + if (access_ok(VERIFY_READ, from, n)) {
6268 + if (!__builtin_constant_p(n))
6269 + check_object_size(to, n, false);
6270 + return __copy_tofrom_user((__force void __user *)to, from, n);
6271 + }
6272 + if ((unsigned long)from < TASK_SIZE) {
6273 + over = (unsigned long)from + n - TASK_SIZE;
6274 + if (!__builtin_constant_p(n - over))
6275 + check_object_size(to, n - over, false);
6276 + return __copy_tofrom_user((__force void __user *)to, from,
6277 + n - over) + over;
6278 + }
6279 + return n;
6280 +}
6281 +
6282 +static inline unsigned long __must_check copy_to_user(void __user *to,
6283 + const void *from, unsigned long n)
6284 +{
6285 + unsigned long over;
6286 +
6287 + if ((long)n < 0)
6288 + return n;
6289 +
6290 + if (access_ok(VERIFY_WRITE, to, n)) {
6291 + if (!__builtin_constant_p(n))
6292 + check_object_size(from, n, true);
6293 + return __copy_tofrom_user(to, (__force void __user *)from, n);
6294 + }
6295 + if ((unsigned long)to < TASK_SIZE) {
6296 + over = (unsigned long)to + n - TASK_SIZE;
6297 + if (!__builtin_constant_p(n))
6298 + check_object_size(from, n - over, true);
6299 + return __copy_tofrom_user(to, (__force void __user *)from,
6300 + n - over) + over;
6301 + }
6302 + return n;
6303 +}
6304 +
6305 +#else /* __powerpc64__ */
6306 +
6307 +#define __copy_in_user(to, from, size) \
6308 + __copy_tofrom_user((to), (from), (size))
6309 +
6310 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6311 +{
6312 + if ((long)n < 0 || n > INT_MAX)
6313 + return n;
6314 +
6315 + if (!__builtin_constant_p(n))
6316 + check_object_size(to, n, false);
6317 +
6318 + if (likely(access_ok(VERIFY_READ, from, n)))
6319 + n = __copy_from_user(to, from, n);
6320 + else
6321 + memset(to, 0, n);
6322 + return n;
6323 +}
6324 +
6325 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6326 +{
6327 + if ((long)n < 0 || n > INT_MAX)
6328 + return n;
6329 +
6330 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
6331 + if (!__builtin_constant_p(n))
6332 + check_object_size(from, n, true);
6333 + n = __copy_to_user(to, from, n);
6334 + }
6335 + return n;
6336 +}
6337 +
6338 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
6339 + unsigned long n);
6340 +
6341 +#endif /* __powerpc64__ */
6342 +
6343 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6344
6345 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6346 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6347 index 4684e33..acc4d19e 100644
6348 --- a/arch/powerpc/kernel/exceptions-64e.S
6349 +++ b/arch/powerpc/kernel/exceptions-64e.S
6350 @@ -715,6 +715,7 @@ storage_fault_common:
6351 std r14,_DAR(r1)
6352 std r15,_DSISR(r1)
6353 addi r3,r1,STACK_FRAME_OVERHEAD
6354 + bl .save_nvgprs
6355 mr r4,r14
6356 mr r5,r15
6357 ld r14,PACA_EXGEN+EX_R14(r13)
6358 @@ -723,8 +724,7 @@ storage_fault_common:
6359 cmpdi r3,0
6360 bne- 1f
6361 b .ret_from_except_lite
6362 -1: bl .save_nvgprs
6363 - mr r5,r3
6364 +1: mr r5,r3
6365 addi r3,r1,STACK_FRAME_OVERHEAD
6366 ld r4,_DAR(r1)
6367 bl .bad_page_fault
6368 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6369 index 4665e82..080ea99 100644
6370 --- a/arch/powerpc/kernel/exceptions-64s.S
6371 +++ b/arch/powerpc/kernel/exceptions-64s.S
6372 @@ -1206,10 +1206,10 @@ handle_page_fault:
6373 11: ld r4,_DAR(r1)
6374 ld r5,_DSISR(r1)
6375 addi r3,r1,STACK_FRAME_OVERHEAD
6376 + bl .save_nvgprs
6377 bl .do_page_fault
6378 cmpdi r3,0
6379 beq+ 12f
6380 - bl .save_nvgprs
6381 mr r5,r3
6382 addi r3,r1,STACK_FRAME_OVERHEAD
6383 lwz r4,_DAR(r1)
6384 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6385 index 2e3200c..72095ce 100644
6386 --- a/arch/powerpc/kernel/module_32.c
6387 +++ b/arch/powerpc/kernel/module_32.c
6388 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6389 me->arch.core_plt_section = i;
6390 }
6391 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6392 - printk("Module doesn't contain .plt or .init.plt sections.\n");
6393 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6394 return -ENOEXEC;
6395 }
6396
6397 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6398
6399 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6400 /* Init, or core PLT? */
6401 - if (location >= mod->module_core
6402 - && location < mod->module_core + mod->core_size)
6403 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6404 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6405 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6406 - else
6407 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6408 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6409 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6410 + else {
6411 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6412 + return ~0UL;
6413 + }
6414
6415 /* Find this entry, or if that fails, the next avail. entry */
6416 while (entry->jump[0]) {
6417 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6418 index 8143067..21ae55b 100644
6419 --- a/arch/powerpc/kernel/process.c
6420 +++ b/arch/powerpc/kernel/process.c
6421 @@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
6422 * Lookup NIP late so we have the best change of getting the
6423 * above info out without failing
6424 */
6425 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6426 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6427 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6428 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6429 #endif
6430 show_stack(current, (unsigned long *) regs->gpr[1]);
6431 if (!user_mode(regs))
6432 @@ -1129,10 +1129,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6433 newsp = stack[0];
6434 ip = stack[STACK_FRAME_LR_SAVE];
6435 if (!firstframe || ip != lr) {
6436 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6437 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6438 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6439 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6440 - printk(" (%pS)",
6441 + printk(" (%pA)",
6442 (void *)current->ret_stack[curr_frame].ret);
6443 curr_frame--;
6444 }
6445 @@ -1152,7 +1152,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6446 struct pt_regs *regs = (struct pt_regs *)
6447 (sp + STACK_FRAME_OVERHEAD);
6448 lr = regs->link;
6449 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
6450 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
6451 regs->trap, (void *)regs->nip, (void *)lr);
6452 firstframe = 1;
6453 }
6454 @@ -1194,58 +1194,3 @@ void __ppc64_runlatch_off(void)
6455 mtspr(SPRN_CTRLT, ctrl);
6456 }
6457 #endif /* CONFIG_PPC64 */
6458 -
6459 -unsigned long arch_align_stack(unsigned long sp)
6460 -{
6461 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6462 - sp -= get_random_int() & ~PAGE_MASK;
6463 - return sp & ~0xf;
6464 -}
6465 -
6466 -static inline unsigned long brk_rnd(void)
6467 -{
6468 - unsigned long rnd = 0;
6469 -
6470 - /* 8MB for 32bit, 1GB for 64bit */
6471 - if (is_32bit_task())
6472 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6473 - else
6474 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6475 -
6476 - return rnd << PAGE_SHIFT;
6477 -}
6478 -
6479 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6480 -{
6481 - unsigned long base = mm->brk;
6482 - unsigned long ret;
6483 -
6484 -#ifdef CONFIG_PPC_STD_MMU_64
6485 - /*
6486 - * If we are using 1TB segments and we are allowed to randomise
6487 - * the heap, we can put it above 1TB so it is backed by a 1TB
6488 - * segment. Otherwise the heap will be in the bottom 1TB
6489 - * which always uses 256MB segments and this may result in a
6490 - * performance penalty.
6491 - */
6492 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6493 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6494 -#endif
6495 -
6496 - ret = PAGE_ALIGN(base + brk_rnd());
6497 -
6498 - if (ret < mm->brk)
6499 - return mm->brk;
6500 -
6501 - return ret;
6502 -}
6503 -
6504 -unsigned long randomize_et_dyn(unsigned long base)
6505 -{
6506 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6507 -
6508 - if (ret < base)
6509 - return base;
6510 -
6511 - return ret;
6512 -}
6513 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6514 index c497000..8fde506 100644
6515 --- a/arch/powerpc/kernel/ptrace.c
6516 +++ b/arch/powerpc/kernel/ptrace.c
6517 @@ -1737,6 +1737,10 @@ long arch_ptrace(struct task_struct *child, long request,
6518 return ret;
6519 }
6520
6521 +#ifdef CONFIG_GRKERNSEC_SETXID
6522 +extern void gr_delayed_cred_worker(void);
6523 +#endif
6524 +
6525 /*
6526 * We must return the syscall number to actually look up in the table.
6527 * This can be -1L to skip running any syscall at all.
6528 @@ -1747,6 +1751,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6529
6530 secure_computing_strict(regs->gpr[0]);
6531
6532 +#ifdef CONFIG_GRKERNSEC_SETXID
6533 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6534 + gr_delayed_cred_worker();
6535 +#endif
6536 +
6537 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6538 tracehook_report_syscall_entry(regs))
6539 /*
6540 @@ -1781,6 +1790,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6541 {
6542 int step;
6543
6544 +#ifdef CONFIG_GRKERNSEC_SETXID
6545 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6546 + gr_delayed_cred_worker();
6547 +#endif
6548 +
6549 audit_syscall_exit(regs);
6550
6551 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6552 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6553 index 804e323..79181c1 100644
6554 --- a/arch/powerpc/kernel/signal_32.c
6555 +++ b/arch/powerpc/kernel/signal_32.c
6556 @@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6557 /* Save user registers on the stack */
6558 frame = &rt_sf->uc.uc_mcontext;
6559 addr = frame;
6560 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6561 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6562 if (save_user_regs(regs, frame, 0, 1))
6563 goto badframe;
6564 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6565 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6566 index 1ca045d..139c3f7 100644
6567 --- a/arch/powerpc/kernel/signal_64.c
6568 +++ b/arch/powerpc/kernel/signal_64.c
6569 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6570 current->thread.fpscr.val = 0;
6571
6572 /* Set up to return from userspace. */
6573 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6574 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6575 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6576 } else {
6577 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6578 diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6579 index 3ce1f86..c30e629 100644
6580 --- a/arch/powerpc/kernel/sysfs.c
6581 +++ b/arch/powerpc/kernel/sysfs.c
6582 @@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6583 return NOTIFY_OK;
6584 }
6585
6586 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6587 +static struct notifier_block sysfs_cpu_nb = {
6588 .notifier_call = sysfs_cpu_notify,
6589 };
6590
6591 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6592 index 3251840..3f7c77a 100644
6593 --- a/arch/powerpc/kernel/traps.c
6594 +++ b/arch/powerpc/kernel/traps.c
6595 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6596 return flags;
6597 }
6598
6599 +extern void gr_handle_kernel_exploit(void);
6600 +
6601 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6602 int signr)
6603 {
6604 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6605 panic("Fatal exception in interrupt");
6606 if (panic_on_oops)
6607 panic("Fatal exception");
6608 +
6609 + gr_handle_kernel_exploit();
6610 +
6611 do_exit(signr);
6612 }
6613
6614 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6615 index 1b2076f..835e4be 100644
6616 --- a/arch/powerpc/kernel/vdso.c
6617 +++ b/arch/powerpc/kernel/vdso.c
6618 @@ -34,6 +34,7 @@
6619 #include <asm/firmware.h>
6620 #include <asm/vdso.h>
6621 #include <asm/vdso_datapage.h>
6622 +#include <asm/mman.h>
6623
6624 #include "setup.h"
6625
6626 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6627 vdso_base = VDSO32_MBASE;
6628 #endif
6629
6630 - current->mm->context.vdso_base = 0;
6631 + current->mm->context.vdso_base = ~0UL;
6632
6633 /* vDSO has a problem and was disabled, just don't "enable" it for the
6634 * process
6635 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6636 vdso_base = get_unmapped_area(NULL, vdso_base,
6637 (vdso_pages << PAGE_SHIFT) +
6638 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6639 - 0, 0);
6640 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
6641 if (IS_ERR_VALUE(vdso_base)) {
6642 rc = vdso_base;
6643 goto fail_mmapsem;
6644 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6645 index 5eea6f3..5d10396 100644
6646 --- a/arch/powerpc/lib/usercopy_64.c
6647 +++ b/arch/powerpc/lib/usercopy_64.c
6648 @@ -9,22 +9,6 @@
6649 #include <linux/module.h>
6650 #include <asm/uaccess.h>
6651
6652 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6653 -{
6654 - if (likely(access_ok(VERIFY_READ, from, n)))
6655 - n = __copy_from_user(to, from, n);
6656 - else
6657 - memset(to, 0, n);
6658 - return n;
6659 -}
6660 -
6661 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6662 -{
6663 - if (likely(access_ok(VERIFY_WRITE, to, n)))
6664 - n = __copy_to_user(to, from, n);
6665 - return n;
6666 -}
6667 -
6668 unsigned long copy_in_user(void __user *to, const void __user *from,
6669 unsigned long n)
6670 {
6671 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6672 return n;
6673 }
6674
6675 -EXPORT_SYMBOL(copy_from_user);
6676 -EXPORT_SYMBOL(copy_to_user);
6677 EXPORT_SYMBOL(copy_in_user);
6678
6679 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6680 index 3a8489a..6a63b3b 100644
6681 --- a/arch/powerpc/mm/fault.c
6682 +++ b/arch/powerpc/mm/fault.c
6683 @@ -32,6 +32,10 @@
6684 #include <linux/perf_event.h>
6685 #include <linux/magic.h>
6686 #include <linux/ratelimit.h>
6687 +#include <linux/slab.h>
6688 +#include <linux/pagemap.h>
6689 +#include <linux/compiler.h>
6690 +#include <linux/unistd.h>
6691
6692 #include <asm/firmware.h>
6693 #include <asm/page.h>
6694 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6695 }
6696 #endif
6697
6698 +#ifdef CONFIG_PAX_PAGEEXEC
6699 +/*
6700 + * PaX: decide what to do with offenders (regs->nip = fault address)
6701 + *
6702 + * returns 1 when task should be killed
6703 + */
6704 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6705 +{
6706 + return 1;
6707 +}
6708 +
6709 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6710 +{
6711 + unsigned long i;
6712 +
6713 + printk(KERN_ERR "PAX: bytes at PC: ");
6714 + for (i = 0; i < 5; i++) {
6715 + unsigned int c;
6716 + if (get_user(c, (unsigned int __user *)pc+i))
6717 + printk(KERN_CONT "???????? ");
6718 + else
6719 + printk(KERN_CONT "%08x ", c);
6720 + }
6721 + printk("\n");
6722 +}
6723 +#endif
6724 +
6725 /*
6726 * Check whether the instruction at regs->nip is a store using
6727 * an update addressing form which will update r1.
6728 @@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6729 * indicate errors in DSISR but can validly be set in SRR1.
6730 */
6731 if (trap == 0x400)
6732 - error_code &= 0x48200000;
6733 + error_code &= 0x58200000;
6734 else
6735 is_write = error_code & DSISR_ISSTORE;
6736 #else
6737 @@ -364,7 +395,7 @@ good_area:
6738 * "undefined". Of those that can be set, this is the only
6739 * one which seems bad.
6740 */
6741 - if (error_code & 0x10000000)
6742 + if (error_code & DSISR_GUARDED)
6743 /* Guarded storage error. */
6744 goto bad_area;
6745 #endif /* CONFIG_8xx */
6746 @@ -379,7 +410,7 @@ good_area:
6747 * processors use the same I/D cache coherency mechanism
6748 * as embedded.
6749 */
6750 - if (error_code & DSISR_PROTFAULT)
6751 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6752 goto bad_area;
6753 #endif /* CONFIG_PPC_STD_MMU */
6754
6755 @@ -462,6 +493,23 @@ bad_area:
6756 bad_area_nosemaphore:
6757 /* User mode accesses cause a SIGSEGV */
6758 if (user_mode(regs)) {
6759 +
6760 +#ifdef CONFIG_PAX_PAGEEXEC
6761 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6762 +#ifdef CONFIG_PPC_STD_MMU
6763 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6764 +#else
6765 + if (is_exec && regs->nip == address) {
6766 +#endif
6767 + switch (pax_handle_fetch_fault(regs)) {
6768 + }
6769 +
6770 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
6771 + do_group_exit(SIGKILL);
6772 + }
6773 + }
6774 +#endif
6775 +
6776 _exception(SIGSEGV, regs, code, address);
6777 return 0;
6778 }
6779 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
6780 index 67a42ed..cd463e0 100644
6781 --- a/arch/powerpc/mm/mmap_64.c
6782 +++ b/arch/powerpc/mm/mmap_64.c
6783 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
6784 {
6785 unsigned long rnd = 0;
6786
6787 +#ifdef CONFIG_PAX_RANDMMAP
6788 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6789 +#endif
6790 +
6791 if (current->flags & PF_RANDOMIZE) {
6792 /* 8MB for 32bit, 1GB for 64bit */
6793 if (is_32bit_task())
6794 @@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6795 */
6796 if (mmap_is_legacy()) {
6797 mm->mmap_base = TASK_UNMAPPED_BASE;
6798 +
6799 +#ifdef CONFIG_PAX_RANDMMAP
6800 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6801 + mm->mmap_base += mm->delta_mmap;
6802 +#endif
6803 +
6804 mm->get_unmapped_area = arch_get_unmapped_area;
6805 mm->unmap_area = arch_unmap_area;
6806 } else {
6807 mm->mmap_base = mmap_base();
6808 +
6809 +#ifdef CONFIG_PAX_RANDMMAP
6810 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6811 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6812 +#endif
6813 +
6814 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6815 mm->unmap_area = arch_unmap_area_topdown;
6816 }
6817 diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
6818 index e779642..e5bb889 100644
6819 --- a/arch/powerpc/mm/mmu_context_nohash.c
6820 +++ b/arch/powerpc/mm/mmu_context_nohash.c
6821 @@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
6822 return NOTIFY_OK;
6823 }
6824
6825 -static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
6826 +static struct notifier_block mmu_context_cpu_nb = {
6827 .notifier_call = mmu_context_cpu_notify,
6828 };
6829
6830 diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
6831 index bba87ca..c346a33 100644
6832 --- a/arch/powerpc/mm/numa.c
6833 +++ b/arch/powerpc/mm/numa.c
6834 @@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
6835 return ret;
6836 }
6837
6838 -static struct notifier_block __cpuinitdata ppc64_numa_nb = {
6839 +static struct notifier_block ppc64_numa_nb = {
6840 .notifier_call = cpu_numa_callback,
6841 .priority = 1 /* Must run before sched domains notifier. */
6842 };
6843 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
6844 index cf9dada..241529f 100644
6845 --- a/arch/powerpc/mm/slice.c
6846 +++ b/arch/powerpc/mm/slice.c
6847 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
6848 if ((mm->task_size - len) < addr)
6849 return 0;
6850 vma = find_vma(mm, addr);
6851 - return (!vma || (addr + len) <= vma->vm_start);
6852 + return check_heap_stack_gap(vma, addr, len, 0);
6853 }
6854
6855 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
6856 @@ -272,7 +272,7 @@ full_search:
6857 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
6858 continue;
6859 }
6860 - if (!vma || addr + len <= vma->vm_start) {
6861 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6862 /*
6863 * Remember the place where we stopped the search:
6864 */
6865 @@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6866 }
6867 }
6868
6869 - addr = mm->mmap_base;
6870 - while (addr > len) {
6871 + if (mm->mmap_base < len)
6872 + addr = -ENOMEM;
6873 + else
6874 + addr = mm->mmap_base - len;
6875 +
6876 + while (!IS_ERR_VALUE(addr)) {
6877 /* Go down by chunk size */
6878 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
6879 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
6880
6881 /* Check for hit with different page size */
6882 mask = slice_range_to_mask(addr, len);
6883 @@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6884 * return with success:
6885 */
6886 vma = find_vma(mm, addr);
6887 - if (!vma || (addr + len) <= vma->vm_start) {
6888 + if (check_heap_stack_gap(vma, addr, len, 0)) {
6889 /* remember the address as a hint for next time */
6890 if (use_cache)
6891 mm->free_area_cache = addr;
6892 @@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
6893 mm->cached_hole_size = vma->vm_start - addr;
6894
6895 /* try just below the current vma->vm_start */
6896 - addr = vma->vm_start;
6897 + addr = skip_heap_stack_gap(vma, len, 0);
6898 }
6899
6900 /*
6901 @@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
6902 if (fixed && addr > (mm->task_size - len))
6903 return -EINVAL;
6904
6905 +#ifdef CONFIG_PAX_RANDMMAP
6906 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
6907 + addr = 0;
6908 +#endif
6909 +
6910 /* If hint, make sure it matches our alignment restrictions */
6911 if (!fixed && addr) {
6912 addr = _ALIGN_UP(addr, 1ul << pshift);
6913 diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
6914 index bdb738a..49c9f95 100644
6915 --- a/arch/powerpc/platforms/powermac/smp.c
6916 +++ b/arch/powerpc/platforms/powermac/smp.c
6917 @@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
6918 return NOTIFY_OK;
6919 }
6920
6921 -static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
6922 +static struct notifier_block smp_core99_cpu_nb = {
6923 .notifier_call = smp_core99_cpu_notify,
6924 };
6925 #endif /* CONFIG_HOTPLUG_CPU */
6926 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
6927 index c797832..ce575c8 100644
6928 --- a/arch/s390/include/asm/atomic.h
6929 +++ b/arch/s390/include/asm/atomic.h
6930 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
6931 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
6932 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6933
6934 +#define atomic64_read_unchecked(v) atomic64_read(v)
6935 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6936 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6937 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6938 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6939 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
6940 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6941 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
6942 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6943 +
6944 #define smp_mb__before_atomic_dec() smp_mb()
6945 #define smp_mb__after_atomic_dec() smp_mb()
6946 #define smp_mb__before_atomic_inc() smp_mb()
6947 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
6948 index 4d7ccac..d03d0ad 100644
6949 --- a/arch/s390/include/asm/cache.h
6950 +++ b/arch/s390/include/asm/cache.h
6951 @@ -9,8 +9,10 @@
6952 #ifndef __ARCH_S390_CACHE_H
6953 #define __ARCH_S390_CACHE_H
6954
6955 -#define L1_CACHE_BYTES 256
6956 +#include <linux/const.h>
6957 +
6958 #define L1_CACHE_SHIFT 8
6959 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6960 #define NET_SKB_PAD 32
6961
6962 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6963 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
6964 index 178ff96..8c93bd1 100644
6965 --- a/arch/s390/include/asm/elf.h
6966 +++ b/arch/s390/include/asm/elf.h
6967 @@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
6968 the loader. We need to make sure that it is out of the way of the program
6969 that it will "exec", and that there is sufficient room for the brk. */
6970
6971 -extern unsigned long randomize_et_dyn(unsigned long base);
6972 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
6973 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
6974 +
6975 +#ifdef CONFIG_PAX_ASLR
6976 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
6977 +
6978 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6979 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
6980 +#endif
6981
6982 /* This yields a mask that user programs can use to figure out what
6983 instruction set this CPU supports. */
6984 @@ -210,9 +216,6 @@ struct linux_binprm;
6985 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6986 int arch_setup_additional_pages(struct linux_binprm *, int);
6987
6988 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6989 -#define arch_randomize_brk arch_randomize_brk
6990 -
6991 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
6992
6993 #endif
6994 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
6995 index c4a93d6..4d2a9b4 100644
6996 --- a/arch/s390/include/asm/exec.h
6997 +++ b/arch/s390/include/asm/exec.h
6998 @@ -7,6 +7,6 @@
6999 #ifndef __ASM_EXEC_H
7000 #define __ASM_EXEC_H
7001
7002 -extern unsigned long arch_align_stack(unsigned long sp);
7003 +#define arch_align_stack(x) ((x) & ~0xfUL)
7004
7005 #endif /* __ASM_EXEC_H */
7006 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7007 index 34268df..ea97318 100644
7008 --- a/arch/s390/include/asm/uaccess.h
7009 +++ b/arch/s390/include/asm/uaccess.h
7010 @@ -252,6 +252,10 @@ static inline unsigned long __must_check
7011 copy_to_user(void __user *to, const void *from, unsigned long n)
7012 {
7013 might_fault();
7014 +
7015 + if ((long)n < 0)
7016 + return n;
7017 +
7018 if (access_ok(VERIFY_WRITE, to, n))
7019 n = __copy_to_user(to, from, n);
7020 return n;
7021 @@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7022 static inline unsigned long __must_check
7023 __copy_from_user(void *to, const void __user *from, unsigned long n)
7024 {
7025 + if ((long)n < 0)
7026 + return n;
7027 +
7028 if (__builtin_constant_p(n) && (n <= 256))
7029 return uaccess.copy_from_user_small(n, from, to);
7030 else
7031 @@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7032 static inline unsigned long __must_check
7033 copy_from_user(void *to, const void __user *from, unsigned long n)
7034 {
7035 - unsigned int sz = __compiletime_object_size(to);
7036 + size_t sz = __compiletime_object_size(to);
7037
7038 might_fault();
7039 - if (unlikely(sz != -1 && sz < n)) {
7040 +
7041 + if ((long)n < 0)
7042 + return n;
7043 +
7044 + if (unlikely(sz != (size_t)-1 && sz < n)) {
7045 copy_from_user_overflow();
7046 return n;
7047 }
7048 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7049 index 4610dea..cf0af21 100644
7050 --- a/arch/s390/kernel/module.c
7051 +++ b/arch/s390/kernel/module.c
7052 @@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7053
7054 /* Increase core size by size of got & plt and set start
7055 offsets for got and plt. */
7056 - me->core_size = ALIGN(me->core_size, 4);
7057 - me->arch.got_offset = me->core_size;
7058 - me->core_size += me->arch.got_size;
7059 - me->arch.plt_offset = me->core_size;
7060 - me->core_size += me->arch.plt_size;
7061 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
7062 + me->arch.got_offset = me->core_size_rw;
7063 + me->core_size_rw += me->arch.got_size;
7064 + me->arch.plt_offset = me->core_size_rx;
7065 + me->core_size_rx += me->arch.plt_size;
7066 return 0;
7067 }
7068
7069 @@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7070 if (info->got_initialized == 0) {
7071 Elf_Addr *gotent;
7072
7073 - gotent = me->module_core + me->arch.got_offset +
7074 + gotent = me->module_core_rw + me->arch.got_offset +
7075 info->got_offset;
7076 *gotent = val;
7077 info->got_initialized = 1;
7078 @@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7079 else if (r_type == R_390_GOTENT ||
7080 r_type == R_390_GOTPLTENT)
7081 *(unsigned int *) loc =
7082 - (val + (Elf_Addr) me->module_core - loc) >> 1;
7083 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
7084 else if (r_type == R_390_GOT64 ||
7085 r_type == R_390_GOTPLT64)
7086 *(unsigned long *) loc = val;
7087 @@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7088 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7089 if (info->plt_initialized == 0) {
7090 unsigned int *ip;
7091 - ip = me->module_core + me->arch.plt_offset +
7092 + ip = me->module_core_rx + me->arch.plt_offset +
7093 info->plt_offset;
7094 #ifndef CONFIG_64BIT
7095 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7096 @@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7097 val - loc + 0xffffUL < 0x1ffffeUL) ||
7098 (r_type == R_390_PLT32DBL &&
7099 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7100 - val = (Elf_Addr) me->module_core +
7101 + val = (Elf_Addr) me->module_core_rx +
7102 me->arch.plt_offset +
7103 info->plt_offset;
7104 val += rela->r_addend - loc;
7105 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7106 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7107 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7108 val = val + rela->r_addend -
7109 - ((Elf_Addr) me->module_core + me->arch.got_offset);
7110 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7111 if (r_type == R_390_GOTOFF16)
7112 *(unsigned short *) loc = val;
7113 else if (r_type == R_390_GOTOFF32)
7114 @@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7115 break;
7116 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7117 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7118 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
7119 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7120 rela->r_addend - loc;
7121 if (r_type == R_390_GOTPC)
7122 *(unsigned int *) loc = val;
7123 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7124 index 536d645..4a5bd9e 100644
7125 --- a/arch/s390/kernel/process.c
7126 +++ b/arch/s390/kernel/process.c
7127 @@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7128 }
7129 return 0;
7130 }
7131 -
7132 -unsigned long arch_align_stack(unsigned long sp)
7133 -{
7134 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7135 - sp -= get_random_int() & ~PAGE_MASK;
7136 - return sp & ~0xf;
7137 -}
7138 -
7139 -static inline unsigned long brk_rnd(void)
7140 -{
7141 - /* 8MB for 32bit, 1GB for 64bit */
7142 - if (is_32bit_task())
7143 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7144 - else
7145 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7146 -}
7147 -
7148 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7149 -{
7150 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7151 -
7152 - if (ret < mm->brk)
7153 - return mm->brk;
7154 - return ret;
7155 -}
7156 -
7157 -unsigned long randomize_et_dyn(unsigned long base)
7158 -{
7159 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7160 -
7161 - if (!(current->flags & PF_RANDOMIZE))
7162 - return base;
7163 - if (ret < base)
7164 - return base;
7165 - return ret;
7166 -}
7167 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7168 index c59a5ef..3fae59c 100644
7169 --- a/arch/s390/mm/mmap.c
7170 +++ b/arch/s390/mm/mmap.c
7171 @@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7172 */
7173 if (mmap_is_legacy()) {
7174 mm->mmap_base = TASK_UNMAPPED_BASE;
7175 +
7176 +#ifdef CONFIG_PAX_RANDMMAP
7177 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7178 + mm->mmap_base += mm->delta_mmap;
7179 +#endif
7180 +
7181 mm->get_unmapped_area = arch_get_unmapped_area;
7182 mm->unmap_area = arch_unmap_area;
7183 } else {
7184 mm->mmap_base = mmap_base();
7185 +
7186 +#ifdef CONFIG_PAX_RANDMMAP
7187 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7188 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7189 +#endif
7190 +
7191 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7192 mm->unmap_area = arch_unmap_area_topdown;
7193 }
7194 @@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7195 */
7196 if (mmap_is_legacy()) {
7197 mm->mmap_base = TASK_UNMAPPED_BASE;
7198 +
7199 +#ifdef CONFIG_PAX_RANDMMAP
7200 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7201 + mm->mmap_base += mm->delta_mmap;
7202 +#endif
7203 +
7204 mm->get_unmapped_area = s390_get_unmapped_area;
7205 mm->unmap_area = arch_unmap_area;
7206 } else {
7207 mm->mmap_base = mmap_base();
7208 +
7209 +#ifdef CONFIG_PAX_RANDMMAP
7210 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7211 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7212 +#endif
7213 +
7214 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7215 mm->unmap_area = arch_unmap_area_topdown;
7216 }
7217 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7218 index ae3d59f..f65f075 100644
7219 --- a/arch/score/include/asm/cache.h
7220 +++ b/arch/score/include/asm/cache.h
7221 @@ -1,7 +1,9 @@
7222 #ifndef _ASM_SCORE_CACHE_H
7223 #define _ASM_SCORE_CACHE_H
7224
7225 +#include <linux/const.h>
7226 +
7227 #define L1_CACHE_SHIFT 4
7228 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7229 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7230
7231 #endif /* _ASM_SCORE_CACHE_H */
7232 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7233 index f9f3cd5..58ff438 100644
7234 --- a/arch/score/include/asm/exec.h
7235 +++ b/arch/score/include/asm/exec.h
7236 @@ -1,6 +1,6 @@
7237 #ifndef _ASM_SCORE_EXEC_H
7238 #define _ASM_SCORE_EXEC_H
7239
7240 -extern unsigned long arch_align_stack(unsigned long sp);
7241 +#define arch_align_stack(x) (x)
7242
7243 #endif /* _ASM_SCORE_EXEC_H */
7244 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7245 index 7956846..5f37677 100644
7246 --- a/arch/score/kernel/process.c
7247 +++ b/arch/score/kernel/process.c
7248 @@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7249
7250 return task_pt_regs(task)->cp0_epc;
7251 }
7252 -
7253 -unsigned long arch_align_stack(unsigned long sp)
7254 -{
7255 - return sp;
7256 -}
7257 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7258 index ef9e555..331bd29 100644
7259 --- a/arch/sh/include/asm/cache.h
7260 +++ b/arch/sh/include/asm/cache.h
7261 @@ -9,10 +9,11 @@
7262 #define __ASM_SH_CACHE_H
7263 #ifdef __KERNEL__
7264
7265 +#include <linux/const.h>
7266 #include <linux/init.h>
7267 #include <cpu/cache.h>
7268
7269 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7270 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7271
7272 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7273
7274 diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7275 index 03f2b55..b027032 100644
7276 --- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7277 +++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7278 @@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7279 return NOTIFY_OK;
7280 }
7281
7282 -static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7283 +static struct notifier_block shx3_cpu_notifier = {
7284 .notifier_call = shx3_cpu_callback,
7285 };
7286
7287 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7288 index 6777177..cb5e44f 100644
7289 --- a/arch/sh/mm/mmap.c
7290 +++ b/arch/sh/mm/mmap.c
7291 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7292 struct mm_struct *mm = current->mm;
7293 struct vm_area_struct *vma;
7294 int do_colour_align;
7295 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7296 struct vm_unmapped_area_info info;
7297
7298 if (flags & MAP_FIXED) {
7299 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7300 if (filp || (flags & MAP_SHARED))
7301 do_colour_align = 1;
7302
7303 +#ifdef CONFIG_PAX_RANDMMAP
7304 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7305 +#endif
7306 +
7307 if (addr) {
7308 if (do_colour_align)
7309 addr = COLOUR_ALIGN(addr, pgoff);
7310 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7311 addr = PAGE_ALIGN(addr);
7312
7313 vma = find_vma(mm, addr);
7314 - if (TASK_SIZE - len >= addr &&
7315 - (!vma || addr + len <= vma->vm_start))
7316 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7317 return addr;
7318 }
7319
7320 info.flags = 0;
7321 info.length = len;
7322 - info.low_limit = TASK_UNMAPPED_BASE;
7323 + info.low_limit = mm->mmap_base;
7324 info.high_limit = TASK_SIZE;
7325 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7326 info.align_offset = pgoff << PAGE_SHIFT;
7327 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7328 struct mm_struct *mm = current->mm;
7329 unsigned long addr = addr0;
7330 int do_colour_align;
7331 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7332 struct vm_unmapped_area_info info;
7333
7334 if (flags & MAP_FIXED) {
7335 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7336 if (filp || (flags & MAP_SHARED))
7337 do_colour_align = 1;
7338
7339 +#ifdef CONFIG_PAX_RANDMMAP
7340 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7341 +#endif
7342 +
7343 /* requesting a specific address */
7344 if (addr) {
7345 if (do_colour_align)
7346 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7347 addr = PAGE_ALIGN(addr);
7348
7349 vma = find_vma(mm, addr);
7350 - if (TASK_SIZE - len >= addr &&
7351 - (!vma || addr + len <= vma->vm_start))
7352 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7353 return addr;
7354 }
7355
7356 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7357 VM_BUG_ON(addr != -ENOMEM);
7358 info.flags = 0;
7359 info.low_limit = TASK_UNMAPPED_BASE;
7360 +
7361 +#ifdef CONFIG_PAX_RANDMMAP
7362 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7363 + info.low_limit += mm->delta_mmap;
7364 +#endif
7365 +
7366 info.high_limit = TASK_SIZE;
7367 addr = vm_unmapped_area(&info);
7368 }
7369 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7370 index be56a24..443328f 100644
7371 --- a/arch/sparc/include/asm/atomic_64.h
7372 +++ b/arch/sparc/include/asm/atomic_64.h
7373 @@ -14,18 +14,40 @@
7374 #define ATOMIC64_INIT(i) { (i) }
7375
7376 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7377 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7378 +{
7379 + return v->counter;
7380 +}
7381 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7382 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7383 +{
7384 + return v->counter;
7385 +}
7386
7387 #define atomic_set(v, i) (((v)->counter) = i)
7388 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7389 +{
7390 + v->counter = i;
7391 +}
7392 #define atomic64_set(v, i) (((v)->counter) = i)
7393 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7394 +{
7395 + v->counter = i;
7396 +}
7397
7398 extern void atomic_add(int, atomic_t *);
7399 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7400 extern void atomic64_add(long, atomic64_t *);
7401 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7402 extern void atomic_sub(int, atomic_t *);
7403 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7404 extern void atomic64_sub(long, atomic64_t *);
7405 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7406
7407 extern int atomic_add_ret(int, atomic_t *);
7408 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7409 extern long atomic64_add_ret(long, atomic64_t *);
7410 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7411 extern int atomic_sub_ret(int, atomic_t *);
7412 extern long atomic64_sub_ret(long, atomic64_t *);
7413
7414 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7415 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7416
7417 #define atomic_inc_return(v) atomic_add_ret(1, v)
7418 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7419 +{
7420 + return atomic_add_ret_unchecked(1, v);
7421 +}
7422 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7423 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7424 +{
7425 + return atomic64_add_ret_unchecked(1, v);
7426 +}
7427
7428 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7429 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7430
7431 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7432 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7433 +{
7434 + return atomic_add_ret_unchecked(i, v);
7435 +}
7436 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7437 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7438 +{
7439 + return atomic64_add_ret_unchecked(i, v);
7440 +}
7441
7442 /*
7443 * atomic_inc_and_test - increment and test
7444 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7445 * other cases.
7446 */
7447 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7448 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7449 +{
7450 + return atomic_inc_return_unchecked(v) == 0;
7451 +}
7452 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7453
7454 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7455 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7456 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7457
7458 #define atomic_inc(v) atomic_add(1, v)
7459 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7460 +{
7461 + atomic_add_unchecked(1, v);
7462 +}
7463 #define atomic64_inc(v) atomic64_add(1, v)
7464 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7465 +{
7466 + atomic64_add_unchecked(1, v);
7467 +}
7468
7469 #define atomic_dec(v) atomic_sub(1, v)
7470 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7471 +{
7472 + atomic_sub_unchecked(1, v);
7473 +}
7474 #define atomic64_dec(v) atomic64_sub(1, v)
7475 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7476 +{
7477 + atomic64_sub_unchecked(1, v);
7478 +}
7479
7480 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7481 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7482
7483 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7484 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7485 +{
7486 + return cmpxchg(&v->counter, old, new);
7487 +}
7488 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7489 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7490 +{
7491 + return xchg(&v->counter, new);
7492 +}
7493
7494 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7495 {
7496 - int c, old;
7497 + int c, old, new;
7498 c = atomic_read(v);
7499 for (;;) {
7500 - if (unlikely(c == (u)))
7501 + if (unlikely(c == u))
7502 break;
7503 - old = atomic_cmpxchg((v), c, c + (a));
7504 +
7505 + asm volatile("addcc %2, %0, %0\n"
7506 +
7507 +#ifdef CONFIG_PAX_REFCOUNT
7508 + "tvs %%icc, 6\n"
7509 +#endif
7510 +
7511 + : "=r" (new)
7512 + : "0" (c), "ir" (a)
7513 + : "cc");
7514 +
7515 + old = atomic_cmpxchg(v, c, new);
7516 if (likely(old == c))
7517 break;
7518 c = old;
7519 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7520 #define atomic64_cmpxchg(v, o, n) \
7521 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7522 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7523 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7524 +{
7525 + return xchg(&v->counter, new);
7526 +}
7527
7528 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7529 {
7530 - long c, old;
7531 + long c, old, new;
7532 c = atomic64_read(v);
7533 for (;;) {
7534 - if (unlikely(c == (u)))
7535 + if (unlikely(c == u))
7536 break;
7537 - old = atomic64_cmpxchg((v), c, c + (a));
7538 +
7539 + asm volatile("addcc %2, %0, %0\n"
7540 +
7541 +#ifdef CONFIG_PAX_REFCOUNT
7542 + "tvs %%xcc, 6\n"
7543 +#endif
7544 +
7545 + : "=r" (new)
7546 + : "0" (c), "ir" (a)
7547 + : "cc");
7548 +
7549 + old = atomic64_cmpxchg(v, c, new);
7550 if (likely(old == c))
7551 break;
7552 c = old;
7553 }
7554 - return c != (u);
7555 + return c != u;
7556 }
7557
7558 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7559 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7560 index 5bb6991..5c2132e 100644
7561 --- a/arch/sparc/include/asm/cache.h
7562 +++ b/arch/sparc/include/asm/cache.h
7563 @@ -7,10 +7,12 @@
7564 #ifndef _SPARC_CACHE_H
7565 #define _SPARC_CACHE_H
7566
7567 +#include <linux/const.h>
7568 +
7569 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7570
7571 #define L1_CACHE_SHIFT 5
7572 -#define L1_CACHE_BYTES 32
7573 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7574
7575 #ifdef CONFIG_SPARC32
7576 #define SMP_CACHE_BYTES_SHIFT 5
7577 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7578 index ac74a2c..a9e58af 100644
7579 --- a/arch/sparc/include/asm/elf_32.h
7580 +++ b/arch/sparc/include/asm/elf_32.h
7581 @@ -114,6 +114,13 @@ typedef struct {
7582
7583 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7584
7585 +#ifdef CONFIG_PAX_ASLR
7586 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7587 +
7588 +#define PAX_DELTA_MMAP_LEN 16
7589 +#define PAX_DELTA_STACK_LEN 16
7590 +#endif
7591 +
7592 /* This yields a mask that user programs can use to figure out what
7593 instruction set this cpu supports. This can NOT be done in userspace
7594 on Sparc. */
7595 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7596 index 370ca1e..d4f4a98 100644
7597 --- a/arch/sparc/include/asm/elf_64.h
7598 +++ b/arch/sparc/include/asm/elf_64.h
7599 @@ -189,6 +189,13 @@ typedef struct {
7600 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7601 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7602
7603 +#ifdef CONFIG_PAX_ASLR
7604 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7605 +
7606 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7607 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7608 +#endif
7609 +
7610 extern unsigned long sparc64_elf_hwcap;
7611 #define ELF_HWCAP sparc64_elf_hwcap
7612
7613 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7614 index 9b1c36d..209298b 100644
7615 --- a/arch/sparc/include/asm/pgalloc_32.h
7616 +++ b/arch/sparc/include/asm/pgalloc_32.h
7617 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7618 }
7619
7620 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7621 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7622
7623 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7624 unsigned long address)
7625 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7626 index bcfe063..b333142 100644
7627 --- a/arch/sparc/include/asm/pgalloc_64.h
7628 +++ b/arch/sparc/include/asm/pgalloc_64.h
7629 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7630 }
7631
7632 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7633 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7634
7635 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7636 {
7637 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7638 index 6fc1348..390c50a 100644
7639 --- a/arch/sparc/include/asm/pgtable_32.h
7640 +++ b/arch/sparc/include/asm/pgtable_32.h
7641 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7642 #define PAGE_SHARED SRMMU_PAGE_SHARED
7643 #define PAGE_COPY SRMMU_PAGE_COPY
7644 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7645 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7646 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7647 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7648 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7649
7650 /* Top-level page directory - dummy used by init-mm.
7651 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7652
7653 /* xwr */
7654 #define __P000 PAGE_NONE
7655 -#define __P001 PAGE_READONLY
7656 -#define __P010 PAGE_COPY
7657 -#define __P011 PAGE_COPY
7658 +#define __P001 PAGE_READONLY_NOEXEC
7659 +#define __P010 PAGE_COPY_NOEXEC
7660 +#define __P011 PAGE_COPY_NOEXEC
7661 #define __P100 PAGE_READONLY
7662 #define __P101 PAGE_READONLY
7663 #define __P110 PAGE_COPY
7664 #define __P111 PAGE_COPY
7665
7666 #define __S000 PAGE_NONE
7667 -#define __S001 PAGE_READONLY
7668 -#define __S010 PAGE_SHARED
7669 -#define __S011 PAGE_SHARED
7670 +#define __S001 PAGE_READONLY_NOEXEC
7671 +#define __S010 PAGE_SHARED_NOEXEC
7672 +#define __S011 PAGE_SHARED_NOEXEC
7673 #define __S100 PAGE_READONLY
7674 #define __S101 PAGE_READONLY
7675 #define __S110 PAGE_SHARED
7676 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7677 index 79da178..c2eede8 100644
7678 --- a/arch/sparc/include/asm/pgtsrmmu.h
7679 +++ b/arch/sparc/include/asm/pgtsrmmu.h
7680 @@ -115,6 +115,11 @@
7681 SRMMU_EXEC | SRMMU_REF)
7682 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7683 SRMMU_EXEC | SRMMU_REF)
7684 +
7685 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7686 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7687 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7688 +
7689 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7690 SRMMU_DIRTY | SRMMU_REF)
7691
7692 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7693 index 9689176..63c18ea 100644
7694 --- a/arch/sparc/include/asm/spinlock_64.h
7695 +++ b/arch/sparc/include/asm/spinlock_64.h
7696 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7697
7698 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7699
7700 -static void inline arch_read_lock(arch_rwlock_t *lock)
7701 +static inline void arch_read_lock(arch_rwlock_t *lock)
7702 {
7703 unsigned long tmp1, tmp2;
7704
7705 __asm__ __volatile__ (
7706 "1: ldsw [%2], %0\n"
7707 " brlz,pn %0, 2f\n"
7708 -"4: add %0, 1, %1\n"
7709 +"4: addcc %0, 1, %1\n"
7710 +
7711 +#ifdef CONFIG_PAX_REFCOUNT
7712 +" tvs %%icc, 6\n"
7713 +#endif
7714 +
7715 " cas [%2], %0, %1\n"
7716 " cmp %0, %1\n"
7717 " bne,pn %%icc, 1b\n"
7718 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7719 " .previous"
7720 : "=&r" (tmp1), "=&r" (tmp2)
7721 : "r" (lock)
7722 - : "memory");
7723 + : "memory", "cc");
7724 }
7725
7726 -static int inline arch_read_trylock(arch_rwlock_t *lock)
7727 +static inline int arch_read_trylock(arch_rwlock_t *lock)
7728 {
7729 int tmp1, tmp2;
7730
7731 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7732 "1: ldsw [%2], %0\n"
7733 " brlz,a,pn %0, 2f\n"
7734 " mov 0, %0\n"
7735 -" add %0, 1, %1\n"
7736 +" addcc %0, 1, %1\n"
7737 +
7738 +#ifdef CONFIG_PAX_REFCOUNT
7739 +" tvs %%icc, 6\n"
7740 +#endif
7741 +
7742 " cas [%2], %0, %1\n"
7743 " cmp %0, %1\n"
7744 " bne,pn %%icc, 1b\n"
7745 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7746 return tmp1;
7747 }
7748
7749 -static void inline arch_read_unlock(arch_rwlock_t *lock)
7750 +static inline void arch_read_unlock(arch_rwlock_t *lock)
7751 {
7752 unsigned long tmp1, tmp2;
7753
7754 __asm__ __volatile__(
7755 "1: lduw [%2], %0\n"
7756 -" sub %0, 1, %1\n"
7757 +" subcc %0, 1, %1\n"
7758 +
7759 +#ifdef CONFIG_PAX_REFCOUNT
7760 +" tvs %%icc, 6\n"
7761 +#endif
7762 +
7763 " cas [%2], %0, %1\n"
7764 " cmp %0, %1\n"
7765 " bne,pn %%xcc, 1b\n"
7766 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
7767 : "memory");
7768 }
7769
7770 -static void inline arch_write_lock(arch_rwlock_t *lock)
7771 +static inline void arch_write_lock(arch_rwlock_t *lock)
7772 {
7773 unsigned long mask, tmp1, tmp2;
7774
7775 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
7776 : "memory");
7777 }
7778
7779 -static void inline arch_write_unlock(arch_rwlock_t *lock)
7780 +static inline void arch_write_unlock(arch_rwlock_t *lock)
7781 {
7782 __asm__ __volatile__(
7783 " stw %%g0, [%0]"
7784 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
7785 : "memory");
7786 }
7787
7788 -static int inline arch_write_trylock(arch_rwlock_t *lock)
7789 +static inline int arch_write_trylock(arch_rwlock_t *lock)
7790 {
7791 unsigned long mask, tmp1, tmp2, result;
7792
7793 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
7794 index 25849ae..924c54b 100644
7795 --- a/arch/sparc/include/asm/thread_info_32.h
7796 +++ b/arch/sparc/include/asm/thread_info_32.h
7797 @@ -49,6 +49,8 @@ struct thread_info {
7798 unsigned long w_saved;
7799
7800 struct restart_block restart_block;
7801 +
7802 + unsigned long lowest_stack;
7803 };
7804
7805 /*
7806 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
7807 index 269bd92..e46a9b8 100644
7808 --- a/arch/sparc/include/asm/thread_info_64.h
7809 +++ b/arch/sparc/include/asm/thread_info_64.h
7810 @@ -63,6 +63,8 @@ struct thread_info {
7811 struct pt_regs *kern_una_regs;
7812 unsigned int kern_una_insn;
7813
7814 + unsigned long lowest_stack;
7815 +
7816 unsigned long fpregs[0] __attribute__ ((aligned(64)));
7817 };
7818
7819 @@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
7820 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
7821 /* flag bit 6 is available */
7822 #define TIF_32BIT 7 /* 32-bit binary */
7823 -/* flag bit 8 is available */
7824 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
7825 #define TIF_SECCOMP 9 /* secure computing */
7826 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
7827 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
7828 +
7829 /* NOTE: Thread flags >= 12 should be ones we have no interest
7830 * in using in assembly, else we can't use the mask as
7831 * an immediate value in instructions such as andcc.
7832 @@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
7833 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
7834 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7835 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
7836 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7837
7838 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
7839 _TIF_DO_NOTIFY_RESUME_MASK | \
7840 _TIF_NEED_RESCHED)
7841 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
7842
7843 +#define _TIF_WORK_SYSCALL \
7844 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
7845 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
7846 +
7847 +
7848 /*
7849 * Thread-synchronous status.
7850 *
7851 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
7852 index 0167d26..9acd8ed 100644
7853 --- a/arch/sparc/include/asm/uaccess.h
7854 +++ b/arch/sparc/include/asm/uaccess.h
7855 @@ -1,5 +1,13 @@
7856 #ifndef ___ASM_SPARC_UACCESS_H
7857 #define ___ASM_SPARC_UACCESS_H
7858 +
7859 +#ifdef __KERNEL__
7860 +#ifndef __ASSEMBLY__
7861 +#include <linux/types.h>
7862 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
7863 +#endif
7864 +#endif
7865 +
7866 #if defined(__sparc__) && defined(__arch64__)
7867 #include <asm/uaccess_64.h>
7868 #else
7869 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
7870 index 53a28dd..50c38c3 100644
7871 --- a/arch/sparc/include/asm/uaccess_32.h
7872 +++ b/arch/sparc/include/asm/uaccess_32.h
7873 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
7874
7875 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
7876 {
7877 - if (n && __access_ok((unsigned long) to, n))
7878 + if ((long)n < 0)
7879 + return n;
7880 +
7881 + if (n && __access_ok((unsigned long) to, n)) {
7882 + if (!__builtin_constant_p(n))
7883 + check_object_size(from, n, true);
7884 return __copy_user(to, (__force void __user *) from, n);
7885 - else
7886 + } else
7887 return n;
7888 }
7889
7890 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
7891 {
7892 + if ((long)n < 0)
7893 + return n;
7894 +
7895 + if (!__builtin_constant_p(n))
7896 + check_object_size(from, n, true);
7897 +
7898 return __copy_user(to, (__force void __user *) from, n);
7899 }
7900
7901 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
7902 {
7903 - if (n && __access_ok((unsigned long) from, n))
7904 + if ((long)n < 0)
7905 + return n;
7906 +
7907 + if (n && __access_ok((unsigned long) from, n)) {
7908 + if (!__builtin_constant_p(n))
7909 + check_object_size(to, n, false);
7910 return __copy_user((__force void __user *) to, from, n);
7911 - else
7912 + } else
7913 return n;
7914 }
7915
7916 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
7917 {
7918 + if ((long)n < 0)
7919 + return n;
7920 +
7921 return __copy_user((__force void __user *) to, from, n);
7922 }
7923
7924 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
7925 index e562d3c..191f176 100644
7926 --- a/arch/sparc/include/asm/uaccess_64.h
7927 +++ b/arch/sparc/include/asm/uaccess_64.h
7928 @@ -10,6 +10,7 @@
7929 #include <linux/compiler.h>
7930 #include <linux/string.h>
7931 #include <linux/thread_info.h>
7932 +#include <linux/kernel.h>
7933 #include <asm/asi.h>
7934 #include <asm/spitfire.h>
7935 #include <asm-generic/uaccess-unaligned.h>
7936 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
7937 static inline unsigned long __must_check
7938 copy_from_user(void *to, const void __user *from, unsigned long size)
7939 {
7940 - unsigned long ret = ___copy_from_user(to, from, size);
7941 + unsigned long ret;
7942
7943 + if ((long)size < 0 || size > INT_MAX)
7944 + return size;
7945 +
7946 + if (!__builtin_constant_p(size))
7947 + check_object_size(to, size, false);
7948 +
7949 + ret = ___copy_from_user(to, from, size);
7950 if (unlikely(ret))
7951 ret = copy_from_user_fixup(to, from, size);
7952
7953 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
7954 static inline unsigned long __must_check
7955 copy_to_user(void __user *to, const void *from, unsigned long size)
7956 {
7957 - unsigned long ret = ___copy_to_user(to, from, size);
7958 + unsigned long ret;
7959
7960 + if ((long)size < 0 || size > INT_MAX)
7961 + return size;
7962 +
7963 + if (!__builtin_constant_p(size))
7964 + check_object_size(from, size, true);
7965 +
7966 + ret = ___copy_to_user(to, from, size);
7967 if (unlikely(ret))
7968 ret = copy_to_user_fixup(to, from, size);
7969 return ret;
7970 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
7971 index 6cf591b..b49e65a 100644
7972 --- a/arch/sparc/kernel/Makefile
7973 +++ b/arch/sparc/kernel/Makefile
7974 @@ -3,7 +3,7 @@
7975 #
7976
7977 asflags-y := -ansi
7978 -ccflags-y := -Werror
7979 +#ccflags-y := -Werror
7980
7981 extra-y := head_$(BITS).o
7982
7983 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
7984 index be8e862..5b50b12 100644
7985 --- a/arch/sparc/kernel/process_32.c
7986 +++ b/arch/sparc/kernel/process_32.c
7987 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
7988
7989 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
7990 r->psr, r->pc, r->npc, r->y, print_tainted());
7991 - printk("PC: <%pS>\n", (void *) r->pc);
7992 + printk("PC: <%pA>\n", (void *) r->pc);
7993 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7994 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
7995 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
7996 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
7997 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
7998 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
7999 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8000 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8001
8002 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8003 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8004 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8005 rw = (struct reg_window32 *) fp;
8006 pc = rw->ins[7];
8007 printk("[%08lx : ", pc);
8008 - printk("%pS ] ", (void *) pc);
8009 + printk("%pA ] ", (void *) pc);
8010 fp = rw->ins[6];
8011 } while (++count < 16);
8012 printk("\n");
8013 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8014 index cdb80b2..5ca141d 100644
8015 --- a/arch/sparc/kernel/process_64.c
8016 +++ b/arch/sparc/kernel/process_64.c
8017 @@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8018 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8019 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8020 if (regs->tstate & TSTATE_PRIV)
8021 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8022 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8023 }
8024
8025 void show_regs(struct pt_regs *regs)
8026 {
8027 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8028 regs->tpc, regs->tnpc, regs->y, print_tainted());
8029 - printk("TPC: <%pS>\n", (void *) regs->tpc);
8030 + printk("TPC: <%pA>\n", (void *) regs->tpc);
8031 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8032 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8033 regs->u_regs[3]);
8034 @@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8035 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8036 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8037 regs->u_regs[15]);
8038 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8039 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8040 show_regwindow(regs);
8041 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8042 }
8043 @@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8044 ((tp && tp->task) ? tp->task->pid : -1));
8045
8046 if (gp->tstate & TSTATE_PRIV) {
8047 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8048 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8049 (void *) gp->tpc,
8050 (void *) gp->o7,
8051 (void *) gp->i7,
8052 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8053 index 7ff45e4..a58f271 100644
8054 --- a/arch/sparc/kernel/ptrace_64.c
8055 +++ b/arch/sparc/kernel/ptrace_64.c
8056 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8057 return ret;
8058 }
8059
8060 +#ifdef CONFIG_GRKERNSEC_SETXID
8061 +extern void gr_delayed_cred_worker(void);
8062 +#endif
8063 +
8064 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8065 {
8066 int ret = 0;
8067 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8068 /* do the secure computing check first */
8069 secure_computing_strict(regs->u_regs[UREG_G1]);
8070
8071 +#ifdef CONFIG_GRKERNSEC_SETXID
8072 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8073 + gr_delayed_cred_worker();
8074 +#endif
8075 +
8076 if (test_thread_flag(TIF_SYSCALL_TRACE))
8077 ret = tracehook_report_syscall_entry(regs);
8078
8079 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8080
8081 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8082 {
8083 +#ifdef CONFIG_GRKERNSEC_SETXID
8084 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8085 + gr_delayed_cred_worker();
8086 +#endif
8087 +
8088 audit_syscall_exit(regs);
8089
8090 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8091 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8092 index 2da0bdc..79128d2 100644
8093 --- a/arch/sparc/kernel/sys_sparc_32.c
8094 +++ b/arch/sparc/kernel/sys_sparc_32.c
8095 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8096 if (len > TASK_SIZE - PAGE_SIZE)
8097 return -ENOMEM;
8098 if (!addr)
8099 - addr = TASK_UNMAPPED_BASE;
8100 + addr = current->mm->mmap_base;
8101
8102 info.flags = 0;
8103 info.length = len;
8104 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8105 index 708bc29..f0129cb 100644
8106 --- a/arch/sparc/kernel/sys_sparc_64.c
8107 +++ b/arch/sparc/kernel/sys_sparc_64.c
8108 @@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8109 struct vm_area_struct * vma;
8110 unsigned long task_size = TASK_SIZE;
8111 int do_color_align;
8112 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8113 struct vm_unmapped_area_info info;
8114
8115 if (flags & MAP_FIXED) {
8116 /* We do not accept a shared mapping if it would violate
8117 * cache aliasing constraints.
8118 */
8119 - if ((flags & MAP_SHARED) &&
8120 + if ((filp || (flags & MAP_SHARED)) &&
8121 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8122 return -EINVAL;
8123 return addr;
8124 @@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8125 if (filp || (flags & MAP_SHARED))
8126 do_color_align = 1;
8127
8128 +#ifdef CONFIG_PAX_RANDMMAP
8129 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8130 +#endif
8131 +
8132 if (addr) {
8133 if (do_color_align)
8134 addr = COLOR_ALIGN(addr, pgoff);
8135 @@ -118,14 +123,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8136 addr = PAGE_ALIGN(addr);
8137
8138 vma = find_vma(mm, addr);
8139 - if (task_size - len >= addr &&
8140 - (!vma || addr + len <= vma->vm_start))
8141 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8142 return addr;
8143 }
8144
8145 info.flags = 0;
8146 info.length = len;
8147 - info.low_limit = TASK_UNMAPPED_BASE;
8148 + info.low_limit = mm->mmap_base;
8149 info.high_limit = min(task_size, VA_EXCLUDE_START);
8150 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8151 info.align_offset = pgoff << PAGE_SHIFT;
8152 @@ -134,6 +138,12 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8153 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8154 VM_BUG_ON(addr != -ENOMEM);
8155 info.low_limit = VA_EXCLUDE_END;
8156 +
8157 +#ifdef CONFIG_PAX_RANDMMAP
8158 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8159 + info.low_limit += mm->delta_mmap;
8160 +#endif
8161 +
8162 info.high_limit = task_size;
8163 addr = vm_unmapped_area(&info);
8164 }
8165 @@ -151,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8166 unsigned long task_size = STACK_TOP32;
8167 unsigned long addr = addr0;
8168 int do_color_align;
8169 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8170 struct vm_unmapped_area_info info;
8171
8172 /* This should only ever run for 32-bit processes. */
8173 @@ -160,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8174 /* We do not accept a shared mapping if it would violate
8175 * cache aliasing constraints.
8176 */
8177 - if ((flags & MAP_SHARED) &&
8178 + if ((filp || (flags & MAP_SHARED)) &&
8179 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8180 return -EINVAL;
8181 return addr;
8182 @@ -173,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8183 if (filp || (flags & MAP_SHARED))
8184 do_color_align = 1;
8185
8186 +#ifdef CONFIG_PAX_RANDMMAP
8187 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8188 +#endif
8189 +
8190 /* requesting a specific address */
8191 if (addr) {
8192 if (do_color_align)
8193 @@ -181,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8194 addr = PAGE_ALIGN(addr);
8195
8196 vma = find_vma(mm, addr);
8197 - if (task_size - len >= addr &&
8198 - (!vma || addr + len <= vma->vm_start))
8199 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8200 return addr;
8201 }
8202
8203 @@ -204,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8204 VM_BUG_ON(addr != -ENOMEM);
8205 info.flags = 0;
8206 info.low_limit = TASK_UNMAPPED_BASE;
8207 +
8208 +#ifdef CONFIG_PAX_RANDMMAP
8209 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8210 + info.low_limit += mm->delta_mmap;
8211 +#endif
8212 +
8213 info.high_limit = STACK_TOP32;
8214 addr = vm_unmapped_area(&info);
8215 }
8216 @@ -264,6 +284,10 @@ static unsigned long mmap_rnd(void)
8217 {
8218 unsigned long rnd = 0UL;
8219
8220 +#ifdef CONFIG_PAX_RANDMMAP
8221 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8222 +#endif
8223 +
8224 if (current->flags & PF_RANDOMIZE) {
8225 unsigned long val = get_random_int();
8226 if (test_thread_flag(TIF_32BIT))
8227 @@ -289,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8228 gap == RLIM_INFINITY ||
8229 sysctl_legacy_va_layout) {
8230 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8231 +
8232 +#ifdef CONFIG_PAX_RANDMMAP
8233 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8234 + mm->mmap_base += mm->delta_mmap;
8235 +#endif
8236 +
8237 mm->get_unmapped_area = arch_get_unmapped_area;
8238 mm->unmap_area = arch_unmap_area;
8239 } else {
8240 @@ -301,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8241 gap = (task_size / 6 * 5);
8242
8243 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8244 +
8245 +#ifdef CONFIG_PAX_RANDMMAP
8246 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8247 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8248 +#endif
8249 +
8250 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8251 mm->unmap_area = arch_unmap_area_topdown;
8252 }
8253 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8254 index e0fed77..604a7e5 100644
8255 --- a/arch/sparc/kernel/syscalls.S
8256 +++ b/arch/sparc/kernel/syscalls.S
8257 @@ -58,7 +58,7 @@ sys32_rt_sigreturn:
8258 #endif
8259 .align 32
8260 1: ldx [%g6 + TI_FLAGS], %l5
8261 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8262 + andcc %l5, _TIF_WORK_SYSCALL, %g0
8263 be,pt %icc, rtrap
8264 nop
8265 call syscall_trace_leave
8266 @@ -190,7 +190,7 @@ linux_sparc_syscall32:
8267
8268 srl %i5, 0, %o5 ! IEU1
8269 srl %i2, 0, %o2 ! IEU0 Group
8270 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8271 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8272 bne,pn %icc, linux_syscall_trace32 ! CTI
8273 mov %i0, %l5 ! IEU1
8274 call %l7 ! CTI Group brk forced
8275 @@ -213,7 +213,7 @@ linux_sparc_syscall:
8276
8277 mov %i3, %o3 ! IEU1
8278 mov %i4, %o4 ! IEU0 Group
8279 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8280 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8281 bne,pn %icc, linux_syscall_trace ! CTI Group
8282 mov %i0, %l5 ! IEU0
8283 2: call %l7 ! CTI Group brk forced
8284 @@ -229,7 +229,7 @@ ret_sys_call:
8285
8286 cmp %o0, -ERESTART_RESTARTBLOCK
8287 bgeu,pn %xcc, 1f
8288 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8289 + andcc %l0, _TIF_WORK_SYSCALL, %g0
8290 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8291
8292 2:
8293 diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8294 index 654e8aa..45f431b 100644
8295 --- a/arch/sparc/kernel/sysfs.c
8296 +++ b/arch/sparc/kernel/sysfs.c
8297 @@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8298 return NOTIFY_OK;
8299 }
8300
8301 -static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8302 +static struct notifier_block sysfs_cpu_nb = {
8303 .notifier_call = sysfs_cpu_notify,
8304 };
8305
8306 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8307 index a5785ea..405c5f7 100644
8308 --- a/arch/sparc/kernel/traps_32.c
8309 +++ b/arch/sparc/kernel/traps_32.c
8310 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8311 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8312 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8313
8314 +extern void gr_handle_kernel_exploit(void);
8315 +
8316 void die_if_kernel(char *str, struct pt_regs *regs)
8317 {
8318 static int die_counter;
8319 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8320 count++ < 30 &&
8321 (((unsigned long) rw) >= PAGE_OFFSET) &&
8322 !(((unsigned long) rw) & 0x7)) {
8323 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
8324 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
8325 (void *) rw->ins[7]);
8326 rw = (struct reg_window32 *)rw->ins[6];
8327 }
8328 }
8329 printk("Instruction DUMP:");
8330 instruction_dump ((unsigned long *) regs->pc);
8331 - if(regs->psr & PSR_PS)
8332 + if(regs->psr & PSR_PS) {
8333 + gr_handle_kernel_exploit();
8334 do_exit(SIGKILL);
8335 + }
8336 do_exit(SIGSEGV);
8337 }
8338
8339 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8340 index e7ecf15..6520e65 100644
8341 --- a/arch/sparc/kernel/traps_64.c
8342 +++ b/arch/sparc/kernel/traps_64.c
8343 @@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8344 i + 1,
8345 p->trapstack[i].tstate, p->trapstack[i].tpc,
8346 p->trapstack[i].tnpc, p->trapstack[i].tt);
8347 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8348 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8349 }
8350 }
8351
8352 @@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8353
8354 lvl -= 0x100;
8355 if (regs->tstate & TSTATE_PRIV) {
8356 +
8357 +#ifdef CONFIG_PAX_REFCOUNT
8358 + if (lvl == 6)
8359 + pax_report_refcount_overflow(regs);
8360 +#endif
8361 +
8362 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8363 die_if_kernel(buffer, regs);
8364 }
8365 @@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8366 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8367 {
8368 char buffer[32];
8369 -
8370 +
8371 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8372 0, lvl, SIGTRAP) == NOTIFY_STOP)
8373 return;
8374
8375 +#ifdef CONFIG_PAX_REFCOUNT
8376 + if (lvl == 6)
8377 + pax_report_refcount_overflow(regs);
8378 +#endif
8379 +
8380 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8381
8382 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8383 @@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8384 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8385 printk("%s" "ERROR(%d): ",
8386 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8387 - printk("TPC<%pS>\n", (void *) regs->tpc);
8388 + printk("TPC<%pA>\n", (void *) regs->tpc);
8389 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8390 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8391 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8392 @@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8393 smp_processor_id(),
8394 (type & 0x1) ? 'I' : 'D',
8395 regs->tpc);
8396 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8397 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8398 panic("Irrecoverable Cheetah+ parity error.");
8399 }
8400
8401 @@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8402 smp_processor_id(),
8403 (type & 0x1) ? 'I' : 'D',
8404 regs->tpc);
8405 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8406 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8407 }
8408
8409 struct sun4v_error_entry {
8410 @@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8411
8412 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8413 regs->tpc, tl);
8414 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8415 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8416 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8417 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8418 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8419 (void *) regs->u_regs[UREG_I7]);
8420 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8421 "pte[%lx] error[%lx]\n",
8422 @@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8423
8424 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8425 regs->tpc, tl);
8426 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8427 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8428 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8429 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8430 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8431 (void *) regs->u_regs[UREG_I7]);
8432 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8433 "pte[%lx] error[%lx]\n",
8434 @@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8435 fp = (unsigned long)sf->fp + STACK_BIAS;
8436 }
8437
8438 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8439 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8440 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8441 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8442 int index = tsk->curr_ret_stack;
8443 if (tsk->ret_stack && index >= graph) {
8444 pc = tsk->ret_stack[index - graph].ret;
8445 - printk(" [%016lx] %pS\n", pc, (void *) pc);
8446 + printk(" [%016lx] %pA\n", pc, (void *) pc);
8447 graph++;
8448 }
8449 }
8450 @@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8451 return (struct reg_window *) (fp + STACK_BIAS);
8452 }
8453
8454 +extern void gr_handle_kernel_exploit(void);
8455 +
8456 void die_if_kernel(char *str, struct pt_regs *regs)
8457 {
8458 static int die_counter;
8459 @@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8460 while (rw &&
8461 count++ < 30 &&
8462 kstack_valid(tp, (unsigned long) rw)) {
8463 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
8464 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
8465 (void *) rw->ins[7]);
8466
8467 rw = kernel_stack_up(rw);
8468 @@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8469 }
8470 user_instruction_dump ((unsigned int __user *) regs->tpc);
8471 }
8472 - if (regs->tstate & TSTATE_PRIV)
8473 + if (regs->tstate & TSTATE_PRIV) {
8474 + gr_handle_kernel_exploit();
8475 do_exit(SIGKILL);
8476 + }
8477 do_exit(SIGSEGV);
8478 }
8479 EXPORT_SYMBOL(die_if_kernel);
8480 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8481 index 8201c25e..072a2a7 100644
8482 --- a/arch/sparc/kernel/unaligned_64.c
8483 +++ b/arch/sparc/kernel/unaligned_64.c
8484 @@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8485 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8486
8487 if (__ratelimit(&ratelimit)) {
8488 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
8489 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
8490 regs->tpc, (void *) regs->tpc);
8491 }
8492 }
8493 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8494 index 8410065f2..4fd4ca22 100644
8495 --- a/arch/sparc/lib/Makefile
8496 +++ b/arch/sparc/lib/Makefile
8497 @@ -2,7 +2,7 @@
8498 #
8499
8500 asflags-y := -ansi -DST_DIV0=0x02
8501 -ccflags-y := -Werror
8502 +#ccflags-y := -Werror
8503
8504 lib-$(CONFIG_SPARC32) += ashrdi3.o
8505 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8506 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8507 index 85c233d..68500e0 100644
8508 --- a/arch/sparc/lib/atomic_64.S
8509 +++ b/arch/sparc/lib/atomic_64.S
8510 @@ -17,7 +17,12 @@
8511 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8512 BACKOFF_SETUP(%o2)
8513 1: lduw [%o1], %g1
8514 - add %g1, %o0, %g7
8515 + addcc %g1, %o0, %g7
8516 +
8517 +#ifdef CONFIG_PAX_REFCOUNT
8518 + tvs %icc, 6
8519 +#endif
8520 +
8521 cas [%o1], %g1, %g7
8522 cmp %g1, %g7
8523 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8524 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8525 2: BACKOFF_SPIN(%o2, %o3, 1b)
8526 ENDPROC(atomic_add)
8527
8528 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8529 + BACKOFF_SETUP(%o2)
8530 +1: lduw [%o1], %g1
8531 + add %g1, %o0, %g7
8532 + cas [%o1], %g1, %g7
8533 + cmp %g1, %g7
8534 + bne,pn %icc, 2f
8535 + nop
8536 + retl
8537 + nop
8538 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8539 +ENDPROC(atomic_add_unchecked)
8540 +
8541 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8542 BACKOFF_SETUP(%o2)
8543 1: lduw [%o1], %g1
8544 - sub %g1, %o0, %g7
8545 + subcc %g1, %o0, %g7
8546 +
8547 +#ifdef CONFIG_PAX_REFCOUNT
8548 + tvs %icc, 6
8549 +#endif
8550 +
8551 cas [%o1], %g1, %g7
8552 cmp %g1, %g7
8553 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8554 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8555 2: BACKOFF_SPIN(%o2, %o3, 1b)
8556 ENDPROC(atomic_sub)
8557
8558 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8559 + BACKOFF_SETUP(%o2)
8560 +1: lduw [%o1], %g1
8561 + sub %g1, %o0, %g7
8562 + cas [%o1], %g1, %g7
8563 + cmp %g1, %g7
8564 + bne,pn %icc, 2f
8565 + nop
8566 + retl
8567 + nop
8568 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8569 +ENDPROC(atomic_sub_unchecked)
8570 +
8571 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8572 BACKOFF_SETUP(%o2)
8573 1: lduw [%o1], %g1
8574 - add %g1, %o0, %g7
8575 + addcc %g1, %o0, %g7
8576 +
8577 +#ifdef CONFIG_PAX_REFCOUNT
8578 + tvs %icc, 6
8579 +#endif
8580 +
8581 cas [%o1], %g1, %g7
8582 cmp %g1, %g7
8583 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8584 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8585 2: BACKOFF_SPIN(%o2, %o3, 1b)
8586 ENDPROC(atomic_add_ret)
8587
8588 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8589 + BACKOFF_SETUP(%o2)
8590 +1: lduw [%o1], %g1
8591 + addcc %g1, %o0, %g7
8592 + cas [%o1], %g1, %g7
8593 + cmp %g1, %g7
8594 + bne,pn %icc, 2f
8595 + add %g7, %o0, %g7
8596 + sra %g7, 0, %o0
8597 + retl
8598 + nop
8599 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8600 +ENDPROC(atomic_add_ret_unchecked)
8601 +
8602 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8603 BACKOFF_SETUP(%o2)
8604 1: lduw [%o1], %g1
8605 - sub %g1, %o0, %g7
8606 + subcc %g1, %o0, %g7
8607 +
8608 +#ifdef CONFIG_PAX_REFCOUNT
8609 + tvs %icc, 6
8610 +#endif
8611 +
8612 cas [%o1], %g1, %g7
8613 cmp %g1, %g7
8614 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8615 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8616 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8617 BACKOFF_SETUP(%o2)
8618 1: ldx [%o1], %g1
8619 - add %g1, %o0, %g7
8620 + addcc %g1, %o0, %g7
8621 +
8622 +#ifdef CONFIG_PAX_REFCOUNT
8623 + tvs %xcc, 6
8624 +#endif
8625 +
8626 casx [%o1], %g1, %g7
8627 cmp %g1, %g7
8628 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8629 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8630 2: BACKOFF_SPIN(%o2, %o3, 1b)
8631 ENDPROC(atomic64_add)
8632
8633 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8634 + BACKOFF_SETUP(%o2)
8635 +1: ldx [%o1], %g1
8636 + addcc %g1, %o0, %g7
8637 + casx [%o1], %g1, %g7
8638 + cmp %g1, %g7
8639 + bne,pn %xcc, 2f
8640 + nop
8641 + retl
8642 + nop
8643 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8644 +ENDPROC(atomic64_add_unchecked)
8645 +
8646 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8647 BACKOFF_SETUP(%o2)
8648 1: ldx [%o1], %g1
8649 - sub %g1, %o0, %g7
8650 + subcc %g1, %o0, %g7
8651 +
8652 +#ifdef CONFIG_PAX_REFCOUNT
8653 + tvs %xcc, 6
8654 +#endif
8655 +
8656 casx [%o1], %g1, %g7
8657 cmp %g1, %g7
8658 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8659 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8660 2: BACKOFF_SPIN(%o2, %o3, 1b)
8661 ENDPROC(atomic64_sub)
8662
8663 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8664 + BACKOFF_SETUP(%o2)
8665 +1: ldx [%o1], %g1
8666 + subcc %g1, %o0, %g7
8667 + casx [%o1], %g1, %g7
8668 + cmp %g1, %g7
8669 + bne,pn %xcc, 2f
8670 + nop
8671 + retl
8672 + nop
8673 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8674 +ENDPROC(atomic64_sub_unchecked)
8675 +
8676 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8677 BACKOFF_SETUP(%o2)
8678 1: ldx [%o1], %g1
8679 - add %g1, %o0, %g7
8680 + addcc %g1, %o0, %g7
8681 +
8682 +#ifdef CONFIG_PAX_REFCOUNT
8683 + tvs %xcc, 6
8684 +#endif
8685 +
8686 casx [%o1], %g1, %g7
8687 cmp %g1, %g7
8688 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8689 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8690 2: BACKOFF_SPIN(%o2, %o3, 1b)
8691 ENDPROC(atomic64_add_ret)
8692
8693 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8694 + BACKOFF_SETUP(%o2)
8695 +1: ldx [%o1], %g1
8696 + addcc %g1, %o0, %g7
8697 + casx [%o1], %g1, %g7
8698 + cmp %g1, %g7
8699 + bne,pn %xcc, 2f
8700 + add %g7, %o0, %g7
8701 + mov %g7, %o0
8702 + retl
8703 + nop
8704 +2: BACKOFF_SPIN(%o2, %o3, 1b)
8705 +ENDPROC(atomic64_add_ret_unchecked)
8706 +
8707 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8708 BACKOFF_SETUP(%o2)
8709 1: ldx [%o1], %g1
8710 - sub %g1, %o0, %g7
8711 + subcc %g1, %o0, %g7
8712 +
8713 +#ifdef CONFIG_PAX_REFCOUNT
8714 + tvs %xcc, 6
8715 +#endif
8716 +
8717 casx [%o1], %g1, %g7
8718 cmp %g1, %g7
8719 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
8720 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
8721 index 0c4e35e..745d3e4 100644
8722 --- a/arch/sparc/lib/ksyms.c
8723 +++ b/arch/sparc/lib/ksyms.c
8724 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
8725
8726 /* Atomic counter implementation. */
8727 EXPORT_SYMBOL(atomic_add);
8728 +EXPORT_SYMBOL(atomic_add_unchecked);
8729 EXPORT_SYMBOL(atomic_add_ret);
8730 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
8731 EXPORT_SYMBOL(atomic_sub);
8732 +EXPORT_SYMBOL(atomic_sub_unchecked);
8733 EXPORT_SYMBOL(atomic_sub_ret);
8734 EXPORT_SYMBOL(atomic64_add);
8735 +EXPORT_SYMBOL(atomic64_add_unchecked);
8736 EXPORT_SYMBOL(atomic64_add_ret);
8737 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
8738 EXPORT_SYMBOL(atomic64_sub);
8739 +EXPORT_SYMBOL(atomic64_sub_unchecked);
8740 EXPORT_SYMBOL(atomic64_sub_ret);
8741 EXPORT_SYMBOL(atomic64_dec_if_positive);
8742
8743 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
8744 index 30c3ecc..736f015 100644
8745 --- a/arch/sparc/mm/Makefile
8746 +++ b/arch/sparc/mm/Makefile
8747 @@ -2,7 +2,7 @@
8748 #
8749
8750 asflags-y := -ansi
8751 -ccflags-y := -Werror
8752 +#ccflags-y := -Werror
8753
8754 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
8755 obj-y += fault_$(BITS).o
8756 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
8757 index e98bfda..ea8d221 100644
8758 --- a/arch/sparc/mm/fault_32.c
8759 +++ b/arch/sparc/mm/fault_32.c
8760 @@ -21,6 +21,9 @@
8761 #include <linux/perf_event.h>
8762 #include <linux/interrupt.h>
8763 #include <linux/kdebug.h>
8764 +#include <linux/slab.h>
8765 +#include <linux/pagemap.h>
8766 +#include <linux/compiler.h>
8767
8768 #include <asm/page.h>
8769 #include <asm/pgtable.h>
8770 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
8771 return safe_compute_effective_address(regs, insn);
8772 }
8773
8774 +#ifdef CONFIG_PAX_PAGEEXEC
8775 +#ifdef CONFIG_PAX_DLRESOLVE
8776 +static void pax_emuplt_close(struct vm_area_struct *vma)
8777 +{
8778 + vma->vm_mm->call_dl_resolve = 0UL;
8779 +}
8780 +
8781 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8782 +{
8783 + unsigned int *kaddr;
8784 +
8785 + vmf->page = alloc_page(GFP_HIGHUSER);
8786 + if (!vmf->page)
8787 + return VM_FAULT_OOM;
8788 +
8789 + kaddr = kmap(vmf->page);
8790 + memset(kaddr, 0, PAGE_SIZE);
8791 + kaddr[0] = 0x9DE3BFA8U; /* save */
8792 + flush_dcache_page(vmf->page);
8793 + kunmap(vmf->page);
8794 + return VM_FAULT_MAJOR;
8795 +}
8796 +
8797 +static const struct vm_operations_struct pax_vm_ops = {
8798 + .close = pax_emuplt_close,
8799 + .fault = pax_emuplt_fault
8800 +};
8801 +
8802 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
8803 +{
8804 + int ret;
8805 +
8806 + INIT_LIST_HEAD(&vma->anon_vma_chain);
8807 + vma->vm_mm = current->mm;
8808 + vma->vm_start = addr;
8809 + vma->vm_end = addr + PAGE_SIZE;
8810 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
8811 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
8812 + vma->vm_ops = &pax_vm_ops;
8813 +
8814 + ret = insert_vm_struct(current->mm, vma);
8815 + if (ret)
8816 + return ret;
8817 +
8818 + ++current->mm->total_vm;
8819 + return 0;
8820 +}
8821 +#endif
8822 +
8823 +/*
8824 + * PaX: decide what to do with offenders (regs->pc = fault address)
8825 + *
8826 + * returns 1 when task should be killed
8827 + * 2 when patched PLT trampoline was detected
8828 + * 3 when unpatched PLT trampoline was detected
8829 + */
8830 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8831 +{
8832 +
8833 +#ifdef CONFIG_PAX_EMUPLT
8834 + int err;
8835 +
8836 + do { /* PaX: patched PLT emulation #1 */
8837 + unsigned int sethi1, sethi2, jmpl;
8838 +
8839 + err = get_user(sethi1, (unsigned int *)regs->pc);
8840 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
8841 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
8842 +
8843 + if (err)
8844 + break;
8845 +
8846 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8847 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
8848 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
8849 + {
8850 + unsigned int addr;
8851 +
8852 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8853 + addr = regs->u_regs[UREG_G1];
8854 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8855 + regs->pc = addr;
8856 + regs->npc = addr+4;
8857 + return 2;
8858 + }
8859 + } while (0);
8860 +
8861 + do { /* PaX: patched PLT emulation #2 */
8862 + unsigned int ba;
8863 +
8864 + err = get_user(ba, (unsigned int *)regs->pc);
8865 +
8866 + if (err)
8867 + break;
8868 +
8869 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8870 + unsigned int addr;
8871 +
8872 + if ((ba & 0xFFC00000U) == 0x30800000U)
8873 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8874 + else
8875 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8876 + regs->pc = addr;
8877 + regs->npc = addr+4;
8878 + return 2;
8879 + }
8880 + } while (0);
8881 +
8882 + do { /* PaX: patched PLT emulation #3 */
8883 + unsigned int sethi, bajmpl, nop;
8884 +
8885 + err = get_user(sethi, (unsigned int *)regs->pc);
8886 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
8887 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8888 +
8889 + if (err)
8890 + break;
8891 +
8892 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8893 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8894 + nop == 0x01000000U)
8895 + {
8896 + unsigned int addr;
8897 +
8898 + addr = (sethi & 0x003FFFFFU) << 10;
8899 + regs->u_regs[UREG_G1] = addr;
8900 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8901 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8902 + else
8903 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8904 + regs->pc = addr;
8905 + regs->npc = addr+4;
8906 + return 2;
8907 + }
8908 + } while (0);
8909 +
8910 + do { /* PaX: unpatched PLT emulation step 1 */
8911 + unsigned int sethi, ba, nop;
8912 +
8913 + err = get_user(sethi, (unsigned int *)regs->pc);
8914 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
8915 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
8916 +
8917 + if (err)
8918 + break;
8919 +
8920 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
8921 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8922 + nop == 0x01000000U)
8923 + {
8924 + unsigned int addr, save, call;
8925 +
8926 + if ((ba & 0xFFC00000U) == 0x30800000U)
8927 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
8928 + else
8929 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
8930 +
8931 + err = get_user(save, (unsigned int *)addr);
8932 + err |= get_user(call, (unsigned int *)(addr+4));
8933 + err |= get_user(nop, (unsigned int *)(addr+8));
8934 + if (err)
8935 + break;
8936 +
8937 +#ifdef CONFIG_PAX_DLRESOLVE
8938 + if (save == 0x9DE3BFA8U &&
8939 + (call & 0xC0000000U) == 0x40000000U &&
8940 + nop == 0x01000000U)
8941 + {
8942 + struct vm_area_struct *vma;
8943 + unsigned long call_dl_resolve;
8944 +
8945 + down_read(&current->mm->mmap_sem);
8946 + call_dl_resolve = current->mm->call_dl_resolve;
8947 + up_read(&current->mm->mmap_sem);
8948 + if (likely(call_dl_resolve))
8949 + goto emulate;
8950 +
8951 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8952 +
8953 + down_write(&current->mm->mmap_sem);
8954 + if (current->mm->call_dl_resolve) {
8955 + call_dl_resolve = current->mm->call_dl_resolve;
8956 + up_write(&current->mm->mmap_sem);
8957 + if (vma)
8958 + kmem_cache_free(vm_area_cachep, vma);
8959 + goto emulate;
8960 + }
8961 +
8962 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8963 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8964 + up_write(&current->mm->mmap_sem);
8965 + if (vma)
8966 + kmem_cache_free(vm_area_cachep, vma);
8967 + return 1;
8968 + }
8969 +
8970 + if (pax_insert_vma(vma, call_dl_resolve)) {
8971 + up_write(&current->mm->mmap_sem);
8972 + kmem_cache_free(vm_area_cachep, vma);
8973 + return 1;
8974 + }
8975 +
8976 + current->mm->call_dl_resolve = call_dl_resolve;
8977 + up_write(&current->mm->mmap_sem);
8978 +
8979 +emulate:
8980 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8981 + regs->pc = call_dl_resolve;
8982 + regs->npc = addr+4;
8983 + return 3;
8984 + }
8985 +#endif
8986 +
8987 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8988 + if ((save & 0xFFC00000U) == 0x05000000U &&
8989 + (call & 0xFFFFE000U) == 0x85C0A000U &&
8990 + nop == 0x01000000U)
8991 + {
8992 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8993 + regs->u_regs[UREG_G2] = addr + 4;
8994 + addr = (save & 0x003FFFFFU) << 10;
8995 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
8996 + regs->pc = addr;
8997 + regs->npc = addr+4;
8998 + return 3;
8999 + }
9000 + }
9001 + } while (0);
9002 +
9003 + do { /* PaX: unpatched PLT emulation step 2 */
9004 + unsigned int save, call, nop;
9005 +
9006 + err = get_user(save, (unsigned int *)(regs->pc-4));
9007 + err |= get_user(call, (unsigned int *)regs->pc);
9008 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
9009 + if (err)
9010 + break;
9011 +
9012 + if (save == 0x9DE3BFA8U &&
9013 + (call & 0xC0000000U) == 0x40000000U &&
9014 + nop == 0x01000000U)
9015 + {
9016 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9017 +
9018 + regs->u_regs[UREG_RETPC] = regs->pc;
9019 + regs->pc = dl_resolve;
9020 + regs->npc = dl_resolve+4;
9021 + return 3;
9022 + }
9023 + } while (0);
9024 +#endif
9025 +
9026 + return 1;
9027 +}
9028 +
9029 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9030 +{
9031 + unsigned long i;
9032 +
9033 + printk(KERN_ERR "PAX: bytes at PC: ");
9034 + for (i = 0; i < 8; i++) {
9035 + unsigned int c;
9036 + if (get_user(c, (unsigned int *)pc+i))
9037 + printk(KERN_CONT "???????? ");
9038 + else
9039 + printk(KERN_CONT "%08x ", c);
9040 + }
9041 + printk("\n");
9042 +}
9043 +#endif
9044 +
9045 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9046 int text_fault)
9047 {
9048 @@ -230,6 +504,24 @@ good_area:
9049 if (!(vma->vm_flags & VM_WRITE))
9050 goto bad_area;
9051 } else {
9052 +
9053 +#ifdef CONFIG_PAX_PAGEEXEC
9054 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9055 + up_read(&mm->mmap_sem);
9056 + switch (pax_handle_fetch_fault(regs)) {
9057 +
9058 +#ifdef CONFIG_PAX_EMUPLT
9059 + case 2:
9060 + case 3:
9061 + return;
9062 +#endif
9063 +
9064 + }
9065 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9066 + do_group_exit(SIGKILL);
9067 + }
9068 +#endif
9069 +
9070 /* Allow reads even for write-only mappings */
9071 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9072 goto bad_area;
9073 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9074 index 097aee7..5ca6697 100644
9075 --- a/arch/sparc/mm/fault_64.c
9076 +++ b/arch/sparc/mm/fault_64.c
9077 @@ -21,6 +21,9 @@
9078 #include <linux/kprobes.h>
9079 #include <linux/kdebug.h>
9080 #include <linux/percpu.h>
9081 +#include <linux/slab.h>
9082 +#include <linux/pagemap.h>
9083 +#include <linux/compiler.h>
9084
9085 #include <asm/page.h>
9086 #include <asm/pgtable.h>
9087 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9088 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9089 regs->tpc);
9090 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9091 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9092 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9093 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9094 dump_stack();
9095 unhandled_fault(regs->tpc, current, regs);
9096 @@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9097 show_regs(regs);
9098 }
9099
9100 +#ifdef CONFIG_PAX_PAGEEXEC
9101 +#ifdef CONFIG_PAX_DLRESOLVE
9102 +static void pax_emuplt_close(struct vm_area_struct *vma)
9103 +{
9104 + vma->vm_mm->call_dl_resolve = 0UL;
9105 +}
9106 +
9107 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9108 +{
9109 + unsigned int *kaddr;
9110 +
9111 + vmf->page = alloc_page(GFP_HIGHUSER);
9112 + if (!vmf->page)
9113 + return VM_FAULT_OOM;
9114 +
9115 + kaddr = kmap(vmf->page);
9116 + memset(kaddr, 0, PAGE_SIZE);
9117 + kaddr[0] = 0x9DE3BFA8U; /* save */
9118 + flush_dcache_page(vmf->page);
9119 + kunmap(vmf->page);
9120 + return VM_FAULT_MAJOR;
9121 +}
9122 +
9123 +static const struct vm_operations_struct pax_vm_ops = {
9124 + .close = pax_emuplt_close,
9125 + .fault = pax_emuplt_fault
9126 +};
9127 +
9128 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9129 +{
9130 + int ret;
9131 +
9132 + INIT_LIST_HEAD(&vma->anon_vma_chain);
9133 + vma->vm_mm = current->mm;
9134 + vma->vm_start = addr;
9135 + vma->vm_end = addr + PAGE_SIZE;
9136 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9137 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9138 + vma->vm_ops = &pax_vm_ops;
9139 +
9140 + ret = insert_vm_struct(current->mm, vma);
9141 + if (ret)
9142 + return ret;
9143 +
9144 + ++current->mm->total_vm;
9145 + return 0;
9146 +}
9147 +#endif
9148 +
9149 +/*
9150 + * PaX: decide what to do with offenders (regs->tpc = fault address)
9151 + *
9152 + * returns 1 when task should be killed
9153 + * 2 when patched PLT trampoline was detected
9154 + * 3 when unpatched PLT trampoline was detected
9155 + */
9156 +static int pax_handle_fetch_fault(struct pt_regs *regs)
9157 +{
9158 +
9159 +#ifdef CONFIG_PAX_EMUPLT
9160 + int err;
9161 +
9162 + do { /* PaX: patched PLT emulation #1 */
9163 + unsigned int sethi1, sethi2, jmpl;
9164 +
9165 + err = get_user(sethi1, (unsigned int *)regs->tpc);
9166 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9167 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9168 +
9169 + if (err)
9170 + break;
9171 +
9172 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9173 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
9174 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
9175 + {
9176 + unsigned long addr;
9177 +
9178 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9179 + addr = regs->u_regs[UREG_G1];
9180 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9181 +
9182 + if (test_thread_flag(TIF_32BIT))
9183 + addr &= 0xFFFFFFFFUL;
9184 +
9185 + regs->tpc = addr;
9186 + regs->tnpc = addr+4;
9187 + return 2;
9188 + }
9189 + } while (0);
9190 +
9191 + do { /* PaX: patched PLT emulation #2 */
9192 + unsigned int ba;
9193 +
9194 + err = get_user(ba, (unsigned int *)regs->tpc);
9195 +
9196 + if (err)
9197 + break;
9198 +
9199 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9200 + unsigned long addr;
9201 +
9202 + if ((ba & 0xFFC00000U) == 0x30800000U)
9203 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9204 + else
9205 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9206 +
9207 + if (test_thread_flag(TIF_32BIT))
9208 + addr &= 0xFFFFFFFFUL;
9209 +
9210 + regs->tpc = addr;
9211 + regs->tnpc = addr+4;
9212 + return 2;
9213 + }
9214 + } while (0);
9215 +
9216 + do { /* PaX: patched PLT emulation #3 */
9217 + unsigned int sethi, bajmpl, nop;
9218 +
9219 + err = get_user(sethi, (unsigned int *)regs->tpc);
9220 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9221 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9222 +
9223 + if (err)
9224 + break;
9225 +
9226 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9227 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9228 + nop == 0x01000000U)
9229 + {
9230 + unsigned long addr;
9231 +
9232 + addr = (sethi & 0x003FFFFFU) << 10;
9233 + regs->u_regs[UREG_G1] = addr;
9234 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9235 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9236 + else
9237 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9238 +
9239 + if (test_thread_flag(TIF_32BIT))
9240 + addr &= 0xFFFFFFFFUL;
9241 +
9242 + regs->tpc = addr;
9243 + regs->tnpc = addr+4;
9244 + return 2;
9245 + }
9246 + } while (0);
9247 +
9248 + do { /* PaX: patched PLT emulation #4 */
9249 + unsigned int sethi, mov1, call, mov2;
9250 +
9251 + err = get_user(sethi, (unsigned int *)regs->tpc);
9252 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9253 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
9254 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9255 +
9256 + if (err)
9257 + break;
9258 +
9259 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9260 + mov1 == 0x8210000FU &&
9261 + (call & 0xC0000000U) == 0x40000000U &&
9262 + mov2 == 0x9E100001U)
9263 + {
9264 + unsigned long addr;
9265 +
9266 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9267 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9268 +
9269 + if (test_thread_flag(TIF_32BIT))
9270 + addr &= 0xFFFFFFFFUL;
9271 +
9272 + regs->tpc = addr;
9273 + regs->tnpc = addr+4;
9274 + return 2;
9275 + }
9276 + } while (0);
9277 +
9278 + do { /* PaX: patched PLT emulation #5 */
9279 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9280 +
9281 + err = get_user(sethi, (unsigned int *)regs->tpc);
9282 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9283 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9284 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9285 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9286 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9287 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9288 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9289 +
9290 + if (err)
9291 + break;
9292 +
9293 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9294 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9295 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9296 + (or1 & 0xFFFFE000U) == 0x82106000U &&
9297 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9298 + sllx == 0x83287020U &&
9299 + jmpl == 0x81C04005U &&
9300 + nop == 0x01000000U)
9301 + {
9302 + unsigned long addr;
9303 +
9304 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9305 + regs->u_regs[UREG_G1] <<= 32;
9306 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9307 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9308 + regs->tpc = addr;
9309 + regs->tnpc = addr+4;
9310 + return 2;
9311 + }
9312 + } while (0);
9313 +
9314 + do { /* PaX: patched PLT emulation #6 */
9315 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9316 +
9317 + err = get_user(sethi, (unsigned int *)regs->tpc);
9318 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9319 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9320 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9321 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
9322 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9323 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9324 +
9325 + if (err)
9326 + break;
9327 +
9328 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9329 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
9330 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9331 + sllx == 0x83287020U &&
9332 + (or & 0xFFFFE000U) == 0x8A116000U &&
9333 + jmpl == 0x81C04005U &&
9334 + nop == 0x01000000U)
9335 + {
9336 + unsigned long addr;
9337 +
9338 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9339 + regs->u_regs[UREG_G1] <<= 32;
9340 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9341 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9342 + regs->tpc = addr;
9343 + regs->tnpc = addr+4;
9344 + return 2;
9345 + }
9346 + } while (0);
9347 +
9348 + do { /* PaX: unpatched PLT emulation step 1 */
9349 + unsigned int sethi, ba, nop;
9350 +
9351 + err = get_user(sethi, (unsigned int *)regs->tpc);
9352 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9353 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9354 +
9355 + if (err)
9356 + break;
9357 +
9358 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9359 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9360 + nop == 0x01000000U)
9361 + {
9362 + unsigned long addr;
9363 + unsigned int save, call;
9364 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9365 +
9366 + if ((ba & 0xFFC00000U) == 0x30800000U)
9367 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9368 + else
9369 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9370 +
9371 + if (test_thread_flag(TIF_32BIT))
9372 + addr &= 0xFFFFFFFFUL;
9373 +
9374 + err = get_user(save, (unsigned int *)addr);
9375 + err |= get_user(call, (unsigned int *)(addr+4));
9376 + err |= get_user(nop, (unsigned int *)(addr+8));
9377 + if (err)
9378 + break;
9379 +
9380 +#ifdef CONFIG_PAX_DLRESOLVE
9381 + if (save == 0x9DE3BFA8U &&
9382 + (call & 0xC0000000U) == 0x40000000U &&
9383 + nop == 0x01000000U)
9384 + {
9385 + struct vm_area_struct *vma;
9386 + unsigned long call_dl_resolve;
9387 +
9388 + down_read(&current->mm->mmap_sem);
9389 + call_dl_resolve = current->mm->call_dl_resolve;
9390 + up_read(&current->mm->mmap_sem);
9391 + if (likely(call_dl_resolve))
9392 + goto emulate;
9393 +
9394 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9395 +
9396 + down_write(&current->mm->mmap_sem);
9397 + if (current->mm->call_dl_resolve) {
9398 + call_dl_resolve = current->mm->call_dl_resolve;
9399 + up_write(&current->mm->mmap_sem);
9400 + if (vma)
9401 + kmem_cache_free(vm_area_cachep, vma);
9402 + goto emulate;
9403 + }
9404 +
9405 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9406 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9407 + up_write(&current->mm->mmap_sem);
9408 + if (vma)
9409 + kmem_cache_free(vm_area_cachep, vma);
9410 + return 1;
9411 + }
9412 +
9413 + if (pax_insert_vma(vma, call_dl_resolve)) {
9414 + up_write(&current->mm->mmap_sem);
9415 + kmem_cache_free(vm_area_cachep, vma);
9416 + return 1;
9417 + }
9418 +
9419 + current->mm->call_dl_resolve = call_dl_resolve;
9420 + up_write(&current->mm->mmap_sem);
9421 +
9422 +emulate:
9423 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9424 + regs->tpc = call_dl_resolve;
9425 + regs->tnpc = addr+4;
9426 + return 3;
9427 + }
9428 +#endif
9429 +
9430 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9431 + if ((save & 0xFFC00000U) == 0x05000000U &&
9432 + (call & 0xFFFFE000U) == 0x85C0A000U &&
9433 + nop == 0x01000000U)
9434 + {
9435 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9436 + regs->u_regs[UREG_G2] = addr + 4;
9437 + addr = (save & 0x003FFFFFU) << 10;
9438 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9439 +
9440 + if (test_thread_flag(TIF_32BIT))
9441 + addr &= 0xFFFFFFFFUL;
9442 +
9443 + regs->tpc = addr;
9444 + regs->tnpc = addr+4;
9445 + return 3;
9446 + }
9447 +
9448 + /* PaX: 64-bit PLT stub */
9449 + err = get_user(sethi1, (unsigned int *)addr);
9450 + err |= get_user(sethi2, (unsigned int *)(addr+4));
9451 + err |= get_user(or1, (unsigned int *)(addr+8));
9452 + err |= get_user(or2, (unsigned int *)(addr+12));
9453 + err |= get_user(sllx, (unsigned int *)(addr+16));
9454 + err |= get_user(add, (unsigned int *)(addr+20));
9455 + err |= get_user(jmpl, (unsigned int *)(addr+24));
9456 + err |= get_user(nop, (unsigned int *)(addr+28));
9457 + if (err)
9458 + break;
9459 +
9460 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9461 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9462 + (or1 & 0xFFFFE000U) == 0x88112000U &&
9463 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
9464 + sllx == 0x89293020U &&
9465 + add == 0x8A010005U &&
9466 + jmpl == 0x89C14000U &&
9467 + nop == 0x01000000U)
9468 + {
9469 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9470 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9471 + regs->u_regs[UREG_G4] <<= 32;
9472 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9473 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9474 + regs->u_regs[UREG_G4] = addr + 24;
9475 + addr = regs->u_regs[UREG_G5];
9476 + regs->tpc = addr;
9477 + regs->tnpc = addr+4;
9478 + return 3;
9479 + }
9480 + }
9481 + } while (0);
9482 +
9483 +#ifdef CONFIG_PAX_DLRESOLVE
9484 + do { /* PaX: unpatched PLT emulation step 2 */
9485 + unsigned int save, call, nop;
9486 +
9487 + err = get_user(save, (unsigned int *)(regs->tpc-4));
9488 + err |= get_user(call, (unsigned int *)regs->tpc);
9489 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9490 + if (err)
9491 + break;
9492 +
9493 + if (save == 0x9DE3BFA8U &&
9494 + (call & 0xC0000000U) == 0x40000000U &&
9495 + nop == 0x01000000U)
9496 + {
9497 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9498 +
9499 + if (test_thread_flag(TIF_32BIT))
9500 + dl_resolve &= 0xFFFFFFFFUL;
9501 +
9502 + regs->u_regs[UREG_RETPC] = regs->tpc;
9503 + regs->tpc = dl_resolve;
9504 + regs->tnpc = dl_resolve+4;
9505 + return 3;
9506 + }
9507 + } while (0);
9508 +#endif
9509 +
9510 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9511 + unsigned int sethi, ba, nop;
9512 +
9513 + err = get_user(sethi, (unsigned int *)regs->tpc);
9514 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9515 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9516 +
9517 + if (err)
9518 + break;
9519 +
9520 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
9521 + (ba & 0xFFF00000U) == 0x30600000U &&
9522 + nop == 0x01000000U)
9523 + {
9524 + unsigned long addr;
9525 +
9526 + addr = (sethi & 0x003FFFFFU) << 10;
9527 + regs->u_regs[UREG_G1] = addr;
9528 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9529 +
9530 + if (test_thread_flag(TIF_32BIT))
9531 + addr &= 0xFFFFFFFFUL;
9532 +
9533 + regs->tpc = addr;
9534 + regs->tnpc = addr+4;
9535 + return 2;
9536 + }
9537 + } while (0);
9538 +
9539 +#endif
9540 +
9541 + return 1;
9542 +}
9543 +
9544 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9545 +{
9546 + unsigned long i;
9547 +
9548 + printk(KERN_ERR "PAX: bytes at PC: ");
9549 + for (i = 0; i < 8; i++) {
9550 + unsigned int c;
9551 + if (get_user(c, (unsigned int *)pc+i))
9552 + printk(KERN_CONT "???????? ");
9553 + else
9554 + printk(KERN_CONT "%08x ", c);
9555 + }
9556 + printk("\n");
9557 +}
9558 +#endif
9559 +
9560 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9561 {
9562 struct mm_struct *mm = current->mm;
9563 @@ -341,6 +804,29 @@ retry:
9564 if (!vma)
9565 goto bad_area;
9566
9567 +#ifdef CONFIG_PAX_PAGEEXEC
9568 + /* PaX: detect ITLB misses on non-exec pages */
9569 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9570 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9571 + {
9572 + if (address != regs->tpc)
9573 + goto good_area;
9574 +
9575 + up_read(&mm->mmap_sem);
9576 + switch (pax_handle_fetch_fault(regs)) {
9577 +
9578 +#ifdef CONFIG_PAX_EMUPLT
9579 + case 2:
9580 + case 3:
9581 + return;
9582 +#endif
9583 +
9584 + }
9585 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9586 + do_group_exit(SIGKILL);
9587 + }
9588 +#endif
9589 +
9590 /* Pure DTLB misses do not tell us whether the fault causing
9591 * load/store/atomic was a write or not, it only says that there
9592 * was no match. So in such a case we (carefully) read the
9593 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9594 index d2b5944..bd813f2 100644
9595 --- a/arch/sparc/mm/hugetlbpage.c
9596 +++ b/arch/sparc/mm/hugetlbpage.c
9597 @@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9598
9599 info.flags = 0;
9600 info.length = len;
9601 - info.low_limit = TASK_UNMAPPED_BASE;
9602 + info.low_limit = mm->mmap_base;
9603 info.high_limit = min(task_size, VA_EXCLUDE_START);
9604 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9605 info.align_offset = 0;
9606 @@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9607 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9608 VM_BUG_ON(addr != -ENOMEM);
9609 info.low_limit = VA_EXCLUDE_END;
9610 +
9611 +#ifdef CONFIG_PAX_RANDMMAP
9612 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9613 + info.low_limit += mm->delta_mmap;
9614 +#endif
9615 +
9616 info.high_limit = task_size;
9617 addr = vm_unmapped_area(&info);
9618 }
9619 @@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9620 VM_BUG_ON(addr != -ENOMEM);
9621 info.flags = 0;
9622 info.low_limit = TASK_UNMAPPED_BASE;
9623 +
9624 +#ifdef CONFIG_PAX_RANDMMAP
9625 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9626 + info.low_limit += mm->delta_mmap;
9627 +#endif
9628 +
9629 info.high_limit = STACK_TOP32;
9630 addr = vm_unmapped_area(&info);
9631 }
9632 @@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9633 struct mm_struct *mm = current->mm;
9634 struct vm_area_struct *vma;
9635 unsigned long task_size = TASK_SIZE;
9636 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
9637
9638 if (test_thread_flag(TIF_32BIT))
9639 task_size = STACK_TOP32;
9640 @@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
9641 return addr;
9642 }
9643
9644 +#ifdef CONFIG_PAX_RANDMMAP
9645 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9646 +#endif
9647 +
9648 if (addr) {
9649 addr = ALIGN(addr, HPAGE_SIZE);
9650 vma = find_vma(mm, addr);
9651 - if (task_size - len >= addr &&
9652 - (!vma || addr + len <= vma->vm_start))
9653 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9654 return addr;
9655 }
9656 if (mm->get_unmapped_area == arch_get_unmapped_area)
9657 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
9658 index f4500c6..889656c 100644
9659 --- a/arch/tile/include/asm/atomic_64.h
9660 +++ b/arch/tile/include/asm/atomic_64.h
9661 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9662
9663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9664
9665 +#define atomic64_read_unchecked(v) atomic64_read(v)
9666 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9667 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9668 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9669 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9670 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9671 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9672 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9673 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9674 +
9675 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
9676 #define smp_mb__before_atomic_dec() smp_mb()
9677 #define smp_mb__after_atomic_dec() smp_mb()
9678 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
9679 index a9a5299..0fce79e 100644
9680 --- a/arch/tile/include/asm/cache.h
9681 +++ b/arch/tile/include/asm/cache.h
9682 @@ -15,11 +15,12 @@
9683 #ifndef _ASM_TILE_CACHE_H
9684 #define _ASM_TILE_CACHE_H
9685
9686 +#include <linux/const.h>
9687 #include <arch/chip.h>
9688
9689 /* bytes per L1 data cache line */
9690 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
9691 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9692 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9693
9694 /* bytes per L2 cache line */
9695 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
9696 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
9697 index 9ab078a..d6635c2 100644
9698 --- a/arch/tile/include/asm/uaccess.h
9699 +++ b/arch/tile/include/asm/uaccess.h
9700 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
9701 const void __user *from,
9702 unsigned long n)
9703 {
9704 - int sz = __compiletime_object_size(to);
9705 + size_t sz = __compiletime_object_size(to);
9706
9707 - if (likely(sz == -1 || sz >= n))
9708 + if (likely(sz == (size_t)-1 || sz >= n))
9709 n = _copy_from_user(to, from, n);
9710 else
9711 copy_from_user_overflow();
9712 diff --git a/arch/um/Makefile b/arch/um/Makefile
9713 index 133f7de..1d6f2f1 100644
9714 --- a/arch/um/Makefile
9715 +++ b/arch/um/Makefile
9716 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
9717 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
9718 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
9719
9720 +ifdef CONSTIFY_PLUGIN
9721 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
9722 +endif
9723 +
9724 #This will adjust *FLAGS accordingly to the platform.
9725 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
9726
9727 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
9728 index 19e1bdd..3665b77 100644
9729 --- a/arch/um/include/asm/cache.h
9730 +++ b/arch/um/include/asm/cache.h
9731 @@ -1,6 +1,7 @@
9732 #ifndef __UM_CACHE_H
9733 #define __UM_CACHE_H
9734
9735 +#include <linux/const.h>
9736
9737 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
9738 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
9739 @@ -12,6 +13,6 @@
9740 # define L1_CACHE_SHIFT 5
9741 #endif
9742
9743 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9744 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9745
9746 #endif
9747 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
9748 index 2e0a6b1..a64d0f5 100644
9749 --- a/arch/um/include/asm/kmap_types.h
9750 +++ b/arch/um/include/asm/kmap_types.h
9751 @@ -8,6 +8,6 @@
9752
9753 /* No more #include "asm/arch/kmap_types.h" ! */
9754
9755 -#define KM_TYPE_NR 14
9756 +#define KM_TYPE_NR 15
9757
9758 #endif
9759 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
9760 index 5ff53d9..5850cdf 100644
9761 --- a/arch/um/include/asm/page.h
9762 +++ b/arch/um/include/asm/page.h
9763 @@ -14,6 +14,9 @@
9764 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
9765 #define PAGE_MASK (~(PAGE_SIZE-1))
9766
9767 +#define ktla_ktva(addr) (addr)
9768 +#define ktva_ktla(addr) (addr)
9769 +
9770 #ifndef __ASSEMBLY__
9771
9772 struct page;
9773 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
9774 index 0032f92..cd151e0 100644
9775 --- a/arch/um/include/asm/pgtable-3level.h
9776 +++ b/arch/um/include/asm/pgtable-3level.h
9777 @@ -58,6 +58,7 @@
9778 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
9779 #define pud_populate(mm, pud, pmd) \
9780 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
9781 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9782
9783 #ifdef CONFIG_64BIT
9784 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
9785 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
9786 index b462b13..e7a19aa 100644
9787 --- a/arch/um/kernel/process.c
9788 +++ b/arch/um/kernel/process.c
9789 @@ -386,22 +386,6 @@ int singlestepping(void * t)
9790 return 2;
9791 }
9792
9793 -/*
9794 - * Only x86 and x86_64 have an arch_align_stack().
9795 - * All other arches have "#define arch_align_stack(x) (x)"
9796 - * in their asm/system.h
9797 - * As this is included in UML from asm-um/system-generic.h,
9798 - * we can use it to behave as the subarch does.
9799 - */
9800 -#ifndef arch_align_stack
9801 -unsigned long arch_align_stack(unsigned long sp)
9802 -{
9803 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9804 - sp -= get_random_int() % 8192;
9805 - return sp & ~0xf;
9806 -}
9807 -#endif
9808 -
9809 unsigned long get_wchan(struct task_struct *p)
9810 {
9811 unsigned long stack_page, sp, ip;
9812 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
9813 index ad8f795..2c7eec6 100644
9814 --- a/arch/unicore32/include/asm/cache.h
9815 +++ b/arch/unicore32/include/asm/cache.h
9816 @@ -12,8 +12,10 @@
9817 #ifndef __UNICORE_CACHE_H__
9818 #define __UNICORE_CACHE_H__
9819
9820 -#define L1_CACHE_SHIFT (5)
9821 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9822 +#include <linux/const.h>
9823 +
9824 +#define L1_CACHE_SHIFT 5
9825 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9826
9827 /*
9828 * Memory returned by kmalloc() may be used for DMA, so we must make
9829 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
9830 index 225543b..f12405b 100644
9831 --- a/arch/x86/Kconfig
9832 +++ b/arch/x86/Kconfig
9833 @@ -238,7 +238,7 @@ config X86_HT
9834
9835 config X86_32_LAZY_GS
9836 def_bool y
9837 - depends on X86_32 && !CC_STACKPROTECTOR
9838 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
9839
9840 config ARCH_HWEIGHT_CFLAGS
9841 string
9842 @@ -1031,6 +1031,7 @@ config MICROCODE_OLD_INTERFACE
9843
9844 config X86_MSR
9845 tristate "/dev/cpu/*/msr - Model-specific register support"
9846 + depends on !GRKERNSEC_KMEM
9847 ---help---
9848 This device gives privileged processes access to the x86
9849 Model-Specific Registers (MSRs). It is a character device with
9850 @@ -1054,7 +1055,7 @@ choice
9851
9852 config NOHIGHMEM
9853 bool "off"
9854 - depends on !X86_NUMAQ
9855 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9856 ---help---
9857 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
9858 However, the address space of 32-bit x86 processors is only 4
9859 @@ -1091,7 +1092,7 @@ config NOHIGHMEM
9860
9861 config HIGHMEM4G
9862 bool "4GB"
9863 - depends on !X86_NUMAQ
9864 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
9865 ---help---
9866 Select this if you have a 32-bit processor and between 1 and 4
9867 gigabytes of physical RAM.
9868 @@ -1145,7 +1146,7 @@ config PAGE_OFFSET
9869 hex
9870 default 0xB0000000 if VMSPLIT_3G_OPT
9871 default 0x80000000 if VMSPLIT_2G
9872 - default 0x78000000 if VMSPLIT_2G_OPT
9873 + default 0x70000000 if VMSPLIT_2G_OPT
9874 default 0x40000000 if VMSPLIT_1G
9875 default 0xC0000000
9876 depends on X86_32
9877 @@ -1546,6 +1547,7 @@ config SECCOMP
9878
9879 config CC_STACKPROTECTOR
9880 bool "Enable -fstack-protector buffer overflow detection"
9881 + depends on X86_64 || !PAX_MEMORY_UDEREF
9882 ---help---
9883 This option turns on the -fstack-protector GCC feature. This
9884 feature puts, at the beginning of functions, a canary value on
9885 @@ -1603,6 +1605,7 @@ config KEXEC_JUMP
9886 config PHYSICAL_START
9887 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
9888 default "0x1000000"
9889 + range 0x400000 0x40000000
9890 ---help---
9891 This gives the physical address where the kernel is loaded.
9892
9893 @@ -1666,6 +1669,7 @@ config X86_NEED_RELOCS
9894 config PHYSICAL_ALIGN
9895 hex "Alignment value to which kernel should be aligned" if X86_32
9896 default "0x1000000"
9897 + range 0x400000 0x1000000 if PAX_KERNEXEC
9898 range 0x2000 0x1000000
9899 ---help---
9900 This value puts the alignment restrictions on physical address
9901 @@ -1741,9 +1745,10 @@ config DEBUG_HOTPLUG_CPU0
9902 If unsure, say N.
9903
9904 config COMPAT_VDSO
9905 - def_bool y
9906 + def_bool n
9907 prompt "Compat VDSO support"
9908 depends on X86_32 || IA32_EMULATION
9909 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
9910 ---help---
9911 Map the 32-bit VDSO to the predictable old-style address too.
9912
9913 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
9914 index c026cca..14657ae 100644
9915 --- a/arch/x86/Kconfig.cpu
9916 +++ b/arch/x86/Kconfig.cpu
9917 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
9918
9919 config X86_F00F_BUG
9920 def_bool y
9921 - depends on M586MMX || M586TSC || M586 || M486
9922 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
9923
9924 config X86_INVD_BUG
9925 def_bool y
9926 @@ -327,7 +327,7 @@ config X86_INVD_BUG
9927
9928 config X86_ALIGNMENT_16
9929 def_bool y
9930 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9931 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
9932
9933 config X86_INTEL_USERCOPY
9934 def_bool y
9935 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
9936 # generates cmov.
9937 config X86_CMOV
9938 def_bool y
9939 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9940 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
9941
9942 config X86_MINIMUM_CPU_FAMILY
9943 int
9944 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
9945 index b322f12..652d0d9 100644
9946 --- a/arch/x86/Kconfig.debug
9947 +++ b/arch/x86/Kconfig.debug
9948 @@ -84,7 +84,7 @@ config X86_PTDUMP
9949 config DEBUG_RODATA
9950 bool "Write protect kernel read-only data structures"
9951 default y
9952 - depends on DEBUG_KERNEL
9953 + depends on DEBUG_KERNEL && BROKEN
9954 ---help---
9955 Mark the kernel read-only data as write-protected in the pagetables,
9956 in order to catch accidental (and incorrect) writes to such const
9957 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
9958
9959 config DEBUG_SET_MODULE_RONX
9960 bool "Set loadable kernel module data as NX and text as RO"
9961 - depends on MODULES
9962 + depends on MODULES && BROKEN
9963 ---help---
9964 This option helps catch unintended modifications to loadable
9965 kernel module's text and read-only data. It also prevents execution
9966 @@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
9967
9968 config DEBUG_STRICT_USER_COPY_CHECKS
9969 bool "Strict copy size checks"
9970 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
9971 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
9972 ---help---
9973 Enabling this option turns a certain set of sanity checks for user
9974 copy operations into compile time failures.
9975 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
9976 index e71fc42..7829607 100644
9977 --- a/arch/x86/Makefile
9978 +++ b/arch/x86/Makefile
9979 @@ -50,6 +50,7 @@ else
9980 UTS_MACHINE := x86_64
9981 CHECKFLAGS += -D__x86_64__ -m64
9982
9983 + biarch := $(call cc-option,-m64)
9984 KBUILD_AFLAGS += -m64
9985 KBUILD_CFLAGS += -m64
9986
9987 @@ -230,3 +231,12 @@ define archhelp
9988 echo ' FDARGS="..." arguments for the booted kernel'
9989 echo ' FDINITRD=file initrd for the booted kernel'
9990 endef
9991 +
9992 +define OLD_LD
9993 +
9994 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
9995 +*** Please upgrade your binutils to 2.18 or newer
9996 +endef
9997 +
9998 +archprepare:
9999 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10000 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10001 index 379814b..add62ce 100644
10002 --- a/arch/x86/boot/Makefile
10003 +++ b/arch/x86/boot/Makefile
10004 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10005 $(call cc-option, -fno-stack-protector) \
10006 $(call cc-option, -mpreferred-stack-boundary=2)
10007 KBUILD_CFLAGS += $(call cc-option, -m32)
10008 +ifdef CONSTIFY_PLUGIN
10009 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10010 +endif
10011 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10012 GCOV_PROFILE := n
10013
10014 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10015 index 878e4b9..20537ab 100644
10016 --- a/arch/x86/boot/bitops.h
10017 +++ b/arch/x86/boot/bitops.h
10018 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10019 u8 v;
10020 const u32 *p = (const u32 *)addr;
10021
10022 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10023 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10024 return v;
10025 }
10026
10027 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10028
10029 static inline void set_bit(int nr, void *addr)
10030 {
10031 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10032 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10033 }
10034
10035 #endif /* BOOT_BITOPS_H */
10036 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10037 index 18997e5..83d9c67 100644
10038 --- a/arch/x86/boot/boot.h
10039 +++ b/arch/x86/boot/boot.h
10040 @@ -85,7 +85,7 @@ static inline void io_delay(void)
10041 static inline u16 ds(void)
10042 {
10043 u16 seg;
10044 - asm("movw %%ds,%0" : "=rm" (seg));
10045 + asm volatile("movw %%ds,%0" : "=rm" (seg));
10046 return seg;
10047 }
10048
10049 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10050 static inline int memcmp(const void *s1, const void *s2, size_t len)
10051 {
10052 u8 diff;
10053 - asm("repe; cmpsb; setnz %0"
10054 + asm volatile("repe; cmpsb; setnz %0"
10055 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10056 return diff;
10057 }
10058 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10059 index 8a84501..b2d165f 100644
10060 --- a/arch/x86/boot/compressed/Makefile
10061 +++ b/arch/x86/boot/compressed/Makefile
10062 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10063 KBUILD_CFLAGS += $(cflags-y)
10064 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10065 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10066 +ifdef CONSTIFY_PLUGIN
10067 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10068 +endif
10069
10070 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10071 GCOV_PROFILE := n
10072 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10073 index f8fa411..c570c53 100644
10074 --- a/arch/x86/boot/compressed/eboot.c
10075 +++ b/arch/x86/boot/compressed/eboot.c
10076 @@ -145,7 +145,6 @@ again:
10077 *addr = max_addr;
10078 }
10079
10080 -free_pool:
10081 efi_call_phys1(sys_table->boottime->free_pool, map);
10082
10083 fail:
10084 @@ -209,7 +208,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10085 if (i == map_size / desc_size)
10086 status = EFI_NOT_FOUND;
10087
10088 -free_pool:
10089 efi_call_phys1(sys_table->boottime->free_pool, map);
10090 fail:
10091 return status;
10092 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10093 index 1e3184f..0d11e2e 100644
10094 --- a/arch/x86/boot/compressed/head_32.S
10095 +++ b/arch/x86/boot/compressed/head_32.S
10096 @@ -118,7 +118,7 @@ preferred_addr:
10097 notl %eax
10098 andl %eax, %ebx
10099 #else
10100 - movl $LOAD_PHYSICAL_ADDR, %ebx
10101 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10102 #endif
10103
10104 /* Target address to relocate to for decompression */
10105 @@ -204,7 +204,7 @@ relocated:
10106 * and where it was actually loaded.
10107 */
10108 movl %ebp, %ebx
10109 - subl $LOAD_PHYSICAL_ADDR, %ebx
10110 + subl $____LOAD_PHYSICAL_ADDR, %ebx
10111 jz 2f /* Nothing to be done if loaded at compiled addr. */
10112 /*
10113 * Process relocations.
10114 @@ -212,8 +212,7 @@ relocated:
10115
10116 1: subl $4, %edi
10117 movl (%edi), %ecx
10118 - testl %ecx, %ecx
10119 - jz 2f
10120 + jecxz 2f
10121 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10122 jmp 1b
10123 2:
10124 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10125 index f5d1aaa..cce11dc 100644
10126 --- a/arch/x86/boot/compressed/head_64.S
10127 +++ b/arch/x86/boot/compressed/head_64.S
10128 @@ -91,7 +91,7 @@ ENTRY(startup_32)
10129 notl %eax
10130 andl %eax, %ebx
10131 #else
10132 - movl $LOAD_PHYSICAL_ADDR, %ebx
10133 + movl $____LOAD_PHYSICAL_ADDR, %ebx
10134 #endif
10135
10136 /* Target address to relocate to for decompression */
10137 @@ -273,7 +273,7 @@ preferred_addr:
10138 notq %rax
10139 andq %rax, %rbp
10140 #else
10141 - movq $LOAD_PHYSICAL_ADDR, %rbp
10142 + movq $____LOAD_PHYSICAL_ADDR, %rbp
10143 #endif
10144
10145 /* Target address to relocate to for decompression */
10146 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10147 index 88f7ff6..ed695dd 100644
10148 --- a/arch/x86/boot/compressed/misc.c
10149 +++ b/arch/x86/boot/compressed/misc.c
10150 @@ -303,7 +303,7 @@ static void parse_elf(void *output)
10151 case PT_LOAD:
10152 #ifdef CONFIG_RELOCATABLE
10153 dest = output;
10154 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10155 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10156 #else
10157 dest = (void *)(phdr->p_paddr);
10158 #endif
10159 @@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10160 error("Destination address too large");
10161 #endif
10162 #ifndef CONFIG_RELOCATABLE
10163 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10164 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10165 error("Wrong destination address");
10166 #endif
10167
10168 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10169 index 4d3ff03..e4972ff 100644
10170 --- a/arch/x86/boot/cpucheck.c
10171 +++ b/arch/x86/boot/cpucheck.c
10172 @@ -74,7 +74,7 @@ static int has_fpu(void)
10173 u16 fcw = -1, fsw = -1;
10174 u32 cr0;
10175
10176 - asm("movl %%cr0,%0" : "=r" (cr0));
10177 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
10178 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10179 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10180 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10181 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10182 {
10183 u32 f0, f1;
10184
10185 - asm("pushfl ; "
10186 + asm volatile("pushfl ; "
10187 "pushfl ; "
10188 "popl %0 ; "
10189 "movl %0,%1 ; "
10190 @@ -115,7 +115,7 @@ static void get_flags(void)
10191 set_bit(X86_FEATURE_FPU, cpu.flags);
10192
10193 if (has_eflag(X86_EFLAGS_ID)) {
10194 - asm("cpuid"
10195 + asm volatile("cpuid"
10196 : "=a" (max_intel_level),
10197 "=b" (cpu_vendor[0]),
10198 "=d" (cpu_vendor[1]),
10199 @@ -124,7 +124,7 @@ static void get_flags(void)
10200
10201 if (max_intel_level >= 0x00000001 &&
10202 max_intel_level <= 0x0000ffff) {
10203 - asm("cpuid"
10204 + asm volatile("cpuid"
10205 : "=a" (tfms),
10206 "=c" (cpu.flags[4]),
10207 "=d" (cpu.flags[0])
10208 @@ -136,7 +136,7 @@ static void get_flags(void)
10209 cpu.model += ((tfms >> 16) & 0xf) << 4;
10210 }
10211
10212 - asm("cpuid"
10213 + asm volatile("cpuid"
10214 : "=a" (max_amd_level)
10215 : "a" (0x80000000)
10216 : "ebx", "ecx", "edx");
10217 @@ -144,7 +144,7 @@ static void get_flags(void)
10218 if (max_amd_level >= 0x80000001 &&
10219 max_amd_level <= 0x8000ffff) {
10220 u32 eax = 0x80000001;
10221 - asm("cpuid"
10222 + asm volatile("cpuid"
10223 : "+a" (eax),
10224 "=c" (cpu.flags[6]),
10225 "=d" (cpu.flags[1])
10226 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10227 u32 ecx = MSR_K7_HWCR;
10228 u32 eax, edx;
10229
10230 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10231 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10232 eax &= ~(1 << 15);
10233 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10234 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10235
10236 get_flags(); /* Make sure it really did something */
10237 err = check_flags();
10238 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10239 u32 ecx = MSR_VIA_FCR;
10240 u32 eax, edx;
10241
10242 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10243 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10244 eax |= (1<<1)|(1<<7);
10245 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10246 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10247
10248 set_bit(X86_FEATURE_CX8, cpu.flags);
10249 err = check_flags();
10250 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10251 u32 eax, edx;
10252 u32 level = 1;
10253
10254 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10255 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10256 - asm("cpuid"
10257 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10258 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10259 + asm volatile("cpuid"
10260 : "+a" (level), "=d" (cpu.flags[0])
10261 : : "ecx", "ebx");
10262 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10263 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10264
10265 err = check_flags();
10266 }
10267 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10268 index 944ce59..87ee37a 100644
10269 --- a/arch/x86/boot/header.S
10270 +++ b/arch/x86/boot/header.S
10271 @@ -401,10 +401,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10272 # single linked list of
10273 # struct setup_data
10274
10275 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10276 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10277
10278 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10279 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10280 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10281 +#else
10282 #define VO_INIT_SIZE (VO__end - VO__text)
10283 +#endif
10284 #if ZO_INIT_SIZE > VO_INIT_SIZE
10285 #define INIT_SIZE ZO_INIT_SIZE
10286 #else
10287 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10288 index db75d07..8e6d0af 100644
10289 --- a/arch/x86/boot/memory.c
10290 +++ b/arch/x86/boot/memory.c
10291 @@ -19,7 +19,7 @@
10292
10293 static int detect_memory_e820(void)
10294 {
10295 - int count = 0;
10296 + unsigned int count = 0;
10297 struct biosregs ireg, oreg;
10298 struct e820entry *desc = boot_params.e820_map;
10299 static struct e820entry buf; /* static so it is zeroed */
10300 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10301 index 11e8c6e..fdbb1ed 100644
10302 --- a/arch/x86/boot/video-vesa.c
10303 +++ b/arch/x86/boot/video-vesa.c
10304 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10305
10306 boot_params.screen_info.vesapm_seg = oreg.es;
10307 boot_params.screen_info.vesapm_off = oreg.di;
10308 + boot_params.screen_info.vesapm_size = oreg.cx;
10309 }
10310
10311 /*
10312 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10313 index 43eda28..5ab5fdb 100644
10314 --- a/arch/x86/boot/video.c
10315 +++ b/arch/x86/boot/video.c
10316 @@ -96,7 +96,7 @@ static void store_mode_params(void)
10317 static unsigned int get_entry(void)
10318 {
10319 char entry_buf[4];
10320 - int i, len = 0;
10321 + unsigned int i, len = 0;
10322 int key;
10323 unsigned int v;
10324
10325 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10326 index 5b577d5..3c1fed4 100644
10327 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
10328 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10329 @@ -8,6 +8,8 @@
10330 * including this sentence is retained in full.
10331 */
10332
10333 +#include <asm/alternative-asm.h>
10334 +
10335 .extern crypto_ft_tab
10336 .extern crypto_it_tab
10337 .extern crypto_fl_tab
10338 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
10339 je B192; \
10340 leaq 32(r9),r9;
10341
10342 +#define ret pax_force_retaddr 0, 1; ret
10343 +
10344 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10345 movq r1,r2; \
10346 movq r3,r4; \
10347 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10348 index 3470624..201259d 100644
10349 --- a/arch/x86/crypto/aesni-intel_asm.S
10350 +++ b/arch/x86/crypto/aesni-intel_asm.S
10351 @@ -31,6 +31,7 @@
10352
10353 #include <linux/linkage.h>
10354 #include <asm/inst.h>
10355 +#include <asm/alternative-asm.h>
10356
10357 #ifdef __x86_64__
10358 .data
10359 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
10360 pop %r14
10361 pop %r13
10362 pop %r12
10363 + pax_force_retaddr 0, 1
10364 ret
10365 +ENDPROC(aesni_gcm_dec)
10366
10367
10368 /*****************************************************************************
10369 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
10370 pop %r14
10371 pop %r13
10372 pop %r12
10373 + pax_force_retaddr 0, 1
10374 ret
10375 +ENDPROC(aesni_gcm_enc)
10376
10377 #endif
10378
10379 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
10380 pxor %xmm1, %xmm0
10381 movaps %xmm0, (TKEYP)
10382 add $0x10, TKEYP
10383 + pax_force_retaddr_bts
10384 ret
10385
10386 .align 4
10387 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
10388 shufps $0b01001110, %xmm2, %xmm1
10389 movaps %xmm1, 0x10(TKEYP)
10390 add $0x20, TKEYP
10391 + pax_force_retaddr_bts
10392 ret
10393
10394 .align 4
10395 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
10396
10397 movaps %xmm0, (TKEYP)
10398 add $0x10, TKEYP
10399 + pax_force_retaddr_bts
10400 ret
10401
10402 .align 4
10403 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
10404 pxor %xmm1, %xmm2
10405 movaps %xmm2, (TKEYP)
10406 add $0x10, TKEYP
10407 + pax_force_retaddr_bts
10408 ret
10409
10410 /*
10411 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
10412 #ifndef __x86_64__
10413 popl KEYP
10414 #endif
10415 + pax_force_retaddr 0, 1
10416 ret
10417 +ENDPROC(aesni_set_key)
10418
10419 /*
10420 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
10421 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
10422 popl KLEN
10423 popl KEYP
10424 #endif
10425 + pax_force_retaddr 0, 1
10426 ret
10427 +ENDPROC(aesni_enc)
10428
10429 /*
10430 * _aesni_enc1: internal ABI
10431 @@ -1959,6 +1972,7 @@ _aesni_enc1:
10432 AESENC KEY STATE
10433 movaps 0x70(TKEYP), KEY
10434 AESENCLAST KEY STATE
10435 + pax_force_retaddr_bts
10436 ret
10437
10438 /*
10439 @@ -2067,6 +2081,7 @@ _aesni_enc4:
10440 AESENCLAST KEY STATE2
10441 AESENCLAST KEY STATE3
10442 AESENCLAST KEY STATE4
10443 + pax_force_retaddr_bts
10444 ret
10445
10446 /*
10447 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
10448 popl KLEN
10449 popl KEYP
10450 #endif
10451 + pax_force_retaddr 0, 1
10452 ret
10453 +ENDPROC(aesni_dec)
10454
10455 /*
10456 * _aesni_dec1: internal ABI
10457 @@ -2146,6 +2163,7 @@ _aesni_dec1:
10458 AESDEC KEY STATE
10459 movaps 0x70(TKEYP), KEY
10460 AESDECLAST KEY STATE
10461 + pax_force_retaddr_bts
10462 ret
10463
10464 /*
10465 @@ -2254,6 +2272,7 @@ _aesni_dec4:
10466 AESDECLAST KEY STATE2
10467 AESDECLAST KEY STATE3
10468 AESDECLAST KEY STATE4
10469 + pax_force_retaddr_bts
10470 ret
10471
10472 /*
10473 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
10474 popl KEYP
10475 popl LEN
10476 #endif
10477 + pax_force_retaddr 0, 1
10478 ret
10479 +ENDPROC(aesni_ecb_enc)
10480
10481 /*
10482 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10483 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
10484 popl KEYP
10485 popl LEN
10486 #endif
10487 + pax_force_retaddr 0, 1
10488 ret
10489 +ENDPROC(aesni_ecb_dec)
10490
10491 /*
10492 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10493 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
10494 popl LEN
10495 popl IVP
10496 #endif
10497 + pax_force_retaddr 0, 1
10498 ret
10499 +ENDPROC(aesni_cbc_enc)
10500
10501 /*
10502 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
10503 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
10504 popl LEN
10505 popl IVP
10506 #endif
10507 + pax_force_retaddr 0, 1
10508 ret
10509 +ENDPROC(aesni_cbc_dec)
10510
10511 #ifdef __x86_64__
10512 .align 16
10513 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
10514 mov $1, TCTR_LOW
10515 MOVQ_R64_XMM TCTR_LOW INC
10516 MOVQ_R64_XMM CTR TCTR_LOW
10517 + pax_force_retaddr_bts
10518 ret
10519
10520 /*
10521 @@ -2554,6 +2582,7 @@ _aesni_inc:
10522 .Linc_low:
10523 movaps CTR, IV
10524 PSHUFB_XMM BSWAP_MASK IV
10525 + pax_force_retaddr_bts
10526 ret
10527
10528 /*
10529 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
10530 .Lctr_enc_ret:
10531 movups IV, (IVP)
10532 .Lctr_enc_just_ret:
10533 + pax_force_retaddr 0, 1
10534 ret
10535 +ENDPROC(aesni_ctr_enc)
10536 #endif
10537 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10538 index 391d245..67f35c2 100644
10539 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10540 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10541 @@ -20,6 +20,8 @@
10542 *
10543 */
10544
10545 +#include <asm/alternative-asm.h>
10546 +
10547 .file "blowfish-x86_64-asm.S"
10548 .text
10549
10550 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
10551 jnz __enc_xor;
10552
10553 write_block();
10554 + pax_force_retaddr 0, 1
10555 ret;
10556 __enc_xor:
10557 xor_block();
10558 + pax_force_retaddr 0, 1
10559 ret;
10560
10561 .align 8
10562 @@ -188,6 +192,7 @@ blowfish_dec_blk:
10563
10564 movq %r11, %rbp;
10565
10566 + pax_force_retaddr 0, 1
10567 ret;
10568
10569 /**********************************************************************
10570 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
10571
10572 popq %rbx;
10573 popq %rbp;
10574 + pax_force_retaddr 0, 1
10575 ret;
10576
10577 __enc_xor4:
10578 @@ -349,6 +355,7 @@ __enc_xor4:
10579
10580 popq %rbx;
10581 popq %rbp;
10582 + pax_force_retaddr 0, 1
10583 ret;
10584
10585 .align 8
10586 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
10587 popq %rbx;
10588 popq %rbp;
10589
10590 + pax_force_retaddr 0, 1
10591 ret;
10592
10593 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
10594 index 0b33743..7a56206 100644
10595 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
10596 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
10597 @@ -20,6 +20,8 @@
10598 *
10599 */
10600
10601 +#include <asm/alternative-asm.h>
10602 +
10603 .file "camellia-x86_64-asm_64.S"
10604 .text
10605
10606 @@ -229,12 +231,14 @@ __enc_done:
10607 enc_outunpack(mov, RT1);
10608
10609 movq RRBP, %rbp;
10610 + pax_force_retaddr 0, 1
10611 ret;
10612
10613 __enc_xor:
10614 enc_outunpack(xor, RT1);
10615
10616 movq RRBP, %rbp;
10617 + pax_force_retaddr 0, 1
10618 ret;
10619
10620 .global camellia_dec_blk;
10621 @@ -275,6 +279,7 @@ __dec_rounds16:
10622 dec_outunpack();
10623
10624 movq RRBP, %rbp;
10625 + pax_force_retaddr 0, 1
10626 ret;
10627
10628 /**********************************************************************
10629 @@ -468,6 +473,7 @@ __enc2_done:
10630
10631 movq RRBP, %rbp;
10632 popq %rbx;
10633 + pax_force_retaddr 0, 1
10634 ret;
10635
10636 __enc2_xor:
10637 @@ -475,6 +481,7 @@ __enc2_xor:
10638
10639 movq RRBP, %rbp;
10640 popq %rbx;
10641 + pax_force_retaddr 0, 1
10642 ret;
10643
10644 .global camellia_dec_blk_2way;
10645 @@ -517,4 +524,5 @@ __dec2_rounds16:
10646
10647 movq RRBP, %rbp;
10648 movq RXOR, %rbx;
10649 + pax_force_retaddr 0, 1
10650 ret;
10651 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10652 index 15b00ac..2071784 100644
10653 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10654 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
10655 @@ -23,6 +23,8 @@
10656 *
10657 */
10658
10659 +#include <asm/alternative-asm.h>
10660 +
10661 .file "cast5-avx-x86_64-asm_64.S"
10662
10663 .extern cast_s1
10664 @@ -281,6 +283,7 @@ __skip_enc:
10665 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10666 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10667
10668 + pax_force_retaddr 0, 1
10669 ret;
10670
10671 .align 16
10672 @@ -353,6 +356,7 @@ __dec_tail:
10673 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
10674 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
10675
10676 + pax_force_retaddr 0, 1
10677 ret;
10678
10679 __skip_dec:
10680 @@ -392,6 +396,7 @@ cast5_ecb_enc_16way:
10681 vmovdqu RR4, (6*4*4)(%r11);
10682 vmovdqu RL4, (7*4*4)(%r11);
10683
10684 + pax_force_retaddr
10685 ret;
10686
10687 .align 16
10688 @@ -427,6 +432,7 @@ cast5_ecb_dec_16way:
10689 vmovdqu RR4, (6*4*4)(%r11);
10690 vmovdqu RL4, (7*4*4)(%r11);
10691
10692 + pax_force_retaddr
10693 ret;
10694
10695 .align 16
10696 @@ -479,6 +485,7 @@ cast5_cbc_dec_16way:
10697
10698 popq %r12;
10699
10700 + pax_force_retaddr
10701 ret;
10702
10703 .align 16
10704 @@ -555,4 +562,5 @@ cast5_ctr_16way:
10705
10706 popq %r12;
10707
10708 + pax_force_retaddr
10709 ret;
10710 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10711 index 2569d0d..637c289 100644
10712 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10713 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
10714 @@ -23,6 +23,8 @@
10715 *
10716 */
10717
10718 +#include <asm/alternative-asm.h>
10719 +
10720 #include "glue_helper-asm-avx.S"
10721
10722 .file "cast6-avx-x86_64-asm_64.S"
10723 @@ -294,6 +296,7 @@ __cast6_enc_blk8:
10724 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10725 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10726
10727 + pax_force_retaddr 0, 1
10728 ret;
10729
10730 .align 8
10731 @@ -340,6 +343,7 @@ __cast6_dec_blk8:
10732 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
10733 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
10734
10735 + pax_force_retaddr 0, 1
10736 ret;
10737
10738 .align 8
10739 @@ -361,6 +365,7 @@ cast6_ecb_enc_8way:
10740
10741 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10742
10743 + pax_force_retaddr
10744 ret;
10745
10746 .align 8
10747 @@ -382,6 +387,7 @@ cast6_ecb_dec_8way:
10748
10749 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10750
10751 + pax_force_retaddr
10752 ret;
10753
10754 .align 8
10755 @@ -408,6 +414,7 @@ cast6_cbc_dec_8way:
10756
10757 popq %r12;
10758
10759 + pax_force_retaddr
10760 ret;
10761
10762 .align 8
10763 @@ -436,4 +443,5 @@ cast6_ctr_8way:
10764
10765 popq %r12;
10766
10767 + pax_force_retaddr
10768 ret;
10769 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10770 index 6214a9b..1f4fc9a 100644
10771 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
10772 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
10773 @@ -1,3 +1,5 @@
10774 +#include <asm/alternative-asm.h>
10775 +
10776 # enter ECRYPT_encrypt_bytes
10777 .text
10778 .p2align 5
10779 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
10780 add %r11,%rsp
10781 mov %rdi,%rax
10782 mov %rsi,%rdx
10783 + pax_force_retaddr 0, 1
10784 ret
10785 # bytesatleast65:
10786 ._bytesatleast65:
10787 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
10788 add %r11,%rsp
10789 mov %rdi,%rax
10790 mov %rsi,%rdx
10791 + pax_force_retaddr
10792 ret
10793 # enter ECRYPT_ivsetup
10794 .text
10795 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
10796 add %r11,%rsp
10797 mov %rdi,%rax
10798 mov %rsi,%rdx
10799 + pax_force_retaddr
10800 ret
10801 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10802 index 02b0e9f..cf4cf5c 100644
10803 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10804 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
10805 @@ -24,6 +24,8 @@
10806 *
10807 */
10808
10809 +#include <asm/alternative-asm.h>
10810 +
10811 #include "glue_helper-asm-avx.S"
10812
10813 .file "serpent-avx-x86_64-asm_64.S"
10814 @@ -618,6 +620,7 @@ __serpent_enc_blk8_avx:
10815 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10816 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10817
10818 + pax_force_retaddr
10819 ret;
10820
10821 .align 8
10822 @@ -673,6 +676,7 @@ __serpent_dec_blk8_avx:
10823 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10824 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10825
10826 + pax_force_retaddr
10827 ret;
10828
10829 .align 8
10830 @@ -692,6 +696,7 @@ serpent_ecb_enc_8way_avx:
10831
10832 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10833
10834 + pax_force_retaddr
10835 ret;
10836
10837 .align 8
10838 @@ -711,6 +716,7 @@ serpent_ecb_dec_8way_avx:
10839
10840 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10841
10842 + pax_force_retaddr
10843 ret;
10844
10845 .align 8
10846 @@ -730,6 +736,7 @@ serpent_cbc_dec_8way_avx:
10847
10848 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
10849
10850 + pax_force_retaddr
10851 ret;
10852
10853 .align 8
10854 @@ -751,4 +758,5 @@ serpent_ctr_8way_avx:
10855
10856 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10857
10858 + pax_force_retaddr
10859 ret;
10860 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10861 index 3ee1ff0..cbc568b 100644
10862 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10863 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
10864 @@ -24,6 +24,8 @@
10865 *
10866 */
10867
10868 +#include <asm/alternative-asm.h>
10869 +
10870 .file "serpent-sse2-x86_64-asm_64.S"
10871 .text
10872
10873 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
10874 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10875 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10876
10877 + pax_force_retaddr
10878 ret;
10879
10880 __enc_xor8:
10881 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
10882 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
10883
10884 + pax_force_retaddr
10885 ret;
10886
10887 .align 8
10888 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
10889 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
10890 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
10891
10892 + pax_force_retaddr
10893 ret;
10894 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
10895 index 49d6987..df66bd4 100644
10896 --- a/arch/x86/crypto/sha1_ssse3_asm.S
10897 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
10898 @@ -28,6 +28,8 @@
10899 * (at your option) any later version.
10900 */
10901
10902 +#include <asm/alternative-asm.h>
10903 +
10904 #define CTX %rdi // arg1
10905 #define BUF %rsi // arg2
10906 #define CNT %rdx // arg3
10907 @@ -104,6 +106,7 @@
10908 pop %r12
10909 pop %rbp
10910 pop %rbx
10911 + pax_force_retaddr 0, 1
10912 ret
10913
10914 .size \name, .-\name
10915 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10916 index ebac16b..8092eb9 100644
10917 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10918 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
10919 @@ -23,6 +23,8 @@
10920 *
10921 */
10922
10923 +#include <asm/alternative-asm.h>
10924 +
10925 #include "glue_helper-asm-avx.S"
10926
10927 .file "twofish-avx-x86_64-asm_64.S"
10928 @@ -283,6 +285,7 @@ __twofish_enc_blk8:
10929 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
10930 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
10931
10932 + pax_force_retaddr 0, 1
10933 ret;
10934
10935 .align 8
10936 @@ -324,6 +327,7 @@ __twofish_dec_blk8:
10937 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
10938 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
10939
10940 + pax_force_retaddr 0, 1
10941 ret;
10942
10943 .align 8
10944 @@ -345,6 +349,7 @@ twofish_ecb_enc_8way:
10945
10946 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
10947
10948 + pax_force_retaddr 0, 1
10949 ret;
10950
10951 .align 8
10952 @@ -366,6 +371,7 @@ twofish_ecb_dec_8way:
10953
10954 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
10955
10956 + pax_force_retaddr 0, 1
10957 ret;
10958
10959 .align 8
10960 @@ -392,6 +398,7 @@ twofish_cbc_dec_8way:
10961
10962 popq %r12;
10963
10964 + pax_force_retaddr 0, 1
10965 ret;
10966
10967 .align 8
10968 @@ -420,4 +427,5 @@ twofish_ctr_8way:
10969
10970 popq %r12;
10971
10972 + pax_force_retaddr 0, 1
10973 ret;
10974 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10975 index 5b012a2..36d5364 100644
10976 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10977 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
10978 @@ -20,6 +20,8 @@
10979 *
10980 */
10981
10982 +#include <asm/alternative-asm.h>
10983 +
10984 .file "twofish-x86_64-asm-3way.S"
10985 .text
10986
10987 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
10988 popq %r13;
10989 popq %r14;
10990 popq %r15;
10991 + pax_force_retaddr 0, 1
10992 ret;
10993
10994 __enc_xor3:
10995 @@ -271,6 +274,7 @@ __enc_xor3:
10996 popq %r13;
10997 popq %r14;
10998 popq %r15;
10999 + pax_force_retaddr 0, 1
11000 ret;
11001
11002 .global twofish_dec_blk_3way
11003 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
11004 popq %r13;
11005 popq %r14;
11006 popq %r15;
11007 + pax_force_retaddr 0, 1
11008 ret;
11009
11010 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11011 index 7bcf3fc..f53832f 100644
11012 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11013 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11014 @@ -21,6 +21,7 @@
11015 .text
11016
11017 #include <asm/asm-offsets.h>
11018 +#include <asm/alternative-asm.h>
11019
11020 #define a_offset 0
11021 #define b_offset 4
11022 @@ -268,6 +269,7 @@ twofish_enc_blk:
11023
11024 popq R1
11025 movq $1,%rax
11026 + pax_force_retaddr 0, 1
11027 ret
11028
11029 twofish_dec_blk:
11030 @@ -319,4 +321,5 @@ twofish_dec_blk:
11031
11032 popq R1
11033 movq $1,%rax
11034 + pax_force_retaddr 0, 1
11035 ret
11036 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11037 index a703af1..f5b9c36 100644
11038 --- a/arch/x86/ia32/ia32_aout.c
11039 +++ b/arch/x86/ia32/ia32_aout.c
11040 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11041 unsigned long dump_start, dump_size;
11042 struct user32 dump;
11043
11044 + memset(&dump, 0, sizeof(dump));
11045 +
11046 fs = get_fs();
11047 set_fs(KERNEL_DS);
11048 has_dumped = 1;
11049 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11050 index a1daf4a..f8c4537 100644
11051 --- a/arch/x86/ia32/ia32_signal.c
11052 +++ b/arch/x86/ia32/ia32_signal.c
11053 @@ -348,7 +348,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
11054 sp -= frame_size;
11055 /* Align the stack pointer according to the i386 ABI,
11056 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11057 - sp = ((sp + 4) & -16ul) - 4;
11058 + sp = ((sp - 12) & -16ul) - 4;
11059 return (void __user *) sp;
11060 }
11061
11062 @@ -406,7 +406,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
11063 * These are actually not used anymore, but left because some
11064 * gdb versions depend on them as a marker.
11065 */
11066 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11067 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11068 } put_user_catch(err);
11069
11070 if (err)
11071 @@ -448,7 +448,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11072 0xb8,
11073 __NR_ia32_rt_sigreturn,
11074 0x80cd,
11075 - 0,
11076 + 0
11077 };
11078
11079 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
11080 @@ -471,16 +471,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
11081
11082 if (ka->sa.sa_flags & SA_RESTORER)
11083 restorer = ka->sa.sa_restorer;
11084 + else if (current->mm->context.vdso)
11085 + /* Return stub is in 32bit vsyscall page */
11086 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11087 else
11088 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11089 - rt_sigreturn);
11090 + restorer = &frame->retcode;
11091 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11092
11093 /*
11094 * Not actually used anymore, but left because some gdb
11095 * versions need it.
11096 */
11097 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11098 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11099 } put_user_catch(err);
11100
11101 err |= copy_siginfo_to_user32(&frame->info, info);
11102 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11103 index 142c4ce..19b683f 100644
11104 --- a/arch/x86/ia32/ia32entry.S
11105 +++ b/arch/x86/ia32/ia32entry.S
11106 @@ -15,8 +15,10 @@
11107 #include <asm/irqflags.h>
11108 #include <asm/asm.h>
11109 #include <asm/smap.h>
11110 +#include <asm/pgtable.h>
11111 #include <linux/linkage.h>
11112 #include <linux/err.h>
11113 +#include <asm/alternative-asm.h>
11114
11115 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11116 #include <linux/elf-em.h>
11117 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11118 ENDPROC(native_irq_enable_sysexit)
11119 #endif
11120
11121 + .macro pax_enter_kernel_user
11122 + pax_set_fptr_mask
11123 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11124 + call pax_enter_kernel_user
11125 +#endif
11126 + .endm
11127 +
11128 + .macro pax_exit_kernel_user
11129 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11130 + call pax_exit_kernel_user
11131 +#endif
11132 +#ifdef CONFIG_PAX_RANDKSTACK
11133 + pushq %rax
11134 + pushq %r11
11135 + call pax_randomize_kstack
11136 + popq %r11
11137 + popq %rax
11138 +#endif
11139 + .endm
11140 +
11141 +.macro pax_erase_kstack
11142 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11143 + call pax_erase_kstack
11144 +#endif
11145 +.endm
11146 +
11147 /*
11148 * 32bit SYSENTER instruction entry.
11149 *
11150 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11151 CFI_REGISTER rsp,rbp
11152 SWAPGS_UNSAFE_STACK
11153 movq PER_CPU_VAR(kernel_stack), %rsp
11154 - addq $(KERNEL_STACK_OFFSET),%rsp
11155 - /*
11156 - * No need to follow this irqs on/off section: the syscall
11157 - * disabled irqs, here we enable it straight after entry:
11158 - */
11159 - ENABLE_INTERRUPTS(CLBR_NONE)
11160 movl %ebp,%ebp /* zero extension */
11161 pushq_cfi $__USER32_DS
11162 /*CFI_REL_OFFSET ss,0*/
11163 @@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11164 CFI_REL_OFFSET rsp,0
11165 pushfq_cfi
11166 /*CFI_REL_OFFSET rflags,0*/
11167 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11168 - CFI_REGISTER rip,r10
11169 + orl $X86_EFLAGS_IF,(%rsp)
11170 + GET_THREAD_INFO(%r11)
11171 + movl TI_sysenter_return(%r11), %r11d
11172 + CFI_REGISTER rip,r11
11173 pushq_cfi $__USER32_CS
11174 /*CFI_REL_OFFSET cs,0*/
11175 movl %eax, %eax
11176 - pushq_cfi %r10
11177 + pushq_cfi %r11
11178 CFI_REL_OFFSET rip,0
11179 pushq_cfi %rax
11180 cld
11181 SAVE_ARGS 0,1,0
11182 + pax_enter_kernel_user
11183 +
11184 +#ifdef CONFIG_PAX_RANDKSTACK
11185 + pax_erase_kstack
11186 +#endif
11187 +
11188 + /*
11189 + * No need to follow this irqs on/off section: the syscall
11190 + * disabled irqs, here we enable it straight after entry:
11191 + */
11192 + ENABLE_INTERRUPTS(CLBR_NONE)
11193 /* no need to do an access_ok check here because rbp has been
11194 32bit zero extended */
11195 +
11196 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11197 + mov $PAX_USER_SHADOW_BASE,%r11
11198 + add %r11,%rbp
11199 +#endif
11200 +
11201 ASM_STAC
11202 1: movl (%rbp),%ebp
11203 _ASM_EXTABLE(1b,ia32_badarg)
11204 ASM_CLAC
11205 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11206 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11207 + GET_THREAD_INFO(%r11)
11208 + orl $TS_COMPAT,TI_status(%r11)
11209 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11210 CFI_REMEMBER_STATE
11211 jnz sysenter_tracesys
11212 cmpq $(IA32_NR_syscalls-1),%rax
11213 @@ -162,12 +204,15 @@ sysenter_do_call:
11214 sysenter_dispatch:
11215 call *ia32_sys_call_table(,%rax,8)
11216 movq %rax,RAX-ARGOFFSET(%rsp)
11217 + GET_THREAD_INFO(%r11)
11218 DISABLE_INTERRUPTS(CLBR_NONE)
11219 TRACE_IRQS_OFF
11220 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11221 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11222 jnz sysexit_audit
11223 sysexit_from_sys_call:
11224 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11225 + pax_exit_kernel_user
11226 + pax_erase_kstack
11227 + andl $~TS_COMPAT,TI_status(%r11)
11228 /* clear IF, that popfq doesn't enable interrupts early */
11229 andl $~0x200,EFLAGS-R11(%rsp)
11230 movl RIP-R11(%rsp),%edx /* User %eip */
11231 @@ -193,6 +238,9 @@ sysexit_from_sys_call:
11232 movl %eax,%esi /* 2nd arg: syscall number */
11233 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11234 call __audit_syscall_entry
11235 +
11236 + pax_erase_kstack
11237 +
11238 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11239 cmpq $(IA32_NR_syscalls-1),%rax
11240 ja ia32_badsys
11241 @@ -204,7 +252,7 @@ sysexit_from_sys_call:
11242 .endm
11243
11244 .macro auditsys_exit exit
11245 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11246 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11247 jnz ia32_ret_from_sys_call
11248 TRACE_IRQS_ON
11249 ENABLE_INTERRUPTS(CLBR_NONE)
11250 @@ -215,11 +263,12 @@ sysexit_from_sys_call:
11251 1: setbe %al /* 1 if error, 0 if not */
11252 movzbl %al,%edi /* zero-extend that into %edi */
11253 call __audit_syscall_exit
11254 + GET_THREAD_INFO(%r11)
11255 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11256 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11257 DISABLE_INTERRUPTS(CLBR_NONE)
11258 TRACE_IRQS_OFF
11259 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11260 + testl %edi,TI_flags(%r11)
11261 jz \exit
11262 CLEAR_RREGS -ARGOFFSET
11263 jmp int_with_check
11264 @@ -237,7 +286,7 @@ sysexit_audit:
11265
11266 sysenter_tracesys:
11267 #ifdef CONFIG_AUDITSYSCALL
11268 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11269 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11270 jz sysenter_auditsys
11271 #endif
11272 SAVE_REST
11273 @@ -249,6 +298,9 @@ sysenter_tracesys:
11274 RESTORE_REST
11275 cmpq $(IA32_NR_syscalls-1),%rax
11276 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11277 +
11278 + pax_erase_kstack
11279 +
11280 jmp sysenter_do_call
11281 CFI_ENDPROC
11282 ENDPROC(ia32_sysenter_target)
11283 @@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11284 ENTRY(ia32_cstar_target)
11285 CFI_STARTPROC32 simple
11286 CFI_SIGNAL_FRAME
11287 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11288 + CFI_DEF_CFA rsp,0
11289 CFI_REGISTER rip,rcx
11290 /*CFI_REGISTER rflags,r11*/
11291 SWAPGS_UNSAFE_STACK
11292 movl %esp,%r8d
11293 CFI_REGISTER rsp,r8
11294 movq PER_CPU_VAR(kernel_stack),%rsp
11295 + SAVE_ARGS 8*6,0,0
11296 + pax_enter_kernel_user
11297 +
11298 +#ifdef CONFIG_PAX_RANDKSTACK
11299 + pax_erase_kstack
11300 +#endif
11301 +
11302 /*
11303 * No need to follow this irqs on/off section: the syscall
11304 * disabled irqs and here we enable it straight after entry:
11305 */
11306 ENABLE_INTERRUPTS(CLBR_NONE)
11307 - SAVE_ARGS 8,0,0
11308 movl %eax,%eax /* zero extension */
11309 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11310 movq %rcx,RIP-ARGOFFSET(%rsp)
11311 @@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11312 /* no need to do an access_ok check here because r8 has been
11313 32bit zero extended */
11314 /* hardware stack frame is complete now */
11315 +
11316 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11317 + mov $PAX_USER_SHADOW_BASE,%r11
11318 + add %r11,%r8
11319 +#endif
11320 +
11321 ASM_STAC
11322 1: movl (%r8),%r9d
11323 _ASM_EXTABLE(1b,ia32_badarg)
11324 ASM_CLAC
11325 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11326 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11327 + GET_THREAD_INFO(%r11)
11328 + orl $TS_COMPAT,TI_status(%r11)
11329 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11330 CFI_REMEMBER_STATE
11331 jnz cstar_tracesys
11332 cmpq $IA32_NR_syscalls-1,%rax
11333 @@ -319,12 +384,15 @@ cstar_do_call:
11334 cstar_dispatch:
11335 call *ia32_sys_call_table(,%rax,8)
11336 movq %rax,RAX-ARGOFFSET(%rsp)
11337 + GET_THREAD_INFO(%r11)
11338 DISABLE_INTERRUPTS(CLBR_NONE)
11339 TRACE_IRQS_OFF
11340 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11341 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11342 jnz sysretl_audit
11343 sysretl_from_sys_call:
11344 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11345 + pax_exit_kernel_user
11346 + pax_erase_kstack
11347 + andl $~TS_COMPAT,TI_status(%r11)
11348 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11349 movl RIP-ARGOFFSET(%rsp),%ecx
11350 CFI_REGISTER rip,rcx
11351 @@ -352,7 +420,7 @@ sysretl_audit:
11352
11353 cstar_tracesys:
11354 #ifdef CONFIG_AUDITSYSCALL
11355 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11356 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11357 jz cstar_auditsys
11358 #endif
11359 xchgl %r9d,%ebp
11360 @@ -366,6 +434,9 @@ cstar_tracesys:
11361 xchgl %ebp,%r9d
11362 cmpq $(IA32_NR_syscalls-1),%rax
11363 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11364 +
11365 + pax_erase_kstack
11366 +
11367 jmp cstar_do_call
11368 END(ia32_cstar_target)
11369
11370 @@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11371 CFI_REL_OFFSET rip,RIP-RIP
11372 PARAVIRT_ADJUST_EXCEPTION_FRAME
11373 SWAPGS
11374 - /*
11375 - * No need to follow this irqs on/off section: the syscall
11376 - * disabled irqs and here we enable it straight after entry:
11377 - */
11378 - ENABLE_INTERRUPTS(CLBR_NONE)
11379 movl %eax,%eax
11380 pushq_cfi %rax
11381 cld
11382 /* note the registers are not zero extended to the sf.
11383 this could be a problem. */
11384 SAVE_ARGS 0,1,0
11385 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11386 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11387 + pax_enter_kernel_user
11388 +
11389 +#ifdef CONFIG_PAX_RANDKSTACK
11390 + pax_erase_kstack
11391 +#endif
11392 +
11393 + /*
11394 + * No need to follow this irqs on/off section: the syscall
11395 + * disabled irqs and here we enable it straight after entry:
11396 + */
11397 + ENABLE_INTERRUPTS(CLBR_NONE)
11398 + GET_THREAD_INFO(%r11)
11399 + orl $TS_COMPAT,TI_status(%r11)
11400 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11401 jnz ia32_tracesys
11402 cmpq $(IA32_NR_syscalls-1),%rax
11403 ja ia32_badsys
11404 @@ -442,6 +520,9 @@ ia32_tracesys:
11405 RESTORE_REST
11406 cmpq $(IA32_NR_syscalls-1),%rax
11407 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11408 +
11409 + pax_erase_kstack
11410 +
11411 jmp ia32_do_call
11412 END(ia32_syscall)
11413
11414 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11415 index d0b689b..34be51d 100644
11416 --- a/arch/x86/ia32/sys_ia32.c
11417 +++ b/arch/x86/ia32/sys_ia32.c
11418 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11419 */
11420 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11421 {
11422 - typeof(ubuf->st_uid) uid = 0;
11423 - typeof(ubuf->st_gid) gid = 0;
11424 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
11425 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
11426 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11427 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11428 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11429 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
11430 mm_segment_t old_fs = get_fs();
11431
11432 set_fs(KERNEL_DS);
11433 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
11434 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
11435 set_fs(old_fs);
11436 if (put_compat_timespec(&t, interval))
11437 return -EFAULT;
11438 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
11439 mm_segment_t old_fs = get_fs();
11440
11441 set_fs(KERNEL_DS);
11442 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
11443 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
11444 set_fs(old_fs);
11445 if (!ret) {
11446 switch (_NSIG_WORDS) {
11447 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
11448 if (copy_siginfo_from_user32(&info, uinfo))
11449 return -EFAULT;
11450 set_fs(KERNEL_DS);
11451 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
11452 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
11453 set_fs(old_fs);
11454 return ret;
11455 }
11456 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11457 return -EFAULT;
11458
11459 set_fs(KERNEL_DS);
11460 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11461 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11462 count);
11463 set_fs(old_fs);
11464
11465 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11466 index 372231c..a5aa1a1 100644
11467 --- a/arch/x86/include/asm/alternative-asm.h
11468 +++ b/arch/x86/include/asm/alternative-asm.h
11469 @@ -18,6 +18,45 @@
11470 .endm
11471 #endif
11472
11473 +#ifdef KERNEXEC_PLUGIN
11474 + .macro pax_force_retaddr_bts rip=0
11475 + btsq $63,\rip(%rsp)
11476 + .endm
11477 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11478 + .macro pax_force_retaddr rip=0, reload=0
11479 + btsq $63,\rip(%rsp)
11480 + .endm
11481 + .macro pax_force_fptr ptr
11482 + btsq $63,\ptr
11483 + .endm
11484 + .macro pax_set_fptr_mask
11485 + .endm
11486 +#endif
11487 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11488 + .macro pax_force_retaddr rip=0, reload=0
11489 + .if \reload
11490 + pax_set_fptr_mask
11491 + .endif
11492 + orq %r10,\rip(%rsp)
11493 + .endm
11494 + .macro pax_force_fptr ptr
11495 + orq %r10,\ptr
11496 + .endm
11497 + .macro pax_set_fptr_mask
11498 + movabs $0x8000000000000000,%r10
11499 + .endm
11500 +#endif
11501 +#else
11502 + .macro pax_force_retaddr rip=0, reload=0
11503 + .endm
11504 + .macro pax_force_fptr ptr
11505 + .endm
11506 + .macro pax_force_retaddr_bts rip=0
11507 + .endm
11508 + .macro pax_set_fptr_mask
11509 + .endm
11510 +#endif
11511 +
11512 .macro altinstruction_entry orig alt feature orig_len alt_len
11513 .long \orig - .
11514 .long \alt - .
11515 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11516 index 58ed6d9..f1cbe58 100644
11517 --- a/arch/x86/include/asm/alternative.h
11518 +++ b/arch/x86/include/asm/alternative.h
11519 @@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11520 ".pushsection .discard,\"aw\",@progbits\n" \
11521 DISCARD_ENTRY(1) \
11522 ".popsection\n" \
11523 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11524 + ".pushsection .altinstr_replacement, \"a\"\n" \
11525 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11526 ".popsection"
11527
11528 @@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11529 DISCARD_ENTRY(1) \
11530 DISCARD_ENTRY(2) \
11531 ".popsection\n" \
11532 - ".pushsection .altinstr_replacement, \"ax\"\n" \
11533 + ".pushsection .altinstr_replacement, \"a\"\n" \
11534 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11535 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11536 ".popsection"
11537 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11538 index 3388034..050f0b9 100644
11539 --- a/arch/x86/include/asm/apic.h
11540 +++ b/arch/x86/include/asm/apic.h
11541 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11542
11543 #ifdef CONFIG_X86_LOCAL_APIC
11544
11545 -extern unsigned int apic_verbosity;
11546 +extern int apic_verbosity;
11547 extern int local_apic_timer_c2_ok;
11548
11549 extern int disable_apic;
11550 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11551 index 20370c6..a2eb9b0 100644
11552 --- a/arch/x86/include/asm/apm.h
11553 +++ b/arch/x86/include/asm/apm.h
11554 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11555 __asm__ __volatile__(APM_DO_ZERO_SEGS
11556 "pushl %%edi\n\t"
11557 "pushl %%ebp\n\t"
11558 - "lcall *%%cs:apm_bios_entry\n\t"
11559 + "lcall *%%ss:apm_bios_entry\n\t"
11560 "setc %%al\n\t"
11561 "popl %%ebp\n\t"
11562 "popl %%edi\n\t"
11563 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11564 __asm__ __volatile__(APM_DO_ZERO_SEGS
11565 "pushl %%edi\n\t"
11566 "pushl %%ebp\n\t"
11567 - "lcall *%%cs:apm_bios_entry\n\t"
11568 + "lcall *%%ss:apm_bios_entry\n\t"
11569 "setc %%bl\n\t"
11570 "popl %%ebp\n\t"
11571 "popl %%edi\n\t"
11572 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11573 index 722aa3b..3a0bb27 100644
11574 --- a/arch/x86/include/asm/atomic.h
11575 +++ b/arch/x86/include/asm/atomic.h
11576 @@ -22,7 +22,18 @@
11577 */
11578 static inline int atomic_read(const atomic_t *v)
11579 {
11580 - return (*(volatile int *)&(v)->counter);
11581 + return (*(volatile const int *)&(v)->counter);
11582 +}
11583 +
11584 +/**
11585 + * atomic_read_unchecked - read atomic variable
11586 + * @v: pointer of type atomic_unchecked_t
11587 + *
11588 + * Atomically reads the value of @v.
11589 + */
11590 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
11591 +{
11592 + return (*(volatile const int *)&(v)->counter);
11593 }
11594
11595 /**
11596 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
11597 }
11598
11599 /**
11600 + * atomic_set_unchecked - set atomic variable
11601 + * @v: pointer of type atomic_unchecked_t
11602 + * @i: required value
11603 + *
11604 + * Atomically sets the value of @v to @i.
11605 + */
11606 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
11607 +{
11608 + v->counter = i;
11609 +}
11610 +
11611 +/**
11612 * atomic_add - add integer to atomic variable
11613 * @i: integer value to add
11614 * @v: pointer of type atomic_t
11615 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
11616 */
11617 static inline void atomic_add(int i, atomic_t *v)
11618 {
11619 - asm volatile(LOCK_PREFIX "addl %1,%0"
11620 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11621 +
11622 +#ifdef CONFIG_PAX_REFCOUNT
11623 + "jno 0f\n"
11624 + LOCK_PREFIX "subl %1,%0\n"
11625 + "int $4\n0:\n"
11626 + _ASM_EXTABLE(0b, 0b)
11627 +#endif
11628 +
11629 + : "+m" (v->counter)
11630 + : "ir" (i));
11631 +}
11632 +
11633 +/**
11634 + * atomic_add_unchecked - add integer to atomic variable
11635 + * @i: integer value to add
11636 + * @v: pointer of type atomic_unchecked_t
11637 + *
11638 + * Atomically adds @i to @v.
11639 + */
11640 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
11641 +{
11642 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
11643 : "+m" (v->counter)
11644 : "ir" (i));
11645 }
11646 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
11647 */
11648 static inline void atomic_sub(int i, atomic_t *v)
11649 {
11650 - asm volatile(LOCK_PREFIX "subl %1,%0"
11651 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11652 +
11653 +#ifdef CONFIG_PAX_REFCOUNT
11654 + "jno 0f\n"
11655 + LOCK_PREFIX "addl %1,%0\n"
11656 + "int $4\n0:\n"
11657 + _ASM_EXTABLE(0b, 0b)
11658 +#endif
11659 +
11660 + : "+m" (v->counter)
11661 + : "ir" (i));
11662 +}
11663 +
11664 +/**
11665 + * atomic_sub_unchecked - subtract integer from atomic variable
11666 + * @i: integer value to subtract
11667 + * @v: pointer of type atomic_unchecked_t
11668 + *
11669 + * Atomically subtracts @i from @v.
11670 + */
11671 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
11672 +{
11673 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
11674 : "+m" (v->counter)
11675 : "ir" (i));
11676 }
11677 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11678 {
11679 unsigned char c;
11680
11681 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
11682 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
11683 +
11684 +#ifdef CONFIG_PAX_REFCOUNT
11685 + "jno 0f\n"
11686 + LOCK_PREFIX "addl %2,%0\n"
11687 + "int $4\n0:\n"
11688 + _ASM_EXTABLE(0b, 0b)
11689 +#endif
11690 +
11691 + "sete %1\n"
11692 : "+m" (v->counter), "=qm" (c)
11693 : "ir" (i) : "memory");
11694 return c;
11695 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
11696 */
11697 static inline void atomic_inc(atomic_t *v)
11698 {
11699 - asm volatile(LOCK_PREFIX "incl %0"
11700 + asm volatile(LOCK_PREFIX "incl %0\n"
11701 +
11702 +#ifdef CONFIG_PAX_REFCOUNT
11703 + "jno 0f\n"
11704 + LOCK_PREFIX "decl %0\n"
11705 + "int $4\n0:\n"
11706 + _ASM_EXTABLE(0b, 0b)
11707 +#endif
11708 +
11709 + : "+m" (v->counter));
11710 +}
11711 +
11712 +/**
11713 + * atomic_inc_unchecked - increment atomic variable
11714 + * @v: pointer of type atomic_unchecked_t
11715 + *
11716 + * Atomically increments @v by 1.
11717 + */
11718 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
11719 +{
11720 + asm volatile(LOCK_PREFIX "incl %0\n"
11721 : "+m" (v->counter));
11722 }
11723
11724 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
11725 */
11726 static inline void atomic_dec(atomic_t *v)
11727 {
11728 - asm volatile(LOCK_PREFIX "decl %0"
11729 + asm volatile(LOCK_PREFIX "decl %0\n"
11730 +
11731 +#ifdef CONFIG_PAX_REFCOUNT
11732 + "jno 0f\n"
11733 + LOCK_PREFIX "incl %0\n"
11734 + "int $4\n0:\n"
11735 + _ASM_EXTABLE(0b, 0b)
11736 +#endif
11737 +
11738 + : "+m" (v->counter));
11739 +}
11740 +
11741 +/**
11742 + * atomic_dec_unchecked - decrement atomic variable
11743 + * @v: pointer of type atomic_unchecked_t
11744 + *
11745 + * Atomically decrements @v by 1.
11746 + */
11747 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
11748 +{
11749 + asm volatile(LOCK_PREFIX "decl %0\n"
11750 : "+m" (v->counter));
11751 }
11752
11753 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
11754 {
11755 unsigned char c;
11756
11757 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
11758 + asm volatile(LOCK_PREFIX "decl %0\n"
11759 +
11760 +#ifdef CONFIG_PAX_REFCOUNT
11761 + "jno 0f\n"
11762 + LOCK_PREFIX "incl %0\n"
11763 + "int $4\n0:\n"
11764 + _ASM_EXTABLE(0b, 0b)
11765 +#endif
11766 +
11767 + "sete %1\n"
11768 : "+m" (v->counter), "=qm" (c)
11769 : : "memory");
11770 return c != 0;
11771 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
11772 {
11773 unsigned char c;
11774
11775 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
11776 + asm volatile(LOCK_PREFIX "incl %0\n"
11777 +
11778 +#ifdef CONFIG_PAX_REFCOUNT
11779 + "jno 0f\n"
11780 + LOCK_PREFIX "decl %0\n"
11781 + "int $4\n0:\n"
11782 + _ASM_EXTABLE(0b, 0b)
11783 +#endif
11784 +
11785 + "sete %1\n"
11786 + : "+m" (v->counter), "=qm" (c)
11787 + : : "memory");
11788 + return c != 0;
11789 +}
11790 +
11791 +/**
11792 + * atomic_inc_and_test_unchecked - increment and test
11793 + * @v: pointer of type atomic_unchecked_t
11794 + *
11795 + * Atomically increments @v by 1
11796 + * and returns true if the result is zero, or false for all
11797 + * other cases.
11798 + */
11799 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
11800 +{
11801 + unsigned char c;
11802 +
11803 + asm volatile(LOCK_PREFIX "incl %0\n"
11804 + "sete %1\n"
11805 : "+m" (v->counter), "=qm" (c)
11806 : : "memory");
11807 return c != 0;
11808 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11809 {
11810 unsigned char c;
11811
11812 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
11813 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
11814 +
11815 +#ifdef CONFIG_PAX_REFCOUNT
11816 + "jno 0f\n"
11817 + LOCK_PREFIX "subl %2,%0\n"
11818 + "int $4\n0:\n"
11819 + _ASM_EXTABLE(0b, 0b)
11820 +#endif
11821 +
11822 + "sets %1\n"
11823 : "+m" (v->counter), "=qm" (c)
11824 : "ir" (i) : "memory");
11825 return c;
11826 @@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
11827 */
11828 static inline int atomic_add_return(int i, atomic_t *v)
11829 {
11830 + return i + xadd_check_overflow(&v->counter, i);
11831 +}
11832 +
11833 +/**
11834 + * atomic_add_return_unchecked - add integer and return
11835 + * @i: integer value to add
11836 + * @v: pointer of type atomic_unchecked_t
11837 + *
11838 + * Atomically adds @i to @v and returns @i + @v
11839 + */
11840 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
11841 +{
11842 return i + xadd(&v->counter, i);
11843 }
11844
11845 @@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
11846 }
11847
11848 #define atomic_inc_return(v) (atomic_add_return(1, v))
11849 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
11850 +{
11851 + return atomic_add_return_unchecked(1, v);
11852 +}
11853 #define atomic_dec_return(v) (atomic_sub_return(1, v))
11854
11855 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11856 @@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
11857 return cmpxchg(&v->counter, old, new);
11858 }
11859
11860 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
11861 +{
11862 + return cmpxchg(&v->counter, old, new);
11863 +}
11864 +
11865 static inline int atomic_xchg(atomic_t *v, int new)
11866 {
11867 return xchg(&v->counter, new);
11868 }
11869
11870 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
11871 +{
11872 + return xchg(&v->counter, new);
11873 +}
11874 +
11875 /**
11876 * __atomic_add_unless - add unless the number is already a given value
11877 * @v: pointer of type atomic_t
11878 @@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
11879 */
11880 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11881 {
11882 - int c, old;
11883 + int c, old, new;
11884 c = atomic_read(v);
11885 for (;;) {
11886 - if (unlikely(c == (u)))
11887 + if (unlikely(c == u))
11888 break;
11889 - old = atomic_cmpxchg((v), c, c + (a));
11890 +
11891 + asm volatile("addl %2,%0\n"
11892 +
11893 +#ifdef CONFIG_PAX_REFCOUNT
11894 + "jno 0f\n"
11895 + "subl %2,%0\n"
11896 + "int $4\n0:\n"
11897 + _ASM_EXTABLE(0b, 0b)
11898 +#endif
11899 +
11900 + : "=r" (new)
11901 + : "0" (c), "ir" (a));
11902 +
11903 + old = atomic_cmpxchg(v, c, new);
11904 if (likely(old == c))
11905 break;
11906 c = old;
11907 @@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
11908 }
11909
11910 /**
11911 + * atomic_inc_not_zero_hint - increment if not null
11912 + * @v: pointer of type atomic_t
11913 + * @hint: probable value of the atomic before the increment
11914 + *
11915 + * This version of atomic_inc_not_zero() gives a hint of probable
11916 + * value of the atomic. This helps processor to not read the memory
11917 + * before doing the atomic read/modify/write cycle, lowering
11918 + * number of bus transactions on some arches.
11919 + *
11920 + * Returns: 0 if increment was not done, 1 otherwise.
11921 + */
11922 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
11923 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
11924 +{
11925 + int val, c = hint, new;
11926 +
11927 + /* sanity test, should be removed by compiler if hint is a constant */
11928 + if (!hint)
11929 + return __atomic_add_unless(v, 1, 0);
11930 +
11931 + do {
11932 + asm volatile("incl %0\n"
11933 +
11934 +#ifdef CONFIG_PAX_REFCOUNT
11935 + "jno 0f\n"
11936 + "decl %0\n"
11937 + "int $4\n0:\n"
11938 + _ASM_EXTABLE(0b, 0b)
11939 +#endif
11940 +
11941 + : "=r" (new)
11942 + : "0" (c));
11943 +
11944 + val = atomic_cmpxchg(v, c, new);
11945 + if (val == c)
11946 + return 1;
11947 + c = val;
11948 + } while (c);
11949 +
11950 + return 0;
11951 +}
11952 +
11953 +/**
11954 * atomic_inc_short - increment of a short integer
11955 * @v: pointer to type int
11956 *
11957 @@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
11958 #endif
11959
11960 /* These are x86-specific, used by some header files */
11961 -#define atomic_clear_mask(mask, addr) \
11962 - asm volatile(LOCK_PREFIX "andl %0,%1" \
11963 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
11964 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
11965 +{
11966 + asm volatile(LOCK_PREFIX "andl %1,%0"
11967 + : "+m" (v->counter)
11968 + : "r" (~(mask))
11969 + : "memory");
11970 +}
11971
11972 -#define atomic_set_mask(mask, addr) \
11973 - asm volatile(LOCK_PREFIX "orl %0,%1" \
11974 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
11975 - : "memory")
11976 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11977 +{
11978 + asm volatile(LOCK_PREFIX "andl %1,%0"
11979 + : "+m" (v->counter)
11980 + : "r" (~(mask))
11981 + : "memory");
11982 +}
11983 +
11984 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
11985 +{
11986 + asm volatile(LOCK_PREFIX "orl %1,%0"
11987 + : "+m" (v->counter)
11988 + : "r" (mask)
11989 + : "memory");
11990 +}
11991 +
11992 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
11993 +{
11994 + asm volatile(LOCK_PREFIX "orl %1,%0"
11995 + : "+m" (v->counter)
11996 + : "r" (mask)
11997 + : "memory");
11998 +}
11999
12000 /* Atomic operations are already serializing on x86 */
12001 #define smp_mb__before_atomic_dec() barrier()
12002 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12003 index b154de7..aadebd8 100644
12004 --- a/arch/x86/include/asm/atomic64_32.h
12005 +++ b/arch/x86/include/asm/atomic64_32.h
12006 @@ -12,6 +12,14 @@ typedef struct {
12007 u64 __aligned(8) counter;
12008 } atomic64_t;
12009
12010 +#ifdef CONFIG_PAX_REFCOUNT
12011 +typedef struct {
12012 + u64 __aligned(8) counter;
12013 +} atomic64_unchecked_t;
12014 +#else
12015 +typedef atomic64_t atomic64_unchecked_t;
12016 +#endif
12017 +
12018 #define ATOMIC64_INIT(val) { (val) }
12019
12020 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12021 @@ -37,21 +45,31 @@ typedef struct {
12022 ATOMIC64_DECL_ONE(sym##_386)
12023
12024 ATOMIC64_DECL_ONE(add_386);
12025 +ATOMIC64_DECL_ONE(add_unchecked_386);
12026 ATOMIC64_DECL_ONE(sub_386);
12027 +ATOMIC64_DECL_ONE(sub_unchecked_386);
12028 ATOMIC64_DECL_ONE(inc_386);
12029 +ATOMIC64_DECL_ONE(inc_unchecked_386);
12030 ATOMIC64_DECL_ONE(dec_386);
12031 +ATOMIC64_DECL_ONE(dec_unchecked_386);
12032 #endif
12033
12034 #define alternative_atomic64(f, out, in...) \
12035 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12036
12037 ATOMIC64_DECL(read);
12038 +ATOMIC64_DECL(read_unchecked);
12039 ATOMIC64_DECL(set);
12040 +ATOMIC64_DECL(set_unchecked);
12041 ATOMIC64_DECL(xchg);
12042 ATOMIC64_DECL(add_return);
12043 +ATOMIC64_DECL(add_return_unchecked);
12044 ATOMIC64_DECL(sub_return);
12045 +ATOMIC64_DECL(sub_return_unchecked);
12046 ATOMIC64_DECL(inc_return);
12047 +ATOMIC64_DECL(inc_return_unchecked);
12048 ATOMIC64_DECL(dec_return);
12049 +ATOMIC64_DECL(dec_return_unchecked);
12050 ATOMIC64_DECL(dec_if_positive);
12051 ATOMIC64_DECL(inc_not_zero);
12052 ATOMIC64_DECL(add_unless);
12053 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12054 }
12055
12056 /**
12057 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12058 + * @p: pointer to type atomic64_unchecked_t
12059 + * @o: expected value
12060 + * @n: new value
12061 + *
12062 + * Atomically sets @v to @n if it was equal to @o and returns
12063 + * the old value.
12064 + */
12065 +
12066 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12067 +{
12068 + return cmpxchg64(&v->counter, o, n);
12069 +}
12070 +
12071 +/**
12072 * atomic64_xchg - xchg atomic64 variable
12073 * @v: pointer to type atomic64_t
12074 * @n: value to assign
12075 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12076 }
12077
12078 /**
12079 + * atomic64_set_unchecked - set atomic64 variable
12080 + * @v: pointer to type atomic64_unchecked_t
12081 + * @n: value to assign
12082 + *
12083 + * Atomically sets the value of @v to @n.
12084 + */
12085 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12086 +{
12087 + unsigned high = (unsigned)(i >> 32);
12088 + unsigned low = (unsigned)i;
12089 + alternative_atomic64(set, /* no output */,
12090 + "S" (v), "b" (low), "c" (high)
12091 + : "eax", "edx", "memory");
12092 +}
12093 +
12094 +/**
12095 * atomic64_read - read atomic64 variable
12096 * @v: pointer to type atomic64_t
12097 *
12098 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12099 }
12100
12101 /**
12102 + * atomic64_read_unchecked - read atomic64 variable
12103 + * @v: pointer to type atomic64_unchecked_t
12104 + *
12105 + * Atomically reads the value of @v and returns it.
12106 + */
12107 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12108 +{
12109 + long long r;
12110 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12111 + return r;
12112 + }
12113 +
12114 +/**
12115 * atomic64_add_return - add and return
12116 * @i: integer value to add
12117 * @v: pointer to type atomic64_t
12118 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12119 return i;
12120 }
12121
12122 +/**
12123 + * atomic64_add_return_unchecked - add and return
12124 + * @i: integer value to add
12125 + * @v: pointer to type atomic64_unchecked_t
12126 + *
12127 + * Atomically adds @i to @v and returns @i + *@v
12128 + */
12129 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12130 +{
12131 + alternative_atomic64(add_return_unchecked,
12132 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12133 + ASM_NO_INPUT_CLOBBER("memory"));
12134 + return i;
12135 +}
12136 +
12137 /*
12138 * Other variants with different arithmetic operators:
12139 */
12140 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12141 return a;
12142 }
12143
12144 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12145 +{
12146 + long long a;
12147 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
12148 + "S" (v) : "memory", "ecx");
12149 + return a;
12150 +}
12151 +
12152 static inline long long atomic64_dec_return(atomic64_t *v)
12153 {
12154 long long a;
12155 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12156 }
12157
12158 /**
12159 + * atomic64_add_unchecked - add integer to atomic64 variable
12160 + * @i: integer value to add
12161 + * @v: pointer to type atomic64_unchecked_t
12162 + *
12163 + * Atomically adds @i to @v.
12164 + */
12165 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12166 +{
12167 + __alternative_atomic64(add_unchecked, add_return_unchecked,
12168 + ASM_OUTPUT2("+A" (i), "+c" (v)),
12169 + ASM_NO_INPUT_CLOBBER("memory"));
12170 + return i;
12171 +}
12172 +
12173 +/**
12174 * atomic64_sub - subtract the atomic64 variable
12175 * @i: integer value to subtract
12176 * @v: pointer to type atomic64_t
12177 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12178 index 0e1cbfc..5623683 100644
12179 --- a/arch/x86/include/asm/atomic64_64.h
12180 +++ b/arch/x86/include/asm/atomic64_64.h
12181 @@ -18,7 +18,19 @@
12182 */
12183 static inline long atomic64_read(const atomic64_t *v)
12184 {
12185 - return (*(volatile long *)&(v)->counter);
12186 + return (*(volatile const long *)&(v)->counter);
12187 +}
12188 +
12189 +/**
12190 + * atomic64_read_unchecked - read atomic64 variable
12191 + * @v: pointer of type atomic64_unchecked_t
12192 + *
12193 + * Atomically reads the value of @v.
12194 + * Doesn't imply a read memory barrier.
12195 + */
12196 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12197 +{
12198 + return (*(volatile const long *)&(v)->counter);
12199 }
12200
12201 /**
12202 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12203 }
12204
12205 /**
12206 + * atomic64_set_unchecked - set atomic64 variable
12207 + * @v: pointer to type atomic64_unchecked_t
12208 + * @i: required value
12209 + *
12210 + * Atomically sets the value of @v to @i.
12211 + */
12212 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12213 +{
12214 + v->counter = i;
12215 +}
12216 +
12217 +/**
12218 * atomic64_add - add integer to atomic64 variable
12219 * @i: integer value to add
12220 * @v: pointer to type atomic64_t
12221 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12222 */
12223 static inline void atomic64_add(long i, atomic64_t *v)
12224 {
12225 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
12226 +
12227 +#ifdef CONFIG_PAX_REFCOUNT
12228 + "jno 0f\n"
12229 + LOCK_PREFIX "subq %1,%0\n"
12230 + "int $4\n0:\n"
12231 + _ASM_EXTABLE(0b, 0b)
12232 +#endif
12233 +
12234 + : "=m" (v->counter)
12235 + : "er" (i), "m" (v->counter));
12236 +}
12237 +
12238 +/**
12239 + * atomic64_add_unchecked - add integer to atomic64 variable
12240 + * @i: integer value to add
12241 + * @v: pointer to type atomic64_unchecked_t
12242 + *
12243 + * Atomically adds @i to @v.
12244 + */
12245 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12246 +{
12247 asm volatile(LOCK_PREFIX "addq %1,%0"
12248 : "=m" (v->counter)
12249 : "er" (i), "m" (v->counter));
12250 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12251 */
12252 static inline void atomic64_sub(long i, atomic64_t *v)
12253 {
12254 - asm volatile(LOCK_PREFIX "subq %1,%0"
12255 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12256 +
12257 +#ifdef CONFIG_PAX_REFCOUNT
12258 + "jno 0f\n"
12259 + LOCK_PREFIX "addq %1,%0\n"
12260 + "int $4\n0:\n"
12261 + _ASM_EXTABLE(0b, 0b)
12262 +#endif
12263 +
12264 + : "=m" (v->counter)
12265 + : "er" (i), "m" (v->counter));
12266 +}
12267 +
12268 +/**
12269 + * atomic64_sub_unchecked - subtract the atomic64 variable
12270 + * @i: integer value to subtract
12271 + * @v: pointer to type atomic64_unchecked_t
12272 + *
12273 + * Atomically subtracts @i from @v.
12274 + */
12275 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12276 +{
12277 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
12278 : "=m" (v->counter)
12279 : "er" (i), "m" (v->counter));
12280 }
12281 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12282 {
12283 unsigned char c;
12284
12285 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12286 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
12287 +
12288 +#ifdef CONFIG_PAX_REFCOUNT
12289 + "jno 0f\n"
12290 + LOCK_PREFIX "addq %2,%0\n"
12291 + "int $4\n0:\n"
12292 + _ASM_EXTABLE(0b, 0b)
12293 +#endif
12294 +
12295 + "sete %1\n"
12296 : "=m" (v->counter), "=qm" (c)
12297 : "er" (i), "m" (v->counter) : "memory");
12298 return c;
12299 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12300 */
12301 static inline void atomic64_inc(atomic64_t *v)
12302 {
12303 + asm volatile(LOCK_PREFIX "incq %0\n"
12304 +
12305 +#ifdef CONFIG_PAX_REFCOUNT
12306 + "jno 0f\n"
12307 + LOCK_PREFIX "decq %0\n"
12308 + "int $4\n0:\n"
12309 + _ASM_EXTABLE(0b, 0b)
12310 +#endif
12311 +
12312 + : "=m" (v->counter)
12313 + : "m" (v->counter));
12314 +}
12315 +
12316 +/**
12317 + * atomic64_inc_unchecked - increment atomic64 variable
12318 + * @v: pointer to type atomic64_unchecked_t
12319 + *
12320 + * Atomically increments @v by 1.
12321 + */
12322 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12323 +{
12324 asm volatile(LOCK_PREFIX "incq %0"
12325 : "=m" (v->counter)
12326 : "m" (v->counter));
12327 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12328 */
12329 static inline void atomic64_dec(atomic64_t *v)
12330 {
12331 - asm volatile(LOCK_PREFIX "decq %0"
12332 + asm volatile(LOCK_PREFIX "decq %0\n"
12333 +
12334 +#ifdef CONFIG_PAX_REFCOUNT
12335 + "jno 0f\n"
12336 + LOCK_PREFIX "incq %0\n"
12337 + "int $4\n0:\n"
12338 + _ASM_EXTABLE(0b, 0b)
12339 +#endif
12340 +
12341 + : "=m" (v->counter)
12342 + : "m" (v->counter));
12343 +}
12344 +
12345 +/**
12346 + * atomic64_dec_unchecked - decrement atomic64 variable
12347 + * @v: pointer to type atomic64_t
12348 + *
12349 + * Atomically decrements @v by 1.
12350 + */
12351 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12352 +{
12353 + asm volatile(LOCK_PREFIX "decq %0\n"
12354 : "=m" (v->counter)
12355 : "m" (v->counter));
12356 }
12357 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12358 {
12359 unsigned char c;
12360
12361 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
12362 + asm volatile(LOCK_PREFIX "decq %0\n"
12363 +
12364 +#ifdef CONFIG_PAX_REFCOUNT
12365 + "jno 0f\n"
12366 + LOCK_PREFIX "incq %0\n"
12367 + "int $4\n0:\n"
12368 + _ASM_EXTABLE(0b, 0b)
12369 +#endif
12370 +
12371 + "sete %1\n"
12372 : "=m" (v->counter), "=qm" (c)
12373 : "m" (v->counter) : "memory");
12374 return c != 0;
12375 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12376 {
12377 unsigned char c;
12378
12379 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
12380 + asm volatile(LOCK_PREFIX "incq %0\n"
12381 +
12382 +#ifdef CONFIG_PAX_REFCOUNT
12383 + "jno 0f\n"
12384 + LOCK_PREFIX "decq %0\n"
12385 + "int $4\n0:\n"
12386 + _ASM_EXTABLE(0b, 0b)
12387 +#endif
12388 +
12389 + "sete %1\n"
12390 : "=m" (v->counter), "=qm" (c)
12391 : "m" (v->counter) : "memory");
12392 return c != 0;
12393 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12394 {
12395 unsigned char c;
12396
12397 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12398 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
12399 +
12400 +#ifdef CONFIG_PAX_REFCOUNT
12401 + "jno 0f\n"
12402 + LOCK_PREFIX "subq %2,%0\n"
12403 + "int $4\n0:\n"
12404 + _ASM_EXTABLE(0b, 0b)
12405 +#endif
12406 +
12407 + "sets %1\n"
12408 : "=m" (v->counter), "=qm" (c)
12409 : "er" (i), "m" (v->counter) : "memory");
12410 return c;
12411 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12412 */
12413 static inline long atomic64_add_return(long i, atomic64_t *v)
12414 {
12415 + return i + xadd_check_overflow(&v->counter, i);
12416 +}
12417 +
12418 +/**
12419 + * atomic64_add_return_unchecked - add and return
12420 + * @i: integer value to add
12421 + * @v: pointer to type atomic64_unchecked_t
12422 + *
12423 + * Atomically adds @i to @v and returns @i + @v
12424 + */
12425 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12426 +{
12427 return i + xadd(&v->counter, i);
12428 }
12429
12430 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12431 }
12432
12433 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12434 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12435 +{
12436 + return atomic64_add_return_unchecked(1, v);
12437 +}
12438 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12439
12440 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12441 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12442 return cmpxchg(&v->counter, old, new);
12443 }
12444
12445 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12446 +{
12447 + return cmpxchg(&v->counter, old, new);
12448 +}
12449 +
12450 static inline long atomic64_xchg(atomic64_t *v, long new)
12451 {
12452 return xchg(&v->counter, new);
12453 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12454 */
12455 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12456 {
12457 - long c, old;
12458 + long c, old, new;
12459 c = atomic64_read(v);
12460 for (;;) {
12461 - if (unlikely(c == (u)))
12462 + if (unlikely(c == u))
12463 break;
12464 - old = atomic64_cmpxchg((v), c, c + (a));
12465 +
12466 + asm volatile("add %2,%0\n"
12467 +
12468 +#ifdef CONFIG_PAX_REFCOUNT
12469 + "jno 0f\n"
12470 + "sub %2,%0\n"
12471 + "int $4\n0:\n"
12472 + _ASM_EXTABLE(0b, 0b)
12473 +#endif
12474 +
12475 + : "=r" (new)
12476 + : "0" (c), "ir" (a));
12477 +
12478 + old = atomic64_cmpxchg(v, c, new);
12479 if (likely(old == c))
12480 break;
12481 c = old;
12482 }
12483 - return c != (u);
12484 + return c != u;
12485 }
12486
12487 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12488 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12489 index 6dfd019..0c6699f 100644
12490 --- a/arch/x86/include/asm/bitops.h
12491 +++ b/arch/x86/include/asm/bitops.h
12492 @@ -40,7 +40,7 @@
12493 * a mask operation on a byte.
12494 */
12495 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12496 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12497 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12498 #define CONST_MASK(nr) (1 << ((nr) & 7))
12499
12500 /**
12501 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12502 index 4fa687a..60f2d39 100644
12503 --- a/arch/x86/include/asm/boot.h
12504 +++ b/arch/x86/include/asm/boot.h
12505 @@ -6,10 +6,15 @@
12506 #include <uapi/asm/boot.h>
12507
12508 /* Physical address where kernel should be loaded. */
12509 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12510 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12511 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12512 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12513
12514 +#ifndef __ASSEMBLY__
12515 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
12516 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12517 +#endif
12518 +
12519 /* Minimum kernel alignment, as a power of two */
12520 #ifdef CONFIG_X86_64
12521 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12522 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12523 index 48f99f1..d78ebf9 100644
12524 --- a/arch/x86/include/asm/cache.h
12525 +++ b/arch/x86/include/asm/cache.h
12526 @@ -5,12 +5,13 @@
12527
12528 /* L1 cache line size */
12529 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12530 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12531 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12532
12533 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12534 +#define __read_only __attribute__((__section__(".data..read_only")))
12535
12536 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12537 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12538 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12539
12540 #ifdef CONFIG_X86_VSMP
12541 #ifdef CONFIG_SMP
12542 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12543 index 9863ee3..4a1f8e1 100644
12544 --- a/arch/x86/include/asm/cacheflush.h
12545 +++ b/arch/x86/include/asm/cacheflush.h
12546 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12547 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12548
12549 if (pg_flags == _PGMT_DEFAULT)
12550 - return -1;
12551 + return ~0UL;
12552 else if (pg_flags == _PGMT_WC)
12553 return _PAGE_CACHE_WC;
12554 else if (pg_flags == _PGMT_UC_MINUS)
12555 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12556 index 46fc474..b02b0f9 100644
12557 --- a/arch/x86/include/asm/checksum_32.h
12558 +++ b/arch/x86/include/asm/checksum_32.h
12559 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12560 int len, __wsum sum,
12561 int *src_err_ptr, int *dst_err_ptr);
12562
12563 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12564 + int len, __wsum sum,
12565 + int *src_err_ptr, int *dst_err_ptr);
12566 +
12567 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12568 + int len, __wsum sum,
12569 + int *src_err_ptr, int *dst_err_ptr);
12570 +
12571 /*
12572 * Note: when you get a NULL pointer exception here this means someone
12573 * passed in an incorrect kernel address to one of these functions.
12574 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
12575 int *err_ptr)
12576 {
12577 might_sleep();
12578 - return csum_partial_copy_generic((__force void *)src, dst,
12579 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
12580 len, sum, err_ptr, NULL);
12581 }
12582
12583 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
12584 {
12585 might_sleep();
12586 if (access_ok(VERIFY_WRITE, dst, len))
12587 - return csum_partial_copy_generic(src, (__force void *)dst,
12588 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
12589 len, sum, NULL, err_ptr);
12590
12591 if (len)
12592 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
12593 index 8d871ea..c1a0dc9 100644
12594 --- a/arch/x86/include/asm/cmpxchg.h
12595 +++ b/arch/x86/include/asm/cmpxchg.h
12596 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
12597 __compiletime_error("Bad argument size for cmpxchg");
12598 extern void __xadd_wrong_size(void)
12599 __compiletime_error("Bad argument size for xadd");
12600 +extern void __xadd_check_overflow_wrong_size(void)
12601 + __compiletime_error("Bad argument size for xadd_check_overflow");
12602 extern void __add_wrong_size(void)
12603 __compiletime_error("Bad argument size for add");
12604 +extern void __add_check_overflow_wrong_size(void)
12605 + __compiletime_error("Bad argument size for add_check_overflow");
12606
12607 /*
12608 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
12609 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
12610 __ret; \
12611 })
12612
12613 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
12614 + ({ \
12615 + __typeof__ (*(ptr)) __ret = (arg); \
12616 + switch (sizeof(*(ptr))) { \
12617 + case __X86_CASE_L: \
12618 + asm volatile (lock #op "l %0, %1\n" \
12619 + "jno 0f\n" \
12620 + "mov %0,%1\n" \
12621 + "int $4\n0:\n" \
12622 + _ASM_EXTABLE(0b, 0b) \
12623 + : "+r" (__ret), "+m" (*(ptr)) \
12624 + : : "memory", "cc"); \
12625 + break; \
12626 + case __X86_CASE_Q: \
12627 + asm volatile (lock #op "q %q0, %1\n" \
12628 + "jno 0f\n" \
12629 + "mov %0,%1\n" \
12630 + "int $4\n0:\n" \
12631 + _ASM_EXTABLE(0b, 0b) \
12632 + : "+r" (__ret), "+m" (*(ptr)) \
12633 + : : "memory", "cc"); \
12634 + break; \
12635 + default: \
12636 + __ ## op ## _check_overflow_wrong_size(); \
12637 + } \
12638 + __ret; \
12639 + })
12640 +
12641 /*
12642 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
12643 * Since this is generally used to protect other memory information, we
12644 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
12645 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
12646 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
12647
12648 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
12649 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
12650 +
12651 #define __add(ptr, inc, lock) \
12652 ({ \
12653 __typeof__ (*(ptr)) __ret = (inc); \
12654 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
12655 index 2d9075e..b75a844 100644
12656 --- a/arch/x86/include/asm/cpufeature.h
12657 +++ b/arch/x86/include/asm/cpufeature.h
12658 @@ -206,7 +206,7 @@
12659 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
12660 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
12661 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
12662 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
12663 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
12664 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
12665 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
12666 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
12667 @@ -375,7 +375,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
12668 ".section .discard,\"aw\",@progbits\n"
12669 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
12670 ".previous\n"
12671 - ".section .altinstr_replacement,\"ax\"\n"
12672 + ".section .altinstr_replacement,\"a\"\n"
12673 "3: movb $1,%0\n"
12674 "4:\n"
12675 ".previous\n"
12676 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
12677 index 8bf1c06..f723dfd 100644
12678 --- a/arch/x86/include/asm/desc.h
12679 +++ b/arch/x86/include/asm/desc.h
12680 @@ -4,6 +4,7 @@
12681 #include <asm/desc_defs.h>
12682 #include <asm/ldt.h>
12683 #include <asm/mmu.h>
12684 +#include <asm/pgtable.h>
12685
12686 #include <linux/smp.h>
12687 #include <linux/percpu.h>
12688 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12689
12690 desc->type = (info->read_exec_only ^ 1) << 1;
12691 desc->type |= info->contents << 2;
12692 + desc->type |= info->seg_not_present ^ 1;
12693
12694 desc->s = 1;
12695 desc->dpl = 0x3;
12696 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
12697 }
12698
12699 extern struct desc_ptr idt_descr;
12700 -extern gate_desc idt_table[];
12701 extern struct desc_ptr nmi_idt_descr;
12702 -extern gate_desc nmi_idt_table[];
12703 -
12704 -struct gdt_page {
12705 - struct desc_struct gdt[GDT_ENTRIES];
12706 -} __attribute__((aligned(PAGE_SIZE)));
12707 -
12708 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
12709 +extern gate_desc idt_table[256];
12710 +extern gate_desc nmi_idt_table[256];
12711
12712 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
12713 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
12714 {
12715 - return per_cpu(gdt_page, cpu).gdt;
12716 + return cpu_gdt_table[cpu];
12717 }
12718
12719 #ifdef CONFIG_X86_64
12720 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
12721 unsigned long base, unsigned dpl, unsigned flags,
12722 unsigned short seg)
12723 {
12724 - gate->a = (seg << 16) | (base & 0xffff);
12725 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
12726 + gate->gate.offset_low = base;
12727 + gate->gate.seg = seg;
12728 + gate->gate.reserved = 0;
12729 + gate->gate.type = type;
12730 + gate->gate.s = 0;
12731 + gate->gate.dpl = dpl;
12732 + gate->gate.p = 1;
12733 + gate->gate.offset_high = base >> 16;
12734 }
12735
12736 #endif
12737 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
12738
12739 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
12740 {
12741 + pax_open_kernel();
12742 memcpy(&idt[entry], gate, sizeof(*gate));
12743 + pax_close_kernel();
12744 }
12745
12746 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
12747 {
12748 + pax_open_kernel();
12749 memcpy(&ldt[entry], desc, 8);
12750 + pax_close_kernel();
12751 }
12752
12753 static inline void
12754 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
12755 default: size = sizeof(*gdt); break;
12756 }
12757
12758 + pax_open_kernel();
12759 memcpy(&gdt[entry], desc, size);
12760 + pax_close_kernel();
12761 }
12762
12763 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
12764 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
12765
12766 static inline void native_load_tr_desc(void)
12767 {
12768 + pax_open_kernel();
12769 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
12770 + pax_close_kernel();
12771 }
12772
12773 static inline void native_load_gdt(const struct desc_ptr *dtr)
12774 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
12775 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
12776 unsigned int i;
12777
12778 + pax_open_kernel();
12779 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
12780 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
12781 + pax_close_kernel();
12782 }
12783
12784 #define _LDT_empty(info) \
12785 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
12786 }
12787
12788 #ifdef CONFIG_X86_64
12789 -static inline void set_nmi_gate(int gate, void *addr)
12790 +static inline void set_nmi_gate(int gate, const void *addr)
12791 {
12792 gate_desc s;
12793
12794 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
12795 }
12796 #endif
12797
12798 -static inline void _set_gate(int gate, unsigned type, void *addr,
12799 +static inline void _set_gate(int gate, unsigned type, const void *addr,
12800 unsigned dpl, unsigned ist, unsigned seg)
12801 {
12802 gate_desc s;
12803 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
12804 * Pentium F0 0F bugfix can have resulted in the mapped
12805 * IDT being write-protected.
12806 */
12807 -static inline void set_intr_gate(unsigned int n, void *addr)
12808 +static inline void set_intr_gate(unsigned int n, const void *addr)
12809 {
12810 BUG_ON((unsigned)n > 0xFF);
12811 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
12812 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
12813 /*
12814 * This routine sets up an interrupt gate at directory privilege level 3.
12815 */
12816 -static inline void set_system_intr_gate(unsigned int n, void *addr)
12817 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
12818 {
12819 BUG_ON((unsigned)n > 0xFF);
12820 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
12821 }
12822
12823 -static inline void set_system_trap_gate(unsigned int n, void *addr)
12824 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
12825 {
12826 BUG_ON((unsigned)n > 0xFF);
12827 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
12828 }
12829
12830 -static inline void set_trap_gate(unsigned int n, void *addr)
12831 +static inline void set_trap_gate(unsigned int n, const void *addr)
12832 {
12833 BUG_ON((unsigned)n > 0xFF);
12834 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
12835 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
12836 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
12837 {
12838 BUG_ON((unsigned)n > 0xFF);
12839 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
12840 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
12841 }
12842
12843 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
12844 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
12845 {
12846 BUG_ON((unsigned)n > 0xFF);
12847 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
12848 }
12849
12850 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
12851 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
12852 {
12853 BUG_ON((unsigned)n > 0xFF);
12854 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
12855 }
12856
12857 +#ifdef CONFIG_X86_32
12858 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
12859 +{
12860 + struct desc_struct d;
12861 +
12862 + if (likely(limit))
12863 + limit = (limit - 1UL) >> PAGE_SHIFT;
12864 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
12865 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
12866 +}
12867 +#endif
12868 +
12869 #endif /* _ASM_X86_DESC_H */
12870 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
12871 index 278441f..b95a174 100644
12872 --- a/arch/x86/include/asm/desc_defs.h
12873 +++ b/arch/x86/include/asm/desc_defs.h
12874 @@ -31,6 +31,12 @@ struct desc_struct {
12875 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
12876 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
12877 };
12878 + struct {
12879 + u16 offset_low;
12880 + u16 seg;
12881 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
12882 + unsigned offset_high: 16;
12883 + } gate;
12884 };
12885 } __attribute__((packed));
12886
12887 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
12888 index 9c999c1..3860cb8 100644
12889 --- a/arch/x86/include/asm/elf.h
12890 +++ b/arch/x86/include/asm/elf.h
12891 @@ -243,7 +243,25 @@ extern int force_personality32;
12892 the loader. We need to make sure that it is out of the way of the program
12893 that it will "exec", and that there is sufficient room for the brk. */
12894
12895 +#ifdef CONFIG_PAX_SEGMEXEC
12896 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
12897 +#else
12898 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
12899 +#endif
12900 +
12901 +#ifdef CONFIG_PAX_ASLR
12902 +#ifdef CONFIG_X86_32
12903 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
12904 +
12905 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12906 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
12907 +#else
12908 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
12909 +
12910 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12911 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
12912 +#endif
12913 +#endif
12914
12915 /* This yields a mask that user programs can use to figure out what
12916 instruction set this CPU supports. This could be done in user space,
12917 @@ -296,16 +314,12 @@ do { \
12918
12919 #define ARCH_DLINFO \
12920 do { \
12921 - if (vdso_enabled) \
12922 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12923 - (unsigned long)current->mm->context.vdso); \
12924 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12925 } while (0)
12926
12927 #define ARCH_DLINFO_X32 \
12928 do { \
12929 - if (vdso_enabled) \
12930 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
12931 - (unsigned long)current->mm->context.vdso); \
12932 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
12933 } while (0)
12934
12935 #define AT_SYSINFO 32
12936 @@ -320,7 +334,7 @@ else \
12937
12938 #endif /* !CONFIG_X86_32 */
12939
12940 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
12941 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
12942
12943 #define VDSO_ENTRY \
12944 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
12945 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
12946 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
12947 #define compat_arch_setup_additional_pages syscall32_setup_pages
12948
12949 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
12950 -#define arch_randomize_brk arch_randomize_brk
12951 -
12952 /*
12953 * True on X86_32 or when emulating IA32 on X86_64
12954 */
12955 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
12956 index 75ce3f4..882e801 100644
12957 --- a/arch/x86/include/asm/emergency-restart.h
12958 +++ b/arch/x86/include/asm/emergency-restart.h
12959 @@ -13,6 +13,6 @@ enum reboot_type {
12960
12961 extern enum reboot_type reboot_type;
12962
12963 -extern void machine_emergency_restart(void);
12964 +extern void machine_emergency_restart(void) __noreturn;
12965
12966 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
12967 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
12968 index 41ab26e..a88c9e6 100644
12969 --- a/arch/x86/include/asm/fpu-internal.h
12970 +++ b/arch/x86/include/asm/fpu-internal.h
12971 @@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
12972 ({ \
12973 int err; \
12974 asm volatile(ASM_STAC "\n" \
12975 - "1:" #insn "\n\t" \
12976 + "1:" \
12977 + __copyuser_seg \
12978 + #insn "\n\t" \
12979 "2: " ASM_CLAC "\n" \
12980 ".section .fixup,\"ax\"\n" \
12981 "3: movl $-1,%[err]\n" \
12982 @@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
12983 "emms\n\t" /* clear stack tags */
12984 "fildl %P[addr]", /* set F?P to defined value */
12985 X86_FEATURE_FXSAVE_LEAK,
12986 - [addr] "m" (tsk->thread.fpu.has_fpu));
12987 + [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
12988
12989 return fpu_restore_checking(&tsk->thread.fpu);
12990 }
12991 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
12992 index be27ba1..8f13ff9 100644
12993 --- a/arch/x86/include/asm/futex.h
12994 +++ b/arch/x86/include/asm/futex.h
12995 @@ -12,6 +12,7 @@
12996 #include <asm/smap.h>
12997
12998 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
12999 + typecheck(u32 __user *, uaddr); \
13000 asm volatile("\t" ASM_STAC "\n" \
13001 "1:\t" insn "\n" \
13002 "2:\t" ASM_CLAC "\n" \
13003 @@ -20,15 +21,16 @@
13004 "\tjmp\t2b\n" \
13005 "\t.previous\n" \
13006 _ASM_EXTABLE(1b, 3b) \
13007 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13008 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13009 : "i" (-EFAULT), "0" (oparg), "1" (0))
13010
13011 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13012 + typecheck(u32 __user *, uaddr); \
13013 asm volatile("\t" ASM_STAC "\n" \
13014 "1:\tmovl %2, %0\n" \
13015 "\tmovl\t%0, %3\n" \
13016 "\t" insn "\n" \
13017 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13018 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13019 "\tjnz\t1b\n" \
13020 "3:\t" ASM_CLAC "\n" \
13021 "\t.section .fixup,\"ax\"\n" \
13022 @@ -38,7 +40,7 @@
13023 _ASM_EXTABLE(1b, 4b) \
13024 _ASM_EXTABLE(2b, 4b) \
13025 : "=&a" (oldval), "=&r" (ret), \
13026 - "+m" (*uaddr), "=&r" (tem) \
13027 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13028 : "r" (oparg), "i" (-EFAULT), "1" (0))
13029
13030 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13031 @@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13032
13033 switch (op) {
13034 case FUTEX_OP_SET:
13035 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13036 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13037 break;
13038 case FUTEX_OP_ADD:
13039 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13040 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13041 uaddr, oparg);
13042 break;
13043 case FUTEX_OP_OR:
13044 @@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13045 return -EFAULT;
13046
13047 asm volatile("\t" ASM_STAC "\n"
13048 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13049 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13050 "2:\t" ASM_CLAC "\n"
13051 "\t.section .fixup, \"ax\"\n"
13052 "3:\tmov %3, %0\n"
13053 "\tjmp 2b\n"
13054 "\t.previous\n"
13055 _ASM_EXTABLE(1b, 3b)
13056 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13057 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13058 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13059 : "memory"
13060 );
13061 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13062 index eb92a6e..b98b2f4 100644
13063 --- a/arch/x86/include/asm/hw_irq.h
13064 +++ b/arch/x86/include/asm/hw_irq.h
13065 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
13066 extern void enable_IO_APIC(void);
13067
13068 /* Statistics */
13069 -extern atomic_t irq_err_count;
13070 -extern atomic_t irq_mis_count;
13071 +extern atomic_unchecked_t irq_err_count;
13072 +extern atomic_unchecked_t irq_mis_count;
13073
13074 /* EISA */
13075 extern void eisa_set_level_irq(unsigned int irq);
13076 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13077 index d8e8eef..15b1179 100644
13078 --- a/arch/x86/include/asm/io.h
13079 +++ b/arch/x86/include/asm/io.h
13080 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13081 return ioremap_nocache(offset, size);
13082 }
13083
13084 -extern void iounmap(volatile void __iomem *addr);
13085 +extern void iounmap(const volatile void __iomem *addr);
13086
13087 extern void set_iounmap_nonlazy(void);
13088
13089 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13090
13091 #include <linux/vmalloc.h>
13092
13093 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13094 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13095 +{
13096 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13097 +}
13098 +
13099 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13100 +{
13101 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13102 +}
13103 +
13104 /*
13105 * Convert a virtual cached pointer to an uncached pointer
13106 */
13107 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13108 index bba3cf8..06bc8da 100644
13109 --- a/arch/x86/include/asm/irqflags.h
13110 +++ b/arch/x86/include/asm/irqflags.h
13111 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13112 sti; \
13113 sysexit
13114
13115 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
13116 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13117 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
13118 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13119 +
13120 #else
13121 #define INTERRUPT_RETURN iret
13122 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13123 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13124 index d3ddd17..c9fb0cc 100644
13125 --- a/arch/x86/include/asm/kprobes.h
13126 +++ b/arch/x86/include/asm/kprobes.h
13127 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13128 #define RELATIVEJUMP_SIZE 5
13129 #define RELATIVECALL_OPCODE 0xe8
13130 #define RELATIVE_ADDR_SIZE 4
13131 -#define MAX_STACK_SIZE 64
13132 -#define MIN_STACK_SIZE(ADDR) \
13133 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13134 - THREAD_SIZE - (unsigned long)(ADDR))) \
13135 - ? (MAX_STACK_SIZE) \
13136 - : (((unsigned long)current_thread_info()) + \
13137 - THREAD_SIZE - (unsigned long)(ADDR)))
13138 +#define MAX_STACK_SIZE 64UL
13139 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13140
13141 #define flush_insn_slot(p) do { } while (0)
13142
13143 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13144 index 2d89e39..baee879 100644
13145 --- a/arch/x86/include/asm/local.h
13146 +++ b/arch/x86/include/asm/local.h
13147 @@ -10,33 +10,97 @@ typedef struct {
13148 atomic_long_t a;
13149 } local_t;
13150
13151 +typedef struct {
13152 + atomic_long_unchecked_t a;
13153 +} local_unchecked_t;
13154 +
13155 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13156
13157 #define local_read(l) atomic_long_read(&(l)->a)
13158 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13159 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13160 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13161
13162 static inline void local_inc(local_t *l)
13163 {
13164 - asm volatile(_ASM_INC "%0"
13165 + asm volatile(_ASM_INC "%0\n"
13166 +
13167 +#ifdef CONFIG_PAX_REFCOUNT
13168 + "jno 0f\n"
13169 + _ASM_DEC "%0\n"
13170 + "int $4\n0:\n"
13171 + _ASM_EXTABLE(0b, 0b)
13172 +#endif
13173 +
13174 + : "+m" (l->a.counter));
13175 +}
13176 +
13177 +static inline void local_inc_unchecked(local_unchecked_t *l)
13178 +{
13179 + asm volatile(_ASM_INC "%0\n"
13180 : "+m" (l->a.counter));
13181 }
13182
13183 static inline void local_dec(local_t *l)
13184 {
13185 - asm volatile(_ASM_DEC "%0"
13186 + asm volatile(_ASM_DEC "%0\n"
13187 +
13188 +#ifdef CONFIG_PAX_REFCOUNT
13189 + "jno 0f\n"
13190 + _ASM_INC "%0\n"
13191 + "int $4\n0:\n"
13192 + _ASM_EXTABLE(0b, 0b)
13193 +#endif
13194 +
13195 + : "+m" (l->a.counter));
13196 +}
13197 +
13198 +static inline void local_dec_unchecked(local_unchecked_t *l)
13199 +{
13200 + asm volatile(_ASM_DEC "%0\n"
13201 : "+m" (l->a.counter));
13202 }
13203
13204 static inline void local_add(long i, local_t *l)
13205 {
13206 - asm volatile(_ASM_ADD "%1,%0"
13207 + asm volatile(_ASM_ADD "%1,%0\n"
13208 +
13209 +#ifdef CONFIG_PAX_REFCOUNT
13210 + "jno 0f\n"
13211 + _ASM_SUB "%1,%0\n"
13212 + "int $4\n0:\n"
13213 + _ASM_EXTABLE(0b, 0b)
13214 +#endif
13215 +
13216 + : "+m" (l->a.counter)
13217 + : "ir" (i));
13218 +}
13219 +
13220 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
13221 +{
13222 + asm volatile(_ASM_ADD "%1,%0\n"
13223 : "+m" (l->a.counter)
13224 : "ir" (i));
13225 }
13226
13227 static inline void local_sub(long i, local_t *l)
13228 {
13229 - asm volatile(_ASM_SUB "%1,%0"
13230 + asm volatile(_ASM_SUB "%1,%0\n"
13231 +
13232 +#ifdef CONFIG_PAX_REFCOUNT
13233 + "jno 0f\n"
13234 + _ASM_ADD "%1,%0\n"
13235 + "int $4\n0:\n"
13236 + _ASM_EXTABLE(0b, 0b)
13237 +#endif
13238 +
13239 + : "+m" (l->a.counter)
13240 + : "ir" (i));
13241 +}
13242 +
13243 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13244 +{
13245 + asm volatile(_ASM_SUB "%1,%0\n"
13246 : "+m" (l->a.counter)
13247 : "ir" (i));
13248 }
13249 @@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13250 {
13251 unsigned char c;
13252
13253 - asm volatile(_ASM_SUB "%2,%0; sete %1"
13254 + asm volatile(_ASM_SUB "%2,%0\n"
13255 +
13256 +#ifdef CONFIG_PAX_REFCOUNT
13257 + "jno 0f\n"
13258 + _ASM_ADD "%2,%0\n"
13259 + "int $4\n0:\n"
13260 + _ASM_EXTABLE(0b, 0b)
13261 +#endif
13262 +
13263 + "sete %1\n"
13264 : "+m" (l->a.counter), "=qm" (c)
13265 : "ir" (i) : "memory");
13266 return c;
13267 @@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13268 {
13269 unsigned char c;
13270
13271 - asm volatile(_ASM_DEC "%0; sete %1"
13272 + asm volatile(_ASM_DEC "%0\n"
13273 +
13274 +#ifdef CONFIG_PAX_REFCOUNT
13275 + "jno 0f\n"
13276 + _ASM_INC "%0\n"
13277 + "int $4\n0:\n"
13278 + _ASM_EXTABLE(0b, 0b)
13279 +#endif
13280 +
13281 + "sete %1\n"
13282 : "+m" (l->a.counter), "=qm" (c)
13283 : : "memory");
13284 return c != 0;
13285 @@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13286 {
13287 unsigned char c;
13288
13289 - asm volatile(_ASM_INC "%0; sete %1"
13290 + asm volatile(_ASM_INC "%0\n"
13291 +
13292 +#ifdef CONFIG_PAX_REFCOUNT
13293 + "jno 0f\n"
13294 + _ASM_DEC "%0\n"
13295 + "int $4\n0:\n"
13296 + _ASM_EXTABLE(0b, 0b)
13297 +#endif
13298 +
13299 + "sete %1\n"
13300 : "+m" (l->a.counter), "=qm" (c)
13301 : : "memory");
13302 return c != 0;
13303 @@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13304 {
13305 unsigned char c;
13306
13307 - asm volatile(_ASM_ADD "%2,%0; sets %1"
13308 + asm volatile(_ASM_ADD "%2,%0\n"
13309 +
13310 +#ifdef CONFIG_PAX_REFCOUNT
13311 + "jno 0f\n"
13312 + _ASM_SUB "%2,%0\n"
13313 + "int $4\n0:\n"
13314 + _ASM_EXTABLE(0b, 0b)
13315 +#endif
13316 +
13317 + "sets %1\n"
13318 : "+m" (l->a.counter), "=qm" (c)
13319 : "ir" (i) : "memory");
13320 return c;
13321 @@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13322 static inline long local_add_return(long i, local_t *l)
13323 {
13324 long __i = i;
13325 + asm volatile(_ASM_XADD "%0, %1\n"
13326 +
13327 +#ifdef CONFIG_PAX_REFCOUNT
13328 + "jno 0f\n"
13329 + _ASM_MOV "%0,%1\n"
13330 + "int $4\n0:\n"
13331 + _ASM_EXTABLE(0b, 0b)
13332 +#endif
13333 +
13334 + : "+r" (i), "+m" (l->a.counter)
13335 + : : "memory");
13336 + return i + __i;
13337 +}
13338 +
13339 +/**
13340 + * local_add_return_unchecked - add and return
13341 + * @i: integer value to add
13342 + * @l: pointer to type local_unchecked_t
13343 + *
13344 + * Atomically adds @i to @l and returns @i + @l
13345 + */
13346 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13347 +{
13348 + long __i = i;
13349 asm volatile(_ASM_XADD "%0, %1;"
13350 : "+r" (i), "+m" (l->a.counter)
13351 : : "memory");
13352 @@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13353
13354 #define local_cmpxchg(l, o, n) \
13355 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13356 +#define local_cmpxchg_unchecked(l, o, n) \
13357 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
13358 /* Always has a lock prefix */
13359 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13360
13361 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13362 new file mode 100644
13363 index 0000000..2bfd3ba
13364 --- /dev/null
13365 +++ b/arch/x86/include/asm/mman.h
13366 @@ -0,0 +1,15 @@
13367 +#ifndef _X86_MMAN_H
13368 +#define _X86_MMAN_H
13369 +
13370 +#include <uapi/asm/mman.h>
13371 +
13372 +#ifdef __KERNEL__
13373 +#ifndef __ASSEMBLY__
13374 +#ifdef CONFIG_X86_32
13375 +#define arch_mmap_check i386_mmap_check
13376 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13377 +#endif
13378 +#endif
13379 +#endif
13380 +
13381 +#endif /* X86_MMAN_H */
13382 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13383 index 5f55e69..e20bfb1 100644
13384 --- a/arch/x86/include/asm/mmu.h
13385 +++ b/arch/x86/include/asm/mmu.h
13386 @@ -9,7 +9,7 @@
13387 * we put the segment information here.
13388 */
13389 typedef struct {
13390 - void *ldt;
13391 + struct desc_struct *ldt;
13392 int size;
13393
13394 #ifdef CONFIG_X86_64
13395 @@ -18,7 +18,19 @@ typedef struct {
13396 #endif
13397
13398 struct mutex lock;
13399 - void *vdso;
13400 + unsigned long vdso;
13401 +
13402 +#ifdef CONFIG_X86_32
13403 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13404 + unsigned long user_cs_base;
13405 + unsigned long user_cs_limit;
13406 +
13407 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13408 + cpumask_t cpu_user_cs_mask;
13409 +#endif
13410 +
13411 +#endif
13412 +#endif
13413 } mm_context_t;
13414
13415 #ifdef CONFIG_SMP
13416 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13417 index cdbf367..adb37ac 100644
13418 --- a/arch/x86/include/asm/mmu_context.h
13419 +++ b/arch/x86/include/asm/mmu_context.h
13420 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13421
13422 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13423 {
13424 +
13425 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13426 + unsigned int i;
13427 + pgd_t *pgd;
13428 +
13429 + pax_open_kernel();
13430 + pgd = get_cpu_pgd(smp_processor_id());
13431 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13432 + set_pgd_batched(pgd+i, native_make_pgd(0));
13433 + pax_close_kernel();
13434 +#endif
13435 +
13436 #ifdef CONFIG_SMP
13437 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13438 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13439 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13440 struct task_struct *tsk)
13441 {
13442 unsigned cpu = smp_processor_id();
13443 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13444 + int tlbstate = TLBSTATE_OK;
13445 +#endif
13446
13447 if (likely(prev != next)) {
13448 #ifdef CONFIG_SMP
13449 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13450 + tlbstate = this_cpu_read(cpu_tlbstate.state);
13451 +#endif
13452 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13453 this_cpu_write(cpu_tlbstate.active_mm, next);
13454 #endif
13455 cpumask_set_cpu(cpu, mm_cpumask(next));
13456
13457 /* Re-load page tables */
13458 +#ifdef CONFIG_PAX_PER_CPU_PGD
13459 + pax_open_kernel();
13460 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13461 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13462 + pax_close_kernel();
13463 + load_cr3(get_cpu_pgd(cpu));
13464 +#else
13465 load_cr3(next->pgd);
13466 +#endif
13467
13468 /* stop flush ipis for the previous mm */
13469 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13470 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13471 */
13472 if (unlikely(prev->context.ldt != next->context.ldt))
13473 load_LDT_nolock(&next->context);
13474 - }
13475 +
13476 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13477 + if (!(__supported_pte_mask & _PAGE_NX)) {
13478 + smp_mb__before_clear_bit();
13479 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13480 + smp_mb__after_clear_bit();
13481 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13482 + }
13483 +#endif
13484 +
13485 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13486 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13487 + prev->context.user_cs_limit != next->context.user_cs_limit))
13488 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13489 #ifdef CONFIG_SMP
13490 + else if (unlikely(tlbstate != TLBSTATE_OK))
13491 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13492 +#endif
13493 +#endif
13494 +
13495 + }
13496 else {
13497 +
13498 +#ifdef CONFIG_PAX_PER_CPU_PGD
13499 + pax_open_kernel();
13500 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13501 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13502 + pax_close_kernel();
13503 + load_cr3(get_cpu_pgd(cpu));
13504 +#endif
13505 +
13506 +#ifdef CONFIG_SMP
13507 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13508 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
13509
13510 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13511 * tlb flush IPI delivery. We must reload CR3
13512 * to make sure to use no freed page tables.
13513 */
13514 +
13515 +#ifndef CONFIG_PAX_PER_CPU_PGD
13516 load_cr3(next->pgd);
13517 +#endif
13518 +
13519 load_LDT_nolock(&next->context);
13520 +
13521 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
13522 + if (!(__supported_pte_mask & _PAGE_NX))
13523 + cpu_set(cpu, next->context.cpu_user_cs_mask);
13524 +#endif
13525 +
13526 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13527 +#ifdef CONFIG_PAX_PAGEEXEC
13528 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
13529 +#endif
13530 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13531 +#endif
13532 +
13533 }
13534 +#endif
13535 }
13536 -#endif
13537 }
13538
13539 #define activate_mm(prev, next) \
13540 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
13541 index e3b7819..b257c64 100644
13542 --- a/arch/x86/include/asm/module.h
13543 +++ b/arch/x86/include/asm/module.h
13544 @@ -5,6 +5,7 @@
13545
13546 #ifdef CONFIG_X86_64
13547 /* X86_64 does not define MODULE_PROC_FAMILY */
13548 +#define MODULE_PROC_FAMILY ""
13549 #elif defined CONFIG_M486
13550 #define MODULE_PROC_FAMILY "486 "
13551 #elif defined CONFIG_M586
13552 @@ -57,8 +58,20 @@
13553 #error unknown processor family
13554 #endif
13555
13556 -#ifdef CONFIG_X86_32
13557 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
13558 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13559 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
13560 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
13561 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
13562 +#else
13563 +#define MODULE_PAX_KERNEXEC ""
13564 #endif
13565
13566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13567 +#define MODULE_PAX_UDEREF "UDEREF "
13568 +#else
13569 +#define MODULE_PAX_UDEREF ""
13570 +#endif
13571 +
13572 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
13573 +
13574 #endif /* _ASM_X86_MODULE_H */
13575 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
13576 index 320f7bb..e89f8f8 100644
13577 --- a/arch/x86/include/asm/page_64_types.h
13578 +++ b/arch/x86/include/asm/page_64_types.h
13579 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
13580
13581 /* duplicated to the one in bootmem.h */
13582 extern unsigned long max_pfn;
13583 -extern unsigned long phys_base;
13584 +extern const unsigned long phys_base;
13585
13586 extern unsigned long __phys_addr(unsigned long);
13587 #define __phys_reloc_hide(x) (x)
13588 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
13589 index 5edd174..9cf5821 100644
13590 --- a/arch/x86/include/asm/paravirt.h
13591 +++ b/arch/x86/include/asm/paravirt.h
13592 @@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
13593 val);
13594 }
13595
13596 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
13597 +{
13598 + pgdval_t val = native_pgd_val(pgd);
13599 +
13600 + if (sizeof(pgdval_t) > sizeof(long))
13601 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
13602 + val, (u64)val >> 32);
13603 + else
13604 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
13605 + val);
13606 +}
13607 +
13608 static inline void pgd_clear(pgd_t *pgdp)
13609 {
13610 set_pgd(pgdp, __pgd(0));
13611 @@ -711,6 +723,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
13612 pv_mmu_ops.set_fixmap(idx, phys, flags);
13613 }
13614
13615 +#ifdef CONFIG_PAX_KERNEXEC
13616 +static inline unsigned long pax_open_kernel(void)
13617 +{
13618 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
13619 +}
13620 +
13621 +static inline unsigned long pax_close_kernel(void)
13622 +{
13623 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
13624 +}
13625 +#else
13626 +static inline unsigned long pax_open_kernel(void) { return 0; }
13627 +static inline unsigned long pax_close_kernel(void) { return 0; }
13628 +#endif
13629 +
13630 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
13631
13632 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
13633 @@ -927,7 +954,7 @@ extern void default_banner(void);
13634
13635 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
13636 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
13637 -#define PARA_INDIRECT(addr) *%cs:addr
13638 +#define PARA_INDIRECT(addr) *%ss:addr
13639 #endif
13640
13641 #define INTERRUPT_RETURN \
13642 @@ -1002,6 +1029,21 @@ extern void default_banner(void);
13643 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
13644 CLBR_NONE, \
13645 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
13646 +
13647 +#define GET_CR0_INTO_RDI \
13648 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
13649 + mov %rax,%rdi
13650 +
13651 +#define SET_RDI_INTO_CR0 \
13652 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
13653 +
13654 +#define GET_CR3_INTO_RDI \
13655 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
13656 + mov %rax,%rdi
13657 +
13658 +#define SET_RDI_INTO_CR3 \
13659 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
13660 +
13661 #endif /* CONFIG_X86_32 */
13662
13663 #endif /* __ASSEMBLY__ */
13664 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
13665 index 142236e..5446ffbc 100644
13666 --- a/arch/x86/include/asm/paravirt_types.h
13667 +++ b/arch/x86/include/asm/paravirt_types.h
13668 @@ -84,7 +84,7 @@ struct pv_init_ops {
13669 */
13670 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
13671 unsigned long addr, unsigned len);
13672 -};
13673 +} __no_const;
13674
13675
13676 struct pv_lazy_ops {
13677 @@ -97,7 +97,7 @@ struct pv_time_ops {
13678 unsigned long long (*sched_clock)(void);
13679 unsigned long long (*steal_clock)(int cpu);
13680 unsigned long (*get_tsc_khz)(void);
13681 -};
13682 +} __no_const;
13683
13684 struct pv_cpu_ops {
13685 /* hooks for various privileged instructions */
13686 @@ -191,7 +191,7 @@ struct pv_cpu_ops {
13687
13688 void (*start_context_switch)(struct task_struct *prev);
13689 void (*end_context_switch)(struct task_struct *next);
13690 -};
13691 +} __no_const;
13692
13693 struct pv_irq_ops {
13694 /*
13695 @@ -222,7 +222,7 @@ struct pv_apic_ops {
13696 unsigned long start_eip,
13697 unsigned long start_esp);
13698 #endif
13699 -};
13700 +} __no_const;
13701
13702 struct pv_mmu_ops {
13703 unsigned long (*read_cr2)(void);
13704 @@ -312,6 +312,7 @@ struct pv_mmu_ops {
13705 struct paravirt_callee_save make_pud;
13706
13707 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
13708 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
13709 #endif /* PAGETABLE_LEVELS == 4 */
13710 #endif /* PAGETABLE_LEVELS >= 3 */
13711
13712 @@ -323,6 +324,12 @@ struct pv_mmu_ops {
13713 an mfn. We can tell which is which from the index. */
13714 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
13715 phys_addr_t phys, pgprot_t flags);
13716 +
13717 +#ifdef CONFIG_PAX_KERNEXEC
13718 + unsigned long (*pax_open_kernel)(void);
13719 + unsigned long (*pax_close_kernel)(void);
13720 +#endif
13721 +
13722 };
13723
13724 struct arch_spinlock;
13725 @@ -333,7 +340,7 @@ struct pv_lock_ops {
13726 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
13727 int (*spin_trylock)(struct arch_spinlock *lock);
13728 void (*spin_unlock)(struct arch_spinlock *lock);
13729 -};
13730 +} __no_const;
13731
13732 /* This contains all the paravirt structures: we get a convenient
13733 * number for each function using the offset which we use to indicate
13734 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
13735 index b4389a4..7024269 100644
13736 --- a/arch/x86/include/asm/pgalloc.h
13737 +++ b/arch/x86/include/asm/pgalloc.h
13738 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
13739 pmd_t *pmd, pte_t *pte)
13740 {
13741 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13742 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
13743 +}
13744 +
13745 +static inline void pmd_populate_user(struct mm_struct *mm,
13746 + pmd_t *pmd, pte_t *pte)
13747 +{
13748 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
13749 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
13750 }
13751
13752 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
13753
13754 #ifdef CONFIG_X86_PAE
13755 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
13756 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
13757 +{
13758 + pud_populate(mm, pudp, pmd);
13759 +}
13760 #else /* !CONFIG_X86_PAE */
13761 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13762 {
13763 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13764 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
13765 }
13766 +
13767 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
13768 +{
13769 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
13770 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
13771 +}
13772 #endif /* CONFIG_X86_PAE */
13773
13774 #if PAGETABLE_LEVELS > 3
13775 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13776 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
13777 }
13778
13779 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
13780 +{
13781 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
13782 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
13783 +}
13784 +
13785 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
13786 {
13787 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
13788 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
13789 index f2b489c..4f7e2e5 100644
13790 --- a/arch/x86/include/asm/pgtable-2level.h
13791 +++ b/arch/x86/include/asm/pgtable-2level.h
13792 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
13793
13794 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13795 {
13796 + pax_open_kernel();
13797 *pmdp = pmd;
13798 + pax_close_kernel();
13799 }
13800
13801 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13802 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
13803 index 4cc9f2b..5fd9226 100644
13804 --- a/arch/x86/include/asm/pgtable-3level.h
13805 +++ b/arch/x86/include/asm/pgtable-3level.h
13806 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
13807
13808 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
13809 {
13810 + pax_open_kernel();
13811 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
13812 + pax_close_kernel();
13813 }
13814
13815 static inline void native_set_pud(pud_t *pudp, pud_t pud)
13816 {
13817 + pax_open_kernel();
13818 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
13819 + pax_close_kernel();
13820 }
13821
13822 /*
13823 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
13824 index 1c1a955..50f828c 100644
13825 --- a/arch/x86/include/asm/pgtable.h
13826 +++ b/arch/x86/include/asm/pgtable.h
13827 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13828
13829 #ifndef __PAGETABLE_PUD_FOLDED
13830 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
13831 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
13832 #define pgd_clear(pgd) native_pgd_clear(pgd)
13833 #endif
13834
13835 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
13836
13837 #define arch_end_context_switch(prev) do {} while(0)
13838
13839 +#define pax_open_kernel() native_pax_open_kernel()
13840 +#define pax_close_kernel() native_pax_close_kernel()
13841 #endif /* CONFIG_PARAVIRT */
13842
13843 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
13844 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
13845 +
13846 +#ifdef CONFIG_PAX_KERNEXEC
13847 +static inline unsigned long native_pax_open_kernel(void)
13848 +{
13849 + unsigned long cr0;
13850 +
13851 + preempt_disable();
13852 + barrier();
13853 + cr0 = read_cr0() ^ X86_CR0_WP;
13854 + BUG_ON(cr0 & X86_CR0_WP);
13855 + write_cr0(cr0);
13856 + return cr0 ^ X86_CR0_WP;
13857 +}
13858 +
13859 +static inline unsigned long native_pax_close_kernel(void)
13860 +{
13861 + unsigned long cr0;
13862 +
13863 + cr0 = read_cr0() ^ X86_CR0_WP;
13864 + BUG_ON(!(cr0 & X86_CR0_WP));
13865 + write_cr0(cr0);
13866 + barrier();
13867 + preempt_enable_no_resched();
13868 + return cr0 ^ X86_CR0_WP;
13869 +}
13870 +#else
13871 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
13872 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
13873 +#endif
13874 +
13875 /*
13876 * The following only work if pte_present() is true.
13877 * Undefined behaviour if not..
13878 */
13879 +static inline int pte_user(pte_t pte)
13880 +{
13881 + return pte_val(pte) & _PAGE_USER;
13882 +}
13883 +
13884 static inline int pte_dirty(pte_t pte)
13885 {
13886 return pte_flags(pte) & _PAGE_DIRTY;
13887 @@ -200,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
13888 return pte_clear_flags(pte, _PAGE_RW);
13889 }
13890
13891 +static inline pte_t pte_mkread(pte_t pte)
13892 +{
13893 + return __pte(pte_val(pte) | _PAGE_USER);
13894 +}
13895 +
13896 static inline pte_t pte_mkexec(pte_t pte)
13897 {
13898 - return pte_clear_flags(pte, _PAGE_NX);
13899 +#ifdef CONFIG_X86_PAE
13900 + if (__supported_pte_mask & _PAGE_NX)
13901 + return pte_clear_flags(pte, _PAGE_NX);
13902 + else
13903 +#endif
13904 + return pte_set_flags(pte, _PAGE_USER);
13905 +}
13906 +
13907 +static inline pte_t pte_exprotect(pte_t pte)
13908 +{
13909 +#ifdef CONFIG_X86_PAE
13910 + if (__supported_pte_mask & _PAGE_NX)
13911 + return pte_set_flags(pte, _PAGE_NX);
13912 + else
13913 +#endif
13914 + return pte_clear_flags(pte, _PAGE_USER);
13915 }
13916
13917 static inline pte_t pte_mkdirty(pte_t pte)
13918 @@ -394,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
13919 #endif
13920
13921 #ifndef __ASSEMBLY__
13922 +
13923 +#ifdef CONFIG_PAX_PER_CPU_PGD
13924 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
13925 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
13926 +{
13927 + return cpu_pgd[cpu];
13928 +}
13929 +#endif
13930 +
13931 #include <linux/mm_types.h>
13932
13933 static inline int pte_none(pte_t pte)
13934 @@ -583,7 +652,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
13935
13936 static inline int pgd_bad(pgd_t pgd)
13937 {
13938 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
13939 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
13940 }
13941
13942 static inline int pgd_none(pgd_t pgd)
13943 @@ -606,7 +675,12 @@ static inline int pgd_none(pgd_t pgd)
13944 * pgd_offset() returns a (pgd_t *)
13945 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
13946 */
13947 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
13948 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
13949 +
13950 +#ifdef CONFIG_PAX_PER_CPU_PGD
13951 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
13952 +#endif
13953 +
13954 /*
13955 * a shortcut which implies the use of the kernel's pgd, instead
13956 * of a process's
13957 @@ -617,6 +691,20 @@ static inline int pgd_none(pgd_t pgd)
13958 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
13959 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
13960
13961 +#ifdef CONFIG_X86_32
13962 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
13963 +#else
13964 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
13965 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
13966 +
13967 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13968 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
13969 +#else
13970 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
13971 +#endif
13972 +
13973 +#endif
13974 +
13975 #ifndef __ASSEMBLY__
13976
13977 extern int direct_gbpages;
13978 @@ -781,11 +869,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
13979 * dst and src can be on the same page, but the range must not overlap,
13980 * and must not cross a page boundary.
13981 */
13982 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
13983 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
13984 {
13985 - memcpy(dst, src, count * sizeof(pgd_t));
13986 + pax_open_kernel();
13987 + while (count--)
13988 + *dst++ = *src++;
13989 + pax_close_kernel();
13990 }
13991
13992 +#ifdef CONFIG_PAX_PER_CPU_PGD
13993 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
13994 +#endif
13995 +
13996 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13997 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
13998 +#else
13999 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14000 +#endif
14001
14002 #include <asm-generic/pgtable.h>
14003 #endif /* __ASSEMBLY__ */
14004 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14005 index 8faa215..a8a17ea 100644
14006 --- a/arch/x86/include/asm/pgtable_32.h
14007 +++ b/arch/x86/include/asm/pgtable_32.h
14008 @@ -25,9 +25,6 @@
14009 struct mm_struct;
14010 struct vm_area_struct;
14011
14012 -extern pgd_t swapper_pg_dir[1024];
14013 -extern pgd_t initial_page_table[1024];
14014 -
14015 static inline void pgtable_cache_init(void) { }
14016 static inline void check_pgt_cache(void) { }
14017 void paging_init(void);
14018 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14019 # include <asm/pgtable-2level.h>
14020 #endif
14021
14022 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14023 +extern pgd_t initial_page_table[PTRS_PER_PGD];
14024 +#ifdef CONFIG_X86_PAE
14025 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14026 +#endif
14027 +
14028 #if defined(CONFIG_HIGHPTE)
14029 #define pte_offset_map(dir, address) \
14030 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14031 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14032 /* Clear a kernel PTE and flush it from the TLB */
14033 #define kpte_clear_flush(ptep, vaddr) \
14034 do { \
14035 + pax_open_kernel(); \
14036 pte_clear(&init_mm, (vaddr), (ptep)); \
14037 + pax_close_kernel(); \
14038 __flush_tlb_one((vaddr)); \
14039 } while (0)
14040
14041 @@ -75,6 +80,9 @@ do { \
14042
14043 #endif /* !__ASSEMBLY__ */
14044
14045 +#define HAVE_ARCH_UNMAPPED_AREA
14046 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14047 +
14048 /*
14049 * kern_addr_valid() is (1) for FLATMEM and (0) for
14050 * SPARSEMEM and DISCONTIGMEM
14051 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14052 index ed5903b..c7fe163 100644
14053 --- a/arch/x86/include/asm/pgtable_32_types.h
14054 +++ b/arch/x86/include/asm/pgtable_32_types.h
14055 @@ -8,7 +8,7 @@
14056 */
14057 #ifdef CONFIG_X86_PAE
14058 # include <asm/pgtable-3level_types.h>
14059 -# define PMD_SIZE (1UL << PMD_SHIFT)
14060 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14061 # define PMD_MASK (~(PMD_SIZE - 1))
14062 #else
14063 # include <asm/pgtable-2level_types.h>
14064 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14065 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14066 #endif
14067
14068 +#ifdef CONFIG_PAX_KERNEXEC
14069 +#ifndef __ASSEMBLY__
14070 +extern unsigned char MODULES_EXEC_VADDR[];
14071 +extern unsigned char MODULES_EXEC_END[];
14072 +#endif
14073 +#include <asm/boot.h>
14074 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14075 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14076 +#else
14077 +#define ktla_ktva(addr) (addr)
14078 +#define ktva_ktla(addr) (addr)
14079 +#endif
14080 +
14081 #define MODULES_VADDR VMALLOC_START
14082 #define MODULES_END VMALLOC_END
14083 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14084 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14085 index 47356f9..deb94a2 100644
14086 --- a/arch/x86/include/asm/pgtable_64.h
14087 +++ b/arch/x86/include/asm/pgtable_64.h
14088 @@ -16,10 +16,14 @@
14089
14090 extern pud_t level3_kernel_pgt[512];
14091 extern pud_t level3_ident_pgt[512];
14092 +extern pud_t level3_vmalloc_start_pgt[512];
14093 +extern pud_t level3_vmalloc_end_pgt[512];
14094 +extern pud_t level3_vmemmap_pgt[512];
14095 +extern pud_t level2_vmemmap_pgt[512];
14096 extern pmd_t level2_kernel_pgt[512];
14097 extern pmd_t level2_fixmap_pgt[512];
14098 -extern pmd_t level2_ident_pgt[512];
14099 -extern pgd_t init_level4_pgt[];
14100 +extern pmd_t level2_ident_pgt[512*2];
14101 +extern pgd_t init_level4_pgt[512];
14102
14103 #define swapper_pg_dir init_level4_pgt
14104
14105 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14106
14107 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14108 {
14109 + pax_open_kernel();
14110 *pmdp = pmd;
14111 + pax_close_kernel();
14112 }
14113
14114 static inline void native_pmd_clear(pmd_t *pmd)
14115 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14116
14117 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14118 {
14119 + pax_open_kernel();
14120 *pudp = pud;
14121 + pax_close_kernel();
14122 }
14123
14124 static inline void native_pud_clear(pud_t *pud)
14125 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14126
14127 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14128 {
14129 + pax_open_kernel();
14130 + *pgdp = pgd;
14131 + pax_close_kernel();
14132 +}
14133 +
14134 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14135 +{
14136 *pgdp = pgd;
14137 }
14138
14139 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14140 index 766ea16..5b96cb3 100644
14141 --- a/arch/x86/include/asm/pgtable_64_types.h
14142 +++ b/arch/x86/include/asm/pgtable_64_types.h
14143 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
14144 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14145 #define MODULES_END _AC(0xffffffffff000000, UL)
14146 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14147 +#define MODULES_EXEC_VADDR MODULES_VADDR
14148 +#define MODULES_EXEC_END MODULES_END
14149 +
14150 +#define ktla_ktva(addr) (addr)
14151 +#define ktva_ktla(addr) (addr)
14152
14153 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
14154 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14155 index 3c32db8..1ddccf5 100644
14156 --- a/arch/x86/include/asm/pgtable_types.h
14157 +++ b/arch/x86/include/asm/pgtable_types.h
14158 @@ -16,13 +16,12 @@
14159 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14160 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14161 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14162 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14163 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14164 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14165 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14166 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14167 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14168 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14169 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14170 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14171 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14172 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14173
14174 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14175 @@ -40,7 +39,6 @@
14176 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14177 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14178 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14179 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14180 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14181 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14182 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14183 @@ -57,8 +55,10 @@
14184
14185 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14186 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14187 -#else
14188 +#elif defined(CONFIG_KMEMCHECK)
14189 #define _PAGE_NX (_AT(pteval_t, 0))
14190 +#else
14191 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14192 #endif
14193
14194 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14195 @@ -116,6 +116,9 @@
14196 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14197 _PAGE_ACCESSED)
14198
14199 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
14200 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
14201 +
14202 #define __PAGE_KERNEL_EXEC \
14203 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14204 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14205 @@ -126,7 +129,7 @@
14206 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14207 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14208 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14209 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14210 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14211 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14212 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14213 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14214 @@ -188,8 +191,8 @@
14215 * bits are combined, this will alow user to access the high address mapped
14216 * VDSO in the presence of CONFIG_COMPAT_VDSO
14217 */
14218 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14219 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14220 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14221 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14222 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14223 #endif
14224
14225 @@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14226 {
14227 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14228 }
14229 +#endif
14230
14231 +#if PAGETABLE_LEVELS == 3
14232 +#include <asm-generic/pgtable-nopud.h>
14233 +#endif
14234 +
14235 +#if PAGETABLE_LEVELS == 2
14236 +#include <asm-generic/pgtable-nopmd.h>
14237 +#endif
14238 +
14239 +#ifndef __ASSEMBLY__
14240 #if PAGETABLE_LEVELS > 3
14241 typedef struct { pudval_t pud; } pud_t;
14242
14243 @@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14244 return pud.pud;
14245 }
14246 #else
14247 -#include <asm-generic/pgtable-nopud.h>
14248 -
14249 static inline pudval_t native_pud_val(pud_t pud)
14250 {
14251 return native_pgd_val(pud.pgd);
14252 @@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14253 return pmd.pmd;
14254 }
14255 #else
14256 -#include <asm-generic/pgtable-nopmd.h>
14257 -
14258 static inline pmdval_t native_pmd_val(pmd_t pmd)
14259 {
14260 return native_pgd_val(pmd.pud.pgd);
14261 @@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14262
14263 extern pteval_t __supported_pte_mask;
14264 extern void set_nx(void);
14265 -extern int nx_enabled;
14266
14267 #define pgprot_writecombine pgprot_writecombine
14268 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14269 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14270 index 888184b..a07ac89 100644
14271 --- a/arch/x86/include/asm/processor.h
14272 +++ b/arch/x86/include/asm/processor.h
14273 @@ -287,7 +287,7 @@ struct tss_struct {
14274
14275 } ____cacheline_aligned;
14276
14277 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14278 +extern struct tss_struct init_tss[NR_CPUS];
14279
14280 /*
14281 * Save the original ist values for checking stack pointers during debugging
14282 @@ -827,11 +827,18 @@ static inline void spin_lock_prefetch(const void *x)
14283 */
14284 #define TASK_SIZE PAGE_OFFSET
14285 #define TASK_SIZE_MAX TASK_SIZE
14286 +
14287 +#ifdef CONFIG_PAX_SEGMEXEC
14288 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14289 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14290 +#else
14291 #define STACK_TOP TASK_SIZE
14292 -#define STACK_TOP_MAX STACK_TOP
14293 +#endif
14294 +
14295 +#define STACK_TOP_MAX TASK_SIZE
14296
14297 #define INIT_THREAD { \
14298 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14299 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14300 .vm86_info = NULL, \
14301 .sysenter_cs = __KERNEL_CS, \
14302 .io_bitmap_ptr = NULL, \
14303 @@ -845,7 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
14304 */
14305 #define INIT_TSS { \
14306 .x86_tss = { \
14307 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
14308 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14309 .ss0 = __KERNEL_DS, \
14310 .ss1 = __KERNEL_CS, \
14311 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14312 @@ -856,11 +863,7 @@ static inline void spin_lock_prefetch(const void *x)
14313 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14314
14315 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14316 -#define KSTK_TOP(info) \
14317 -({ \
14318 - unsigned long *__ptr = (unsigned long *)(info); \
14319 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14320 -})
14321 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14322
14323 /*
14324 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14325 @@ -875,7 +878,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14326 #define task_pt_regs(task) \
14327 ({ \
14328 struct pt_regs *__regs__; \
14329 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14330 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14331 __regs__ - 1; \
14332 })
14333
14334 @@ -885,13 +888,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14335 /*
14336 * User space process size. 47bits minus one guard page.
14337 */
14338 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14339 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14340
14341 /* This decides where the kernel will search for a free chunk of vm
14342 * space during mmap's.
14343 */
14344 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14345 - 0xc0000000 : 0xFFFFe000)
14346 + 0xc0000000 : 0xFFFFf000)
14347
14348 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14349 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14350 @@ -902,11 +905,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14351 #define STACK_TOP_MAX TASK_SIZE_MAX
14352
14353 #define INIT_THREAD { \
14354 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14355 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14356 }
14357
14358 #define INIT_TSS { \
14359 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14360 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14361 }
14362
14363 /*
14364 @@ -934,6 +937,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14365 */
14366 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14367
14368 +#ifdef CONFIG_PAX_SEGMEXEC
14369 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14370 +#endif
14371 +
14372 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14373
14374 /* Get/set a process' ability to use the timestamp counter instruction */
14375 @@ -994,12 +1001,12 @@ extern bool cpu_has_amd_erratum(const int *);
14376 #define cpu_has_amd_erratum(x) (false)
14377 #endif /* CONFIG_CPU_SUP_AMD */
14378
14379 -extern unsigned long arch_align_stack(unsigned long sp);
14380 +#define arch_align_stack(x) ((x) & ~0xfUL)
14381 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14382
14383 void default_idle(void);
14384 bool set_pm_idle_to_default(void);
14385
14386 -void stop_this_cpu(void *dummy);
14387 +void stop_this_cpu(void *dummy) __noreturn;
14388
14389 #endif /* _ASM_X86_PROCESSOR_H */
14390 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14391 index 942a086..6c26446 100644
14392 --- a/arch/x86/include/asm/ptrace.h
14393 +++ b/arch/x86/include/asm/ptrace.h
14394 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14395 }
14396
14397 /*
14398 - * user_mode_vm(regs) determines whether a register set came from user mode.
14399 + * user_mode(regs) determines whether a register set came from user mode.
14400 * This is true if V8086 mode was enabled OR if the register set was from
14401 * protected mode with RPL-3 CS value. This tricky test checks that with
14402 * one comparison. Many places in the kernel can bypass this full check
14403 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14404 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14405 + * be used.
14406 */
14407 -static inline int user_mode(struct pt_regs *regs)
14408 +static inline int user_mode_novm(struct pt_regs *regs)
14409 {
14410 #ifdef CONFIG_X86_32
14411 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14412 #else
14413 - return !!(regs->cs & 3);
14414 + return !!(regs->cs & SEGMENT_RPL_MASK);
14415 #endif
14416 }
14417
14418 -static inline int user_mode_vm(struct pt_regs *regs)
14419 +static inline int user_mode(struct pt_regs *regs)
14420 {
14421 #ifdef CONFIG_X86_32
14422 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14423 USER_RPL;
14424 #else
14425 - return user_mode(regs);
14426 + return user_mode_novm(regs);
14427 #endif
14428 }
14429
14430 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14431 #ifdef CONFIG_X86_64
14432 static inline bool user_64bit_mode(struct pt_regs *regs)
14433 {
14434 + unsigned long cs = regs->cs & 0xffff;
14435 #ifndef CONFIG_PARAVIRT
14436 /*
14437 * On non-paravirt systems, this is the only long mode CPL 3
14438 * selector. We do not allow long mode selectors in the LDT.
14439 */
14440 - return regs->cs == __USER_CS;
14441 + return cs == __USER_CS;
14442 #else
14443 /* Headers are too twisted for this to go in paravirt.h. */
14444 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
14445 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
14446 #endif
14447 }
14448
14449 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
14450 * Traps from the kernel do not save sp and ss.
14451 * Use the helper function to retrieve sp.
14452 */
14453 - if (offset == offsetof(struct pt_regs, sp) &&
14454 - regs->cs == __KERNEL_CS)
14455 - return kernel_stack_pointer(regs);
14456 + if (offset == offsetof(struct pt_regs, sp)) {
14457 + unsigned long cs = regs->cs & 0xffff;
14458 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
14459 + return kernel_stack_pointer(regs);
14460 + }
14461 #endif
14462 return *(unsigned long *)((unsigned long)regs + offset);
14463 }
14464 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
14465 index fe1ec5b..dc5c3fe 100644
14466 --- a/arch/x86/include/asm/realmode.h
14467 +++ b/arch/x86/include/asm/realmode.h
14468 @@ -22,16 +22,14 @@ struct real_mode_header {
14469 #endif
14470 /* APM/BIOS reboot */
14471 u32 machine_real_restart_asm;
14472 -#ifdef CONFIG_X86_64
14473 u32 machine_real_restart_seg;
14474 -#endif
14475 };
14476
14477 /* This must match data at trampoline_32/64.S */
14478 struct trampoline_header {
14479 #ifdef CONFIG_X86_32
14480 u32 start;
14481 - u16 gdt_pad;
14482 + u16 boot_cs;
14483 u16 gdt_limit;
14484 u32 gdt_base;
14485 #else
14486 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
14487 index a82c4f1..ac45053 100644
14488 --- a/arch/x86/include/asm/reboot.h
14489 +++ b/arch/x86/include/asm/reboot.h
14490 @@ -6,13 +6,13 @@
14491 struct pt_regs;
14492
14493 struct machine_ops {
14494 - void (*restart)(char *cmd);
14495 - void (*halt)(void);
14496 - void (*power_off)(void);
14497 + void (* __noreturn restart)(char *cmd);
14498 + void (* __noreturn halt)(void);
14499 + void (* __noreturn power_off)(void);
14500 void (*shutdown)(void);
14501 void (*crash_shutdown)(struct pt_regs *);
14502 - void (*emergency_restart)(void);
14503 -};
14504 + void (* __noreturn emergency_restart)(void);
14505 +} __no_const;
14506
14507 extern struct machine_ops machine_ops;
14508
14509 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
14510 index 2dbe4a7..ce1db00 100644
14511 --- a/arch/x86/include/asm/rwsem.h
14512 +++ b/arch/x86/include/asm/rwsem.h
14513 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
14514 {
14515 asm volatile("# beginning down_read\n\t"
14516 LOCK_PREFIX _ASM_INC "(%1)\n\t"
14517 +
14518 +#ifdef CONFIG_PAX_REFCOUNT
14519 + "jno 0f\n"
14520 + LOCK_PREFIX _ASM_DEC "(%1)\n"
14521 + "int $4\n0:\n"
14522 + _ASM_EXTABLE(0b, 0b)
14523 +#endif
14524 +
14525 /* adds 0x00000001 */
14526 " jns 1f\n"
14527 " call call_rwsem_down_read_failed\n"
14528 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
14529 "1:\n\t"
14530 " mov %1,%2\n\t"
14531 " add %3,%2\n\t"
14532 +
14533 +#ifdef CONFIG_PAX_REFCOUNT
14534 + "jno 0f\n"
14535 + "sub %3,%2\n"
14536 + "int $4\n0:\n"
14537 + _ASM_EXTABLE(0b, 0b)
14538 +#endif
14539 +
14540 " jle 2f\n\t"
14541 LOCK_PREFIX " cmpxchg %2,%0\n\t"
14542 " jnz 1b\n\t"
14543 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
14544 long tmp;
14545 asm volatile("# beginning down_write\n\t"
14546 LOCK_PREFIX " xadd %1,(%2)\n\t"
14547 +
14548 +#ifdef CONFIG_PAX_REFCOUNT
14549 + "jno 0f\n"
14550 + "mov %1,(%2)\n"
14551 + "int $4\n0:\n"
14552 + _ASM_EXTABLE(0b, 0b)
14553 +#endif
14554 +
14555 /* adds 0xffff0001, returns the old value */
14556 " test %1,%1\n\t"
14557 /* was the count 0 before? */
14558 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
14559 long tmp;
14560 asm volatile("# beginning __up_read\n\t"
14561 LOCK_PREFIX " xadd %1,(%2)\n\t"
14562 +
14563 +#ifdef CONFIG_PAX_REFCOUNT
14564 + "jno 0f\n"
14565 + "mov %1,(%2)\n"
14566 + "int $4\n0:\n"
14567 + _ASM_EXTABLE(0b, 0b)
14568 +#endif
14569 +
14570 /* subtracts 1, returns the old value */
14571 " jns 1f\n\t"
14572 " call call_rwsem_wake\n" /* expects old value in %edx */
14573 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
14574 long tmp;
14575 asm volatile("# beginning __up_write\n\t"
14576 LOCK_PREFIX " xadd %1,(%2)\n\t"
14577 +
14578 +#ifdef CONFIG_PAX_REFCOUNT
14579 + "jno 0f\n"
14580 + "mov %1,(%2)\n"
14581 + "int $4\n0:\n"
14582 + _ASM_EXTABLE(0b, 0b)
14583 +#endif
14584 +
14585 /* subtracts 0xffff0001, returns the old value */
14586 " jns 1f\n\t"
14587 " call call_rwsem_wake\n" /* expects old value in %edx */
14588 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14589 {
14590 asm volatile("# beginning __downgrade_write\n\t"
14591 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
14592 +
14593 +#ifdef CONFIG_PAX_REFCOUNT
14594 + "jno 0f\n"
14595 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
14596 + "int $4\n0:\n"
14597 + _ASM_EXTABLE(0b, 0b)
14598 +#endif
14599 +
14600 /*
14601 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
14602 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
14603 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
14604 */
14605 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14606 {
14607 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
14608 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
14609 +
14610 +#ifdef CONFIG_PAX_REFCOUNT
14611 + "jno 0f\n"
14612 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
14613 + "int $4\n0:\n"
14614 + _ASM_EXTABLE(0b, 0b)
14615 +#endif
14616 +
14617 : "+m" (sem->count)
14618 : "er" (delta));
14619 }
14620 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
14621 */
14622 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
14623 {
14624 - return delta + xadd(&sem->count, delta);
14625 + return delta + xadd_check_overflow(&sem->count, delta);
14626 }
14627
14628 #endif /* __KERNEL__ */
14629 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
14630 index c48a950..c6d7468 100644
14631 --- a/arch/x86/include/asm/segment.h
14632 +++ b/arch/x86/include/asm/segment.h
14633 @@ -64,10 +64,15 @@
14634 * 26 - ESPFIX small SS
14635 * 27 - per-cpu [ offset to per-cpu data area ]
14636 * 28 - stack_canary-20 [ for stack protector ]
14637 - * 29 - unused
14638 - * 30 - unused
14639 + * 29 - PCI BIOS CS
14640 + * 30 - PCI BIOS DS
14641 * 31 - TSS for double fault handler
14642 */
14643 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
14644 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
14645 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
14646 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
14647 +
14648 #define GDT_ENTRY_TLS_MIN 6
14649 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
14650
14651 @@ -79,6 +84,8 @@
14652
14653 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
14654
14655 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
14656 +
14657 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
14658
14659 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
14660 @@ -104,6 +111,12 @@
14661 #define __KERNEL_STACK_CANARY 0
14662 #endif
14663
14664 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
14665 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
14666 +
14667 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
14668 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
14669 +
14670 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
14671
14672 /*
14673 @@ -141,7 +154,7 @@
14674 */
14675
14676 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
14677 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
14678 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
14679
14680
14681 #else
14682 @@ -165,6 +178,8 @@
14683 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
14684 #define __USER32_DS __USER_DS
14685
14686 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
14687 +
14688 #define GDT_ENTRY_TSS 8 /* needs two entries */
14689 #define GDT_ENTRY_LDT 10 /* needs two entries */
14690 #define GDT_ENTRY_TLS_MIN 12
14691 @@ -185,6 +200,7 @@
14692 #endif
14693
14694 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
14695 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
14696 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
14697 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
14698 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
14699 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
14700 {
14701 unsigned long __limit;
14702 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
14703 - return __limit + 1;
14704 + return __limit;
14705 }
14706
14707 #endif /* !__ASSEMBLY__ */
14708 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
14709 index b073aae..39f9bdd 100644
14710 --- a/arch/x86/include/asm/smp.h
14711 +++ b/arch/x86/include/asm/smp.h
14712 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
14713 /* cpus sharing the last level cache: */
14714 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
14715 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
14716 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
14717 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
14718
14719 static inline struct cpumask *cpu_sibling_mask(int cpu)
14720 {
14721 @@ -79,7 +79,7 @@ struct smp_ops {
14722
14723 void (*send_call_func_ipi)(const struct cpumask *mask);
14724 void (*send_call_func_single_ipi)(int cpu);
14725 -};
14726 +} __no_const;
14727
14728 /* Globals due to paravirt */
14729 extern void set_cpu_sibling_map(int cpu);
14730 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
14731 extern int safe_smp_processor_id(void);
14732
14733 #elif defined(CONFIG_X86_64_SMP)
14734 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14735 -
14736 -#define stack_smp_processor_id() \
14737 -({ \
14738 - struct thread_info *ti; \
14739 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
14740 - ti->cpu; \
14741 -})
14742 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
14743 +#define stack_smp_processor_id() raw_smp_processor_id()
14744 #define safe_smp_processor_id() smp_processor_id()
14745
14746 #endif
14747 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
14748 index 33692ea..350a534 100644
14749 --- a/arch/x86/include/asm/spinlock.h
14750 +++ b/arch/x86/include/asm/spinlock.h
14751 @@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
14752 static inline void arch_read_lock(arch_rwlock_t *rw)
14753 {
14754 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
14755 +
14756 +#ifdef CONFIG_PAX_REFCOUNT
14757 + "jno 0f\n"
14758 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
14759 + "int $4\n0:\n"
14760 + _ASM_EXTABLE(0b, 0b)
14761 +#endif
14762 +
14763 "jns 1f\n"
14764 "call __read_lock_failed\n\t"
14765 "1:\n"
14766 @@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
14767 static inline void arch_write_lock(arch_rwlock_t *rw)
14768 {
14769 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
14770 +
14771 +#ifdef CONFIG_PAX_REFCOUNT
14772 + "jno 0f\n"
14773 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
14774 + "int $4\n0:\n"
14775 + _ASM_EXTABLE(0b, 0b)
14776 +#endif
14777 +
14778 "jz 1f\n"
14779 "call __write_lock_failed\n\t"
14780 "1:\n"
14781 @@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
14782
14783 static inline void arch_read_unlock(arch_rwlock_t *rw)
14784 {
14785 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
14786 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
14787 +
14788 +#ifdef CONFIG_PAX_REFCOUNT
14789 + "jno 0f\n"
14790 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
14791 + "int $4\n0:\n"
14792 + _ASM_EXTABLE(0b, 0b)
14793 +#endif
14794 +
14795 :"+m" (rw->lock) : : "memory");
14796 }
14797
14798 static inline void arch_write_unlock(arch_rwlock_t *rw)
14799 {
14800 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
14801 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
14802 +
14803 +#ifdef CONFIG_PAX_REFCOUNT
14804 + "jno 0f\n"
14805 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
14806 + "int $4\n0:\n"
14807 + _ASM_EXTABLE(0b, 0b)
14808 +#endif
14809 +
14810 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
14811 }
14812
14813 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
14814 index 6a99859..03cb807 100644
14815 --- a/arch/x86/include/asm/stackprotector.h
14816 +++ b/arch/x86/include/asm/stackprotector.h
14817 @@ -47,7 +47,7 @@
14818 * head_32 for boot CPU and setup_per_cpu_areas() for others.
14819 */
14820 #define GDT_STACK_CANARY_INIT \
14821 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
14822 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
14823
14824 /*
14825 * Initialize the stackprotector canary value.
14826 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
14827
14828 static inline void load_stack_canary_segment(void)
14829 {
14830 -#ifdef CONFIG_X86_32
14831 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
14832 asm volatile ("mov %0, %%gs" : : "r" (0));
14833 #endif
14834 }
14835 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
14836 index 70bbe39..4ae2bd4 100644
14837 --- a/arch/x86/include/asm/stacktrace.h
14838 +++ b/arch/x86/include/asm/stacktrace.h
14839 @@ -11,28 +11,20 @@
14840
14841 extern int kstack_depth_to_print;
14842
14843 -struct thread_info;
14844 +struct task_struct;
14845 struct stacktrace_ops;
14846
14847 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
14848 - unsigned long *stack,
14849 - unsigned long bp,
14850 - const struct stacktrace_ops *ops,
14851 - void *data,
14852 - unsigned long *end,
14853 - int *graph);
14854 +typedef unsigned long walk_stack_t(struct task_struct *task,
14855 + void *stack_start,
14856 + unsigned long *stack,
14857 + unsigned long bp,
14858 + const struct stacktrace_ops *ops,
14859 + void *data,
14860 + unsigned long *end,
14861 + int *graph);
14862
14863 -extern unsigned long
14864 -print_context_stack(struct thread_info *tinfo,
14865 - unsigned long *stack, unsigned long bp,
14866 - const struct stacktrace_ops *ops, void *data,
14867 - unsigned long *end, int *graph);
14868 -
14869 -extern unsigned long
14870 -print_context_stack_bp(struct thread_info *tinfo,
14871 - unsigned long *stack, unsigned long bp,
14872 - const struct stacktrace_ops *ops, void *data,
14873 - unsigned long *end, int *graph);
14874 +extern walk_stack_t print_context_stack;
14875 +extern walk_stack_t print_context_stack_bp;
14876
14877 /* Generic stack tracer with callbacks */
14878
14879 @@ -40,7 +32,7 @@ struct stacktrace_ops {
14880 void (*address)(void *data, unsigned long address, int reliable);
14881 /* On negative return stop dumping */
14882 int (*stack)(void *data, char *name);
14883 - walk_stack_t walk_stack;
14884 + walk_stack_t *walk_stack;
14885 };
14886
14887 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
14888 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
14889 index 4ec45b3..a4f0a8a 100644
14890 --- a/arch/x86/include/asm/switch_to.h
14891 +++ b/arch/x86/include/asm/switch_to.h
14892 @@ -108,7 +108,7 @@ do { \
14893 "call __switch_to\n\t" \
14894 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
14895 __switch_canary \
14896 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
14897 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
14898 "movq %%rax,%%rdi\n\t" \
14899 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
14900 "jnz ret_from_fork\n\t" \
14901 @@ -119,7 +119,7 @@ do { \
14902 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
14903 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
14904 [_tif_fork] "i" (_TIF_FORK), \
14905 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
14906 + [thread_info] "m" (current_tinfo), \
14907 [current_task] "m" (current_task) \
14908 __switch_canary_iparam \
14909 : "memory", "cc" __EXTRA_CLOBBER)
14910 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
14911 index 2d946e6..e453ec4 100644
14912 --- a/arch/x86/include/asm/thread_info.h
14913 +++ b/arch/x86/include/asm/thread_info.h
14914 @@ -10,6 +10,7 @@
14915 #include <linux/compiler.h>
14916 #include <asm/page.h>
14917 #include <asm/types.h>
14918 +#include <asm/percpu.h>
14919
14920 /*
14921 * low level task data that entry.S needs immediate access to
14922 @@ -24,7 +25,6 @@ struct exec_domain;
14923 #include <linux/atomic.h>
14924
14925 struct thread_info {
14926 - struct task_struct *task; /* main task structure */
14927 struct exec_domain *exec_domain; /* execution domain */
14928 __u32 flags; /* low level flags */
14929 __u32 status; /* thread synchronous flags */
14930 @@ -34,19 +34,13 @@ struct thread_info {
14931 mm_segment_t addr_limit;
14932 struct restart_block restart_block;
14933 void __user *sysenter_return;
14934 -#ifdef CONFIG_X86_32
14935 - unsigned long previous_esp; /* ESP of the previous stack in
14936 - case of nested (IRQ) stacks
14937 - */
14938 - __u8 supervisor_stack[0];
14939 -#endif
14940 + unsigned long lowest_stack;
14941 unsigned int sig_on_uaccess_error:1;
14942 unsigned int uaccess_err:1; /* uaccess failed */
14943 };
14944
14945 -#define INIT_THREAD_INFO(tsk) \
14946 +#define INIT_THREAD_INFO \
14947 { \
14948 - .task = &tsk, \
14949 .exec_domain = &default_exec_domain, \
14950 .flags = 0, \
14951 .cpu = 0, \
14952 @@ -57,7 +51,7 @@ struct thread_info {
14953 }, \
14954 }
14955
14956 -#define init_thread_info (init_thread_union.thread_info)
14957 +#define init_thread_info (init_thread_union.stack)
14958 #define init_stack (init_thread_union.stack)
14959
14960 #else /* !__ASSEMBLY__ */
14961 @@ -98,6 +92,7 @@ struct thread_info {
14962 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
14963 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
14964 #define TIF_X32 30 /* 32-bit native x86-64 binary */
14965 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
14966
14967 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
14968 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
14969 @@ -122,17 +117,18 @@ struct thread_info {
14970 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
14971 #define _TIF_ADDR32 (1 << TIF_ADDR32)
14972 #define _TIF_X32 (1 << TIF_X32)
14973 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
14974
14975 /* work to do in syscall_trace_enter() */
14976 #define _TIF_WORK_SYSCALL_ENTRY \
14977 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
14978 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
14979 - _TIF_NOHZ)
14980 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
14981
14982 /* work to do in syscall_trace_leave() */
14983 #define _TIF_WORK_SYSCALL_EXIT \
14984 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
14985 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
14986 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
14987
14988 /* work to do on interrupt/exception return */
14989 #define _TIF_WORK_MASK \
14990 @@ -143,7 +139,7 @@ struct thread_info {
14991 /* work to do on any return to user space */
14992 #define _TIF_ALLWORK_MASK \
14993 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
14994 - _TIF_NOHZ)
14995 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
14996
14997 /* Only used for 64 bit */
14998 #define _TIF_DO_NOTIFY_MASK \
14999 @@ -159,45 +155,40 @@ struct thread_info {
15000
15001 #define PREEMPT_ACTIVE 0x10000000
15002
15003 -#ifdef CONFIG_X86_32
15004 -
15005 -#define STACK_WARN (THREAD_SIZE/8)
15006 -/*
15007 - * macros/functions for gaining access to the thread information structure
15008 - *
15009 - * preempt_count needs to be 1 initially, until the scheduler is functional.
15010 - */
15011 -#ifndef __ASSEMBLY__
15012 -
15013 -
15014 -/* how to get the current stack pointer from C */
15015 -register unsigned long current_stack_pointer asm("esp") __used;
15016 -
15017 -/* how to get the thread information struct from C */
15018 -static inline struct thread_info *current_thread_info(void)
15019 -{
15020 - return (struct thread_info *)
15021 - (current_stack_pointer & ~(THREAD_SIZE - 1));
15022 -}
15023 -
15024 -#else /* !__ASSEMBLY__ */
15025 -
15026 +#ifdef __ASSEMBLY__
15027 /* how to get the thread information struct from ASM */
15028 #define GET_THREAD_INFO(reg) \
15029 - movl $-THREAD_SIZE, reg; \
15030 - andl %esp, reg
15031 + mov PER_CPU_VAR(current_tinfo), reg
15032
15033 /* use this one if reg already contains %esp */
15034 -#define GET_THREAD_INFO_WITH_ESP(reg) \
15035 - andl $-THREAD_SIZE, reg
15036 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15037 +#else
15038 +/* how to get the thread information struct from C */
15039 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15040 +
15041 +static __always_inline struct thread_info *current_thread_info(void)
15042 +{
15043 + return this_cpu_read_stable(current_tinfo);
15044 +}
15045 +#endif
15046 +
15047 +#ifdef CONFIG_X86_32
15048 +
15049 +#define STACK_WARN (THREAD_SIZE/8)
15050 +/*
15051 + * macros/functions for gaining access to the thread information structure
15052 + *
15053 + * preempt_count needs to be 1 initially, until the scheduler is functional.
15054 + */
15055 +#ifndef __ASSEMBLY__
15056 +
15057 +/* how to get the current stack pointer from C */
15058 +register unsigned long current_stack_pointer asm("esp") __used;
15059
15060 #endif
15061
15062 #else /* X86_32 */
15063
15064 -#include <asm/percpu.h>
15065 -#define KERNEL_STACK_OFFSET (5*8)
15066 -
15067 /*
15068 * macros/functions for gaining access to the thread information structure
15069 * preempt_count needs to be 1 initially, until the scheduler is functional.
15070 @@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
15071 #ifndef __ASSEMBLY__
15072 DECLARE_PER_CPU(unsigned long, kernel_stack);
15073
15074 -static inline struct thread_info *current_thread_info(void)
15075 -{
15076 - struct thread_info *ti;
15077 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
15078 - KERNEL_STACK_OFFSET - THREAD_SIZE);
15079 - return ti;
15080 -}
15081 -
15082 -#else /* !__ASSEMBLY__ */
15083 -
15084 -/* how to get the thread information struct from ASM */
15085 -#define GET_THREAD_INFO(reg) \
15086 - movq PER_CPU_VAR(kernel_stack),reg ; \
15087 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15088 -
15089 -/*
15090 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15091 - * a certain register (to be used in assembler memory operands).
15092 - */
15093 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15094 -
15095 +/* how to get the current stack pointer from C */
15096 +register unsigned long current_stack_pointer asm("rsp") __used;
15097 #endif
15098
15099 #endif /* !X86_32 */
15100 @@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
15101 extern void arch_task_cache_init(void);
15102 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15103 extern void arch_release_task_struct(struct task_struct *tsk);
15104 +
15105 +#define __HAVE_THREAD_FUNCTIONS
15106 +#define task_thread_info(task) (&(task)->tinfo)
15107 +#define task_stack_page(task) ((task)->stack)
15108 +#define setup_thread_stack(p, org) do {} while (0)
15109 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15110 +
15111 #endif
15112 #endif /* _ASM_X86_THREAD_INFO_H */
15113 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15114 index 1709801..0a60f2f 100644
15115 --- a/arch/x86/include/asm/uaccess.h
15116 +++ b/arch/x86/include/asm/uaccess.h
15117 @@ -7,6 +7,7 @@
15118 #include <linux/compiler.h>
15119 #include <linux/thread_info.h>
15120 #include <linux/string.h>
15121 +#include <linux/sched.h>
15122 #include <asm/asm.h>
15123 #include <asm/page.h>
15124 #include <asm/smap.h>
15125 @@ -29,7 +30,12 @@
15126
15127 #define get_ds() (KERNEL_DS)
15128 #define get_fs() (current_thread_info()->addr_limit)
15129 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15130 +void __set_fs(mm_segment_t x);
15131 +void set_fs(mm_segment_t x);
15132 +#else
15133 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15134 +#endif
15135
15136 #define segment_eq(a, b) ((a).seg == (b).seg)
15137
15138 @@ -77,8 +83,33 @@
15139 * checks that the pointer is in the user space range - after calling
15140 * this function, memory access functions may still return -EFAULT.
15141 */
15142 -#define access_ok(type, addr, size) \
15143 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15144 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15145 +#define access_ok(type, addr, size) \
15146 +({ \
15147 + long __size = size; \
15148 + unsigned long __addr = (unsigned long)addr; \
15149 + unsigned long __addr_ao = __addr & PAGE_MASK; \
15150 + unsigned long __end_ao = __addr + __size - 1; \
15151 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15152 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15153 + while(__addr_ao <= __end_ao) { \
15154 + char __c_ao; \
15155 + __addr_ao += PAGE_SIZE; \
15156 + if (__size > PAGE_SIZE) \
15157 + cond_resched(); \
15158 + if (__get_user(__c_ao, (char __user *)__addr)) \
15159 + break; \
15160 + if (type != VERIFY_WRITE) { \
15161 + __addr = __addr_ao; \
15162 + continue; \
15163 + } \
15164 + if (__put_user(__c_ao, (char __user *)__addr)) \
15165 + break; \
15166 + __addr = __addr_ao; \
15167 + } \
15168 + } \
15169 + __ret_ao; \
15170 +})
15171
15172 /*
15173 * The exception table consists of pairs of addresses relative to the
15174 @@ -189,13 +220,21 @@ extern int __get_user_bad(void);
15175 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15176 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15177
15178 -
15179 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15180 +#define __copyuser_seg "gs;"
15181 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15182 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15183 +#else
15184 +#define __copyuser_seg
15185 +#define __COPYUSER_SET_ES
15186 +#define __COPYUSER_RESTORE_ES
15187 +#endif
15188
15189 #ifdef CONFIG_X86_32
15190 #define __put_user_asm_u64(x, addr, err, errret) \
15191 asm volatile(ASM_STAC "\n" \
15192 - "1: movl %%eax,0(%2)\n" \
15193 - "2: movl %%edx,4(%2)\n" \
15194 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15195 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15196 "3: " ASM_CLAC "\n" \
15197 ".section .fixup,\"ax\"\n" \
15198 "4: movl %3,%0\n" \
15199 @@ -208,8 +247,8 @@ extern int __get_user_bad(void);
15200
15201 #define __put_user_asm_ex_u64(x, addr) \
15202 asm volatile(ASM_STAC "\n" \
15203 - "1: movl %%eax,0(%1)\n" \
15204 - "2: movl %%edx,4(%1)\n" \
15205 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15206 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15207 "3: " ASM_CLAC "\n" \
15208 _ASM_EXTABLE_EX(1b, 2b) \
15209 _ASM_EXTABLE_EX(2b, 3b) \
15210 @@ -259,7 +298,7 @@ extern void __put_user_8(void);
15211 __typeof__(*(ptr)) __pu_val; \
15212 __chk_user_ptr(ptr); \
15213 might_fault(); \
15214 - __pu_val = x; \
15215 + __pu_val = (x); \
15216 switch (sizeof(*(ptr))) { \
15217 case 1: \
15218 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15219 @@ -358,7 +397,7 @@ do { \
15220
15221 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15222 asm volatile(ASM_STAC "\n" \
15223 - "1: mov"itype" %2,%"rtype"1\n" \
15224 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15225 "2: " ASM_CLAC "\n" \
15226 ".section .fixup,\"ax\"\n" \
15227 "3: mov %3,%0\n" \
15228 @@ -366,7 +405,7 @@ do { \
15229 " jmp 2b\n" \
15230 ".previous\n" \
15231 _ASM_EXTABLE(1b, 3b) \
15232 - : "=r" (err), ltype(x) \
15233 + : "=r" (err), ltype (x) \
15234 : "m" (__m(addr)), "i" (errret), "0" (err))
15235
15236 #define __get_user_size_ex(x, ptr, size) \
15237 @@ -391,7 +430,7 @@ do { \
15238 } while (0)
15239
15240 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15241 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15242 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15243 "2:\n" \
15244 _ASM_EXTABLE_EX(1b, 2b) \
15245 : ltype(x) : "m" (__m(addr)))
15246 @@ -408,13 +447,24 @@ do { \
15247 int __gu_err; \
15248 unsigned long __gu_val; \
15249 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15250 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
15251 + (x) = (__typeof__(*(ptr)))__gu_val; \
15252 __gu_err; \
15253 })
15254
15255 /* FIXME: this hack is definitely wrong -AK */
15256 struct __large_struct { unsigned long buf[100]; };
15257 -#define __m(x) (*(struct __large_struct __user *)(x))
15258 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15259 +#define ____m(x) \
15260 +({ \
15261 + unsigned long ____x = (unsigned long)(x); \
15262 + if (____x < PAX_USER_SHADOW_BASE) \
15263 + ____x += PAX_USER_SHADOW_BASE; \
15264 + (void __user *)____x; \
15265 +})
15266 +#else
15267 +#define ____m(x) (x)
15268 +#endif
15269 +#define __m(x) (*(struct __large_struct __user *)____m(x))
15270
15271 /*
15272 * Tell gcc we read from memory instead of writing: this is because
15273 @@ -423,7 +473,7 @@ struct __large_struct { unsigned long buf[100]; };
15274 */
15275 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15276 asm volatile(ASM_STAC "\n" \
15277 - "1: mov"itype" %"rtype"1,%2\n" \
15278 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15279 "2: " ASM_CLAC "\n" \
15280 ".section .fixup,\"ax\"\n" \
15281 "3: mov %3,%0\n" \
15282 @@ -431,10 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
15283 ".previous\n" \
15284 _ASM_EXTABLE(1b, 3b) \
15285 : "=r"(err) \
15286 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15287 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15288
15289 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15290 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15291 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15292 "2:\n" \
15293 _ASM_EXTABLE_EX(1b, 2b) \
15294 : : ltype(x), "m" (__m(addr)))
15295 @@ -473,8 +523,12 @@ struct __large_struct { unsigned long buf[100]; };
15296 * On error, the variable @x is set to zero.
15297 */
15298
15299 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15300 +#define __get_user(x, ptr) get_user((x), (ptr))
15301 +#else
15302 #define __get_user(x, ptr) \
15303 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15304 +#endif
15305
15306 /**
15307 * __put_user: - Write a simple value into user space, with less checking.
15308 @@ -496,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
15309 * Returns zero on success, or -EFAULT on error.
15310 */
15311
15312 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15313 +#define __put_user(x, ptr) put_user((x), (ptr))
15314 +#else
15315 #define __put_user(x, ptr) \
15316 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15317 +#endif
15318
15319 #define __get_user_unaligned __get_user
15320 #define __put_user_unaligned __put_user
15321 @@ -515,7 +573,7 @@ struct __large_struct { unsigned long buf[100]; };
15322 #define get_user_ex(x, ptr) do { \
15323 unsigned long __gue_val; \
15324 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15325 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
15326 + (x) = (__typeof__(*(ptr)))__gue_val; \
15327 } while (0)
15328
15329 #define put_user_try uaccess_try
15330 @@ -532,8 +590,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15331 extern __must_check long strlen_user(const char __user *str);
15332 extern __must_check long strnlen_user(const char __user *str, long n);
15333
15334 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15335 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15336 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15337 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15338
15339 /*
15340 * movsl can be slow when source and dest are not both 8-byte aligned
15341 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15342 index 7f760a9..04b1c65 100644
15343 --- a/arch/x86/include/asm/uaccess_32.h
15344 +++ b/arch/x86/include/asm/uaccess_32.h
15345 @@ -11,15 +11,15 @@
15346 #include <asm/page.h>
15347
15348 unsigned long __must_check __copy_to_user_ll
15349 - (void __user *to, const void *from, unsigned long n);
15350 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15351 unsigned long __must_check __copy_from_user_ll
15352 - (void *to, const void __user *from, unsigned long n);
15353 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15354 unsigned long __must_check __copy_from_user_ll_nozero
15355 - (void *to, const void __user *from, unsigned long n);
15356 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15357 unsigned long __must_check __copy_from_user_ll_nocache
15358 - (void *to, const void __user *from, unsigned long n);
15359 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15360 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15361 - (void *to, const void __user *from, unsigned long n);
15362 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15363
15364 /**
15365 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15366 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15367 static __always_inline unsigned long __must_check
15368 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15369 {
15370 + if ((long)n < 0)
15371 + return n;
15372 +
15373 + check_object_size(from, n, true);
15374 +
15375 if (__builtin_constant_p(n)) {
15376 unsigned long ret;
15377
15378 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15379 __copy_to_user(void __user *to, const void *from, unsigned long n)
15380 {
15381 might_fault();
15382 +
15383 return __copy_to_user_inatomic(to, from, n);
15384 }
15385
15386 static __always_inline unsigned long
15387 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15388 {
15389 + if ((long)n < 0)
15390 + return n;
15391 +
15392 /* Avoid zeroing the tail if the copy fails..
15393 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15394 * but as the zeroing behaviour is only significant when n is not
15395 @@ -137,6 +146,12 @@ static __always_inline unsigned long
15396 __copy_from_user(void *to, const void __user *from, unsigned long n)
15397 {
15398 might_fault();
15399 +
15400 + if ((long)n < 0)
15401 + return n;
15402 +
15403 + check_object_size(to, n, false);
15404 +
15405 if (__builtin_constant_p(n)) {
15406 unsigned long ret;
15407
15408 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15409 const void __user *from, unsigned long n)
15410 {
15411 might_fault();
15412 +
15413 + if ((long)n < 0)
15414 + return n;
15415 +
15416 if (__builtin_constant_p(n)) {
15417 unsigned long ret;
15418
15419 @@ -181,15 +200,19 @@ static __always_inline unsigned long
15420 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15421 unsigned long n)
15422 {
15423 - return __copy_from_user_ll_nocache_nozero(to, from, n);
15424 + if ((long)n < 0)
15425 + return n;
15426 +
15427 + return __copy_from_user_ll_nocache_nozero(to, from, n);
15428 }
15429
15430 -unsigned long __must_check copy_to_user(void __user *to,
15431 - const void *from, unsigned long n);
15432 -unsigned long __must_check _copy_from_user(void *to,
15433 - const void __user *from,
15434 - unsigned long n);
15435 -
15436 +extern void copy_to_user_overflow(void)
15437 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15438 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15439 +#else
15440 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15441 +#endif
15442 +;
15443
15444 extern void copy_from_user_overflow(void)
15445 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15446 @@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
15447 #endif
15448 ;
15449
15450 -static inline unsigned long __must_check copy_from_user(void *to,
15451 - const void __user *from,
15452 - unsigned long n)
15453 +/**
15454 + * copy_to_user: - Copy a block of data into user space.
15455 + * @to: Destination address, in user space.
15456 + * @from: Source address, in kernel space.
15457 + * @n: Number of bytes to copy.
15458 + *
15459 + * Context: User context only. This function may sleep.
15460 + *
15461 + * Copy data from kernel space to user space.
15462 + *
15463 + * Returns number of bytes that could not be copied.
15464 + * On success, this will be zero.
15465 + */
15466 +static inline unsigned long __must_check
15467 +copy_to_user(void __user *to, const void *from, unsigned long n)
15468 {
15469 - int sz = __compiletime_object_size(to);
15470 + size_t sz = __compiletime_object_size(from);
15471
15472 - if (likely(sz == -1 || sz >= n))
15473 - n = _copy_from_user(to, from, n);
15474 - else
15475 + if (unlikely(sz != (size_t)-1 && sz < n))
15476 + copy_to_user_overflow();
15477 + else if (access_ok(VERIFY_WRITE, to, n))
15478 + n = __copy_to_user(to, from, n);
15479 + return n;
15480 +}
15481 +
15482 +/**
15483 + * copy_from_user: - Copy a block of data from user space.
15484 + * @to: Destination address, in kernel space.
15485 + * @from: Source address, in user space.
15486 + * @n: Number of bytes to copy.
15487 + *
15488 + * Context: User context only. This function may sleep.
15489 + *
15490 + * Copy data from user space to kernel space.
15491 + *
15492 + * Returns number of bytes that could not be copied.
15493 + * On success, this will be zero.
15494 + *
15495 + * If some data could not be copied, this function will pad the copied
15496 + * data to the requested size using zero bytes.
15497 + */
15498 +static inline unsigned long __must_check
15499 +copy_from_user(void *to, const void __user *from, unsigned long n)
15500 +{
15501 + size_t sz = __compiletime_object_size(to);
15502 +
15503 + check_object_size(to, n, false);
15504 +
15505 + if (unlikely(sz != (size_t)-1 && sz < n))
15506 copy_from_user_overflow();
15507 -
15508 + else if (access_ok(VERIFY_READ, from, n))
15509 + n = __copy_from_user(to, from, n);
15510 + else if ((long)n > 0)
15511 + memset(to, 0, n);
15512 return n;
15513 }
15514
15515 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
15516 index 142810c..747941a 100644
15517 --- a/arch/x86/include/asm/uaccess_64.h
15518 +++ b/arch/x86/include/asm/uaccess_64.h
15519 @@ -10,6 +10,9 @@
15520 #include <asm/alternative.h>
15521 #include <asm/cpufeature.h>
15522 #include <asm/page.h>
15523 +#include <asm/pgtable.h>
15524 +
15525 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
15526
15527 /*
15528 * Copy To/From Userspace
15529 @@ -17,13 +20,13 @@
15530
15531 /* Handles exceptions in both to and from, but doesn't do access_ok */
15532 __must_check unsigned long
15533 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
15534 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
15535 __must_check unsigned long
15536 -copy_user_generic_string(void *to, const void *from, unsigned len);
15537 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
15538 __must_check unsigned long
15539 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
15540 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
15541
15542 -static __always_inline __must_check unsigned long
15543 +static __always_inline __must_check __size_overflow(3) unsigned long
15544 copy_user_generic(void *to, const void *from, unsigned len)
15545 {
15546 unsigned ret;
15547 @@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
15548 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
15549 "=d" (len)),
15550 "1" (to), "2" (from), "3" (len)
15551 - : "memory", "rcx", "r8", "r9", "r10", "r11");
15552 + : "memory", "rcx", "r8", "r9", "r11");
15553 return ret;
15554 }
15555
15556 +static __always_inline __must_check unsigned long
15557 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
15558 +static __always_inline __must_check unsigned long
15559 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
15560 __must_check unsigned long
15561 -_copy_to_user(void __user *to, const void *from, unsigned len);
15562 -__must_check unsigned long
15563 -_copy_from_user(void *to, const void __user *from, unsigned len);
15564 -__must_check unsigned long
15565 -copy_in_user(void __user *to, const void __user *from, unsigned len);
15566 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
15567 +
15568 +extern void copy_to_user_overflow(void)
15569 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15570 + __compiletime_error("copy_to_user() buffer size is not provably correct")
15571 +#else
15572 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
15573 +#endif
15574 +;
15575 +
15576 +extern void copy_from_user_overflow(void)
15577 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
15578 + __compiletime_error("copy_from_user() buffer size is not provably correct")
15579 +#else
15580 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
15581 +#endif
15582 +;
15583
15584 static inline unsigned long __must_check copy_from_user(void *to,
15585 const void __user *from,
15586 unsigned long n)
15587 {
15588 - int sz = __compiletime_object_size(to);
15589 -
15590 might_fault();
15591 - if (likely(sz == -1 || sz >= n))
15592 - n = _copy_from_user(to, from, n);
15593 -#ifdef CONFIG_DEBUG_VM
15594 - else
15595 - WARN(1, "Buffer overflow detected!\n");
15596 -#endif
15597 +
15598 + check_object_size(to, n, false);
15599 +
15600 + if (access_ok(VERIFY_READ, from, n))
15601 + n = __copy_from_user(to, from, n);
15602 + else if (n < INT_MAX)
15603 + memset(to, 0, n);
15604 return n;
15605 }
15606
15607 static __always_inline __must_check
15608 -int copy_to_user(void __user *dst, const void *src, unsigned size)
15609 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
15610 {
15611 might_fault();
15612
15613 - return _copy_to_user(dst, src, size);
15614 + if (access_ok(VERIFY_WRITE, dst, size))
15615 + size = __copy_to_user(dst, src, size);
15616 + return size;
15617 }
15618
15619 static __always_inline __must_check
15620 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
15621 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
15622 {
15623 - int ret = 0;
15624 + size_t sz = __compiletime_object_size(dst);
15625 + unsigned ret = 0;
15626
15627 might_fault();
15628 +
15629 + if (size > INT_MAX)
15630 + return size;
15631 +
15632 + check_object_size(dst, size, false);
15633 +
15634 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15635 + if (!__access_ok(VERIFY_READ, src, size))
15636 + return size;
15637 +#endif
15638 +
15639 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15640 + copy_from_user_overflow();
15641 + return size;
15642 + }
15643 +
15644 if (!__builtin_constant_p(size))
15645 - return copy_user_generic(dst, (__force void *)src, size);
15646 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15647 switch (size) {
15648 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
15649 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
15650 ret, "b", "b", "=q", 1);
15651 return ret;
15652 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
15653 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
15654 ret, "w", "w", "=r", 2);
15655 return ret;
15656 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
15657 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
15658 ret, "l", "k", "=r", 4);
15659 return ret;
15660 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
15661 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15662 ret, "q", "", "=r", 8);
15663 return ret;
15664 case 10:
15665 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15666 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15667 ret, "q", "", "=r", 10);
15668 if (unlikely(ret))
15669 return ret;
15670 __get_user_asm(*(u16 *)(8 + (char *)dst),
15671 - (u16 __user *)(8 + (char __user *)src),
15672 + (const u16 __user *)(8 + (const char __user *)src),
15673 ret, "w", "w", "=r", 2);
15674 return ret;
15675 case 16:
15676 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
15677 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
15678 ret, "q", "", "=r", 16);
15679 if (unlikely(ret))
15680 return ret;
15681 __get_user_asm(*(u64 *)(8 + (char *)dst),
15682 - (u64 __user *)(8 + (char __user *)src),
15683 + (const u64 __user *)(8 + (const char __user *)src),
15684 ret, "q", "", "=r", 8);
15685 return ret;
15686 default:
15687 - return copy_user_generic(dst, (__force void *)src, size);
15688 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15689 }
15690 }
15691
15692 static __always_inline __must_check
15693 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
15694 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
15695 {
15696 - int ret = 0;
15697 + size_t sz = __compiletime_object_size(src);
15698 + unsigned ret = 0;
15699
15700 might_fault();
15701 +
15702 + if (size > INT_MAX)
15703 + return size;
15704 +
15705 + check_object_size(src, size, true);
15706 +
15707 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15708 + if (!__access_ok(VERIFY_WRITE, dst, size))
15709 + return size;
15710 +#endif
15711 +
15712 + if (unlikely(sz != (size_t)-1 && sz < size)) {
15713 + copy_to_user_overflow();
15714 + return size;
15715 + }
15716 +
15717 if (!__builtin_constant_p(size))
15718 - return copy_user_generic((__force void *)dst, src, size);
15719 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15720 switch (size) {
15721 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
15722 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
15723 ret, "b", "b", "iq", 1);
15724 return ret;
15725 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
15726 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
15727 ret, "w", "w", "ir", 2);
15728 return ret;
15729 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
15730 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
15731 ret, "l", "k", "ir", 4);
15732 return ret;
15733 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
15734 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15735 ret, "q", "", "er", 8);
15736 return ret;
15737 case 10:
15738 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15739 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15740 ret, "q", "", "er", 10);
15741 if (unlikely(ret))
15742 return ret;
15743 asm("":::"memory");
15744 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
15745 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
15746 ret, "w", "w", "ir", 2);
15747 return ret;
15748 case 16:
15749 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
15750 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
15751 ret, "q", "", "er", 16);
15752 if (unlikely(ret))
15753 return ret;
15754 asm("":::"memory");
15755 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
15756 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
15757 ret, "q", "", "er", 8);
15758 return ret;
15759 default:
15760 - return copy_user_generic((__force void *)dst, src, size);
15761 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15762 }
15763 }
15764
15765 static __always_inline __must_check
15766 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15767 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
15768 {
15769 - int ret = 0;
15770 + unsigned ret = 0;
15771
15772 might_fault();
15773 +
15774 + if (size > INT_MAX)
15775 + return size;
15776 +
15777 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15778 + if (!__access_ok(VERIFY_READ, src, size))
15779 + return size;
15780 + if (!__access_ok(VERIFY_WRITE, dst, size))
15781 + return size;
15782 +#endif
15783 +
15784 if (!__builtin_constant_p(size))
15785 - return copy_user_generic((__force void *)dst,
15786 - (__force void *)src, size);
15787 + return copy_user_generic((__force_kernel void *)____m(dst),
15788 + (__force_kernel const void *)____m(src), size);
15789 switch (size) {
15790 case 1: {
15791 u8 tmp;
15792 - __get_user_asm(tmp, (u8 __user *)src,
15793 + __get_user_asm(tmp, (const u8 __user *)src,
15794 ret, "b", "b", "=q", 1);
15795 if (likely(!ret))
15796 __put_user_asm(tmp, (u8 __user *)dst,
15797 @@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15798 }
15799 case 2: {
15800 u16 tmp;
15801 - __get_user_asm(tmp, (u16 __user *)src,
15802 + __get_user_asm(tmp, (const u16 __user *)src,
15803 ret, "w", "w", "=r", 2);
15804 if (likely(!ret))
15805 __put_user_asm(tmp, (u16 __user *)dst,
15806 @@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15807
15808 case 4: {
15809 u32 tmp;
15810 - __get_user_asm(tmp, (u32 __user *)src,
15811 + __get_user_asm(tmp, (const u32 __user *)src,
15812 ret, "l", "k", "=r", 4);
15813 if (likely(!ret))
15814 __put_user_asm(tmp, (u32 __user *)dst,
15815 @@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15816 }
15817 case 8: {
15818 u64 tmp;
15819 - __get_user_asm(tmp, (u64 __user *)src,
15820 + __get_user_asm(tmp, (const u64 __user *)src,
15821 ret, "q", "", "=r", 8);
15822 if (likely(!ret))
15823 __put_user_asm(tmp, (u64 __user *)dst,
15824 @@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
15825 return ret;
15826 }
15827 default:
15828 - return copy_user_generic((__force void *)dst,
15829 - (__force void *)src, size);
15830 + return copy_user_generic((__force_kernel void *)____m(dst),
15831 + (__force_kernel const void *)____m(src), size);
15832 }
15833 }
15834
15835 static __must_check __always_inline int
15836 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
15837 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
15838 {
15839 - return copy_user_generic(dst, (__force const void *)src, size);
15840 + if (size > INT_MAX)
15841 + return size;
15842 +
15843 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15844 + if (!__access_ok(VERIFY_READ, src, size))
15845 + return size;
15846 +#endif
15847 +
15848 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
15849 }
15850
15851 -static __must_check __always_inline int
15852 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
15853 +static __must_check __always_inline unsigned long
15854 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
15855 {
15856 - return copy_user_generic((__force void *)dst, src, size);
15857 + if (size > INT_MAX)
15858 + return size;
15859 +
15860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15861 + if (!__access_ok(VERIFY_WRITE, dst, size))
15862 + return size;
15863 +#endif
15864 +
15865 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
15866 }
15867
15868 -extern long __copy_user_nocache(void *dst, const void __user *src,
15869 - unsigned size, int zerorest);
15870 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
15871 + unsigned long size, int zerorest) __size_overflow(3);
15872
15873 -static inline int
15874 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
15875 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
15876 {
15877 might_sleep();
15878 +
15879 + if (size > INT_MAX)
15880 + return size;
15881 +
15882 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15883 + if (!__access_ok(VERIFY_READ, src, size))
15884 + return size;
15885 +#endif
15886 +
15887 return __copy_user_nocache(dst, src, size, 1);
15888 }
15889
15890 -static inline int
15891 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15892 - unsigned size)
15893 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
15894 + unsigned long size)
15895 {
15896 + if (size > INT_MAX)
15897 + return size;
15898 +
15899 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15900 + if (!__access_ok(VERIFY_READ, src, size))
15901 + return size;
15902 +#endif
15903 +
15904 return __copy_user_nocache(dst, src, size, 0);
15905 }
15906
15907 -unsigned long
15908 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
15909 +extern unsigned long
15910 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
15911
15912 #endif /* _ASM_X86_UACCESS_64_H */
15913 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
15914 index 5b238981..77fdd78 100644
15915 --- a/arch/x86/include/asm/word-at-a-time.h
15916 +++ b/arch/x86/include/asm/word-at-a-time.h
15917 @@ -11,7 +11,7 @@
15918 * and shift, for example.
15919 */
15920 struct word_at_a_time {
15921 - const unsigned long one_bits, high_bits;
15922 + unsigned long one_bits, high_bits;
15923 };
15924
15925 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
15926 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
15927 index 5769349..a3d3e2a 100644
15928 --- a/arch/x86/include/asm/x86_init.h
15929 +++ b/arch/x86/include/asm/x86_init.h
15930 @@ -141,7 +141,7 @@ struct x86_init_ops {
15931 struct x86_init_timers timers;
15932 struct x86_init_iommu iommu;
15933 struct x86_init_pci pci;
15934 -};
15935 +} __no_const;
15936
15937 /**
15938 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
15939 @@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
15940 void (*setup_percpu_clockev)(void);
15941 void (*early_percpu_clock_init)(void);
15942 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
15943 -};
15944 +} __no_const;
15945
15946 /**
15947 * struct x86_platform_ops - platform specific runtime functions
15948 @@ -178,7 +178,7 @@ struct x86_platform_ops {
15949 void (*save_sched_clock_state)(void);
15950 void (*restore_sched_clock_state)(void);
15951 void (*apic_post_init)(void);
15952 -};
15953 +} __no_const;
15954
15955 struct pci_dev;
15956
15957 @@ -187,14 +187,14 @@ struct x86_msi_ops {
15958 void (*teardown_msi_irq)(unsigned int irq);
15959 void (*teardown_msi_irqs)(struct pci_dev *dev);
15960 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
15961 -};
15962 +} __no_const;
15963
15964 struct x86_io_apic_ops {
15965 void (*init) (void);
15966 unsigned int (*read) (unsigned int apic, unsigned int reg);
15967 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
15968 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
15969 -};
15970 +} __no_const;
15971
15972 extern struct x86_init_ops x86_init;
15973 extern struct x86_cpuinit_ops x86_cpuinit;
15974 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
15975 index 0415cda..b43d877 100644
15976 --- a/arch/x86/include/asm/xsave.h
15977 +++ b/arch/x86/include/asm/xsave.h
15978 @@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15979 return -EFAULT;
15980
15981 __asm__ __volatile__(ASM_STAC "\n"
15982 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
15983 + "1:"
15984 + __copyuser_seg
15985 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
15986 "2: " ASM_CLAC "\n"
15987 ".section .fixup,\"ax\"\n"
15988 "3: movl $-1,%[err]\n"
15989 @@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
15990 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
15991 {
15992 int err;
15993 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
15994 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
15995 u32 lmask = mask;
15996 u32 hmask = mask >> 32;
15997
15998 __asm__ __volatile__(ASM_STAC "\n"
15999 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16000 + "1:"
16001 + __copyuser_seg
16002 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16003 "2: " ASM_CLAC "\n"
16004 ".section .fixup,\"ax\"\n"
16005 "3: movl $-1,%[err]\n"
16006 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16007 index bbae024..e1528f9 100644
16008 --- a/arch/x86/include/uapi/asm/e820.h
16009 +++ b/arch/x86/include/uapi/asm/e820.h
16010 @@ -63,7 +63,7 @@ struct e820map {
16011 #define ISA_START_ADDRESS 0xa0000
16012 #define ISA_END_ADDRESS 0x100000
16013
16014 -#define BIOS_BEGIN 0x000a0000
16015 +#define BIOS_BEGIN 0x000c0000
16016 #define BIOS_END 0x00100000
16017
16018 #define BIOS_ROM_BASE 0xffe00000
16019 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16020 index 34e923a..0c6bb6e 100644
16021 --- a/arch/x86/kernel/Makefile
16022 +++ b/arch/x86/kernel/Makefile
16023 @@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16024 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16025 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16026 obj-y += probe_roms.o
16027 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16028 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16029 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16030 obj-y += syscall_$(BITS).o
16031 obj-$(CONFIG_X86_64) += vsyscall_64.o
16032 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16033 index d5e0d71..6533e08 100644
16034 --- a/arch/x86/kernel/acpi/sleep.c
16035 +++ b/arch/x86/kernel/acpi/sleep.c
16036 @@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16037 #else /* CONFIG_64BIT */
16038 #ifdef CONFIG_SMP
16039 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16040 +
16041 + pax_open_kernel();
16042 early_gdt_descr.address =
16043 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16044 + pax_close_kernel();
16045 +
16046 initial_gs = per_cpu_offset(smp_processor_id());
16047 #endif
16048 initial_code = (unsigned long)wakeup_long64;
16049 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16050 index 13ab720..95d5442 100644
16051 --- a/arch/x86/kernel/acpi/wakeup_32.S
16052 +++ b/arch/x86/kernel/acpi/wakeup_32.S
16053 @@ -30,13 +30,11 @@ wakeup_pmode_return:
16054 # and restore the stack ... but you need gdt for this to work
16055 movl saved_context_esp, %esp
16056
16057 - movl %cs:saved_magic, %eax
16058 - cmpl $0x12345678, %eax
16059 + cmpl $0x12345678, saved_magic
16060 jne bogus_magic
16061
16062 # jump to place where we left off
16063 - movl saved_eip, %eax
16064 - jmp *%eax
16065 + jmp *(saved_eip)
16066
16067 bogus_magic:
16068 jmp bogus_magic
16069 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16070 index ef5ccca..bd83949 100644
16071 --- a/arch/x86/kernel/alternative.c
16072 +++ b/arch/x86/kernel/alternative.c
16073 @@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16074 */
16075 for (a = start; a < end; a++) {
16076 instr = (u8 *)&a->instr_offset + a->instr_offset;
16077 +
16078 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16079 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16080 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16081 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16082 +#endif
16083 +
16084 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16085 BUG_ON(a->replacementlen > a->instrlen);
16086 BUG_ON(a->instrlen > sizeof(insnbuf));
16087 @@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16088 for (poff = start; poff < end; poff++) {
16089 u8 *ptr = (u8 *)poff + *poff;
16090
16091 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16092 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16093 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16094 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16095 +#endif
16096 +
16097 if (!*poff || ptr < text || ptr >= text_end)
16098 continue;
16099 /* turn DS segment override prefix into lock prefix */
16100 - if (*ptr == 0x3e)
16101 + if (*ktla_ktva(ptr) == 0x3e)
16102 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16103 }
16104 mutex_unlock(&text_mutex);
16105 @@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16106 for (poff = start; poff < end; poff++) {
16107 u8 *ptr = (u8 *)poff + *poff;
16108
16109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16110 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16111 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16112 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16113 +#endif
16114 +
16115 if (!*poff || ptr < text || ptr >= text_end)
16116 continue;
16117 /* turn lock prefix into DS segment override prefix */
16118 - if (*ptr == 0xf0)
16119 + if (*ktla_ktva(ptr) == 0xf0)
16120 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16121 }
16122 mutex_unlock(&text_mutex);
16123 @@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16124
16125 BUG_ON(p->len > MAX_PATCH_LEN);
16126 /* prep the buffer with the original instructions */
16127 - memcpy(insnbuf, p->instr, p->len);
16128 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16129 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16130 (unsigned long)p->instr, p->len);
16131
16132 @@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16133 if (!uniproc_patched || num_possible_cpus() == 1)
16134 free_init_pages("SMP alternatives",
16135 (unsigned long)__smp_locks,
16136 - (unsigned long)__smp_locks_end);
16137 + PAGE_ALIGN((unsigned long)__smp_locks_end));
16138 #endif
16139
16140 apply_paravirt(__parainstructions, __parainstructions_end);
16141 @@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16142 * instructions. And on the local CPU you need to be protected again NMI or MCE
16143 * handlers seeing an inconsistent instruction while you patch.
16144 */
16145 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
16146 +void *__kprobes text_poke_early(void *addr, const void *opcode,
16147 size_t len)
16148 {
16149 unsigned long flags;
16150 local_irq_save(flags);
16151 - memcpy(addr, opcode, len);
16152 +
16153 + pax_open_kernel();
16154 + memcpy(ktla_ktva(addr), opcode, len);
16155 sync_core();
16156 + pax_close_kernel();
16157 +
16158 local_irq_restore(flags);
16159 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16160 that causes hangs on some VIA CPUs. */
16161 @@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16162 */
16163 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16164 {
16165 - unsigned long flags;
16166 - char *vaddr;
16167 + unsigned char *vaddr = ktla_ktva(addr);
16168 struct page *pages[2];
16169 - int i;
16170 + size_t i;
16171
16172 if (!core_kernel_text((unsigned long)addr)) {
16173 - pages[0] = vmalloc_to_page(addr);
16174 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16175 + pages[0] = vmalloc_to_page(vaddr);
16176 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16177 } else {
16178 - pages[0] = virt_to_page(addr);
16179 + pages[0] = virt_to_page(vaddr);
16180 WARN_ON(!PageReserved(pages[0]));
16181 - pages[1] = virt_to_page(addr + PAGE_SIZE);
16182 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16183 }
16184 BUG_ON(!pages[0]);
16185 - local_irq_save(flags);
16186 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16187 - if (pages[1])
16188 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16189 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16190 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16191 - clear_fixmap(FIX_TEXT_POKE0);
16192 - if (pages[1])
16193 - clear_fixmap(FIX_TEXT_POKE1);
16194 - local_flush_tlb();
16195 - sync_core();
16196 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
16197 - that causes hangs on some VIA CPUs. */
16198 + text_poke_early(addr, opcode, len);
16199 for (i = 0; i < len; i++)
16200 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16201 - local_irq_restore(flags);
16202 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16203 return addr;
16204 }
16205
16206 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16207 index b994cc8..812b537 100644
16208 --- a/arch/x86/kernel/apic/apic.c
16209 +++ b/arch/x86/kernel/apic/apic.c
16210 @@ -131,7 +131,7 @@ static int __init parse_lapic(char *arg)
16211 {
16212 if (config_enabled(CONFIG_X86_32) && !arg)
16213 force_enable_local_apic = 1;
16214 - else if (!strncmp(arg, "notscdeadline", 13))
16215 + else if (arg && !strncmp(arg, "notscdeadline", 13))
16216 setup_clear_cpu_cap(X86_FEATURE_TSC_DEADLINE_TIMER);
16217 return 0;
16218 }
16219 @@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16220 /*
16221 * Debug level, exported for io_apic.c
16222 */
16223 -unsigned int apic_verbosity;
16224 +int apic_verbosity;
16225
16226 int pic_mode;
16227
16228 @@ -1956,7 +1956,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16229 apic_write(APIC_ESR, 0);
16230 v1 = apic_read(APIC_ESR);
16231 ack_APIC_irq();
16232 - atomic_inc(&irq_err_count);
16233 + atomic_inc_unchecked(&irq_err_count);
16234
16235 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16236 smp_processor_id(), v0 , v1);
16237 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16238 index 00c77cf..2dc6a2d 100644
16239 --- a/arch/x86/kernel/apic/apic_flat_64.c
16240 +++ b/arch/x86/kernel/apic/apic_flat_64.c
16241 @@ -157,7 +157,7 @@ static int flat_probe(void)
16242 return 1;
16243 }
16244
16245 -static struct apic apic_flat = {
16246 +static struct apic apic_flat __read_only = {
16247 .name = "flat",
16248 .probe = flat_probe,
16249 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16250 @@ -271,7 +271,7 @@ static int physflat_probe(void)
16251 return 0;
16252 }
16253
16254 -static struct apic apic_physflat = {
16255 +static struct apic apic_physflat __read_only = {
16256
16257 .name = "physical flat",
16258 .probe = physflat_probe,
16259 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16260 index d50e364..543bee3 100644
16261 --- a/arch/x86/kernel/apic/bigsmp_32.c
16262 +++ b/arch/x86/kernel/apic/bigsmp_32.c
16263 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16264 return dmi_bigsmp;
16265 }
16266
16267 -static struct apic apic_bigsmp = {
16268 +static struct apic apic_bigsmp __read_only = {
16269
16270 .name = "bigsmp",
16271 .probe = probe_bigsmp,
16272 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16273 index 0874799..24a836e 100644
16274 --- a/arch/x86/kernel/apic/es7000_32.c
16275 +++ b/arch/x86/kernel/apic/es7000_32.c
16276 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16277 return ret && es7000_apic_is_cluster();
16278 }
16279
16280 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16281 -static struct apic __refdata apic_es7000_cluster = {
16282 +static struct apic apic_es7000_cluster __read_only = {
16283
16284 .name = "es7000",
16285 .probe = probe_es7000,
16286 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16287 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16288 };
16289
16290 -static struct apic __refdata apic_es7000 = {
16291 +static struct apic __refdata apic_es7000 __read_only = {
16292
16293 .name = "es7000",
16294 .probe = probe_es7000,
16295 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16296 index b739d39..6e4f1db 100644
16297 --- a/arch/x86/kernel/apic/io_apic.c
16298 +++ b/arch/x86/kernel/apic/io_apic.c
16299 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16300 }
16301 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16302
16303 -void lock_vector_lock(void)
16304 +void lock_vector_lock(void) __acquires(vector_lock)
16305 {
16306 /* Used to the online set of cpus does not change
16307 * during assign_irq_vector.
16308 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
16309 raw_spin_lock(&vector_lock);
16310 }
16311
16312 -void unlock_vector_lock(void)
16313 +void unlock_vector_lock(void) __releases(vector_lock)
16314 {
16315 raw_spin_unlock(&vector_lock);
16316 }
16317 @@ -2399,7 +2399,7 @@ static void ack_apic_edge(struct irq_data *data)
16318 ack_APIC_irq();
16319 }
16320
16321 -atomic_t irq_mis_count;
16322 +atomic_unchecked_t irq_mis_count;
16323
16324 #ifdef CONFIG_GENERIC_PENDING_IRQ
16325 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16326 @@ -2540,7 +2540,7 @@ static void ack_apic_level(struct irq_data *data)
16327 * at the cpu.
16328 */
16329 if (!(v & (1 << (i & 0x1f)))) {
16330 - atomic_inc(&irq_mis_count);
16331 + atomic_inc_unchecked(&irq_mis_count);
16332
16333 eoi_ioapic_irq(irq, cfg);
16334 }
16335 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16336 index d661ee9..791fd33 100644
16337 --- a/arch/x86/kernel/apic/numaq_32.c
16338 +++ b/arch/x86/kernel/apic/numaq_32.c
16339 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16340 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16341 }
16342
16343 -/* Use __refdata to keep false positive warning calm. */
16344 -static struct apic __refdata apic_numaq = {
16345 +static struct apic apic_numaq __read_only = {
16346
16347 .name = "NUMAQ",
16348 .probe = probe_numaq,
16349 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16350 index eb35ef9..f184a21 100644
16351 --- a/arch/x86/kernel/apic/probe_32.c
16352 +++ b/arch/x86/kernel/apic/probe_32.c
16353 @@ -72,7 +72,7 @@ static int probe_default(void)
16354 return 1;
16355 }
16356
16357 -static struct apic apic_default = {
16358 +static struct apic apic_default __read_only = {
16359
16360 .name = "default",
16361 .probe = probe_default,
16362 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16363 index 77c95c0..434f8a4 100644
16364 --- a/arch/x86/kernel/apic/summit_32.c
16365 +++ b/arch/x86/kernel/apic/summit_32.c
16366 @@ -486,7 +486,7 @@ void setup_summit(void)
16367 }
16368 #endif
16369
16370 -static struct apic apic_summit = {
16371 +static struct apic apic_summit __read_only = {
16372
16373 .name = "summit",
16374 .probe = probe_summit,
16375 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16376 index c88baa4..757aee1 100644
16377 --- a/arch/x86/kernel/apic/x2apic_cluster.c
16378 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
16379 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16380 return notifier_from_errno(err);
16381 }
16382
16383 -static struct notifier_block __refdata x2apic_cpu_notifier = {
16384 +static struct notifier_block x2apic_cpu_notifier = {
16385 .notifier_call = update_clusterinfo,
16386 };
16387
16388 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16389 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16390 }
16391
16392 -static struct apic apic_x2apic_cluster = {
16393 +static struct apic apic_x2apic_cluster __read_only = {
16394
16395 .name = "cluster x2apic",
16396 .probe = x2apic_cluster_probe,
16397 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16398 index 562a76d..a003c0f 100644
16399 --- a/arch/x86/kernel/apic/x2apic_phys.c
16400 +++ b/arch/x86/kernel/apic/x2apic_phys.c
16401 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16402 return apic == &apic_x2apic_phys;
16403 }
16404
16405 -static struct apic apic_x2apic_phys = {
16406 +static struct apic apic_x2apic_phys __read_only = {
16407
16408 .name = "physical x2apic",
16409 .probe = x2apic_phys_probe,
16410 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
16411 index 8cfade9..b9d04fc 100644
16412 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
16413 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
16414 @@ -333,7 +333,7 @@ static int uv_probe(void)
16415 return apic == &apic_x2apic_uv_x;
16416 }
16417
16418 -static struct apic __refdata apic_x2apic_uv_x = {
16419 +static struct apic apic_x2apic_uv_x __read_only = {
16420
16421 .name = "UV large system",
16422 .probe = uv_probe,
16423 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
16424 index d65464e..1035d31 100644
16425 --- a/arch/x86/kernel/apm_32.c
16426 +++ b/arch/x86/kernel/apm_32.c
16427 @@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
16428 * This is for buggy BIOS's that refer to (real mode) segment 0x40
16429 * even though they are called in protected mode.
16430 */
16431 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
16432 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
16433 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
16434
16435 static const char driver_version[] = "1.16ac"; /* no spaces */
16436 @@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
16437 BUG_ON(cpu != 0);
16438 gdt = get_cpu_gdt_table(cpu);
16439 save_desc_40 = gdt[0x40 / 8];
16440 +
16441 + pax_open_kernel();
16442 gdt[0x40 / 8] = bad_bios_desc;
16443 + pax_close_kernel();
16444
16445 apm_irq_save(flags);
16446 APM_DO_SAVE_SEGS;
16447 @@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
16448 &call->esi);
16449 APM_DO_RESTORE_SEGS;
16450 apm_irq_restore(flags);
16451 +
16452 + pax_open_kernel();
16453 gdt[0x40 / 8] = save_desc_40;
16454 + pax_close_kernel();
16455 +
16456 put_cpu();
16457
16458 return call->eax & 0xff;
16459 @@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
16460 BUG_ON(cpu != 0);
16461 gdt = get_cpu_gdt_table(cpu);
16462 save_desc_40 = gdt[0x40 / 8];
16463 +
16464 + pax_open_kernel();
16465 gdt[0x40 / 8] = bad_bios_desc;
16466 + pax_close_kernel();
16467
16468 apm_irq_save(flags);
16469 APM_DO_SAVE_SEGS;
16470 @@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
16471 &call->eax);
16472 APM_DO_RESTORE_SEGS;
16473 apm_irq_restore(flags);
16474 +
16475 + pax_open_kernel();
16476 gdt[0x40 / 8] = save_desc_40;
16477 + pax_close_kernel();
16478 +
16479 put_cpu();
16480 return error;
16481 }
16482 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
16483 * code to that CPU.
16484 */
16485 gdt = get_cpu_gdt_table(0);
16486 +
16487 + pax_open_kernel();
16488 set_desc_base(&gdt[APM_CS >> 3],
16489 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
16490 set_desc_base(&gdt[APM_CS_16 >> 3],
16491 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
16492 set_desc_base(&gdt[APM_DS >> 3],
16493 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
16494 + pax_close_kernel();
16495
16496 proc_create("apm", 0, NULL, &apm_file_ops);
16497
16498 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
16499 index 2861082..6d4718e 100644
16500 --- a/arch/x86/kernel/asm-offsets.c
16501 +++ b/arch/x86/kernel/asm-offsets.c
16502 @@ -33,6 +33,8 @@ void common(void) {
16503 OFFSET(TI_status, thread_info, status);
16504 OFFSET(TI_addr_limit, thread_info, addr_limit);
16505 OFFSET(TI_preempt_count, thread_info, preempt_count);
16506 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
16507 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
16508
16509 BLANK();
16510 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
16511 @@ -53,8 +55,26 @@ void common(void) {
16512 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
16513 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
16514 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
16515 +
16516 +#ifdef CONFIG_PAX_KERNEXEC
16517 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
16518 #endif
16519
16520 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16521 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
16522 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
16523 +#ifdef CONFIG_X86_64
16524 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
16525 +#endif
16526 +#endif
16527 +
16528 +#endif
16529 +
16530 + BLANK();
16531 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
16532 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
16533 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
16534 +
16535 #ifdef CONFIG_XEN
16536 BLANK();
16537 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
16538 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
16539 index 1b4754f..fbb4227 100644
16540 --- a/arch/x86/kernel/asm-offsets_64.c
16541 +++ b/arch/x86/kernel/asm-offsets_64.c
16542 @@ -76,6 +76,7 @@ int main(void)
16543 BLANK();
16544 #undef ENTRY
16545
16546 + DEFINE(TSS_size, sizeof(struct tss_struct));
16547 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
16548 BLANK();
16549
16550 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
16551 index a0e067d..9c7db16 100644
16552 --- a/arch/x86/kernel/cpu/Makefile
16553 +++ b/arch/x86/kernel/cpu/Makefile
16554 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
16555 CFLAGS_REMOVE_perf_event.o = -pg
16556 endif
16557
16558 -# Make sure load_percpu_segment has no stackprotector
16559 -nostackp := $(call cc-option, -fno-stack-protector)
16560 -CFLAGS_common.o := $(nostackp)
16561 -
16562 obj-y := intel_cacheinfo.o scattered.o topology.o
16563 obj-y += proc.o capflags.o powerflags.o common.o
16564 obj-y += vmware.o hypervisor.o mshyperv.o
16565 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
16566 index 15239ff..e23e04e 100644
16567 --- a/arch/x86/kernel/cpu/amd.c
16568 +++ b/arch/x86/kernel/cpu/amd.c
16569 @@ -733,7 +733,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
16570 unsigned int size)
16571 {
16572 /* AMD errata T13 (order #21922) */
16573 - if ((c->x86 == 6)) {
16574 + if (c->x86 == 6) {
16575 /* Duron Rev A0 */
16576 if (c->x86_model == 3 && c->x86_mask == 0)
16577 size = 64;
16578 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
16579 index 9c3ab43..51e6366 100644
16580 --- a/arch/x86/kernel/cpu/common.c
16581 +++ b/arch/x86/kernel/cpu/common.c
16582 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
16583
16584 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
16585
16586 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
16587 -#ifdef CONFIG_X86_64
16588 - /*
16589 - * We need valid kernel segments for data and code in long mode too
16590 - * IRET will check the segment types kkeil 2000/10/28
16591 - * Also sysret mandates a special GDT layout
16592 - *
16593 - * TLS descriptors are currently at a different place compared to i386.
16594 - * Hopefully nobody expects them at a fixed place (Wine?)
16595 - */
16596 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
16597 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
16598 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
16599 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
16600 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
16601 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
16602 -#else
16603 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
16604 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16605 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
16606 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
16607 - /*
16608 - * Segments used for calling PnP BIOS have byte granularity.
16609 - * They code segments and data segments have fixed 64k limits,
16610 - * the transfer segment sizes are set at run time.
16611 - */
16612 - /* 32-bit code */
16613 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16614 - /* 16-bit code */
16615 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16616 - /* 16-bit data */
16617 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
16618 - /* 16-bit data */
16619 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
16620 - /* 16-bit data */
16621 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
16622 - /*
16623 - * The APM segments have byte granularity and their bases
16624 - * are set at run time. All have 64k limits.
16625 - */
16626 - /* 32-bit code */
16627 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
16628 - /* 16-bit code */
16629 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
16630 - /* data */
16631 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
16632 -
16633 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16634 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
16635 - GDT_STACK_CANARY_INIT
16636 -#endif
16637 -} };
16638 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
16639 -
16640 static int __init x86_xsave_setup(char *s)
16641 {
16642 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
16643 @@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
16644 {
16645 struct desc_ptr gdt_descr;
16646
16647 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
16648 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
16649 gdt_descr.size = GDT_SIZE - 1;
16650 load_gdt(&gdt_descr);
16651 /* Reload the per-cpu base */
16652 @@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
16653 /* Filter out anything that depends on CPUID levels we don't have */
16654 filter_cpuid_features(c, true);
16655
16656 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
16657 + setup_clear_cpu_cap(X86_FEATURE_SEP);
16658 +#endif
16659 +
16660 /* If the model name is still unset, do table lookup. */
16661 if (!c->x86_model_id[0]) {
16662 const char *p;
16663 @@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
16664 }
16665 __setup("clearcpuid=", setup_disablecpuid);
16666
16667 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
16668 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
16669 +
16670 #ifdef CONFIG_X86_64
16671 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
16672 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
16673 - (unsigned long) nmi_idt_table };
16674 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
16675
16676 DEFINE_PER_CPU_FIRST(union irq_stack_union,
16677 irq_stack_union) __aligned(PAGE_SIZE);
16678 @@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
16679 EXPORT_PER_CPU_SYMBOL(current_task);
16680
16681 DEFINE_PER_CPU(unsigned long, kernel_stack) =
16682 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
16683 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
16684 EXPORT_PER_CPU_SYMBOL(kernel_stack);
16685
16686 DEFINE_PER_CPU(char *, irq_stack_ptr) =
16687 @@ -1224,7 +1176,7 @@ void __cpuinit cpu_init(void)
16688 int i;
16689
16690 cpu = stack_smp_processor_id();
16691 - t = &per_cpu(init_tss, cpu);
16692 + t = init_tss + cpu;
16693 oist = &per_cpu(orig_ist, cpu);
16694
16695 #ifdef CONFIG_NUMA
16696 @@ -1250,7 +1202,7 @@ void __cpuinit cpu_init(void)
16697 switch_to_new_gdt(cpu);
16698 loadsegment(fs, 0);
16699
16700 - load_idt((const struct desc_ptr *)&idt_descr);
16701 + load_idt(&idt_descr);
16702
16703 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
16704 syscall_init();
16705 @@ -1259,7 +1211,6 @@ void __cpuinit cpu_init(void)
16706 wrmsrl(MSR_KERNEL_GS_BASE, 0);
16707 barrier();
16708
16709 - x86_configure_nx();
16710 enable_x2apic();
16711
16712 /*
16713 @@ -1311,7 +1262,7 @@ void __cpuinit cpu_init(void)
16714 {
16715 int cpu = smp_processor_id();
16716 struct task_struct *curr = current;
16717 - struct tss_struct *t = &per_cpu(init_tss, cpu);
16718 + struct tss_struct *t = init_tss + cpu;
16719 struct thread_struct *thread = &curr->thread;
16720
16721 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
16722 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
16723 index fcaabd0..7b55a26 100644
16724 --- a/arch/x86/kernel/cpu/intel.c
16725 +++ b/arch/x86/kernel/cpu/intel.c
16726 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
16727 * Update the IDT descriptor and reload the IDT so that
16728 * it uses the read-only mapped virtual address.
16729 */
16730 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
16731 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
16732 load_idt(&idt_descr);
16733 }
16734 #endif
16735 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
16736 index 84c1309..39b7224 100644
16737 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
16738 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
16739 @@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
16740 };
16741
16742 #ifdef CONFIG_AMD_NB
16743 +static struct attribute *default_attrs_amd_nb[] = {
16744 + &type.attr,
16745 + &level.attr,
16746 + &coherency_line_size.attr,
16747 + &physical_line_partition.attr,
16748 + &ways_of_associativity.attr,
16749 + &number_of_sets.attr,
16750 + &size.attr,
16751 + &shared_cpu_map.attr,
16752 + &shared_cpu_list.attr,
16753 + NULL,
16754 + NULL,
16755 + NULL,
16756 + NULL
16757 +};
16758 +
16759 static struct attribute ** __cpuinit amd_l3_attrs(void)
16760 {
16761 static struct attribute **attrs;
16762 @@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
16763
16764 n = ARRAY_SIZE(default_attrs);
16765
16766 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
16767 - n += 2;
16768 -
16769 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
16770 - n += 1;
16771 -
16772 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
16773 - if (attrs == NULL)
16774 - return attrs = default_attrs;
16775 -
16776 - for (n = 0; default_attrs[n]; n++)
16777 - attrs[n] = default_attrs[n];
16778 + attrs = default_attrs_amd_nb;
16779
16780 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
16781 attrs[n++] = &cache_disable_0.attr;
16782 @@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
16783 .default_attrs = default_attrs,
16784 };
16785
16786 +#ifdef CONFIG_AMD_NB
16787 +static struct kobj_type ktype_cache_amd_nb = {
16788 + .sysfs_ops = &sysfs_ops,
16789 + .default_attrs = default_attrs_amd_nb,
16790 +};
16791 +#endif
16792 +
16793 static struct kobj_type ktype_percpu_entry = {
16794 .sysfs_ops = &sysfs_ops,
16795 };
16796 @@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
16797 return retval;
16798 }
16799
16800 +#ifdef CONFIG_AMD_NB
16801 + amd_l3_attrs();
16802 +#endif
16803 +
16804 for (i = 0; i < num_cache_leaves; i++) {
16805 + struct kobj_type *ktype;
16806 +
16807 this_object = INDEX_KOBJECT_PTR(cpu, i);
16808 this_object->cpu = cpu;
16809 this_object->index = i;
16810
16811 this_leaf = CPUID4_INFO_IDX(cpu, i);
16812
16813 - ktype_cache.default_attrs = default_attrs;
16814 + ktype = &ktype_cache;
16815 #ifdef CONFIG_AMD_NB
16816 if (this_leaf->base.nb)
16817 - ktype_cache.default_attrs = amd_l3_attrs();
16818 + ktype = &ktype_cache_amd_nb;
16819 #endif
16820 retval = kobject_init_and_add(&(this_object->kobj),
16821 - &ktype_cache,
16822 + ktype,
16823 per_cpu(ici_cache_kobject, cpu),
16824 "index%1lu", i);
16825 if (unlikely(retval)) {
16826 @@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
16827 return NOTIFY_OK;
16828 }
16829
16830 -static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
16831 +static struct notifier_block cacheinfo_cpu_notifier = {
16832 .notifier_call = cacheinfo_cpu_callback,
16833 };
16834
16835 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
16836 index 80dbda8..b45ebad 100644
16837 --- a/arch/x86/kernel/cpu/mcheck/mce.c
16838 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
16839 @@ -45,6 +45,7 @@
16840 #include <asm/processor.h>
16841 #include <asm/mce.h>
16842 #include <asm/msr.h>
16843 +#include <asm/local.h>
16844
16845 #include "mce-internal.h"
16846
16847 @@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
16848 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
16849 m->cs, m->ip);
16850
16851 - if (m->cs == __KERNEL_CS)
16852 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
16853 print_symbol("{%s}", m->ip);
16854 pr_cont("\n");
16855 }
16856 @@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
16857
16858 #define PANIC_TIMEOUT 5 /* 5 seconds */
16859
16860 -static atomic_t mce_paniced;
16861 +static atomic_unchecked_t mce_paniced;
16862
16863 static int fake_panic;
16864 -static atomic_t mce_fake_paniced;
16865 +static atomic_unchecked_t mce_fake_paniced;
16866
16867 /* Panic in progress. Enable interrupts and wait for final IPI */
16868 static void wait_for_panic(void)
16869 @@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16870 /*
16871 * Make sure only one CPU runs in machine check panic
16872 */
16873 - if (atomic_inc_return(&mce_paniced) > 1)
16874 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
16875 wait_for_panic();
16876 barrier();
16877
16878 @@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
16879 console_verbose();
16880 } else {
16881 /* Don't log too much for fake panic */
16882 - if (atomic_inc_return(&mce_fake_paniced) > 1)
16883 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
16884 return;
16885 }
16886 /* First print corrected ones that are still unlogged */
16887 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
16888 * might have been modified by someone else.
16889 */
16890 rmb();
16891 - if (atomic_read(&mce_paniced))
16892 + if (atomic_read_unchecked(&mce_paniced))
16893 wait_for_panic();
16894 if (!mca_cfg.monarch_timeout)
16895 goto out;
16896 @@ -1662,7 +1663,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
16897 }
16898
16899 /* Call the installed machine check handler for this CPU setup. */
16900 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
16901 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
16902 unexpected_machine_check;
16903
16904 /*
16905 @@ -1685,7 +1686,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16906 return;
16907 }
16908
16909 + pax_open_kernel();
16910 machine_check_vector = do_machine_check;
16911 + pax_close_kernel();
16912
16913 __mcheck_cpu_init_generic();
16914 __mcheck_cpu_init_vendor(c);
16915 @@ -1699,7 +1702,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
16916 */
16917
16918 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
16919 -static int mce_chrdev_open_count; /* #times opened */
16920 +static local_t mce_chrdev_open_count; /* #times opened */
16921 static int mce_chrdev_open_exclu; /* already open exclusive? */
16922
16923 static int mce_chrdev_open(struct inode *inode, struct file *file)
16924 @@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16925 spin_lock(&mce_chrdev_state_lock);
16926
16927 if (mce_chrdev_open_exclu ||
16928 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
16929 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
16930 spin_unlock(&mce_chrdev_state_lock);
16931
16932 return -EBUSY;
16933 @@ -1715,7 +1718,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
16934
16935 if (file->f_flags & O_EXCL)
16936 mce_chrdev_open_exclu = 1;
16937 - mce_chrdev_open_count++;
16938 + local_inc(&mce_chrdev_open_count);
16939
16940 spin_unlock(&mce_chrdev_state_lock);
16941
16942 @@ -1726,7 +1729,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
16943 {
16944 spin_lock(&mce_chrdev_state_lock);
16945
16946 - mce_chrdev_open_count--;
16947 + local_dec(&mce_chrdev_open_count);
16948 mce_chrdev_open_exclu = 0;
16949
16950 spin_unlock(&mce_chrdev_state_lock);
16951 @@ -2372,7 +2375,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
16952 return NOTIFY_OK;
16953 }
16954
16955 -static struct notifier_block mce_cpu_notifier __cpuinitdata = {
16956 +static struct notifier_block mce_cpu_notifier = {
16957 .notifier_call = mce_cpu_callback,
16958 };
16959
16960 @@ -2450,7 +2453,7 @@ struct dentry *mce_get_debugfs_dir(void)
16961 static void mce_reset(void)
16962 {
16963 cpu_missing = 0;
16964 - atomic_set(&mce_fake_paniced, 0);
16965 + atomic_set_unchecked(&mce_fake_paniced, 0);
16966 atomic_set(&mce_executing, 0);
16967 atomic_set(&mce_callin, 0);
16968 atomic_set(&global_nwo, 0);
16969 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
16970 index 2d5454c..51987eb 100644
16971 --- a/arch/x86/kernel/cpu/mcheck/p5.c
16972 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
16973 @@ -11,6 +11,7 @@
16974 #include <asm/processor.h>
16975 #include <asm/mce.h>
16976 #include <asm/msr.h>
16977 +#include <asm/pgtable.h>
16978
16979 /* By default disabled */
16980 int mce_p5_enabled __read_mostly;
16981 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
16982 if (!cpu_has(c, X86_FEATURE_MCE))
16983 return;
16984
16985 + pax_open_kernel();
16986 machine_check_vector = pentium_machine_check;
16987 + pax_close_kernel();
16988 /* Make sure the vector pointer is visible before we enable MCEs: */
16989 wmb();
16990
16991 diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16992 index 47a1870..8c019a7 100644
16993 --- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
16994 +++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
16995 @@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
16996 return notifier_from_errno(err);
16997 }
16998
16999 -static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17000 +static struct notifier_block thermal_throttle_cpu_notifier =
17001 {
17002 .notifier_call = thermal_throttle_cpu_callback,
17003 };
17004 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17005 index 2d7998f..17c9de1 100644
17006 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
17007 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17008 @@ -10,6 +10,7 @@
17009 #include <asm/processor.h>
17010 #include <asm/mce.h>
17011 #include <asm/msr.h>
17012 +#include <asm/pgtable.h>
17013
17014 /* Machine check handler for WinChip C6: */
17015 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17016 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17017 {
17018 u32 lo, hi;
17019
17020 + pax_open_kernel();
17021 machine_check_vector = winchip_machine_check;
17022 + pax_close_kernel();
17023 /* Make sure the vector pointer is visible before we enable MCEs: */
17024 wmb();
17025
17026 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17027 index 726bf96..81f0526 100644
17028 --- a/arch/x86/kernel/cpu/mtrr/main.c
17029 +++ b/arch/x86/kernel/cpu/mtrr/main.c
17030 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17031 u64 size_or_mask, size_and_mask;
17032 static bool mtrr_aps_delayed_init;
17033
17034 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17035 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17036
17037 const struct mtrr_ops *mtrr_if;
17038
17039 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17040 index df5e41f..816c719 100644
17041 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17042 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17043 @@ -25,7 +25,7 @@ struct mtrr_ops {
17044 int (*validate_add_page)(unsigned long base, unsigned long size,
17045 unsigned int type);
17046 int (*have_wrcomb)(void);
17047 -};
17048 +} __do_const;
17049
17050 extern int generic_get_free_region(unsigned long base, unsigned long size,
17051 int replace_reg);
17052 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17053 index 6774c17..a691911 100644
17054 --- a/arch/x86/kernel/cpu/perf_event.c
17055 +++ b/arch/x86/kernel/cpu/perf_event.c
17056 @@ -1880,7 +1880,7 @@ static unsigned long get_segment_base(unsigned int segment)
17057 if (idx > GDT_ENTRIES)
17058 return 0;
17059
17060 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17061 + desc = get_cpu_gdt_table(smp_processor_id());
17062 }
17063
17064 return get_desc_base(desc + idx);
17065 @@ -1970,7 +1970,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17066 break;
17067
17068 perf_callchain_store(entry, frame.return_address);
17069 - fp = frame.next_frame;
17070 + fp = (const void __force_user *)frame.next_frame;
17071 }
17072 }
17073
17074 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17075 index 4914e94..60b06e3 100644
17076 --- a/arch/x86/kernel/cpu/perf_event_intel.c
17077 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
17078 @@ -1958,10 +1958,10 @@ __init int intel_pmu_init(void)
17079 * v2 and above have a perf capabilities MSR
17080 */
17081 if (version > 1) {
17082 - u64 capabilities;
17083 + u64 capabilities = x86_pmu.intel_cap.capabilities;
17084
17085 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17086 - x86_pmu.intel_cap.capabilities = capabilities;
17087 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17088 + x86_pmu.intel_cap.capabilities = capabilities;
17089 }
17090
17091 intel_ds_init();
17092 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17093 index b43200d..62cddfe 100644
17094 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17095 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17096 @@ -2826,7 +2826,7 @@ static int
17097 return NOTIFY_OK;
17098 }
17099
17100 -static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17101 +static struct notifier_block uncore_cpu_nb = {
17102 .notifier_call = uncore_cpu_notifier,
17103 /*
17104 * to migrate uncore events, our notifier should be executed
17105 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17106 index 60c7891..9e911d3 100644
17107 --- a/arch/x86/kernel/cpuid.c
17108 +++ b/arch/x86/kernel/cpuid.c
17109 @@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17110 return notifier_from_errno(err);
17111 }
17112
17113 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
17114 +static struct notifier_block cpuid_class_cpu_notifier =
17115 {
17116 .notifier_call = cpuid_class_cpu_callback,
17117 };
17118 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17119 index 74467fe..18793d5 100644
17120 --- a/arch/x86/kernel/crash.c
17121 +++ b/arch/x86/kernel/crash.c
17122 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17123 {
17124 #ifdef CONFIG_X86_32
17125 struct pt_regs fixed_regs;
17126 -#endif
17127
17128 -#ifdef CONFIG_X86_32
17129 - if (!user_mode_vm(regs)) {
17130 + if (!user_mode(regs)) {
17131 crash_fixup_ss_esp(&fixed_regs, regs);
17132 regs = &fixed_regs;
17133 }
17134 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17135 index 37250fe..bf2ec74 100644
17136 --- a/arch/x86/kernel/doublefault_32.c
17137 +++ b/arch/x86/kernel/doublefault_32.c
17138 @@ -11,7 +11,7 @@
17139
17140 #define DOUBLEFAULT_STACKSIZE (1024)
17141 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17142 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17143 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17144
17145 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17146
17147 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
17148 unsigned long gdt, tss;
17149
17150 store_gdt(&gdt_desc);
17151 - gdt = gdt_desc.address;
17152 + gdt = (unsigned long)gdt_desc.address;
17153
17154 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17155
17156 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17157 /* 0x2 bit is always set */
17158 .flags = X86_EFLAGS_SF | 0x2,
17159 .sp = STACK_START,
17160 - .es = __USER_DS,
17161 + .es = __KERNEL_DS,
17162 .cs = __KERNEL_CS,
17163 .ss = __KERNEL_DS,
17164 - .ds = __USER_DS,
17165 + .ds = __KERNEL_DS,
17166 .fs = __KERNEL_PERCPU,
17167
17168 .__cr3 = __pa_nodebug(swapper_pg_dir),
17169 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17170 index ae42418b..787c16b 100644
17171 --- a/arch/x86/kernel/dumpstack.c
17172 +++ b/arch/x86/kernel/dumpstack.c
17173 @@ -2,6 +2,9 @@
17174 * Copyright (C) 1991, 1992 Linus Torvalds
17175 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17176 */
17177 +#ifdef CONFIG_GRKERNSEC_HIDESYM
17178 +#define __INCLUDED_BY_HIDESYM 1
17179 +#endif
17180 #include <linux/kallsyms.h>
17181 #include <linux/kprobes.h>
17182 #include <linux/uaccess.h>
17183 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17184 static void
17185 print_ftrace_graph_addr(unsigned long addr, void *data,
17186 const struct stacktrace_ops *ops,
17187 - struct thread_info *tinfo, int *graph)
17188 + struct task_struct *task, int *graph)
17189 {
17190 - struct task_struct *task;
17191 unsigned long ret_addr;
17192 int index;
17193
17194 if (addr != (unsigned long)return_to_handler)
17195 return;
17196
17197 - task = tinfo->task;
17198 index = task->curr_ret_stack;
17199
17200 if (!task->ret_stack || index < *graph)
17201 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17202 static inline void
17203 print_ftrace_graph_addr(unsigned long addr, void *data,
17204 const struct stacktrace_ops *ops,
17205 - struct thread_info *tinfo, int *graph)
17206 + struct task_struct *task, int *graph)
17207 { }
17208 #endif
17209
17210 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17211 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17212 */
17213
17214 -static inline int valid_stack_ptr(struct thread_info *tinfo,
17215 - void *p, unsigned int size, void *end)
17216 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17217 {
17218 - void *t = tinfo;
17219 if (end) {
17220 if (p < end && p >= (end-THREAD_SIZE))
17221 return 1;
17222 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17223 }
17224
17225 unsigned long
17226 -print_context_stack(struct thread_info *tinfo,
17227 +print_context_stack(struct task_struct *task, void *stack_start,
17228 unsigned long *stack, unsigned long bp,
17229 const struct stacktrace_ops *ops, void *data,
17230 unsigned long *end, int *graph)
17231 {
17232 struct stack_frame *frame = (struct stack_frame *)bp;
17233
17234 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17235 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17236 unsigned long addr;
17237
17238 addr = *stack;
17239 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17240 } else {
17241 ops->address(data, addr, 0);
17242 }
17243 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17244 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17245 }
17246 stack++;
17247 }
17248 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17249 EXPORT_SYMBOL_GPL(print_context_stack);
17250
17251 unsigned long
17252 -print_context_stack_bp(struct thread_info *tinfo,
17253 +print_context_stack_bp(struct task_struct *task, void *stack_start,
17254 unsigned long *stack, unsigned long bp,
17255 const struct stacktrace_ops *ops, void *data,
17256 unsigned long *end, int *graph)
17257 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17258 struct stack_frame *frame = (struct stack_frame *)bp;
17259 unsigned long *ret_addr = &frame->return_address;
17260
17261 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17262 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17263 unsigned long addr = *ret_addr;
17264
17265 if (!__kernel_text_address(addr))
17266 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17267 ops->address(data, addr, 1);
17268 frame = frame->next_frame;
17269 ret_addr = &frame->return_address;
17270 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17271 + print_ftrace_graph_addr(addr, data, ops, task, graph);
17272 }
17273
17274 return (unsigned long)frame;
17275 @@ -189,7 +188,7 @@ void dump_stack(void)
17276
17277 bp = stack_frame(current, NULL);
17278 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17279 - current->pid, current->comm, print_tainted(),
17280 + task_pid_nr(current), current->comm, print_tainted(),
17281 init_utsname()->release,
17282 (int)strcspn(init_utsname()->version, " "),
17283 init_utsname()->version);
17284 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17285 }
17286 EXPORT_SYMBOL_GPL(oops_begin);
17287
17288 +extern void gr_handle_kernel_exploit(void);
17289 +
17290 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17291 {
17292 if (regs && kexec_should_crash(current))
17293 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17294 panic("Fatal exception in interrupt");
17295 if (panic_on_oops)
17296 panic("Fatal exception");
17297 - do_exit(signr);
17298 +
17299 + gr_handle_kernel_exploit();
17300 +
17301 + do_group_exit(signr);
17302 }
17303
17304 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17305 @@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17306 print_modules();
17307 show_regs(regs);
17308 #ifdef CONFIG_X86_32
17309 - if (user_mode_vm(regs)) {
17310 + if (user_mode(regs)) {
17311 sp = regs->sp;
17312 ss = regs->ss & 0xffff;
17313 } else {
17314 @@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17315 unsigned long flags = oops_begin();
17316 int sig = SIGSEGV;
17317
17318 - if (!user_mode_vm(regs))
17319 + if (!user_mode(regs))
17320 report_bug(regs->ip, regs);
17321
17322 if (__die(str, regs, err))
17323 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17324 index 1038a41..db2c12b 100644
17325 --- a/arch/x86/kernel/dumpstack_32.c
17326 +++ b/arch/x86/kernel/dumpstack_32.c
17327 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17328 bp = stack_frame(task, regs);
17329
17330 for (;;) {
17331 - struct thread_info *context;
17332 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17333
17334 - context = (struct thread_info *)
17335 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17336 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
17337 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17338
17339 - stack = (unsigned long *)context->previous_esp;
17340 - if (!stack)
17341 + if (stack_start == task_stack_page(task))
17342 break;
17343 + stack = *(unsigned long **)stack_start;
17344 if (ops->stack(data, "IRQ") < 0)
17345 break;
17346 touch_nmi_watchdog();
17347 @@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
17348 {
17349 int i;
17350
17351 - __show_regs(regs, !user_mode_vm(regs));
17352 + __show_regs(regs, !user_mode(regs));
17353
17354 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
17355 TASK_COMM_LEN, current->comm, task_pid_nr(current),
17356 @@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
17357 * When in-kernel, we also print out the stack and code at the
17358 * time of the fault..
17359 */
17360 - if (!user_mode_vm(regs)) {
17361 + if (!user_mode(regs)) {
17362 unsigned int code_prologue = code_bytes * 43 / 64;
17363 unsigned int code_len = code_bytes;
17364 unsigned char c;
17365 u8 *ip;
17366 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
17367
17368 pr_emerg("Stack:\n");
17369 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
17370
17371 pr_emerg("Code:");
17372
17373 - ip = (u8 *)regs->ip - code_prologue;
17374 + ip = (u8 *)regs->ip - code_prologue + cs_base;
17375 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
17376 /* try starting at IP */
17377 - ip = (u8 *)regs->ip;
17378 + ip = (u8 *)regs->ip + cs_base;
17379 code_len = code_len - code_prologue + 1;
17380 }
17381 for (i = 0; i < code_len; i++, ip++) {
17382 @@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
17383 pr_cont(" Bad EIP value.");
17384 break;
17385 }
17386 - if (ip == (u8 *)regs->ip)
17387 + if (ip == (u8 *)regs->ip + cs_base)
17388 pr_cont(" <%02x>", c);
17389 else
17390 pr_cont(" %02x", c);
17391 @@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
17392 {
17393 unsigned short ud2;
17394
17395 + ip = ktla_ktva(ip);
17396 if (ip < PAGE_OFFSET)
17397 return 0;
17398 if (probe_kernel_address((unsigned short *)ip, ud2))
17399 @@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
17400
17401 return ud2 == 0x0b0f;
17402 }
17403 +
17404 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17405 +void pax_check_alloca(unsigned long size)
17406 +{
17407 + unsigned long sp = (unsigned long)&sp, stack_left;
17408 +
17409 + /* all kernel stacks are of the same size */
17410 + stack_left = sp & (THREAD_SIZE - 1);
17411 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17412 +}
17413 +EXPORT_SYMBOL(pax_check_alloca);
17414 +#endif
17415 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
17416 index b653675..51cc8c0 100644
17417 --- a/arch/x86/kernel/dumpstack_64.c
17418 +++ b/arch/x86/kernel/dumpstack_64.c
17419 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17420 unsigned long *irq_stack_end =
17421 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
17422 unsigned used = 0;
17423 - struct thread_info *tinfo;
17424 int graph = 0;
17425 unsigned long dummy;
17426 + void *stack_start;
17427
17428 if (!task)
17429 task = current;
17430 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17431 * current stack address. If the stacks consist of nested
17432 * exceptions
17433 */
17434 - tinfo = task_thread_info(task);
17435 for (;;) {
17436 char *id;
17437 unsigned long *estack_end;
17438 +
17439 estack_end = in_exception_stack(cpu, (unsigned long)stack,
17440 &used, &id);
17441
17442 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17443 if (ops->stack(data, id) < 0)
17444 break;
17445
17446 - bp = ops->walk_stack(tinfo, stack, bp, ops,
17447 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
17448 data, estack_end, &graph);
17449 ops->stack(data, "<EOE>");
17450 /*
17451 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17452 * second-to-last pointer (index -2 to end) in the
17453 * exception stack:
17454 */
17455 + if ((u16)estack_end[-1] != __KERNEL_DS)
17456 + goto out;
17457 stack = (unsigned long *) estack_end[-2];
17458 continue;
17459 }
17460 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17461 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
17462 if (ops->stack(data, "IRQ") < 0)
17463 break;
17464 - bp = ops->walk_stack(tinfo, stack, bp,
17465 + bp = ops->walk_stack(task, irq_stack, stack, bp,
17466 ops, data, irq_stack_end, &graph);
17467 /*
17468 * We link to the next stack (which would be
17469 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17470 /*
17471 * This handles the process stack:
17472 */
17473 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
17474 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17475 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
17476 +out:
17477 put_cpu();
17478 }
17479 EXPORT_SYMBOL(dump_trace);
17480 @@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
17481 {
17482 int i;
17483 unsigned long sp;
17484 - const int cpu = smp_processor_id();
17485 + const int cpu = raw_smp_processor_id();
17486 struct task_struct *cur = current;
17487
17488 sp = regs->sp;
17489 @@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
17490
17491 return ud2 == 0x0b0f;
17492 }
17493 +
17494 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17495 +void pax_check_alloca(unsigned long size)
17496 +{
17497 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
17498 + unsigned cpu, used;
17499 + char *id;
17500 +
17501 + /* check the process stack first */
17502 + stack_start = (unsigned long)task_stack_page(current);
17503 + stack_end = stack_start + THREAD_SIZE;
17504 + if (likely(stack_start <= sp && sp < stack_end)) {
17505 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
17506 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17507 + return;
17508 + }
17509 +
17510 + cpu = get_cpu();
17511 +
17512 + /* check the irq stacks */
17513 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
17514 + stack_start = stack_end - IRQ_STACK_SIZE;
17515 + if (stack_start <= sp && sp < stack_end) {
17516 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
17517 + put_cpu();
17518 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17519 + return;
17520 + }
17521 +
17522 + /* check the exception stacks */
17523 + used = 0;
17524 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
17525 + stack_start = stack_end - EXCEPTION_STKSZ;
17526 + if (stack_end && stack_start <= sp && sp < stack_end) {
17527 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
17528 + put_cpu();
17529 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
17530 + return;
17531 + }
17532 +
17533 + put_cpu();
17534 +
17535 + /* unknown stack */
17536 + BUG();
17537 +}
17538 +EXPORT_SYMBOL(pax_check_alloca);
17539 +#endif
17540 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
17541 index 9b9f18b..9fcaa04 100644
17542 --- a/arch/x86/kernel/early_printk.c
17543 +++ b/arch/x86/kernel/early_printk.c
17544 @@ -7,6 +7,7 @@
17545 #include <linux/pci_regs.h>
17546 #include <linux/pci_ids.h>
17547 #include <linux/errno.h>
17548 +#include <linux/sched.h>
17549 #include <asm/io.h>
17550 #include <asm/processor.h>
17551 #include <asm/fcntl.h>
17552 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
17553 index 6ed91d9..6cc365b 100644
17554 --- a/arch/x86/kernel/entry_32.S
17555 +++ b/arch/x86/kernel/entry_32.S
17556 @@ -177,13 +177,153 @@
17557 /*CFI_REL_OFFSET gs, PT_GS*/
17558 .endm
17559 .macro SET_KERNEL_GS reg
17560 +
17561 +#ifdef CONFIG_CC_STACKPROTECTOR
17562 movl $(__KERNEL_STACK_CANARY), \reg
17563 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17564 + movl $(__USER_DS), \reg
17565 +#else
17566 + xorl \reg, \reg
17567 +#endif
17568 +
17569 movl \reg, %gs
17570 .endm
17571
17572 #endif /* CONFIG_X86_32_LAZY_GS */
17573
17574 -.macro SAVE_ALL
17575 +.macro pax_enter_kernel
17576 +#ifdef CONFIG_PAX_KERNEXEC
17577 + call pax_enter_kernel
17578 +#endif
17579 +.endm
17580 +
17581 +.macro pax_exit_kernel
17582 +#ifdef CONFIG_PAX_KERNEXEC
17583 + call pax_exit_kernel
17584 +#endif
17585 +.endm
17586 +
17587 +#ifdef CONFIG_PAX_KERNEXEC
17588 +ENTRY(pax_enter_kernel)
17589 +#ifdef CONFIG_PARAVIRT
17590 + pushl %eax
17591 + pushl %ecx
17592 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
17593 + mov %eax, %esi
17594 +#else
17595 + mov %cr0, %esi
17596 +#endif
17597 + bts $16, %esi
17598 + jnc 1f
17599 + mov %cs, %esi
17600 + cmp $__KERNEL_CS, %esi
17601 + jz 3f
17602 + ljmp $__KERNEL_CS, $3f
17603 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
17604 +2:
17605 +#ifdef CONFIG_PARAVIRT
17606 + mov %esi, %eax
17607 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17608 +#else
17609 + mov %esi, %cr0
17610 +#endif
17611 +3:
17612 +#ifdef CONFIG_PARAVIRT
17613 + popl %ecx
17614 + popl %eax
17615 +#endif
17616 + ret
17617 +ENDPROC(pax_enter_kernel)
17618 +
17619 +ENTRY(pax_exit_kernel)
17620 +#ifdef CONFIG_PARAVIRT
17621 + pushl %eax
17622 + pushl %ecx
17623 +#endif
17624 + mov %cs, %esi
17625 + cmp $__KERNEXEC_KERNEL_CS, %esi
17626 + jnz 2f
17627 +#ifdef CONFIG_PARAVIRT
17628 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
17629 + mov %eax, %esi
17630 +#else
17631 + mov %cr0, %esi
17632 +#endif
17633 + btr $16, %esi
17634 + ljmp $__KERNEL_CS, $1f
17635 +1:
17636 +#ifdef CONFIG_PARAVIRT
17637 + mov %esi, %eax
17638 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
17639 +#else
17640 + mov %esi, %cr0
17641 +#endif
17642 +2:
17643 +#ifdef CONFIG_PARAVIRT
17644 + popl %ecx
17645 + popl %eax
17646 +#endif
17647 + ret
17648 +ENDPROC(pax_exit_kernel)
17649 +#endif
17650 +
17651 +.macro pax_erase_kstack
17652 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17653 + call pax_erase_kstack
17654 +#endif
17655 +.endm
17656 +
17657 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17658 +/*
17659 + * ebp: thread_info
17660 + */
17661 +ENTRY(pax_erase_kstack)
17662 + pushl %edi
17663 + pushl %ecx
17664 + pushl %eax
17665 +
17666 + mov TI_lowest_stack(%ebp), %edi
17667 + mov $-0xBEEF, %eax
17668 + std
17669 +
17670 +1: mov %edi, %ecx
17671 + and $THREAD_SIZE_asm - 1, %ecx
17672 + shr $2, %ecx
17673 + repne scasl
17674 + jecxz 2f
17675 +
17676 + cmp $2*16, %ecx
17677 + jc 2f
17678 +
17679 + mov $2*16, %ecx
17680 + repe scasl
17681 + jecxz 2f
17682 + jne 1b
17683 +
17684 +2: cld
17685 + mov %esp, %ecx
17686 + sub %edi, %ecx
17687 +
17688 + cmp $THREAD_SIZE_asm, %ecx
17689 + jb 3f
17690 + ud2
17691 +3:
17692 +
17693 + shr $2, %ecx
17694 + rep stosl
17695 +
17696 + mov TI_task_thread_sp0(%ebp), %edi
17697 + sub $128, %edi
17698 + mov %edi, TI_lowest_stack(%ebp)
17699 +
17700 + popl %eax
17701 + popl %ecx
17702 + popl %edi
17703 + ret
17704 +ENDPROC(pax_erase_kstack)
17705 +#endif
17706 +
17707 +.macro __SAVE_ALL _DS
17708 cld
17709 PUSH_GS
17710 pushl_cfi %fs
17711 @@ -206,7 +346,7 @@
17712 CFI_REL_OFFSET ecx, 0
17713 pushl_cfi %ebx
17714 CFI_REL_OFFSET ebx, 0
17715 - movl $(__USER_DS), %edx
17716 + movl $\_DS, %edx
17717 movl %edx, %ds
17718 movl %edx, %es
17719 movl $(__KERNEL_PERCPU), %edx
17720 @@ -214,6 +354,15 @@
17721 SET_KERNEL_GS %edx
17722 .endm
17723
17724 +.macro SAVE_ALL
17725 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
17726 + __SAVE_ALL __KERNEL_DS
17727 + pax_enter_kernel
17728 +#else
17729 + __SAVE_ALL __USER_DS
17730 +#endif
17731 +.endm
17732 +
17733 .macro RESTORE_INT_REGS
17734 popl_cfi %ebx
17735 CFI_RESTORE ebx
17736 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
17737 popfl_cfi
17738 jmp syscall_exit
17739 CFI_ENDPROC
17740 -END(ret_from_fork)
17741 +ENDPROC(ret_from_fork)
17742
17743 ENTRY(ret_from_kernel_thread)
17744 CFI_STARTPROC
17745 @@ -344,7 +493,15 @@ ret_from_intr:
17746 andl $SEGMENT_RPL_MASK, %eax
17747 #endif
17748 cmpl $USER_RPL, %eax
17749 +
17750 +#ifdef CONFIG_PAX_KERNEXEC
17751 + jae resume_userspace
17752 +
17753 + pax_exit_kernel
17754 + jmp resume_kernel
17755 +#else
17756 jb resume_kernel # not returning to v8086 or userspace
17757 +#endif
17758
17759 ENTRY(resume_userspace)
17760 LOCKDEP_SYS_EXIT
17761 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
17762 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
17763 # int/exception return?
17764 jne work_pending
17765 - jmp restore_all
17766 -END(ret_from_exception)
17767 + jmp restore_all_pax
17768 +ENDPROC(ret_from_exception)
17769
17770 #ifdef CONFIG_PREEMPT
17771 ENTRY(resume_kernel)
17772 @@ -372,7 +529,7 @@ need_resched:
17773 jz restore_all
17774 call preempt_schedule_irq
17775 jmp need_resched
17776 -END(resume_kernel)
17777 +ENDPROC(resume_kernel)
17778 #endif
17779 CFI_ENDPROC
17780 /*
17781 @@ -406,30 +563,45 @@ sysenter_past_esp:
17782 /*CFI_REL_OFFSET cs, 0*/
17783 /*
17784 * Push current_thread_info()->sysenter_return to the stack.
17785 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
17786 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
17787 */
17788 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
17789 + pushl_cfi $0
17790 CFI_REL_OFFSET eip, 0
17791
17792 pushl_cfi %eax
17793 SAVE_ALL
17794 + GET_THREAD_INFO(%ebp)
17795 + movl TI_sysenter_return(%ebp),%ebp
17796 + movl %ebp,PT_EIP(%esp)
17797 ENABLE_INTERRUPTS(CLBR_NONE)
17798
17799 /*
17800 * Load the potential sixth argument from user stack.
17801 * Careful about security.
17802 */
17803 + movl PT_OLDESP(%esp),%ebp
17804 +
17805 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17806 + mov PT_OLDSS(%esp),%ds
17807 +1: movl %ds:(%ebp),%ebp
17808 + push %ss
17809 + pop %ds
17810 +#else
17811 cmpl $__PAGE_OFFSET-3,%ebp
17812 jae syscall_fault
17813 ASM_STAC
17814 1: movl (%ebp),%ebp
17815 ASM_CLAC
17816 +#endif
17817 +
17818 movl %ebp,PT_EBP(%esp)
17819 _ASM_EXTABLE(1b,syscall_fault)
17820
17821 GET_THREAD_INFO(%ebp)
17822
17823 +#ifdef CONFIG_PAX_RANDKSTACK
17824 + pax_erase_kstack
17825 +#endif
17826 +
17827 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17828 jnz sysenter_audit
17829 sysenter_do_call:
17830 @@ -444,12 +616,24 @@ sysenter_do_call:
17831 testl $_TIF_ALLWORK_MASK, %ecx
17832 jne sysexit_audit
17833 sysenter_exit:
17834 +
17835 +#ifdef CONFIG_PAX_RANDKSTACK
17836 + pushl_cfi %eax
17837 + movl %esp, %eax
17838 + call pax_randomize_kstack
17839 + popl_cfi %eax
17840 +#endif
17841 +
17842 + pax_erase_kstack
17843 +
17844 /* if something modifies registers it must also disable sysexit */
17845 movl PT_EIP(%esp), %edx
17846 movl PT_OLDESP(%esp), %ecx
17847 xorl %ebp,%ebp
17848 TRACE_IRQS_ON
17849 1: mov PT_FS(%esp), %fs
17850 +2: mov PT_DS(%esp), %ds
17851 +3: mov PT_ES(%esp), %es
17852 PTGS_TO_GS
17853 ENABLE_INTERRUPTS_SYSEXIT
17854
17855 @@ -466,6 +650,9 @@ sysenter_audit:
17856 movl %eax,%edx /* 2nd arg: syscall number */
17857 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
17858 call __audit_syscall_entry
17859 +
17860 + pax_erase_kstack
17861 +
17862 pushl_cfi %ebx
17863 movl PT_EAX(%esp),%eax /* reload syscall number */
17864 jmp sysenter_do_call
17865 @@ -491,10 +678,16 @@ sysexit_audit:
17866
17867 CFI_ENDPROC
17868 .pushsection .fixup,"ax"
17869 -2: movl $0,PT_FS(%esp)
17870 +4: movl $0,PT_FS(%esp)
17871 + jmp 1b
17872 +5: movl $0,PT_DS(%esp)
17873 + jmp 1b
17874 +6: movl $0,PT_ES(%esp)
17875 jmp 1b
17876 .popsection
17877 - _ASM_EXTABLE(1b,2b)
17878 + _ASM_EXTABLE(1b,4b)
17879 + _ASM_EXTABLE(2b,5b)
17880 + _ASM_EXTABLE(3b,6b)
17881 PTGS_TO_GS_EX
17882 ENDPROC(ia32_sysenter_target)
17883
17884 @@ -509,6 +702,11 @@ ENTRY(system_call)
17885 pushl_cfi %eax # save orig_eax
17886 SAVE_ALL
17887 GET_THREAD_INFO(%ebp)
17888 +
17889 +#ifdef CONFIG_PAX_RANDKSTACK
17890 + pax_erase_kstack
17891 +#endif
17892 +
17893 # system call tracing in operation / emulation
17894 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
17895 jnz syscall_trace_entry
17896 @@ -527,6 +725,15 @@ syscall_exit:
17897 testl $_TIF_ALLWORK_MASK, %ecx # current->work
17898 jne syscall_exit_work
17899
17900 +restore_all_pax:
17901 +
17902 +#ifdef CONFIG_PAX_RANDKSTACK
17903 + movl %esp, %eax
17904 + call pax_randomize_kstack
17905 +#endif
17906 +
17907 + pax_erase_kstack
17908 +
17909 restore_all:
17910 TRACE_IRQS_IRET
17911 restore_all_notrace:
17912 @@ -583,14 +790,34 @@ ldt_ss:
17913 * compensating for the offset by changing to the ESPFIX segment with
17914 * a base address that matches for the difference.
17915 */
17916 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
17917 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
17918 mov %esp, %edx /* load kernel esp */
17919 mov PT_OLDESP(%esp), %eax /* load userspace esp */
17920 mov %dx, %ax /* eax: new kernel esp */
17921 sub %eax, %edx /* offset (low word is 0) */
17922 +#ifdef CONFIG_SMP
17923 + movl PER_CPU_VAR(cpu_number), %ebx
17924 + shll $PAGE_SHIFT_asm, %ebx
17925 + addl $cpu_gdt_table, %ebx
17926 +#else
17927 + movl $cpu_gdt_table, %ebx
17928 +#endif
17929 shr $16, %edx
17930 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
17931 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
17932 +
17933 +#ifdef CONFIG_PAX_KERNEXEC
17934 + mov %cr0, %esi
17935 + btr $16, %esi
17936 + mov %esi, %cr0
17937 +#endif
17938 +
17939 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
17940 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
17941 +
17942 +#ifdef CONFIG_PAX_KERNEXEC
17943 + bts $16, %esi
17944 + mov %esi, %cr0
17945 +#endif
17946 +
17947 pushl_cfi $__ESPFIX_SS
17948 pushl_cfi %eax /* new kernel esp */
17949 /* Disable interrupts, but do not irqtrace this section: we
17950 @@ -619,20 +846,18 @@ work_resched:
17951 movl TI_flags(%ebp), %ecx
17952 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
17953 # than syscall tracing?
17954 - jz restore_all
17955 + jz restore_all_pax
17956 testb $_TIF_NEED_RESCHED, %cl
17957 jnz work_resched
17958
17959 work_notifysig: # deal with pending signals and
17960 # notify-resume requests
17961 + movl %esp, %eax
17962 #ifdef CONFIG_VM86
17963 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
17964 - movl %esp, %eax
17965 jne work_notifysig_v86 # returning to kernel-space or
17966 # vm86-space
17967 1:
17968 -#else
17969 - movl %esp, %eax
17970 #endif
17971 TRACE_IRQS_ON
17972 ENABLE_INTERRUPTS(CLBR_NONE)
17973 @@ -653,7 +878,7 @@ work_notifysig_v86:
17974 movl %eax, %esp
17975 jmp 1b
17976 #endif
17977 -END(work_pending)
17978 +ENDPROC(work_pending)
17979
17980 # perform syscall exit tracing
17981 ALIGN
17982 @@ -661,11 +886,14 @@ syscall_trace_entry:
17983 movl $-ENOSYS,PT_EAX(%esp)
17984 movl %esp, %eax
17985 call syscall_trace_enter
17986 +
17987 + pax_erase_kstack
17988 +
17989 /* What it returned is what we'll actually use. */
17990 cmpl $(NR_syscalls), %eax
17991 jnae syscall_call
17992 jmp syscall_exit
17993 -END(syscall_trace_entry)
17994 +ENDPROC(syscall_trace_entry)
17995
17996 # perform syscall exit tracing
17997 ALIGN
17998 @@ -678,21 +906,25 @@ syscall_exit_work:
17999 movl %esp, %eax
18000 call syscall_trace_leave
18001 jmp resume_userspace
18002 -END(syscall_exit_work)
18003 +ENDPROC(syscall_exit_work)
18004 CFI_ENDPROC
18005
18006 RING0_INT_FRAME # can't unwind into user space anyway
18007 syscall_fault:
18008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18009 + push %ss
18010 + pop %ds
18011 +#endif
18012 ASM_CLAC
18013 GET_THREAD_INFO(%ebp)
18014 movl $-EFAULT,PT_EAX(%esp)
18015 jmp resume_userspace
18016 -END(syscall_fault)
18017 +ENDPROC(syscall_fault)
18018
18019 syscall_badsys:
18020 movl $-ENOSYS,PT_EAX(%esp)
18021 jmp resume_userspace
18022 -END(syscall_badsys)
18023 +ENDPROC(syscall_badsys)
18024 CFI_ENDPROC
18025 /*
18026 * End of kprobes section
18027 @@ -753,8 +985,15 @@ PTREGSCALL1(vm86old)
18028 * normal stack and adjusts ESP with the matching offset.
18029 */
18030 /* fixup the stack */
18031 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18032 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18033 +#ifdef CONFIG_SMP
18034 + movl PER_CPU_VAR(cpu_number), %ebx
18035 + shll $PAGE_SHIFT_asm, %ebx
18036 + addl $cpu_gdt_table, %ebx
18037 +#else
18038 + movl $cpu_gdt_table, %ebx
18039 +#endif
18040 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18041 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18042 shl $16, %eax
18043 addl %esp, %eax /* the adjusted stack pointer */
18044 pushl_cfi $__KERNEL_DS
18045 @@ -807,7 +1046,7 @@ vector=vector+1
18046 .endr
18047 2: jmp common_interrupt
18048 .endr
18049 -END(irq_entries_start)
18050 +ENDPROC(irq_entries_start)
18051
18052 .previous
18053 END(interrupt)
18054 @@ -858,7 +1097,7 @@ ENTRY(coprocessor_error)
18055 pushl_cfi $do_coprocessor_error
18056 jmp error_code
18057 CFI_ENDPROC
18058 -END(coprocessor_error)
18059 +ENDPROC(coprocessor_error)
18060
18061 ENTRY(simd_coprocessor_error)
18062 RING0_INT_FRAME
18063 @@ -880,7 +1119,7 @@ ENTRY(simd_coprocessor_error)
18064 #endif
18065 jmp error_code
18066 CFI_ENDPROC
18067 -END(simd_coprocessor_error)
18068 +ENDPROC(simd_coprocessor_error)
18069
18070 ENTRY(device_not_available)
18071 RING0_INT_FRAME
18072 @@ -889,18 +1128,18 @@ ENTRY(device_not_available)
18073 pushl_cfi $do_device_not_available
18074 jmp error_code
18075 CFI_ENDPROC
18076 -END(device_not_available)
18077 +ENDPROC(device_not_available)
18078
18079 #ifdef CONFIG_PARAVIRT
18080 ENTRY(native_iret)
18081 iret
18082 _ASM_EXTABLE(native_iret, iret_exc)
18083 -END(native_iret)
18084 +ENDPROC(native_iret)
18085
18086 ENTRY(native_irq_enable_sysexit)
18087 sti
18088 sysexit
18089 -END(native_irq_enable_sysexit)
18090 +ENDPROC(native_irq_enable_sysexit)
18091 #endif
18092
18093 ENTRY(overflow)
18094 @@ -910,7 +1149,7 @@ ENTRY(overflow)
18095 pushl_cfi $do_overflow
18096 jmp error_code
18097 CFI_ENDPROC
18098 -END(overflow)
18099 +ENDPROC(overflow)
18100
18101 ENTRY(bounds)
18102 RING0_INT_FRAME
18103 @@ -919,7 +1158,7 @@ ENTRY(bounds)
18104 pushl_cfi $do_bounds
18105 jmp error_code
18106 CFI_ENDPROC
18107 -END(bounds)
18108 +ENDPROC(bounds)
18109
18110 ENTRY(invalid_op)
18111 RING0_INT_FRAME
18112 @@ -928,7 +1167,7 @@ ENTRY(invalid_op)
18113 pushl_cfi $do_invalid_op
18114 jmp error_code
18115 CFI_ENDPROC
18116 -END(invalid_op)
18117 +ENDPROC(invalid_op)
18118
18119 ENTRY(coprocessor_segment_overrun)
18120 RING0_INT_FRAME
18121 @@ -937,7 +1176,7 @@ ENTRY(coprocessor_segment_overrun)
18122 pushl_cfi $do_coprocessor_segment_overrun
18123 jmp error_code
18124 CFI_ENDPROC
18125 -END(coprocessor_segment_overrun)
18126 +ENDPROC(coprocessor_segment_overrun)
18127
18128 ENTRY(invalid_TSS)
18129 RING0_EC_FRAME
18130 @@ -945,7 +1184,7 @@ ENTRY(invalid_TSS)
18131 pushl_cfi $do_invalid_TSS
18132 jmp error_code
18133 CFI_ENDPROC
18134 -END(invalid_TSS)
18135 +ENDPROC(invalid_TSS)
18136
18137 ENTRY(segment_not_present)
18138 RING0_EC_FRAME
18139 @@ -953,7 +1192,7 @@ ENTRY(segment_not_present)
18140 pushl_cfi $do_segment_not_present
18141 jmp error_code
18142 CFI_ENDPROC
18143 -END(segment_not_present)
18144 +ENDPROC(segment_not_present)
18145
18146 ENTRY(stack_segment)
18147 RING0_EC_FRAME
18148 @@ -961,7 +1200,7 @@ ENTRY(stack_segment)
18149 pushl_cfi $do_stack_segment
18150 jmp error_code
18151 CFI_ENDPROC
18152 -END(stack_segment)
18153 +ENDPROC(stack_segment)
18154
18155 ENTRY(alignment_check)
18156 RING0_EC_FRAME
18157 @@ -969,7 +1208,7 @@ ENTRY(alignment_check)
18158 pushl_cfi $do_alignment_check
18159 jmp error_code
18160 CFI_ENDPROC
18161 -END(alignment_check)
18162 +ENDPROC(alignment_check)
18163
18164 ENTRY(divide_error)
18165 RING0_INT_FRAME
18166 @@ -978,7 +1217,7 @@ ENTRY(divide_error)
18167 pushl_cfi $do_divide_error
18168 jmp error_code
18169 CFI_ENDPROC
18170 -END(divide_error)
18171 +ENDPROC(divide_error)
18172
18173 #ifdef CONFIG_X86_MCE
18174 ENTRY(machine_check)
18175 @@ -988,7 +1227,7 @@ ENTRY(machine_check)
18176 pushl_cfi machine_check_vector
18177 jmp error_code
18178 CFI_ENDPROC
18179 -END(machine_check)
18180 +ENDPROC(machine_check)
18181 #endif
18182
18183 ENTRY(spurious_interrupt_bug)
18184 @@ -998,7 +1237,7 @@ ENTRY(spurious_interrupt_bug)
18185 pushl_cfi $do_spurious_interrupt_bug
18186 jmp error_code
18187 CFI_ENDPROC
18188 -END(spurious_interrupt_bug)
18189 +ENDPROC(spurious_interrupt_bug)
18190 /*
18191 * End of kprobes section
18192 */
18193 @@ -1101,7 +1340,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
18194
18195 ENTRY(mcount)
18196 ret
18197 -END(mcount)
18198 +ENDPROC(mcount)
18199
18200 ENTRY(ftrace_caller)
18201 cmpl $0, function_trace_stop
18202 @@ -1134,7 +1373,7 @@ ftrace_graph_call:
18203 .globl ftrace_stub
18204 ftrace_stub:
18205 ret
18206 -END(ftrace_caller)
18207 +ENDPROC(ftrace_caller)
18208
18209 ENTRY(ftrace_regs_caller)
18210 pushf /* push flags before compare (in cs location) */
18211 @@ -1235,7 +1474,7 @@ trace:
18212 popl %ecx
18213 popl %eax
18214 jmp ftrace_stub
18215 -END(mcount)
18216 +ENDPROC(mcount)
18217 #endif /* CONFIG_DYNAMIC_FTRACE */
18218 #endif /* CONFIG_FUNCTION_TRACER */
18219
18220 @@ -1253,7 +1492,7 @@ ENTRY(ftrace_graph_caller)
18221 popl %ecx
18222 popl %eax
18223 ret
18224 -END(ftrace_graph_caller)
18225 +ENDPROC(ftrace_graph_caller)
18226
18227 .globl return_to_handler
18228 return_to_handler:
18229 @@ -1309,15 +1548,18 @@ error_code:
18230 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18231 REG_TO_PTGS %ecx
18232 SET_KERNEL_GS %ecx
18233 - movl $(__USER_DS), %ecx
18234 + movl $(__KERNEL_DS), %ecx
18235 movl %ecx, %ds
18236 movl %ecx, %es
18237 +
18238 + pax_enter_kernel
18239 +
18240 TRACE_IRQS_OFF
18241 movl %esp,%eax # pt_regs pointer
18242 call *%edi
18243 jmp ret_from_exception
18244 CFI_ENDPROC
18245 -END(page_fault)
18246 +ENDPROC(page_fault)
18247
18248 /*
18249 * Debug traps and NMI can happen at the one SYSENTER instruction
18250 @@ -1360,7 +1602,7 @@ debug_stack_correct:
18251 call do_debug
18252 jmp ret_from_exception
18253 CFI_ENDPROC
18254 -END(debug)
18255 +ENDPROC(debug)
18256
18257 /*
18258 * NMI is doubly nasty. It can happen _while_ we're handling
18259 @@ -1398,6 +1640,9 @@ nmi_stack_correct:
18260 xorl %edx,%edx # zero error code
18261 movl %esp,%eax # pt_regs pointer
18262 call do_nmi
18263 +
18264 + pax_exit_kernel
18265 +
18266 jmp restore_all_notrace
18267 CFI_ENDPROC
18268
18269 @@ -1434,12 +1679,15 @@ nmi_espfix_stack:
18270 FIXUP_ESPFIX_STACK # %eax == %esp
18271 xorl %edx,%edx # zero error code
18272 call do_nmi
18273 +
18274 + pax_exit_kernel
18275 +
18276 RESTORE_REGS
18277 lss 12+4(%esp), %esp # back to espfix stack
18278 CFI_ADJUST_CFA_OFFSET -24
18279 jmp irq_return
18280 CFI_ENDPROC
18281 -END(nmi)
18282 +ENDPROC(nmi)
18283
18284 ENTRY(int3)
18285 RING0_INT_FRAME
18286 @@ -1452,14 +1700,14 @@ ENTRY(int3)
18287 call do_int3
18288 jmp ret_from_exception
18289 CFI_ENDPROC
18290 -END(int3)
18291 +ENDPROC(int3)
18292
18293 ENTRY(general_protection)
18294 RING0_EC_FRAME
18295 pushl_cfi $do_general_protection
18296 jmp error_code
18297 CFI_ENDPROC
18298 -END(general_protection)
18299 +ENDPROC(general_protection)
18300
18301 #ifdef CONFIG_KVM_GUEST
18302 ENTRY(async_page_fault)
18303 @@ -1468,7 +1716,7 @@ ENTRY(async_page_fault)
18304 pushl_cfi $do_async_page_fault
18305 jmp error_code
18306 CFI_ENDPROC
18307 -END(async_page_fault)
18308 +ENDPROC(async_page_fault)
18309 #endif
18310
18311 /*
18312 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18313 index cb3c591..bc63707 100644
18314 --- a/arch/x86/kernel/entry_64.S
18315 +++ b/arch/x86/kernel/entry_64.S
18316 @@ -59,6 +59,8 @@
18317 #include <asm/context_tracking.h>
18318 #include <asm/smap.h>
18319 #include <linux/err.h>
18320 +#include <asm/pgtable.h>
18321 +#include <asm/alternative-asm.h>
18322
18323 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
18324 #include <linux/elf-em.h>
18325 @@ -80,8 +82,9 @@
18326 #ifdef CONFIG_DYNAMIC_FTRACE
18327
18328 ENTRY(function_hook)
18329 + pax_force_retaddr
18330 retq
18331 -END(function_hook)
18332 +ENDPROC(function_hook)
18333
18334 /* skip is set if stack has been adjusted */
18335 .macro ftrace_caller_setup skip=0
18336 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
18337 #endif
18338
18339 GLOBAL(ftrace_stub)
18340 + pax_force_retaddr
18341 retq
18342 -END(ftrace_caller)
18343 +ENDPROC(ftrace_caller)
18344
18345 ENTRY(ftrace_regs_caller)
18346 /* Save the current flags before compare (in SS location)*/
18347 @@ -191,7 +195,7 @@ ftrace_restore_flags:
18348 popfq
18349 jmp ftrace_stub
18350
18351 -END(ftrace_regs_caller)
18352 +ENDPROC(ftrace_regs_caller)
18353
18354
18355 #else /* ! CONFIG_DYNAMIC_FTRACE */
18356 @@ -212,6 +216,7 @@ ENTRY(function_hook)
18357 #endif
18358
18359 GLOBAL(ftrace_stub)
18360 + pax_force_retaddr
18361 retq
18362
18363 trace:
18364 @@ -225,12 +230,13 @@ trace:
18365 #endif
18366 subq $MCOUNT_INSN_SIZE, %rdi
18367
18368 + pax_force_fptr ftrace_trace_function
18369 call *ftrace_trace_function
18370
18371 MCOUNT_RESTORE_FRAME
18372
18373 jmp ftrace_stub
18374 -END(function_hook)
18375 +ENDPROC(function_hook)
18376 #endif /* CONFIG_DYNAMIC_FTRACE */
18377 #endif /* CONFIG_FUNCTION_TRACER */
18378
18379 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
18380
18381 MCOUNT_RESTORE_FRAME
18382
18383 + pax_force_retaddr
18384 retq
18385 -END(ftrace_graph_caller)
18386 +ENDPROC(ftrace_graph_caller)
18387
18388 GLOBAL(return_to_handler)
18389 subq $24, %rsp
18390 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
18391 movq 8(%rsp), %rdx
18392 movq (%rsp), %rax
18393 addq $24, %rsp
18394 + pax_force_fptr %rdi
18395 jmp *%rdi
18396 +ENDPROC(return_to_handler)
18397 #endif
18398
18399
18400 @@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
18401 ENDPROC(native_usergs_sysret64)
18402 #endif /* CONFIG_PARAVIRT */
18403
18404 + .macro ljmpq sel, off
18405 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
18406 + .byte 0x48; ljmp *1234f(%rip)
18407 + .pushsection .rodata
18408 + .align 16
18409 + 1234: .quad \off; .word \sel
18410 + .popsection
18411 +#else
18412 + pushq $\sel
18413 + pushq $\off
18414 + lretq
18415 +#endif
18416 + .endm
18417 +
18418 + .macro pax_enter_kernel
18419 + pax_set_fptr_mask
18420 +#ifdef CONFIG_PAX_KERNEXEC
18421 + call pax_enter_kernel
18422 +#endif
18423 + .endm
18424 +
18425 + .macro pax_exit_kernel
18426 +#ifdef CONFIG_PAX_KERNEXEC
18427 + call pax_exit_kernel
18428 +#endif
18429 + .endm
18430 +
18431 +#ifdef CONFIG_PAX_KERNEXEC
18432 +ENTRY(pax_enter_kernel)
18433 + pushq %rdi
18434 +
18435 +#ifdef CONFIG_PARAVIRT
18436 + PV_SAVE_REGS(CLBR_RDI)
18437 +#endif
18438 +
18439 + GET_CR0_INTO_RDI
18440 + bts $16,%rdi
18441 + jnc 3f
18442 + mov %cs,%edi
18443 + cmp $__KERNEL_CS,%edi
18444 + jnz 2f
18445 +1:
18446 +
18447 +#ifdef CONFIG_PARAVIRT
18448 + PV_RESTORE_REGS(CLBR_RDI)
18449 +#endif
18450 +
18451 + popq %rdi
18452 + pax_force_retaddr
18453 + retq
18454 +
18455 +2: ljmpq __KERNEL_CS,1f
18456 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
18457 +4: SET_RDI_INTO_CR0
18458 + jmp 1b
18459 +ENDPROC(pax_enter_kernel)
18460 +
18461 +ENTRY(pax_exit_kernel)
18462 + pushq %rdi
18463 +
18464 +#ifdef CONFIG_PARAVIRT
18465 + PV_SAVE_REGS(CLBR_RDI)
18466 +#endif
18467 +
18468 + mov %cs,%rdi
18469 + cmp $__KERNEXEC_KERNEL_CS,%edi
18470 + jz 2f
18471 +1:
18472 +
18473 +#ifdef CONFIG_PARAVIRT
18474 + PV_RESTORE_REGS(CLBR_RDI);
18475 +#endif
18476 +
18477 + popq %rdi
18478 + pax_force_retaddr
18479 + retq
18480 +
18481 +2: GET_CR0_INTO_RDI
18482 + btr $16,%rdi
18483 + ljmpq __KERNEL_CS,3f
18484 +3: SET_RDI_INTO_CR0
18485 + jmp 1b
18486 +ENDPROC(pax_exit_kernel)
18487 +#endif
18488 +
18489 + .macro pax_enter_kernel_user
18490 + pax_set_fptr_mask
18491 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18492 + call pax_enter_kernel_user
18493 +#endif
18494 + .endm
18495 +
18496 + .macro pax_exit_kernel_user
18497 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18498 + call pax_exit_kernel_user
18499 +#endif
18500 +#ifdef CONFIG_PAX_RANDKSTACK
18501 + pushq %rax
18502 + call pax_randomize_kstack
18503 + popq %rax
18504 +#endif
18505 + .endm
18506 +
18507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18508 +ENTRY(pax_enter_kernel_user)
18509 + pushq %rdi
18510 + pushq %rbx
18511 +
18512 +#ifdef CONFIG_PARAVIRT
18513 + PV_SAVE_REGS(CLBR_RDI)
18514 +#endif
18515 +
18516 + GET_CR3_INTO_RDI
18517 + mov %rdi,%rbx
18518 + add $__START_KERNEL_map,%rbx
18519 + sub phys_base(%rip),%rbx
18520 +
18521 +#ifdef CONFIG_PARAVIRT
18522 + pushq %rdi
18523 + cmpl $0, pv_info+PARAVIRT_enabled
18524 + jz 1f
18525 + i = 0
18526 + .rept USER_PGD_PTRS
18527 + mov i*8(%rbx),%rsi
18528 + mov $0,%sil
18529 + lea i*8(%rbx),%rdi
18530 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18531 + i = i + 1
18532 + .endr
18533 + jmp 2f
18534 +1:
18535 +#endif
18536 +
18537 + i = 0
18538 + .rept USER_PGD_PTRS
18539 + movb $0,i*8(%rbx)
18540 + i = i + 1
18541 + .endr
18542 +
18543 +#ifdef CONFIG_PARAVIRT
18544 +2: popq %rdi
18545 +#endif
18546 + SET_RDI_INTO_CR3
18547 +
18548 +#ifdef CONFIG_PAX_KERNEXEC
18549 + GET_CR0_INTO_RDI
18550 + bts $16,%rdi
18551 + SET_RDI_INTO_CR0
18552 +#endif
18553 +
18554 +#ifdef CONFIG_PARAVIRT
18555 + PV_RESTORE_REGS(CLBR_RDI)
18556 +#endif
18557 +
18558 + popq %rbx
18559 + popq %rdi
18560 + pax_force_retaddr
18561 + retq
18562 +ENDPROC(pax_enter_kernel_user)
18563 +
18564 +ENTRY(pax_exit_kernel_user)
18565 + push %rdi
18566 +
18567 +#ifdef CONFIG_PARAVIRT
18568 + pushq %rbx
18569 + PV_SAVE_REGS(CLBR_RDI)
18570 +#endif
18571 +
18572 +#ifdef CONFIG_PAX_KERNEXEC
18573 + GET_CR0_INTO_RDI
18574 + btr $16,%rdi
18575 + SET_RDI_INTO_CR0
18576 +#endif
18577 +
18578 + GET_CR3_INTO_RDI
18579 + add $__START_KERNEL_map,%rdi
18580 + sub phys_base(%rip),%rdi
18581 +
18582 +#ifdef CONFIG_PARAVIRT
18583 + cmpl $0, pv_info+PARAVIRT_enabled
18584 + jz 1f
18585 + mov %rdi,%rbx
18586 + i = 0
18587 + .rept USER_PGD_PTRS
18588 + mov i*8(%rbx),%rsi
18589 + mov $0x67,%sil
18590 + lea i*8(%rbx),%rdi
18591 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
18592 + i = i + 1
18593 + .endr
18594 + jmp 2f
18595 +1:
18596 +#endif
18597 +
18598 + i = 0
18599 + .rept USER_PGD_PTRS
18600 + movb $0x67,i*8(%rdi)
18601 + i = i + 1
18602 + .endr
18603 +
18604 +#ifdef CONFIG_PARAVIRT
18605 +2: PV_RESTORE_REGS(CLBR_RDI)
18606 + popq %rbx
18607 +#endif
18608 +
18609 + popq %rdi
18610 + pax_force_retaddr
18611 + retq
18612 +ENDPROC(pax_exit_kernel_user)
18613 +#endif
18614 +
18615 +.macro pax_erase_kstack
18616 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18617 + call pax_erase_kstack
18618 +#endif
18619 +.endm
18620 +
18621 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18622 +ENTRY(pax_erase_kstack)
18623 + pushq %rdi
18624 + pushq %rcx
18625 + pushq %rax
18626 + pushq %r11
18627 +
18628 + GET_THREAD_INFO(%r11)
18629 + mov TI_lowest_stack(%r11), %rdi
18630 + mov $-0xBEEF, %rax
18631 + std
18632 +
18633 +1: mov %edi, %ecx
18634 + and $THREAD_SIZE_asm - 1, %ecx
18635 + shr $3, %ecx
18636 + repne scasq
18637 + jecxz 2f
18638 +
18639 + cmp $2*8, %ecx
18640 + jc 2f
18641 +
18642 + mov $2*8, %ecx
18643 + repe scasq
18644 + jecxz 2f
18645 + jne 1b
18646 +
18647 +2: cld
18648 + mov %esp, %ecx
18649 + sub %edi, %ecx
18650 +
18651 + cmp $THREAD_SIZE_asm, %rcx
18652 + jb 3f
18653 + ud2
18654 +3:
18655 +
18656 + shr $3, %ecx
18657 + rep stosq
18658 +
18659 + mov TI_task_thread_sp0(%r11), %rdi
18660 + sub $256, %rdi
18661 + mov %rdi, TI_lowest_stack(%r11)
18662 +
18663 + popq %r11
18664 + popq %rax
18665 + popq %rcx
18666 + popq %rdi
18667 + pax_force_retaddr
18668 + ret
18669 +ENDPROC(pax_erase_kstack)
18670 +#endif
18671
18672 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
18673 #ifdef CONFIG_TRACE_IRQFLAGS
18674 @@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
18675 .endm
18676
18677 .macro UNFAKE_STACK_FRAME
18678 - addq $8*6, %rsp
18679 - CFI_ADJUST_CFA_OFFSET -(6*8)
18680 + addq $8*6 + ARG_SKIP, %rsp
18681 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
18682 .endm
18683
18684 /*
18685 @@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
18686 movq %rsp, %rsi
18687
18688 leaq -RBP(%rsp),%rdi /* arg1 for handler */
18689 - testl $3, CS-RBP(%rsi)
18690 + testb $3, CS-RBP(%rsi)
18691 je 1f
18692 SWAPGS
18693 /*
18694 @@ -498,9 +774,10 @@ ENTRY(save_rest)
18695 movq_cfi r15, R15+16
18696 movq %r11, 8(%rsp) /* return address */
18697 FIXUP_TOP_OF_STACK %r11, 16
18698 + pax_force_retaddr
18699 ret
18700 CFI_ENDPROC
18701 -END(save_rest)
18702 +ENDPROC(save_rest)
18703
18704 /* save complete stack frame */
18705 .pushsection .kprobes.text, "ax"
18706 @@ -529,9 +806,10 @@ ENTRY(save_paranoid)
18707 js 1f /* negative -> in kernel */
18708 SWAPGS
18709 xorl %ebx,%ebx
18710 -1: ret
18711 +1: pax_force_retaddr_bts
18712 + ret
18713 CFI_ENDPROC
18714 -END(save_paranoid)
18715 +ENDPROC(save_paranoid)
18716 .popsection
18717
18718 /*
18719 @@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
18720
18721 RESTORE_REST
18722
18723 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18724 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
18725 jz 1f
18726
18727 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
18728 @@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
18729 RESTORE_REST
18730 jmp int_ret_from_sys_call
18731 CFI_ENDPROC
18732 -END(ret_from_fork)
18733 +ENDPROC(ret_from_fork)
18734
18735 /*
18736 * System call entry. Up to 6 arguments in registers are supported.
18737 @@ -608,7 +886,7 @@ END(ret_from_fork)
18738 ENTRY(system_call)
18739 CFI_STARTPROC simple
18740 CFI_SIGNAL_FRAME
18741 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
18742 + CFI_DEF_CFA rsp,0
18743 CFI_REGISTER rip,rcx
18744 /*CFI_REGISTER rflags,r11*/
18745 SWAPGS_UNSAFE_STACK
18746 @@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
18747
18748 movq %rsp,PER_CPU_VAR(old_rsp)
18749 movq PER_CPU_VAR(kernel_stack),%rsp
18750 + SAVE_ARGS 8*6,0
18751 + pax_enter_kernel_user
18752 +
18753 +#ifdef CONFIG_PAX_RANDKSTACK
18754 + pax_erase_kstack
18755 +#endif
18756 +
18757 /*
18758 * No need to follow this irqs off/on section - it's straight
18759 * and short:
18760 */
18761 ENABLE_INTERRUPTS(CLBR_NONE)
18762 - SAVE_ARGS 8,0
18763 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
18764 movq %rcx,RIP-ARGOFFSET(%rsp)
18765 CFI_REL_OFFSET rip,RIP-ARGOFFSET
18766 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18767 + GET_THREAD_INFO(%rcx)
18768 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
18769 jnz tracesys
18770 system_call_fastpath:
18771 #if __SYSCALL_MASK == ~0
18772 @@ -640,7 +925,7 @@ system_call_fastpath:
18773 cmpl $__NR_syscall_max,%eax
18774 #endif
18775 ja badsys
18776 - movq %r10,%rcx
18777 + movq R10-ARGOFFSET(%rsp),%rcx
18778 call *sys_call_table(,%rax,8) # XXX: rip relative
18779 movq %rax,RAX-ARGOFFSET(%rsp)
18780 /*
18781 @@ -654,10 +939,13 @@ sysret_check:
18782 LOCKDEP_SYS_EXIT
18783 DISABLE_INTERRUPTS(CLBR_NONE)
18784 TRACE_IRQS_OFF
18785 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
18786 + GET_THREAD_INFO(%rcx)
18787 + movl TI_flags(%rcx),%edx
18788 andl %edi,%edx
18789 jnz sysret_careful
18790 CFI_REMEMBER_STATE
18791 + pax_exit_kernel_user
18792 + pax_erase_kstack
18793 /*
18794 * sysretq will re-enable interrupts:
18795 */
18796 @@ -709,14 +997,18 @@ badsys:
18797 * jump back to the normal fast path.
18798 */
18799 auditsys:
18800 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
18801 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
18802 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
18803 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
18804 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
18805 movq %rax,%rsi /* 2nd arg: syscall number */
18806 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
18807 call __audit_syscall_entry
18808 +
18809 + pax_erase_kstack
18810 +
18811 LOAD_ARGS 0 /* reload call-clobbered registers */
18812 + pax_set_fptr_mask
18813 jmp system_call_fastpath
18814
18815 /*
18816 @@ -737,7 +1029,7 @@ sysret_audit:
18817 /* Do syscall tracing */
18818 tracesys:
18819 #ifdef CONFIG_AUDITSYSCALL
18820 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
18821 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
18822 jz auditsys
18823 #endif
18824 SAVE_REST
18825 @@ -745,12 +1037,16 @@ tracesys:
18826 FIXUP_TOP_OF_STACK %rdi
18827 movq %rsp,%rdi
18828 call syscall_trace_enter
18829 +
18830 + pax_erase_kstack
18831 +
18832 /*
18833 * Reload arg registers from stack in case ptrace changed them.
18834 * We don't reload %rax because syscall_trace_enter() returned
18835 * the value it wants us to use in the table lookup.
18836 */
18837 LOAD_ARGS ARGOFFSET, 1
18838 + pax_set_fptr_mask
18839 RESTORE_REST
18840 #if __SYSCALL_MASK == ~0
18841 cmpq $__NR_syscall_max,%rax
18842 @@ -759,7 +1055,7 @@ tracesys:
18843 cmpl $__NR_syscall_max,%eax
18844 #endif
18845 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
18846 - movq %r10,%rcx /* fixup for C */
18847 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
18848 call *sys_call_table(,%rax,8)
18849 movq %rax,RAX-ARGOFFSET(%rsp)
18850 /* Use IRET because user could have changed frame */
18851 @@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
18852 andl %edi,%edx
18853 jnz int_careful
18854 andl $~TS_COMPAT,TI_status(%rcx)
18855 - jmp retint_swapgs
18856 + pax_exit_kernel_user
18857 + pax_erase_kstack
18858 + jmp retint_swapgs_pax
18859
18860 /* Either reschedule or signal or syscall exit tracking needed. */
18861 /* First do a reschedule test. */
18862 @@ -826,7 +1124,7 @@ int_restore_rest:
18863 TRACE_IRQS_OFF
18864 jmp int_with_check
18865 CFI_ENDPROC
18866 -END(system_call)
18867 +ENDPROC(system_call)
18868
18869 /*
18870 * Certain special system calls that need to save a complete full stack frame.
18871 @@ -842,7 +1140,7 @@ ENTRY(\label)
18872 call \func
18873 jmp ptregscall_common
18874 CFI_ENDPROC
18875 -END(\label)
18876 +ENDPROC(\label)
18877 .endm
18878
18879 .macro FORK_LIKE func
18880 @@ -856,9 +1154,10 @@ ENTRY(stub_\func)
18881 DEFAULT_FRAME 0 8 /* offset 8: return address */
18882 call sys_\func
18883 RESTORE_TOP_OF_STACK %r11, 8
18884 + pax_force_retaddr
18885 ret $REST_SKIP /* pop extended registers */
18886 CFI_ENDPROC
18887 -END(stub_\func)
18888 +ENDPROC(stub_\func)
18889 .endm
18890
18891 FORK_LIKE clone
18892 @@ -875,9 +1174,10 @@ ENTRY(ptregscall_common)
18893 movq_cfi_restore R12+8, r12
18894 movq_cfi_restore RBP+8, rbp
18895 movq_cfi_restore RBX+8, rbx
18896 + pax_force_retaddr
18897 ret $REST_SKIP /* pop extended registers */
18898 CFI_ENDPROC
18899 -END(ptregscall_common)
18900 +ENDPROC(ptregscall_common)
18901
18902 ENTRY(stub_execve)
18903 CFI_STARTPROC
18904 @@ -891,7 +1191,7 @@ ENTRY(stub_execve)
18905 RESTORE_REST
18906 jmp int_ret_from_sys_call
18907 CFI_ENDPROC
18908 -END(stub_execve)
18909 +ENDPROC(stub_execve)
18910
18911 /*
18912 * sigreturn is special because it needs to restore all registers on return.
18913 @@ -909,7 +1209,7 @@ ENTRY(stub_rt_sigreturn)
18914 RESTORE_REST
18915 jmp int_ret_from_sys_call
18916 CFI_ENDPROC
18917 -END(stub_rt_sigreturn)
18918 +ENDPROC(stub_rt_sigreturn)
18919
18920 #ifdef CONFIG_X86_X32_ABI
18921 ENTRY(stub_x32_rt_sigreturn)
18922 @@ -975,7 +1275,7 @@ vector=vector+1
18923 2: jmp common_interrupt
18924 .endr
18925 CFI_ENDPROC
18926 -END(irq_entries_start)
18927 +ENDPROC(irq_entries_start)
18928
18929 .previous
18930 END(interrupt)
18931 @@ -995,6 +1295,16 @@ END(interrupt)
18932 subq $ORIG_RAX-RBP, %rsp
18933 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
18934 SAVE_ARGS_IRQ
18935 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18936 + testb $3, CS(%rdi)
18937 + jnz 1f
18938 + pax_enter_kernel
18939 + jmp 2f
18940 +1: pax_enter_kernel_user
18941 +2:
18942 +#else
18943 + pax_enter_kernel
18944 +#endif
18945 call \func
18946 .endm
18947
18948 @@ -1027,7 +1337,7 @@ ret_from_intr:
18949
18950 exit_intr:
18951 GET_THREAD_INFO(%rcx)
18952 - testl $3,CS-ARGOFFSET(%rsp)
18953 + testb $3,CS-ARGOFFSET(%rsp)
18954 je retint_kernel
18955
18956 /* Interrupt came from user space */
18957 @@ -1049,12 +1359,16 @@ retint_swapgs: /* return to user-space */
18958 * The iretq could re-enable interrupts:
18959 */
18960 DISABLE_INTERRUPTS(CLBR_ANY)
18961 + pax_exit_kernel_user
18962 +retint_swapgs_pax:
18963 TRACE_IRQS_IRETQ
18964 SWAPGS
18965 jmp restore_args
18966
18967 retint_restore_args: /* return to kernel space */
18968 DISABLE_INTERRUPTS(CLBR_ANY)
18969 + pax_exit_kernel
18970 + pax_force_retaddr (RIP-ARGOFFSET)
18971 /*
18972 * The iretq could re-enable interrupts:
18973 */
18974 @@ -1137,7 +1451,7 @@ ENTRY(retint_kernel)
18975 #endif
18976
18977 CFI_ENDPROC
18978 -END(common_interrupt)
18979 +ENDPROC(common_interrupt)
18980 /*
18981 * End of kprobes section
18982 */
18983 @@ -1155,7 +1469,7 @@ ENTRY(\sym)
18984 interrupt \do_sym
18985 jmp ret_from_intr
18986 CFI_ENDPROC
18987 -END(\sym)
18988 +ENDPROC(\sym)
18989 .endm
18990
18991 #ifdef CONFIG_SMP
18992 @@ -1211,12 +1525,22 @@ ENTRY(\sym)
18993 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
18994 call error_entry
18995 DEFAULT_FRAME 0
18996 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18997 + testb $3, CS(%rsp)
18998 + jnz 1f
18999 + pax_enter_kernel
19000 + jmp 2f
19001 +1: pax_enter_kernel_user
19002 +2:
19003 +#else
19004 + pax_enter_kernel
19005 +#endif
19006 movq %rsp,%rdi /* pt_regs pointer */
19007 xorl %esi,%esi /* no error code */
19008 call \do_sym
19009 jmp error_exit /* %ebx: no swapgs flag */
19010 CFI_ENDPROC
19011 -END(\sym)
19012 +ENDPROC(\sym)
19013 .endm
19014
19015 .macro paranoidzeroentry sym do_sym
19016 @@ -1229,15 +1553,25 @@ ENTRY(\sym)
19017 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19018 call save_paranoid
19019 TRACE_IRQS_OFF
19020 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19021 + testb $3, CS(%rsp)
19022 + jnz 1f
19023 + pax_enter_kernel
19024 + jmp 2f
19025 +1: pax_enter_kernel_user
19026 +2:
19027 +#else
19028 + pax_enter_kernel
19029 +#endif
19030 movq %rsp,%rdi /* pt_regs pointer */
19031 xorl %esi,%esi /* no error code */
19032 call \do_sym
19033 jmp paranoid_exit /* %ebx: no swapgs flag */
19034 CFI_ENDPROC
19035 -END(\sym)
19036 +ENDPROC(\sym)
19037 .endm
19038
19039 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19040 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19041 .macro paranoidzeroentry_ist sym do_sym ist
19042 ENTRY(\sym)
19043 INTR_FRAME
19044 @@ -1248,14 +1582,30 @@ ENTRY(\sym)
19045 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19046 call save_paranoid
19047 TRACE_IRQS_OFF_DEBUG
19048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19049 + testb $3, CS(%rsp)
19050 + jnz 1f
19051 + pax_enter_kernel
19052 + jmp 2f
19053 +1: pax_enter_kernel_user
19054 +2:
19055 +#else
19056 + pax_enter_kernel
19057 +#endif
19058 movq %rsp,%rdi /* pt_regs pointer */
19059 xorl %esi,%esi /* no error code */
19060 +#ifdef CONFIG_SMP
19061 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19062 + lea init_tss(%r12), %r12
19063 +#else
19064 + lea init_tss(%rip), %r12
19065 +#endif
19066 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19067 call \do_sym
19068 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19069 jmp paranoid_exit /* %ebx: no swapgs flag */
19070 CFI_ENDPROC
19071 -END(\sym)
19072 +ENDPROC(\sym)
19073 .endm
19074
19075 .macro errorentry sym do_sym
19076 @@ -1267,13 +1617,23 @@ ENTRY(\sym)
19077 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19078 call error_entry
19079 DEFAULT_FRAME 0
19080 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19081 + testb $3, CS(%rsp)
19082 + jnz 1f
19083 + pax_enter_kernel
19084 + jmp 2f
19085 +1: pax_enter_kernel_user
19086 +2:
19087 +#else
19088 + pax_enter_kernel
19089 +#endif
19090 movq %rsp,%rdi /* pt_regs pointer */
19091 movq ORIG_RAX(%rsp),%rsi /* get error code */
19092 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19093 call \do_sym
19094 jmp error_exit /* %ebx: no swapgs flag */
19095 CFI_ENDPROC
19096 -END(\sym)
19097 +ENDPROC(\sym)
19098 .endm
19099
19100 /* error code is on the stack already */
19101 @@ -1287,13 +1647,23 @@ ENTRY(\sym)
19102 call save_paranoid
19103 DEFAULT_FRAME 0
19104 TRACE_IRQS_OFF
19105 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19106 + testb $3, CS(%rsp)
19107 + jnz 1f
19108 + pax_enter_kernel
19109 + jmp 2f
19110 +1: pax_enter_kernel_user
19111 +2:
19112 +#else
19113 + pax_enter_kernel
19114 +#endif
19115 movq %rsp,%rdi /* pt_regs pointer */
19116 movq ORIG_RAX(%rsp),%rsi /* get error code */
19117 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19118 call \do_sym
19119 jmp paranoid_exit /* %ebx: no swapgs flag */
19120 CFI_ENDPROC
19121 -END(\sym)
19122 +ENDPROC(\sym)
19123 .endm
19124
19125 zeroentry divide_error do_divide_error
19126 @@ -1323,9 +1693,10 @@ gs_change:
19127 2: mfence /* workaround */
19128 SWAPGS
19129 popfq_cfi
19130 + pax_force_retaddr
19131 ret
19132 CFI_ENDPROC
19133 -END(native_load_gs_index)
19134 +ENDPROC(native_load_gs_index)
19135
19136 _ASM_EXTABLE(gs_change,bad_gs)
19137 .section .fixup,"ax"
19138 @@ -1353,9 +1724,10 @@ ENTRY(call_softirq)
19139 CFI_DEF_CFA_REGISTER rsp
19140 CFI_ADJUST_CFA_OFFSET -8
19141 decl PER_CPU_VAR(irq_count)
19142 + pax_force_retaddr
19143 ret
19144 CFI_ENDPROC
19145 -END(call_softirq)
19146 +ENDPROC(call_softirq)
19147
19148 #ifdef CONFIG_XEN
19149 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19150 @@ -1393,7 +1765,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19151 decl PER_CPU_VAR(irq_count)
19152 jmp error_exit
19153 CFI_ENDPROC
19154 -END(xen_do_hypervisor_callback)
19155 +ENDPROC(xen_do_hypervisor_callback)
19156
19157 /*
19158 * Hypervisor uses this for application faults while it executes.
19159 @@ -1452,7 +1824,7 @@ ENTRY(xen_failsafe_callback)
19160 SAVE_ALL
19161 jmp error_exit
19162 CFI_ENDPROC
19163 -END(xen_failsafe_callback)
19164 +ENDPROC(xen_failsafe_callback)
19165
19166 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
19167 xen_hvm_callback_vector xen_evtchn_do_upcall
19168 @@ -1501,16 +1873,31 @@ ENTRY(paranoid_exit)
19169 TRACE_IRQS_OFF_DEBUG
19170 testl %ebx,%ebx /* swapgs needed? */
19171 jnz paranoid_restore
19172 - testl $3,CS(%rsp)
19173 + testb $3,CS(%rsp)
19174 jnz paranoid_userspace
19175 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19176 + pax_exit_kernel
19177 + TRACE_IRQS_IRETQ 0
19178 + SWAPGS_UNSAFE_STACK
19179 + RESTORE_ALL 8
19180 + pax_force_retaddr_bts
19181 + jmp irq_return
19182 +#endif
19183 paranoid_swapgs:
19184 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19185 + pax_exit_kernel_user
19186 +#else
19187 + pax_exit_kernel
19188 +#endif
19189 TRACE_IRQS_IRETQ 0
19190 SWAPGS_UNSAFE_STACK
19191 RESTORE_ALL 8
19192 jmp irq_return
19193 paranoid_restore:
19194 + pax_exit_kernel
19195 TRACE_IRQS_IRETQ_DEBUG 0
19196 RESTORE_ALL 8
19197 + pax_force_retaddr_bts
19198 jmp irq_return
19199 paranoid_userspace:
19200 GET_THREAD_INFO(%rcx)
19201 @@ -1539,7 +1926,7 @@ paranoid_schedule:
19202 TRACE_IRQS_OFF
19203 jmp paranoid_userspace
19204 CFI_ENDPROC
19205 -END(paranoid_exit)
19206 +ENDPROC(paranoid_exit)
19207
19208 /*
19209 * Exception entry point. This expects an error code/orig_rax on the stack.
19210 @@ -1566,12 +1953,13 @@ ENTRY(error_entry)
19211 movq_cfi r14, R14+8
19212 movq_cfi r15, R15+8
19213 xorl %ebx,%ebx
19214 - testl $3,CS+8(%rsp)
19215 + testb $3,CS+8(%rsp)
19216 je error_kernelspace
19217 error_swapgs:
19218 SWAPGS
19219 error_sti:
19220 TRACE_IRQS_OFF
19221 + pax_force_retaddr_bts
19222 ret
19223
19224 /*
19225 @@ -1598,7 +1986,7 @@ bstep_iret:
19226 movq %rcx,RIP+8(%rsp)
19227 jmp error_swapgs
19228 CFI_ENDPROC
19229 -END(error_entry)
19230 +ENDPROC(error_entry)
19231
19232
19233 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19234 @@ -1618,7 +2006,7 @@ ENTRY(error_exit)
19235 jnz retint_careful
19236 jmp retint_swapgs
19237 CFI_ENDPROC
19238 -END(error_exit)
19239 +ENDPROC(error_exit)
19240
19241 /*
19242 * Test if a given stack is an NMI stack or not.
19243 @@ -1676,9 +2064,11 @@ ENTRY(nmi)
19244 * If %cs was not the kernel segment, then the NMI triggered in user
19245 * space, which means it is definitely not nested.
19246 */
19247 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19248 + je 1f
19249 cmpl $__KERNEL_CS, 16(%rsp)
19250 jne first_nmi
19251 -
19252 +1:
19253 /*
19254 * Check the special variable on the stack to see if NMIs are
19255 * executing.
19256 @@ -1847,6 +2237,17 @@ end_repeat_nmi:
19257 */
19258 movq %cr2, %r12
19259
19260 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19261 + testb $3, CS(%rsp)
19262 + jnz 1f
19263 + pax_enter_kernel
19264 + jmp 2f
19265 +1: pax_enter_kernel_user
19266 +2:
19267 +#else
19268 + pax_enter_kernel
19269 +#endif
19270 +
19271 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
19272 movq %rsp,%rdi
19273 movq $-1,%rsi
19274 @@ -1862,23 +2263,34 @@ end_repeat_nmi:
19275 testl %ebx,%ebx /* swapgs needed? */
19276 jnz nmi_restore
19277 nmi_swapgs:
19278 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19279 + pax_exit_kernel_user
19280 +#else
19281 + pax_exit_kernel
19282 +#endif
19283 SWAPGS_UNSAFE_STACK
19284 + RESTORE_ALL 6*8
19285 + /* Clear the NMI executing stack variable */
19286 + movq $0, 5*8(%rsp)
19287 + jmp irq_return
19288 nmi_restore:
19289 + pax_exit_kernel
19290 /* Pop the extra iret frame at once */
19291 RESTORE_ALL 6*8
19292 + pax_force_retaddr_bts
19293
19294 /* Clear the NMI executing stack variable */
19295 movq $0, 5*8(%rsp)
19296 jmp irq_return
19297 CFI_ENDPROC
19298 -END(nmi)
19299 +ENDPROC(nmi)
19300
19301 ENTRY(ignore_sysret)
19302 CFI_STARTPROC
19303 mov $-ENOSYS,%eax
19304 sysret
19305 CFI_ENDPROC
19306 -END(ignore_sysret)
19307 +ENDPROC(ignore_sysret)
19308
19309 /*
19310 * End of kprobes section
19311 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
19312 index 1d41402..af9a46a 100644
19313 --- a/arch/x86/kernel/ftrace.c
19314 +++ b/arch/x86/kernel/ftrace.c
19315 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
19316 {
19317 unsigned char replaced[MCOUNT_INSN_SIZE];
19318
19319 + ip = ktla_ktva(ip);
19320 +
19321 /*
19322 * Note: Due to modules and __init, code can
19323 * disappear and change, we need to protect against faulting
19324 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19325 unsigned char old[MCOUNT_INSN_SIZE], *new;
19326 int ret;
19327
19328 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
19329 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
19330 new = ftrace_call_replace(ip, (unsigned long)func);
19331
19332 /* See comment above by declaration of modifying_ftrace_code */
19333 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
19334 /* Also update the regs callback function */
19335 if (!ret) {
19336 ip = (unsigned long)(&ftrace_regs_call);
19337 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
19338 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
19339 new = ftrace_call_replace(ip, (unsigned long)func);
19340 ret = ftrace_modify_code(ip, old, new);
19341 }
19342 @@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
19343 * kernel identity mapping to modify code.
19344 */
19345 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
19346 - ip = (unsigned long)__va(__pa(ip));
19347 + ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
19348
19349 return probe_kernel_write((void *)ip, val, size);
19350 }
19351 @@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
19352 unsigned char replaced[MCOUNT_INSN_SIZE];
19353 unsigned char brk = BREAKPOINT_INSTRUCTION;
19354
19355 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
19356 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
19357 return -EFAULT;
19358
19359 /* Make sure it is what we expect it to be */
19360 @@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
19361 return ret;
19362
19363 fail_update:
19364 - probe_kernel_write((void *)ip, &old_code[0], 1);
19365 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
19366 goto out;
19367 }
19368
19369 @@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
19370 {
19371 unsigned char code[MCOUNT_INSN_SIZE];
19372
19373 + ip = ktla_ktva(ip);
19374 +
19375 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
19376 return -EFAULT;
19377
19378 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
19379 index c18f59d..9c0c9f6 100644
19380 --- a/arch/x86/kernel/head32.c
19381 +++ b/arch/x86/kernel/head32.c
19382 @@ -18,6 +18,7 @@
19383 #include <asm/io_apic.h>
19384 #include <asm/bios_ebda.h>
19385 #include <asm/tlbflush.h>
19386 +#include <asm/boot.h>
19387
19388 static void __init i386_default_early_setup(void)
19389 {
19390 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
19391
19392 void __init i386_start_kernel(void)
19393 {
19394 - memblock_reserve(__pa_symbol(&_text),
19395 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
19396 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
19397
19398 #ifdef CONFIG_BLK_DEV_INITRD
19399 /* Reserve INITRD */
19400 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
19401 index c8932c7..d56b622 100644
19402 --- a/arch/x86/kernel/head_32.S
19403 +++ b/arch/x86/kernel/head_32.S
19404 @@ -26,6 +26,12 @@
19405 /* Physical address */
19406 #define pa(X) ((X) - __PAGE_OFFSET)
19407
19408 +#ifdef CONFIG_PAX_KERNEXEC
19409 +#define ta(X) (X)
19410 +#else
19411 +#define ta(X) ((X) - __PAGE_OFFSET)
19412 +#endif
19413 +
19414 /*
19415 * References to members of the new_cpu_data structure.
19416 */
19417 @@ -55,11 +61,7 @@
19418 * and small than max_low_pfn, otherwise will waste some page table entries
19419 */
19420
19421 -#if PTRS_PER_PMD > 1
19422 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
19423 -#else
19424 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
19425 -#endif
19426 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
19427
19428 /* Number of possible pages in the lowmem region */
19429 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
19430 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
19431 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19432
19433 /*
19434 + * Real beginning of normal "text" segment
19435 + */
19436 +ENTRY(stext)
19437 +ENTRY(_stext)
19438 +
19439 +/*
19440 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
19441 * %esi points to the real-mode code as a 32-bit pointer.
19442 * CS and DS must be 4 GB flat segments, but we don't depend on
19443 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
19444 * can.
19445 */
19446 __HEAD
19447 +
19448 +#ifdef CONFIG_PAX_KERNEXEC
19449 + jmp startup_32
19450 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
19451 +.fill PAGE_SIZE-5,1,0xcc
19452 +#endif
19453 +
19454 ENTRY(startup_32)
19455 movl pa(stack_start),%ecx
19456
19457 @@ -106,6 +121,59 @@ ENTRY(startup_32)
19458 2:
19459 leal -__PAGE_OFFSET(%ecx),%esp
19460
19461 +#ifdef CONFIG_SMP
19462 + movl $pa(cpu_gdt_table),%edi
19463 + movl $__per_cpu_load,%eax
19464 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
19465 + rorl $16,%eax
19466 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
19467 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
19468 + movl $__per_cpu_end - 1,%eax
19469 + subl $__per_cpu_start,%eax
19470 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
19471 +#endif
19472 +
19473 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19474 + movl $NR_CPUS,%ecx
19475 + movl $pa(cpu_gdt_table),%edi
19476 +1:
19477 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
19478 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
19479 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
19480 + addl $PAGE_SIZE_asm,%edi
19481 + loop 1b
19482 +#endif
19483 +
19484 +#ifdef CONFIG_PAX_KERNEXEC
19485 + movl $pa(boot_gdt),%edi
19486 + movl $__LOAD_PHYSICAL_ADDR,%eax
19487 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
19488 + rorl $16,%eax
19489 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
19490 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
19491 + rorl $16,%eax
19492 +
19493 + ljmp $(__BOOT_CS),$1f
19494 +1:
19495 +
19496 + movl $NR_CPUS,%ecx
19497 + movl $pa(cpu_gdt_table),%edi
19498 + addl $__PAGE_OFFSET,%eax
19499 +1:
19500 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
19501 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
19502 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
19503 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
19504 + rorl $16,%eax
19505 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
19506 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
19507 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
19508 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
19509 + rorl $16,%eax
19510 + addl $PAGE_SIZE_asm,%edi
19511 + loop 1b
19512 +#endif
19513 +
19514 /*
19515 * Clear BSS first so that there are no surprises...
19516 */
19517 @@ -196,8 +264,11 @@ ENTRY(startup_32)
19518 movl %eax, pa(max_pfn_mapped)
19519
19520 /* Do early initialization of the fixmap area */
19521 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19522 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
19523 +#ifdef CONFIG_COMPAT_VDSO
19524 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
19525 +#else
19526 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
19527 +#endif
19528 #else /* Not PAE */
19529
19530 page_pde_offset = (__PAGE_OFFSET >> 20);
19531 @@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19532 movl %eax, pa(max_pfn_mapped)
19533
19534 /* Do early initialization of the fixmap area */
19535 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
19536 - movl %eax,pa(initial_page_table+0xffc)
19537 +#ifdef CONFIG_COMPAT_VDSO
19538 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
19539 +#else
19540 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
19541 +#endif
19542 #endif
19543
19544 #ifdef CONFIG_PARAVIRT
19545 @@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
19546 cmpl $num_subarch_entries, %eax
19547 jae bad_subarch
19548
19549 - movl pa(subarch_entries)(,%eax,4), %eax
19550 - subl $__PAGE_OFFSET, %eax
19551 - jmp *%eax
19552 + jmp *pa(subarch_entries)(,%eax,4)
19553
19554 bad_subarch:
19555 WEAK(lguest_entry)
19556 @@ -256,10 +328,10 @@ WEAK(xen_entry)
19557 __INITDATA
19558
19559 subarch_entries:
19560 - .long default_entry /* normal x86/PC */
19561 - .long lguest_entry /* lguest hypervisor */
19562 - .long xen_entry /* Xen hypervisor */
19563 - .long default_entry /* Moorestown MID */
19564 + .long ta(default_entry) /* normal x86/PC */
19565 + .long ta(lguest_entry) /* lguest hypervisor */
19566 + .long ta(xen_entry) /* Xen hypervisor */
19567 + .long ta(default_entry) /* Moorestown MID */
19568 num_subarch_entries = (. - subarch_entries) / 4
19569 .previous
19570 #else
19571 @@ -335,6 +407,7 @@ default_entry:
19572 movl pa(mmu_cr4_features),%eax
19573 movl %eax,%cr4
19574
19575 +#ifdef CONFIG_X86_PAE
19576 testb $X86_CR4_PAE, %al # check if PAE is enabled
19577 jz 6f
19578
19579 @@ -363,6 +436,9 @@ default_entry:
19580 /* Make changes effective */
19581 wrmsr
19582
19583 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
19584 +#endif
19585 +
19586 6:
19587
19588 /*
19589 @@ -460,14 +536,20 @@ is386: movl $2,%ecx # set MP
19590 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
19591 movl %eax,%ss # after changing gdt.
19592
19593 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
19594 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
19595 movl %eax,%ds
19596 movl %eax,%es
19597
19598 movl $(__KERNEL_PERCPU), %eax
19599 movl %eax,%fs # set this cpu's percpu
19600
19601 +#ifdef CONFIG_CC_STACKPROTECTOR
19602 movl $(__KERNEL_STACK_CANARY),%eax
19603 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
19604 + movl $(__USER_DS),%eax
19605 +#else
19606 + xorl %eax,%eax
19607 +#endif
19608 movl %eax,%gs
19609
19610 xorl %eax,%eax # Clear LDT
19611 @@ -544,8 +626,11 @@ setup_once:
19612 * relocation. Manually set base address in stack canary
19613 * segment descriptor.
19614 */
19615 - movl $gdt_page,%eax
19616 + movl $cpu_gdt_table,%eax
19617 movl $stack_canary,%ecx
19618 +#ifdef CONFIG_SMP
19619 + addl $__per_cpu_load,%ecx
19620 +#endif
19621 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
19622 shrl $16, %ecx
19623 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
19624 @@ -576,7 +661,7 @@ ENDPROC(early_idt_handlers)
19625 /* This is global to keep gas from relaxing the jumps */
19626 ENTRY(early_idt_handler)
19627 cld
19628 - cmpl $2,%ss:early_recursion_flag
19629 + cmpl $1,%ss:early_recursion_flag
19630 je hlt_loop
19631 incl %ss:early_recursion_flag
19632
19633 @@ -614,8 +699,8 @@ ENTRY(early_idt_handler)
19634 pushl (20+6*4)(%esp) /* trapno */
19635 pushl $fault_msg
19636 call printk
19637 -#endif
19638 call dump_stack
19639 +#endif
19640 hlt_loop:
19641 hlt
19642 jmp hlt_loop
19643 @@ -634,8 +719,11 @@ ENDPROC(early_idt_handler)
19644 /* This is the default interrupt "handler" :-) */
19645 ALIGN
19646 ignore_int:
19647 - cld
19648 #ifdef CONFIG_PRINTK
19649 + cmpl $2,%ss:early_recursion_flag
19650 + je hlt_loop
19651 + incl %ss:early_recursion_flag
19652 + cld
19653 pushl %eax
19654 pushl %ecx
19655 pushl %edx
19656 @@ -644,9 +732,6 @@ ignore_int:
19657 movl $(__KERNEL_DS),%eax
19658 movl %eax,%ds
19659 movl %eax,%es
19660 - cmpl $2,early_recursion_flag
19661 - je hlt_loop
19662 - incl early_recursion_flag
19663 pushl 16(%esp)
19664 pushl 24(%esp)
19665 pushl 32(%esp)
19666 @@ -680,29 +765,43 @@ ENTRY(setup_once_ref)
19667 /*
19668 * BSS section
19669 */
19670 -__PAGE_ALIGNED_BSS
19671 - .align PAGE_SIZE
19672 #ifdef CONFIG_X86_PAE
19673 +.section .initial_pg_pmd,"a",@progbits
19674 initial_pg_pmd:
19675 .fill 1024*KPMDS,4,0
19676 #else
19677 +.section .initial_page_table,"a",@progbits
19678 ENTRY(initial_page_table)
19679 .fill 1024,4,0
19680 #endif
19681 +.section .initial_pg_fixmap,"a",@progbits
19682 initial_pg_fixmap:
19683 .fill 1024,4,0
19684 +.section .empty_zero_page,"a",@progbits
19685 ENTRY(empty_zero_page)
19686 .fill 4096,1,0
19687 +.section .swapper_pg_dir,"a",@progbits
19688 ENTRY(swapper_pg_dir)
19689 +#ifdef CONFIG_X86_PAE
19690 + .fill 4,8,0
19691 +#else
19692 .fill 1024,4,0
19693 +#endif
19694 +
19695 +/*
19696 + * The IDT has to be page-aligned to simplify the Pentium
19697 + * F0 0F bug workaround.. We have a special link segment
19698 + * for this.
19699 + */
19700 +.section .idt,"a",@progbits
19701 +ENTRY(idt_table)
19702 + .fill 256,8,0
19703
19704 /*
19705 * This starts the data section.
19706 */
19707 #ifdef CONFIG_X86_PAE
19708 -__PAGE_ALIGNED_DATA
19709 - /* Page-aligned for the benefit of paravirt? */
19710 - .align PAGE_SIZE
19711 +.section .initial_page_table,"a",@progbits
19712 ENTRY(initial_page_table)
19713 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
19714 # if KPMDS == 3
19715 @@ -721,12 +820,20 @@ ENTRY(initial_page_table)
19716 # error "Kernel PMDs should be 1, 2 or 3"
19717 # endif
19718 .align PAGE_SIZE /* needs to be page-sized too */
19719 +
19720 +#ifdef CONFIG_PAX_PER_CPU_PGD
19721 +ENTRY(cpu_pgd)
19722 + .rept NR_CPUS
19723 + .fill 4,8,0
19724 + .endr
19725 +#endif
19726 +
19727 #endif
19728
19729 .data
19730 .balign 4
19731 ENTRY(stack_start)
19732 - .long init_thread_union+THREAD_SIZE
19733 + .long init_thread_union+THREAD_SIZE-8
19734
19735 __INITRODATA
19736 int_msg:
19737 @@ -754,7 +861,7 @@ fault_msg:
19738 * segment size, and 32-bit linear address value:
19739 */
19740
19741 - .data
19742 +.section .rodata,"a",@progbits
19743 .globl boot_gdt_descr
19744 .globl idt_descr
19745
19746 @@ -763,7 +870,7 @@ fault_msg:
19747 .word 0 # 32 bit align gdt_desc.address
19748 boot_gdt_descr:
19749 .word __BOOT_DS+7
19750 - .long boot_gdt - __PAGE_OFFSET
19751 + .long pa(boot_gdt)
19752
19753 .word 0 # 32-bit align idt_desc.address
19754 idt_descr:
19755 @@ -774,7 +881,7 @@ idt_descr:
19756 .word 0 # 32 bit align gdt_desc.address
19757 ENTRY(early_gdt_descr)
19758 .word GDT_ENTRIES*8-1
19759 - .long gdt_page /* Overwritten for secondary CPUs */
19760 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
19761
19762 /*
19763 * The boot_gdt must mirror the equivalent in setup.S and is
19764 @@ -783,5 +890,65 @@ ENTRY(early_gdt_descr)
19765 .align L1_CACHE_BYTES
19766 ENTRY(boot_gdt)
19767 .fill GDT_ENTRY_BOOT_CS,8,0
19768 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
19769 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
19770 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
19771 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
19772 +
19773 + .align PAGE_SIZE_asm
19774 +ENTRY(cpu_gdt_table)
19775 + .rept NR_CPUS
19776 + .quad 0x0000000000000000 /* NULL descriptor */
19777 + .quad 0x0000000000000000 /* 0x0b reserved */
19778 + .quad 0x0000000000000000 /* 0x13 reserved */
19779 + .quad 0x0000000000000000 /* 0x1b reserved */
19780 +
19781 +#ifdef CONFIG_PAX_KERNEXEC
19782 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
19783 +#else
19784 + .quad 0x0000000000000000 /* 0x20 unused */
19785 +#endif
19786 +
19787 + .quad 0x0000000000000000 /* 0x28 unused */
19788 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
19789 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
19790 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
19791 + .quad 0x0000000000000000 /* 0x4b reserved */
19792 + .quad 0x0000000000000000 /* 0x53 reserved */
19793 + .quad 0x0000000000000000 /* 0x5b reserved */
19794 +
19795 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
19796 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
19797 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
19798 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
19799 +
19800 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
19801 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
19802 +
19803 + /*
19804 + * Segments used for calling PnP BIOS have byte granularity.
19805 + * The code segments and data segments have fixed 64k limits,
19806 + * the transfer segment sizes are set at run time.
19807 + */
19808 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
19809 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
19810 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
19811 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
19812 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
19813 +
19814 + /*
19815 + * The APM segments have byte granularity and their bases
19816 + * are set at run time. All have 64k limits.
19817 + */
19818 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
19819 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
19820 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
19821 +
19822 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
19823 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
19824 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
19825 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
19826 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
19827 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
19828 +
19829 + /* Be sure this is zeroed to avoid false validations in Xen */
19830 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
19831 + .endr
19832 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
19833 index 980053c..74d3b44 100644
19834 --- a/arch/x86/kernel/head_64.S
19835 +++ b/arch/x86/kernel/head_64.S
19836 @@ -20,6 +20,8 @@
19837 #include <asm/processor-flags.h>
19838 #include <asm/percpu.h>
19839 #include <asm/nops.h>
19840 +#include <asm/cpufeature.h>
19841 +#include <asm/alternative-asm.h>
19842
19843 #ifdef CONFIG_PARAVIRT
19844 #include <asm/asm-offsets.h>
19845 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
19846 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
19847 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
19848 L3_START_KERNEL = pud_index(__START_KERNEL_map)
19849 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
19850 +L3_VMALLOC_START = pud_index(VMALLOC_START)
19851 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
19852 +L3_VMALLOC_END = pud_index(VMALLOC_END)
19853 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
19854 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
19855
19856 .text
19857 __HEAD
19858 @@ -88,35 +96,23 @@ startup_64:
19859 */
19860 addq %rbp, init_level4_pgt + 0(%rip)
19861 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
19862 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
19863 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
19864 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
19865 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
19866
19867 addq %rbp, level3_ident_pgt + 0(%rip)
19868 +#ifndef CONFIG_XEN
19869 + addq %rbp, level3_ident_pgt + 8(%rip)
19870 +#endif
19871
19872 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
19873 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
19874 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
19875 +
19876 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
19877 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
19878
19879 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
19880 -
19881 - /* Add an Identity mapping if I am above 1G */
19882 - leaq _text(%rip), %rdi
19883 - andq $PMD_PAGE_MASK, %rdi
19884 -
19885 - movq %rdi, %rax
19886 - shrq $PUD_SHIFT, %rax
19887 - andq $(PTRS_PER_PUD - 1), %rax
19888 - jz ident_complete
19889 -
19890 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
19891 - leaq level3_ident_pgt(%rip), %rbx
19892 - movq %rdx, 0(%rbx, %rax, 8)
19893 -
19894 - movq %rdi, %rax
19895 - shrq $PMD_SHIFT, %rax
19896 - andq $(PTRS_PER_PMD - 1), %rax
19897 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
19898 - leaq level2_spare_pgt(%rip), %rbx
19899 - movq %rdx, 0(%rbx, %rax, 8)
19900 -ident_complete:
19901 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
19902
19903 /*
19904 * Fixup the kernel text+data virtual addresses. Note that
19905 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
19906 * after the boot processor executes this code.
19907 */
19908
19909 - /* Enable PAE mode and PGE */
19910 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
19911 + /* Enable PAE mode and PSE/PGE */
19912 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
19913 movq %rax, %cr4
19914
19915 /* Setup early boot stage 4 level pagetables. */
19916 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
19917 movl $MSR_EFER, %ecx
19918 rdmsr
19919 btsl $_EFER_SCE, %eax /* Enable System Call */
19920 - btl $20,%edi /* No Execute supported? */
19921 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
19922 jnc 1f
19923 btsl $_EFER_NX, %eax
19924 + leaq init_level4_pgt(%rip), %rdi
19925 +#ifndef CONFIG_EFI
19926 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
19927 +#endif
19928 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
19929 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
19930 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
19931 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
19932 1: wrmsr /* Make changes effective */
19933
19934 /* Setup cr0 */
19935 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
19936 * jump. In addition we need to ensure %cs is set so we make this
19937 * a far return.
19938 */
19939 + pax_set_fptr_mask
19940 movq initial_code(%rip),%rax
19941 pushq $0 # fake return address to stop unwinder
19942 pushq $__KERNEL_CS # set correct cs
19943 @@ -284,7 +289,7 @@ ENDPROC(start_cpu0)
19944 bad_address:
19945 jmp bad_address
19946
19947 - .section ".init.text","ax"
19948 + __INIT
19949 .globl early_idt_handlers
19950 early_idt_handlers:
19951 # 104(%rsp) %rflags
19952 @@ -343,7 +348,7 @@ ENTRY(early_idt_handler)
19953 call dump_stack
19954 #ifdef CONFIG_KALLSYMS
19955 leaq early_idt_ripmsg(%rip),%rdi
19956 - movq 40(%rsp),%rsi # %rip again
19957 + movq 88(%rsp),%rsi # %rip again
19958 call __print_symbol
19959 #endif
19960 #endif /* EARLY_PRINTK */
19961 @@ -363,11 +368,15 @@ ENTRY(early_idt_handler)
19962 addq $16,%rsp # drop vector number and error code
19963 decl early_recursion_flag(%rip)
19964 INTERRUPT_RETURN
19965 + .previous
19966
19967 + __INITDATA
19968 .balign 4
19969 early_recursion_flag:
19970 .long 0
19971 + .previous
19972
19973 + .section .rodata,"a",@progbits
19974 #ifdef CONFIG_EARLY_PRINTK
19975 early_idt_msg:
19976 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
19977 @@ -376,6 +385,7 @@ early_idt_ripmsg:
19978 #endif /* CONFIG_EARLY_PRINTK */
19979 .previous
19980
19981 + .section .rodata,"a",@progbits
19982 #define NEXT_PAGE(name) \
19983 .balign PAGE_SIZE; \
19984 ENTRY(name)
19985 @@ -388,7 +398,6 @@ ENTRY(name)
19986 i = i + 1 ; \
19987 .endr
19988
19989 - .data
19990 /*
19991 * This default setting generates an ident mapping at address 0x100000
19992 * and a mapping for the kernel that precisely maps virtual address
19993 @@ -399,13 +408,41 @@ NEXT_PAGE(init_level4_pgt)
19994 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19995 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
19996 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
19997 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
19998 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
19999 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
20000 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20001 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20002 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20003 .org init_level4_pgt + L4_START_KERNEL*8, 0
20004 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20005 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20006
20007 +#ifdef CONFIG_PAX_PER_CPU_PGD
20008 +NEXT_PAGE(cpu_pgd)
20009 + .rept NR_CPUS
20010 + .fill 512,8,0
20011 + .endr
20012 +#endif
20013 +
20014 NEXT_PAGE(level3_ident_pgt)
20015 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20016 +#ifdef CONFIG_XEN
20017 .fill 511,8,0
20018 +#else
20019 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20020 + .fill 510,8,0
20021 +#endif
20022 +
20023 +NEXT_PAGE(level3_vmalloc_start_pgt)
20024 + .fill 512,8,0
20025 +
20026 +NEXT_PAGE(level3_vmalloc_end_pgt)
20027 + .fill 512,8,0
20028 +
20029 +NEXT_PAGE(level3_vmemmap_pgt)
20030 + .fill L3_VMEMMAP_START,8,0
20031 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20032
20033 NEXT_PAGE(level3_kernel_pgt)
20034 .fill L3_START_KERNEL,8,0
20035 @@ -413,20 +450,23 @@ NEXT_PAGE(level3_kernel_pgt)
20036 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20037 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20038
20039 +NEXT_PAGE(level2_vmemmap_pgt)
20040 + .fill 512,8,0
20041 +
20042 NEXT_PAGE(level2_fixmap_pgt)
20043 - .fill 506,8,0
20044 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20045 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20046 - .fill 5,8,0
20047 + .fill 507,8,0
20048 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20049 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20050 + .fill 4,8,0
20051
20052 -NEXT_PAGE(level1_fixmap_pgt)
20053 +NEXT_PAGE(level1_vsyscall_pgt)
20054 .fill 512,8,0
20055
20056 -NEXT_PAGE(level2_ident_pgt)
20057 - /* Since I easily can, map the first 1G.
20058 + /* Since I easily can, map the first 2G.
20059 * Don't set NX because code runs from these pages.
20060 */
20061 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20062 +NEXT_PAGE(level2_ident_pgt)
20063 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20064
20065 NEXT_PAGE(level2_kernel_pgt)
20066 /*
20067 @@ -439,37 +479,59 @@ NEXT_PAGE(level2_kernel_pgt)
20068 * If you want to increase this then increase MODULES_VADDR
20069 * too.)
20070 */
20071 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
20072 - KERNEL_IMAGE_SIZE/PMD_SIZE)
20073 -
20074 -NEXT_PAGE(level2_spare_pgt)
20075 - .fill 512, 8, 0
20076 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
20077
20078 #undef PMDS
20079 #undef NEXT_PAGE
20080
20081 - .data
20082 + .align PAGE_SIZE
20083 +ENTRY(cpu_gdt_table)
20084 + .rept NR_CPUS
20085 + .quad 0x0000000000000000 /* NULL descriptor */
20086 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20087 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
20088 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
20089 + .quad 0x00cffb000000ffff /* __USER32_CS */
20090 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20091 + .quad 0x00affb000000ffff /* __USER_CS */
20092 +
20093 +#ifdef CONFIG_PAX_KERNEXEC
20094 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20095 +#else
20096 + .quad 0x0 /* unused */
20097 +#endif
20098 +
20099 + .quad 0,0 /* TSS */
20100 + .quad 0,0 /* LDT */
20101 + .quad 0,0,0 /* three TLS descriptors */
20102 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
20103 + /* asm/segment.h:GDT_ENTRIES must match this */
20104 +
20105 + /* zero the remaining page */
20106 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20107 + .endr
20108 +
20109 .align 16
20110 .globl early_gdt_descr
20111 early_gdt_descr:
20112 .word GDT_ENTRIES*8-1
20113 early_gdt_descr_base:
20114 - .quad INIT_PER_CPU_VAR(gdt_page)
20115 + .quad cpu_gdt_table
20116
20117 ENTRY(phys_base)
20118 /* This must match the first entry in level2_kernel_pgt */
20119 .quad 0x0000000000000000
20120
20121 #include "../../x86/xen/xen-head.S"
20122 -
20123 - .section .bss, "aw", @nobits
20124 +
20125 + .section .rodata,"a",@progbits
20126 .align L1_CACHE_BYTES
20127 ENTRY(idt_table)
20128 - .skip IDT_ENTRIES * 16
20129 + .fill 512,8,0
20130
20131 .align L1_CACHE_BYTES
20132 ENTRY(nmi_idt_table)
20133 - .skip IDT_ENTRIES * 16
20134 + .fill 512,8,0
20135
20136 __PAGE_ALIGNED_BSS
20137 .align PAGE_SIZE
20138 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20139 index 9c3bd4a..e1d9b35 100644
20140 --- a/arch/x86/kernel/i386_ksyms_32.c
20141 +++ b/arch/x86/kernel/i386_ksyms_32.c
20142 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20143 EXPORT_SYMBOL(cmpxchg8b_emu);
20144 #endif
20145
20146 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
20147 +
20148 /* Networking helper routines. */
20149 EXPORT_SYMBOL(csum_partial_copy_generic);
20150 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20151 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20152
20153 EXPORT_SYMBOL(__get_user_1);
20154 EXPORT_SYMBOL(__get_user_2);
20155 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
20156
20157 EXPORT_SYMBOL(csum_partial);
20158 EXPORT_SYMBOL(empty_zero_page);
20159 +
20160 +#ifdef CONFIG_PAX_KERNEXEC
20161 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20162 +#endif
20163 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20164 index 245a71d..89d9ce4 100644
20165 --- a/arch/x86/kernel/i387.c
20166 +++ b/arch/x86/kernel/i387.c
20167 @@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20168 static inline bool interrupted_user_mode(void)
20169 {
20170 struct pt_regs *regs = get_irq_regs();
20171 - return regs && user_mode_vm(regs);
20172 + return regs && user_mode(regs);
20173 }
20174
20175 /*
20176 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20177 index 9a5c460..dc4374d 100644
20178 --- a/arch/x86/kernel/i8259.c
20179 +++ b/arch/x86/kernel/i8259.c
20180 @@ -209,7 +209,7 @@ spurious_8259A_irq:
20181 "spurious 8259A interrupt: IRQ%d.\n", irq);
20182 spurious_irq_mask |= irqmask;
20183 }
20184 - atomic_inc(&irq_err_count);
20185 + atomic_inc_unchecked(&irq_err_count);
20186 /*
20187 * Theoretically we do not have to handle this IRQ,
20188 * but in Linux this does not cause problems and is
20189 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20190 index 8c96897..be66bfa 100644
20191 --- a/arch/x86/kernel/ioport.c
20192 +++ b/arch/x86/kernel/ioport.c
20193 @@ -6,6 +6,7 @@
20194 #include <linux/sched.h>
20195 #include <linux/kernel.h>
20196 #include <linux/capability.h>
20197 +#include <linux/security.h>
20198 #include <linux/errno.h>
20199 #include <linux/types.h>
20200 #include <linux/ioport.h>
20201 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20202
20203 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20204 return -EINVAL;
20205 +#ifdef CONFIG_GRKERNSEC_IO
20206 + if (turn_on && grsec_disable_privio) {
20207 + gr_handle_ioperm();
20208 + return -EPERM;
20209 + }
20210 +#endif
20211 if (turn_on && !capable(CAP_SYS_RAWIO))
20212 return -EPERM;
20213
20214 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20215 * because the ->io_bitmap_max value must match the bitmap
20216 * contents:
20217 */
20218 - tss = &per_cpu(init_tss, get_cpu());
20219 + tss = init_tss + get_cpu();
20220
20221 if (turn_on)
20222 bitmap_clear(t->io_bitmap_ptr, from, num);
20223 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
20224 return -EINVAL;
20225 /* Trying to gain more privileges? */
20226 if (level > old) {
20227 +#ifdef CONFIG_GRKERNSEC_IO
20228 + if (grsec_disable_privio) {
20229 + gr_handle_iopl();
20230 + return -EPERM;
20231 + }
20232 +#endif
20233 if (!capable(CAP_SYS_RAWIO))
20234 return -EPERM;
20235 }
20236 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20237 index e4595f1..ee3bfb8 100644
20238 --- a/arch/x86/kernel/irq.c
20239 +++ b/arch/x86/kernel/irq.c
20240 @@ -18,7 +18,7 @@
20241 #include <asm/mce.h>
20242 #include <asm/hw_irq.h>
20243
20244 -atomic_t irq_err_count;
20245 +atomic_unchecked_t irq_err_count;
20246
20247 /* Function pointer for generic interrupt vector handling */
20248 void (*x86_platform_ipi_callback)(void) = NULL;
20249 @@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20250 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20251 seq_printf(p, " Machine check polls\n");
20252 #endif
20253 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20254 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20255 #if defined(CONFIG_X86_IO_APIC)
20256 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20257 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20258 #endif
20259 return 0;
20260 }
20261 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20262
20263 u64 arch_irq_stat(void)
20264 {
20265 - u64 sum = atomic_read(&irq_err_count);
20266 + u64 sum = atomic_read_unchecked(&irq_err_count);
20267
20268 #ifdef CONFIG_X86_IO_APIC
20269 - sum += atomic_read(&irq_mis_count);
20270 + sum += atomic_read_unchecked(&irq_mis_count);
20271 #endif
20272 return sum;
20273 }
20274 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20275 index 344faf8..355f60d 100644
20276 --- a/arch/x86/kernel/irq_32.c
20277 +++ b/arch/x86/kernel/irq_32.c
20278 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20279 __asm__ __volatile__("andl %%esp,%0" :
20280 "=r" (sp) : "0" (THREAD_SIZE - 1));
20281
20282 - return sp < (sizeof(struct thread_info) + STACK_WARN);
20283 + return sp < STACK_WARN;
20284 }
20285
20286 static void print_stack_overflow(void)
20287 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20288 * per-CPU IRQ handling contexts (thread information and stack)
20289 */
20290 union irq_ctx {
20291 - struct thread_info tinfo;
20292 - u32 stack[THREAD_SIZE/sizeof(u32)];
20293 + unsigned long previous_esp;
20294 + u32 stack[THREAD_SIZE/sizeof(u32)];
20295 } __attribute__((aligned(THREAD_SIZE)));
20296
20297 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
20298 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
20299 static inline int
20300 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20301 {
20302 - union irq_ctx *curctx, *irqctx;
20303 + union irq_ctx *irqctx;
20304 u32 *isp, arg1, arg2;
20305
20306 - curctx = (union irq_ctx *) current_thread_info();
20307 irqctx = __this_cpu_read(hardirq_ctx);
20308
20309 /*
20310 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20311 * handler) we can't do that and just have to keep using the
20312 * current stack (which is the irq stack already after all)
20313 */
20314 - if (unlikely(curctx == irqctx))
20315 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
20316 return 0;
20317
20318 /* build the stack frame on the IRQ stack */
20319 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20320 - irqctx->tinfo.task = curctx->tinfo.task;
20321 - irqctx->tinfo.previous_esp = current_stack_pointer;
20322 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20323 + irqctx->previous_esp = current_stack_pointer;
20324
20325 - /* Copy the preempt_count so that the [soft]irq checks work. */
20326 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
20327 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20328 + __set_fs(MAKE_MM_SEG(0));
20329 +#endif
20330
20331 if (unlikely(overflow))
20332 call_on_stack(print_stack_overflow, isp);
20333 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20334 : "0" (irq), "1" (desc), "2" (isp),
20335 "D" (desc->handle_irq)
20336 : "memory", "cc", "ecx");
20337 +
20338 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20339 + __set_fs(current_thread_info()->addr_limit);
20340 +#endif
20341 +
20342 return 1;
20343 }
20344
20345 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
20346 */
20347 void __cpuinit irq_ctx_init(int cpu)
20348 {
20349 - union irq_ctx *irqctx;
20350 -
20351 if (per_cpu(hardirq_ctx, cpu))
20352 return;
20353
20354 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20355 - THREADINFO_GFP,
20356 - THREAD_SIZE_ORDER));
20357 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20358 - irqctx->tinfo.cpu = cpu;
20359 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
20360 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20361 -
20362 - per_cpu(hardirq_ctx, cpu) = irqctx;
20363 -
20364 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
20365 - THREADINFO_GFP,
20366 - THREAD_SIZE_ORDER));
20367 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
20368 - irqctx->tinfo.cpu = cpu;
20369 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
20370 -
20371 - per_cpu(softirq_ctx, cpu) = irqctx;
20372 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20373 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
20374 +
20375 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20376 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20377
20378 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
20379 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
20380 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
20381 asmlinkage void do_softirq(void)
20382 {
20383 unsigned long flags;
20384 - struct thread_info *curctx;
20385 union irq_ctx *irqctx;
20386 u32 *isp;
20387
20388 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
20389 local_irq_save(flags);
20390
20391 if (local_softirq_pending()) {
20392 - curctx = current_thread_info();
20393 irqctx = __this_cpu_read(softirq_ctx);
20394 - irqctx->tinfo.task = curctx->task;
20395 - irqctx->tinfo.previous_esp = current_stack_pointer;
20396 + irqctx->previous_esp = current_stack_pointer;
20397
20398 /* build the stack frame on the softirq stack */
20399 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
20400 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
20401 +
20402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20403 + __set_fs(MAKE_MM_SEG(0));
20404 +#endif
20405
20406 call_on_stack(__do_softirq, isp);
20407 +
20408 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20409 + __set_fs(current_thread_info()->addr_limit);
20410 +#endif
20411 +
20412 /*
20413 * Shouldn't happen, we returned above if in_interrupt():
20414 */
20415 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
20416 if (unlikely(!desc))
20417 return false;
20418
20419 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20420 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
20421 if (unlikely(overflow))
20422 print_stack_overflow();
20423 desc->handle_irq(irq, desc);
20424 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
20425 index d04d3ec..ea4b374 100644
20426 --- a/arch/x86/kernel/irq_64.c
20427 +++ b/arch/x86/kernel/irq_64.c
20428 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
20429 u64 estack_top, estack_bottom;
20430 u64 curbase = (u64)task_stack_page(current);
20431
20432 - if (user_mode_vm(regs))
20433 + if (user_mode(regs))
20434 return;
20435
20436 if (regs->sp >= curbase + sizeof(struct thread_info) +
20437 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
20438 index dc1404b..bbc43e7 100644
20439 --- a/arch/x86/kernel/kdebugfs.c
20440 +++ b/arch/x86/kernel/kdebugfs.c
20441 @@ -27,7 +27,7 @@ struct setup_data_node {
20442 u32 len;
20443 };
20444
20445 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
20446 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
20447 size_t count, loff_t *ppos)
20448 {
20449 struct setup_data_node *node = file->private_data;
20450 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
20451 index 836f832..a8bda67 100644
20452 --- a/arch/x86/kernel/kgdb.c
20453 +++ b/arch/x86/kernel/kgdb.c
20454 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
20455 #ifdef CONFIG_X86_32
20456 switch (regno) {
20457 case GDB_SS:
20458 - if (!user_mode_vm(regs))
20459 + if (!user_mode(regs))
20460 *(unsigned long *)mem = __KERNEL_DS;
20461 break;
20462 case GDB_SP:
20463 - if (!user_mode_vm(regs))
20464 + if (!user_mode(regs))
20465 *(unsigned long *)mem = kernel_stack_pointer(regs);
20466 break;
20467 case GDB_GS:
20468 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
20469 bp->attr.bp_addr = breakinfo[breakno].addr;
20470 bp->attr.bp_len = breakinfo[breakno].len;
20471 bp->attr.bp_type = breakinfo[breakno].type;
20472 - info->address = breakinfo[breakno].addr;
20473 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
20474 + info->address = ktla_ktva(breakinfo[breakno].addr);
20475 + else
20476 + info->address = breakinfo[breakno].addr;
20477 info->len = breakinfo[breakno].len;
20478 info->type = breakinfo[breakno].type;
20479 val = arch_install_hw_breakpoint(bp);
20480 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
20481 case 'k':
20482 /* clear the trace bit */
20483 linux_regs->flags &= ~X86_EFLAGS_TF;
20484 - atomic_set(&kgdb_cpu_doing_single_step, -1);
20485 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
20486
20487 /* set the trace bit if we're stepping */
20488 if (remcomInBuffer[0] == 's') {
20489 linux_regs->flags |= X86_EFLAGS_TF;
20490 - atomic_set(&kgdb_cpu_doing_single_step,
20491 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
20492 raw_smp_processor_id());
20493 }
20494
20495 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
20496
20497 switch (cmd) {
20498 case DIE_DEBUG:
20499 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
20500 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
20501 if (user_mode(regs))
20502 return single_step_cont(regs, args);
20503 break;
20504 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20505 #endif /* CONFIG_DEBUG_RODATA */
20506
20507 bpt->type = BP_BREAKPOINT;
20508 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
20509 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
20510 BREAK_INSTR_SIZE);
20511 if (err)
20512 return err;
20513 - err = probe_kernel_write((char *)bpt->bpt_addr,
20514 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20515 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
20516 #ifdef CONFIG_DEBUG_RODATA
20517 if (!err)
20518 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
20519 return -EBUSY;
20520 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
20521 BREAK_INSTR_SIZE);
20522 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20523 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20524 if (err)
20525 return err;
20526 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
20527 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
20528 if (mutex_is_locked(&text_mutex))
20529 goto knl_write;
20530 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
20531 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
20532 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
20533 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
20534 goto knl_write;
20535 return err;
20536 knl_write:
20537 #endif /* CONFIG_DEBUG_RODATA */
20538 - return probe_kernel_write((char *)bpt->bpt_addr,
20539 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
20540 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
20541 }
20542
20543 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
20544 index c5e410e..ed5a7f0 100644
20545 --- a/arch/x86/kernel/kprobes-opt.c
20546 +++ b/arch/x86/kernel/kprobes-opt.c
20547 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20548 * Verify if the address gap is in 2GB range, because this uses
20549 * a relative jump.
20550 */
20551 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
20552 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
20553 if (abs(rel) > 0x7fffffff)
20554 return -ERANGE;
20555
20556 @@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
20557 op->optinsn.size = ret;
20558
20559 /* Copy arch-dep-instance from template */
20560 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
20561 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
20562
20563 /* Set probe information */
20564 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
20565
20566 /* Set probe function call */
20567 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
20568 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
20569
20570 /* Set returning jmp instruction at the tail of out-of-line buffer */
20571 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
20572 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
20573 (u8 *)op->kp.addr + op->optinsn.size);
20574
20575 flush_icache_range((unsigned long) buf,
20576 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
20577 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
20578
20579 /* Backup instructions which will be replaced by jump address */
20580 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
20581 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
20582 RELATIVE_ADDR_SIZE);
20583
20584 insn_buf[0] = RELATIVEJUMP_OPCODE;
20585 @@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
20586 /* This kprobe is really able to run optimized path. */
20587 op = container_of(p, struct optimized_kprobe, kp);
20588 /* Detour through copied instructions */
20589 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
20590 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
20591 if (!reenter)
20592 reset_current_kprobe();
20593 preempt_enable_no_resched();
20594 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
20595 index 57916c0..9e0b9d0 100644
20596 --- a/arch/x86/kernel/kprobes.c
20597 +++ b/arch/x86/kernel/kprobes.c
20598 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
20599 s32 raddr;
20600 } __attribute__((packed)) *insn;
20601
20602 - insn = (struct __arch_relative_insn *)from;
20603 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
20604 +
20605 + pax_open_kernel();
20606 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
20607 insn->op = op;
20608 + pax_close_kernel();
20609 }
20610
20611 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
20612 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
20613 kprobe_opcode_t opcode;
20614 kprobe_opcode_t *orig_opcodes = opcodes;
20615
20616 - if (search_exception_tables((unsigned long)opcodes))
20617 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
20618 return 0; /* Page fault may occur on this address. */
20619
20620 retry:
20621 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
20622 * for the first byte, we can recover the original instruction
20623 * from it and kp->opcode.
20624 */
20625 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20626 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
20627 buf[0] = kp->opcode;
20628 - return (unsigned long)buf;
20629 + return ktva_ktla((unsigned long)buf);
20630 }
20631
20632 /*
20633 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20634 /* Another subsystem puts a breakpoint, failed to recover */
20635 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
20636 return 0;
20637 + pax_open_kernel();
20638 memcpy(dest, insn.kaddr, insn.length);
20639 + pax_close_kernel();
20640
20641 #ifdef CONFIG_X86_64
20642 if (insn_rip_relative(&insn)) {
20643 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
20644 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
20645 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
20646 disp = (u8 *) dest + insn_offset_displacement(&insn);
20647 + pax_open_kernel();
20648 *(s32 *) disp = (s32) newdisp;
20649 + pax_close_kernel();
20650 }
20651 #endif
20652 return insn.length;
20653 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20654 * nor set current_kprobe, because it doesn't use single
20655 * stepping.
20656 */
20657 - regs->ip = (unsigned long)p->ainsn.insn;
20658 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20659 preempt_enable_no_resched();
20660 return;
20661 }
20662 @@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
20663 regs->flags &= ~X86_EFLAGS_IF;
20664 /* single step inline if the instruction is an int3 */
20665 if (p->opcode == BREAKPOINT_INSTRUCTION)
20666 - regs->ip = (unsigned long)p->addr;
20667 + regs->ip = ktla_ktva((unsigned long)p->addr);
20668 else
20669 - regs->ip = (unsigned long)p->ainsn.insn;
20670 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
20671 }
20672
20673 /*
20674 @@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
20675 setup_singlestep(p, regs, kcb, 0);
20676 return 1;
20677 }
20678 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
20679 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
20680 /*
20681 * The breakpoint instruction was removed right
20682 * after we hit it. Another cpu has removed
20683 @@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
20684 " movq %rax, 152(%rsp)\n"
20685 RESTORE_REGS_STRING
20686 " popfq\n"
20687 +#ifdef KERNEXEC_PLUGIN
20688 + " btsq $63,(%rsp)\n"
20689 +#endif
20690 #else
20691 " pushf\n"
20692 SAVE_REGS_STRING
20693 @@ -788,7 +798,7 @@ static void __kprobes
20694 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
20695 {
20696 unsigned long *tos = stack_addr(regs);
20697 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
20698 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
20699 unsigned long orig_ip = (unsigned long)p->addr;
20700 kprobe_opcode_t *insn = p->ainsn.insn;
20701
20702 @@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
20703 struct die_args *args = data;
20704 int ret = NOTIFY_DONE;
20705
20706 - if (args->regs && user_mode_vm(args->regs))
20707 + if (args->regs && user_mode(args->regs))
20708 return ret;
20709
20710 switch (val) {
20711 diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
20712 index 9c2bd8b..bb1131c 100644
20713 --- a/arch/x86/kernel/kvm.c
20714 +++ b/arch/x86/kernel/kvm.c
20715 @@ -452,7 +452,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
20716 return NOTIFY_OK;
20717 }
20718
20719 -static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
20720 +static struct notifier_block kvm_cpu_notifier = {
20721 .notifier_call = kvm_cpu_notify,
20722 };
20723 #endif
20724 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
20725 index ebc9873..1b9724b 100644
20726 --- a/arch/x86/kernel/ldt.c
20727 +++ b/arch/x86/kernel/ldt.c
20728 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
20729 if (reload) {
20730 #ifdef CONFIG_SMP
20731 preempt_disable();
20732 - load_LDT(pc);
20733 + load_LDT_nolock(pc);
20734 if (!cpumask_equal(mm_cpumask(current->mm),
20735 cpumask_of(smp_processor_id())))
20736 smp_call_function(flush_ldt, current->mm, 1);
20737 preempt_enable();
20738 #else
20739 - load_LDT(pc);
20740 + load_LDT_nolock(pc);
20741 #endif
20742 }
20743 if (oldsize) {
20744 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
20745 return err;
20746
20747 for (i = 0; i < old->size; i++)
20748 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
20749 + write_ldt_entry(new->ldt, i, old->ldt + i);
20750 return 0;
20751 }
20752
20753 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
20754 retval = copy_ldt(&mm->context, &old_mm->context);
20755 mutex_unlock(&old_mm->context.lock);
20756 }
20757 +
20758 + if (tsk == current) {
20759 + mm->context.vdso = 0;
20760 +
20761 +#ifdef CONFIG_X86_32
20762 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
20763 + mm->context.user_cs_base = 0UL;
20764 + mm->context.user_cs_limit = ~0UL;
20765 +
20766 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
20767 + cpus_clear(mm->context.cpu_user_cs_mask);
20768 +#endif
20769 +
20770 +#endif
20771 +#endif
20772 +
20773 + }
20774 +
20775 return retval;
20776 }
20777
20778 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
20779 }
20780 }
20781
20782 +#ifdef CONFIG_PAX_SEGMEXEC
20783 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
20784 + error = -EINVAL;
20785 + goto out_unlock;
20786 + }
20787 +#endif
20788 +
20789 fill_ldt(&ldt, &ldt_info);
20790 if (oldmode)
20791 ldt.avl = 0;
20792 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
20793 index 5b19e4d..6476a76 100644
20794 --- a/arch/x86/kernel/machine_kexec_32.c
20795 +++ b/arch/x86/kernel/machine_kexec_32.c
20796 @@ -26,7 +26,7 @@
20797 #include <asm/cacheflush.h>
20798 #include <asm/debugreg.h>
20799
20800 -static void set_idt(void *newidt, __u16 limit)
20801 +static void set_idt(struct desc_struct *newidt, __u16 limit)
20802 {
20803 struct desc_ptr curidt;
20804
20805 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
20806 }
20807
20808
20809 -static void set_gdt(void *newgdt, __u16 limit)
20810 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
20811 {
20812 struct desc_ptr curgdt;
20813
20814 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
20815 }
20816
20817 control_page = page_address(image->control_code_page);
20818 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
20819 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
20820
20821 relocate_kernel_ptr = control_page;
20822 page_list[PA_CONTROL_PAGE] = __pa(control_page);
20823 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
20824 index 3a04b22..1d2eb09 100644
20825 --- a/arch/x86/kernel/microcode_core.c
20826 +++ b/arch/x86/kernel/microcode_core.c
20827 @@ -512,7 +512,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
20828 return NOTIFY_OK;
20829 }
20830
20831 -static struct notifier_block __refdata mc_cpu_notifier = {
20832 +static struct notifier_block mc_cpu_notifier = {
20833 .notifier_call = mc_cpu_callback,
20834 };
20835
20836 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
20837 index 3544aed..01ddc1c 100644
20838 --- a/arch/x86/kernel/microcode_intel.c
20839 +++ b/arch/x86/kernel/microcode_intel.c
20840 @@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
20841
20842 static int get_ucode_user(void *to, const void *from, size_t n)
20843 {
20844 - return copy_from_user(to, from, n);
20845 + return copy_from_user(to, (const void __force_user *)from, n);
20846 }
20847
20848 static enum ucode_state
20849 request_microcode_user(int cpu, const void __user *buf, size_t size)
20850 {
20851 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
20852 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
20853 }
20854
20855 static void microcode_fini_cpu(int cpu)
20856 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
20857 index 216a4d7..228255a 100644
20858 --- a/arch/x86/kernel/module.c
20859 +++ b/arch/x86/kernel/module.c
20860 @@ -43,15 +43,60 @@ do { \
20861 } while (0)
20862 #endif
20863
20864 -void *module_alloc(unsigned long size)
20865 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
20866 {
20867 - if (PAGE_ALIGN(size) > MODULES_LEN)
20868 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
20869 return NULL;
20870 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
20871 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
20872 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
20873 -1, __builtin_return_address(0));
20874 }
20875
20876 +void *module_alloc(unsigned long size)
20877 +{
20878 +
20879 +#ifdef CONFIG_PAX_KERNEXEC
20880 + return __module_alloc(size, PAGE_KERNEL);
20881 +#else
20882 + return __module_alloc(size, PAGE_KERNEL_EXEC);
20883 +#endif
20884 +
20885 +}
20886 +
20887 +#ifdef CONFIG_PAX_KERNEXEC
20888 +#ifdef CONFIG_X86_32
20889 +void *module_alloc_exec(unsigned long size)
20890 +{
20891 + struct vm_struct *area;
20892 +
20893 + if (size == 0)
20894 + return NULL;
20895 +
20896 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
20897 + return area ? area->addr : NULL;
20898 +}
20899 +EXPORT_SYMBOL(module_alloc_exec);
20900 +
20901 +void module_free_exec(struct module *mod, void *module_region)
20902 +{
20903 + vunmap(module_region);
20904 +}
20905 +EXPORT_SYMBOL(module_free_exec);
20906 +#else
20907 +void module_free_exec(struct module *mod, void *module_region)
20908 +{
20909 + module_free(mod, module_region);
20910 +}
20911 +EXPORT_SYMBOL(module_free_exec);
20912 +
20913 +void *module_alloc_exec(unsigned long size)
20914 +{
20915 + return __module_alloc(size, PAGE_KERNEL_RX);
20916 +}
20917 +EXPORT_SYMBOL(module_alloc_exec);
20918 +#endif
20919 +#endif
20920 +
20921 #ifdef CONFIG_X86_32
20922 int apply_relocate(Elf32_Shdr *sechdrs,
20923 const char *strtab,
20924 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20925 unsigned int i;
20926 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
20927 Elf32_Sym *sym;
20928 - uint32_t *location;
20929 + uint32_t *plocation, location;
20930
20931 DEBUGP("Applying relocate section %u to %u\n",
20932 relsec, sechdrs[relsec].sh_info);
20933 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
20934 /* This is where to make the change */
20935 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
20936 - + rel[i].r_offset;
20937 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
20938 + location = (uint32_t)plocation;
20939 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
20940 + plocation = ktla_ktva((void *)plocation);
20941 /* This is the symbol it is referring to. Note that all
20942 undefined symbols have been resolved. */
20943 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
20944 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
20945 switch (ELF32_R_TYPE(rel[i].r_info)) {
20946 case R_386_32:
20947 /* We add the value into the location given */
20948 - *location += sym->st_value;
20949 + pax_open_kernel();
20950 + *plocation += sym->st_value;
20951 + pax_close_kernel();
20952 break;
20953 case R_386_PC32:
20954 /* Add the value, subtract its position */
20955 - *location += sym->st_value - (uint32_t)location;
20956 + pax_open_kernel();
20957 + *plocation += sym->st_value - location;
20958 + pax_close_kernel();
20959 break;
20960 default:
20961 pr_err("%s: Unknown relocation: %u\n",
20962 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
20963 case R_X86_64_NONE:
20964 break;
20965 case R_X86_64_64:
20966 + pax_open_kernel();
20967 *(u64 *)loc = val;
20968 + pax_close_kernel();
20969 break;
20970 case R_X86_64_32:
20971 + pax_open_kernel();
20972 *(u32 *)loc = val;
20973 + pax_close_kernel();
20974 if (val != *(u32 *)loc)
20975 goto overflow;
20976 break;
20977 case R_X86_64_32S:
20978 + pax_open_kernel();
20979 *(s32 *)loc = val;
20980 + pax_close_kernel();
20981 if ((s64)val != *(s32 *)loc)
20982 goto overflow;
20983 break;
20984 case R_X86_64_PC32:
20985 val -= (u64)loc;
20986 + pax_open_kernel();
20987 *(u32 *)loc = val;
20988 + pax_close_kernel();
20989 +
20990 #if 0
20991 if ((s64)val != *(s32 *)loc)
20992 goto overflow;
20993 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
20994 index 4929502..686c291 100644
20995 --- a/arch/x86/kernel/msr.c
20996 +++ b/arch/x86/kernel/msr.c
20997 @@ -234,7 +234,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
20998 return notifier_from_errno(err);
20999 }
21000
21001 -static struct notifier_block __refdata msr_class_cpu_notifier = {
21002 +static struct notifier_block msr_class_cpu_notifier = {
21003 .notifier_call = msr_class_cpu_callback,
21004 };
21005
21006 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21007 index f84f5c5..e27e54b 100644
21008 --- a/arch/x86/kernel/nmi.c
21009 +++ b/arch/x86/kernel/nmi.c
21010 @@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21011 dotraplinkage notrace __kprobes void
21012 do_nmi(struct pt_regs *regs, long error_code)
21013 {
21014 +
21015 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21016 + if (!user_mode(regs)) {
21017 + unsigned long cs = regs->cs & 0xFFFF;
21018 + unsigned long ip = ktva_ktla(regs->ip);
21019 +
21020 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21021 + regs->ip = ip;
21022 + }
21023 +#endif
21024 +
21025 nmi_nesting_preprocess(regs);
21026
21027 nmi_enter();
21028 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21029 index 676b8c7..870ba04 100644
21030 --- a/arch/x86/kernel/paravirt-spinlocks.c
21031 +++ b/arch/x86/kernel/paravirt-spinlocks.c
21032 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21033 arch_spin_lock(lock);
21034 }
21035
21036 -struct pv_lock_ops pv_lock_ops = {
21037 +struct pv_lock_ops pv_lock_ops __read_only = {
21038 #ifdef CONFIG_SMP
21039 .spin_is_locked = __ticket_spin_is_locked,
21040 .spin_is_contended = __ticket_spin_is_contended,
21041 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21042 index 17fff18..5cfa0f4 100644
21043 --- a/arch/x86/kernel/paravirt.c
21044 +++ b/arch/x86/kernel/paravirt.c
21045 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21046 {
21047 return x;
21048 }
21049 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21050 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21051 +#endif
21052
21053 void __init default_banner(void)
21054 {
21055 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21056 if (opfunc == NULL)
21057 /* If there's no function, patch it with a ud2a (BUG) */
21058 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21059 - else if (opfunc == _paravirt_nop)
21060 + else if (opfunc == (void *)_paravirt_nop)
21061 /* If the operation is a nop, then nop the callsite */
21062 ret = paravirt_patch_nop();
21063
21064 /* identity functions just return their single argument */
21065 - else if (opfunc == _paravirt_ident_32)
21066 + else if (opfunc == (void *)_paravirt_ident_32)
21067 ret = paravirt_patch_ident_32(insnbuf, len);
21068 - else if (opfunc == _paravirt_ident_64)
21069 + else if (opfunc == (void *)_paravirt_ident_64)
21070 ret = paravirt_patch_ident_64(insnbuf, len);
21071 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21072 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21073 + ret = paravirt_patch_ident_64(insnbuf, len);
21074 +#endif
21075
21076 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21077 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21078 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21079 if (insn_len > len || start == NULL)
21080 insn_len = len;
21081 else
21082 - memcpy(insnbuf, start, insn_len);
21083 + memcpy(insnbuf, ktla_ktva(start), insn_len);
21084
21085 return insn_len;
21086 }
21087 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
21088 preempt_enable();
21089 }
21090
21091 -struct pv_info pv_info = {
21092 +struct pv_info pv_info __read_only = {
21093 .name = "bare hardware",
21094 .paravirt_enabled = 0,
21095 .kernel_rpl = 0,
21096 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
21097 #endif
21098 };
21099
21100 -struct pv_init_ops pv_init_ops = {
21101 +struct pv_init_ops pv_init_ops __read_only = {
21102 .patch = native_patch,
21103 };
21104
21105 -struct pv_time_ops pv_time_ops = {
21106 +struct pv_time_ops pv_time_ops __read_only = {
21107 .sched_clock = native_sched_clock,
21108 .steal_clock = native_steal_clock,
21109 };
21110
21111 -struct pv_irq_ops pv_irq_ops = {
21112 +struct pv_irq_ops pv_irq_ops __read_only = {
21113 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21114 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21115 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21116 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21117 #endif
21118 };
21119
21120 -struct pv_cpu_ops pv_cpu_ops = {
21121 +struct pv_cpu_ops pv_cpu_ops __read_only = {
21122 .cpuid = native_cpuid,
21123 .get_debugreg = native_get_debugreg,
21124 .set_debugreg = native_set_debugreg,
21125 @@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21126 .end_context_switch = paravirt_nop,
21127 };
21128
21129 -struct pv_apic_ops pv_apic_ops = {
21130 +struct pv_apic_ops pv_apic_ops __read_only= {
21131 #ifdef CONFIG_X86_LOCAL_APIC
21132 .startup_ipi_hook = paravirt_nop,
21133 #endif
21134 };
21135
21136 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21137 +#ifdef CONFIG_X86_32
21138 +#ifdef CONFIG_X86_PAE
21139 +/* 64-bit pagetable entries */
21140 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21141 +#else
21142 /* 32-bit pagetable entries */
21143 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21144 +#endif
21145 #else
21146 /* 64-bit pagetable entries */
21147 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21148 #endif
21149
21150 -struct pv_mmu_ops pv_mmu_ops = {
21151 +struct pv_mmu_ops pv_mmu_ops __read_only = {
21152
21153 .read_cr2 = native_read_cr2,
21154 .write_cr2 = native_write_cr2,
21155 @@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21156 .make_pud = PTE_IDENT,
21157
21158 .set_pgd = native_set_pgd,
21159 + .set_pgd_batched = native_set_pgd_batched,
21160 #endif
21161 #endif /* PAGETABLE_LEVELS >= 3 */
21162
21163 @@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21164 },
21165
21166 .set_fixmap = native_set_fixmap,
21167 +
21168 +#ifdef CONFIG_PAX_KERNEXEC
21169 + .pax_open_kernel = native_pax_open_kernel,
21170 + .pax_close_kernel = native_pax_close_kernel,
21171 +#endif
21172 +
21173 };
21174
21175 EXPORT_SYMBOL_GPL(pv_time_ops);
21176 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21177 index 35ccf75..7a15747 100644
21178 --- a/arch/x86/kernel/pci-iommu_table.c
21179 +++ b/arch/x86/kernel/pci-iommu_table.c
21180 @@ -2,7 +2,7 @@
21181 #include <asm/iommu_table.h>
21182 #include <linux/string.h>
21183 #include <linux/kallsyms.h>
21184 -
21185 +#include <linux/sched.h>
21186
21187 #define DEBUG 1
21188
21189 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21190 index 2ed787f..f70c9f6 100644
21191 --- a/arch/x86/kernel/process.c
21192 +++ b/arch/x86/kernel/process.c
21193 @@ -36,7 +36,8 @@
21194 * section. Since TSS's are completely CPU-local, we want them
21195 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21196 */
21197 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
21198 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
21199 +EXPORT_SYMBOL(init_tss);
21200
21201 #ifdef CONFIG_X86_64
21202 static DEFINE_PER_CPU(unsigned char, is_idle);
21203 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
21204 task_xstate_cachep =
21205 kmem_cache_create("task_xstate", xstate_size,
21206 __alignof__(union thread_xstate),
21207 - SLAB_PANIC | SLAB_NOTRACK, NULL);
21208 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
21209 }
21210
21211 /*
21212 @@ -105,7 +106,7 @@ void exit_thread(void)
21213 unsigned long *bp = t->io_bitmap_ptr;
21214
21215 if (bp) {
21216 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
21217 + struct tss_struct *tss = init_tss + get_cpu();
21218
21219 t->io_bitmap_ptr = NULL;
21220 clear_thread_flag(TIF_IO_BITMAP);
21221 @@ -136,7 +137,7 @@ void show_regs_common(void)
21222 board = dmi_get_system_info(DMI_BOARD_NAME);
21223
21224 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
21225 - current->pid, current->comm, print_tainted(),
21226 + task_pid_nr(current), current->comm, print_tainted(),
21227 init_utsname()->release,
21228 (int)strcspn(init_utsname()->version, " "),
21229 init_utsname()->version,
21230 @@ -149,6 +150,9 @@ void flush_thread(void)
21231 {
21232 struct task_struct *tsk = current;
21233
21234 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
21235 + loadsegment(gs, 0);
21236 +#endif
21237 flush_ptrace_hw_breakpoint(tsk);
21238 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
21239 drop_init_fpu(tsk);
21240 @@ -301,7 +305,7 @@ static void __exit_idle(void)
21241 void exit_idle(void)
21242 {
21243 /* idle loop has pid 0 */
21244 - if (current->pid)
21245 + if (task_pid_nr(current))
21246 return;
21247 __exit_idle();
21248 }
21249 @@ -404,7 +408,7 @@ bool set_pm_idle_to_default(void)
21250
21251 return ret;
21252 }
21253 -void stop_this_cpu(void *dummy)
21254 +__noreturn void stop_this_cpu(void *dummy)
21255 {
21256 local_irq_disable();
21257 /*
21258 @@ -632,16 +636,37 @@ static int __init idle_setup(char *str)
21259 }
21260 early_param("idle", idle_setup);
21261
21262 -unsigned long arch_align_stack(unsigned long sp)
21263 +#ifdef CONFIG_PAX_RANDKSTACK
21264 +void pax_randomize_kstack(struct pt_regs *regs)
21265 {
21266 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
21267 - sp -= get_random_int() % 8192;
21268 - return sp & ~0xf;
21269 -}
21270 + struct thread_struct *thread = &current->thread;
21271 + unsigned long time;
21272
21273 -unsigned long arch_randomize_brk(struct mm_struct *mm)
21274 -{
21275 - unsigned long range_end = mm->brk + 0x02000000;
21276 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
21277 -}
21278 + if (!randomize_va_space)
21279 + return;
21280 +
21281 + if (v8086_mode(regs))
21282 + return;
21283
21284 + rdtscl(time);
21285 +
21286 + /* P4 seems to return a 0 LSB, ignore it */
21287 +#ifdef CONFIG_MPENTIUM4
21288 + time &= 0x3EUL;
21289 + time <<= 2;
21290 +#elif defined(CONFIG_X86_64)
21291 + time &= 0xFUL;
21292 + time <<= 4;
21293 +#else
21294 + time &= 0x1FUL;
21295 + time <<= 3;
21296 +#endif
21297 +
21298 + thread->sp0 ^= time;
21299 + load_sp0(init_tss + smp_processor_id(), thread);
21300 +
21301 +#ifdef CONFIG_X86_64
21302 + this_cpu_write(kernel_stack, thread->sp0);
21303 +#endif
21304 +}
21305 +#endif
21306 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
21307 index b5a8905..d9cacac 100644
21308 --- a/arch/x86/kernel/process_32.c
21309 +++ b/arch/x86/kernel/process_32.c
21310 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
21311 unsigned long thread_saved_pc(struct task_struct *tsk)
21312 {
21313 return ((unsigned long *)tsk->thread.sp)[3];
21314 +//XXX return tsk->thread.eip;
21315 }
21316
21317 void __show_regs(struct pt_regs *regs, int all)
21318 @@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
21319 unsigned long sp;
21320 unsigned short ss, gs;
21321
21322 - if (user_mode_vm(regs)) {
21323 + if (user_mode(regs)) {
21324 sp = regs->sp;
21325 ss = regs->ss & 0xffff;
21326 - gs = get_user_gs(regs);
21327 } else {
21328 sp = kernel_stack_pointer(regs);
21329 savesegment(ss, ss);
21330 - savesegment(gs, gs);
21331 }
21332 + gs = get_user_gs(regs);
21333
21334 show_regs_common();
21335
21336 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
21337 (u16)regs->cs, regs->ip, regs->flags,
21338 - smp_processor_id());
21339 + raw_smp_processor_id());
21340 print_symbol("EIP is at %s\n", regs->ip);
21341
21342 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
21343 @@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
21344 int copy_thread(unsigned long clone_flags, unsigned long sp,
21345 unsigned long arg, struct task_struct *p)
21346 {
21347 - struct pt_regs *childregs = task_pt_regs(p);
21348 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
21349 struct task_struct *tsk;
21350 int err;
21351
21352 p->thread.sp = (unsigned long) childregs;
21353 p->thread.sp0 = (unsigned long) (childregs+1);
21354 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21355
21356 if (unlikely(p->flags & PF_KTHREAD)) {
21357 /* kernel thread */
21358 memset(childregs, 0, sizeof(struct pt_regs));
21359 p->thread.ip = (unsigned long) ret_from_kernel_thread;
21360 - task_user_gs(p) = __KERNEL_STACK_CANARY;
21361 - childregs->ds = __USER_DS;
21362 - childregs->es = __USER_DS;
21363 + savesegment(gs, childregs->gs);
21364 + childregs->ds = __KERNEL_DS;
21365 + childregs->es = __KERNEL_DS;
21366 childregs->fs = __KERNEL_PERCPU;
21367 childregs->bx = sp; /* function */
21368 childregs->bp = arg;
21369 @@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21370 struct thread_struct *prev = &prev_p->thread,
21371 *next = &next_p->thread;
21372 int cpu = smp_processor_id();
21373 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21374 + struct tss_struct *tss = init_tss + cpu;
21375 fpu_switch_t fpu;
21376
21377 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
21378 @@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21379 */
21380 lazy_save_gs(prev->gs);
21381
21382 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21383 + __set_fs(task_thread_info(next_p)->addr_limit);
21384 +#endif
21385 +
21386 /*
21387 * Load the per-thread Thread-Local Storage descriptor.
21388 */
21389 @@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21390 */
21391 arch_end_context_switch(next_p);
21392
21393 + this_cpu_write(current_task, next_p);
21394 + this_cpu_write(current_tinfo, &next_p->tinfo);
21395 +
21396 /*
21397 * Restore %gs if needed (which is common)
21398 */
21399 @@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21400
21401 switch_fpu_finish(next_p, fpu);
21402
21403 - this_cpu_write(current_task, next_p);
21404 -
21405 return prev_p;
21406 }
21407
21408 @@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
21409 } while (count++ < 16);
21410 return 0;
21411 }
21412 -
21413 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
21414 index 6e68a61..955a9a5 100644
21415 --- a/arch/x86/kernel/process_64.c
21416 +++ b/arch/x86/kernel/process_64.c
21417 @@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
21418 struct pt_regs *childregs;
21419 struct task_struct *me = current;
21420
21421 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
21422 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
21423 childregs = task_pt_regs(p);
21424 p->thread.sp = (unsigned long) childregs;
21425 p->thread.usersp = me->thread.usersp;
21426 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
21427 set_tsk_thread_flag(p, TIF_FORK);
21428 p->fpu_counter = 0;
21429 p->thread.io_bitmap_ptr = NULL;
21430 @@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21431 struct thread_struct *prev = &prev_p->thread;
21432 struct thread_struct *next = &next_p->thread;
21433 int cpu = smp_processor_id();
21434 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
21435 + struct tss_struct *tss = init_tss + cpu;
21436 unsigned fsindex, gsindex;
21437 fpu_switch_t fpu;
21438
21439 @@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
21440 prev->usersp = this_cpu_read(old_rsp);
21441 this_cpu_write(old_rsp, next->usersp);
21442 this_cpu_write(current_task, next_p);
21443 + this_cpu_write(current_tinfo, &next_p->tinfo);
21444
21445 - this_cpu_write(kernel_stack,
21446 - (unsigned long)task_stack_page(next_p) +
21447 - THREAD_SIZE - KERNEL_STACK_OFFSET);
21448 + this_cpu_write(kernel_stack, next->sp0);
21449
21450 /*
21451 * Now maybe reload the debug registers and handle I/O bitmaps
21452 @@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
21453 if (!p || p == current || p->state == TASK_RUNNING)
21454 return 0;
21455 stack = (unsigned long)task_stack_page(p);
21456 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
21457 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
21458 return 0;
21459 fp = *(u64 *)(p->thread.sp);
21460 do {
21461 - if (fp < (unsigned long)stack ||
21462 - fp >= (unsigned long)stack+THREAD_SIZE)
21463 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
21464 return 0;
21465 ip = *(u64 *)(fp+8);
21466 if (!in_sched_functions(ip))
21467 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
21468 index b629bbe..0fa615a 100644
21469 --- a/arch/x86/kernel/ptrace.c
21470 +++ b/arch/x86/kernel/ptrace.c
21471 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
21472 {
21473 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
21474 unsigned long sp = (unsigned long)&regs->sp;
21475 - struct thread_info *tinfo;
21476
21477 - if (context == (sp & ~(THREAD_SIZE - 1)))
21478 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
21479 return sp;
21480
21481 - tinfo = (struct thread_info *)context;
21482 - if (tinfo->previous_esp)
21483 - return tinfo->previous_esp;
21484 + sp = *(unsigned long *)context;
21485 + if (sp)
21486 + return sp;
21487
21488 return (unsigned long)regs;
21489 }
21490 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
21491 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
21492 {
21493 int i;
21494 - int dr7 = 0;
21495 + unsigned long dr7 = 0;
21496 struct arch_hw_breakpoint *info;
21497
21498 for (i = 0; i < HBP_NUM; i++) {
21499 @@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
21500 unsigned long addr, unsigned long data)
21501 {
21502 int ret;
21503 - unsigned long __user *datap = (unsigned long __user *)data;
21504 + unsigned long __user *datap = (__force unsigned long __user *)data;
21505
21506 switch (request) {
21507 /* read the word at location addr in the USER area. */
21508 @@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
21509 if ((int) addr < 0)
21510 return -EIO;
21511 ret = do_get_thread_area(child, addr,
21512 - (struct user_desc __user *)data);
21513 + (__force struct user_desc __user *) data);
21514 break;
21515
21516 case PTRACE_SET_THREAD_AREA:
21517 if ((int) addr < 0)
21518 return -EIO;
21519 ret = do_set_thread_area(child, addr,
21520 - (struct user_desc __user *)data, 0);
21521 + (__force struct user_desc __user *) data, 0);
21522 break;
21523 #endif
21524
21525 @@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
21526
21527 #ifdef CONFIG_X86_64
21528
21529 -static struct user_regset x86_64_regsets[] __read_mostly = {
21530 +static user_regset_no_const x86_64_regsets[] __read_only = {
21531 [REGSET_GENERAL] = {
21532 .core_note_type = NT_PRSTATUS,
21533 .n = sizeof(struct user_regs_struct) / sizeof(long),
21534 @@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
21535 #endif /* CONFIG_X86_64 */
21536
21537 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
21538 -static struct user_regset x86_32_regsets[] __read_mostly = {
21539 +static user_regset_no_const x86_32_regsets[] __read_only = {
21540 [REGSET_GENERAL] = {
21541 .core_note_type = NT_PRSTATUS,
21542 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
21543 @@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
21544 */
21545 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
21546
21547 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21548 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
21549 {
21550 #ifdef CONFIG_X86_64
21551 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
21552 @@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
21553 memset(info, 0, sizeof(*info));
21554 info->si_signo = SIGTRAP;
21555 info->si_code = si_code;
21556 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
21557 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
21558 }
21559
21560 void user_single_step_siginfo(struct task_struct *tsk,
21561 @@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
21562 # define IS_IA32 0
21563 #endif
21564
21565 +#ifdef CONFIG_GRKERNSEC_SETXID
21566 +extern void gr_delayed_cred_worker(void);
21567 +#endif
21568 +
21569 /*
21570 * We must return the syscall number to actually look up in the table.
21571 * This can be -1L to skip running any syscall at all.
21572 @@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
21573
21574 user_exit();
21575
21576 +#ifdef CONFIG_GRKERNSEC_SETXID
21577 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21578 + gr_delayed_cred_worker();
21579 +#endif
21580 +
21581 /*
21582 * If we stepped into a sysenter/syscall insn, it trapped in
21583 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
21584 @@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
21585 */
21586 user_exit();
21587
21588 +#ifdef CONFIG_GRKERNSEC_SETXID
21589 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
21590 + gr_delayed_cred_worker();
21591 +#endif
21592 +
21593 audit_syscall_exit(regs);
21594
21595 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
21596 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
21597 index 85c3959..76b89f9 100644
21598 --- a/arch/x86/kernel/pvclock.c
21599 +++ b/arch/x86/kernel/pvclock.c
21600 @@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
21601 return pv_tsc_khz;
21602 }
21603
21604 -static atomic64_t last_value = ATOMIC64_INIT(0);
21605 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
21606
21607 void pvclock_resume(void)
21608 {
21609 - atomic64_set(&last_value, 0);
21610 + atomic64_set_unchecked(&last_value, 0);
21611 }
21612
21613 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
21614 @@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
21615 * updating at the same time, and one of them could be slightly behind,
21616 * making the assumption that last_value always go forward fail to hold.
21617 */
21618 - last = atomic64_read(&last_value);
21619 + last = atomic64_read_unchecked(&last_value);
21620 do {
21621 if (ret < last)
21622 return last;
21623 - last = atomic64_cmpxchg(&last_value, last, ret);
21624 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
21625 } while (unlikely(last != ret));
21626
21627 return ret;
21628 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
21629 index 76fa1e9..abf09ea 100644
21630 --- a/arch/x86/kernel/reboot.c
21631 +++ b/arch/x86/kernel/reboot.c
21632 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
21633 EXPORT_SYMBOL(pm_power_off);
21634
21635 static const struct desc_ptr no_idt = {};
21636 -static int reboot_mode;
21637 +static unsigned short reboot_mode;
21638 enum reboot_type reboot_type = BOOT_ACPI;
21639 int reboot_force;
21640
21641 @@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
21642
21643 void __noreturn machine_real_restart(unsigned int type)
21644 {
21645 +
21646 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21647 + struct desc_struct *gdt;
21648 +#endif
21649 +
21650 local_irq_disable();
21651
21652 /*
21653 @@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
21654
21655 /* Jump to the identity-mapped low memory code */
21656 #ifdef CONFIG_X86_32
21657 - asm volatile("jmpl *%0" : :
21658 +
21659 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21660 + gdt = get_cpu_gdt_table(smp_processor_id());
21661 + pax_open_kernel();
21662 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21663 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
21664 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
21665 + loadsegment(ds, __KERNEL_DS);
21666 + loadsegment(es, __KERNEL_DS);
21667 + loadsegment(ss, __KERNEL_DS);
21668 +#endif
21669 +#ifdef CONFIG_PAX_KERNEXEC
21670 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
21671 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
21672 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
21673 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
21674 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
21675 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
21676 +#endif
21677 + pax_close_kernel();
21678 +#endif
21679 +
21680 + asm volatile("ljmpl *%0" : :
21681 "rm" (real_mode_header->machine_real_restart_asm),
21682 "a" (type));
21683 #else
21684 @@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
21685 * try to force a triple fault and then cycle between hitting the keyboard
21686 * controller and doing that
21687 */
21688 -static void native_machine_emergency_restart(void)
21689 +static void __noreturn native_machine_emergency_restart(void)
21690 {
21691 int i;
21692 int attempt = 0;
21693 @@ -654,13 +681,13 @@ void native_machine_shutdown(void)
21694 #endif
21695 }
21696
21697 -static void __machine_emergency_restart(int emergency)
21698 +static void __noreturn __machine_emergency_restart(int emergency)
21699 {
21700 reboot_emergency = emergency;
21701 machine_ops.emergency_restart();
21702 }
21703
21704 -static void native_machine_restart(char *__unused)
21705 +static void __noreturn native_machine_restart(char *__unused)
21706 {
21707 pr_notice("machine restart\n");
21708
21709 @@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
21710 __machine_emergency_restart(0);
21711 }
21712
21713 -static void native_machine_halt(void)
21714 +static void __noreturn native_machine_halt(void)
21715 {
21716 /* Stop other cpus and apics */
21717 machine_shutdown();
21718 @@ -679,7 +706,7 @@ static void native_machine_halt(void)
21719 stop_this_cpu(NULL);
21720 }
21721
21722 -static void native_machine_power_off(void)
21723 +static void __noreturn native_machine_power_off(void)
21724 {
21725 if (pm_power_off) {
21726 if (!reboot_force)
21727 @@ -688,9 +715,10 @@ static void native_machine_power_off(void)
21728 }
21729 /* A fallback in case there is no PM info available */
21730 tboot_shutdown(TB_SHUTDOWN_HALT);
21731 + unreachable();
21732 }
21733
21734 -struct machine_ops machine_ops = {
21735 +struct machine_ops machine_ops __read_only = {
21736 .power_off = native_machine_power_off,
21737 .shutdown = native_machine_shutdown,
21738 .emergency_restart = native_machine_emergency_restart,
21739 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
21740 index 7a6f3b3..bed145d7 100644
21741 --- a/arch/x86/kernel/relocate_kernel_64.S
21742 +++ b/arch/x86/kernel/relocate_kernel_64.S
21743 @@ -11,6 +11,7 @@
21744 #include <asm/kexec.h>
21745 #include <asm/processor-flags.h>
21746 #include <asm/pgtable_types.h>
21747 +#include <asm/alternative-asm.h>
21748
21749 /*
21750 * Must be relocatable PIC code callable as a C function
21751 @@ -160,13 +161,14 @@ identity_mapped:
21752 xorq %rbp, %rbp
21753 xorq %r8, %r8
21754 xorq %r9, %r9
21755 - xorq %r10, %r9
21756 + xorq %r10, %r10
21757 xorq %r11, %r11
21758 xorq %r12, %r12
21759 xorq %r13, %r13
21760 xorq %r14, %r14
21761 xorq %r15, %r15
21762
21763 + pax_force_retaddr 0, 1
21764 ret
21765
21766 1:
21767 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
21768 index 8b24289..d37b58b 100644
21769 --- a/arch/x86/kernel/setup.c
21770 +++ b/arch/x86/kernel/setup.c
21771 @@ -437,7 +437,7 @@ static void __init parse_setup_data(void)
21772
21773 switch (data->type) {
21774 case SETUP_E820_EXT:
21775 - parse_e820_ext(data);
21776 + parse_e820_ext((struct setup_data __force_kernel *)data);
21777 break;
21778 case SETUP_DTB:
21779 add_dtb(pa_data);
21780 @@ -706,7 +706,7 @@ static void __init trim_bios_range(void)
21781 * area (640->1Mb) as ram even though it is not.
21782 * take them out.
21783 */
21784 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
21785 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
21786
21787 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
21788 }
21789 @@ -830,14 +830,14 @@ void __init setup_arch(char **cmdline_p)
21790
21791 if (!boot_params.hdr.root_flags)
21792 root_mountflags &= ~MS_RDONLY;
21793 - init_mm.start_code = (unsigned long) _text;
21794 - init_mm.end_code = (unsigned long) _etext;
21795 + init_mm.start_code = ktla_ktva((unsigned long) _text);
21796 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
21797 init_mm.end_data = (unsigned long) _edata;
21798 init_mm.brk = _brk_end;
21799
21800 - code_resource.start = virt_to_phys(_text);
21801 - code_resource.end = virt_to_phys(_etext)-1;
21802 - data_resource.start = virt_to_phys(_etext);
21803 + code_resource.start = virt_to_phys(ktla_ktva(_text));
21804 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
21805 + data_resource.start = virt_to_phys(_sdata);
21806 data_resource.end = virt_to_phys(_edata)-1;
21807 bss_resource.start = virt_to_phys(&__bss_start);
21808 bss_resource.end = virt_to_phys(&__bss_stop)-1;
21809 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
21810 index 5cdff03..5810740 100644
21811 --- a/arch/x86/kernel/setup_percpu.c
21812 +++ b/arch/x86/kernel/setup_percpu.c
21813 @@ -21,19 +21,17 @@
21814 #include <asm/cpu.h>
21815 #include <asm/stackprotector.h>
21816
21817 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
21818 +#ifdef CONFIG_SMP
21819 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
21820 EXPORT_PER_CPU_SYMBOL(cpu_number);
21821 +#endif
21822
21823 -#ifdef CONFIG_X86_64
21824 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
21825 -#else
21826 -#define BOOT_PERCPU_OFFSET 0
21827 -#endif
21828
21829 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
21830 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
21831
21832 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
21833 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
21834 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
21835 };
21836 EXPORT_SYMBOL(__per_cpu_offset);
21837 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
21838 {
21839 #ifdef CONFIG_X86_32
21840 struct desc_struct gdt;
21841 + unsigned long base = per_cpu_offset(cpu);
21842
21843 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
21844 - 0x2 | DESCTYPE_S, 0x8);
21845 - gdt.s = 1;
21846 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
21847 + 0x83 | DESCTYPE_S, 0xC);
21848 write_gdt_entry(get_cpu_gdt_table(cpu),
21849 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
21850 #endif
21851 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
21852 /* alrighty, percpu areas up and running */
21853 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
21854 for_each_possible_cpu(cpu) {
21855 +#ifdef CONFIG_CC_STACKPROTECTOR
21856 +#ifdef CONFIG_X86_32
21857 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
21858 +#endif
21859 +#endif
21860 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
21861 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
21862 per_cpu(cpu_number, cpu) = cpu;
21863 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
21864 */
21865 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
21866 #endif
21867 +#ifdef CONFIG_CC_STACKPROTECTOR
21868 +#ifdef CONFIG_X86_32
21869 + if (!cpu)
21870 + per_cpu(stack_canary.canary, cpu) = canary;
21871 +#endif
21872 +#endif
21873 /*
21874 * Up to this point, the boot CPU has been using .init.data
21875 * area. Reload any changed state for the boot CPU.
21876 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
21877 index d6bf1f3..3ffce5a 100644
21878 --- a/arch/x86/kernel/signal.c
21879 +++ b/arch/x86/kernel/signal.c
21880 @@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
21881 * Align the stack pointer according to the i386 ABI,
21882 * i.e. so that on function entry ((sp + 4) & 15) == 0.
21883 */
21884 - sp = ((sp + 4) & -16ul) - 4;
21885 + sp = ((sp - 12) & -16ul) - 4;
21886 #else /* !CONFIG_X86_32 */
21887 sp = round_down(sp, 16) - 8;
21888 #endif
21889 @@ -304,9 +304,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21890 }
21891
21892 if (current->mm->context.vdso)
21893 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21894 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
21895 else
21896 - restorer = &frame->retcode;
21897 + restorer = (void __user *)&frame->retcode;
21898 if (ka->sa.sa_flags & SA_RESTORER)
21899 restorer = ka->sa.sa_restorer;
21900
21901 @@ -320,7 +320,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
21902 * reasons and because gdb uses it as a signature to notice
21903 * signal handler stack frames.
21904 */
21905 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
21906 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
21907
21908 if (err)
21909 return -EFAULT;
21910 @@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21911 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
21912
21913 /* Set up to return from userspace. */
21914 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21915 + if (current->mm->context.vdso)
21916 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
21917 + else
21918 + restorer = (void __user *)&frame->retcode;
21919 if (ka->sa.sa_flags & SA_RESTORER)
21920 restorer = ka->sa.sa_restorer;
21921 put_user_ex(restorer, &frame->pretcode);
21922 @@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
21923 * reasons and because gdb uses it as a signature to notice
21924 * signal handler stack frames.
21925 */
21926 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
21927 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
21928 } put_user_catch(err);
21929
21930 err |= copy_siginfo_to_user(&frame->info, info);
21931 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
21932 index 48d2b7d..90d328a 100644
21933 --- a/arch/x86/kernel/smp.c
21934 +++ b/arch/x86/kernel/smp.c
21935 @@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
21936
21937 __setup("nonmi_ipi", nonmi_ipi_setup);
21938
21939 -struct smp_ops smp_ops = {
21940 +struct smp_ops smp_ops __read_only = {
21941 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
21942 .smp_prepare_cpus = native_smp_prepare_cpus,
21943 .smp_cpus_done = native_smp_cpus_done,
21944 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
21945 index ed0fe38..87fc692 100644
21946 --- a/arch/x86/kernel/smpboot.c
21947 +++ b/arch/x86/kernel/smpboot.c
21948 @@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21949 idle->thread.sp = (unsigned long) (((struct pt_regs *)
21950 (THREAD_SIZE + task_stack_page(idle))) - 1);
21951 per_cpu(current_task, cpu) = idle;
21952 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
21953
21954 #ifdef CONFIG_X86_32
21955 /* Stack for startup_32 can be just as for start_secondary onwards */
21956 @@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
21957 #else
21958 clear_tsk_thread_flag(idle, TIF_FORK);
21959 initial_gs = per_cpu_offset(cpu);
21960 - per_cpu(kernel_stack, cpu) =
21961 - (unsigned long)task_stack_page(idle) -
21962 - KERNEL_STACK_OFFSET + THREAD_SIZE;
21963 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
21964 #endif
21965 +
21966 + pax_open_kernel();
21967 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21968 + pax_close_kernel();
21969 +
21970 initial_code = (unsigned long)start_secondary;
21971 stack_start = idle->thread.sp;
21972
21973 @@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
21974 /* the FPU context is blank, nobody can own it */
21975 __cpu_disable_lazy_restore(cpu);
21976
21977 +#ifdef CONFIG_PAX_PER_CPU_PGD
21978 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
21979 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
21980 + KERNEL_PGD_PTRS);
21981 +#endif
21982 +
21983 + /* the FPU context is blank, nobody can own it */
21984 + __cpu_disable_lazy_restore(cpu);
21985 +
21986 err = do_boot_cpu(apicid, cpu, tidle);
21987 if (err) {
21988 pr_debug("do_boot_cpu failed %d\n", err);
21989 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
21990 index 9b4d51d..5d28b58 100644
21991 --- a/arch/x86/kernel/step.c
21992 +++ b/arch/x86/kernel/step.c
21993 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
21994 struct desc_struct *desc;
21995 unsigned long base;
21996
21997 - seg &= ~7UL;
21998 + seg >>= 3;
21999
22000 mutex_lock(&child->mm->context.lock);
22001 - if (unlikely((seg >> 3) >= child->mm->context.size))
22002 + if (unlikely(seg >= child->mm->context.size))
22003 addr = -1L; /* bogus selector, access would fault */
22004 else {
22005 desc = child->mm->context.ldt + seg;
22006 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22007 addr += base;
22008 }
22009 mutex_unlock(&child->mm->context.lock);
22010 - }
22011 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22012 + addr = ktla_ktva(addr);
22013
22014 return addr;
22015 }
22016 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22017 unsigned char opcode[15];
22018 unsigned long addr = convert_ip_to_linear(child, regs);
22019
22020 + if (addr == -EINVAL)
22021 + return 0;
22022 +
22023 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22024 for (i = 0; i < copied; i++) {
22025 switch (opcode[i]) {
22026 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22027 new file mode 100644
22028 index 0000000..26bb1af
22029 --- /dev/null
22030 +++ b/arch/x86/kernel/sys_i386_32.c
22031 @@ -0,0 +1,249 @@
22032 +/*
22033 + * This file contains various random system calls that
22034 + * have a non-standard calling sequence on the Linux/i386
22035 + * platform.
22036 + */
22037 +
22038 +#include <linux/errno.h>
22039 +#include <linux/sched.h>
22040 +#include <linux/mm.h>
22041 +#include <linux/fs.h>
22042 +#include <linux/smp.h>
22043 +#include <linux/sem.h>
22044 +#include <linux/msg.h>
22045 +#include <linux/shm.h>
22046 +#include <linux/stat.h>
22047 +#include <linux/syscalls.h>
22048 +#include <linux/mman.h>
22049 +#include <linux/file.h>
22050 +#include <linux/utsname.h>
22051 +#include <linux/ipc.h>
22052 +
22053 +#include <linux/uaccess.h>
22054 +#include <linux/unistd.h>
22055 +
22056 +#include <asm/syscalls.h>
22057 +
22058 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22059 +{
22060 + unsigned long pax_task_size = TASK_SIZE;
22061 +
22062 +#ifdef CONFIG_PAX_SEGMEXEC
22063 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22064 + pax_task_size = SEGMEXEC_TASK_SIZE;
22065 +#endif
22066 +
22067 + if (len > pax_task_size || addr > pax_task_size - len)
22068 + return -EINVAL;
22069 +
22070 + return 0;
22071 +}
22072 +
22073 +unsigned long
22074 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
22075 + unsigned long len, unsigned long pgoff, unsigned long flags)
22076 +{
22077 + struct mm_struct *mm = current->mm;
22078 + struct vm_area_struct *vma;
22079 + unsigned long start_addr, pax_task_size = TASK_SIZE;
22080 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22081 +
22082 +#ifdef CONFIG_PAX_SEGMEXEC
22083 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22084 + pax_task_size = SEGMEXEC_TASK_SIZE;
22085 +#endif
22086 +
22087 + pax_task_size -= PAGE_SIZE;
22088 +
22089 + if (len > pax_task_size)
22090 + return -ENOMEM;
22091 +
22092 + if (flags & MAP_FIXED)
22093 + return addr;
22094 +
22095 +#ifdef CONFIG_PAX_RANDMMAP
22096 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22097 +#endif
22098 +
22099 + if (addr) {
22100 + addr = PAGE_ALIGN(addr);
22101 + if (pax_task_size - len >= addr) {
22102 + vma = find_vma(mm, addr);
22103 + if (check_heap_stack_gap(vma, addr, len, offset))
22104 + return addr;
22105 + }
22106 + }
22107 + if (len > mm->cached_hole_size) {
22108 + start_addr = addr = mm->free_area_cache;
22109 + } else {
22110 + start_addr = addr = mm->mmap_base;
22111 + mm->cached_hole_size = 0;
22112 + }
22113 +
22114 +#ifdef CONFIG_PAX_PAGEEXEC
22115 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
22116 + start_addr = 0x00110000UL;
22117 +
22118 +#ifdef CONFIG_PAX_RANDMMAP
22119 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22120 + start_addr += mm->delta_mmap & 0x03FFF000UL;
22121 +#endif
22122 +
22123 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
22124 + start_addr = addr = mm->mmap_base;
22125 + else
22126 + addr = start_addr;
22127 + }
22128 +#endif
22129 +
22130 +full_search:
22131 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
22132 + /* At this point: (!vma || addr < vma->vm_end). */
22133 + if (pax_task_size - len < addr) {
22134 + /*
22135 + * Start a new search - just in case we missed
22136 + * some holes.
22137 + */
22138 + if (start_addr != mm->mmap_base) {
22139 + start_addr = addr = mm->mmap_base;
22140 + mm->cached_hole_size = 0;
22141 + goto full_search;
22142 + }
22143 + return -ENOMEM;
22144 + }
22145 + if (check_heap_stack_gap(vma, addr, len, offset))
22146 + break;
22147 + if (addr + mm->cached_hole_size < vma->vm_start)
22148 + mm->cached_hole_size = vma->vm_start - addr;
22149 + addr = vma->vm_end;
22150 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
22151 + start_addr = addr = mm->mmap_base;
22152 + mm->cached_hole_size = 0;
22153 + goto full_search;
22154 + }
22155 + }
22156 +
22157 + /*
22158 + * Remember the place where we stopped the search:
22159 + */
22160 + mm->free_area_cache = addr + len;
22161 + return addr;
22162 +}
22163 +
22164 +unsigned long
22165 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22166 + const unsigned long len, const unsigned long pgoff,
22167 + const unsigned long flags)
22168 +{
22169 + struct vm_area_struct *vma;
22170 + struct mm_struct *mm = current->mm;
22171 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
22172 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22173 +
22174 +#ifdef CONFIG_PAX_SEGMEXEC
22175 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22176 + pax_task_size = SEGMEXEC_TASK_SIZE;
22177 +#endif
22178 +
22179 + pax_task_size -= PAGE_SIZE;
22180 +
22181 + /* requested length too big for entire address space */
22182 + if (len > pax_task_size)
22183 + return -ENOMEM;
22184 +
22185 + if (flags & MAP_FIXED)
22186 + return addr;
22187 +
22188 +#ifdef CONFIG_PAX_PAGEEXEC
22189 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
22190 + goto bottomup;
22191 +#endif
22192 +
22193 +#ifdef CONFIG_PAX_RANDMMAP
22194 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22195 +#endif
22196 +
22197 + /* requesting a specific address */
22198 + if (addr) {
22199 + addr = PAGE_ALIGN(addr);
22200 + if (pax_task_size - len >= addr) {
22201 + vma = find_vma(mm, addr);
22202 + if (check_heap_stack_gap(vma, addr, len, offset))
22203 + return addr;
22204 + }
22205 + }
22206 +
22207 + /* check if free_area_cache is useful for us */
22208 + if (len <= mm->cached_hole_size) {
22209 + mm->cached_hole_size = 0;
22210 + mm->free_area_cache = mm->mmap_base;
22211 + }
22212 +
22213 + /* either no address requested or can't fit in requested address hole */
22214 + addr = mm->free_area_cache;
22215 +
22216 + /* make sure it can fit in the remaining address space */
22217 + if (addr > len) {
22218 + vma = find_vma(mm, addr-len);
22219 + if (check_heap_stack_gap(vma, addr - len, len, offset))
22220 + /* remember the address as a hint for next time */
22221 + return (mm->free_area_cache = addr-len);
22222 + }
22223 +
22224 + if (mm->mmap_base < len)
22225 + goto bottomup;
22226 +
22227 + addr = mm->mmap_base-len;
22228 +
22229 + do {
22230 + /*
22231 + * Lookup failure means no vma is above this address,
22232 + * else if new region fits below vma->vm_start,
22233 + * return with success:
22234 + */
22235 + vma = find_vma(mm, addr);
22236 + if (check_heap_stack_gap(vma, addr, len, offset))
22237 + /* remember the address as a hint for next time */
22238 + return (mm->free_area_cache = addr);
22239 +
22240 + /* remember the largest hole we saw so far */
22241 + if (addr + mm->cached_hole_size < vma->vm_start)
22242 + mm->cached_hole_size = vma->vm_start - addr;
22243 +
22244 + /* try just below the current vma->vm_start */
22245 + addr = skip_heap_stack_gap(vma, len, offset);
22246 + } while (!IS_ERR_VALUE(addr));
22247 +
22248 +bottomup:
22249 + /*
22250 + * A failed mmap() very likely causes application failure,
22251 + * so fall back to the bottom-up function here. This scenario
22252 + * can happen with large stack limits and large mmap()
22253 + * allocations.
22254 + */
22255 +
22256 +#ifdef CONFIG_PAX_SEGMEXEC
22257 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
22258 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
22259 + else
22260 +#endif
22261 +
22262 + mm->mmap_base = TASK_UNMAPPED_BASE;
22263 +
22264 +#ifdef CONFIG_PAX_RANDMMAP
22265 + if (mm->pax_flags & MF_PAX_RANDMMAP)
22266 + mm->mmap_base += mm->delta_mmap;
22267 +#endif
22268 +
22269 + mm->free_area_cache = mm->mmap_base;
22270 + mm->cached_hole_size = ~0UL;
22271 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
22272 + /*
22273 + * Restore the topdown base:
22274 + */
22275 + mm->mmap_base = base;
22276 + mm->free_area_cache = base;
22277 + mm->cached_hole_size = ~0UL;
22278 +
22279 + return addr;
22280 +}
22281 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
22282 index 97ef74b..57a1882 100644
22283 --- a/arch/x86/kernel/sys_x86_64.c
22284 +++ b/arch/x86/kernel/sys_x86_64.c
22285 @@ -81,8 +81,8 @@ out:
22286 return error;
22287 }
22288
22289 -static void find_start_end(unsigned long flags, unsigned long *begin,
22290 - unsigned long *end)
22291 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
22292 + unsigned long *begin, unsigned long *end)
22293 {
22294 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
22295 unsigned long new_begin;
22296 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
22297 *begin = new_begin;
22298 }
22299 } else {
22300 - *begin = TASK_UNMAPPED_BASE;
22301 + *begin = mm->mmap_base;
22302 *end = TASK_SIZE;
22303 }
22304 }
22305 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
22306 struct vm_area_struct *vma;
22307 struct vm_unmapped_area_info info;
22308 unsigned long begin, end;
22309 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22310
22311 if (flags & MAP_FIXED)
22312 return addr;
22313
22314 - find_start_end(flags, &begin, &end);
22315 + find_start_end(mm, flags, &begin, &end);
22316
22317 if (len > end)
22318 return -ENOMEM;
22319
22320 +#ifdef CONFIG_PAX_RANDMMAP
22321 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22322 +#endif
22323 +
22324 if (addr) {
22325 addr = PAGE_ALIGN(addr);
22326 vma = find_vma(mm, addr);
22327 - if (end - len >= addr &&
22328 - (!vma || addr + len <= vma->vm_start))
22329 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
22330 return addr;
22331 }
22332
22333 @@ -161,6 +165,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
22334 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
22335 goto bottomup;
22336
22337 +#ifdef CONFIG_PAX_RANDMMAP
22338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22339 +#endif
22340 +
22341 /* requesting a specific address */
22342 if (addr) {
22343 addr = PAGE_ALIGN(addr);
22344 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
22345 index f84fe00..f41d9f1 100644
22346 --- a/arch/x86/kernel/tboot.c
22347 +++ b/arch/x86/kernel/tboot.c
22348 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
22349
22350 void tboot_shutdown(u32 shutdown_type)
22351 {
22352 - void (*shutdown)(void);
22353 + void (* __noreturn shutdown)(void);
22354
22355 if (!tboot_enabled())
22356 return;
22357 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
22358
22359 switch_to_tboot_pt();
22360
22361 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
22362 + shutdown = (void *)tboot->shutdown_entry;
22363 shutdown();
22364
22365 /* should not reach here */
22366 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
22367 return 0;
22368 }
22369
22370 -static atomic_t ap_wfs_count;
22371 +static atomic_unchecked_t ap_wfs_count;
22372
22373 static int tboot_wait_for_aps(int num_aps)
22374 {
22375 @@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
22376 {
22377 switch (action) {
22378 case CPU_DYING:
22379 - atomic_inc(&ap_wfs_count);
22380 + atomic_inc_unchecked(&ap_wfs_count);
22381 if (num_online_cpus() == 1)
22382 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
22383 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
22384 return NOTIFY_BAD;
22385 break;
22386 }
22387 return NOTIFY_OK;
22388 }
22389
22390 -static struct notifier_block tboot_cpu_notifier __cpuinitdata =
22391 +static struct notifier_block tboot_cpu_notifier =
22392 {
22393 .notifier_call = tboot_cpu_callback,
22394 };
22395 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
22396
22397 tboot_create_trampoline();
22398
22399 - atomic_set(&ap_wfs_count, 0);
22400 + atomic_set_unchecked(&ap_wfs_count, 0);
22401 register_hotcpu_notifier(&tboot_cpu_notifier);
22402
22403 acpi_os_set_prepare_sleep(&tboot_sleep);
22404 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
22405 index 24d3c91..d06b473 100644
22406 --- a/arch/x86/kernel/time.c
22407 +++ b/arch/x86/kernel/time.c
22408 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
22409 {
22410 unsigned long pc = instruction_pointer(regs);
22411
22412 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
22413 + if (!user_mode(regs) && in_lock_functions(pc)) {
22414 #ifdef CONFIG_FRAME_POINTER
22415 - return *(unsigned long *)(regs->bp + sizeof(long));
22416 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
22417 #else
22418 unsigned long *sp =
22419 (unsigned long *)kernel_stack_pointer(regs);
22420 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
22421 * or above a saved flags. Eflags has bits 22-31 zero,
22422 * kernel addresses don't.
22423 */
22424 +
22425 +#ifdef CONFIG_PAX_KERNEXEC
22426 + return ktla_ktva(sp[0]);
22427 +#else
22428 if (sp[0] >> 22)
22429 return sp[0];
22430 if (sp[1] >> 22)
22431 return sp[1];
22432 #endif
22433 +
22434 +#endif
22435 }
22436 return pc;
22437 }
22438 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
22439 index 9d9d2f9..cad418a 100644
22440 --- a/arch/x86/kernel/tls.c
22441 +++ b/arch/x86/kernel/tls.c
22442 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
22443 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
22444 return -EINVAL;
22445
22446 +#ifdef CONFIG_PAX_SEGMEXEC
22447 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
22448 + return -EINVAL;
22449 +#endif
22450 +
22451 set_tls_desc(p, idx, &info, 1);
22452
22453 return 0;
22454 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
22455
22456 if (kbuf)
22457 info = kbuf;
22458 - else if (__copy_from_user(infobuf, ubuf, count))
22459 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
22460 return -EFAULT;
22461 else
22462 info = infobuf;
22463 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
22464 index ecffca1..95c4d13 100644
22465 --- a/arch/x86/kernel/traps.c
22466 +++ b/arch/x86/kernel/traps.c
22467 @@ -68,12 +68,6 @@
22468 #include <asm/setup.h>
22469
22470 asmlinkage int system_call(void);
22471 -
22472 -/*
22473 - * The IDT has to be page-aligned to simplify the Pentium
22474 - * F0 0F bug workaround.
22475 - */
22476 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
22477 #endif
22478
22479 DECLARE_BITMAP(used_vectors, NR_VECTORS);
22480 @@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
22481 }
22482
22483 static int __kprobes
22484 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22485 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
22486 struct pt_regs *regs, long error_code)
22487 {
22488 #ifdef CONFIG_X86_32
22489 - if (regs->flags & X86_VM_MASK) {
22490 + if (v8086_mode(regs)) {
22491 /*
22492 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
22493 * On nmi (interrupt 2), do_trap should not be called.
22494 @@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22495 return -1;
22496 }
22497 #endif
22498 - if (!user_mode(regs)) {
22499 + if (!user_mode_novm(regs)) {
22500 if (!fixup_exception(regs)) {
22501 tsk->thread.error_code = error_code;
22502 tsk->thread.trap_nr = trapnr;
22503 +
22504 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22505 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
22506 + str = "PAX: suspicious stack segment fault";
22507 +#endif
22508 +
22509 die(str, regs, error_code);
22510 }
22511 +
22512 +#ifdef CONFIG_PAX_REFCOUNT
22513 + if (trapnr == 4)
22514 + pax_report_refcount_overflow(regs);
22515 +#endif
22516 +
22517 return 0;
22518 }
22519
22520 @@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
22521 }
22522
22523 static void __kprobes
22524 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22525 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
22526 long error_code, siginfo_t *info)
22527 {
22528 struct task_struct *tsk = current;
22529 @@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
22530 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
22531 printk_ratelimit()) {
22532 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
22533 - tsk->comm, tsk->pid, str,
22534 + tsk->comm, task_pid_nr(tsk), str,
22535 regs->ip, regs->sp, error_code);
22536 print_vma_addr(" in ", regs->ip);
22537 pr_cont("\n");
22538 @@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
22539 conditional_sti(regs);
22540
22541 #ifdef CONFIG_X86_32
22542 - if (regs->flags & X86_VM_MASK) {
22543 + if (v8086_mode(regs)) {
22544 local_irq_enable();
22545 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
22546 goto exit;
22547 @@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
22548 #endif
22549
22550 tsk = current;
22551 - if (!user_mode(regs)) {
22552 + if (!user_mode_novm(regs)) {
22553 if (fixup_exception(regs))
22554 goto exit;
22555
22556 tsk->thread.error_code = error_code;
22557 tsk->thread.trap_nr = X86_TRAP_GP;
22558 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
22559 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
22560 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
22561 +
22562 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22563 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
22564 + die("PAX: suspicious general protection fault", regs, error_code);
22565 + else
22566 +#endif
22567 +
22568 die("general protection fault", regs, error_code);
22569 + }
22570 goto exit;
22571 }
22572
22573 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
22574 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
22575 + struct mm_struct *mm = tsk->mm;
22576 + unsigned long limit;
22577 +
22578 + down_write(&mm->mmap_sem);
22579 + limit = mm->context.user_cs_limit;
22580 + if (limit < TASK_SIZE) {
22581 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
22582 + up_write(&mm->mmap_sem);
22583 + return;
22584 + }
22585 + up_write(&mm->mmap_sem);
22586 + }
22587 +#endif
22588 +
22589 tsk->thread.error_code = error_code;
22590 tsk->thread.trap_nr = X86_TRAP_GP;
22591
22592 @@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22593 /* It's safe to allow irq's after DR6 has been saved */
22594 preempt_conditional_sti(regs);
22595
22596 - if (regs->flags & X86_VM_MASK) {
22597 + if (v8086_mode(regs)) {
22598 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
22599 X86_TRAP_DB);
22600 preempt_conditional_cli(regs);
22601 @@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
22602 * We already checked v86 mode above, so we can check for kernel mode
22603 * by just checking the CPL of CS.
22604 */
22605 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
22606 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
22607 tsk->thread.debugreg6 &= ~DR_STEP;
22608 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
22609 regs->flags &= ~X86_EFLAGS_TF;
22610 @@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
22611 return;
22612 conditional_sti(regs);
22613
22614 - if (!user_mode_vm(regs))
22615 + if (!user_mode(regs))
22616 {
22617 if (!fixup_exception(regs)) {
22618 task->thread.error_code = error_code;
22619 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
22620 index c71025b..b117501 100644
22621 --- a/arch/x86/kernel/uprobes.c
22622 +++ b/arch/x86/kernel/uprobes.c
22623 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
22624 int ret = NOTIFY_DONE;
22625
22626 /* We are only interested in userspace traps */
22627 - if (regs && !user_mode_vm(regs))
22628 + if (regs && !user_mode(regs))
22629 return NOTIFY_DONE;
22630
22631 switch (val) {
22632 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
22633 index b9242ba..50c5edd 100644
22634 --- a/arch/x86/kernel/verify_cpu.S
22635 +++ b/arch/x86/kernel/verify_cpu.S
22636 @@ -20,6 +20,7 @@
22637 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
22638 * arch/x86/kernel/trampoline_64.S: secondary processor verification
22639 * arch/x86/kernel/head_32.S: processor startup
22640 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
22641 *
22642 * verify_cpu, returns the status of longmode and SSE in register %eax.
22643 * 0: Success 1: Failure
22644 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
22645 index 1dfe69c..a3df6f6 100644
22646 --- a/arch/x86/kernel/vm86_32.c
22647 +++ b/arch/x86/kernel/vm86_32.c
22648 @@ -43,6 +43,7 @@
22649 #include <linux/ptrace.h>
22650 #include <linux/audit.h>
22651 #include <linux/stddef.h>
22652 +#include <linux/grsecurity.h>
22653
22654 #include <asm/uaccess.h>
22655 #include <asm/io.h>
22656 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
22657 do_exit(SIGSEGV);
22658 }
22659
22660 - tss = &per_cpu(init_tss, get_cpu());
22661 + tss = init_tss + get_cpu();
22662 current->thread.sp0 = current->thread.saved_sp0;
22663 current->thread.sysenter_cs = __KERNEL_CS;
22664 load_sp0(tss, &current->thread);
22665 @@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
22666 struct task_struct *tsk;
22667 int tmp, ret = -EPERM;
22668
22669 +#ifdef CONFIG_GRKERNSEC_VM86
22670 + if (!capable(CAP_SYS_RAWIO)) {
22671 + gr_handle_vm86();
22672 + goto out;
22673 + }
22674 +#endif
22675 +
22676 tsk = current;
22677 if (tsk->thread.saved_sp0)
22678 goto out;
22679 @@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
22680 int tmp, ret;
22681 struct vm86plus_struct __user *v86;
22682
22683 +#ifdef CONFIG_GRKERNSEC_VM86
22684 + if (!capable(CAP_SYS_RAWIO)) {
22685 + gr_handle_vm86();
22686 + ret = -EPERM;
22687 + goto out;
22688 + }
22689 +#endif
22690 +
22691 tsk = current;
22692 switch (cmd) {
22693 case VM86_REQUEST_IRQ:
22694 @@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
22695 tsk->thread.saved_fs = info->regs32->fs;
22696 tsk->thread.saved_gs = get_user_gs(info->regs32);
22697
22698 - tss = &per_cpu(init_tss, get_cpu());
22699 + tss = init_tss + get_cpu();
22700 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
22701 if (cpu_has_sep)
22702 tsk->thread.sysenter_cs = 0;
22703 @@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
22704 goto cannot_handle;
22705 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
22706 goto cannot_handle;
22707 - intr_ptr = (unsigned long __user *) (i << 2);
22708 + intr_ptr = (__force unsigned long __user *) (i << 2);
22709 if (get_user(segoffs, intr_ptr))
22710 goto cannot_handle;
22711 if ((segoffs >> 16) == BIOSSEG)
22712 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
22713 index 22a1530..8fbaaad 100644
22714 --- a/arch/x86/kernel/vmlinux.lds.S
22715 +++ b/arch/x86/kernel/vmlinux.lds.S
22716 @@ -26,6 +26,13 @@
22717 #include <asm/page_types.h>
22718 #include <asm/cache.h>
22719 #include <asm/boot.h>
22720 +#include <asm/segment.h>
22721 +
22722 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22723 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
22724 +#else
22725 +#define __KERNEL_TEXT_OFFSET 0
22726 +#endif
22727
22728 #undef i386 /* in case the preprocessor is a 32bit one */
22729
22730 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
22731
22732 PHDRS {
22733 text PT_LOAD FLAGS(5); /* R_E */
22734 +#ifdef CONFIG_X86_32
22735 + module PT_LOAD FLAGS(5); /* R_E */
22736 +#endif
22737 +#ifdef CONFIG_XEN
22738 + rodata PT_LOAD FLAGS(5); /* R_E */
22739 +#else
22740 + rodata PT_LOAD FLAGS(4); /* R__ */
22741 +#endif
22742 data PT_LOAD FLAGS(6); /* RW_ */
22743 -#ifdef CONFIG_X86_64
22744 + init.begin PT_LOAD FLAGS(6); /* RW_ */
22745 #ifdef CONFIG_SMP
22746 percpu PT_LOAD FLAGS(6); /* RW_ */
22747 #endif
22748 + text.init PT_LOAD FLAGS(5); /* R_E */
22749 + text.exit PT_LOAD FLAGS(5); /* R_E */
22750 init PT_LOAD FLAGS(7); /* RWE */
22751 -#endif
22752 note PT_NOTE FLAGS(0); /* ___ */
22753 }
22754
22755 SECTIONS
22756 {
22757 #ifdef CONFIG_X86_32
22758 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
22759 - phys_startup_32 = startup_32 - LOAD_OFFSET;
22760 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
22761 #else
22762 - . = __START_KERNEL;
22763 - phys_startup_64 = startup_64 - LOAD_OFFSET;
22764 + . = __START_KERNEL;
22765 #endif
22766
22767 /* Text and read-only data */
22768 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
22769 - _text = .;
22770 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22771 /* bootstrapping code */
22772 +#ifdef CONFIG_X86_32
22773 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22774 +#else
22775 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22776 +#endif
22777 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
22778 + _text = .;
22779 HEAD_TEXT
22780 #ifdef CONFIG_X86_32
22781 . = ALIGN(PAGE_SIZE);
22782 @@ -108,13 +128,48 @@ SECTIONS
22783 IRQENTRY_TEXT
22784 *(.fixup)
22785 *(.gnu.warning)
22786 - /* End of text section */
22787 - _etext = .;
22788 } :text = 0x9090
22789
22790 - NOTES :text :note
22791 + . += __KERNEL_TEXT_OFFSET;
22792
22793 - EXCEPTION_TABLE(16) :text = 0x9090
22794 +#ifdef CONFIG_X86_32
22795 + . = ALIGN(PAGE_SIZE);
22796 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
22797 +
22798 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
22799 + MODULES_EXEC_VADDR = .;
22800 + BYTE(0)
22801 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
22802 + . = ALIGN(HPAGE_SIZE) - 1;
22803 + MODULES_EXEC_END = .;
22804 +#endif
22805 +
22806 + } :module
22807 +#endif
22808 +
22809 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
22810 + /* End of text section */
22811 + BYTE(0)
22812 + _etext = . - __KERNEL_TEXT_OFFSET;
22813 + }
22814 +
22815 +#ifdef CONFIG_X86_32
22816 + . = ALIGN(PAGE_SIZE);
22817 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
22818 + *(.idt)
22819 + . = ALIGN(PAGE_SIZE);
22820 + *(.empty_zero_page)
22821 + *(.initial_pg_fixmap)
22822 + *(.initial_pg_pmd)
22823 + *(.initial_page_table)
22824 + *(.swapper_pg_dir)
22825 + } :rodata
22826 +#endif
22827 +
22828 + . = ALIGN(PAGE_SIZE);
22829 + NOTES :rodata :note
22830 +
22831 + EXCEPTION_TABLE(16) :rodata
22832
22833 #if defined(CONFIG_DEBUG_RODATA)
22834 /* .text should occupy whole number of pages */
22835 @@ -126,16 +181,20 @@ SECTIONS
22836
22837 /* Data */
22838 .data : AT(ADDR(.data) - LOAD_OFFSET) {
22839 +
22840 +#ifdef CONFIG_PAX_KERNEXEC
22841 + . = ALIGN(HPAGE_SIZE);
22842 +#else
22843 + . = ALIGN(PAGE_SIZE);
22844 +#endif
22845 +
22846 /* Start of data section */
22847 _sdata = .;
22848
22849 /* init_task */
22850 INIT_TASK_DATA(THREAD_SIZE)
22851
22852 -#ifdef CONFIG_X86_32
22853 - /* 32 bit has nosave before _edata */
22854 NOSAVE_DATA
22855 -#endif
22856
22857 PAGE_ALIGNED_DATA(PAGE_SIZE)
22858
22859 @@ -176,12 +235,19 @@ SECTIONS
22860 #endif /* CONFIG_X86_64 */
22861
22862 /* Init code and data - will be freed after init */
22863 - . = ALIGN(PAGE_SIZE);
22864 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
22865 + BYTE(0)
22866 +
22867 +#ifdef CONFIG_PAX_KERNEXEC
22868 + . = ALIGN(HPAGE_SIZE);
22869 +#else
22870 + . = ALIGN(PAGE_SIZE);
22871 +#endif
22872 +
22873 __init_begin = .; /* paired with __init_end */
22874 - }
22875 + } :init.begin
22876
22877 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
22878 +#ifdef CONFIG_SMP
22879 /*
22880 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
22881 * output PHDR, so the next output section - .init.text - should
22882 @@ -190,12 +256,27 @@ SECTIONS
22883 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
22884 #endif
22885
22886 - INIT_TEXT_SECTION(PAGE_SIZE)
22887 -#ifdef CONFIG_X86_64
22888 - :init
22889 -#endif
22890 + . = ALIGN(PAGE_SIZE);
22891 + init_begin = .;
22892 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
22893 + VMLINUX_SYMBOL(_sinittext) = .;
22894 + INIT_TEXT
22895 + VMLINUX_SYMBOL(_einittext) = .;
22896 + . = ALIGN(PAGE_SIZE);
22897 + } :text.init
22898
22899 - INIT_DATA_SECTION(16)
22900 + /*
22901 + * .exit.text is discard at runtime, not link time, to deal with
22902 + * references from .altinstructions and .eh_frame
22903 + */
22904 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
22905 + EXIT_TEXT
22906 + . = ALIGN(16);
22907 + } :text.exit
22908 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
22909 +
22910 + . = ALIGN(PAGE_SIZE);
22911 + INIT_DATA_SECTION(16) :init
22912
22913 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
22914 __x86_cpu_dev_start = .;
22915 @@ -257,19 +338,12 @@ SECTIONS
22916 }
22917
22918 . = ALIGN(8);
22919 - /*
22920 - * .exit.text is discard at runtime, not link time, to deal with
22921 - * references from .altinstructions and .eh_frame
22922 - */
22923 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
22924 - EXIT_TEXT
22925 - }
22926
22927 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
22928 EXIT_DATA
22929 }
22930
22931 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
22932 +#ifndef CONFIG_SMP
22933 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
22934 #endif
22935
22936 @@ -288,16 +362,10 @@ SECTIONS
22937 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
22938 __smp_locks = .;
22939 *(.smp_locks)
22940 - . = ALIGN(PAGE_SIZE);
22941 __smp_locks_end = .;
22942 + . = ALIGN(PAGE_SIZE);
22943 }
22944
22945 -#ifdef CONFIG_X86_64
22946 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
22947 - NOSAVE_DATA
22948 - }
22949 -#endif
22950 -
22951 /* BSS */
22952 . = ALIGN(PAGE_SIZE);
22953 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
22954 @@ -313,6 +381,7 @@ SECTIONS
22955 __brk_base = .;
22956 . += 64 * 1024; /* 64k alignment slop space */
22957 *(.brk_reservation) /* areas brk users have reserved */
22958 + . = ALIGN(HPAGE_SIZE);
22959 __brk_limit = .;
22960 }
22961
22962 @@ -339,13 +408,12 @@ SECTIONS
22963 * for the boot processor.
22964 */
22965 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
22966 -INIT_PER_CPU(gdt_page);
22967 INIT_PER_CPU(irq_stack_union);
22968
22969 /*
22970 * Build-time check on the image size:
22971 */
22972 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
22973 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
22974 "kernel image bigger than KERNEL_IMAGE_SIZE");
22975
22976 #ifdef CONFIG_SMP
22977 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
22978 index 9a907a6..f83f921 100644
22979 --- a/arch/x86/kernel/vsyscall_64.c
22980 +++ b/arch/x86/kernel/vsyscall_64.c
22981 @@ -56,15 +56,13 @@
22982 DEFINE_VVAR(int, vgetcpu_mode);
22983 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
22984
22985 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
22986 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
22987
22988 static int __init vsyscall_setup(char *str)
22989 {
22990 if (str) {
22991 if (!strcmp("emulate", str))
22992 vsyscall_mode = EMULATE;
22993 - else if (!strcmp("native", str))
22994 - vsyscall_mode = NATIVE;
22995 else if (!strcmp("none", str))
22996 vsyscall_mode = NONE;
22997 else
22998 @@ -323,8 +321,7 @@ do_ret:
22999 return true;
23000
23001 sigsegv:
23002 - force_sig(SIGSEGV, current);
23003 - return true;
23004 + do_group_exit(SIGKILL);
23005 }
23006
23007 /*
23008 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23009 extern char __vvar_page;
23010 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23011
23012 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23013 - vsyscall_mode == NATIVE
23014 - ? PAGE_KERNEL_VSYSCALL
23015 - : PAGE_KERNEL_VVAR);
23016 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23017 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23018 (unsigned long)VSYSCALL_START);
23019
23020 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23021 index 1330dd1..d220b99 100644
23022 --- a/arch/x86/kernel/x8664_ksyms_64.c
23023 +++ b/arch/x86/kernel/x8664_ksyms_64.c
23024 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23025 EXPORT_SYMBOL(copy_user_generic_unrolled);
23026 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23027 EXPORT_SYMBOL(__copy_user_nocache);
23028 -EXPORT_SYMBOL(_copy_from_user);
23029 -EXPORT_SYMBOL(_copy_to_user);
23030
23031 EXPORT_SYMBOL(copy_page);
23032 EXPORT_SYMBOL(clear_page);
23033 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23034 index 7a3d075..6cb373d 100644
23035 --- a/arch/x86/kernel/x86_init.c
23036 +++ b/arch/x86/kernel/x86_init.c
23037 @@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
23038 },
23039 };
23040
23041 -struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23042 +struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23043 .early_percpu_clock_init = x86_init_noop,
23044 .setup_percpu_clockev = setup_secondary_APIC_clock,
23045 };
23046 @@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23047 static void default_nmi_init(void) { };
23048 static int default_i8042_detect(void) { return 1; };
23049
23050 -struct x86_platform_ops x86_platform = {
23051 +struct x86_platform_ops x86_platform __read_only = {
23052 .calibrate_tsc = native_calibrate_tsc,
23053 .get_wallclock = mach_get_cmos_time,
23054 .set_wallclock = mach_set_rtc_mmss,
23055 @@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
23056 };
23057
23058 EXPORT_SYMBOL_GPL(x86_platform);
23059 -struct x86_msi_ops x86_msi = {
23060 +struct x86_msi_ops x86_msi __read_only = {
23061 .setup_msi_irqs = native_setup_msi_irqs,
23062 .teardown_msi_irq = native_teardown_msi_irq,
23063 .teardown_msi_irqs = default_teardown_msi_irqs,
23064 .restore_msi_irqs = default_restore_msi_irqs,
23065 };
23066
23067 -struct x86_io_apic_ops x86_io_apic_ops = {
23068 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23069 .init = native_io_apic_init_mappings,
23070 .read = native_io_apic_read,
23071 .write = native_io_apic_write,
23072 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23073 index ada87a3..afea76d 100644
23074 --- a/arch/x86/kernel/xsave.c
23075 +++ b/arch/x86/kernel/xsave.c
23076 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23077 {
23078 int err;
23079
23080 + buf = (struct xsave_struct __user *)____m(buf);
23081 if (use_xsave())
23082 err = xsave_user(buf);
23083 else if (use_fxsr())
23084 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23085 */
23086 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23087 {
23088 + buf = (void __user *)____m(buf);
23089 if (use_xsave()) {
23090 if ((unsigned long)buf % 64 || fx_only) {
23091 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23092 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23093 index a20ecb5..d0e2194 100644
23094 --- a/arch/x86/kvm/cpuid.c
23095 +++ b/arch/x86/kvm/cpuid.c
23096 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23097 struct kvm_cpuid2 *cpuid,
23098 struct kvm_cpuid_entry2 __user *entries)
23099 {
23100 - int r;
23101 + int r, i;
23102
23103 r = -E2BIG;
23104 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23105 goto out;
23106 r = -EFAULT;
23107 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23108 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23109 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23110 goto out;
23111 + for (i = 0; i < cpuid->nent; ++i) {
23112 + struct kvm_cpuid_entry2 cpuid_entry;
23113 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23114 + goto out;
23115 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
23116 + }
23117 vcpu->arch.cpuid_nent = cpuid->nent;
23118 kvm_apic_set_version(vcpu);
23119 kvm_x86_ops->cpuid_update(vcpu);
23120 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23121 struct kvm_cpuid2 *cpuid,
23122 struct kvm_cpuid_entry2 __user *entries)
23123 {
23124 - int r;
23125 + int r, i;
23126
23127 r = -E2BIG;
23128 if (cpuid->nent < vcpu->arch.cpuid_nent)
23129 goto out;
23130 r = -EFAULT;
23131 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23132 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23133 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23134 goto out;
23135 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23136 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23137 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23138 + goto out;
23139 + }
23140 return 0;
23141
23142 out:
23143 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23144 index a27e763..54bfe43 100644
23145 --- a/arch/x86/kvm/emulate.c
23146 +++ b/arch/x86/kvm/emulate.c
23147 @@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23148
23149 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23150 do { \
23151 + unsigned long _tmp; \
23152 __asm__ __volatile__ ( \
23153 _PRE_EFLAGS("0", "4", "2") \
23154 _op _suffix " %"_x"3,%1; " \
23155 @@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23156 /* Raw emulation: instruction has two explicit operands. */
23157 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23158 do { \
23159 - unsigned long _tmp; \
23160 - \
23161 switch ((ctxt)->dst.bytes) { \
23162 case 2: \
23163 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23164 @@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23165
23166 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23167 do { \
23168 - unsigned long _tmp; \
23169 switch ((ctxt)->dst.bytes) { \
23170 case 1: \
23171 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
23172 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
23173 index 9392f52..0e56d77 100644
23174 --- a/arch/x86/kvm/lapic.c
23175 +++ b/arch/x86/kvm/lapic.c
23176 @@ -55,7 +55,7 @@
23177 #define APIC_BUS_CYCLE_NS 1
23178
23179 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
23180 -#define apic_debug(fmt, arg...)
23181 +#define apic_debug(fmt, arg...) do {} while (0)
23182
23183 #define APIC_LVT_NUM 6
23184 /* 14 is the version for Xeon and Pentium 8.4.8*/
23185 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
23186 index 891eb6d..e027900 100644
23187 --- a/arch/x86/kvm/paging_tmpl.h
23188 +++ b/arch/x86/kvm/paging_tmpl.h
23189 @@ -208,7 +208,7 @@ retry_walk:
23190 if (unlikely(kvm_is_error_hva(host_addr)))
23191 goto error;
23192
23193 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
23194 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
23195 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
23196 goto error;
23197 walker->ptep_user[walker->level - 1] = ptep_user;
23198 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
23199 index d29d3cd..ec9d522 100644
23200 --- a/arch/x86/kvm/svm.c
23201 +++ b/arch/x86/kvm/svm.c
23202 @@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
23203 int cpu = raw_smp_processor_id();
23204
23205 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
23206 +
23207 + pax_open_kernel();
23208 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
23209 + pax_close_kernel();
23210 +
23211 load_TR_desc();
23212 }
23213
23214 @@ -3881,6 +3885,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
23215 #endif
23216 #endif
23217
23218 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23219 + __set_fs(current_thread_info()->addr_limit);
23220 +#endif
23221 +
23222 reload_tss(vcpu);
23223
23224 local_irq_disable();
23225 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
23226 index 9120ae1..238abc0 100644
23227 --- a/arch/x86/kvm/vmx.c
23228 +++ b/arch/x86/kvm/vmx.c
23229 @@ -1370,7 +1370,11 @@ static void reload_tss(void)
23230 struct desc_struct *descs;
23231
23232 descs = (void *)gdt->address;
23233 +
23234 + pax_open_kernel();
23235 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
23236 + pax_close_kernel();
23237 +
23238 load_TR_desc();
23239 }
23240
23241 @@ -1594,6 +1598,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
23242 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
23243 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
23244
23245 +#ifdef CONFIG_PAX_PER_CPU_PGD
23246 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23247 +#endif
23248 +
23249 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
23250 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
23251 vmx->loaded_vmcs->cpu = cpu;
23252 @@ -2738,8 +2746,11 @@ static __init int hardware_setup(void)
23253 if (!cpu_has_vmx_flexpriority())
23254 flexpriority_enabled = 0;
23255
23256 - if (!cpu_has_vmx_tpr_shadow())
23257 - kvm_x86_ops->update_cr8_intercept = NULL;
23258 + if (!cpu_has_vmx_tpr_shadow()) {
23259 + pax_open_kernel();
23260 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
23261 + pax_close_kernel();
23262 + }
23263
23264 if (enable_ept && !cpu_has_vmx_ept_2m_page())
23265 kvm_disable_largepages();
23266 @@ -3782,7 +3793,10 @@ static void vmx_set_constant_host_state(void)
23267
23268 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
23269 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
23270 +
23271 +#ifndef CONFIG_PAX_PER_CPU_PGD
23272 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
23273 +#endif
23274
23275 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
23276 #ifdef CONFIG_X86_64
23277 @@ -3803,7 +3817,7 @@ static void vmx_set_constant_host_state(void)
23278 native_store_idt(&dt);
23279 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
23280
23281 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
23282 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
23283
23284 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
23285 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
23286 @@ -6355,6 +6369,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23287 "jmp 2f \n\t"
23288 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
23289 "2: "
23290 +
23291 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23292 + "ljmp %[cs],$3f\n\t"
23293 + "3: "
23294 +#endif
23295 +
23296 /* Save guest registers, load host registers, keep flags */
23297 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
23298 "pop %0 \n\t"
23299 @@ -6407,6 +6427,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23300 #endif
23301 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
23302 [wordsize]"i"(sizeof(ulong))
23303 +
23304 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23305 + ,[cs]"i"(__KERNEL_CS)
23306 +#endif
23307 +
23308 : "cc", "memory"
23309 #ifdef CONFIG_X86_64
23310 , "rax", "rbx", "rdi", "rsi"
23311 @@ -6420,7 +6445,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23312 if (debugctlmsr)
23313 update_debugctlmsr(debugctlmsr);
23314
23315 -#ifndef CONFIG_X86_64
23316 +#ifdef CONFIG_X86_32
23317 /*
23318 * The sysexit path does not restore ds/es, so we must set them to
23319 * a reasonable value ourselves.
23320 @@ -6429,8 +6454,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
23321 * may be executed in interrupt context, which saves and restore segments
23322 * around it, nullifying its effect.
23323 */
23324 - loadsegment(ds, __USER_DS);
23325 - loadsegment(es, __USER_DS);
23326 + loadsegment(ds, __KERNEL_DS);
23327 + loadsegment(es, __KERNEL_DS);
23328 + loadsegment(ss, __KERNEL_DS);
23329 +
23330 +#ifdef CONFIG_PAX_KERNEXEC
23331 + loadsegment(fs, __KERNEL_PERCPU);
23332 +#endif
23333 +
23334 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23335 + __set_fs(current_thread_info()->addr_limit);
23336 +#endif
23337 +
23338 #endif
23339
23340 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
23341 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
23342 index c243b81..9eb193f 100644
23343 --- a/arch/x86/kvm/x86.c
23344 +++ b/arch/x86/kvm/x86.c
23345 @@ -1692,8 +1692,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
23346 {
23347 struct kvm *kvm = vcpu->kvm;
23348 int lm = is_long_mode(vcpu);
23349 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23350 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23351 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
23352 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
23353 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
23354 : kvm->arch.xen_hvm_config.blob_size_32;
23355 u32 page_num = data & ~PAGE_MASK;
23356 @@ -2571,6 +2571,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
23357 if (n < msr_list.nmsrs)
23358 goto out;
23359 r = -EFAULT;
23360 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
23361 + goto out;
23362 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
23363 num_msrs_to_save * sizeof(u32)))
23364 goto out;
23365 @@ -2700,7 +2702,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
23366 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
23367 struct kvm_interrupt *irq)
23368 {
23369 - if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
23370 + if (irq->irq >= KVM_NR_INTERRUPTS)
23371 return -EINVAL;
23372 if (irqchip_in_kernel(vcpu->kvm))
23373 return -ENXIO;
23374 @@ -5213,7 +5215,7 @@ static struct notifier_block pvclock_gtod_notifier = {
23375 };
23376 #endif
23377
23378 -int kvm_arch_init(void *opaque)
23379 +int kvm_arch_init(const void *opaque)
23380 {
23381 int r;
23382 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
23383 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
23384 index df4176c..23ce092 100644
23385 --- a/arch/x86/lguest/boot.c
23386 +++ b/arch/x86/lguest/boot.c
23387 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
23388 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
23389 * Launcher to reboot us.
23390 */
23391 -static void lguest_restart(char *reason)
23392 +static __noreturn void lguest_restart(char *reason)
23393 {
23394 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
23395 + BUG();
23396 }
23397
23398 /*G:050
23399 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
23400 index 00933d5..3a64af9 100644
23401 --- a/arch/x86/lib/atomic64_386_32.S
23402 +++ b/arch/x86/lib/atomic64_386_32.S
23403 @@ -48,6 +48,10 @@ BEGIN(read)
23404 movl (v), %eax
23405 movl 4(v), %edx
23406 RET_ENDP
23407 +BEGIN(read_unchecked)
23408 + movl (v), %eax
23409 + movl 4(v), %edx
23410 +RET_ENDP
23411 #undef v
23412
23413 #define v %esi
23414 @@ -55,6 +59,10 @@ BEGIN(set)
23415 movl %ebx, (v)
23416 movl %ecx, 4(v)
23417 RET_ENDP
23418 +BEGIN(set_unchecked)
23419 + movl %ebx, (v)
23420 + movl %ecx, 4(v)
23421 +RET_ENDP
23422 #undef v
23423
23424 #define v %esi
23425 @@ -70,6 +78,20 @@ RET_ENDP
23426 BEGIN(add)
23427 addl %eax, (v)
23428 adcl %edx, 4(v)
23429 +
23430 +#ifdef CONFIG_PAX_REFCOUNT
23431 + jno 0f
23432 + subl %eax, (v)
23433 + sbbl %edx, 4(v)
23434 + int $4
23435 +0:
23436 + _ASM_EXTABLE(0b, 0b)
23437 +#endif
23438 +
23439 +RET_ENDP
23440 +BEGIN(add_unchecked)
23441 + addl %eax, (v)
23442 + adcl %edx, 4(v)
23443 RET_ENDP
23444 #undef v
23445
23446 @@ -77,6 +99,24 @@ RET_ENDP
23447 BEGIN(add_return)
23448 addl (v), %eax
23449 adcl 4(v), %edx
23450 +
23451 +#ifdef CONFIG_PAX_REFCOUNT
23452 + into
23453 +1234:
23454 + _ASM_EXTABLE(1234b, 2f)
23455 +#endif
23456 +
23457 + movl %eax, (v)
23458 + movl %edx, 4(v)
23459 +
23460 +#ifdef CONFIG_PAX_REFCOUNT
23461 +2:
23462 +#endif
23463 +
23464 +RET_ENDP
23465 +BEGIN(add_return_unchecked)
23466 + addl (v), %eax
23467 + adcl 4(v), %edx
23468 movl %eax, (v)
23469 movl %edx, 4(v)
23470 RET_ENDP
23471 @@ -86,6 +126,20 @@ RET_ENDP
23472 BEGIN(sub)
23473 subl %eax, (v)
23474 sbbl %edx, 4(v)
23475 +
23476 +#ifdef CONFIG_PAX_REFCOUNT
23477 + jno 0f
23478 + addl %eax, (v)
23479 + adcl %edx, 4(v)
23480 + int $4
23481 +0:
23482 + _ASM_EXTABLE(0b, 0b)
23483 +#endif
23484 +
23485 +RET_ENDP
23486 +BEGIN(sub_unchecked)
23487 + subl %eax, (v)
23488 + sbbl %edx, 4(v)
23489 RET_ENDP
23490 #undef v
23491
23492 @@ -96,6 +150,27 @@ BEGIN(sub_return)
23493 sbbl $0, %edx
23494 addl (v), %eax
23495 adcl 4(v), %edx
23496 +
23497 +#ifdef CONFIG_PAX_REFCOUNT
23498 + into
23499 +1234:
23500 + _ASM_EXTABLE(1234b, 2f)
23501 +#endif
23502 +
23503 + movl %eax, (v)
23504 + movl %edx, 4(v)
23505 +
23506 +#ifdef CONFIG_PAX_REFCOUNT
23507 +2:
23508 +#endif
23509 +
23510 +RET_ENDP
23511 +BEGIN(sub_return_unchecked)
23512 + negl %edx
23513 + negl %eax
23514 + sbbl $0, %edx
23515 + addl (v), %eax
23516 + adcl 4(v), %edx
23517 movl %eax, (v)
23518 movl %edx, 4(v)
23519 RET_ENDP
23520 @@ -105,6 +180,20 @@ RET_ENDP
23521 BEGIN(inc)
23522 addl $1, (v)
23523 adcl $0, 4(v)
23524 +
23525 +#ifdef CONFIG_PAX_REFCOUNT
23526 + jno 0f
23527 + subl $1, (v)
23528 + sbbl $0, 4(v)
23529 + int $4
23530 +0:
23531 + _ASM_EXTABLE(0b, 0b)
23532 +#endif
23533 +
23534 +RET_ENDP
23535 +BEGIN(inc_unchecked)
23536 + addl $1, (v)
23537 + adcl $0, 4(v)
23538 RET_ENDP
23539 #undef v
23540
23541 @@ -114,6 +203,26 @@ BEGIN(inc_return)
23542 movl 4(v), %edx
23543 addl $1, %eax
23544 adcl $0, %edx
23545 +
23546 +#ifdef CONFIG_PAX_REFCOUNT
23547 + into
23548 +1234:
23549 + _ASM_EXTABLE(1234b, 2f)
23550 +#endif
23551 +
23552 + movl %eax, (v)
23553 + movl %edx, 4(v)
23554 +
23555 +#ifdef CONFIG_PAX_REFCOUNT
23556 +2:
23557 +#endif
23558 +
23559 +RET_ENDP
23560 +BEGIN(inc_return_unchecked)
23561 + movl (v), %eax
23562 + movl 4(v), %edx
23563 + addl $1, %eax
23564 + adcl $0, %edx
23565 movl %eax, (v)
23566 movl %edx, 4(v)
23567 RET_ENDP
23568 @@ -123,6 +232,20 @@ RET_ENDP
23569 BEGIN(dec)
23570 subl $1, (v)
23571 sbbl $0, 4(v)
23572 +
23573 +#ifdef CONFIG_PAX_REFCOUNT
23574 + jno 0f
23575 + addl $1, (v)
23576 + adcl $0, 4(v)
23577 + int $4
23578 +0:
23579 + _ASM_EXTABLE(0b, 0b)
23580 +#endif
23581 +
23582 +RET_ENDP
23583 +BEGIN(dec_unchecked)
23584 + subl $1, (v)
23585 + sbbl $0, 4(v)
23586 RET_ENDP
23587 #undef v
23588
23589 @@ -132,6 +255,26 @@ BEGIN(dec_return)
23590 movl 4(v), %edx
23591 subl $1, %eax
23592 sbbl $0, %edx
23593 +
23594 +#ifdef CONFIG_PAX_REFCOUNT
23595 + into
23596 +1234:
23597 + _ASM_EXTABLE(1234b, 2f)
23598 +#endif
23599 +
23600 + movl %eax, (v)
23601 + movl %edx, 4(v)
23602 +
23603 +#ifdef CONFIG_PAX_REFCOUNT
23604 +2:
23605 +#endif
23606 +
23607 +RET_ENDP
23608 +BEGIN(dec_return_unchecked)
23609 + movl (v), %eax
23610 + movl 4(v), %edx
23611 + subl $1, %eax
23612 + sbbl $0, %edx
23613 movl %eax, (v)
23614 movl %edx, 4(v)
23615 RET_ENDP
23616 @@ -143,6 +286,13 @@ BEGIN(add_unless)
23617 adcl %edx, %edi
23618 addl (v), %eax
23619 adcl 4(v), %edx
23620 +
23621 +#ifdef CONFIG_PAX_REFCOUNT
23622 + into
23623 +1234:
23624 + _ASM_EXTABLE(1234b, 2f)
23625 +#endif
23626 +
23627 cmpl %eax, %ecx
23628 je 3f
23629 1:
23630 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
23631 1:
23632 addl $1, %eax
23633 adcl $0, %edx
23634 +
23635 +#ifdef CONFIG_PAX_REFCOUNT
23636 + into
23637 +1234:
23638 + _ASM_EXTABLE(1234b, 2f)
23639 +#endif
23640 +
23641 movl %eax, (v)
23642 movl %edx, 4(v)
23643 movl $1, %eax
23644 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
23645 movl 4(v), %edx
23646 subl $1, %eax
23647 sbbl $0, %edx
23648 +
23649 +#ifdef CONFIG_PAX_REFCOUNT
23650 + into
23651 +1234:
23652 + _ASM_EXTABLE(1234b, 1f)
23653 +#endif
23654 +
23655 js 1f
23656 movl %eax, (v)
23657 movl %edx, 4(v)
23658 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
23659 index f5cc9eb..51fa319 100644
23660 --- a/arch/x86/lib/atomic64_cx8_32.S
23661 +++ b/arch/x86/lib/atomic64_cx8_32.S
23662 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
23663 CFI_STARTPROC
23664
23665 read64 %ecx
23666 + pax_force_retaddr
23667 ret
23668 CFI_ENDPROC
23669 ENDPROC(atomic64_read_cx8)
23670
23671 +ENTRY(atomic64_read_unchecked_cx8)
23672 + CFI_STARTPROC
23673 +
23674 + read64 %ecx
23675 + pax_force_retaddr
23676 + ret
23677 + CFI_ENDPROC
23678 +ENDPROC(atomic64_read_unchecked_cx8)
23679 +
23680 ENTRY(atomic64_set_cx8)
23681 CFI_STARTPROC
23682
23683 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
23684 cmpxchg8b (%esi)
23685 jne 1b
23686
23687 + pax_force_retaddr
23688 ret
23689 CFI_ENDPROC
23690 ENDPROC(atomic64_set_cx8)
23691
23692 +ENTRY(atomic64_set_unchecked_cx8)
23693 + CFI_STARTPROC
23694 +
23695 +1:
23696 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
23697 + * are atomic on 586 and newer */
23698 + cmpxchg8b (%esi)
23699 + jne 1b
23700 +
23701 + pax_force_retaddr
23702 + ret
23703 + CFI_ENDPROC
23704 +ENDPROC(atomic64_set_unchecked_cx8)
23705 +
23706 ENTRY(atomic64_xchg_cx8)
23707 CFI_STARTPROC
23708
23709 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
23710 cmpxchg8b (%esi)
23711 jne 1b
23712
23713 + pax_force_retaddr
23714 ret
23715 CFI_ENDPROC
23716 ENDPROC(atomic64_xchg_cx8)
23717
23718 -.macro addsub_return func ins insc
23719 -ENTRY(atomic64_\func\()_return_cx8)
23720 +.macro addsub_return func ins insc unchecked=""
23721 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23722 CFI_STARTPROC
23723 SAVE ebp
23724 SAVE ebx
23725 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
23726 movl %edx, %ecx
23727 \ins\()l %esi, %ebx
23728 \insc\()l %edi, %ecx
23729 +
23730 +.ifb \unchecked
23731 +#ifdef CONFIG_PAX_REFCOUNT
23732 + into
23733 +2:
23734 + _ASM_EXTABLE(2b, 3f)
23735 +#endif
23736 +.endif
23737 +
23738 LOCK_PREFIX
23739 cmpxchg8b (%ebp)
23740 jne 1b
23741 -
23742 -10:
23743 movl %ebx, %eax
23744 movl %ecx, %edx
23745 +
23746 +.ifb \unchecked
23747 +#ifdef CONFIG_PAX_REFCOUNT
23748 +3:
23749 +#endif
23750 +.endif
23751 +
23752 RESTORE edi
23753 RESTORE esi
23754 RESTORE ebx
23755 RESTORE ebp
23756 + pax_force_retaddr
23757 ret
23758 CFI_ENDPROC
23759 -ENDPROC(atomic64_\func\()_return_cx8)
23760 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23761 .endm
23762
23763 addsub_return add add adc
23764 addsub_return sub sub sbb
23765 +addsub_return add add adc _unchecked
23766 +addsub_return sub sub sbb _unchecked
23767
23768 -.macro incdec_return func ins insc
23769 -ENTRY(atomic64_\func\()_return_cx8)
23770 +.macro incdec_return func ins insc unchecked=""
23771 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
23772 CFI_STARTPROC
23773 SAVE ebx
23774
23775 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
23776 movl %edx, %ecx
23777 \ins\()l $1, %ebx
23778 \insc\()l $0, %ecx
23779 +
23780 +.ifb \unchecked
23781 +#ifdef CONFIG_PAX_REFCOUNT
23782 + into
23783 +2:
23784 + _ASM_EXTABLE(2b, 3f)
23785 +#endif
23786 +.endif
23787 +
23788 LOCK_PREFIX
23789 cmpxchg8b (%esi)
23790 jne 1b
23791
23792 -10:
23793 movl %ebx, %eax
23794 movl %ecx, %edx
23795 +
23796 +.ifb \unchecked
23797 +#ifdef CONFIG_PAX_REFCOUNT
23798 +3:
23799 +#endif
23800 +.endif
23801 +
23802 RESTORE ebx
23803 + pax_force_retaddr
23804 ret
23805 CFI_ENDPROC
23806 -ENDPROC(atomic64_\func\()_return_cx8)
23807 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
23808 .endm
23809
23810 incdec_return inc add adc
23811 incdec_return dec sub sbb
23812 +incdec_return inc add adc _unchecked
23813 +incdec_return dec sub sbb _unchecked
23814
23815 ENTRY(atomic64_dec_if_positive_cx8)
23816 CFI_STARTPROC
23817 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
23818 movl %edx, %ecx
23819 subl $1, %ebx
23820 sbb $0, %ecx
23821 +
23822 +#ifdef CONFIG_PAX_REFCOUNT
23823 + into
23824 +1234:
23825 + _ASM_EXTABLE(1234b, 2f)
23826 +#endif
23827 +
23828 js 2f
23829 LOCK_PREFIX
23830 cmpxchg8b (%esi)
23831 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
23832 movl %ebx, %eax
23833 movl %ecx, %edx
23834 RESTORE ebx
23835 + pax_force_retaddr
23836 ret
23837 CFI_ENDPROC
23838 ENDPROC(atomic64_dec_if_positive_cx8)
23839 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
23840 movl %edx, %ecx
23841 addl %ebp, %ebx
23842 adcl %edi, %ecx
23843 +
23844 +#ifdef CONFIG_PAX_REFCOUNT
23845 + into
23846 +1234:
23847 + _ASM_EXTABLE(1234b, 3f)
23848 +#endif
23849 +
23850 LOCK_PREFIX
23851 cmpxchg8b (%esi)
23852 jne 1b
23853 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
23854 CFI_ADJUST_CFA_OFFSET -8
23855 RESTORE ebx
23856 RESTORE ebp
23857 + pax_force_retaddr
23858 ret
23859 4:
23860 cmpl %edx, 4(%esp)
23861 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
23862 xorl %ecx, %ecx
23863 addl $1, %ebx
23864 adcl %edx, %ecx
23865 +
23866 +#ifdef CONFIG_PAX_REFCOUNT
23867 + into
23868 +1234:
23869 + _ASM_EXTABLE(1234b, 3f)
23870 +#endif
23871 +
23872 LOCK_PREFIX
23873 cmpxchg8b (%esi)
23874 jne 1b
23875 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
23876 movl $1, %eax
23877 3:
23878 RESTORE ebx
23879 + pax_force_retaddr
23880 ret
23881 CFI_ENDPROC
23882 ENDPROC(atomic64_inc_not_zero_cx8)
23883 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
23884 index 2af5df3..62b1a5a 100644
23885 --- a/arch/x86/lib/checksum_32.S
23886 +++ b/arch/x86/lib/checksum_32.S
23887 @@ -29,7 +29,8 @@
23888 #include <asm/dwarf2.h>
23889 #include <asm/errno.h>
23890 #include <asm/asm.h>
23891 -
23892 +#include <asm/segment.h>
23893 +
23894 /*
23895 * computes a partial checksum, e.g. for TCP/UDP fragments
23896 */
23897 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
23898
23899 #define ARGBASE 16
23900 #define FP 12
23901 -
23902 -ENTRY(csum_partial_copy_generic)
23903 +
23904 +ENTRY(csum_partial_copy_generic_to_user)
23905 CFI_STARTPROC
23906 +
23907 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23908 + pushl_cfi %gs
23909 + popl_cfi %es
23910 + jmp csum_partial_copy_generic
23911 +#endif
23912 +
23913 +ENTRY(csum_partial_copy_generic_from_user)
23914 +
23915 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23916 + pushl_cfi %gs
23917 + popl_cfi %ds
23918 +#endif
23919 +
23920 +ENTRY(csum_partial_copy_generic)
23921 subl $4,%esp
23922 CFI_ADJUST_CFA_OFFSET 4
23923 pushl_cfi %edi
23924 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
23925 jmp 4f
23926 SRC(1: movw (%esi), %bx )
23927 addl $2, %esi
23928 -DST( movw %bx, (%edi) )
23929 +DST( movw %bx, %es:(%edi) )
23930 addl $2, %edi
23931 addw %bx, %ax
23932 adcl $0, %eax
23933 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
23934 SRC(1: movl (%esi), %ebx )
23935 SRC( movl 4(%esi), %edx )
23936 adcl %ebx, %eax
23937 -DST( movl %ebx, (%edi) )
23938 +DST( movl %ebx, %es:(%edi) )
23939 adcl %edx, %eax
23940 -DST( movl %edx, 4(%edi) )
23941 +DST( movl %edx, %es:4(%edi) )
23942
23943 SRC( movl 8(%esi), %ebx )
23944 SRC( movl 12(%esi), %edx )
23945 adcl %ebx, %eax
23946 -DST( movl %ebx, 8(%edi) )
23947 +DST( movl %ebx, %es:8(%edi) )
23948 adcl %edx, %eax
23949 -DST( movl %edx, 12(%edi) )
23950 +DST( movl %edx, %es:12(%edi) )
23951
23952 SRC( movl 16(%esi), %ebx )
23953 SRC( movl 20(%esi), %edx )
23954 adcl %ebx, %eax
23955 -DST( movl %ebx, 16(%edi) )
23956 +DST( movl %ebx, %es:16(%edi) )
23957 adcl %edx, %eax
23958 -DST( movl %edx, 20(%edi) )
23959 +DST( movl %edx, %es:20(%edi) )
23960
23961 SRC( movl 24(%esi), %ebx )
23962 SRC( movl 28(%esi), %edx )
23963 adcl %ebx, %eax
23964 -DST( movl %ebx, 24(%edi) )
23965 +DST( movl %ebx, %es:24(%edi) )
23966 adcl %edx, %eax
23967 -DST( movl %edx, 28(%edi) )
23968 +DST( movl %edx, %es:28(%edi) )
23969
23970 lea 32(%esi), %esi
23971 lea 32(%edi), %edi
23972 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
23973 shrl $2, %edx # This clears CF
23974 SRC(3: movl (%esi), %ebx )
23975 adcl %ebx, %eax
23976 -DST( movl %ebx, (%edi) )
23977 +DST( movl %ebx, %es:(%edi) )
23978 lea 4(%esi), %esi
23979 lea 4(%edi), %edi
23980 dec %edx
23981 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
23982 jb 5f
23983 SRC( movw (%esi), %cx )
23984 leal 2(%esi), %esi
23985 -DST( movw %cx, (%edi) )
23986 +DST( movw %cx, %es:(%edi) )
23987 leal 2(%edi), %edi
23988 je 6f
23989 shll $16,%ecx
23990 SRC(5: movb (%esi), %cl )
23991 -DST( movb %cl, (%edi) )
23992 +DST( movb %cl, %es:(%edi) )
23993 6: addl %ecx, %eax
23994 adcl $0, %eax
23995 7:
23996 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
23997
23998 6001:
23999 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24000 - movl $-EFAULT, (%ebx)
24001 + movl $-EFAULT, %ss:(%ebx)
24002
24003 # zero the complete destination - computing the rest
24004 # is too much work
24005 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24006
24007 6002:
24008 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24009 - movl $-EFAULT,(%ebx)
24010 + movl $-EFAULT,%ss:(%ebx)
24011 jmp 5000b
24012
24013 .previous
24014
24015 + pushl_cfi %ss
24016 + popl_cfi %ds
24017 + pushl_cfi %ss
24018 + popl_cfi %es
24019 popl_cfi %ebx
24020 CFI_RESTORE ebx
24021 popl_cfi %esi
24022 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24023 popl_cfi %ecx # equivalent to addl $4,%esp
24024 ret
24025 CFI_ENDPROC
24026 -ENDPROC(csum_partial_copy_generic)
24027 +ENDPROC(csum_partial_copy_generic_to_user)
24028
24029 #else
24030
24031 /* Version for PentiumII/PPro */
24032
24033 #define ROUND1(x) \
24034 + nop; nop; nop; \
24035 SRC(movl x(%esi), %ebx ) ; \
24036 addl %ebx, %eax ; \
24037 - DST(movl %ebx, x(%edi) ) ;
24038 + DST(movl %ebx, %es:x(%edi)) ;
24039
24040 #define ROUND(x) \
24041 + nop; nop; nop; \
24042 SRC(movl x(%esi), %ebx ) ; \
24043 adcl %ebx, %eax ; \
24044 - DST(movl %ebx, x(%edi) ) ;
24045 + DST(movl %ebx, %es:x(%edi)) ;
24046
24047 #define ARGBASE 12
24048 -
24049 -ENTRY(csum_partial_copy_generic)
24050 +
24051 +ENTRY(csum_partial_copy_generic_to_user)
24052 CFI_STARTPROC
24053 +
24054 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24055 + pushl_cfi %gs
24056 + popl_cfi %es
24057 + jmp csum_partial_copy_generic
24058 +#endif
24059 +
24060 +ENTRY(csum_partial_copy_generic_from_user)
24061 +
24062 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24063 + pushl_cfi %gs
24064 + popl_cfi %ds
24065 +#endif
24066 +
24067 +ENTRY(csum_partial_copy_generic)
24068 pushl_cfi %ebx
24069 CFI_REL_OFFSET ebx, 0
24070 pushl_cfi %edi
24071 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24072 subl %ebx, %edi
24073 lea -1(%esi),%edx
24074 andl $-32,%edx
24075 - lea 3f(%ebx,%ebx), %ebx
24076 + lea 3f(%ebx,%ebx,2), %ebx
24077 testl %esi, %esi
24078 jmp *%ebx
24079 1: addl $64,%esi
24080 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24081 jb 5f
24082 SRC( movw (%esi), %dx )
24083 leal 2(%esi), %esi
24084 -DST( movw %dx, (%edi) )
24085 +DST( movw %dx, %es:(%edi) )
24086 leal 2(%edi), %edi
24087 je 6f
24088 shll $16,%edx
24089 5:
24090 SRC( movb (%esi), %dl )
24091 -DST( movb %dl, (%edi) )
24092 +DST( movb %dl, %es:(%edi) )
24093 6: addl %edx, %eax
24094 adcl $0, %eax
24095 7:
24096 .section .fixup, "ax"
24097 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24098 - movl $-EFAULT, (%ebx)
24099 + movl $-EFAULT, %ss:(%ebx)
24100 # zero the complete destination (computing the rest is too much work)
24101 movl ARGBASE+8(%esp),%edi # dst
24102 movl ARGBASE+12(%esp),%ecx # len
24103 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24104 rep; stosb
24105 jmp 7b
24106 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24107 - movl $-EFAULT, (%ebx)
24108 + movl $-EFAULT, %ss:(%ebx)
24109 jmp 7b
24110 .previous
24111
24112 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24113 + pushl_cfi %ss
24114 + popl_cfi %ds
24115 + pushl_cfi %ss
24116 + popl_cfi %es
24117 +#endif
24118 +
24119 popl_cfi %esi
24120 CFI_RESTORE esi
24121 popl_cfi %edi
24122 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24123 CFI_RESTORE ebx
24124 ret
24125 CFI_ENDPROC
24126 -ENDPROC(csum_partial_copy_generic)
24127 +ENDPROC(csum_partial_copy_generic_to_user)
24128
24129 #undef ROUND
24130 #undef ROUND1
24131 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24132 index f2145cf..cea889d 100644
24133 --- a/arch/x86/lib/clear_page_64.S
24134 +++ b/arch/x86/lib/clear_page_64.S
24135 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24136 movl $4096/8,%ecx
24137 xorl %eax,%eax
24138 rep stosq
24139 + pax_force_retaddr
24140 ret
24141 CFI_ENDPROC
24142 ENDPROC(clear_page_c)
24143 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
24144 movl $4096,%ecx
24145 xorl %eax,%eax
24146 rep stosb
24147 + pax_force_retaddr
24148 ret
24149 CFI_ENDPROC
24150 ENDPROC(clear_page_c_e)
24151 @@ -43,6 +45,7 @@ ENTRY(clear_page)
24152 leaq 64(%rdi),%rdi
24153 jnz .Lloop
24154 nop
24155 + pax_force_retaddr
24156 ret
24157 CFI_ENDPROC
24158 .Lclear_page_end:
24159 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
24160
24161 #include <asm/cpufeature.h>
24162
24163 - .section .altinstr_replacement,"ax"
24164 + .section .altinstr_replacement,"a"
24165 1: .byte 0xeb /* jmp <disp8> */
24166 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
24167 2: .byte 0xeb /* jmp <disp8> */
24168 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
24169 index 1e572c5..2a162cd 100644
24170 --- a/arch/x86/lib/cmpxchg16b_emu.S
24171 +++ b/arch/x86/lib/cmpxchg16b_emu.S
24172 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
24173
24174 popf
24175 mov $1, %al
24176 + pax_force_retaddr
24177 ret
24178
24179 not_same:
24180 popf
24181 xor %al,%al
24182 + pax_force_retaddr
24183 ret
24184
24185 CFI_ENDPROC
24186 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
24187 index 176cca6..1166c50 100644
24188 --- a/arch/x86/lib/copy_page_64.S
24189 +++ b/arch/x86/lib/copy_page_64.S
24190 @@ -9,6 +9,7 @@ copy_page_rep:
24191 CFI_STARTPROC
24192 movl $4096/8, %ecx
24193 rep movsq
24194 + pax_force_retaddr
24195 ret
24196 CFI_ENDPROC
24197 ENDPROC(copy_page_rep)
24198 @@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
24199
24200 ENTRY(copy_page)
24201 CFI_STARTPROC
24202 - subq $2*8, %rsp
24203 - CFI_ADJUST_CFA_OFFSET 2*8
24204 + subq $3*8, %rsp
24205 + CFI_ADJUST_CFA_OFFSET 3*8
24206 movq %rbx, (%rsp)
24207 CFI_REL_OFFSET rbx, 0
24208 movq %r12, 1*8(%rsp)
24209 CFI_REL_OFFSET r12, 1*8
24210 + movq %r13, 2*8(%rsp)
24211 + CFI_REL_OFFSET r13, 2*8
24212
24213 movl $(4096/64)-5, %ecx
24214 .p2align 4
24215 @@ -36,7 +39,7 @@ ENTRY(copy_page)
24216 movq 0x8*2(%rsi), %rdx
24217 movq 0x8*3(%rsi), %r8
24218 movq 0x8*4(%rsi), %r9
24219 - movq 0x8*5(%rsi), %r10
24220 + movq 0x8*5(%rsi), %r13
24221 movq 0x8*6(%rsi), %r11
24222 movq 0x8*7(%rsi), %r12
24223
24224 @@ -47,7 +50,7 @@ ENTRY(copy_page)
24225 movq %rdx, 0x8*2(%rdi)
24226 movq %r8, 0x8*3(%rdi)
24227 movq %r9, 0x8*4(%rdi)
24228 - movq %r10, 0x8*5(%rdi)
24229 + movq %r13, 0x8*5(%rdi)
24230 movq %r11, 0x8*6(%rdi)
24231 movq %r12, 0x8*7(%rdi)
24232
24233 @@ -66,7 +69,7 @@ ENTRY(copy_page)
24234 movq 0x8*2(%rsi), %rdx
24235 movq 0x8*3(%rsi), %r8
24236 movq 0x8*4(%rsi), %r9
24237 - movq 0x8*5(%rsi), %r10
24238 + movq 0x8*5(%rsi), %r13
24239 movq 0x8*6(%rsi), %r11
24240 movq 0x8*7(%rsi), %r12
24241
24242 @@ -75,7 +78,7 @@ ENTRY(copy_page)
24243 movq %rdx, 0x8*2(%rdi)
24244 movq %r8, 0x8*3(%rdi)
24245 movq %r9, 0x8*4(%rdi)
24246 - movq %r10, 0x8*5(%rdi)
24247 + movq %r13, 0x8*5(%rdi)
24248 movq %r11, 0x8*6(%rdi)
24249 movq %r12, 0x8*7(%rdi)
24250
24251 @@ -87,8 +90,11 @@ ENTRY(copy_page)
24252 CFI_RESTORE rbx
24253 movq 1*8(%rsp), %r12
24254 CFI_RESTORE r12
24255 - addq $2*8, %rsp
24256 - CFI_ADJUST_CFA_OFFSET -2*8
24257 + movq 2*8(%rsp), %r13
24258 + CFI_RESTORE r13
24259 + addq $3*8, %rsp
24260 + CFI_ADJUST_CFA_OFFSET -3*8
24261 + pax_force_retaddr
24262 ret
24263 .Lcopy_page_end:
24264 CFI_ENDPROC
24265 @@ -99,7 +105,7 @@ ENDPROC(copy_page)
24266
24267 #include <asm/cpufeature.h>
24268
24269 - .section .altinstr_replacement,"ax"
24270 + .section .altinstr_replacement,"a"
24271 1: .byte 0xeb /* jmp <disp8> */
24272 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
24273 2:
24274 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
24275 index a30ca15..d25fab6 100644
24276 --- a/arch/x86/lib/copy_user_64.S
24277 +++ b/arch/x86/lib/copy_user_64.S
24278 @@ -18,6 +18,7 @@
24279 #include <asm/alternative-asm.h>
24280 #include <asm/asm.h>
24281 #include <asm/smap.h>
24282 +#include <asm/pgtable.h>
24283
24284 /*
24285 * By placing feature2 after feature1 in altinstructions section, we logically
24286 @@ -31,7 +32,7 @@
24287 .byte 0xe9 /* 32bit jump */
24288 .long \orig-1f /* by default jump to orig */
24289 1:
24290 - .section .altinstr_replacement,"ax"
24291 + .section .altinstr_replacement,"a"
24292 2: .byte 0xe9 /* near jump with 32bit immediate */
24293 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
24294 3: .byte 0xe9 /* near jump with 32bit immediate */
24295 @@ -70,47 +71,20 @@
24296 #endif
24297 .endm
24298
24299 -/* Standard copy_to_user with segment limit checking */
24300 -ENTRY(_copy_to_user)
24301 - CFI_STARTPROC
24302 - GET_THREAD_INFO(%rax)
24303 - movq %rdi,%rcx
24304 - addq %rdx,%rcx
24305 - jc bad_to_user
24306 - cmpq TI_addr_limit(%rax),%rcx
24307 - ja bad_to_user
24308 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24309 - copy_user_generic_unrolled,copy_user_generic_string, \
24310 - copy_user_enhanced_fast_string
24311 - CFI_ENDPROC
24312 -ENDPROC(_copy_to_user)
24313 -
24314 -/* Standard copy_from_user with segment limit checking */
24315 -ENTRY(_copy_from_user)
24316 - CFI_STARTPROC
24317 - GET_THREAD_INFO(%rax)
24318 - movq %rsi,%rcx
24319 - addq %rdx,%rcx
24320 - jc bad_from_user
24321 - cmpq TI_addr_limit(%rax),%rcx
24322 - ja bad_from_user
24323 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
24324 - copy_user_generic_unrolled,copy_user_generic_string, \
24325 - copy_user_enhanced_fast_string
24326 - CFI_ENDPROC
24327 -ENDPROC(_copy_from_user)
24328 -
24329 .section .fixup,"ax"
24330 /* must zero dest */
24331 ENTRY(bad_from_user)
24332 bad_from_user:
24333 CFI_STARTPROC
24334 + testl %edx,%edx
24335 + js bad_to_user
24336 movl %edx,%ecx
24337 xorl %eax,%eax
24338 rep
24339 stosb
24340 bad_to_user:
24341 movl %edx,%eax
24342 + pax_force_retaddr
24343 ret
24344 CFI_ENDPROC
24345 ENDPROC(bad_from_user)
24346 @@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
24347 jz 17f
24348 1: movq (%rsi),%r8
24349 2: movq 1*8(%rsi),%r9
24350 -3: movq 2*8(%rsi),%r10
24351 +3: movq 2*8(%rsi),%rax
24352 4: movq 3*8(%rsi),%r11
24353 5: movq %r8,(%rdi)
24354 6: movq %r9,1*8(%rdi)
24355 -7: movq %r10,2*8(%rdi)
24356 +7: movq %rax,2*8(%rdi)
24357 8: movq %r11,3*8(%rdi)
24358 9: movq 4*8(%rsi),%r8
24359 10: movq 5*8(%rsi),%r9
24360 -11: movq 6*8(%rsi),%r10
24361 +11: movq 6*8(%rsi),%rax
24362 12: movq 7*8(%rsi),%r11
24363 13: movq %r8,4*8(%rdi)
24364 14: movq %r9,5*8(%rdi)
24365 -15: movq %r10,6*8(%rdi)
24366 +15: movq %rax,6*8(%rdi)
24367 16: movq %r11,7*8(%rdi)
24368 leaq 64(%rsi),%rsi
24369 leaq 64(%rdi),%rdi
24370 @@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
24371 jnz 21b
24372 23: xor %eax,%eax
24373 ASM_CLAC
24374 + pax_force_retaddr
24375 ret
24376
24377 .section .fixup,"ax"
24378 @@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
24379 movsb
24380 4: xorl %eax,%eax
24381 ASM_CLAC
24382 + pax_force_retaddr
24383 ret
24384
24385 .section .fixup,"ax"
24386 @@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
24387 movsb
24388 2: xorl %eax,%eax
24389 ASM_CLAC
24390 + pax_force_retaddr
24391 ret
24392
24393 .section .fixup,"ax"
24394 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
24395 index 6a4f43c..f5f9e26 100644
24396 --- a/arch/x86/lib/copy_user_nocache_64.S
24397 +++ b/arch/x86/lib/copy_user_nocache_64.S
24398 @@ -8,6 +8,7 @@
24399
24400 #include <linux/linkage.h>
24401 #include <asm/dwarf2.h>
24402 +#include <asm/alternative-asm.h>
24403
24404 #define FIX_ALIGNMENT 1
24405
24406 @@ -16,6 +17,7 @@
24407 #include <asm/thread_info.h>
24408 #include <asm/asm.h>
24409 #include <asm/smap.h>
24410 +#include <asm/pgtable.h>
24411
24412 .macro ALIGN_DESTINATION
24413 #ifdef FIX_ALIGNMENT
24414 @@ -49,6 +51,15 @@
24415 */
24416 ENTRY(__copy_user_nocache)
24417 CFI_STARTPROC
24418 +
24419 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24420 + mov $PAX_USER_SHADOW_BASE,%rcx
24421 + cmp %rcx,%rsi
24422 + jae 1f
24423 + add %rcx,%rsi
24424 +1:
24425 +#endif
24426 +
24427 ASM_STAC
24428 cmpl $8,%edx
24429 jb 20f /* less then 8 bytes, go to byte copy loop */
24430 @@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
24431 jz 17f
24432 1: movq (%rsi),%r8
24433 2: movq 1*8(%rsi),%r9
24434 -3: movq 2*8(%rsi),%r10
24435 +3: movq 2*8(%rsi),%rax
24436 4: movq 3*8(%rsi),%r11
24437 5: movnti %r8,(%rdi)
24438 6: movnti %r9,1*8(%rdi)
24439 -7: movnti %r10,2*8(%rdi)
24440 +7: movnti %rax,2*8(%rdi)
24441 8: movnti %r11,3*8(%rdi)
24442 9: movq 4*8(%rsi),%r8
24443 10: movq 5*8(%rsi),%r9
24444 -11: movq 6*8(%rsi),%r10
24445 +11: movq 6*8(%rsi),%rax
24446 12: movq 7*8(%rsi),%r11
24447 13: movnti %r8,4*8(%rdi)
24448 14: movnti %r9,5*8(%rdi)
24449 -15: movnti %r10,6*8(%rdi)
24450 +15: movnti %rax,6*8(%rdi)
24451 16: movnti %r11,7*8(%rdi)
24452 leaq 64(%rsi),%rsi
24453 leaq 64(%rdi),%rdi
24454 @@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
24455 23: xorl %eax,%eax
24456 ASM_CLAC
24457 sfence
24458 + pax_force_retaddr
24459 ret
24460
24461 .section .fixup,"ax"
24462 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
24463 index 2419d5f..953ee51 100644
24464 --- a/arch/x86/lib/csum-copy_64.S
24465 +++ b/arch/x86/lib/csum-copy_64.S
24466 @@ -9,6 +9,7 @@
24467 #include <asm/dwarf2.h>
24468 #include <asm/errno.h>
24469 #include <asm/asm.h>
24470 +#include <asm/alternative-asm.h>
24471
24472 /*
24473 * Checksum copy with exception handling.
24474 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
24475 CFI_RESTORE rbp
24476 addq $7*8, %rsp
24477 CFI_ADJUST_CFA_OFFSET -7*8
24478 + pax_force_retaddr 0, 1
24479 ret
24480 CFI_RESTORE_STATE
24481
24482 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
24483 index 25b7ae8..169fafc 100644
24484 --- a/arch/x86/lib/csum-wrappers_64.c
24485 +++ b/arch/x86/lib/csum-wrappers_64.c
24486 @@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
24487 len -= 2;
24488 }
24489 }
24490 - isum = csum_partial_copy_generic((__force const void *)src,
24491 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
24492 dst, len, isum, errp, NULL);
24493 if (unlikely(*errp))
24494 goto out_err;
24495 @@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
24496 }
24497
24498 *errp = 0;
24499 - return csum_partial_copy_generic(src, (void __force *)dst,
24500 + return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
24501 len, isum, NULL, errp);
24502 }
24503 EXPORT_SYMBOL(csum_partial_copy_to_user);
24504 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
24505 index 156b9c8..b144132 100644
24506 --- a/arch/x86/lib/getuser.S
24507 +++ b/arch/x86/lib/getuser.S
24508 @@ -34,17 +34,40 @@
24509 #include <asm/thread_info.h>
24510 #include <asm/asm.h>
24511 #include <asm/smap.h>
24512 +#include <asm/segment.h>
24513 +#include <asm/pgtable.h>
24514 +#include <asm/alternative-asm.h>
24515 +
24516 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24517 +#define __copyuser_seg gs;
24518 +#else
24519 +#define __copyuser_seg
24520 +#endif
24521
24522 .text
24523 ENTRY(__get_user_1)
24524 CFI_STARTPROC
24525 +
24526 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24527 GET_THREAD_INFO(%_ASM_DX)
24528 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24529 jae bad_get_user
24530 ASM_STAC
24531 -1: movzb (%_ASM_AX),%edx
24532 +
24533 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24534 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24535 + cmp %_ASM_DX,%_ASM_AX
24536 + jae 1234f
24537 + add %_ASM_DX,%_ASM_AX
24538 +1234:
24539 +#endif
24540 +
24541 +#endif
24542 +
24543 +1: __copyuser_seg movzb (%_ASM_AX),%edx
24544 xor %eax,%eax
24545 ASM_CLAC
24546 + pax_force_retaddr
24547 ret
24548 CFI_ENDPROC
24549 ENDPROC(__get_user_1)
24550 @@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
24551 ENTRY(__get_user_2)
24552 CFI_STARTPROC
24553 add $1,%_ASM_AX
24554 +
24555 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24556 jc bad_get_user
24557 GET_THREAD_INFO(%_ASM_DX)
24558 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24559 jae bad_get_user
24560 ASM_STAC
24561 -2: movzwl -1(%_ASM_AX),%edx
24562 +
24563 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24564 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24565 + cmp %_ASM_DX,%_ASM_AX
24566 + jae 1234f
24567 + add %_ASM_DX,%_ASM_AX
24568 +1234:
24569 +#endif
24570 +
24571 +#endif
24572 +
24573 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
24574 xor %eax,%eax
24575 ASM_CLAC
24576 + pax_force_retaddr
24577 ret
24578 CFI_ENDPROC
24579 ENDPROC(__get_user_2)
24580 @@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
24581 ENTRY(__get_user_4)
24582 CFI_STARTPROC
24583 add $3,%_ASM_AX
24584 +
24585 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24586 jc bad_get_user
24587 GET_THREAD_INFO(%_ASM_DX)
24588 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24589 jae bad_get_user
24590 ASM_STAC
24591 -3: mov -3(%_ASM_AX),%edx
24592 +
24593 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24594 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24595 + cmp %_ASM_DX,%_ASM_AX
24596 + jae 1234f
24597 + add %_ASM_DX,%_ASM_AX
24598 +1234:
24599 +#endif
24600 +
24601 +#endif
24602 +
24603 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
24604 xor %eax,%eax
24605 ASM_CLAC
24606 + pax_force_retaddr
24607 ret
24608 CFI_ENDPROC
24609 ENDPROC(__get_user_4)
24610 @@ -87,10 +138,20 @@ ENTRY(__get_user_8)
24611 GET_THREAD_INFO(%_ASM_DX)
24612 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
24613 jae bad_get_user
24614 +
24615 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24616 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
24617 + cmp %_ASM_DX,%_ASM_AX
24618 + jae 1234f
24619 + add %_ASM_DX,%_ASM_AX
24620 +1234:
24621 +#endif
24622 +
24623 ASM_STAC
24624 4: movq -7(%_ASM_AX),%_ASM_DX
24625 xor %eax,%eax
24626 ASM_CLAC
24627 + pax_force_retaddr
24628 ret
24629 CFI_ENDPROC
24630 ENDPROC(__get_user_8)
24631 @@ -101,6 +162,7 @@ bad_get_user:
24632 xor %edx,%edx
24633 mov $(-EFAULT),%_ASM_AX
24634 ASM_CLAC
24635 + pax_force_retaddr
24636 ret
24637 CFI_ENDPROC
24638 END(bad_get_user)
24639 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
24640 index 54fcffe..7be149e 100644
24641 --- a/arch/x86/lib/insn.c
24642 +++ b/arch/x86/lib/insn.c
24643 @@ -20,8 +20,10 @@
24644
24645 #ifdef __KERNEL__
24646 #include <linux/string.h>
24647 +#include <asm/pgtable_types.h>
24648 #else
24649 #include <string.h>
24650 +#define ktla_ktva(addr) addr
24651 #endif
24652 #include <asm/inat.h>
24653 #include <asm/insn.h>
24654 @@ -53,8 +55,8 @@
24655 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
24656 {
24657 memset(insn, 0, sizeof(*insn));
24658 - insn->kaddr = kaddr;
24659 - insn->next_byte = kaddr;
24660 + insn->kaddr = ktla_ktva(kaddr);
24661 + insn->next_byte = ktla_ktva(kaddr);
24662 insn->x86_64 = x86_64 ? 1 : 0;
24663 insn->opnd_bytes = 4;
24664 if (x86_64)
24665 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
24666 index 05a95e7..326f2fa 100644
24667 --- a/arch/x86/lib/iomap_copy_64.S
24668 +++ b/arch/x86/lib/iomap_copy_64.S
24669 @@ -17,6 +17,7 @@
24670
24671 #include <linux/linkage.h>
24672 #include <asm/dwarf2.h>
24673 +#include <asm/alternative-asm.h>
24674
24675 /*
24676 * override generic version in lib/iomap_copy.c
24677 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
24678 CFI_STARTPROC
24679 movl %edx,%ecx
24680 rep movsd
24681 + pax_force_retaddr
24682 ret
24683 CFI_ENDPROC
24684 ENDPROC(__iowrite32_copy)
24685 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
24686 index 1c273be..da9cc0e 100644
24687 --- a/arch/x86/lib/memcpy_64.S
24688 +++ b/arch/x86/lib/memcpy_64.S
24689 @@ -33,6 +33,7 @@
24690 rep movsq
24691 movl %edx, %ecx
24692 rep movsb
24693 + pax_force_retaddr
24694 ret
24695 .Lmemcpy_e:
24696 .previous
24697 @@ -49,6 +50,7 @@
24698 movq %rdi, %rax
24699 movq %rdx, %rcx
24700 rep movsb
24701 + pax_force_retaddr
24702 ret
24703 .Lmemcpy_e_e:
24704 .previous
24705 @@ -76,13 +78,13 @@ ENTRY(memcpy)
24706 */
24707 movq 0*8(%rsi), %r8
24708 movq 1*8(%rsi), %r9
24709 - movq 2*8(%rsi), %r10
24710 + movq 2*8(%rsi), %rcx
24711 movq 3*8(%rsi), %r11
24712 leaq 4*8(%rsi), %rsi
24713
24714 movq %r8, 0*8(%rdi)
24715 movq %r9, 1*8(%rdi)
24716 - movq %r10, 2*8(%rdi)
24717 + movq %rcx, 2*8(%rdi)
24718 movq %r11, 3*8(%rdi)
24719 leaq 4*8(%rdi), %rdi
24720 jae .Lcopy_forward_loop
24721 @@ -105,12 +107,12 @@ ENTRY(memcpy)
24722 subq $0x20, %rdx
24723 movq -1*8(%rsi), %r8
24724 movq -2*8(%rsi), %r9
24725 - movq -3*8(%rsi), %r10
24726 + movq -3*8(%rsi), %rcx
24727 movq -4*8(%rsi), %r11
24728 leaq -4*8(%rsi), %rsi
24729 movq %r8, -1*8(%rdi)
24730 movq %r9, -2*8(%rdi)
24731 - movq %r10, -3*8(%rdi)
24732 + movq %rcx, -3*8(%rdi)
24733 movq %r11, -4*8(%rdi)
24734 leaq -4*8(%rdi), %rdi
24735 jae .Lcopy_backward_loop
24736 @@ -130,12 +132,13 @@ ENTRY(memcpy)
24737 */
24738 movq 0*8(%rsi), %r8
24739 movq 1*8(%rsi), %r9
24740 - movq -2*8(%rsi, %rdx), %r10
24741 + movq -2*8(%rsi, %rdx), %rcx
24742 movq -1*8(%rsi, %rdx), %r11
24743 movq %r8, 0*8(%rdi)
24744 movq %r9, 1*8(%rdi)
24745 - movq %r10, -2*8(%rdi, %rdx)
24746 + movq %rcx, -2*8(%rdi, %rdx)
24747 movq %r11, -1*8(%rdi, %rdx)
24748 + pax_force_retaddr
24749 retq
24750 .p2align 4
24751 .Lless_16bytes:
24752 @@ -148,6 +151,7 @@ ENTRY(memcpy)
24753 movq -1*8(%rsi, %rdx), %r9
24754 movq %r8, 0*8(%rdi)
24755 movq %r9, -1*8(%rdi, %rdx)
24756 + pax_force_retaddr
24757 retq
24758 .p2align 4
24759 .Lless_8bytes:
24760 @@ -161,6 +165,7 @@ ENTRY(memcpy)
24761 movl -4(%rsi, %rdx), %r8d
24762 movl %ecx, (%rdi)
24763 movl %r8d, -4(%rdi, %rdx)
24764 + pax_force_retaddr
24765 retq
24766 .p2align 4
24767 .Lless_3bytes:
24768 @@ -179,6 +184,7 @@ ENTRY(memcpy)
24769 movb %cl, (%rdi)
24770
24771 .Lend:
24772 + pax_force_retaddr
24773 retq
24774 CFI_ENDPROC
24775 ENDPROC(memcpy)
24776 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
24777 index ee16461..c39c199 100644
24778 --- a/arch/x86/lib/memmove_64.S
24779 +++ b/arch/x86/lib/memmove_64.S
24780 @@ -61,13 +61,13 @@ ENTRY(memmove)
24781 5:
24782 sub $0x20, %rdx
24783 movq 0*8(%rsi), %r11
24784 - movq 1*8(%rsi), %r10
24785 + movq 1*8(%rsi), %rcx
24786 movq 2*8(%rsi), %r9
24787 movq 3*8(%rsi), %r8
24788 leaq 4*8(%rsi), %rsi
24789
24790 movq %r11, 0*8(%rdi)
24791 - movq %r10, 1*8(%rdi)
24792 + movq %rcx, 1*8(%rdi)
24793 movq %r9, 2*8(%rdi)
24794 movq %r8, 3*8(%rdi)
24795 leaq 4*8(%rdi), %rdi
24796 @@ -81,10 +81,10 @@ ENTRY(memmove)
24797 4:
24798 movq %rdx, %rcx
24799 movq -8(%rsi, %rdx), %r11
24800 - lea -8(%rdi, %rdx), %r10
24801 + lea -8(%rdi, %rdx), %r9
24802 shrq $3, %rcx
24803 rep movsq
24804 - movq %r11, (%r10)
24805 + movq %r11, (%r9)
24806 jmp 13f
24807 .Lmemmove_end_forward:
24808
24809 @@ -95,14 +95,14 @@ ENTRY(memmove)
24810 7:
24811 movq %rdx, %rcx
24812 movq (%rsi), %r11
24813 - movq %rdi, %r10
24814 + movq %rdi, %r9
24815 leaq -8(%rsi, %rdx), %rsi
24816 leaq -8(%rdi, %rdx), %rdi
24817 shrq $3, %rcx
24818 std
24819 rep movsq
24820 cld
24821 - movq %r11, (%r10)
24822 + movq %r11, (%r9)
24823 jmp 13f
24824
24825 /*
24826 @@ -127,13 +127,13 @@ ENTRY(memmove)
24827 8:
24828 subq $0x20, %rdx
24829 movq -1*8(%rsi), %r11
24830 - movq -2*8(%rsi), %r10
24831 + movq -2*8(%rsi), %rcx
24832 movq -3*8(%rsi), %r9
24833 movq -4*8(%rsi), %r8
24834 leaq -4*8(%rsi), %rsi
24835
24836 movq %r11, -1*8(%rdi)
24837 - movq %r10, -2*8(%rdi)
24838 + movq %rcx, -2*8(%rdi)
24839 movq %r9, -3*8(%rdi)
24840 movq %r8, -4*8(%rdi)
24841 leaq -4*8(%rdi), %rdi
24842 @@ -151,11 +151,11 @@ ENTRY(memmove)
24843 * Move data from 16 bytes to 31 bytes.
24844 */
24845 movq 0*8(%rsi), %r11
24846 - movq 1*8(%rsi), %r10
24847 + movq 1*8(%rsi), %rcx
24848 movq -2*8(%rsi, %rdx), %r9
24849 movq -1*8(%rsi, %rdx), %r8
24850 movq %r11, 0*8(%rdi)
24851 - movq %r10, 1*8(%rdi)
24852 + movq %rcx, 1*8(%rdi)
24853 movq %r9, -2*8(%rdi, %rdx)
24854 movq %r8, -1*8(%rdi, %rdx)
24855 jmp 13f
24856 @@ -167,9 +167,9 @@ ENTRY(memmove)
24857 * Move data from 8 bytes to 15 bytes.
24858 */
24859 movq 0*8(%rsi), %r11
24860 - movq -1*8(%rsi, %rdx), %r10
24861 + movq -1*8(%rsi, %rdx), %r9
24862 movq %r11, 0*8(%rdi)
24863 - movq %r10, -1*8(%rdi, %rdx)
24864 + movq %r9, -1*8(%rdi, %rdx)
24865 jmp 13f
24866 10:
24867 cmpq $4, %rdx
24868 @@ -178,9 +178,9 @@ ENTRY(memmove)
24869 * Move data from 4 bytes to 7 bytes.
24870 */
24871 movl (%rsi), %r11d
24872 - movl -4(%rsi, %rdx), %r10d
24873 + movl -4(%rsi, %rdx), %r9d
24874 movl %r11d, (%rdi)
24875 - movl %r10d, -4(%rdi, %rdx)
24876 + movl %r9d, -4(%rdi, %rdx)
24877 jmp 13f
24878 11:
24879 cmp $2, %rdx
24880 @@ -189,9 +189,9 @@ ENTRY(memmove)
24881 * Move data from 2 bytes to 3 bytes.
24882 */
24883 movw (%rsi), %r11w
24884 - movw -2(%rsi, %rdx), %r10w
24885 + movw -2(%rsi, %rdx), %r9w
24886 movw %r11w, (%rdi)
24887 - movw %r10w, -2(%rdi, %rdx)
24888 + movw %r9w, -2(%rdi, %rdx)
24889 jmp 13f
24890 12:
24891 cmp $1, %rdx
24892 @@ -202,6 +202,7 @@ ENTRY(memmove)
24893 movb (%rsi), %r11b
24894 movb %r11b, (%rdi)
24895 13:
24896 + pax_force_retaddr
24897 retq
24898 CFI_ENDPROC
24899
24900 @@ -210,6 +211,7 @@ ENTRY(memmove)
24901 /* Forward moving data. */
24902 movq %rdx, %rcx
24903 rep movsb
24904 + pax_force_retaddr
24905 retq
24906 .Lmemmove_end_forward_efs:
24907 .previous
24908 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
24909 index 2dcb380..963660a 100644
24910 --- a/arch/x86/lib/memset_64.S
24911 +++ b/arch/x86/lib/memset_64.S
24912 @@ -30,6 +30,7 @@
24913 movl %edx,%ecx
24914 rep stosb
24915 movq %r9,%rax
24916 + pax_force_retaddr
24917 ret
24918 .Lmemset_e:
24919 .previous
24920 @@ -52,6 +53,7 @@
24921 movq %rdx,%rcx
24922 rep stosb
24923 movq %r9,%rax
24924 + pax_force_retaddr
24925 ret
24926 .Lmemset_e_e:
24927 .previous
24928 @@ -59,7 +61,7 @@
24929 ENTRY(memset)
24930 ENTRY(__memset)
24931 CFI_STARTPROC
24932 - movq %rdi,%r10
24933 + movq %rdi,%r11
24934
24935 /* expand byte value */
24936 movzbl %sil,%ecx
24937 @@ -117,7 +119,8 @@ ENTRY(__memset)
24938 jnz .Lloop_1
24939
24940 .Lende:
24941 - movq %r10,%rax
24942 + movq %r11,%rax
24943 + pax_force_retaddr
24944 ret
24945
24946 CFI_RESTORE_STATE
24947 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
24948 index c9f2d9b..e7fd2c0 100644
24949 --- a/arch/x86/lib/mmx_32.c
24950 +++ b/arch/x86/lib/mmx_32.c
24951 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24952 {
24953 void *p;
24954 int i;
24955 + unsigned long cr0;
24956
24957 if (unlikely(in_interrupt()))
24958 return __memcpy(to, from, len);
24959 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
24960 kernel_fpu_begin();
24961
24962 __asm__ __volatile__ (
24963 - "1: prefetch (%0)\n" /* This set is 28 bytes */
24964 - " prefetch 64(%0)\n"
24965 - " prefetch 128(%0)\n"
24966 - " prefetch 192(%0)\n"
24967 - " prefetch 256(%0)\n"
24968 + "1: prefetch (%1)\n" /* This set is 28 bytes */
24969 + " prefetch 64(%1)\n"
24970 + " prefetch 128(%1)\n"
24971 + " prefetch 192(%1)\n"
24972 + " prefetch 256(%1)\n"
24973 "2: \n"
24974 ".section .fixup, \"ax\"\n"
24975 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24976 + "3: \n"
24977 +
24978 +#ifdef CONFIG_PAX_KERNEXEC
24979 + " movl %%cr0, %0\n"
24980 + " movl %0, %%eax\n"
24981 + " andl $0xFFFEFFFF, %%eax\n"
24982 + " movl %%eax, %%cr0\n"
24983 +#endif
24984 +
24985 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
24986 +
24987 +#ifdef CONFIG_PAX_KERNEXEC
24988 + " movl %0, %%cr0\n"
24989 +#endif
24990 +
24991 " jmp 2b\n"
24992 ".previous\n"
24993 _ASM_EXTABLE(1b, 3b)
24994 - : : "r" (from));
24995 + : "=&r" (cr0) : "r" (from) : "ax");
24996
24997 for ( ; i > 5; i--) {
24998 __asm__ __volatile__ (
24999 - "1: prefetch 320(%0)\n"
25000 - "2: movq (%0), %%mm0\n"
25001 - " movq 8(%0), %%mm1\n"
25002 - " movq 16(%0), %%mm2\n"
25003 - " movq 24(%0), %%mm3\n"
25004 - " movq %%mm0, (%1)\n"
25005 - " movq %%mm1, 8(%1)\n"
25006 - " movq %%mm2, 16(%1)\n"
25007 - " movq %%mm3, 24(%1)\n"
25008 - " movq 32(%0), %%mm0\n"
25009 - " movq 40(%0), %%mm1\n"
25010 - " movq 48(%0), %%mm2\n"
25011 - " movq 56(%0), %%mm3\n"
25012 - " movq %%mm0, 32(%1)\n"
25013 - " movq %%mm1, 40(%1)\n"
25014 - " movq %%mm2, 48(%1)\n"
25015 - " movq %%mm3, 56(%1)\n"
25016 + "1: prefetch 320(%1)\n"
25017 + "2: movq (%1), %%mm0\n"
25018 + " movq 8(%1), %%mm1\n"
25019 + " movq 16(%1), %%mm2\n"
25020 + " movq 24(%1), %%mm3\n"
25021 + " movq %%mm0, (%2)\n"
25022 + " movq %%mm1, 8(%2)\n"
25023 + " movq %%mm2, 16(%2)\n"
25024 + " movq %%mm3, 24(%2)\n"
25025 + " movq 32(%1), %%mm0\n"
25026 + " movq 40(%1), %%mm1\n"
25027 + " movq 48(%1), %%mm2\n"
25028 + " movq 56(%1), %%mm3\n"
25029 + " movq %%mm0, 32(%2)\n"
25030 + " movq %%mm1, 40(%2)\n"
25031 + " movq %%mm2, 48(%2)\n"
25032 + " movq %%mm3, 56(%2)\n"
25033 ".section .fixup, \"ax\"\n"
25034 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25035 + "3:\n"
25036 +
25037 +#ifdef CONFIG_PAX_KERNEXEC
25038 + " movl %%cr0, %0\n"
25039 + " movl %0, %%eax\n"
25040 + " andl $0xFFFEFFFF, %%eax\n"
25041 + " movl %%eax, %%cr0\n"
25042 +#endif
25043 +
25044 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25045 +
25046 +#ifdef CONFIG_PAX_KERNEXEC
25047 + " movl %0, %%cr0\n"
25048 +#endif
25049 +
25050 " jmp 2b\n"
25051 ".previous\n"
25052 _ASM_EXTABLE(1b, 3b)
25053 - : : "r" (from), "r" (to) : "memory");
25054 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25055
25056 from += 64;
25057 to += 64;
25058 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25059 static void fast_copy_page(void *to, void *from)
25060 {
25061 int i;
25062 + unsigned long cr0;
25063
25064 kernel_fpu_begin();
25065
25066 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25067 * but that is for later. -AV
25068 */
25069 __asm__ __volatile__(
25070 - "1: prefetch (%0)\n"
25071 - " prefetch 64(%0)\n"
25072 - " prefetch 128(%0)\n"
25073 - " prefetch 192(%0)\n"
25074 - " prefetch 256(%0)\n"
25075 + "1: prefetch (%1)\n"
25076 + " prefetch 64(%1)\n"
25077 + " prefetch 128(%1)\n"
25078 + " prefetch 192(%1)\n"
25079 + " prefetch 256(%1)\n"
25080 "2: \n"
25081 ".section .fixup, \"ax\"\n"
25082 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25083 + "3: \n"
25084 +
25085 +#ifdef CONFIG_PAX_KERNEXEC
25086 + " movl %%cr0, %0\n"
25087 + " movl %0, %%eax\n"
25088 + " andl $0xFFFEFFFF, %%eax\n"
25089 + " movl %%eax, %%cr0\n"
25090 +#endif
25091 +
25092 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25093 +
25094 +#ifdef CONFIG_PAX_KERNEXEC
25095 + " movl %0, %%cr0\n"
25096 +#endif
25097 +
25098 " jmp 2b\n"
25099 ".previous\n"
25100 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25101 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25102
25103 for (i = 0; i < (4096-320)/64; i++) {
25104 __asm__ __volatile__ (
25105 - "1: prefetch 320(%0)\n"
25106 - "2: movq (%0), %%mm0\n"
25107 - " movntq %%mm0, (%1)\n"
25108 - " movq 8(%0), %%mm1\n"
25109 - " movntq %%mm1, 8(%1)\n"
25110 - " movq 16(%0), %%mm2\n"
25111 - " movntq %%mm2, 16(%1)\n"
25112 - " movq 24(%0), %%mm3\n"
25113 - " movntq %%mm3, 24(%1)\n"
25114 - " movq 32(%0), %%mm4\n"
25115 - " movntq %%mm4, 32(%1)\n"
25116 - " movq 40(%0), %%mm5\n"
25117 - " movntq %%mm5, 40(%1)\n"
25118 - " movq 48(%0), %%mm6\n"
25119 - " movntq %%mm6, 48(%1)\n"
25120 - " movq 56(%0), %%mm7\n"
25121 - " movntq %%mm7, 56(%1)\n"
25122 + "1: prefetch 320(%1)\n"
25123 + "2: movq (%1), %%mm0\n"
25124 + " movntq %%mm0, (%2)\n"
25125 + " movq 8(%1), %%mm1\n"
25126 + " movntq %%mm1, 8(%2)\n"
25127 + " movq 16(%1), %%mm2\n"
25128 + " movntq %%mm2, 16(%2)\n"
25129 + " movq 24(%1), %%mm3\n"
25130 + " movntq %%mm3, 24(%2)\n"
25131 + " movq 32(%1), %%mm4\n"
25132 + " movntq %%mm4, 32(%2)\n"
25133 + " movq 40(%1), %%mm5\n"
25134 + " movntq %%mm5, 40(%2)\n"
25135 + " movq 48(%1), %%mm6\n"
25136 + " movntq %%mm6, 48(%2)\n"
25137 + " movq 56(%1), %%mm7\n"
25138 + " movntq %%mm7, 56(%2)\n"
25139 ".section .fixup, \"ax\"\n"
25140 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25141 + "3:\n"
25142 +
25143 +#ifdef CONFIG_PAX_KERNEXEC
25144 + " movl %%cr0, %0\n"
25145 + " movl %0, %%eax\n"
25146 + " andl $0xFFFEFFFF, %%eax\n"
25147 + " movl %%eax, %%cr0\n"
25148 +#endif
25149 +
25150 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25151 +
25152 +#ifdef CONFIG_PAX_KERNEXEC
25153 + " movl %0, %%cr0\n"
25154 +#endif
25155 +
25156 " jmp 2b\n"
25157 ".previous\n"
25158 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
25159 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25160
25161 from += 64;
25162 to += 64;
25163 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
25164 static void fast_copy_page(void *to, void *from)
25165 {
25166 int i;
25167 + unsigned long cr0;
25168
25169 kernel_fpu_begin();
25170
25171 __asm__ __volatile__ (
25172 - "1: prefetch (%0)\n"
25173 - " prefetch 64(%0)\n"
25174 - " prefetch 128(%0)\n"
25175 - " prefetch 192(%0)\n"
25176 - " prefetch 256(%0)\n"
25177 + "1: prefetch (%1)\n"
25178 + " prefetch 64(%1)\n"
25179 + " prefetch 128(%1)\n"
25180 + " prefetch 192(%1)\n"
25181 + " prefetch 256(%1)\n"
25182 "2: \n"
25183 ".section .fixup, \"ax\"\n"
25184 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25185 + "3: \n"
25186 +
25187 +#ifdef CONFIG_PAX_KERNEXEC
25188 + " movl %%cr0, %0\n"
25189 + " movl %0, %%eax\n"
25190 + " andl $0xFFFEFFFF, %%eax\n"
25191 + " movl %%eax, %%cr0\n"
25192 +#endif
25193 +
25194 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25195 +
25196 +#ifdef CONFIG_PAX_KERNEXEC
25197 + " movl %0, %%cr0\n"
25198 +#endif
25199 +
25200 " jmp 2b\n"
25201 ".previous\n"
25202 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
25203 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25204
25205 for (i = 0; i < 4096/64; i++) {
25206 __asm__ __volatile__ (
25207 - "1: prefetch 320(%0)\n"
25208 - "2: movq (%0), %%mm0\n"
25209 - " movq 8(%0), %%mm1\n"
25210 - " movq 16(%0), %%mm2\n"
25211 - " movq 24(%0), %%mm3\n"
25212 - " movq %%mm0, (%1)\n"
25213 - " movq %%mm1, 8(%1)\n"
25214 - " movq %%mm2, 16(%1)\n"
25215 - " movq %%mm3, 24(%1)\n"
25216 - " movq 32(%0), %%mm0\n"
25217 - " movq 40(%0), %%mm1\n"
25218 - " movq 48(%0), %%mm2\n"
25219 - " movq 56(%0), %%mm3\n"
25220 - " movq %%mm0, 32(%1)\n"
25221 - " movq %%mm1, 40(%1)\n"
25222 - " movq %%mm2, 48(%1)\n"
25223 - " movq %%mm3, 56(%1)\n"
25224 + "1: prefetch 320(%1)\n"
25225 + "2: movq (%1), %%mm0\n"
25226 + " movq 8(%1), %%mm1\n"
25227 + " movq 16(%1), %%mm2\n"
25228 + " movq 24(%1), %%mm3\n"
25229 + " movq %%mm0, (%2)\n"
25230 + " movq %%mm1, 8(%2)\n"
25231 + " movq %%mm2, 16(%2)\n"
25232 + " movq %%mm3, 24(%2)\n"
25233 + " movq 32(%1), %%mm0\n"
25234 + " movq 40(%1), %%mm1\n"
25235 + " movq 48(%1), %%mm2\n"
25236 + " movq 56(%1), %%mm3\n"
25237 + " movq %%mm0, 32(%2)\n"
25238 + " movq %%mm1, 40(%2)\n"
25239 + " movq %%mm2, 48(%2)\n"
25240 + " movq %%mm3, 56(%2)\n"
25241 ".section .fixup, \"ax\"\n"
25242 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25243 + "3:\n"
25244 +
25245 +#ifdef CONFIG_PAX_KERNEXEC
25246 + " movl %%cr0, %0\n"
25247 + " movl %0, %%eax\n"
25248 + " andl $0xFFFEFFFF, %%eax\n"
25249 + " movl %%eax, %%cr0\n"
25250 +#endif
25251 +
25252 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25253 +
25254 +#ifdef CONFIG_PAX_KERNEXEC
25255 + " movl %0, %%cr0\n"
25256 +#endif
25257 +
25258 " jmp 2b\n"
25259 ".previous\n"
25260 _ASM_EXTABLE(1b, 3b)
25261 - : : "r" (from), "r" (to) : "memory");
25262 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25263
25264 from += 64;
25265 to += 64;
25266 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
25267 index f6d13ee..aca5f0b 100644
25268 --- a/arch/x86/lib/msr-reg.S
25269 +++ b/arch/x86/lib/msr-reg.S
25270 @@ -3,6 +3,7 @@
25271 #include <asm/dwarf2.h>
25272 #include <asm/asm.h>
25273 #include <asm/msr.h>
25274 +#include <asm/alternative-asm.h>
25275
25276 #ifdef CONFIG_X86_64
25277 /*
25278 @@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
25279 CFI_STARTPROC
25280 pushq_cfi %rbx
25281 pushq_cfi %rbp
25282 - movq %rdi, %r10 /* Save pointer */
25283 + movq %rdi, %r9 /* Save pointer */
25284 xorl %r11d, %r11d /* Return value */
25285 movl (%rdi), %eax
25286 movl 4(%rdi), %ecx
25287 @@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
25288 movl 28(%rdi), %edi
25289 CFI_REMEMBER_STATE
25290 1: \op
25291 -2: movl %eax, (%r10)
25292 +2: movl %eax, (%r9)
25293 movl %r11d, %eax /* Return value */
25294 - movl %ecx, 4(%r10)
25295 - movl %edx, 8(%r10)
25296 - movl %ebx, 12(%r10)
25297 - movl %ebp, 20(%r10)
25298 - movl %esi, 24(%r10)
25299 - movl %edi, 28(%r10)
25300 + movl %ecx, 4(%r9)
25301 + movl %edx, 8(%r9)
25302 + movl %ebx, 12(%r9)
25303 + movl %ebp, 20(%r9)
25304 + movl %esi, 24(%r9)
25305 + movl %edi, 28(%r9)
25306 popq_cfi %rbp
25307 popq_cfi %rbx
25308 + pax_force_retaddr
25309 ret
25310 3:
25311 CFI_RESTORE_STATE
25312 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
25313 index fc6ba17..04471c5 100644
25314 --- a/arch/x86/lib/putuser.S
25315 +++ b/arch/x86/lib/putuser.S
25316 @@ -16,7 +16,9 @@
25317 #include <asm/errno.h>
25318 #include <asm/asm.h>
25319 #include <asm/smap.h>
25320 -
25321 +#include <asm/segment.h>
25322 +#include <asm/pgtable.h>
25323 +#include <asm/alternative-asm.h>
25324
25325 /*
25326 * __put_user_X
25327 @@ -30,57 +32,125 @@
25328 * as they get called from within inline assembly.
25329 */
25330
25331 -#define ENTER CFI_STARTPROC ; \
25332 - GET_THREAD_INFO(%_ASM_BX)
25333 -#define EXIT ASM_CLAC ; \
25334 - ret ; \
25335 +#define ENTER CFI_STARTPROC
25336 +#define EXIT ASM_CLAC ; \
25337 + pax_force_retaddr ; \
25338 + ret ; \
25339 CFI_ENDPROC
25340
25341 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25342 +#define _DEST %_ASM_CX,%_ASM_BX
25343 +#else
25344 +#define _DEST %_ASM_CX
25345 +#endif
25346 +
25347 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25348 +#define __copyuser_seg gs;
25349 +#else
25350 +#define __copyuser_seg
25351 +#endif
25352 +
25353 .text
25354 ENTRY(__put_user_1)
25355 ENTER
25356 +
25357 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25358 + GET_THREAD_INFO(%_ASM_BX)
25359 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
25360 jae bad_put_user
25361 ASM_STAC
25362 -1: movb %al,(%_ASM_CX)
25363 +
25364 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25365 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25366 + cmp %_ASM_BX,%_ASM_CX
25367 + jb 1234f
25368 + xor %ebx,%ebx
25369 +1234:
25370 +#endif
25371 +
25372 +#endif
25373 +
25374 +1: __copyuser_seg movb %al,(_DEST)
25375 xor %eax,%eax
25376 EXIT
25377 ENDPROC(__put_user_1)
25378
25379 ENTRY(__put_user_2)
25380 ENTER
25381 +
25382 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25383 + GET_THREAD_INFO(%_ASM_BX)
25384 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25385 sub $1,%_ASM_BX
25386 cmp %_ASM_BX,%_ASM_CX
25387 jae bad_put_user
25388 ASM_STAC
25389 -2: movw %ax,(%_ASM_CX)
25390 +
25391 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25392 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25393 + cmp %_ASM_BX,%_ASM_CX
25394 + jb 1234f
25395 + xor %ebx,%ebx
25396 +1234:
25397 +#endif
25398 +
25399 +#endif
25400 +
25401 +2: __copyuser_seg movw %ax,(_DEST)
25402 xor %eax,%eax
25403 EXIT
25404 ENDPROC(__put_user_2)
25405
25406 ENTRY(__put_user_4)
25407 ENTER
25408 +
25409 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25410 + GET_THREAD_INFO(%_ASM_BX)
25411 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25412 sub $3,%_ASM_BX
25413 cmp %_ASM_BX,%_ASM_CX
25414 jae bad_put_user
25415 ASM_STAC
25416 -3: movl %eax,(%_ASM_CX)
25417 +
25418 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25419 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25420 + cmp %_ASM_BX,%_ASM_CX
25421 + jb 1234f
25422 + xor %ebx,%ebx
25423 +1234:
25424 +#endif
25425 +
25426 +#endif
25427 +
25428 +3: __copyuser_seg movl %eax,(_DEST)
25429 xor %eax,%eax
25430 EXIT
25431 ENDPROC(__put_user_4)
25432
25433 ENTRY(__put_user_8)
25434 ENTER
25435 +
25436 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25437 + GET_THREAD_INFO(%_ASM_BX)
25438 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
25439 sub $7,%_ASM_BX
25440 cmp %_ASM_BX,%_ASM_CX
25441 jae bad_put_user
25442 ASM_STAC
25443 -4: mov %_ASM_AX,(%_ASM_CX)
25444 +
25445 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25446 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
25447 + cmp %_ASM_BX,%_ASM_CX
25448 + jb 1234f
25449 + xor %ebx,%ebx
25450 +1234:
25451 +#endif
25452 +
25453 +#endif
25454 +
25455 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
25456 #ifdef CONFIG_X86_32
25457 -5: movl %edx,4(%_ASM_CX)
25458 +5: __copyuser_seg movl %edx,4(_DEST)
25459 #endif
25460 xor %eax,%eax
25461 EXIT
25462 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
25463 index 1cad221..de671ee 100644
25464 --- a/arch/x86/lib/rwlock.S
25465 +++ b/arch/x86/lib/rwlock.S
25466 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
25467 FRAME
25468 0: LOCK_PREFIX
25469 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25470 +
25471 +#ifdef CONFIG_PAX_REFCOUNT
25472 + jno 1234f
25473 + LOCK_PREFIX
25474 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25475 + int $4
25476 +1234:
25477 + _ASM_EXTABLE(1234b, 1234b)
25478 +#endif
25479 +
25480 1: rep; nop
25481 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
25482 jne 1b
25483 LOCK_PREFIX
25484 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
25485 +
25486 +#ifdef CONFIG_PAX_REFCOUNT
25487 + jno 1234f
25488 + LOCK_PREFIX
25489 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
25490 + int $4
25491 +1234:
25492 + _ASM_EXTABLE(1234b, 1234b)
25493 +#endif
25494 +
25495 jnz 0b
25496 ENDFRAME
25497 + pax_force_retaddr
25498 ret
25499 CFI_ENDPROC
25500 END(__write_lock_failed)
25501 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
25502 FRAME
25503 0: LOCK_PREFIX
25504 READ_LOCK_SIZE(inc) (%__lock_ptr)
25505 +
25506 +#ifdef CONFIG_PAX_REFCOUNT
25507 + jno 1234f
25508 + LOCK_PREFIX
25509 + READ_LOCK_SIZE(dec) (%__lock_ptr)
25510 + int $4
25511 +1234:
25512 + _ASM_EXTABLE(1234b, 1234b)
25513 +#endif
25514 +
25515 1: rep; nop
25516 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
25517 js 1b
25518 LOCK_PREFIX
25519 READ_LOCK_SIZE(dec) (%__lock_ptr)
25520 +
25521 +#ifdef CONFIG_PAX_REFCOUNT
25522 + jno 1234f
25523 + LOCK_PREFIX
25524 + READ_LOCK_SIZE(inc) (%__lock_ptr)
25525 + int $4
25526 +1234:
25527 + _ASM_EXTABLE(1234b, 1234b)
25528 +#endif
25529 +
25530 js 0b
25531 ENDFRAME
25532 + pax_force_retaddr
25533 ret
25534 CFI_ENDPROC
25535 END(__read_lock_failed)
25536 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
25537 index 5dff5f0..cadebf4 100644
25538 --- a/arch/x86/lib/rwsem.S
25539 +++ b/arch/x86/lib/rwsem.S
25540 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
25541 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25542 CFI_RESTORE __ASM_REG(dx)
25543 restore_common_regs
25544 + pax_force_retaddr
25545 ret
25546 CFI_ENDPROC
25547 ENDPROC(call_rwsem_down_read_failed)
25548 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
25549 movq %rax,%rdi
25550 call rwsem_down_write_failed
25551 restore_common_regs
25552 + pax_force_retaddr
25553 ret
25554 CFI_ENDPROC
25555 ENDPROC(call_rwsem_down_write_failed)
25556 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
25557 movq %rax,%rdi
25558 call rwsem_wake
25559 restore_common_regs
25560 -1: ret
25561 +1: pax_force_retaddr
25562 + ret
25563 CFI_ENDPROC
25564 ENDPROC(call_rwsem_wake)
25565
25566 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
25567 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
25568 CFI_RESTORE __ASM_REG(dx)
25569 restore_common_regs
25570 + pax_force_retaddr
25571 ret
25572 CFI_ENDPROC
25573 ENDPROC(call_rwsem_downgrade_wake)
25574 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
25575 index a63efd6..ccecad8 100644
25576 --- a/arch/x86/lib/thunk_64.S
25577 +++ b/arch/x86/lib/thunk_64.S
25578 @@ -8,6 +8,7 @@
25579 #include <linux/linkage.h>
25580 #include <asm/dwarf2.h>
25581 #include <asm/calling.h>
25582 +#include <asm/alternative-asm.h>
25583
25584 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
25585 .macro THUNK name, func, put_ret_addr_in_rdi=0
25586 @@ -41,5 +42,6 @@
25587 SAVE_ARGS
25588 restore:
25589 RESTORE_ARGS
25590 + pax_force_retaddr
25591 ret
25592 CFI_ENDPROC
25593 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
25594 index f0312d7..9c39d63 100644
25595 --- a/arch/x86/lib/usercopy_32.c
25596 +++ b/arch/x86/lib/usercopy_32.c
25597 @@ -42,11 +42,13 @@ do { \
25598 int __d0; \
25599 might_fault(); \
25600 __asm__ __volatile__( \
25601 + __COPYUSER_SET_ES \
25602 ASM_STAC "\n" \
25603 "0: rep; stosl\n" \
25604 " movl %2,%0\n" \
25605 "1: rep; stosb\n" \
25606 "2: " ASM_CLAC "\n" \
25607 + __COPYUSER_RESTORE_ES \
25608 ".section .fixup,\"ax\"\n" \
25609 "3: lea 0(%2,%0,4),%0\n" \
25610 " jmp 2b\n" \
25611 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
25612
25613 #ifdef CONFIG_X86_INTEL_USERCOPY
25614 static unsigned long
25615 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
25616 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
25617 {
25618 int d0, d1;
25619 __asm__ __volatile__(
25620 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25621 " .align 2,0x90\n"
25622 "3: movl 0(%4), %%eax\n"
25623 "4: movl 4(%4), %%edx\n"
25624 - "5: movl %%eax, 0(%3)\n"
25625 - "6: movl %%edx, 4(%3)\n"
25626 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
25627 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
25628 "7: movl 8(%4), %%eax\n"
25629 "8: movl 12(%4),%%edx\n"
25630 - "9: movl %%eax, 8(%3)\n"
25631 - "10: movl %%edx, 12(%3)\n"
25632 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
25633 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
25634 "11: movl 16(%4), %%eax\n"
25635 "12: movl 20(%4), %%edx\n"
25636 - "13: movl %%eax, 16(%3)\n"
25637 - "14: movl %%edx, 20(%3)\n"
25638 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
25639 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
25640 "15: movl 24(%4), %%eax\n"
25641 "16: movl 28(%4), %%edx\n"
25642 - "17: movl %%eax, 24(%3)\n"
25643 - "18: movl %%edx, 28(%3)\n"
25644 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
25645 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
25646 "19: movl 32(%4), %%eax\n"
25647 "20: movl 36(%4), %%edx\n"
25648 - "21: movl %%eax, 32(%3)\n"
25649 - "22: movl %%edx, 36(%3)\n"
25650 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
25651 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
25652 "23: movl 40(%4), %%eax\n"
25653 "24: movl 44(%4), %%edx\n"
25654 - "25: movl %%eax, 40(%3)\n"
25655 - "26: movl %%edx, 44(%3)\n"
25656 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
25657 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
25658 "27: movl 48(%4), %%eax\n"
25659 "28: movl 52(%4), %%edx\n"
25660 - "29: movl %%eax, 48(%3)\n"
25661 - "30: movl %%edx, 52(%3)\n"
25662 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
25663 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
25664 "31: movl 56(%4), %%eax\n"
25665 "32: movl 60(%4), %%edx\n"
25666 - "33: movl %%eax, 56(%3)\n"
25667 - "34: movl %%edx, 60(%3)\n"
25668 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
25669 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
25670 " addl $-64, %0\n"
25671 " addl $64, %4\n"
25672 " addl $64, %3\n"
25673 @@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25674 " shrl $2, %0\n"
25675 " andl $3, %%eax\n"
25676 " cld\n"
25677 + __COPYUSER_SET_ES
25678 "99: rep; movsl\n"
25679 "36: movl %%eax, %0\n"
25680 "37: rep; movsb\n"
25681 "100:\n"
25682 + __COPYUSER_RESTORE_ES
25683 ".section .fixup,\"ax\"\n"
25684 "101: lea 0(%%eax,%0,4),%0\n"
25685 " jmp 100b\n"
25686 @@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
25687 }
25688
25689 static unsigned long
25690 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
25691 +{
25692 + int d0, d1;
25693 + __asm__ __volatile__(
25694 + " .align 2,0x90\n"
25695 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
25696 + " cmpl $67, %0\n"
25697 + " jbe 3f\n"
25698 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
25699 + " .align 2,0x90\n"
25700 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
25701 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
25702 + "5: movl %%eax, 0(%3)\n"
25703 + "6: movl %%edx, 4(%3)\n"
25704 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
25705 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
25706 + "9: movl %%eax, 8(%3)\n"
25707 + "10: movl %%edx, 12(%3)\n"
25708 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
25709 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
25710 + "13: movl %%eax, 16(%3)\n"
25711 + "14: movl %%edx, 20(%3)\n"
25712 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
25713 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
25714 + "17: movl %%eax, 24(%3)\n"
25715 + "18: movl %%edx, 28(%3)\n"
25716 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
25717 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
25718 + "21: movl %%eax, 32(%3)\n"
25719 + "22: movl %%edx, 36(%3)\n"
25720 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
25721 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
25722 + "25: movl %%eax, 40(%3)\n"
25723 + "26: movl %%edx, 44(%3)\n"
25724 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
25725 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
25726 + "29: movl %%eax, 48(%3)\n"
25727 + "30: movl %%edx, 52(%3)\n"
25728 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
25729 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
25730 + "33: movl %%eax, 56(%3)\n"
25731 + "34: movl %%edx, 60(%3)\n"
25732 + " addl $-64, %0\n"
25733 + " addl $64, %4\n"
25734 + " addl $64, %3\n"
25735 + " cmpl $63, %0\n"
25736 + " ja 1b\n"
25737 + "35: movl %0, %%eax\n"
25738 + " shrl $2, %0\n"
25739 + " andl $3, %%eax\n"
25740 + " cld\n"
25741 + "99: rep; "__copyuser_seg" movsl\n"
25742 + "36: movl %%eax, %0\n"
25743 + "37: rep; "__copyuser_seg" movsb\n"
25744 + "100:\n"
25745 + ".section .fixup,\"ax\"\n"
25746 + "101: lea 0(%%eax,%0,4),%0\n"
25747 + " jmp 100b\n"
25748 + ".previous\n"
25749 + _ASM_EXTABLE(1b,100b)
25750 + _ASM_EXTABLE(2b,100b)
25751 + _ASM_EXTABLE(3b,100b)
25752 + _ASM_EXTABLE(4b,100b)
25753 + _ASM_EXTABLE(5b,100b)
25754 + _ASM_EXTABLE(6b,100b)
25755 + _ASM_EXTABLE(7b,100b)
25756 + _ASM_EXTABLE(8b,100b)
25757 + _ASM_EXTABLE(9b,100b)
25758 + _ASM_EXTABLE(10b,100b)
25759 + _ASM_EXTABLE(11b,100b)
25760 + _ASM_EXTABLE(12b,100b)
25761 + _ASM_EXTABLE(13b,100b)
25762 + _ASM_EXTABLE(14b,100b)
25763 + _ASM_EXTABLE(15b,100b)
25764 + _ASM_EXTABLE(16b,100b)
25765 + _ASM_EXTABLE(17b,100b)
25766 + _ASM_EXTABLE(18b,100b)
25767 + _ASM_EXTABLE(19b,100b)
25768 + _ASM_EXTABLE(20b,100b)
25769 + _ASM_EXTABLE(21b,100b)
25770 + _ASM_EXTABLE(22b,100b)
25771 + _ASM_EXTABLE(23b,100b)
25772 + _ASM_EXTABLE(24b,100b)
25773 + _ASM_EXTABLE(25b,100b)
25774 + _ASM_EXTABLE(26b,100b)
25775 + _ASM_EXTABLE(27b,100b)
25776 + _ASM_EXTABLE(28b,100b)
25777 + _ASM_EXTABLE(29b,100b)
25778 + _ASM_EXTABLE(30b,100b)
25779 + _ASM_EXTABLE(31b,100b)
25780 + _ASM_EXTABLE(32b,100b)
25781 + _ASM_EXTABLE(33b,100b)
25782 + _ASM_EXTABLE(34b,100b)
25783 + _ASM_EXTABLE(35b,100b)
25784 + _ASM_EXTABLE(36b,100b)
25785 + _ASM_EXTABLE(37b,100b)
25786 + _ASM_EXTABLE(99b,101b)
25787 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
25788 + : "1"(to), "2"(from), "0"(size)
25789 + : "eax", "edx", "memory");
25790 + return size;
25791 +}
25792 +
25793 +static unsigned long __size_overflow(3)
25794 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25795 {
25796 int d0, d1;
25797 __asm__ __volatile__(
25798 " .align 2,0x90\n"
25799 - "0: movl 32(%4), %%eax\n"
25800 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25801 " cmpl $67, %0\n"
25802 " jbe 2f\n"
25803 - "1: movl 64(%4), %%eax\n"
25804 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25805 " .align 2,0x90\n"
25806 - "2: movl 0(%4), %%eax\n"
25807 - "21: movl 4(%4), %%edx\n"
25808 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25809 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25810 " movl %%eax, 0(%3)\n"
25811 " movl %%edx, 4(%3)\n"
25812 - "3: movl 8(%4), %%eax\n"
25813 - "31: movl 12(%4),%%edx\n"
25814 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25815 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25816 " movl %%eax, 8(%3)\n"
25817 " movl %%edx, 12(%3)\n"
25818 - "4: movl 16(%4), %%eax\n"
25819 - "41: movl 20(%4), %%edx\n"
25820 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25821 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25822 " movl %%eax, 16(%3)\n"
25823 " movl %%edx, 20(%3)\n"
25824 - "10: movl 24(%4), %%eax\n"
25825 - "51: movl 28(%4), %%edx\n"
25826 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25827 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25828 " movl %%eax, 24(%3)\n"
25829 " movl %%edx, 28(%3)\n"
25830 - "11: movl 32(%4), %%eax\n"
25831 - "61: movl 36(%4), %%edx\n"
25832 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25833 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25834 " movl %%eax, 32(%3)\n"
25835 " movl %%edx, 36(%3)\n"
25836 - "12: movl 40(%4), %%eax\n"
25837 - "71: movl 44(%4), %%edx\n"
25838 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25839 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25840 " movl %%eax, 40(%3)\n"
25841 " movl %%edx, 44(%3)\n"
25842 - "13: movl 48(%4), %%eax\n"
25843 - "81: movl 52(%4), %%edx\n"
25844 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25845 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25846 " movl %%eax, 48(%3)\n"
25847 " movl %%edx, 52(%3)\n"
25848 - "14: movl 56(%4), %%eax\n"
25849 - "91: movl 60(%4), %%edx\n"
25850 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25851 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25852 " movl %%eax, 56(%3)\n"
25853 " movl %%edx, 60(%3)\n"
25854 " addl $-64, %0\n"
25855 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25856 " shrl $2, %0\n"
25857 " andl $3, %%eax\n"
25858 " cld\n"
25859 - "6: rep; movsl\n"
25860 + "6: rep; "__copyuser_seg" movsl\n"
25861 " movl %%eax,%0\n"
25862 - "7: rep; movsb\n"
25863 + "7: rep; "__copyuser_seg" movsb\n"
25864 "8:\n"
25865 ".section .fixup,\"ax\"\n"
25866 "9: lea 0(%%eax,%0,4),%0\n"
25867 @@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
25868 * hyoshiok@miraclelinux.com
25869 */
25870
25871 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25872 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
25873 const void __user *from, unsigned long size)
25874 {
25875 int d0, d1;
25876
25877 __asm__ __volatile__(
25878 " .align 2,0x90\n"
25879 - "0: movl 32(%4), %%eax\n"
25880 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25881 " cmpl $67, %0\n"
25882 " jbe 2f\n"
25883 - "1: movl 64(%4), %%eax\n"
25884 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25885 " .align 2,0x90\n"
25886 - "2: movl 0(%4), %%eax\n"
25887 - "21: movl 4(%4), %%edx\n"
25888 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25889 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25890 " movnti %%eax, 0(%3)\n"
25891 " movnti %%edx, 4(%3)\n"
25892 - "3: movl 8(%4), %%eax\n"
25893 - "31: movl 12(%4),%%edx\n"
25894 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25895 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25896 " movnti %%eax, 8(%3)\n"
25897 " movnti %%edx, 12(%3)\n"
25898 - "4: movl 16(%4), %%eax\n"
25899 - "41: movl 20(%4), %%edx\n"
25900 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25901 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25902 " movnti %%eax, 16(%3)\n"
25903 " movnti %%edx, 20(%3)\n"
25904 - "10: movl 24(%4), %%eax\n"
25905 - "51: movl 28(%4), %%edx\n"
25906 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25907 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25908 " movnti %%eax, 24(%3)\n"
25909 " movnti %%edx, 28(%3)\n"
25910 - "11: movl 32(%4), %%eax\n"
25911 - "61: movl 36(%4), %%edx\n"
25912 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25913 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25914 " movnti %%eax, 32(%3)\n"
25915 " movnti %%edx, 36(%3)\n"
25916 - "12: movl 40(%4), %%eax\n"
25917 - "71: movl 44(%4), %%edx\n"
25918 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25919 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
25920 " movnti %%eax, 40(%3)\n"
25921 " movnti %%edx, 44(%3)\n"
25922 - "13: movl 48(%4), %%eax\n"
25923 - "81: movl 52(%4), %%edx\n"
25924 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
25925 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
25926 " movnti %%eax, 48(%3)\n"
25927 " movnti %%edx, 52(%3)\n"
25928 - "14: movl 56(%4), %%eax\n"
25929 - "91: movl 60(%4), %%edx\n"
25930 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
25931 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
25932 " movnti %%eax, 56(%3)\n"
25933 " movnti %%edx, 60(%3)\n"
25934 " addl $-64, %0\n"
25935 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25936 " shrl $2, %0\n"
25937 " andl $3, %%eax\n"
25938 " cld\n"
25939 - "6: rep; movsl\n"
25940 + "6: rep; "__copyuser_seg" movsl\n"
25941 " movl %%eax,%0\n"
25942 - "7: rep; movsb\n"
25943 + "7: rep; "__copyuser_seg" movsb\n"
25944 "8:\n"
25945 ".section .fixup,\"ax\"\n"
25946 "9: lea 0(%%eax,%0,4),%0\n"
25947 @@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
25948 return size;
25949 }
25950
25951 -static unsigned long __copy_user_intel_nocache(void *to,
25952 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
25953 const void __user *from, unsigned long size)
25954 {
25955 int d0, d1;
25956
25957 __asm__ __volatile__(
25958 " .align 2,0x90\n"
25959 - "0: movl 32(%4), %%eax\n"
25960 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
25961 " cmpl $67, %0\n"
25962 " jbe 2f\n"
25963 - "1: movl 64(%4), %%eax\n"
25964 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
25965 " .align 2,0x90\n"
25966 - "2: movl 0(%4), %%eax\n"
25967 - "21: movl 4(%4), %%edx\n"
25968 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
25969 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
25970 " movnti %%eax, 0(%3)\n"
25971 " movnti %%edx, 4(%3)\n"
25972 - "3: movl 8(%4), %%eax\n"
25973 - "31: movl 12(%4),%%edx\n"
25974 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
25975 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
25976 " movnti %%eax, 8(%3)\n"
25977 " movnti %%edx, 12(%3)\n"
25978 - "4: movl 16(%4), %%eax\n"
25979 - "41: movl 20(%4), %%edx\n"
25980 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
25981 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
25982 " movnti %%eax, 16(%3)\n"
25983 " movnti %%edx, 20(%3)\n"
25984 - "10: movl 24(%4), %%eax\n"
25985 - "51: movl 28(%4), %%edx\n"
25986 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
25987 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
25988 " movnti %%eax, 24(%3)\n"
25989 " movnti %%edx, 28(%3)\n"
25990 - "11: movl 32(%4), %%eax\n"
25991 - "61: movl 36(%4), %%edx\n"
25992 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
25993 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
25994 " movnti %%eax, 32(%3)\n"
25995 " movnti %%edx, 36(%3)\n"
25996 - "12: movl 40(%4), %%eax\n"
25997 - "71: movl 44(%4), %%edx\n"
25998 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
25999 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26000 " movnti %%eax, 40(%3)\n"
26001 " movnti %%edx, 44(%3)\n"
26002 - "13: movl 48(%4), %%eax\n"
26003 - "81: movl 52(%4), %%edx\n"
26004 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26005 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26006 " movnti %%eax, 48(%3)\n"
26007 " movnti %%edx, 52(%3)\n"
26008 - "14: movl 56(%4), %%eax\n"
26009 - "91: movl 60(%4), %%edx\n"
26010 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26011 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26012 " movnti %%eax, 56(%3)\n"
26013 " movnti %%edx, 60(%3)\n"
26014 " addl $-64, %0\n"
26015 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26016 " shrl $2, %0\n"
26017 " andl $3, %%eax\n"
26018 " cld\n"
26019 - "6: rep; movsl\n"
26020 + "6: rep; "__copyuser_seg" movsl\n"
26021 " movl %%eax,%0\n"
26022 - "7: rep; movsb\n"
26023 + "7: rep; "__copyuser_seg" movsb\n"
26024 "8:\n"
26025 ".section .fixup,\"ax\"\n"
26026 "9: lea 0(%%eax,%0,4),%0\n"
26027 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26028 */
26029 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26030 unsigned long size);
26031 -unsigned long __copy_user_intel(void __user *to, const void *from,
26032 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26033 + unsigned long size);
26034 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26035 unsigned long size);
26036 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26037 const void __user *from, unsigned long size);
26038 #endif /* CONFIG_X86_INTEL_USERCOPY */
26039
26040 /* Generic arbitrary sized copy. */
26041 -#define __copy_user(to, from, size) \
26042 +#define __copy_user(to, from, size, prefix, set, restore) \
26043 do { \
26044 int __d0, __d1, __d2; \
26045 __asm__ __volatile__( \
26046 + set \
26047 " cmp $7,%0\n" \
26048 " jbe 1f\n" \
26049 " movl %1,%0\n" \
26050 " negl %0\n" \
26051 " andl $7,%0\n" \
26052 " subl %0,%3\n" \
26053 - "4: rep; movsb\n" \
26054 + "4: rep; "prefix"movsb\n" \
26055 " movl %3,%0\n" \
26056 " shrl $2,%0\n" \
26057 " andl $3,%3\n" \
26058 " .align 2,0x90\n" \
26059 - "0: rep; movsl\n" \
26060 + "0: rep; "prefix"movsl\n" \
26061 " movl %3,%0\n" \
26062 - "1: rep; movsb\n" \
26063 + "1: rep; "prefix"movsb\n" \
26064 "2:\n" \
26065 + restore \
26066 ".section .fixup,\"ax\"\n" \
26067 "5: addl %3,%0\n" \
26068 " jmp 2b\n" \
26069 @@ -538,14 +650,14 @@ do { \
26070 " negl %0\n" \
26071 " andl $7,%0\n" \
26072 " subl %0,%3\n" \
26073 - "4: rep; movsb\n" \
26074 + "4: rep; "__copyuser_seg"movsb\n" \
26075 " movl %3,%0\n" \
26076 " shrl $2,%0\n" \
26077 " andl $3,%3\n" \
26078 " .align 2,0x90\n" \
26079 - "0: rep; movsl\n" \
26080 + "0: rep; "__copyuser_seg"movsl\n" \
26081 " movl %3,%0\n" \
26082 - "1: rep; movsb\n" \
26083 + "1: rep; "__copyuser_seg"movsb\n" \
26084 "2:\n" \
26085 ".section .fixup,\"ax\"\n" \
26086 "5: addl %3,%0\n" \
26087 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26088 {
26089 stac();
26090 if (movsl_is_ok(to, from, n))
26091 - __copy_user(to, from, n);
26092 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26093 else
26094 - n = __copy_user_intel(to, from, n);
26095 + n = __generic_copy_to_user_intel(to, from, n);
26096 clac();
26097 return n;
26098 }
26099 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26100 {
26101 stac();
26102 if (movsl_is_ok(to, from, n))
26103 - __copy_user(to, from, n);
26104 + __copy_user(to, from, n, __copyuser_seg, "", "");
26105 else
26106 - n = __copy_user_intel((void __user *)to,
26107 - (const void *)from, n);
26108 + n = __generic_copy_from_user_intel(to, from, n);
26109 clac();
26110 return n;
26111 }
26112 @@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26113 if (n > 64 && cpu_has_xmm2)
26114 n = __copy_user_intel_nocache(to, from, n);
26115 else
26116 - __copy_user(to, from, n);
26117 + __copy_user(to, from, n, __copyuser_seg, "", "");
26118 #else
26119 - __copy_user(to, from, n);
26120 + __copy_user(to, from, n, __copyuser_seg, "", "");
26121 #endif
26122 clac();
26123 return n;
26124 }
26125 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
26126
26127 -/**
26128 - * copy_to_user: - Copy a block of data into user space.
26129 - * @to: Destination address, in user space.
26130 - * @from: Source address, in kernel space.
26131 - * @n: Number of bytes to copy.
26132 - *
26133 - * Context: User context only. This function may sleep.
26134 - *
26135 - * Copy data from kernel space to user space.
26136 - *
26137 - * Returns number of bytes that could not be copied.
26138 - * On success, this will be zero.
26139 - */
26140 -unsigned long
26141 -copy_to_user(void __user *to, const void *from, unsigned long n)
26142 -{
26143 - if (access_ok(VERIFY_WRITE, to, n))
26144 - n = __copy_to_user(to, from, n);
26145 - return n;
26146 -}
26147 -EXPORT_SYMBOL(copy_to_user);
26148 -
26149 -/**
26150 - * copy_from_user: - Copy a block of data from user space.
26151 - * @to: Destination address, in kernel space.
26152 - * @from: Source address, in user space.
26153 - * @n: Number of bytes to copy.
26154 - *
26155 - * Context: User context only. This function may sleep.
26156 - *
26157 - * Copy data from user space to kernel space.
26158 - *
26159 - * Returns number of bytes that could not be copied.
26160 - * On success, this will be zero.
26161 - *
26162 - * If some data could not be copied, this function will pad the copied
26163 - * data to the requested size using zero bytes.
26164 - */
26165 -unsigned long
26166 -_copy_from_user(void *to, const void __user *from, unsigned long n)
26167 -{
26168 - if (access_ok(VERIFY_READ, from, n))
26169 - n = __copy_from_user(to, from, n);
26170 - else
26171 - memset(to, 0, n);
26172 - return n;
26173 -}
26174 -EXPORT_SYMBOL(_copy_from_user);
26175 -
26176 void copy_from_user_overflow(void)
26177 {
26178 WARN(1, "Buffer overflow detected!\n");
26179 }
26180 EXPORT_SYMBOL(copy_from_user_overflow);
26181 +
26182 +void copy_to_user_overflow(void)
26183 +{
26184 + WARN(1, "Buffer overflow detected!\n");
26185 +}
26186 +EXPORT_SYMBOL(copy_to_user_overflow);
26187 +
26188 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26189 +void __set_fs(mm_segment_t x)
26190 +{
26191 + switch (x.seg) {
26192 + case 0:
26193 + loadsegment(gs, 0);
26194 + break;
26195 + case TASK_SIZE_MAX:
26196 + loadsegment(gs, __USER_DS);
26197 + break;
26198 + case -1UL:
26199 + loadsegment(gs, __KERNEL_DS);
26200 + break;
26201 + default:
26202 + BUG();
26203 + }
26204 + return;
26205 +}
26206 +EXPORT_SYMBOL(__set_fs);
26207 +
26208 +void set_fs(mm_segment_t x)
26209 +{
26210 + current_thread_info()->addr_limit = x;
26211 + __set_fs(x);
26212 +}
26213 +EXPORT_SYMBOL(set_fs);
26214 +#endif
26215 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
26216 index 05928aa..b33dea1 100644
26217 --- a/arch/x86/lib/usercopy_64.c
26218 +++ b/arch/x86/lib/usercopy_64.c
26219 @@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
26220 _ASM_EXTABLE(0b,3b)
26221 _ASM_EXTABLE(1b,2b)
26222 : [size8] "=&c"(size), [dst] "=&D" (__d0)
26223 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
26224 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
26225 [zero] "r" (0UL), [eight] "r" (8UL));
26226 clac();
26227 return size;
26228 @@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
26229 }
26230 EXPORT_SYMBOL(clear_user);
26231
26232 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
26233 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
26234 {
26235 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
26236 - return copy_user_generic((__force void *)to, (__force void *)from, len);
26237 - }
26238 - return len;
26239 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
26240 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
26241 + return len;
26242 }
26243 EXPORT_SYMBOL(copy_in_user);
26244
26245 @@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
26246 * it is not necessary to optimize tail handling.
26247 */
26248 unsigned long
26249 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26250 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
26251 {
26252 char c;
26253 unsigned zero_len;
26254 @@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
26255 clac();
26256 return len;
26257 }
26258 +
26259 +void copy_from_user_overflow(void)
26260 +{
26261 + WARN(1, "Buffer overflow detected!\n");
26262 +}
26263 +EXPORT_SYMBOL(copy_from_user_overflow);
26264 +
26265 +void copy_to_user_overflow(void)
26266 +{
26267 + WARN(1, "Buffer overflow detected!\n");
26268 +}
26269 +EXPORT_SYMBOL(copy_to_user_overflow);
26270 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
26271 index 903ec1e..c4166b2 100644
26272 --- a/arch/x86/mm/extable.c
26273 +++ b/arch/x86/mm/extable.c
26274 @@ -6,12 +6,24 @@
26275 static inline unsigned long
26276 ex_insn_addr(const struct exception_table_entry *x)
26277 {
26278 - return (unsigned long)&x->insn + x->insn;
26279 + unsigned long reloc = 0;
26280 +
26281 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26282 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26283 +#endif
26284 +
26285 + return (unsigned long)&x->insn + x->insn + reloc;
26286 }
26287 static inline unsigned long
26288 ex_fixup_addr(const struct exception_table_entry *x)
26289 {
26290 - return (unsigned long)&x->fixup + x->fixup;
26291 + unsigned long reloc = 0;
26292 +
26293 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26294 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26295 +#endif
26296 +
26297 + return (unsigned long)&x->fixup + x->fixup + reloc;
26298 }
26299
26300 int fixup_exception(struct pt_regs *regs)
26301 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
26302 unsigned long new_ip;
26303
26304 #ifdef CONFIG_PNPBIOS
26305 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
26306 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
26307 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
26308 extern u32 pnp_bios_is_utter_crap;
26309 pnp_bios_is_utter_crap = 1;
26310 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
26311 i += 4;
26312 p->fixup -= i;
26313 i += 4;
26314 +
26315 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26316 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
26317 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26318 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
26319 +#endif
26320 +
26321 }
26322 }
26323
26324 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
26325 index fb674fd..272f369 100644
26326 --- a/arch/x86/mm/fault.c
26327 +++ b/arch/x86/mm/fault.c
26328 @@ -13,12 +13,19 @@
26329 #include <linux/perf_event.h> /* perf_sw_event */
26330 #include <linux/hugetlb.h> /* hstate_index_to_shift */
26331 #include <linux/prefetch.h> /* prefetchw */
26332 +#include <linux/unistd.h>
26333 +#include <linux/compiler.h>
26334
26335 #include <asm/traps.h> /* dotraplinkage, ... */
26336 #include <asm/pgalloc.h> /* pgd_*(), ... */
26337 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
26338 #include <asm/fixmap.h> /* VSYSCALL_START */
26339 #include <asm/context_tracking.h> /* exception_enter(), ... */
26340 +#include <asm/tlbflush.h>
26341 +
26342 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26343 +#include <asm/stacktrace.h>
26344 +#endif
26345
26346 /*
26347 * Page fault error code bits:
26348 @@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
26349 int ret = 0;
26350
26351 /* kprobe_running() needs smp_processor_id() */
26352 - if (kprobes_built_in() && !user_mode_vm(regs)) {
26353 + if (kprobes_built_in() && !user_mode(regs)) {
26354 preempt_disable();
26355 if (kprobe_running() && kprobe_fault_handler(regs, 14))
26356 ret = 1;
26357 @@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
26358 return !instr_lo || (instr_lo>>1) == 1;
26359 case 0x00:
26360 /* Prefetch instruction is 0x0F0D or 0x0F18 */
26361 - if (probe_kernel_address(instr, opcode))
26362 + if (user_mode(regs)) {
26363 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26364 + return 0;
26365 + } else if (probe_kernel_address(instr, opcode))
26366 return 0;
26367
26368 *prefetch = (instr_lo == 0xF) &&
26369 @@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
26370 while (instr < max_instr) {
26371 unsigned char opcode;
26372
26373 - if (probe_kernel_address(instr, opcode))
26374 + if (user_mode(regs)) {
26375 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
26376 + break;
26377 + } else if (probe_kernel_address(instr, opcode))
26378 break;
26379
26380 instr++;
26381 @@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
26382 force_sig_info(si_signo, &info, tsk);
26383 }
26384
26385 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26386 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
26387 +#endif
26388 +
26389 +#ifdef CONFIG_PAX_EMUTRAMP
26390 +static int pax_handle_fetch_fault(struct pt_regs *regs);
26391 +#endif
26392 +
26393 +#ifdef CONFIG_PAX_PAGEEXEC
26394 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
26395 +{
26396 + pgd_t *pgd;
26397 + pud_t *pud;
26398 + pmd_t *pmd;
26399 +
26400 + pgd = pgd_offset(mm, address);
26401 + if (!pgd_present(*pgd))
26402 + return NULL;
26403 + pud = pud_offset(pgd, address);
26404 + if (!pud_present(*pud))
26405 + return NULL;
26406 + pmd = pmd_offset(pud, address);
26407 + if (!pmd_present(*pmd))
26408 + return NULL;
26409 + return pmd;
26410 +}
26411 +#endif
26412 +
26413 DEFINE_SPINLOCK(pgd_lock);
26414 LIST_HEAD(pgd_list);
26415
26416 @@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
26417 for (address = VMALLOC_START & PMD_MASK;
26418 address >= TASK_SIZE && address < FIXADDR_TOP;
26419 address += PMD_SIZE) {
26420 +
26421 +#ifdef CONFIG_PAX_PER_CPU_PGD
26422 + unsigned long cpu;
26423 +#else
26424 struct page *page;
26425 +#endif
26426
26427 spin_lock(&pgd_lock);
26428 +
26429 +#ifdef CONFIG_PAX_PER_CPU_PGD
26430 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26431 + pgd_t *pgd = get_cpu_pgd(cpu);
26432 + pmd_t *ret;
26433 +#else
26434 list_for_each_entry(page, &pgd_list, lru) {
26435 + pgd_t *pgd = page_address(page);
26436 spinlock_t *pgt_lock;
26437 pmd_t *ret;
26438
26439 @@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
26440 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26441
26442 spin_lock(pgt_lock);
26443 - ret = vmalloc_sync_one(page_address(page), address);
26444 +#endif
26445 +
26446 + ret = vmalloc_sync_one(pgd, address);
26447 +
26448 +#ifndef CONFIG_PAX_PER_CPU_PGD
26449 spin_unlock(pgt_lock);
26450 +#endif
26451
26452 if (!ret)
26453 break;
26454 @@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26455 * an interrupt in the middle of a task switch..
26456 */
26457 pgd_paddr = read_cr3();
26458 +
26459 +#ifdef CONFIG_PAX_PER_CPU_PGD
26460 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
26461 +#endif
26462 +
26463 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
26464 if (!pmd_k)
26465 return -1;
26466 @@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
26467 * happen within a race in page table update. In the later
26468 * case just flush:
26469 */
26470 +
26471 +#ifdef CONFIG_PAX_PER_CPU_PGD
26472 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
26473 + pgd = pgd_offset_cpu(smp_processor_id(), address);
26474 +#else
26475 pgd = pgd_offset(current->active_mm, address);
26476 +#endif
26477 +
26478 pgd_ref = pgd_offset_k(address);
26479 if (pgd_none(*pgd_ref))
26480 return -1;
26481 @@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
26482 static int is_errata100(struct pt_regs *regs, unsigned long address)
26483 {
26484 #ifdef CONFIG_X86_64
26485 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
26486 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
26487 return 1;
26488 #endif
26489 return 0;
26490 @@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
26491 }
26492
26493 static const char nx_warning[] = KERN_CRIT
26494 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
26495 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
26496
26497 static void
26498 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26499 @@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
26500 if (!oops_may_print())
26501 return;
26502
26503 - if (error_code & PF_INSTR) {
26504 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
26505 unsigned int level;
26506
26507 pte_t *pte = lookup_address(address, &level);
26508
26509 if (pte && pte_present(*pte) && !pte_exec(*pte))
26510 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
26511 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
26512 }
26513
26514 +#ifdef CONFIG_PAX_KERNEXEC
26515 + if (init_mm.start_code <= address && address < init_mm.end_code) {
26516 + if (current->signal->curr_ip)
26517 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
26518 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
26519 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26520 + else
26521 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
26522 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
26523 + }
26524 +#endif
26525 +
26526 printk(KERN_ALERT "BUG: unable to handle kernel ");
26527 if (address < PAGE_SIZE)
26528 printk(KERN_CONT "NULL pointer dereference");
26529 @@ -748,6 +830,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
26530 return;
26531 }
26532 #endif
26533 +
26534 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26535 + if (pax_is_fetch_fault(regs, error_code, address)) {
26536 +
26537 +#ifdef CONFIG_PAX_EMUTRAMP
26538 + switch (pax_handle_fetch_fault(regs)) {
26539 + case 2:
26540 + return;
26541 + }
26542 +#endif
26543 +
26544 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26545 + do_group_exit(SIGKILL);
26546 + }
26547 +#endif
26548 +
26549 /* Kernel addresses are always protection faults: */
26550 if (address >= TASK_SIZE)
26551 error_code |= PF_PROT;
26552 @@ -833,7 +931,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
26553 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
26554 printk(KERN_ERR
26555 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
26556 - tsk->comm, tsk->pid, address);
26557 + tsk->comm, task_pid_nr(tsk), address);
26558 code = BUS_MCEERR_AR;
26559 }
26560 #endif
26561 @@ -896,6 +994,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
26562 return 1;
26563 }
26564
26565 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26566 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
26567 +{
26568 + pte_t *pte;
26569 + pmd_t *pmd;
26570 + spinlock_t *ptl;
26571 + unsigned char pte_mask;
26572 +
26573 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
26574 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
26575 + return 0;
26576 +
26577 + /* PaX: it's our fault, let's handle it if we can */
26578 +
26579 + /* PaX: take a look at read faults before acquiring any locks */
26580 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
26581 + /* instruction fetch attempt from a protected page in user mode */
26582 + up_read(&mm->mmap_sem);
26583 +
26584 +#ifdef CONFIG_PAX_EMUTRAMP
26585 + switch (pax_handle_fetch_fault(regs)) {
26586 + case 2:
26587 + return 1;
26588 + }
26589 +#endif
26590 +
26591 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
26592 + do_group_exit(SIGKILL);
26593 + }
26594 +
26595 + pmd = pax_get_pmd(mm, address);
26596 + if (unlikely(!pmd))
26597 + return 0;
26598 +
26599 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
26600 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
26601 + pte_unmap_unlock(pte, ptl);
26602 + return 0;
26603 + }
26604 +
26605 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
26606 + /* write attempt to a protected page in user mode */
26607 + pte_unmap_unlock(pte, ptl);
26608 + return 0;
26609 + }
26610 +
26611 +#ifdef CONFIG_SMP
26612 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
26613 +#else
26614 + if (likely(address > get_limit(regs->cs)))
26615 +#endif
26616 + {
26617 + set_pte(pte, pte_mkread(*pte));
26618 + __flush_tlb_one(address);
26619 + pte_unmap_unlock(pte, ptl);
26620 + up_read(&mm->mmap_sem);
26621 + return 1;
26622 + }
26623 +
26624 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
26625 +
26626 + /*
26627 + * PaX: fill DTLB with user rights and retry
26628 + */
26629 + __asm__ __volatile__ (
26630 + "orb %2,(%1)\n"
26631 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
26632 +/*
26633 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
26634 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
26635 + * page fault when examined during a TLB load attempt. this is true not only
26636 + * for PTEs holding a non-present entry but also present entries that will
26637 + * raise a page fault (such as those set up by PaX, or the copy-on-write
26638 + * mechanism). in effect it means that we do *not* need to flush the TLBs
26639 + * for our target pages since their PTEs are simply not in the TLBs at all.
26640 +
26641 + * the best thing in omitting it is that we gain around 15-20% speed in the
26642 + * fast path of the page fault handler and can get rid of tracing since we
26643 + * can no longer flush unintended entries.
26644 + */
26645 + "invlpg (%0)\n"
26646 +#endif
26647 + __copyuser_seg"testb $0,(%0)\n"
26648 + "xorb %3,(%1)\n"
26649 + :
26650 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
26651 + : "memory", "cc");
26652 + pte_unmap_unlock(pte, ptl);
26653 + up_read(&mm->mmap_sem);
26654 + return 1;
26655 +}
26656 +#endif
26657 +
26658 /*
26659 * Handle a spurious fault caused by a stale TLB entry.
26660 *
26661 @@ -968,6 +1159,9 @@ int show_unhandled_signals = 1;
26662 static inline int
26663 access_error(unsigned long error_code, struct vm_area_struct *vma)
26664 {
26665 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
26666 + return 1;
26667 +
26668 if (error_code & PF_WRITE) {
26669 /* write, present and write, not present: */
26670 if (unlikely(!(vma->vm_flags & VM_WRITE)))
26671 @@ -996,7 +1190,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
26672 if (error_code & PF_USER)
26673 return false;
26674
26675 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
26676 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
26677 return false;
26678
26679 return true;
26680 @@ -1012,18 +1206,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26681 {
26682 struct vm_area_struct *vma;
26683 struct task_struct *tsk;
26684 - unsigned long address;
26685 struct mm_struct *mm;
26686 int fault;
26687 int write = error_code & PF_WRITE;
26688 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
26689 (write ? FAULT_FLAG_WRITE : 0);
26690
26691 - tsk = current;
26692 - mm = tsk->mm;
26693 -
26694 /* Get the faulting address: */
26695 - address = read_cr2();
26696 + unsigned long address = read_cr2();
26697 +
26698 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26699 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
26700 + if (!search_exception_tables(regs->ip)) {
26701 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26702 + bad_area_nosemaphore(regs, error_code, address);
26703 + return;
26704 + }
26705 + if (address < PAX_USER_SHADOW_BASE) {
26706 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
26707 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
26708 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
26709 + } else
26710 + address -= PAX_USER_SHADOW_BASE;
26711 + }
26712 +#endif
26713 +
26714 + tsk = current;
26715 + mm = tsk->mm;
26716
26717 /*
26718 * Detect and handle instructions that would cause a page fault for
26719 @@ -1084,7 +1293,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
26720 * User-mode registers count as a user access even for any
26721 * potential system fault or CPU buglet:
26722 */
26723 - if (user_mode_vm(regs)) {
26724 + if (user_mode(regs)) {
26725 local_irq_enable();
26726 error_code |= PF_USER;
26727 } else {
26728 @@ -1146,6 +1355,11 @@ retry:
26729 might_sleep();
26730 }
26731
26732 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26733 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
26734 + return;
26735 +#endif
26736 +
26737 vma = find_vma(mm, address);
26738 if (unlikely(!vma)) {
26739 bad_area(regs, error_code, address);
26740 @@ -1157,18 +1371,24 @@ retry:
26741 bad_area(regs, error_code, address);
26742 return;
26743 }
26744 - if (error_code & PF_USER) {
26745 - /*
26746 - * Accessing the stack below %sp is always a bug.
26747 - * The large cushion allows instructions like enter
26748 - * and pusha to work. ("enter $65535, $31" pushes
26749 - * 32 pointers and then decrements %sp by 65535.)
26750 - */
26751 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
26752 - bad_area(regs, error_code, address);
26753 - return;
26754 - }
26755 + /*
26756 + * Accessing the stack below %sp is always a bug.
26757 + * The large cushion allows instructions like enter
26758 + * and pusha to work. ("enter $65535, $31" pushes
26759 + * 32 pointers and then decrements %sp by 65535.)
26760 + */
26761 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
26762 + bad_area(regs, error_code, address);
26763 + return;
26764 }
26765 +
26766 +#ifdef CONFIG_PAX_SEGMEXEC
26767 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
26768 + bad_area(regs, error_code, address);
26769 + return;
26770 + }
26771 +#endif
26772 +
26773 if (unlikely(expand_stack(vma, address))) {
26774 bad_area(regs, error_code, address);
26775 return;
26776 @@ -1232,3 +1452,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
26777 __do_page_fault(regs, error_code);
26778 exception_exit(regs);
26779 }
26780 +
26781 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26782 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
26783 +{
26784 + struct mm_struct *mm = current->mm;
26785 + unsigned long ip = regs->ip;
26786 +
26787 + if (v8086_mode(regs))
26788 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
26789 +
26790 +#ifdef CONFIG_PAX_PAGEEXEC
26791 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
26792 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
26793 + return true;
26794 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
26795 + return true;
26796 + return false;
26797 + }
26798 +#endif
26799 +
26800 +#ifdef CONFIG_PAX_SEGMEXEC
26801 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
26802 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
26803 + return true;
26804 + return false;
26805 + }
26806 +#endif
26807 +
26808 + return false;
26809 +}
26810 +#endif
26811 +
26812 +#ifdef CONFIG_PAX_EMUTRAMP
26813 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
26814 +{
26815 + int err;
26816 +
26817 + do { /* PaX: libffi trampoline emulation */
26818 + unsigned char mov, jmp;
26819 + unsigned int addr1, addr2;
26820 +
26821 +#ifdef CONFIG_X86_64
26822 + if ((regs->ip + 9) >> 32)
26823 + break;
26824 +#endif
26825 +
26826 + err = get_user(mov, (unsigned char __user *)regs->ip);
26827 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26828 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26829 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26830 +
26831 + if (err)
26832 + break;
26833 +
26834 + if (mov == 0xB8 && jmp == 0xE9) {
26835 + regs->ax = addr1;
26836 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26837 + return 2;
26838 + }
26839 + } while (0);
26840 +
26841 + do { /* PaX: gcc trampoline emulation #1 */
26842 + unsigned char mov1, mov2;
26843 + unsigned short jmp;
26844 + unsigned int addr1, addr2;
26845 +
26846 +#ifdef CONFIG_X86_64
26847 + if ((regs->ip + 11) >> 32)
26848 + break;
26849 +#endif
26850 +
26851 + err = get_user(mov1, (unsigned char __user *)regs->ip);
26852 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26853 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
26854 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26855 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
26856 +
26857 + if (err)
26858 + break;
26859 +
26860 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
26861 + regs->cx = addr1;
26862 + regs->ax = addr2;
26863 + regs->ip = addr2;
26864 + return 2;
26865 + }
26866 + } while (0);
26867 +
26868 + do { /* PaX: gcc trampoline emulation #2 */
26869 + unsigned char mov, jmp;
26870 + unsigned int addr1, addr2;
26871 +
26872 +#ifdef CONFIG_X86_64
26873 + if ((regs->ip + 9) >> 32)
26874 + break;
26875 +#endif
26876 +
26877 + err = get_user(mov, (unsigned char __user *)regs->ip);
26878 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
26879 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
26880 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
26881 +
26882 + if (err)
26883 + break;
26884 +
26885 + if (mov == 0xB9 && jmp == 0xE9) {
26886 + regs->cx = addr1;
26887 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
26888 + return 2;
26889 + }
26890 + } while (0);
26891 +
26892 + return 1; /* PaX in action */
26893 +}
26894 +
26895 +#ifdef CONFIG_X86_64
26896 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
26897 +{
26898 + int err;
26899 +
26900 + do { /* PaX: libffi trampoline emulation */
26901 + unsigned short mov1, mov2, jmp1;
26902 + unsigned char stcclc, jmp2;
26903 + unsigned long addr1, addr2;
26904 +
26905 + err = get_user(mov1, (unsigned short __user *)regs->ip);
26906 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26907 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26908 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26909 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
26910 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
26911 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
26912 +
26913 + if (err)
26914 + break;
26915 +
26916 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26917 + regs->r11 = addr1;
26918 + regs->r10 = addr2;
26919 + if (stcclc == 0xF8)
26920 + regs->flags &= ~X86_EFLAGS_CF;
26921 + else
26922 + regs->flags |= X86_EFLAGS_CF;
26923 + regs->ip = addr1;
26924 + return 2;
26925 + }
26926 + } while (0);
26927 +
26928 + do { /* PaX: gcc trampoline emulation #1 */
26929 + unsigned short mov1, mov2, jmp1;
26930 + unsigned char jmp2;
26931 + unsigned int addr1;
26932 + unsigned long addr2;
26933 +
26934 + err = get_user(mov1, (unsigned short __user *)regs->ip);
26935 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
26936 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
26937 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
26938 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
26939 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
26940 +
26941 + if (err)
26942 + break;
26943 +
26944 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26945 + regs->r11 = addr1;
26946 + regs->r10 = addr2;
26947 + regs->ip = addr1;
26948 + return 2;
26949 + }
26950 + } while (0);
26951 +
26952 + do { /* PaX: gcc trampoline emulation #2 */
26953 + unsigned short mov1, mov2, jmp1;
26954 + unsigned char jmp2;
26955 + unsigned long addr1, addr2;
26956 +
26957 + err = get_user(mov1, (unsigned short __user *)regs->ip);
26958 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
26959 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
26960 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
26961 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
26962 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
26963 +
26964 + if (err)
26965 + break;
26966 +
26967 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
26968 + regs->r11 = addr1;
26969 + regs->r10 = addr2;
26970 + regs->ip = addr1;
26971 + return 2;
26972 + }
26973 + } while (0);
26974 +
26975 + return 1; /* PaX in action */
26976 +}
26977 +#endif
26978 +
26979 +/*
26980 + * PaX: decide what to do with offenders (regs->ip = fault address)
26981 + *
26982 + * returns 1 when task should be killed
26983 + * 2 when gcc trampoline was detected
26984 + */
26985 +static int pax_handle_fetch_fault(struct pt_regs *regs)
26986 +{
26987 + if (v8086_mode(regs))
26988 + return 1;
26989 +
26990 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
26991 + return 1;
26992 +
26993 +#ifdef CONFIG_X86_32
26994 + return pax_handle_fetch_fault_32(regs);
26995 +#else
26996 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
26997 + return pax_handle_fetch_fault_32(regs);
26998 + else
26999 + return pax_handle_fetch_fault_64(regs);
27000 +#endif
27001 +}
27002 +#endif
27003 +
27004 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27005 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27006 +{
27007 + long i;
27008 +
27009 + printk(KERN_ERR "PAX: bytes at PC: ");
27010 + for (i = 0; i < 20; i++) {
27011 + unsigned char c;
27012 + if (get_user(c, (unsigned char __force_user *)pc+i))
27013 + printk(KERN_CONT "?? ");
27014 + else
27015 + printk(KERN_CONT "%02x ", c);
27016 + }
27017 + printk("\n");
27018 +
27019 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27020 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
27021 + unsigned long c;
27022 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
27023 +#ifdef CONFIG_X86_32
27024 + printk(KERN_CONT "???????? ");
27025 +#else
27026 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27027 + printk(KERN_CONT "???????? ???????? ");
27028 + else
27029 + printk(KERN_CONT "???????????????? ");
27030 +#endif
27031 + } else {
27032 +#ifdef CONFIG_X86_64
27033 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27034 + printk(KERN_CONT "%08x ", (unsigned int)c);
27035 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27036 + } else
27037 +#endif
27038 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27039 + }
27040 + }
27041 + printk("\n");
27042 +}
27043 +#endif
27044 +
27045 +/**
27046 + * probe_kernel_write(): safely attempt to write to a location
27047 + * @dst: address to write to
27048 + * @src: pointer to the data that shall be written
27049 + * @size: size of the data chunk
27050 + *
27051 + * Safely write to address @dst from the buffer at @src. If a kernel fault
27052 + * happens, handle that and return -EFAULT.
27053 + */
27054 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27055 +{
27056 + long ret;
27057 + mm_segment_t old_fs = get_fs();
27058 +
27059 + set_fs(KERNEL_DS);
27060 + pagefault_disable();
27061 + pax_open_kernel();
27062 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27063 + pax_close_kernel();
27064 + pagefault_enable();
27065 + set_fs(old_fs);
27066 +
27067 + return ret ? -EFAULT : 0;
27068 +}
27069 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27070 index dd74e46..7d26398 100644
27071 --- a/arch/x86/mm/gup.c
27072 +++ b/arch/x86/mm/gup.c
27073 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27074 addr = start;
27075 len = (unsigned long) nr_pages << PAGE_SHIFT;
27076 end = start + len;
27077 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27078 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27079 (void __user *)start, len)))
27080 return 0;
27081
27082 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27083 index 6f31ee5..8ee4164 100644
27084 --- a/arch/x86/mm/highmem_32.c
27085 +++ b/arch/x86/mm/highmem_32.c
27086 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27087 idx = type + KM_TYPE_NR*smp_processor_id();
27088 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27089 BUG_ON(!pte_none(*(kmap_pte-idx)));
27090 +
27091 + pax_open_kernel();
27092 set_pte(kmap_pte-idx, mk_pte(page, prot));
27093 + pax_close_kernel();
27094 +
27095 arch_flush_lazy_mmu_mode();
27096
27097 return (void *)vaddr;
27098 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27099 index ae1aa71..56316db 100644
27100 --- a/arch/x86/mm/hugetlbpage.c
27101 +++ b/arch/x86/mm/hugetlbpage.c
27102 @@ -279,6 +279,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27103 info.flags = 0;
27104 info.length = len;
27105 info.low_limit = TASK_UNMAPPED_BASE;
27106 +
27107 +#ifdef CONFIG_PAX_RANDMMAP
27108 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27109 + info.low_limit += current->mm->delta_mmap;
27110 +#endif
27111 +
27112 info.high_limit = TASK_SIZE;
27113 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
27114 info.align_offset = 0;
27115 @@ -311,6 +317,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
27116 VM_BUG_ON(addr != -ENOMEM);
27117 info.flags = 0;
27118 info.low_limit = TASK_UNMAPPED_BASE;
27119 +
27120 +#ifdef CONFIG_PAX_RANDMMAP
27121 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27122 + info.low_limit += current->mm->delta_mmap;
27123 +#endif
27124 +
27125 info.high_limit = TASK_SIZE;
27126 addr = vm_unmapped_area(&info);
27127 }
27128 @@ -325,10 +337,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27129 struct hstate *h = hstate_file(file);
27130 struct mm_struct *mm = current->mm;
27131 struct vm_area_struct *vma;
27132 + unsigned long pax_task_size = TASK_SIZE;
27133 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
27134
27135 if (len & ~huge_page_mask(h))
27136 return -EINVAL;
27137 - if (len > TASK_SIZE)
27138 +
27139 +#ifdef CONFIG_PAX_SEGMEXEC
27140 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27141 + pax_task_size = SEGMEXEC_TASK_SIZE;
27142 +#endif
27143 +
27144 + pax_task_size -= PAGE_SIZE;
27145 +
27146 + if (len > pax_task_size)
27147 return -ENOMEM;
27148
27149 if (flags & MAP_FIXED) {
27150 @@ -337,11 +359,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
27151 return addr;
27152 }
27153
27154 +#ifdef CONFIG_PAX_RANDMMAP
27155 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27156 +#endif
27157 +
27158 if (addr) {
27159 addr = ALIGN(addr, huge_page_size(h));
27160 vma = find_vma(mm, addr);
27161 - if (TASK_SIZE - len >= addr &&
27162 - (!vma || addr + len <= vma->vm_start))
27163 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27164 return addr;
27165 }
27166 if (mm->get_unmapped_area == arch_get_unmapped_area)
27167 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
27168 index d7aea41..0fc945b 100644
27169 --- a/arch/x86/mm/init.c
27170 +++ b/arch/x86/mm/init.c
27171 @@ -4,6 +4,7 @@
27172 #include <linux/swap.h>
27173 #include <linux/memblock.h>
27174 #include <linux/bootmem.h> /* for max_low_pfn */
27175 +#include <linux/tboot.h>
27176
27177 #include <asm/cacheflush.h>
27178 #include <asm/e820.h>
27179 @@ -16,6 +17,8 @@
27180 #include <asm/tlb.h>
27181 #include <asm/proto.h>
27182 #include <asm/dma.h> /* for MAX_DMA_PFN */
27183 +#include <asm/desc.h>
27184 +#include <asm/bios_ebda.h>
27185
27186 unsigned long __initdata pgt_buf_start;
27187 unsigned long __meminitdata pgt_buf_end;
27188 @@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
27189 {
27190 int i;
27191 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
27192 - unsigned long start = 0, good_end;
27193 + unsigned long start = 0x100000, good_end;
27194 phys_addr_t base;
27195
27196 for (i = 0; i < nr_range; i++) {
27197 @@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
27198 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
27199 * mmio resources as well as potential bios/acpi data regions.
27200 */
27201 +
27202 +#ifdef CONFIG_GRKERNSEC_KMEM
27203 +static unsigned int ebda_start __read_only;
27204 +static unsigned int ebda_end __read_only;
27205 +#endif
27206 +
27207 int devmem_is_allowed(unsigned long pagenr)
27208 {
27209 - if (pagenr < 256)
27210 +#ifdef CONFIG_GRKERNSEC_KMEM
27211 + /* allow BDA */
27212 + if (!pagenr)
27213 return 1;
27214 + /* allow EBDA */
27215 + if (pagenr >= ebda_start && pagenr < ebda_end)
27216 + return 1;
27217 + /* if tboot is in use, allow access to its hardcoded serial log range */
27218 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
27219 + return 1;
27220 +#else
27221 + if (!pagenr)
27222 + return 1;
27223 +#ifdef CONFIG_VM86
27224 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
27225 + return 1;
27226 +#endif
27227 +#endif
27228 +
27229 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
27230 + return 1;
27231 +#ifdef CONFIG_GRKERNSEC_KMEM
27232 + /* throw out everything else below 1MB */
27233 + if (pagenr <= 256)
27234 + return 0;
27235 +#endif
27236 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
27237 return 0;
27238 if (!page_is_ram(pagenr))
27239 @@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
27240 #endif
27241 }
27242
27243 +#ifdef CONFIG_GRKERNSEC_KMEM
27244 +static inline void gr_init_ebda(void)
27245 +{
27246 + unsigned int ebda_addr;
27247 + unsigned int ebda_size = 0;
27248 +
27249 + ebda_addr = get_bios_ebda();
27250 + if (ebda_addr) {
27251 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
27252 + ebda_size <<= 10;
27253 + }
27254 + if (ebda_addr && ebda_size) {
27255 + ebda_start = ebda_addr >> PAGE_SHIFT;
27256 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
27257 + } else {
27258 + ebda_start = 0x9f000 >> PAGE_SHIFT;
27259 + ebda_end = 0xa0000 >> PAGE_SHIFT;
27260 + }
27261 +}
27262 +#else
27263 +static inline void gr_init_ebda(void) { }
27264 +#endif
27265 +
27266 void free_initmem(void)
27267 {
27268 +#ifdef CONFIG_PAX_KERNEXEC
27269 +#ifdef CONFIG_X86_32
27270 + /* PaX: limit KERNEL_CS to actual size */
27271 + unsigned long addr, limit;
27272 + struct desc_struct d;
27273 + int cpu;
27274 +#else
27275 + pgd_t *pgd;
27276 + pud_t *pud;
27277 + pmd_t *pmd;
27278 + unsigned long addr, end;
27279 +#endif
27280 +#endif
27281 +
27282 + gr_init_ebda();
27283 +
27284 +#ifdef CONFIG_PAX_KERNEXEC
27285 +#ifdef CONFIG_X86_32
27286 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
27287 + limit = (limit - 1UL) >> PAGE_SHIFT;
27288 +
27289 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
27290 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27291 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
27292 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
27293 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
27294 + }
27295 +
27296 + /* PaX: make KERNEL_CS read-only */
27297 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
27298 + if (!paravirt_enabled())
27299 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
27300 +/*
27301 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
27302 + pgd = pgd_offset_k(addr);
27303 + pud = pud_offset(pgd, addr);
27304 + pmd = pmd_offset(pud, addr);
27305 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27306 + }
27307 +*/
27308 +#ifdef CONFIG_X86_PAE
27309 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
27310 +/*
27311 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
27312 + pgd = pgd_offset_k(addr);
27313 + pud = pud_offset(pgd, addr);
27314 + pmd = pmd_offset(pud, addr);
27315 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27316 + }
27317 +*/
27318 +#endif
27319 +
27320 +#ifdef CONFIG_MODULES
27321 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
27322 +#endif
27323 +
27324 +#else
27325 + /* PaX: make kernel code/rodata read-only, rest non-executable */
27326 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
27327 + pgd = pgd_offset_k(addr);
27328 + pud = pud_offset(pgd, addr);
27329 + pmd = pmd_offset(pud, addr);
27330 + if (!pmd_present(*pmd))
27331 + continue;
27332 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
27333 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27334 + else
27335 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
27336 + }
27337 +
27338 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
27339 + end = addr + KERNEL_IMAGE_SIZE;
27340 + for (; addr < end; addr += PMD_SIZE) {
27341 + pgd = pgd_offset_k(addr);
27342 + pud = pud_offset(pgd, addr);
27343 + pmd = pmd_offset(pud, addr);
27344 + if (!pmd_present(*pmd))
27345 + continue;
27346 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
27347 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
27348 + }
27349 +#endif
27350 +
27351 + flush_tlb_all();
27352 +#endif
27353 +
27354 free_init_pages("unused kernel memory",
27355 (unsigned long)(&__init_begin),
27356 (unsigned long)(&__init_end));
27357 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
27358 index 745d66b..56bf568 100644
27359 --- a/arch/x86/mm/init_32.c
27360 +++ b/arch/x86/mm/init_32.c
27361 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
27362 }
27363
27364 /*
27365 - * Creates a middle page table and puts a pointer to it in the
27366 - * given global directory entry. This only returns the gd entry
27367 - * in non-PAE compilation mode, since the middle layer is folded.
27368 - */
27369 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
27370 -{
27371 - pud_t *pud;
27372 - pmd_t *pmd_table;
27373 -
27374 -#ifdef CONFIG_X86_PAE
27375 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
27376 - if (after_bootmem)
27377 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
27378 - else
27379 - pmd_table = (pmd_t *)alloc_low_page();
27380 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
27381 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
27382 - pud = pud_offset(pgd, 0);
27383 - BUG_ON(pmd_table != pmd_offset(pud, 0));
27384 -
27385 - return pmd_table;
27386 - }
27387 -#endif
27388 - pud = pud_offset(pgd, 0);
27389 - pmd_table = pmd_offset(pud, 0);
27390 -
27391 - return pmd_table;
27392 -}
27393 -
27394 -/*
27395 * Create a page table and place a pointer to it in a middle page
27396 * directory entry:
27397 */
27398 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
27399 page_table = (pte_t *)alloc_low_page();
27400
27401 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
27402 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27403 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
27404 +#else
27405 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
27406 +#endif
27407 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
27408 }
27409
27410 return pte_offset_kernel(pmd, 0);
27411 }
27412
27413 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
27414 +{
27415 + pud_t *pud;
27416 + pmd_t *pmd_table;
27417 +
27418 + pud = pud_offset(pgd, 0);
27419 + pmd_table = pmd_offset(pud, 0);
27420 +
27421 + return pmd_table;
27422 +}
27423 +
27424 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
27425 {
27426 int pgd_idx = pgd_index(vaddr);
27427 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27428 int pgd_idx, pmd_idx;
27429 unsigned long vaddr;
27430 pgd_t *pgd;
27431 + pud_t *pud;
27432 pmd_t *pmd;
27433 pte_t *pte = NULL;
27434
27435 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27436 pgd = pgd_base + pgd_idx;
27437
27438 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
27439 - pmd = one_md_table_init(pgd);
27440 - pmd = pmd + pmd_index(vaddr);
27441 + pud = pud_offset(pgd, vaddr);
27442 + pmd = pmd_offset(pud, vaddr);
27443 +
27444 +#ifdef CONFIG_X86_PAE
27445 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27446 +#endif
27447 +
27448 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
27449 pmd++, pmd_idx++) {
27450 pte = page_table_kmap_check(one_page_table_init(pmd),
27451 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
27452 }
27453 }
27454
27455 -static inline int is_kernel_text(unsigned long addr)
27456 +static inline int is_kernel_text(unsigned long start, unsigned long end)
27457 {
27458 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
27459 - return 1;
27460 - return 0;
27461 + if ((start > ktla_ktva((unsigned long)_etext) ||
27462 + end <= ktla_ktva((unsigned long)_stext)) &&
27463 + (start > ktla_ktva((unsigned long)_einittext) ||
27464 + end <= ktla_ktva((unsigned long)_sinittext)) &&
27465 +
27466 +#ifdef CONFIG_ACPI_SLEEP
27467 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
27468 +#endif
27469 +
27470 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
27471 + return 0;
27472 + return 1;
27473 }
27474
27475 /*
27476 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
27477 unsigned long last_map_addr = end;
27478 unsigned long start_pfn, end_pfn;
27479 pgd_t *pgd_base = swapper_pg_dir;
27480 - int pgd_idx, pmd_idx, pte_ofs;
27481 + unsigned int pgd_idx, pmd_idx, pte_ofs;
27482 unsigned long pfn;
27483 pgd_t *pgd;
27484 + pud_t *pud;
27485 pmd_t *pmd;
27486 pte_t *pte;
27487 unsigned pages_2m, pages_4k;
27488 @@ -280,8 +281,13 @@ repeat:
27489 pfn = start_pfn;
27490 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27491 pgd = pgd_base + pgd_idx;
27492 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
27493 - pmd = one_md_table_init(pgd);
27494 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
27495 + pud = pud_offset(pgd, 0);
27496 + pmd = pmd_offset(pud, 0);
27497 +
27498 +#ifdef CONFIG_X86_PAE
27499 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
27500 +#endif
27501
27502 if (pfn >= end_pfn)
27503 continue;
27504 @@ -293,14 +299,13 @@ repeat:
27505 #endif
27506 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
27507 pmd++, pmd_idx++) {
27508 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
27509 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
27510
27511 /*
27512 * Map with big pages if possible, otherwise
27513 * create normal page tables:
27514 */
27515 if (use_pse) {
27516 - unsigned int addr2;
27517 pgprot_t prot = PAGE_KERNEL_LARGE;
27518 /*
27519 * first pass will use the same initial
27520 @@ -310,11 +315,7 @@ repeat:
27521 __pgprot(PTE_IDENT_ATTR |
27522 _PAGE_PSE);
27523
27524 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
27525 - PAGE_OFFSET + PAGE_SIZE-1;
27526 -
27527 - if (is_kernel_text(addr) ||
27528 - is_kernel_text(addr2))
27529 + if (is_kernel_text(address, address + PMD_SIZE))
27530 prot = PAGE_KERNEL_LARGE_EXEC;
27531
27532 pages_2m++;
27533 @@ -331,7 +332,7 @@ repeat:
27534 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
27535 pte += pte_ofs;
27536 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
27537 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
27538 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
27539 pgprot_t prot = PAGE_KERNEL;
27540 /*
27541 * first pass will use the same initial
27542 @@ -339,7 +340,7 @@ repeat:
27543 */
27544 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
27545
27546 - if (is_kernel_text(addr))
27547 + if (is_kernel_text(address, address + PAGE_SIZE))
27548 prot = PAGE_KERNEL_EXEC;
27549
27550 pages_4k++;
27551 @@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
27552
27553 pud = pud_offset(pgd, va);
27554 pmd = pmd_offset(pud, va);
27555 - if (!pmd_present(*pmd))
27556 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
27557 break;
27558
27559 pte = pte_offset_kernel(pmd, va);
27560 @@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
27561
27562 static void __init pagetable_init(void)
27563 {
27564 - pgd_t *pgd_base = swapper_pg_dir;
27565 -
27566 - permanent_kmaps_init(pgd_base);
27567 + permanent_kmaps_init(swapper_pg_dir);
27568 }
27569
27570 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27571 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
27572 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27573
27574 /* user-defined highmem size */
27575 @@ -728,6 +727,12 @@ void __init mem_init(void)
27576
27577 pci_iommu_alloc();
27578
27579 +#ifdef CONFIG_PAX_PER_CPU_PGD
27580 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27581 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27582 + KERNEL_PGD_PTRS);
27583 +#endif
27584 +
27585 #ifdef CONFIG_FLATMEM
27586 BUG_ON(!mem_map);
27587 #endif
27588 @@ -754,7 +759,7 @@ void __init mem_init(void)
27589 reservedpages++;
27590
27591 codesize = (unsigned long) &_etext - (unsigned long) &_text;
27592 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
27593 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
27594 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
27595
27596 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
27597 @@ -795,10 +800,10 @@ void __init mem_init(void)
27598 ((unsigned long)&__init_end -
27599 (unsigned long)&__init_begin) >> 10,
27600
27601 - (unsigned long)&_etext, (unsigned long)&_edata,
27602 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
27603 + (unsigned long)&_sdata, (unsigned long)&_edata,
27604 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
27605
27606 - (unsigned long)&_text, (unsigned long)&_etext,
27607 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
27608 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
27609
27610 /*
27611 @@ -876,6 +881,7 @@ void set_kernel_text_rw(void)
27612 if (!kernel_set_to_readonly)
27613 return;
27614
27615 + start = ktla_ktva(start);
27616 pr_debug("Set kernel text: %lx - %lx for read write\n",
27617 start, start+size);
27618
27619 @@ -890,6 +896,7 @@ void set_kernel_text_ro(void)
27620 if (!kernel_set_to_readonly)
27621 return;
27622
27623 + start = ktla_ktva(start);
27624 pr_debug("Set kernel text: %lx - %lx for read only\n",
27625 start, start+size);
27626
27627 @@ -918,6 +925,7 @@ void mark_rodata_ro(void)
27628 unsigned long start = PFN_ALIGN(_text);
27629 unsigned long size = PFN_ALIGN(_etext) - start;
27630
27631 + start = ktla_ktva(start);
27632 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
27633 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
27634 size >> 10);
27635 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
27636 index 75c9a6a..498d677 100644
27637 --- a/arch/x86/mm/init_64.c
27638 +++ b/arch/x86/mm/init_64.c
27639 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
27640 * around without checking the pgd every time.
27641 */
27642
27643 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
27644 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
27645 EXPORT_SYMBOL_GPL(__supported_pte_mask);
27646
27647 int force_personality32;
27648 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27649
27650 for (address = start; address <= end; address += PGDIR_SIZE) {
27651 const pgd_t *pgd_ref = pgd_offset_k(address);
27652 +
27653 +#ifdef CONFIG_PAX_PER_CPU_PGD
27654 + unsigned long cpu;
27655 +#else
27656 struct page *page;
27657 +#endif
27658
27659 if (pgd_none(*pgd_ref))
27660 continue;
27661
27662 spin_lock(&pgd_lock);
27663 +
27664 +#ifdef CONFIG_PAX_PER_CPU_PGD
27665 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27666 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
27667 +#else
27668 list_for_each_entry(page, &pgd_list, lru) {
27669 pgd_t *pgd;
27670 spinlock_t *pgt_lock;
27671 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27672 /* the pgt_lock only for Xen */
27673 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27674 spin_lock(pgt_lock);
27675 +#endif
27676
27677 if (pgd_none(*pgd))
27678 set_pgd(pgd, *pgd_ref);
27679 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
27680 BUG_ON(pgd_page_vaddr(*pgd)
27681 != pgd_page_vaddr(*pgd_ref));
27682
27683 +#ifndef CONFIG_PAX_PER_CPU_PGD
27684 spin_unlock(pgt_lock);
27685 +#endif
27686 +
27687 }
27688 spin_unlock(&pgd_lock);
27689 }
27690 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
27691 {
27692 if (pgd_none(*pgd)) {
27693 pud_t *pud = (pud_t *)spp_getpage();
27694 - pgd_populate(&init_mm, pgd, pud);
27695 + pgd_populate_kernel(&init_mm, pgd, pud);
27696 if (pud != pud_offset(pgd, 0))
27697 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
27698 pud, pud_offset(pgd, 0));
27699 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
27700 {
27701 if (pud_none(*pud)) {
27702 pmd_t *pmd = (pmd_t *) spp_getpage();
27703 - pud_populate(&init_mm, pud, pmd);
27704 + pud_populate_kernel(&init_mm, pud, pmd);
27705 if (pmd != pmd_offset(pud, 0))
27706 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
27707 pmd, pmd_offset(pud, 0));
27708 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
27709 pmd = fill_pmd(pud, vaddr);
27710 pte = fill_pte(pmd, vaddr);
27711
27712 + pax_open_kernel();
27713 set_pte(pte, new_pte);
27714 + pax_close_kernel();
27715
27716 /*
27717 * It's enough to flush this one mapping.
27718 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
27719 pgd = pgd_offset_k((unsigned long)__va(phys));
27720 if (pgd_none(*pgd)) {
27721 pud = (pud_t *) spp_getpage();
27722 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
27723 - _PAGE_USER));
27724 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
27725 }
27726 pud = pud_offset(pgd, (unsigned long)__va(phys));
27727 if (pud_none(*pud)) {
27728 pmd = (pmd_t *) spp_getpage();
27729 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
27730 - _PAGE_USER));
27731 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
27732 }
27733 pmd = pmd_offset(pud, phys);
27734 BUG_ON(!pmd_none(*pmd));
27735 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
27736 if (pfn >= pgt_buf_top)
27737 panic("alloc_low_page: ran out of memory");
27738
27739 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27740 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
27741 clear_page(adr);
27742 *phys = pfn * PAGE_SIZE;
27743 return adr;
27744 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
27745
27746 phys = __pa(virt);
27747 left = phys & (PAGE_SIZE - 1);
27748 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27749 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
27750 adr = (void *)(((unsigned long)adr) | left);
27751
27752 return adr;
27753 @@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
27754 unmap_low_page(pmd);
27755
27756 spin_lock(&init_mm.page_table_lock);
27757 - pud_populate(&init_mm, pud, __va(pmd_phys));
27758 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
27759 spin_unlock(&init_mm.page_table_lock);
27760 }
27761 __flush_tlb_all();
27762 @@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
27763 unmap_low_page(pud);
27764
27765 spin_lock(&init_mm.page_table_lock);
27766 - pgd_populate(&init_mm, pgd, __va(pud_phys));
27767 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
27768 spin_unlock(&init_mm.page_table_lock);
27769 pgd_changed = true;
27770 }
27771 @@ -693,6 +707,12 @@ void __init mem_init(void)
27772
27773 pci_iommu_alloc();
27774
27775 +#ifdef CONFIG_PAX_PER_CPU_PGD
27776 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
27777 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27778 + KERNEL_PGD_PTRS);
27779 +#endif
27780 +
27781 /* clear_bss() already clear the empty_zero_page */
27782
27783 reservedpages = 0;
27784 @@ -856,8 +876,8 @@ int kern_addr_valid(unsigned long addr)
27785 static struct vm_area_struct gate_vma = {
27786 .vm_start = VSYSCALL_START,
27787 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
27788 - .vm_page_prot = PAGE_READONLY_EXEC,
27789 - .vm_flags = VM_READ | VM_EXEC
27790 + .vm_page_prot = PAGE_READONLY,
27791 + .vm_flags = VM_READ
27792 };
27793
27794 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27795 @@ -891,7 +911,7 @@ int in_gate_area_no_mm(unsigned long addr)
27796
27797 const char *arch_vma_name(struct vm_area_struct *vma)
27798 {
27799 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27800 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27801 return "[vdso]";
27802 if (vma == &gate_vma)
27803 return "[vsyscall]";
27804 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
27805 index 7b179b4..6bd1777 100644
27806 --- a/arch/x86/mm/iomap_32.c
27807 +++ b/arch/x86/mm/iomap_32.c
27808 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
27809 type = kmap_atomic_idx_push();
27810 idx = type + KM_TYPE_NR * smp_processor_id();
27811 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27812 +
27813 + pax_open_kernel();
27814 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
27815 + pax_close_kernel();
27816 +
27817 arch_flush_lazy_mmu_mode();
27818
27819 return (void *)vaddr;
27820 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
27821 index 78fe3f1..2f9433c 100644
27822 --- a/arch/x86/mm/ioremap.c
27823 +++ b/arch/x86/mm/ioremap.c
27824 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
27825 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
27826 int is_ram = page_is_ram(pfn);
27827
27828 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
27829 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
27830 return NULL;
27831 WARN_ON_ONCE(is_ram);
27832 }
27833 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
27834 *
27835 * Caller must ensure there is only one unmapping for the same pointer.
27836 */
27837 -void iounmap(volatile void __iomem *addr)
27838 +void iounmap(const volatile void __iomem *addr)
27839 {
27840 struct vm_struct *p, *o;
27841
27842 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
27843
27844 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
27845 if (page_is_ram(start >> PAGE_SHIFT))
27846 +#ifdef CONFIG_HIGHMEM
27847 + if ((start >> PAGE_SHIFT) < max_low_pfn)
27848 +#endif
27849 return __va(phys);
27850
27851 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
27852 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
27853 early_param("early_ioremap_debug", early_ioremap_debug_setup);
27854
27855 static __initdata int after_paging_init;
27856 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
27857 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
27858
27859 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
27860 {
27861 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
27862 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
27863
27864 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
27865 - memset(bm_pte, 0, sizeof(bm_pte));
27866 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
27867 + pmd_populate_user(&init_mm, pmd, bm_pte);
27868
27869 /*
27870 * The boot-ioremap range spans multiple pmds, for which
27871 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
27872 index d87dd6d..bf3fa66 100644
27873 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
27874 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
27875 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
27876 * memory (e.g. tracked pages)? For now, we need this to avoid
27877 * invoking kmemcheck for PnP BIOS calls.
27878 */
27879 - if (regs->flags & X86_VM_MASK)
27880 + if (v8086_mode(regs))
27881 return false;
27882 - if (regs->cs != __KERNEL_CS)
27883 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
27884 return false;
27885
27886 pte = kmemcheck_pte_lookup(address);
27887 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
27888 index 845df68..1d8d29f 100644
27889 --- a/arch/x86/mm/mmap.c
27890 +++ b/arch/x86/mm/mmap.c
27891 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
27892 * Leave an at least ~128 MB hole with possible stack randomization.
27893 */
27894 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
27895 -#define MAX_GAP (TASK_SIZE/6*5)
27896 +#define MAX_GAP (pax_task_size/6*5)
27897
27898 static int mmap_is_legacy(void)
27899 {
27900 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
27901 return rnd << PAGE_SHIFT;
27902 }
27903
27904 -static unsigned long mmap_base(void)
27905 +static unsigned long mmap_base(struct mm_struct *mm)
27906 {
27907 unsigned long gap = rlimit(RLIMIT_STACK);
27908 + unsigned long pax_task_size = TASK_SIZE;
27909 +
27910 +#ifdef CONFIG_PAX_SEGMEXEC
27911 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27912 + pax_task_size = SEGMEXEC_TASK_SIZE;
27913 +#endif
27914
27915 if (gap < MIN_GAP)
27916 gap = MIN_GAP;
27917 else if (gap > MAX_GAP)
27918 gap = MAX_GAP;
27919
27920 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
27921 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
27922 }
27923
27924 /*
27925 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
27926 * does, but not when emulating X86_32
27927 */
27928 -static unsigned long mmap_legacy_base(void)
27929 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
27930 {
27931 - if (mmap_is_ia32())
27932 + if (mmap_is_ia32()) {
27933 +
27934 +#ifdef CONFIG_PAX_SEGMEXEC
27935 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27936 + return SEGMEXEC_TASK_UNMAPPED_BASE;
27937 + else
27938 +#endif
27939 +
27940 return TASK_UNMAPPED_BASE;
27941 - else
27942 + } else
27943 return TASK_UNMAPPED_BASE + mmap_rnd();
27944 }
27945
27946 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
27947 void arch_pick_mmap_layout(struct mm_struct *mm)
27948 {
27949 if (mmap_is_legacy()) {
27950 - mm->mmap_base = mmap_legacy_base();
27951 + mm->mmap_base = mmap_legacy_base(mm);
27952 +
27953 +#ifdef CONFIG_PAX_RANDMMAP
27954 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27955 + mm->mmap_base += mm->delta_mmap;
27956 +#endif
27957 +
27958 mm->get_unmapped_area = arch_get_unmapped_area;
27959 mm->unmap_area = arch_unmap_area;
27960 } else {
27961 - mm->mmap_base = mmap_base();
27962 + mm->mmap_base = mmap_base(mm);
27963 +
27964 +#ifdef CONFIG_PAX_RANDMMAP
27965 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27966 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
27967 +#endif
27968 +
27969 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
27970 mm->unmap_area = arch_unmap_area_topdown;
27971 }
27972 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
27973 index dc0b727..f612039 100644
27974 --- a/arch/x86/mm/mmio-mod.c
27975 +++ b/arch/x86/mm/mmio-mod.c
27976 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
27977 break;
27978 default:
27979 {
27980 - unsigned char *ip = (unsigned char *)instptr;
27981 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
27982 my_trace->opcode = MMIO_UNKNOWN_OP;
27983 my_trace->width = 0;
27984 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
27985 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
27986 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27987 void __iomem *addr)
27988 {
27989 - static atomic_t next_id;
27990 + static atomic_unchecked_t next_id;
27991 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
27992 /* These are page-unaligned. */
27993 struct mmiotrace_map map = {
27994 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
27995 .private = trace
27996 },
27997 .phys = offset,
27998 - .id = atomic_inc_return(&next_id)
27999 + .id = atomic_inc_return_unchecked(&next_id)
28000 };
28001 map.map_id = trace->id;
28002
28003 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28004 ioremap_trace_core(offset, size, addr);
28005 }
28006
28007 -static void iounmap_trace_core(volatile void __iomem *addr)
28008 +static void iounmap_trace_core(const volatile void __iomem *addr)
28009 {
28010 struct mmiotrace_map map = {
28011 .phys = 0,
28012 @@ -328,7 +328,7 @@ not_enabled:
28013 }
28014 }
28015
28016 -void mmiotrace_iounmap(volatile void __iomem *addr)
28017 +void mmiotrace_iounmap(const volatile void __iomem *addr)
28018 {
28019 might_sleep();
28020 if (is_enabled()) /* recheck and proper locking in *_core() */
28021 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28022 index b008656..773eac2 100644
28023 --- a/arch/x86/mm/pageattr-test.c
28024 +++ b/arch/x86/mm/pageattr-test.c
28025 @@ -36,7 +36,7 @@ enum {
28026
28027 static int pte_testbit(pte_t pte)
28028 {
28029 - return pte_flags(pte) & _PAGE_UNUSED1;
28030 + return pte_flags(pte) & _PAGE_CPA_TEST;
28031 }
28032
28033 struct split_state {
28034 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28035 index a718e0d..77419bc 100644
28036 --- a/arch/x86/mm/pageattr.c
28037 +++ b/arch/x86/mm/pageattr.c
28038 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28039 */
28040 #ifdef CONFIG_PCI_BIOS
28041 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28042 - pgprot_val(forbidden) |= _PAGE_NX;
28043 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28044 #endif
28045
28046 /*
28047 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28048 * Does not cover __inittext since that is gone later on. On
28049 * 64bit we do not enforce !NX on the low mapping
28050 */
28051 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
28052 - pgprot_val(forbidden) |= _PAGE_NX;
28053 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28054 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28055
28056 +#ifdef CONFIG_DEBUG_RODATA
28057 /*
28058 * The .rodata section needs to be read-only. Using the pfn
28059 * catches all aliases.
28060 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28061 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
28062 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
28063 pgprot_val(forbidden) |= _PAGE_RW;
28064 +#endif
28065
28066 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28067 /*
28068 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28069 }
28070 #endif
28071
28072 +#ifdef CONFIG_PAX_KERNEXEC
28073 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28074 + pgprot_val(forbidden) |= _PAGE_RW;
28075 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28076 + }
28077 +#endif
28078 +
28079 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28080
28081 return prot;
28082 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
28083 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28084 {
28085 /* change init_mm */
28086 + pax_open_kernel();
28087 set_pte_atomic(kpte, pte);
28088 +
28089 #ifdef CONFIG_X86_32
28090 if (!SHARED_KERNEL_PMD) {
28091 +
28092 +#ifdef CONFIG_PAX_PER_CPU_PGD
28093 + unsigned long cpu;
28094 +#else
28095 struct page *page;
28096 +#endif
28097
28098 +#ifdef CONFIG_PAX_PER_CPU_PGD
28099 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28100 + pgd_t *pgd = get_cpu_pgd(cpu);
28101 +#else
28102 list_for_each_entry(page, &pgd_list, lru) {
28103 - pgd_t *pgd;
28104 + pgd_t *pgd = (pgd_t *)page_address(page);
28105 +#endif
28106 +
28107 pud_t *pud;
28108 pmd_t *pmd;
28109
28110 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
28111 + pgd += pgd_index(address);
28112 pud = pud_offset(pgd, address);
28113 pmd = pmd_offset(pud, address);
28114 set_pte_atomic((pte_t *)pmd, pte);
28115 }
28116 }
28117 #endif
28118 + pax_close_kernel();
28119 }
28120
28121 static int
28122 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
28123 index 0eb572e..92f5c1e 100644
28124 --- a/arch/x86/mm/pat.c
28125 +++ b/arch/x86/mm/pat.c
28126 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
28127
28128 if (!entry) {
28129 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
28130 - current->comm, current->pid, start, end - 1);
28131 + current->comm, task_pid_nr(current), start, end - 1);
28132 return -EINVAL;
28133 }
28134
28135 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
28136
28137 while (cursor < to) {
28138 if (!devmem_is_allowed(pfn)) {
28139 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
28140 - current->comm, from, to - 1);
28141 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
28142 + current->comm, from, to - 1, cursor);
28143 return 0;
28144 }
28145 cursor += PAGE_SIZE;
28146 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
28147 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
28148 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
28149 "for [mem %#010Lx-%#010Lx]\n",
28150 - current->comm, current->pid,
28151 + current->comm, task_pid_nr(current),
28152 cattr_name(flags),
28153 base, (unsigned long long)(base + size-1));
28154 return -EINVAL;
28155 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28156 flags = lookup_memtype(paddr);
28157 if (want_flags != flags) {
28158 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
28159 - current->comm, current->pid,
28160 + current->comm, task_pid_nr(current),
28161 cattr_name(want_flags),
28162 (unsigned long long)paddr,
28163 (unsigned long long)(paddr + size - 1),
28164 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
28165 free_memtype(paddr, paddr + size);
28166 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
28167 " for [mem %#010Lx-%#010Lx], got %s\n",
28168 - current->comm, current->pid,
28169 + current->comm, task_pid_nr(current),
28170 cattr_name(want_flags),
28171 (unsigned long long)paddr,
28172 (unsigned long long)(paddr + size - 1),
28173 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
28174 index 9f0614d..92ae64a 100644
28175 --- a/arch/x86/mm/pf_in.c
28176 +++ b/arch/x86/mm/pf_in.c
28177 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
28178 int i;
28179 enum reason_type rv = OTHERS;
28180
28181 - p = (unsigned char *)ins_addr;
28182 + p = (unsigned char *)ktla_ktva(ins_addr);
28183 p += skip_prefix(p, &prf);
28184 p += get_opcode(p, &opcode);
28185
28186 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
28187 struct prefix_bits prf;
28188 int i;
28189
28190 - p = (unsigned char *)ins_addr;
28191 + p = (unsigned char *)ktla_ktva(ins_addr);
28192 p += skip_prefix(p, &prf);
28193 p += get_opcode(p, &opcode);
28194
28195 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
28196 struct prefix_bits prf;
28197 int i;
28198
28199 - p = (unsigned char *)ins_addr;
28200 + p = (unsigned char *)ktla_ktva(ins_addr);
28201 p += skip_prefix(p, &prf);
28202 p += get_opcode(p, &opcode);
28203
28204 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
28205 struct prefix_bits prf;
28206 int i;
28207
28208 - p = (unsigned char *)ins_addr;
28209 + p = (unsigned char *)ktla_ktva(ins_addr);
28210 p += skip_prefix(p, &prf);
28211 p += get_opcode(p, &opcode);
28212 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
28213 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
28214 struct prefix_bits prf;
28215 int i;
28216
28217 - p = (unsigned char *)ins_addr;
28218 + p = (unsigned char *)ktla_ktva(ins_addr);
28219 p += skip_prefix(p, &prf);
28220 p += get_opcode(p, &opcode);
28221 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
28222 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
28223 index e27fbf8..8b56dc9 100644
28224 --- a/arch/x86/mm/pgtable.c
28225 +++ b/arch/x86/mm/pgtable.c
28226 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
28227 list_del(&page->lru);
28228 }
28229
28230 -#define UNSHARED_PTRS_PER_PGD \
28231 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28232 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28233 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
28234
28235 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
28236 +{
28237 + unsigned int count = USER_PGD_PTRS;
28238
28239 + while (count--)
28240 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
28241 +}
28242 +#endif
28243 +
28244 +#ifdef CONFIG_PAX_PER_CPU_PGD
28245 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
28246 +{
28247 + unsigned int count = USER_PGD_PTRS;
28248 +
28249 + while (count--) {
28250 + pgd_t pgd;
28251 +
28252 +#ifdef CONFIG_X86_64
28253 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
28254 +#else
28255 + pgd = *src++;
28256 +#endif
28257 +
28258 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28259 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
28260 +#endif
28261 +
28262 + *dst++ = pgd;
28263 + }
28264 +
28265 +}
28266 +#endif
28267 +
28268 +#ifdef CONFIG_X86_64
28269 +#define pxd_t pud_t
28270 +#define pyd_t pgd_t
28271 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
28272 +#define pxd_free(mm, pud) pud_free((mm), (pud))
28273 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
28274 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
28275 +#define PYD_SIZE PGDIR_SIZE
28276 +#else
28277 +#define pxd_t pmd_t
28278 +#define pyd_t pud_t
28279 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
28280 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
28281 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
28282 +#define pyd_offset(mm, address) pud_offset((mm), (address))
28283 +#define PYD_SIZE PUD_SIZE
28284 +#endif
28285 +
28286 +#ifdef CONFIG_PAX_PER_CPU_PGD
28287 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
28288 +static inline void pgd_dtor(pgd_t *pgd) {}
28289 +#else
28290 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
28291 {
28292 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
28293 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
28294 pgd_list_del(pgd);
28295 spin_unlock(&pgd_lock);
28296 }
28297 +#endif
28298
28299 /*
28300 * List of all pgd's needed for non-PAE so it can invalidate entries
28301 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
28302 * -- nyc
28303 */
28304
28305 -#ifdef CONFIG_X86_PAE
28306 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
28307 /*
28308 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
28309 * updating the top-level pagetable entries to guarantee the
28310 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
28311 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
28312 * and initialize the kernel pmds here.
28313 */
28314 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
28315 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
28316
28317 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28318 {
28319 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
28320 */
28321 flush_tlb_mm(mm);
28322 }
28323 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
28324 +#define PREALLOCATED_PXDS USER_PGD_PTRS
28325 #else /* !CONFIG_X86_PAE */
28326
28327 /* No need to prepopulate any pagetable entries in non-PAE modes. */
28328 -#define PREALLOCATED_PMDS 0
28329 +#define PREALLOCATED_PXDS 0
28330
28331 #endif /* CONFIG_X86_PAE */
28332
28333 -static void free_pmds(pmd_t *pmds[])
28334 +static void free_pxds(pxd_t *pxds[])
28335 {
28336 int i;
28337
28338 - for(i = 0; i < PREALLOCATED_PMDS; i++)
28339 - if (pmds[i])
28340 - free_page((unsigned long)pmds[i]);
28341 + for(i = 0; i < PREALLOCATED_PXDS; i++)
28342 + if (pxds[i])
28343 + free_page((unsigned long)pxds[i]);
28344 }
28345
28346 -static int preallocate_pmds(pmd_t *pmds[])
28347 +static int preallocate_pxds(pxd_t *pxds[])
28348 {
28349 int i;
28350 bool failed = false;
28351
28352 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28353 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
28354 - if (pmd == NULL)
28355 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28356 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
28357 + if (pxd == NULL)
28358 failed = true;
28359 - pmds[i] = pmd;
28360 + pxds[i] = pxd;
28361 }
28362
28363 if (failed) {
28364 - free_pmds(pmds);
28365 + free_pxds(pxds);
28366 return -ENOMEM;
28367 }
28368
28369 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
28370 * preallocate which never got a corresponding vma will need to be
28371 * freed manually.
28372 */
28373 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
28374 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
28375 {
28376 int i;
28377
28378 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
28379 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
28380 pgd_t pgd = pgdp[i];
28381
28382 if (pgd_val(pgd) != 0) {
28383 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
28384 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
28385
28386 - pgdp[i] = native_make_pgd(0);
28387 + set_pgd(pgdp + i, native_make_pgd(0));
28388
28389 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
28390 - pmd_free(mm, pmd);
28391 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
28392 + pxd_free(mm, pxd);
28393 }
28394 }
28395 }
28396
28397 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
28398 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
28399 {
28400 - pud_t *pud;
28401 + pyd_t *pyd;
28402 unsigned long addr;
28403 int i;
28404
28405 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
28406 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
28407 return;
28408
28409 - pud = pud_offset(pgd, 0);
28410 +#ifdef CONFIG_X86_64
28411 + pyd = pyd_offset(mm, 0L);
28412 +#else
28413 + pyd = pyd_offset(pgd, 0L);
28414 +#endif
28415
28416 - for (addr = i = 0; i < PREALLOCATED_PMDS;
28417 - i++, pud++, addr += PUD_SIZE) {
28418 - pmd_t *pmd = pmds[i];
28419 + for (addr = i = 0; i < PREALLOCATED_PXDS;
28420 + i++, pyd++, addr += PYD_SIZE) {
28421 + pxd_t *pxd = pxds[i];
28422
28423 if (i >= KERNEL_PGD_BOUNDARY)
28424 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28425 - sizeof(pmd_t) * PTRS_PER_PMD);
28426 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
28427 + sizeof(pxd_t) * PTRS_PER_PMD);
28428
28429 - pud_populate(mm, pud, pmd);
28430 + pyd_populate(mm, pyd, pxd);
28431 }
28432 }
28433
28434 pgd_t *pgd_alloc(struct mm_struct *mm)
28435 {
28436 pgd_t *pgd;
28437 - pmd_t *pmds[PREALLOCATED_PMDS];
28438 + pxd_t *pxds[PREALLOCATED_PXDS];
28439
28440 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
28441
28442 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28443
28444 mm->pgd = pgd;
28445
28446 - if (preallocate_pmds(pmds) != 0)
28447 + if (preallocate_pxds(pxds) != 0)
28448 goto out_free_pgd;
28449
28450 if (paravirt_pgd_alloc(mm) != 0)
28451 - goto out_free_pmds;
28452 + goto out_free_pxds;
28453
28454 /*
28455 * Make sure that pre-populating the pmds is atomic with
28456 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
28457 spin_lock(&pgd_lock);
28458
28459 pgd_ctor(mm, pgd);
28460 - pgd_prepopulate_pmd(mm, pgd, pmds);
28461 + pgd_prepopulate_pxd(mm, pgd, pxds);
28462
28463 spin_unlock(&pgd_lock);
28464
28465 return pgd;
28466
28467 -out_free_pmds:
28468 - free_pmds(pmds);
28469 +out_free_pxds:
28470 + free_pxds(pxds);
28471 out_free_pgd:
28472 free_page((unsigned long)pgd);
28473 out:
28474 @@ -295,7 +356,7 @@ out:
28475
28476 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
28477 {
28478 - pgd_mop_up_pmds(mm, pgd);
28479 + pgd_mop_up_pxds(mm, pgd);
28480 pgd_dtor(pgd);
28481 paravirt_pgd_free(mm, pgd);
28482 free_page((unsigned long)pgd);
28483 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
28484 index a69bcb8..19068ab 100644
28485 --- a/arch/x86/mm/pgtable_32.c
28486 +++ b/arch/x86/mm/pgtable_32.c
28487 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
28488 return;
28489 }
28490 pte = pte_offset_kernel(pmd, vaddr);
28491 +
28492 + pax_open_kernel();
28493 if (pte_val(pteval))
28494 set_pte_at(&init_mm, vaddr, pte, pteval);
28495 else
28496 pte_clear(&init_mm, vaddr, pte);
28497 + pax_close_kernel();
28498
28499 /*
28500 * It's enough to flush this one mapping.
28501 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
28502 index 410531d..0f16030 100644
28503 --- a/arch/x86/mm/setup_nx.c
28504 +++ b/arch/x86/mm/setup_nx.c
28505 @@ -5,8 +5,10 @@
28506 #include <asm/pgtable.h>
28507 #include <asm/proto.h>
28508
28509 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28510 static int disable_nx __cpuinitdata;
28511
28512 +#ifndef CONFIG_PAX_PAGEEXEC
28513 /*
28514 * noexec = on|off
28515 *
28516 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
28517 return 0;
28518 }
28519 early_param("noexec", noexec_setup);
28520 +#endif
28521 +
28522 +#endif
28523
28524 void __cpuinit x86_configure_nx(void)
28525 {
28526 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
28527 if (cpu_has_nx && !disable_nx)
28528 __supported_pte_mask |= _PAGE_NX;
28529 else
28530 +#endif
28531 __supported_pte_mask &= ~_PAGE_NX;
28532 }
28533
28534 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
28535 index 13a6b29..c2fff23 100644
28536 --- a/arch/x86/mm/tlb.c
28537 +++ b/arch/x86/mm/tlb.c
28538 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
28539 BUG();
28540 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
28541 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
28542 +
28543 +#ifndef CONFIG_PAX_PER_CPU_PGD
28544 load_cr3(swapper_pg_dir);
28545 +#endif
28546 +
28547 }
28548 }
28549 EXPORT_SYMBOL_GPL(leave_mm);
28550 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
28551 index 877b9a1..a8ecf42 100644
28552 --- a/arch/x86/net/bpf_jit.S
28553 +++ b/arch/x86/net/bpf_jit.S
28554 @@ -9,6 +9,7 @@
28555 */
28556 #include <linux/linkage.h>
28557 #include <asm/dwarf2.h>
28558 +#include <asm/alternative-asm.h>
28559
28560 /*
28561 * Calling convention :
28562 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
28563 jle bpf_slow_path_word
28564 mov (SKBDATA,%rsi),%eax
28565 bswap %eax /* ntohl() */
28566 + pax_force_retaddr
28567 ret
28568
28569 sk_load_half:
28570 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
28571 jle bpf_slow_path_half
28572 movzwl (SKBDATA,%rsi),%eax
28573 rol $8,%ax # ntohs()
28574 + pax_force_retaddr
28575 ret
28576
28577 sk_load_byte:
28578 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
28579 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
28580 jle bpf_slow_path_byte
28581 movzbl (SKBDATA,%rsi),%eax
28582 + pax_force_retaddr
28583 ret
28584
28585 /**
28586 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
28587 movzbl (SKBDATA,%rsi),%ebx
28588 and $15,%bl
28589 shl $2,%bl
28590 + pax_force_retaddr
28591 ret
28592
28593 /* rsi contains offset and can be scratched */
28594 @@ -109,6 +114,7 @@ bpf_slow_path_word:
28595 js bpf_error
28596 mov -12(%rbp),%eax
28597 bswap %eax
28598 + pax_force_retaddr
28599 ret
28600
28601 bpf_slow_path_half:
28602 @@ -117,12 +123,14 @@ bpf_slow_path_half:
28603 mov -12(%rbp),%ax
28604 rol $8,%ax
28605 movzwl %ax,%eax
28606 + pax_force_retaddr
28607 ret
28608
28609 bpf_slow_path_byte:
28610 bpf_slow_path_common(1)
28611 js bpf_error
28612 movzbl -12(%rbp),%eax
28613 + pax_force_retaddr
28614 ret
28615
28616 bpf_slow_path_byte_msh:
28617 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
28618 and $15,%al
28619 shl $2,%al
28620 xchg %eax,%ebx
28621 + pax_force_retaddr
28622 ret
28623
28624 #define sk_negative_common(SIZE) \
28625 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
28626 sk_negative_common(4)
28627 mov (%rax), %eax
28628 bswap %eax
28629 + pax_force_retaddr
28630 ret
28631
28632 bpf_slow_path_half_neg:
28633 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
28634 mov (%rax),%ax
28635 rol $8,%ax
28636 movzwl %ax,%eax
28637 + pax_force_retaddr
28638 ret
28639
28640 bpf_slow_path_byte_neg:
28641 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
28642 .globl sk_load_byte_negative_offset
28643 sk_negative_common(1)
28644 movzbl (%rax), %eax
28645 + pax_force_retaddr
28646 ret
28647
28648 bpf_slow_path_byte_msh_neg:
28649 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
28650 and $15,%al
28651 shl $2,%al
28652 xchg %eax,%ebx
28653 + pax_force_retaddr
28654 ret
28655
28656 bpf_error:
28657 @@ -197,4 +210,5 @@ bpf_error:
28658 xor %eax,%eax
28659 mov -8(%rbp),%rbx
28660 leaveq
28661 + pax_force_retaddr
28662 ret
28663 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
28664 index d11a470..3f9adff3 100644
28665 --- a/arch/x86/net/bpf_jit_comp.c
28666 +++ b/arch/x86/net/bpf_jit_comp.c
28667 @@ -12,6 +12,7 @@
28668 #include <linux/netdevice.h>
28669 #include <linux/filter.h>
28670 #include <linux/if_vlan.h>
28671 +#include <linux/random.h>
28672
28673 /*
28674 * Conventions :
28675 @@ -49,13 +50,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
28676 return ptr + len;
28677 }
28678
28679 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28680 +#define MAX_INSTR_CODE_SIZE 96
28681 +#else
28682 +#define MAX_INSTR_CODE_SIZE 64
28683 +#endif
28684 +
28685 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
28686
28687 #define EMIT1(b1) EMIT(b1, 1)
28688 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
28689 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
28690 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
28691 +
28692 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28693 +/* original constant will appear in ecx */
28694 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
28695 +do { \
28696 + /* mov ecx, randkey */ \
28697 + EMIT1(0xb9); \
28698 + EMIT(_key, 4); \
28699 + /* xor ecx, randkey ^ off */ \
28700 + EMIT2(0x81, 0xf1); \
28701 + EMIT((_key) ^ (_off), 4); \
28702 +} while (0)
28703 +
28704 +#define EMIT1_off32(b1, _off) \
28705 +do { \
28706 + switch (b1) { \
28707 + case 0x05: /* add eax, imm32 */ \
28708 + case 0x2d: /* sub eax, imm32 */ \
28709 + case 0x25: /* and eax, imm32 */ \
28710 + case 0x0d: /* or eax, imm32 */ \
28711 + case 0xb8: /* mov eax, imm32 */ \
28712 + case 0x3d: /* cmp eax, imm32 */ \
28713 + case 0xa9: /* test eax, imm32 */ \
28714 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28715 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
28716 + break; \
28717 + case 0xbb: /* mov ebx, imm32 */ \
28718 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28719 + /* mov ebx, ecx */ \
28720 + EMIT2(0x89, 0xcb); \
28721 + break; \
28722 + case 0xbe: /* mov esi, imm32 */ \
28723 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28724 + /* mov esi, ecx */ \
28725 + EMIT2(0x89, 0xce); \
28726 + break; \
28727 + case 0xe9: /* jmp rel imm32 */ \
28728 + EMIT1(b1); \
28729 + EMIT(_off, 4); \
28730 + /* prevent fall-through, we're not called if off = 0 */ \
28731 + EMIT(0xcccccccc, 4); \
28732 + EMIT(0xcccccccc, 4); \
28733 + break; \
28734 + default: \
28735 + EMIT1(b1); \
28736 + EMIT(_off, 4); \
28737 + } \
28738 +} while (0)
28739 +
28740 +#define EMIT2_off32(b1, b2, _off) \
28741 +do { \
28742 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
28743 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
28744 + EMIT(randkey, 4); \
28745 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
28746 + EMIT((_off) - randkey, 4); \
28747 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
28748 + DILUTE_CONST_SEQUENCE(_off, randkey); \
28749 + /* imul eax, ecx */ \
28750 + EMIT3(0x0f, 0xaf, 0xc1); \
28751 + } else { \
28752 + EMIT2(b1, b2); \
28753 + EMIT(_off, 4); \
28754 + } \
28755 +} while (0)
28756 +#else
28757 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
28758 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
28759 +#endif
28760
28761 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
28762 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
28763 @@ -90,6 +165,24 @@ do { \
28764 #define X86_JBE 0x76
28765 #define X86_JA 0x77
28766
28767 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28768 +#define APPEND_FLOW_VERIFY() \
28769 +do { \
28770 + /* mov ecx, randkey */ \
28771 + EMIT1(0xb9); \
28772 + EMIT(randkey, 4); \
28773 + /* cmp ecx, randkey */ \
28774 + EMIT2(0x81, 0xf9); \
28775 + EMIT(randkey, 4); \
28776 + /* jz after 8 int 3s */ \
28777 + EMIT2(0x74, 0x08); \
28778 + EMIT(0xcccccccc, 4); \
28779 + EMIT(0xcccccccc, 4); \
28780 +} while (0)
28781 +#else
28782 +#define APPEND_FLOW_VERIFY() do { } while (0)
28783 +#endif
28784 +
28785 #define EMIT_COND_JMP(op, offset) \
28786 do { \
28787 if (is_near(offset)) \
28788 @@ -97,6 +190,7 @@ do { \
28789 else { \
28790 EMIT2(0x0f, op + 0x10); \
28791 EMIT(offset, 4); /* jxx .+off32 */ \
28792 + APPEND_FLOW_VERIFY(); \
28793 } \
28794 } while (0)
28795
28796 @@ -121,12 +215,17 @@ static inline void bpf_flush_icache(void *start, void *end)
28797 set_fs(old_fs);
28798 }
28799
28800 +struct bpf_jit_work {
28801 + struct work_struct work;
28802 + void *image;
28803 +};
28804 +
28805 #define CHOOSE_LOAD_FUNC(K, func) \
28806 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
28807
28808 void bpf_jit_compile(struct sk_filter *fp)
28809 {
28810 - u8 temp[64];
28811 + u8 temp[MAX_INSTR_CODE_SIZE];
28812 u8 *prog;
28813 unsigned int proglen, oldproglen = 0;
28814 int ilen, i;
28815 @@ -139,6 +238,9 @@ void bpf_jit_compile(struct sk_filter *fp)
28816 unsigned int *addrs;
28817 const struct sock_filter *filter = fp->insns;
28818 int flen = fp->len;
28819 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28820 + unsigned int randkey;
28821 +#endif
28822
28823 if (!bpf_jit_enable)
28824 return;
28825 @@ -147,11 +249,19 @@ void bpf_jit_compile(struct sk_filter *fp)
28826 if (addrs == NULL)
28827 return;
28828
28829 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
28830 + if (!fp->work)
28831 + goto out;
28832 +
28833 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28834 + randkey = get_random_int();
28835 +#endif
28836 +
28837 /* Before first pass, make a rough estimation of addrs[]
28838 - * each bpf instruction is translated to less than 64 bytes
28839 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
28840 */
28841 for (proglen = 0, i = 0; i < flen; i++) {
28842 - proglen += 64;
28843 + proglen += MAX_INSTR_CODE_SIZE;
28844 addrs[i] = proglen;
28845 }
28846 cleanup_addr = proglen; /* epilogue address */
28847 @@ -261,10 +371,8 @@ void bpf_jit_compile(struct sk_filter *fp)
28848 case BPF_S_ALU_MUL_K: /* A *= K */
28849 if (is_imm8(K))
28850 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
28851 - else {
28852 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
28853 - EMIT(K, 4);
28854 - }
28855 + else
28856 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
28857 break;
28858 case BPF_S_ALU_DIV_X: /* A /= X; */
28859 seen |= SEEN_XREG;
28860 @@ -304,13 +412,23 @@ void bpf_jit_compile(struct sk_filter *fp)
28861 break;
28862 case BPF_S_ALU_MOD_K: /* A %= K; */
28863 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
28864 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28865 + DILUTE_CONST_SEQUENCE(K, randkey);
28866 +#else
28867 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
28868 +#endif
28869 EMIT2(0xf7, 0xf1); /* div %ecx */
28870 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
28871 break;
28872 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
28873 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
28874 + DILUTE_CONST_SEQUENCE(K, randkey);
28875 + // imul rax, rcx
28876 + EMIT4(0x48, 0x0f, 0xaf, 0xc1);
28877 +#else
28878 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
28879 EMIT(K, 4);
28880 +#endif
28881 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
28882 break;
28883 case BPF_S_ALU_AND_X:
28884 @@ -564,8 +682,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
28885 if (is_imm8(K)) {
28886 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
28887 } else {
28888 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
28889 - EMIT(K, 4);
28890 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
28891 }
28892 } else {
28893 EMIT2(0x89,0xde); /* mov %ebx,%esi */
28894 @@ -648,17 +765,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28895 break;
28896 default:
28897 /* hmm, too complex filter, give up with jit compiler */
28898 - goto out;
28899 + goto error;
28900 }
28901 ilen = prog - temp;
28902 if (image) {
28903 if (unlikely(proglen + ilen > oldproglen)) {
28904 pr_err("bpb_jit_compile fatal error\n");
28905 - kfree(addrs);
28906 - module_free(NULL, image);
28907 - return;
28908 + module_free_exec(NULL, image);
28909 + goto error;
28910 }
28911 + pax_open_kernel();
28912 memcpy(image + proglen, temp, ilen);
28913 + pax_close_kernel();
28914 }
28915 proglen += ilen;
28916 addrs[i] = proglen;
28917 @@ -679,11 +797,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28918 break;
28919 }
28920 if (proglen == oldproglen) {
28921 - image = module_alloc(max_t(unsigned int,
28922 - proglen,
28923 - sizeof(struct work_struct)));
28924 + image = module_alloc_exec(proglen);
28925 if (!image)
28926 - goto out;
28927 + goto error;
28928 }
28929 oldproglen = proglen;
28930 }
28931 @@ -699,7 +815,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
28932 bpf_flush_icache(image, image + proglen);
28933
28934 fp->bpf_func = (void *)image;
28935 - }
28936 + } else
28937 +error:
28938 + kfree(fp->work);
28939 +
28940 out:
28941 kfree(addrs);
28942 return;
28943 @@ -707,18 +826,20 @@ out:
28944
28945 static void jit_free_defer(struct work_struct *arg)
28946 {
28947 - module_free(NULL, arg);
28948 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
28949 + kfree(arg);
28950 }
28951
28952 /* run from softirq, we must use a work_struct to call
28953 - * module_free() from process context
28954 + * module_free_exec() from process context
28955 */
28956 void bpf_jit_free(struct sk_filter *fp)
28957 {
28958 if (fp->bpf_func != sk_run_filter) {
28959 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
28960 + struct work_struct *work = &fp->work->work;
28961
28962 INIT_WORK(work, jit_free_defer);
28963 + fp->work->image = fp->bpf_func;
28964 schedule_work(work);
28965 }
28966 }
28967 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
28968 index d6aa6e8..266395a 100644
28969 --- a/arch/x86/oprofile/backtrace.c
28970 +++ b/arch/x86/oprofile/backtrace.c
28971 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
28972 struct stack_frame_ia32 *fp;
28973 unsigned long bytes;
28974
28975 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28976 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28977 if (bytes != sizeof(bufhead))
28978 return NULL;
28979
28980 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
28981 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
28982
28983 oprofile_add_trace(bufhead[0].return_address);
28984
28985 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
28986 struct stack_frame bufhead[2];
28987 unsigned long bytes;
28988
28989 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
28990 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
28991 if (bytes != sizeof(bufhead))
28992 return NULL;
28993
28994 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
28995 {
28996 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
28997
28998 - if (!user_mode_vm(regs)) {
28999 + if (!user_mode(regs)) {
29000 unsigned long stack = kernel_stack_pointer(regs);
29001 if (depth)
29002 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29003 diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
29004 index e9e6ed5..e47ae67 100644
29005 --- a/arch/x86/pci/amd_bus.c
29006 +++ b/arch/x86/pci/amd_bus.c
29007 @@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
29008 return NOTIFY_OK;
29009 }
29010
29011 -static struct notifier_block __cpuinitdata amd_cpu_notifier = {
29012 +static struct notifier_block amd_cpu_notifier = {
29013 .notifier_call = amd_cpu_notify,
29014 };
29015
29016 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
29017 index 6eb18c4..20d83de 100644
29018 --- a/arch/x86/pci/mrst.c
29019 +++ b/arch/x86/pci/mrst.c
29020 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
29021 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
29022 pci_mmcfg_late_init();
29023 pcibios_enable_irq = mrst_pci_irq_enable;
29024 - pci_root_ops = pci_mrst_ops;
29025 + pax_open_kernel();
29026 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
29027 + pax_close_kernel();
29028 pci_soc_mode = 1;
29029 /* Continue with standard init */
29030 return 1;
29031 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
29032 index c77b24a..c979855 100644
29033 --- a/arch/x86/pci/pcbios.c
29034 +++ b/arch/x86/pci/pcbios.c
29035 @@ -79,7 +79,7 @@ union bios32 {
29036 static struct {
29037 unsigned long address;
29038 unsigned short segment;
29039 -} bios32_indirect = { 0, __KERNEL_CS };
29040 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
29041
29042 /*
29043 * Returns the entry point for the given service, NULL on error
29044 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
29045 unsigned long length; /* %ecx */
29046 unsigned long entry; /* %edx */
29047 unsigned long flags;
29048 + struct desc_struct d, *gdt;
29049
29050 local_irq_save(flags);
29051 - __asm__("lcall *(%%edi); cld"
29052 +
29053 + gdt = get_cpu_gdt_table(smp_processor_id());
29054 +
29055 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
29056 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29057 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
29058 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29059 +
29060 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
29061 : "=a" (return_code),
29062 "=b" (address),
29063 "=c" (length),
29064 "=d" (entry)
29065 : "0" (service),
29066 "1" (0),
29067 - "D" (&bios32_indirect));
29068 + "D" (&bios32_indirect),
29069 + "r"(__PCIBIOS_DS)
29070 + : "memory");
29071 +
29072 + pax_open_kernel();
29073 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
29074 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
29075 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
29076 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
29077 + pax_close_kernel();
29078 +
29079 local_irq_restore(flags);
29080
29081 switch (return_code) {
29082 - case 0:
29083 - return address + entry;
29084 - case 0x80: /* Not present */
29085 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29086 - return 0;
29087 - default: /* Shouldn't happen */
29088 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29089 - service, return_code);
29090 + case 0: {
29091 + int cpu;
29092 + unsigned char flags;
29093 +
29094 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
29095 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
29096 + printk(KERN_WARNING "bios32_service: not valid\n");
29097 return 0;
29098 + }
29099 + address = address + PAGE_OFFSET;
29100 + length += 16UL; /* some BIOSs underreport this... */
29101 + flags = 4;
29102 + if (length >= 64*1024*1024) {
29103 + length >>= PAGE_SHIFT;
29104 + flags |= 8;
29105 + }
29106 +
29107 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
29108 + gdt = get_cpu_gdt_table(cpu);
29109 + pack_descriptor(&d, address, length, 0x9b, flags);
29110 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
29111 + pack_descriptor(&d, address, length, 0x93, flags);
29112 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
29113 + }
29114 + return entry;
29115 + }
29116 + case 0x80: /* Not present */
29117 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
29118 + return 0;
29119 + default: /* Shouldn't happen */
29120 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
29121 + service, return_code);
29122 + return 0;
29123 }
29124 }
29125
29126 static struct {
29127 unsigned long address;
29128 unsigned short segment;
29129 -} pci_indirect = { 0, __KERNEL_CS };
29130 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
29131
29132 -static int pci_bios_present;
29133 +static int pci_bios_present __read_only;
29134
29135 static int check_pcibios(void)
29136 {
29137 @@ -131,11 +174,13 @@ static int check_pcibios(void)
29138 unsigned long flags, pcibios_entry;
29139
29140 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
29141 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
29142 + pci_indirect.address = pcibios_entry;
29143
29144 local_irq_save(flags);
29145 - __asm__(
29146 - "lcall *(%%edi); cld\n\t"
29147 + __asm__("movw %w6, %%ds\n\t"
29148 + "lcall *%%ss:(%%edi); cld\n\t"
29149 + "push %%ss\n\t"
29150 + "pop %%ds\n\t"
29151 "jc 1f\n\t"
29152 "xor %%ah, %%ah\n"
29153 "1:"
29154 @@ -144,7 +189,8 @@ static int check_pcibios(void)
29155 "=b" (ebx),
29156 "=c" (ecx)
29157 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
29158 - "D" (&pci_indirect)
29159 + "D" (&pci_indirect),
29160 + "r" (__PCIBIOS_DS)
29161 : "memory");
29162 local_irq_restore(flags);
29163
29164 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29165
29166 switch (len) {
29167 case 1:
29168 - __asm__("lcall *(%%esi); cld\n\t"
29169 + __asm__("movw %w6, %%ds\n\t"
29170 + "lcall *%%ss:(%%esi); cld\n\t"
29171 + "push %%ss\n\t"
29172 + "pop %%ds\n\t"
29173 "jc 1f\n\t"
29174 "xor %%ah, %%ah\n"
29175 "1:"
29176 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29177 : "1" (PCIBIOS_READ_CONFIG_BYTE),
29178 "b" (bx),
29179 "D" ((long)reg),
29180 - "S" (&pci_indirect));
29181 + "S" (&pci_indirect),
29182 + "r" (__PCIBIOS_DS));
29183 /*
29184 * Zero-extend the result beyond 8 bits, do not trust the
29185 * BIOS having done it:
29186 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29187 *value &= 0xff;
29188 break;
29189 case 2:
29190 - __asm__("lcall *(%%esi); cld\n\t"
29191 + __asm__("movw %w6, %%ds\n\t"
29192 + "lcall *%%ss:(%%esi); cld\n\t"
29193 + "push %%ss\n\t"
29194 + "pop %%ds\n\t"
29195 "jc 1f\n\t"
29196 "xor %%ah, %%ah\n"
29197 "1:"
29198 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29199 : "1" (PCIBIOS_READ_CONFIG_WORD),
29200 "b" (bx),
29201 "D" ((long)reg),
29202 - "S" (&pci_indirect));
29203 + "S" (&pci_indirect),
29204 + "r" (__PCIBIOS_DS));
29205 /*
29206 * Zero-extend the result beyond 16 bits, do not trust the
29207 * BIOS having done it:
29208 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29209 *value &= 0xffff;
29210 break;
29211 case 4:
29212 - __asm__("lcall *(%%esi); cld\n\t"
29213 + __asm__("movw %w6, %%ds\n\t"
29214 + "lcall *%%ss:(%%esi); cld\n\t"
29215 + "push %%ss\n\t"
29216 + "pop %%ds\n\t"
29217 "jc 1f\n\t"
29218 "xor %%ah, %%ah\n"
29219 "1:"
29220 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
29221 : "1" (PCIBIOS_READ_CONFIG_DWORD),
29222 "b" (bx),
29223 "D" ((long)reg),
29224 - "S" (&pci_indirect));
29225 + "S" (&pci_indirect),
29226 + "r" (__PCIBIOS_DS));
29227 break;
29228 }
29229
29230 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29231
29232 switch (len) {
29233 case 1:
29234 - __asm__("lcall *(%%esi); cld\n\t"
29235 + __asm__("movw %w6, %%ds\n\t"
29236 + "lcall *%%ss:(%%esi); cld\n\t"
29237 + "push %%ss\n\t"
29238 + "pop %%ds\n\t"
29239 "jc 1f\n\t"
29240 "xor %%ah, %%ah\n"
29241 "1:"
29242 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29243 "c" (value),
29244 "b" (bx),
29245 "D" ((long)reg),
29246 - "S" (&pci_indirect));
29247 + "S" (&pci_indirect),
29248 + "r" (__PCIBIOS_DS));
29249 break;
29250 case 2:
29251 - __asm__("lcall *(%%esi); cld\n\t"
29252 + __asm__("movw %w6, %%ds\n\t"
29253 + "lcall *%%ss:(%%esi); cld\n\t"
29254 + "push %%ss\n\t"
29255 + "pop %%ds\n\t"
29256 "jc 1f\n\t"
29257 "xor %%ah, %%ah\n"
29258 "1:"
29259 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29260 "c" (value),
29261 "b" (bx),
29262 "D" ((long)reg),
29263 - "S" (&pci_indirect));
29264 + "S" (&pci_indirect),
29265 + "r" (__PCIBIOS_DS));
29266 break;
29267 case 4:
29268 - __asm__("lcall *(%%esi); cld\n\t"
29269 + __asm__("movw %w6, %%ds\n\t"
29270 + "lcall *%%ss:(%%esi); cld\n\t"
29271 + "push %%ss\n\t"
29272 + "pop %%ds\n\t"
29273 "jc 1f\n\t"
29274 "xor %%ah, %%ah\n"
29275 "1:"
29276 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
29277 "c" (value),
29278 "b" (bx),
29279 "D" ((long)reg),
29280 - "S" (&pci_indirect));
29281 + "S" (&pci_indirect),
29282 + "r" (__PCIBIOS_DS));
29283 break;
29284 }
29285
29286 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29287
29288 DBG("PCI: Fetching IRQ routing table... ");
29289 __asm__("push %%es\n\t"
29290 + "movw %w8, %%ds\n\t"
29291 "push %%ds\n\t"
29292 "pop %%es\n\t"
29293 - "lcall *(%%esi); cld\n\t"
29294 + "lcall *%%ss:(%%esi); cld\n\t"
29295 "pop %%es\n\t"
29296 + "push %%ss\n\t"
29297 + "pop %%ds\n"
29298 "jc 1f\n\t"
29299 "xor %%ah, %%ah\n"
29300 "1:"
29301 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
29302 "1" (0),
29303 "D" ((long) &opt),
29304 "S" (&pci_indirect),
29305 - "m" (opt)
29306 + "m" (opt),
29307 + "r" (__PCIBIOS_DS)
29308 : "memory");
29309 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
29310 if (ret & 0xff00)
29311 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29312 {
29313 int ret;
29314
29315 - __asm__("lcall *(%%esi); cld\n\t"
29316 + __asm__("movw %w5, %%ds\n\t"
29317 + "lcall *%%ss:(%%esi); cld\n\t"
29318 + "push %%ss\n\t"
29319 + "pop %%ds\n"
29320 "jc 1f\n\t"
29321 "xor %%ah, %%ah\n"
29322 "1:"
29323 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
29324 : "0" (PCIBIOS_SET_PCI_HW_INT),
29325 "b" ((dev->bus->number << 8) | dev->devfn),
29326 "c" ((irq << 8) | (pin + 10)),
29327 - "S" (&pci_indirect));
29328 + "S" (&pci_indirect),
29329 + "r" (__PCIBIOS_DS));
29330 return !(ret & 0xff00);
29331 }
29332 EXPORT_SYMBOL(pcibios_set_irq_routing);
29333 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
29334 index 40e4469..1ab536e 100644
29335 --- a/arch/x86/platform/efi/efi_32.c
29336 +++ b/arch/x86/platform/efi/efi_32.c
29337 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
29338 {
29339 struct desc_ptr gdt_descr;
29340
29341 +#ifdef CONFIG_PAX_KERNEXEC
29342 + struct desc_struct d;
29343 +#endif
29344 +
29345 local_irq_save(efi_rt_eflags);
29346
29347 load_cr3(initial_page_table);
29348 __flush_tlb_all();
29349
29350 +#ifdef CONFIG_PAX_KERNEXEC
29351 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
29352 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29353 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
29354 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29355 +#endif
29356 +
29357 gdt_descr.address = __pa(get_cpu_gdt_table(0));
29358 gdt_descr.size = GDT_SIZE - 1;
29359 load_gdt(&gdt_descr);
29360 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
29361 {
29362 struct desc_ptr gdt_descr;
29363
29364 +#ifdef CONFIG_PAX_KERNEXEC
29365 + struct desc_struct d;
29366 +
29367 + memset(&d, 0, sizeof d);
29368 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
29369 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
29370 +#endif
29371 +
29372 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
29373 gdt_descr.size = GDT_SIZE - 1;
29374 load_gdt(&gdt_descr);
29375 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
29376 index fbe66e6..eae5e38 100644
29377 --- a/arch/x86/platform/efi/efi_stub_32.S
29378 +++ b/arch/x86/platform/efi/efi_stub_32.S
29379 @@ -6,7 +6,9 @@
29380 */
29381
29382 #include <linux/linkage.h>
29383 +#include <linux/init.h>
29384 #include <asm/page_types.h>
29385 +#include <asm/segment.h>
29386
29387 /*
29388 * efi_call_phys(void *, ...) is a function with variable parameters.
29389 @@ -20,7 +22,7 @@
29390 * service functions will comply with gcc calling convention, too.
29391 */
29392
29393 -.text
29394 +__INIT
29395 ENTRY(efi_call_phys)
29396 /*
29397 * 0. The function can only be called in Linux kernel. So CS has been
29398 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
29399 * The mapping of lower virtual memory has been created in prelog and
29400 * epilog.
29401 */
29402 - movl $1f, %edx
29403 - subl $__PAGE_OFFSET, %edx
29404 - jmp *%edx
29405 +#ifdef CONFIG_PAX_KERNEXEC
29406 + movl $(__KERNEXEC_EFI_DS), %edx
29407 + mov %edx, %ds
29408 + mov %edx, %es
29409 + mov %edx, %ss
29410 + addl $2f,(1f)
29411 + ljmp *(1f)
29412 +
29413 +__INITDATA
29414 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
29415 +.previous
29416 +
29417 +2:
29418 + subl $2b,(1b)
29419 +#else
29420 + jmp 1f-__PAGE_OFFSET
29421 1:
29422 +#endif
29423
29424 /*
29425 * 2. Now on the top of stack is the return
29426 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
29427 * parameter 2, ..., param n. To make things easy, we save the return
29428 * address of efi_call_phys in a global variable.
29429 */
29430 - popl %edx
29431 - movl %edx, saved_return_addr
29432 - /* get the function pointer into ECX*/
29433 - popl %ecx
29434 - movl %ecx, efi_rt_function_ptr
29435 - movl $2f, %edx
29436 - subl $__PAGE_OFFSET, %edx
29437 - pushl %edx
29438 + popl (saved_return_addr)
29439 + popl (efi_rt_function_ptr)
29440
29441 /*
29442 * 3. Clear PG bit in %CR0.
29443 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
29444 /*
29445 * 5. Call the physical function.
29446 */
29447 - jmp *%ecx
29448 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
29449
29450 -2:
29451 /*
29452 * 6. After EFI runtime service returns, control will return to
29453 * following instruction. We'd better readjust stack pointer first.
29454 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
29455 movl %cr0, %edx
29456 orl $0x80000000, %edx
29457 movl %edx, %cr0
29458 - jmp 1f
29459 -1:
29460 +
29461 /*
29462 * 8. Now restore the virtual mode from flat mode by
29463 * adding EIP with PAGE_OFFSET.
29464 */
29465 - movl $1f, %edx
29466 - jmp *%edx
29467 +#ifdef CONFIG_PAX_KERNEXEC
29468 + movl $(__KERNEL_DS), %edx
29469 + mov %edx, %ds
29470 + mov %edx, %es
29471 + mov %edx, %ss
29472 + ljmp $(__KERNEL_CS),$1f
29473 +#else
29474 + jmp 1f+__PAGE_OFFSET
29475 +#endif
29476 1:
29477
29478 /*
29479 * 9. Balance the stack. And because EAX contain the return value,
29480 * we'd better not clobber it.
29481 */
29482 - leal efi_rt_function_ptr, %edx
29483 - movl (%edx), %ecx
29484 - pushl %ecx
29485 + pushl (efi_rt_function_ptr)
29486
29487 /*
29488 - * 10. Push the saved return address onto the stack and return.
29489 + * 10. Return to the saved return address.
29490 */
29491 - leal saved_return_addr, %edx
29492 - movl (%edx), %ecx
29493 - pushl %ecx
29494 - ret
29495 + jmpl *(saved_return_addr)
29496 ENDPROC(efi_call_phys)
29497 .previous
29498
29499 -.data
29500 +__INITDATA
29501 saved_return_addr:
29502 .long 0
29503 efi_rt_function_ptr:
29504 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
29505 index 4c07cca..2c8427d 100644
29506 --- a/arch/x86/platform/efi/efi_stub_64.S
29507 +++ b/arch/x86/platform/efi/efi_stub_64.S
29508 @@ -7,6 +7,7 @@
29509 */
29510
29511 #include <linux/linkage.h>
29512 +#include <asm/alternative-asm.h>
29513
29514 #define SAVE_XMM \
29515 mov %rsp, %rax; \
29516 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
29517 call *%rdi
29518 addq $32, %rsp
29519 RESTORE_XMM
29520 + pax_force_retaddr 0, 1
29521 ret
29522 ENDPROC(efi_call0)
29523
29524 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
29525 call *%rdi
29526 addq $32, %rsp
29527 RESTORE_XMM
29528 + pax_force_retaddr 0, 1
29529 ret
29530 ENDPROC(efi_call1)
29531
29532 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
29533 call *%rdi
29534 addq $32, %rsp
29535 RESTORE_XMM
29536 + pax_force_retaddr 0, 1
29537 ret
29538 ENDPROC(efi_call2)
29539
29540 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
29541 call *%rdi
29542 addq $32, %rsp
29543 RESTORE_XMM
29544 + pax_force_retaddr 0, 1
29545 ret
29546 ENDPROC(efi_call3)
29547
29548 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
29549 call *%rdi
29550 addq $32, %rsp
29551 RESTORE_XMM
29552 + pax_force_retaddr 0, 1
29553 ret
29554 ENDPROC(efi_call4)
29555
29556 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
29557 call *%rdi
29558 addq $48, %rsp
29559 RESTORE_XMM
29560 + pax_force_retaddr 0, 1
29561 ret
29562 ENDPROC(efi_call5)
29563
29564 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
29565 call *%rdi
29566 addq $48, %rsp
29567 RESTORE_XMM
29568 + pax_force_retaddr 0, 1
29569 ret
29570 ENDPROC(efi_call6)
29571 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
29572 index e31bcd8..f12dc46 100644
29573 --- a/arch/x86/platform/mrst/mrst.c
29574 +++ b/arch/x86/platform/mrst/mrst.c
29575 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
29576 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
29577 int sfi_mrtc_num;
29578
29579 -static void mrst_power_off(void)
29580 +static __noreturn void mrst_power_off(void)
29581 {
29582 + BUG();
29583 }
29584
29585 -static void mrst_reboot(void)
29586 +static __noreturn void mrst_reboot(void)
29587 {
29588 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
29589 + BUG();
29590 }
29591
29592 /* parse all the mtimer info to a static mtimer array */
29593 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
29594 index d6ee929..3637cb5 100644
29595 --- a/arch/x86/platform/olpc/olpc_dt.c
29596 +++ b/arch/x86/platform/olpc/olpc_dt.c
29597 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
29598 return res;
29599 }
29600
29601 -static struct of_pdt_ops prom_olpc_ops __initdata = {
29602 +static struct of_pdt_ops prom_olpc_ops __initconst = {
29603 .nextprop = olpc_dt_nextprop,
29604 .getproplen = olpc_dt_getproplen,
29605 .getproperty = olpc_dt_getproperty,
29606 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
29607 index 120cee1..b2db75a 100644
29608 --- a/arch/x86/power/cpu.c
29609 +++ b/arch/x86/power/cpu.c
29610 @@ -133,7 +133,7 @@ static void do_fpu_end(void)
29611 static void fix_processor_context(void)
29612 {
29613 int cpu = smp_processor_id();
29614 - struct tss_struct *t = &per_cpu(init_tss, cpu);
29615 + struct tss_struct *t = init_tss + cpu;
29616
29617 set_tss_desc(cpu, t); /*
29618 * This just modifies memory; should not be
29619 @@ -143,8 +143,6 @@ static void fix_processor_context(void)
29620 */
29621
29622 #ifdef CONFIG_X86_64
29623 - get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
29624 -
29625 syscall_init(); /* This sets MSR_*STAR and related */
29626 #endif
29627 load_TR_desc(); /* This does ltr */
29628 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
29629 index cbca565..bae7133 100644
29630 --- a/arch/x86/realmode/init.c
29631 +++ b/arch/x86/realmode/init.c
29632 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
29633 __va(real_mode_header->trampoline_header);
29634
29635 #ifdef CONFIG_X86_32
29636 - trampoline_header->start = __pa(startup_32_smp);
29637 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
29638 +
29639 +#ifdef CONFIG_PAX_KERNEXEC
29640 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
29641 +#endif
29642 +
29643 + trampoline_header->boot_cs = __BOOT_CS;
29644 trampoline_header->gdt_limit = __BOOT_DS + 7;
29645 trampoline_header->gdt_base = __pa(boot_gdt);
29646 #else
29647 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
29648 index 8869287..d577672 100644
29649 --- a/arch/x86/realmode/rm/Makefile
29650 +++ b/arch/x86/realmode/rm/Makefile
29651 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
29652 $(call cc-option, -fno-unit-at-a-time)) \
29653 $(call cc-option, -fno-stack-protector) \
29654 $(call cc-option, -mpreferred-stack-boundary=2)
29655 +ifdef CONSTIFY_PLUGIN
29656 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
29657 +endif
29658 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
29659 GCOV_PROFILE := n
29660 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
29661 index a28221d..93c40f1 100644
29662 --- a/arch/x86/realmode/rm/header.S
29663 +++ b/arch/x86/realmode/rm/header.S
29664 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
29665 #endif
29666 /* APM/BIOS reboot */
29667 .long pa_machine_real_restart_asm
29668 -#ifdef CONFIG_X86_64
29669 +#ifdef CONFIG_X86_32
29670 + .long __KERNEL_CS
29671 +#else
29672 .long __KERNEL32_CS
29673 #endif
29674 END(real_mode_header)
29675 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
29676 index c1b2791..f9e31c7 100644
29677 --- a/arch/x86/realmode/rm/trampoline_32.S
29678 +++ b/arch/x86/realmode/rm/trampoline_32.S
29679 @@ -25,6 +25,12 @@
29680 #include <asm/page_types.h>
29681 #include "realmode.h"
29682
29683 +#ifdef CONFIG_PAX_KERNEXEC
29684 +#define ta(X) (X)
29685 +#else
29686 +#define ta(X) (pa_ ## X)
29687 +#endif
29688 +
29689 .text
29690 .code16
29691
29692 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
29693
29694 cli # We should be safe anyway
29695
29696 - movl tr_start, %eax # where we need to go
29697 -
29698 movl $0xA5A5A5A5, trampoline_status
29699 # write marker for master knows we're running
29700
29701 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
29702 movw $1, %dx # protected mode (PE) bit
29703 lmsw %dx # into protected mode
29704
29705 - ljmpl $__BOOT_CS, $pa_startup_32
29706 + ljmpl *(trampoline_header)
29707
29708 .section ".text32","ax"
29709 .code32
29710 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
29711 .balign 8
29712 GLOBAL(trampoline_header)
29713 tr_start: .space 4
29714 - tr_gdt_pad: .space 2
29715 + tr_boot_cs: .space 2
29716 tr_gdt: .space 6
29717 END(trampoline_header)
29718
29719 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
29720 index bb360dc..3e5945f 100644
29721 --- a/arch/x86/realmode/rm/trampoline_64.S
29722 +++ b/arch/x86/realmode/rm/trampoline_64.S
29723 @@ -107,7 +107,7 @@ ENTRY(startup_32)
29724 wrmsr
29725
29726 # Enable paging and in turn activate Long Mode
29727 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
29728 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
29729 movl %eax, %cr0
29730
29731 /*
29732 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
29733 index 79d67bd..c7e1b90 100644
29734 --- a/arch/x86/tools/relocs.c
29735 +++ b/arch/x86/tools/relocs.c
29736 @@ -12,10 +12,13 @@
29737 #include <regex.h>
29738 #include <tools/le_byteshift.h>
29739
29740 +#include "../../../include/generated/autoconf.h"
29741 +
29742 static void die(char *fmt, ...);
29743
29744 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
29745 static Elf32_Ehdr ehdr;
29746 +static Elf32_Phdr *phdr;
29747 static unsigned long reloc_count, reloc_idx;
29748 static unsigned long *relocs;
29749 static unsigned long reloc16_count, reloc16_idx;
29750 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
29751 }
29752 }
29753
29754 +static void read_phdrs(FILE *fp)
29755 +{
29756 + unsigned int i;
29757 +
29758 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
29759 + if (!phdr) {
29760 + die("Unable to allocate %d program headers\n",
29761 + ehdr.e_phnum);
29762 + }
29763 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
29764 + die("Seek to %d failed: %s\n",
29765 + ehdr.e_phoff, strerror(errno));
29766 + }
29767 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
29768 + die("Cannot read ELF program headers: %s\n",
29769 + strerror(errno));
29770 + }
29771 + for(i = 0; i < ehdr.e_phnum; i++) {
29772 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
29773 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
29774 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
29775 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
29776 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
29777 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
29778 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
29779 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
29780 + }
29781 +
29782 +}
29783 +
29784 static void read_shdrs(FILE *fp)
29785 {
29786 - int i;
29787 + unsigned int i;
29788 Elf32_Shdr shdr;
29789
29790 secs = calloc(ehdr.e_shnum, sizeof(struct section));
29791 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
29792
29793 static void read_strtabs(FILE *fp)
29794 {
29795 - int i;
29796 + unsigned int i;
29797 for (i = 0; i < ehdr.e_shnum; i++) {
29798 struct section *sec = &secs[i];
29799 if (sec->shdr.sh_type != SHT_STRTAB) {
29800 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
29801
29802 static void read_symtabs(FILE *fp)
29803 {
29804 - int i,j;
29805 + unsigned int i,j;
29806 for (i = 0; i < ehdr.e_shnum; i++) {
29807 struct section *sec = &secs[i];
29808 if (sec->shdr.sh_type != SHT_SYMTAB) {
29809 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
29810 }
29811
29812
29813 -static void read_relocs(FILE *fp)
29814 +static void read_relocs(FILE *fp, int use_real_mode)
29815 {
29816 - int i,j;
29817 + unsigned int i,j;
29818 + uint32_t base;
29819 +
29820 for (i = 0; i < ehdr.e_shnum; i++) {
29821 struct section *sec = &secs[i];
29822 if (sec->shdr.sh_type != SHT_REL) {
29823 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
29824 die("Cannot read symbol table: %s\n",
29825 strerror(errno));
29826 }
29827 + base = 0;
29828 +
29829 +#ifdef CONFIG_X86_32
29830 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
29831 + if (phdr[j].p_type != PT_LOAD )
29832 + continue;
29833 + 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)
29834 + continue;
29835 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
29836 + break;
29837 + }
29838 +#endif
29839 +
29840 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
29841 Elf32_Rel *rel = &sec->reltab[j];
29842 - rel->r_offset = elf32_to_cpu(rel->r_offset);
29843 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
29844 rel->r_info = elf32_to_cpu(rel->r_info);
29845 }
29846 }
29847 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
29848
29849 static void print_absolute_symbols(void)
29850 {
29851 - int i;
29852 + unsigned int i;
29853 printf("Absolute symbols\n");
29854 printf(" Num: Value Size Type Bind Visibility Name\n");
29855 for (i = 0; i < ehdr.e_shnum; i++) {
29856 struct section *sec = &secs[i];
29857 char *sym_strtab;
29858 - int j;
29859 + unsigned int j;
29860
29861 if (sec->shdr.sh_type != SHT_SYMTAB) {
29862 continue;
29863 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
29864
29865 static void print_absolute_relocs(void)
29866 {
29867 - int i, printed = 0;
29868 + unsigned int i, printed = 0;
29869
29870 for (i = 0; i < ehdr.e_shnum; i++) {
29871 struct section *sec = &secs[i];
29872 struct section *sec_applies, *sec_symtab;
29873 char *sym_strtab;
29874 Elf32_Sym *sh_symtab;
29875 - int j;
29876 + unsigned int j;
29877 if (sec->shdr.sh_type != SHT_REL) {
29878 continue;
29879 }
29880 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
29881 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29882 int use_real_mode)
29883 {
29884 - int i;
29885 + unsigned int i;
29886 /* Walk through the relocations */
29887 for (i = 0; i < ehdr.e_shnum; i++) {
29888 char *sym_strtab;
29889 Elf32_Sym *sh_symtab;
29890 struct section *sec_applies, *sec_symtab;
29891 - int j;
29892 + unsigned int j;
29893 struct section *sec = &secs[i];
29894
29895 if (sec->shdr.sh_type != SHT_REL) {
29896 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
29897 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
29898 r_type = ELF32_R_TYPE(rel->r_info);
29899
29900 + if (!use_real_mode) {
29901 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
29902 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
29903 + continue;
29904 +
29905 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
29906 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
29907 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
29908 + continue;
29909 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
29910 + continue;
29911 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
29912 + continue;
29913 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
29914 + continue;
29915 +#endif
29916 + }
29917 +
29918 shn_abs = sym->st_shndx == SHN_ABS;
29919
29920 switch (r_type) {
29921 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
29922
29923 static void emit_relocs(int as_text, int use_real_mode)
29924 {
29925 - int i;
29926 + unsigned int i;
29927 /* Count how many relocations I have and allocate space for them. */
29928 reloc_count = 0;
29929 walk_relocs(count_reloc, use_real_mode);
29930 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
29931 fname, strerror(errno));
29932 }
29933 read_ehdr(fp);
29934 + read_phdrs(fp);
29935 read_shdrs(fp);
29936 read_strtabs(fp);
29937 read_symtabs(fp);
29938 - read_relocs(fp);
29939 + read_relocs(fp, use_real_mode);
29940 if (show_absolute_syms) {
29941 print_absolute_symbols();
29942 goto out;
29943 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
29944 index fd14be1..e3c79c0 100644
29945 --- a/arch/x86/vdso/Makefile
29946 +++ b/arch/x86/vdso/Makefile
29947 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
29948 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
29949 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
29950
29951 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29952 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
29953 GCOV_PROFILE := n
29954
29955 #
29956 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
29957 index 0faad64..39ef157 100644
29958 --- a/arch/x86/vdso/vdso32-setup.c
29959 +++ b/arch/x86/vdso/vdso32-setup.c
29960 @@ -25,6 +25,7 @@
29961 #include <asm/tlbflush.h>
29962 #include <asm/vdso.h>
29963 #include <asm/proto.h>
29964 +#include <asm/mman.h>
29965
29966 enum {
29967 VDSO_DISABLED = 0,
29968 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
29969 void enable_sep_cpu(void)
29970 {
29971 int cpu = get_cpu();
29972 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
29973 + struct tss_struct *tss = init_tss + cpu;
29974
29975 if (!boot_cpu_has(X86_FEATURE_SEP)) {
29976 put_cpu();
29977 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
29978 gate_vma.vm_start = FIXADDR_USER_START;
29979 gate_vma.vm_end = FIXADDR_USER_END;
29980 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29981 - gate_vma.vm_page_prot = __P101;
29982 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29983
29984 return 0;
29985 }
29986 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29987 if (compat)
29988 addr = VDSO_HIGH_BASE;
29989 else {
29990 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29991 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29992 if (IS_ERR_VALUE(addr)) {
29993 ret = addr;
29994 goto up_fail;
29995 }
29996 }
29997
29998 - current->mm->context.vdso = (void *)addr;
29999 + current->mm->context.vdso = addr;
30000
30001 if (compat_uses_vma || !compat) {
30002 /*
30003 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30004 }
30005
30006 current_thread_info()->sysenter_return =
30007 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30008 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
30009
30010 up_fail:
30011 if (ret)
30012 - current->mm->context.vdso = NULL;
30013 + current->mm->context.vdso = 0;
30014
30015 up_write(&mm->mmap_sem);
30016
30017 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
30018
30019 const char *arch_vma_name(struct vm_area_struct *vma)
30020 {
30021 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
30022 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
30023 return "[vdso]";
30024 +
30025 +#ifdef CONFIG_PAX_SEGMEXEC
30026 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
30027 + return "[vdso]";
30028 +#endif
30029 +
30030 return NULL;
30031 }
30032
30033 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
30034 * Check to see if the corresponding task was created in compat vdso
30035 * mode.
30036 */
30037 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
30038 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
30039 return &gate_vma;
30040 return NULL;
30041 }
30042 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
30043 index 431e875..cbb23f3 100644
30044 --- a/arch/x86/vdso/vma.c
30045 +++ b/arch/x86/vdso/vma.c
30046 @@ -16,8 +16,6 @@
30047 #include <asm/vdso.h>
30048 #include <asm/page.h>
30049
30050 -unsigned int __read_mostly vdso_enabled = 1;
30051 -
30052 extern char vdso_start[], vdso_end[];
30053 extern unsigned short vdso_sync_cpuid;
30054
30055 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
30056 * unaligned here as a result of stack start randomization.
30057 */
30058 addr = PAGE_ALIGN(addr);
30059 - addr = align_vdso_addr(addr);
30060
30061 return addr;
30062 }
30063 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
30064 unsigned size)
30065 {
30066 struct mm_struct *mm = current->mm;
30067 - unsigned long addr;
30068 + unsigned long addr = 0;
30069 int ret;
30070
30071 - if (!vdso_enabled)
30072 - return 0;
30073 -
30074 down_write(&mm->mmap_sem);
30075 +
30076 +#ifdef CONFIG_PAX_RANDMMAP
30077 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30078 +#endif
30079 +
30080 addr = vdso_addr(mm->start_stack, size);
30081 + addr = align_vdso_addr(addr);
30082 addr = get_unmapped_area(NULL, addr, size, 0, 0);
30083 if (IS_ERR_VALUE(addr)) {
30084 ret = addr;
30085 goto up_fail;
30086 }
30087
30088 - current->mm->context.vdso = (void *)addr;
30089 + mm->context.vdso = addr;
30090
30091 ret = install_special_mapping(mm, addr, size,
30092 VM_READ|VM_EXEC|
30093 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
30094 pages);
30095 - if (ret) {
30096 - current->mm->context.vdso = NULL;
30097 - goto up_fail;
30098 - }
30099 + if (ret)
30100 + mm->context.vdso = 0;
30101
30102 up_fail:
30103 up_write(&mm->mmap_sem);
30104 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
30105 vdsox32_size);
30106 }
30107 #endif
30108 -
30109 -static __init int vdso_setup(char *s)
30110 -{
30111 - vdso_enabled = simple_strtoul(s, NULL, 0);
30112 - return 0;
30113 -}
30114 -__setup("vdso=", vdso_setup);
30115 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
30116 index e014092..c76ab69 100644
30117 --- a/arch/x86/xen/enlighten.c
30118 +++ b/arch/x86/xen/enlighten.c
30119 @@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
30120
30121 struct shared_info xen_dummy_shared_info;
30122
30123 -void *xen_initial_gdt;
30124 -
30125 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
30126 __read_mostly int xen_have_vector_callback;
30127 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
30128 @@ -495,8 +493,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
30129 {
30130 unsigned long va = dtr->address;
30131 unsigned int size = dtr->size + 1;
30132 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30133 - unsigned long frames[pages];
30134 + unsigned long frames[65536 / PAGE_SIZE];
30135 int f;
30136
30137 /*
30138 @@ -544,8 +541,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
30139 {
30140 unsigned long va = dtr->address;
30141 unsigned int size = dtr->size + 1;
30142 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
30143 - unsigned long frames[pages];
30144 + unsigned long frames[65536 / PAGE_SIZE];
30145 int f;
30146
30147 /*
30148 @@ -938,7 +934,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
30149 return 0;
30150 }
30151
30152 -static void set_xen_basic_apic_ops(void)
30153 +static void __init set_xen_basic_apic_ops(void)
30154 {
30155 apic->read = xen_apic_read;
30156 apic->write = xen_apic_write;
30157 @@ -1244,30 +1240,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
30158 #endif
30159 };
30160
30161 -static void xen_reboot(int reason)
30162 +static __noreturn void xen_reboot(int reason)
30163 {
30164 struct sched_shutdown r = { .reason = reason };
30165
30166 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
30167 - BUG();
30168 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
30169 + BUG();
30170 }
30171
30172 -static void xen_restart(char *msg)
30173 +static __noreturn void xen_restart(char *msg)
30174 {
30175 xen_reboot(SHUTDOWN_reboot);
30176 }
30177
30178 -static void xen_emergency_restart(void)
30179 +static __noreturn void xen_emergency_restart(void)
30180 {
30181 xen_reboot(SHUTDOWN_reboot);
30182 }
30183
30184 -static void xen_machine_halt(void)
30185 +static __noreturn void xen_machine_halt(void)
30186 {
30187 xen_reboot(SHUTDOWN_poweroff);
30188 }
30189
30190 -static void xen_machine_power_off(void)
30191 +static __noreturn void xen_machine_power_off(void)
30192 {
30193 if (pm_power_off)
30194 pm_power_off();
30195 @@ -1369,7 +1365,17 @@ asmlinkage void __init xen_start_kernel(void)
30196 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
30197
30198 /* Work out if we support NX */
30199 - x86_configure_nx();
30200 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30201 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
30202 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
30203 + unsigned l, h;
30204 +
30205 + __supported_pte_mask |= _PAGE_NX;
30206 + rdmsr(MSR_EFER, l, h);
30207 + l |= EFER_NX;
30208 + wrmsr(MSR_EFER, l, h);
30209 + }
30210 +#endif
30211
30212 xen_setup_features();
30213
30214 @@ -1398,14 +1404,7 @@ asmlinkage void __init xen_start_kernel(void)
30215 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
30216 }
30217
30218 - machine_ops = xen_machine_ops;
30219 -
30220 - /*
30221 - * The only reliable way to retain the initial address of the
30222 - * percpu gdt_page is to remember it here, so we can go and
30223 - * mark it RW later, when the initial percpu area is freed.
30224 - */
30225 - xen_initial_gdt = &per_cpu(gdt_page, 0);
30226 + memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
30227
30228 xen_smp_init();
30229
30230 @@ -1590,7 +1589,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
30231 return NOTIFY_OK;
30232 }
30233
30234 -static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
30235 +static struct notifier_block xen_hvm_cpu_notifier = {
30236 .notifier_call = xen_hvm_cpu_notify,
30237 };
30238
30239 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
30240 index 01de35c..0bda07b 100644
30241 --- a/arch/x86/xen/mmu.c
30242 +++ b/arch/x86/xen/mmu.c
30243 @@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30244 /* L3_k[510] -> level2_kernel_pgt
30245 * L3_i[511] -> level2_fixmap_pgt */
30246 convert_pfn_mfn(level3_kernel_pgt);
30247 + convert_pfn_mfn(level3_vmalloc_start_pgt);
30248 + convert_pfn_mfn(level3_vmalloc_end_pgt);
30249 + convert_pfn_mfn(level3_vmemmap_pgt);
30250
30251 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
30252 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
30253 @@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
30254 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
30255 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
30256 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
30257 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
30258 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
30259 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
30260 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
30261 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
30262 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
30263 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
30264 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
30265
30266 @@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
30267 pv_mmu_ops.set_pud = xen_set_pud;
30268 #if PAGETABLE_LEVELS == 4
30269 pv_mmu_ops.set_pgd = xen_set_pgd;
30270 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
30271 #endif
30272
30273 /* This will work as long as patching hasn't happened yet
30274 @@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
30275 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
30276 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
30277 .set_pgd = xen_set_pgd_hyper,
30278 + .set_pgd_batched = xen_set_pgd_hyper,
30279
30280 .alloc_pud = xen_alloc_pmd_init,
30281 .release_pud = xen_release_pmd_init,
30282 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
30283 index 34bc4ce..c34aa24 100644
30284 --- a/arch/x86/xen/smp.c
30285 +++ b/arch/x86/xen/smp.c
30286 @@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
30287 {
30288 BUG_ON(smp_processor_id() != 0);
30289 native_smp_prepare_boot_cpu();
30290 -
30291 - /* We've switched to the "real" per-cpu gdt, so make sure the
30292 - old memory can be recycled */
30293 - make_lowmem_page_readwrite(xen_initial_gdt);
30294 -
30295 xen_filter_cpu_maps();
30296 xen_setup_vcpu_info_placement();
30297 }
30298 @@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
30299 gdt = get_cpu_gdt_table(cpu);
30300
30301 ctxt->flags = VGCF_IN_KERNEL;
30302 - ctxt->user_regs.ds = __USER_DS;
30303 - ctxt->user_regs.es = __USER_DS;
30304 + ctxt->user_regs.ds = __KERNEL_DS;
30305 + ctxt->user_regs.es = __KERNEL_DS;
30306 ctxt->user_regs.ss = __KERNEL_DS;
30307 #ifdef CONFIG_X86_32
30308 ctxt->user_regs.fs = __KERNEL_PERCPU;
30309 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
30310 + savesegment(gs, ctxt->user_regs.gs);
30311 #else
30312 ctxt->gs_base_kernel = per_cpu_offset(cpu);
30313 #endif
30314 @@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
30315 int rc;
30316
30317 per_cpu(current_task, cpu) = idle;
30318 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
30319 #ifdef CONFIG_X86_32
30320 irq_ctx_init(cpu);
30321 #else
30322 clear_tsk_thread_flag(idle, TIF_FORK);
30323 - per_cpu(kernel_stack, cpu) =
30324 - (unsigned long)task_stack_page(idle) -
30325 - KERNEL_STACK_OFFSET + THREAD_SIZE;
30326 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
30327 #endif
30328 xen_setup_runstate_info(cpu);
30329 xen_setup_timer(cpu);
30330 @@ -630,7 +624,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
30331
30332 void __init xen_smp_init(void)
30333 {
30334 - smp_ops = xen_smp_ops;
30335 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
30336 xen_fill_possible_map();
30337 xen_init_spinlocks();
30338 }
30339 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
30340 index 33ca6e4..0ded929 100644
30341 --- a/arch/x86/xen/xen-asm_32.S
30342 +++ b/arch/x86/xen/xen-asm_32.S
30343 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
30344 ESP_OFFSET=4 # bytes pushed onto stack
30345
30346 /*
30347 - * Store vcpu_info pointer for easy access. Do it this way to
30348 - * avoid having to reload %fs
30349 + * Store vcpu_info pointer for easy access.
30350 */
30351 #ifdef CONFIG_SMP
30352 - GET_THREAD_INFO(%eax)
30353 - movl %ss:TI_cpu(%eax), %eax
30354 - movl %ss:__per_cpu_offset(,%eax,4), %eax
30355 - mov %ss:xen_vcpu(%eax), %eax
30356 + push %fs
30357 + mov $(__KERNEL_PERCPU), %eax
30358 + mov %eax, %fs
30359 + mov PER_CPU_VAR(xen_vcpu), %eax
30360 + pop %fs
30361 #else
30362 movl %ss:xen_vcpu, %eax
30363 #endif
30364 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
30365 index 7faed58..ba4427c 100644
30366 --- a/arch/x86/xen/xen-head.S
30367 +++ b/arch/x86/xen/xen-head.S
30368 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
30369 #ifdef CONFIG_X86_32
30370 mov %esi,xen_start_info
30371 mov $init_thread_union+THREAD_SIZE,%esp
30372 +#ifdef CONFIG_SMP
30373 + movl $cpu_gdt_table,%edi
30374 + movl $__per_cpu_load,%eax
30375 + movw %ax,__KERNEL_PERCPU + 2(%edi)
30376 + rorl $16,%eax
30377 + movb %al,__KERNEL_PERCPU + 4(%edi)
30378 + movb %ah,__KERNEL_PERCPU + 7(%edi)
30379 + movl $__per_cpu_end - 1,%eax
30380 + subl $__per_cpu_start,%eax
30381 + movw %ax,__KERNEL_PERCPU + 0(%edi)
30382 +#endif
30383 #else
30384 mov %rsi,xen_start_info
30385 mov $init_thread_union+THREAD_SIZE,%rsp
30386 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
30387 index a95b417..b6dbd0b 100644
30388 --- a/arch/x86/xen/xen-ops.h
30389 +++ b/arch/x86/xen/xen-ops.h
30390 @@ -10,8 +10,6 @@
30391 extern const char xen_hypervisor_callback[];
30392 extern const char xen_failsafe_callback[];
30393
30394 -extern void *xen_initial_gdt;
30395 -
30396 struct trap_info;
30397 void xen_copy_trap_info(struct trap_info *traps);
30398
30399 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
30400 index 525bd3d..ef888b1 100644
30401 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
30402 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
30403 @@ -119,9 +119,9 @@
30404 ----------------------------------------------------------------------*/
30405
30406 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
30407 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
30408 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
30409 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
30410 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30411
30412 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
30413 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
30414 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
30415 index 2f33760..835e50a 100644
30416 --- a/arch/xtensa/variants/fsf/include/variant/core.h
30417 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
30418 @@ -11,6 +11,7 @@
30419 #ifndef _XTENSA_CORE_H
30420 #define _XTENSA_CORE_H
30421
30422 +#include <linux/const.h>
30423
30424 /****************************************************************************
30425 Parameters Useful for Any Code, USER or PRIVILEGED
30426 @@ -112,9 +113,9 @@
30427 ----------------------------------------------------------------------*/
30428
30429 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30430 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30431 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30432 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30433 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30434
30435 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
30436 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
30437 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
30438 index af00795..2bb8105 100644
30439 --- a/arch/xtensa/variants/s6000/include/variant/core.h
30440 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
30441 @@ -11,6 +11,7 @@
30442 #ifndef _XTENSA_CORE_CONFIGURATION_H
30443 #define _XTENSA_CORE_CONFIGURATION_H
30444
30445 +#include <linux/const.h>
30446
30447 /****************************************************************************
30448 Parameters Useful for Any Code, USER or PRIVILEGED
30449 @@ -118,9 +119,9 @@
30450 ----------------------------------------------------------------------*/
30451
30452 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
30453 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
30454 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
30455 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
30456 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
30457
30458 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
30459 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
30460 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
30461 index 58916af..eb9dbcf6 100644
30462 --- a/block/blk-iopoll.c
30463 +++ b/block/blk-iopoll.c
30464 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
30465 }
30466 EXPORT_SYMBOL(blk_iopoll_complete);
30467
30468 -static void blk_iopoll_softirq(struct softirq_action *h)
30469 +static void blk_iopoll_softirq(void)
30470 {
30471 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
30472 int rearm = 0, budget = blk_iopoll_budget;
30473 @@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
30474 return NOTIFY_OK;
30475 }
30476
30477 -static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
30478 +static struct notifier_block blk_iopoll_cpu_notifier = {
30479 .notifier_call = blk_iopoll_cpu_notify,
30480 };
30481
30482 diff --git a/block/blk-map.c b/block/blk-map.c
30483 index 623e1cd..ca1e109 100644
30484 --- a/block/blk-map.c
30485 +++ b/block/blk-map.c
30486 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
30487 if (!len || !kbuf)
30488 return -EINVAL;
30489
30490 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
30491 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
30492 if (do_copy)
30493 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
30494 else
30495 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
30496 index 467c8de..f3628c5 100644
30497 --- a/block/blk-softirq.c
30498 +++ b/block/blk-softirq.c
30499 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
30500 * Softirq action handler - move entries to local list and loop over them
30501 * while passing them to the queue registered handler.
30502 */
30503 -static void blk_done_softirq(struct softirq_action *h)
30504 +static void blk_done_softirq(void)
30505 {
30506 struct list_head *cpu_list, local_list;
30507
30508 @@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
30509 return NOTIFY_OK;
30510 }
30511
30512 -static struct notifier_block __cpuinitdata blk_cpu_notifier = {
30513 +static struct notifier_block blk_cpu_notifier = {
30514 .notifier_call = blk_cpu_notify,
30515 };
30516
30517 diff --git a/block/bsg.c b/block/bsg.c
30518 index ff64ae3..593560c 100644
30519 --- a/block/bsg.c
30520 +++ b/block/bsg.c
30521 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
30522 struct sg_io_v4 *hdr, struct bsg_device *bd,
30523 fmode_t has_write_perm)
30524 {
30525 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30526 + unsigned char *cmdptr;
30527 +
30528 if (hdr->request_len > BLK_MAX_CDB) {
30529 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
30530 if (!rq->cmd)
30531 return -ENOMEM;
30532 - }
30533 + cmdptr = rq->cmd;
30534 + } else
30535 + cmdptr = tmpcmd;
30536
30537 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
30538 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
30539 hdr->request_len))
30540 return -EFAULT;
30541
30542 + if (cmdptr != rq->cmd)
30543 + memcpy(rq->cmd, cmdptr, hdr->request_len);
30544 +
30545 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
30546 if (blk_verify_command(rq->cmd, has_write_perm))
30547 return -EPERM;
30548 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
30549 index 7c668c8..db3521c 100644
30550 --- a/block/compat_ioctl.c
30551 +++ b/block/compat_ioctl.c
30552 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
30553 err |= __get_user(f->spec1, &uf->spec1);
30554 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
30555 err |= __get_user(name, &uf->name);
30556 - f->name = compat_ptr(name);
30557 + f->name = (void __force_kernel *)compat_ptr(name);
30558 if (err) {
30559 err = -EFAULT;
30560 goto out;
30561 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
30562 index b62fb88..bdab4c4 100644
30563 --- a/block/partitions/efi.c
30564 +++ b/block/partitions/efi.c
30565 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
30566 if (!gpt)
30567 return NULL;
30568
30569 + if (!le32_to_cpu(gpt->num_partition_entries))
30570 + return NULL;
30571 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
30572 + if (!pte)
30573 + return NULL;
30574 +
30575 count = le32_to_cpu(gpt->num_partition_entries) *
30576 le32_to_cpu(gpt->sizeof_partition_entry);
30577 - if (!count)
30578 - return NULL;
30579 - pte = kzalloc(count, GFP_KERNEL);
30580 - if (!pte)
30581 - return NULL;
30582 -
30583 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
30584 (u8 *) pte,
30585 count) < count) {
30586 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
30587 index 9a87daa..fb17486 100644
30588 --- a/block/scsi_ioctl.c
30589 +++ b/block/scsi_ioctl.c
30590 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
30591 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
30592 struct sg_io_hdr *hdr, fmode_t mode)
30593 {
30594 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
30595 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30596 + unsigned char *cmdptr;
30597 +
30598 + if (rq->cmd != rq->__cmd)
30599 + cmdptr = rq->cmd;
30600 + else
30601 + cmdptr = tmpcmd;
30602 +
30603 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
30604 return -EFAULT;
30605 +
30606 + if (cmdptr != rq->cmd)
30607 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
30608 +
30609 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
30610 return -EPERM;
30611
30612 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30613 int err;
30614 unsigned int in_len, out_len, bytes, opcode, cmdlen;
30615 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
30616 + unsigned char tmpcmd[sizeof(rq->__cmd)];
30617 + unsigned char *cmdptr;
30618
30619 if (!sic)
30620 return -EINVAL;
30621 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
30622 */
30623 err = -EFAULT;
30624 rq->cmd_len = cmdlen;
30625 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
30626 +
30627 + if (rq->cmd != rq->__cmd)
30628 + cmdptr = rq->cmd;
30629 + else
30630 + cmdptr = tmpcmd;
30631 +
30632 + if (copy_from_user(cmdptr, sic->data, cmdlen))
30633 goto error;
30634
30635 + if (rq->cmd != cmdptr)
30636 + memcpy(rq->cmd, cmdptr, cmdlen);
30637 +
30638 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
30639 goto error;
30640
30641 diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
30642 index 533de95..7d4a8d2 100644
30643 --- a/crypto/ablkcipher.c
30644 +++ b/crypto/ablkcipher.c
30645 @@ -388,9 +388,9 @@ static int crypto_ablkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30646 {
30647 struct crypto_report_blkcipher rblkcipher;
30648
30649 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "ablkcipher");
30650 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30651 - alg->cra_ablkcipher.geniv ?: "<default>");
30652 + strncpy(rblkcipher.type, "ablkcipher", sizeof(rblkcipher.type));
30653 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<default>",
30654 + sizeof(rblkcipher.geniv));
30655
30656 rblkcipher.blocksize = alg->cra_blocksize;
30657 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30658 @@ -469,9 +469,9 @@ static int crypto_givcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30659 {
30660 struct crypto_report_blkcipher rblkcipher;
30661
30662 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "givcipher");
30663 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30664 - alg->cra_ablkcipher.geniv ?: "<built-in>");
30665 + strncpy(rblkcipher.type, "givcipher", sizeof(rblkcipher.type));
30666 + strncpy(rblkcipher.geniv, alg->cra_ablkcipher.geniv ?: "<built-in>",
30667 + sizeof(rblkcipher.geniv));
30668
30669 rblkcipher.blocksize = alg->cra_blocksize;
30670 rblkcipher.min_keysize = alg->cra_ablkcipher.min_keysize;
30671 diff --git a/crypto/aead.c b/crypto/aead.c
30672 index 0b8121e..27bc487 100644
30673 --- a/crypto/aead.c
30674 +++ b/crypto/aead.c
30675 @@ -117,9 +117,8 @@ static int crypto_aead_report(struct sk_buff *skb, struct crypto_alg *alg)
30676 struct crypto_report_aead raead;
30677 struct aead_alg *aead = &alg->cra_aead;
30678
30679 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "aead");
30680 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30681 - aead->geniv ?: "<built-in>");
30682 + strncpy(raead.type, "aead", sizeof(raead.type));
30683 + strncpy(raead.geniv, aead->geniv ?: "<built-in>", sizeof(raead.geniv));
30684
30685 raead.blocksize = alg->cra_blocksize;
30686 raead.maxauthsize = aead->maxauthsize;
30687 @@ -203,8 +202,8 @@ static int crypto_nivaead_report(struct sk_buff *skb, struct crypto_alg *alg)
30688 struct crypto_report_aead raead;
30689 struct aead_alg *aead = &alg->cra_aead;
30690
30691 - snprintf(raead.type, CRYPTO_MAX_ALG_NAME, "%s", "nivaead");
30692 - snprintf(raead.geniv, CRYPTO_MAX_ALG_NAME, "%s", aead->geniv);
30693 + strncpy(raead.type, "nivaead", sizeof(raead.type));
30694 + strncpy(raead.geniv, aead->geniv, sizeof(raead.geniv));
30695
30696 raead.blocksize = alg->cra_blocksize;
30697 raead.maxauthsize = aead->maxauthsize;
30698 diff --git a/crypto/ahash.c b/crypto/ahash.c
30699 index 3887856..793a27f 100644
30700 --- a/crypto/ahash.c
30701 +++ b/crypto/ahash.c
30702 @@ -404,7 +404,7 @@ static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
30703 {
30704 struct crypto_report_hash rhash;
30705
30706 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "ahash");
30707 + strncpy(rhash.type, "ahash", sizeof(rhash.type));
30708
30709 rhash.blocksize = alg->cra_blocksize;
30710 rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
30711 diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
30712 index a8d85a1..c44e014 100644
30713 --- a/crypto/blkcipher.c
30714 +++ b/crypto/blkcipher.c
30715 @@ -499,9 +499,9 @@ static int crypto_blkcipher_report(struct sk_buff *skb, struct crypto_alg *alg)
30716 {
30717 struct crypto_report_blkcipher rblkcipher;
30718
30719 - snprintf(rblkcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "blkcipher");
30720 - snprintf(rblkcipher.geniv, CRYPTO_MAX_ALG_NAME, "%s",
30721 - alg->cra_blkcipher.geniv ?: "<default>");
30722 + strncpy(rblkcipher.type, "blkcipher", sizeof(rblkcipher.type));
30723 + strncpy(rblkcipher.geniv, alg->cra_blkcipher.geniv ?: "<default>",
30724 + sizeof(rblkcipher.geniv));
30725
30726 rblkcipher.blocksize = alg->cra_blocksize;
30727 rblkcipher.min_keysize = alg->cra_blkcipher.min_keysize;
30728 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
30729 index 7bdd61b..afec999 100644
30730 --- a/crypto/cryptd.c
30731 +++ b/crypto/cryptd.c
30732 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
30733
30734 struct cryptd_blkcipher_request_ctx {
30735 crypto_completion_t complete;
30736 -};
30737 +} __no_const;
30738
30739 struct cryptd_hash_ctx {
30740 struct crypto_shash *child;
30741 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
30742
30743 struct cryptd_aead_request_ctx {
30744 crypto_completion_t complete;
30745 -};
30746 +} __no_const;
30747
30748 static void cryptd_queue_worker(struct work_struct *work);
30749
30750 diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c
30751 index 35d700a..dfd511f 100644
30752 --- a/crypto/crypto_user.c
30753 +++ b/crypto/crypto_user.c
30754 @@ -30,6 +30,8 @@
30755
30756 #include "internal.h"
30757
30758 +#define null_terminated(x) (strnlen(x, sizeof(x)) < sizeof(x))
30759 +
30760 static DEFINE_MUTEX(crypto_cfg_mutex);
30761
30762 /* The crypto netlink socket */
30763 @@ -75,7 +77,7 @@ static int crypto_report_cipher(struct sk_buff *skb, struct crypto_alg *alg)
30764 {
30765 struct crypto_report_cipher rcipher;
30766
30767 - snprintf(rcipher.type, CRYPTO_MAX_ALG_NAME, "%s", "cipher");
30768 + strncpy(rcipher.type, "cipher", sizeof(rcipher.type));
30769
30770 rcipher.blocksize = alg->cra_blocksize;
30771 rcipher.min_keysize = alg->cra_cipher.cia_min_keysize;
30772 @@ -94,8 +96,7 @@ static int crypto_report_comp(struct sk_buff *skb, struct crypto_alg *alg)
30773 {
30774 struct crypto_report_comp rcomp;
30775
30776 - snprintf(rcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "compression");
30777 -
30778 + strncpy(rcomp.type, "compression", sizeof(rcomp.type));
30779 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30780 sizeof(struct crypto_report_comp), &rcomp))
30781 goto nla_put_failure;
30782 @@ -108,12 +109,14 @@ nla_put_failure:
30783 static int crypto_report_one(struct crypto_alg *alg,
30784 struct crypto_user_alg *ualg, struct sk_buff *skb)
30785 {
30786 - memcpy(&ualg->cru_name, &alg->cra_name, sizeof(ualg->cru_name));
30787 - memcpy(&ualg->cru_driver_name, &alg->cra_driver_name,
30788 - sizeof(ualg->cru_driver_name));
30789 - memcpy(&ualg->cru_module_name, module_name(alg->cra_module),
30790 - CRYPTO_MAX_ALG_NAME);
30791 + strncpy(ualg->cru_name, alg->cra_name, sizeof(ualg->cru_name));
30792 + strncpy(ualg->cru_driver_name, alg->cra_driver_name,
30793 + sizeof(ualg->cru_driver_name));
30794 + strncpy(ualg->cru_module_name, module_name(alg->cra_module),
30795 + sizeof(ualg->cru_module_name));
30796
30797 + ualg->cru_type = 0;
30798 + ualg->cru_mask = 0;
30799 ualg->cru_flags = alg->cra_flags;
30800 ualg->cru_refcnt = atomic_read(&alg->cra_refcnt);
30801
30802 @@ -122,8 +125,7 @@ static int crypto_report_one(struct crypto_alg *alg,
30803 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
30804 struct crypto_report_larval rl;
30805
30806 - snprintf(rl.type, CRYPTO_MAX_ALG_NAME, "%s", "larval");
30807 -
30808 + strncpy(rl.type, "larval", sizeof(rl.type));
30809 if (nla_put(skb, CRYPTOCFGA_REPORT_LARVAL,
30810 sizeof(struct crypto_report_larval), &rl))
30811 goto nla_put_failure;
30812 @@ -196,7 +198,10 @@ static int crypto_report(struct sk_buff *in_skb, struct nlmsghdr *in_nlh,
30813 struct crypto_dump_info info;
30814 int err;
30815
30816 - if (!p->cru_driver_name)
30817 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30818 + return -EINVAL;
30819 +
30820 + if (!p->cru_driver_name[0])
30821 return -EINVAL;
30822
30823 alg = crypto_alg_match(p, 1);
30824 @@ -260,6 +265,9 @@ static int crypto_update_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30825 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30826 LIST_HEAD(list);
30827
30828 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30829 + return -EINVAL;
30830 +
30831 if (priority && !strlen(p->cru_driver_name))
30832 return -EINVAL;
30833
30834 @@ -287,6 +295,9 @@ static int crypto_del_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30835 struct crypto_alg *alg;
30836 struct crypto_user_alg *p = nlmsg_data(nlh);
30837
30838 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30839 + return -EINVAL;
30840 +
30841 alg = crypto_alg_match(p, 1);
30842 if (!alg)
30843 return -ENOENT;
30844 @@ -368,6 +379,9 @@ static int crypto_add_alg(struct sk_buff *skb, struct nlmsghdr *nlh,
30845 struct crypto_user_alg *p = nlmsg_data(nlh);
30846 struct nlattr *priority = attrs[CRYPTOCFGA_PRIORITY_VAL];
30847
30848 + if (!null_terminated(p->cru_name) || !null_terminated(p->cru_driver_name))
30849 + return -EINVAL;
30850 +
30851 if (strlen(p->cru_driver_name))
30852 exact = 1;
30853
30854 diff --git a/crypto/pcompress.c b/crypto/pcompress.c
30855 index 04e083f..7140fe7 100644
30856 --- a/crypto/pcompress.c
30857 +++ b/crypto/pcompress.c
30858 @@ -53,8 +53,7 @@ static int crypto_pcomp_report(struct sk_buff *skb, struct crypto_alg *alg)
30859 {
30860 struct crypto_report_comp rpcomp;
30861
30862 - snprintf(rpcomp.type, CRYPTO_MAX_ALG_NAME, "%s", "pcomp");
30863 -
30864 + strncpy(rpcomp.type, "pcomp", sizeof(rpcomp.type));
30865 if (nla_put(skb, CRYPTOCFGA_REPORT_COMPRESS,
30866 sizeof(struct crypto_report_comp), &rpcomp))
30867 goto nla_put_failure;
30868 diff --git a/crypto/rng.c b/crypto/rng.c
30869 index f3b7894..e0a25c2 100644
30870 --- a/crypto/rng.c
30871 +++ b/crypto/rng.c
30872 @@ -65,7 +65,7 @@ static int crypto_rng_report(struct sk_buff *skb, struct crypto_alg *alg)
30873 {
30874 struct crypto_report_rng rrng;
30875
30876 - snprintf(rrng.type, CRYPTO_MAX_ALG_NAME, "%s", "rng");
30877 + strncpy(rrng.type, "rng", sizeof(rrng.type));
30878
30879 rrng.seedsize = alg->cra_rng.seedsize;
30880
30881 diff --git a/crypto/shash.c b/crypto/shash.c
30882 index f426330f..929058a 100644
30883 --- a/crypto/shash.c
30884 +++ b/crypto/shash.c
30885 @@ -530,7 +530,8 @@ static int crypto_shash_report(struct sk_buff *skb, struct crypto_alg *alg)
30886 struct crypto_report_hash rhash;
30887 struct shash_alg *salg = __crypto_shash_alg(alg);
30888
30889 - snprintf(rhash.type, CRYPTO_MAX_ALG_NAME, "%s", "shash");
30890 + strncpy(rhash.type, "shash", sizeof(rhash.type));
30891 +
30892 rhash.blocksize = alg->cra_blocksize;
30893 rhash.digestsize = salg->digestsize;
30894
30895 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
30896 index e6defd8..c26a225 100644
30897 --- a/drivers/acpi/apei/cper.c
30898 +++ b/drivers/acpi/apei/cper.c
30899 @@ -38,12 +38,12 @@
30900 */
30901 u64 cper_next_record_id(void)
30902 {
30903 - static atomic64_t seq;
30904 + static atomic64_unchecked_t seq;
30905
30906 - if (!atomic64_read(&seq))
30907 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
30908 + if (!atomic64_read_unchecked(&seq))
30909 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
30910
30911 - return atomic64_inc_return(&seq);
30912 + return atomic64_inc_return_unchecked(&seq);
30913 }
30914 EXPORT_SYMBOL_GPL(cper_next_record_id);
30915
30916 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
30917 index 7586544..636a2f0 100644
30918 --- a/drivers/acpi/ec_sys.c
30919 +++ b/drivers/acpi/ec_sys.c
30920 @@ -12,6 +12,7 @@
30921 #include <linux/acpi.h>
30922 #include <linux/debugfs.h>
30923 #include <linux/module.h>
30924 +#include <linux/uaccess.h>
30925 #include "internal.h"
30926
30927 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
30928 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30929 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
30930 */
30931 unsigned int size = EC_SPACE_SIZE;
30932 - u8 *data = (u8 *) buf;
30933 + u8 data;
30934 loff_t init_off = *off;
30935 int err = 0;
30936
30937 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
30938 size = count;
30939
30940 while (size) {
30941 - err = ec_read(*off, &data[*off - init_off]);
30942 + err = ec_read(*off, &data);
30943 if (err)
30944 return err;
30945 + if (put_user(data, &buf[*off - init_off]))
30946 + return -EFAULT;
30947 *off += 1;
30948 size--;
30949 }
30950 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30951
30952 unsigned int size = count;
30953 loff_t init_off = *off;
30954 - u8 *data = (u8 *) buf;
30955 int err = 0;
30956
30957 if (*off >= EC_SPACE_SIZE)
30958 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
30959 }
30960
30961 while (size) {
30962 - u8 byte_write = data[*off - init_off];
30963 + u8 byte_write;
30964 + if (get_user(byte_write, &buf[*off - init_off]))
30965 + return -EFAULT;
30966 err = ec_write(*off, byte_write);
30967 if (err)
30968 return err;
30969 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
30970 index e83311b..142b5cc 100644
30971 --- a/drivers/acpi/processor_driver.c
30972 +++ b/drivers/acpi/processor_driver.c
30973 @@ -558,7 +558,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
30974 return 0;
30975 #endif
30976
30977 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
30978 + BUG_ON(pr->id >= nr_cpu_ids);
30979
30980 /*
30981 * Buggy BIOS check
30982 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
30983 index 46cd3f4..0871ad0 100644
30984 --- a/drivers/ata/libata-core.c
30985 +++ b/drivers/ata/libata-core.c
30986 @@ -4780,7 +4780,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
30987 struct ata_port *ap;
30988 unsigned int tag;
30989
30990 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30991 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30992 ap = qc->ap;
30993
30994 qc->flags = 0;
30995 @@ -4796,7 +4796,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30996 struct ata_port *ap;
30997 struct ata_link *link;
30998
30999 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31000 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31001 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
31002 ap = qc->ap;
31003 link = qc->dev->link;
31004 @@ -5892,6 +5892,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31005 return;
31006
31007 spin_lock(&lock);
31008 + pax_open_kernel();
31009
31010 for (cur = ops->inherits; cur; cur = cur->inherits) {
31011 void **inherit = (void **)cur;
31012 @@ -5905,8 +5906,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
31013 if (IS_ERR(*pp))
31014 *pp = NULL;
31015
31016 - ops->inherits = NULL;
31017 + *(struct ata_port_operations **)&ops->inherits = NULL;
31018
31019 + pax_close_kernel();
31020 spin_unlock(&lock);
31021 }
31022
31023 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
31024 index 405022d..fb70e53 100644
31025 --- a/drivers/ata/pata_arasan_cf.c
31026 +++ b/drivers/ata/pata_arasan_cf.c
31027 @@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
31028 /* Handle platform specific quirks */
31029 if (pdata->quirk) {
31030 if (pdata->quirk & CF_BROKEN_PIO) {
31031 - ap->ops->set_piomode = NULL;
31032 + pax_open_kernel();
31033 + *(void **)&ap->ops->set_piomode = NULL;
31034 + pax_close_kernel();
31035 ap->pio_mask = 0;
31036 }
31037 if (pdata->quirk & CF_BROKEN_MWDMA)
31038 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
31039 index f9b983a..887b9d8 100644
31040 --- a/drivers/atm/adummy.c
31041 +++ b/drivers/atm/adummy.c
31042 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
31043 vcc->pop(vcc, skb);
31044 else
31045 dev_kfree_skb_any(skb);
31046 - atomic_inc(&vcc->stats->tx);
31047 + atomic_inc_unchecked(&vcc->stats->tx);
31048
31049 return 0;
31050 }
31051 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
31052 index 77a7480..05cde58 100644
31053 --- a/drivers/atm/ambassador.c
31054 +++ b/drivers/atm/ambassador.c
31055 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
31056 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
31057
31058 // VC layer stats
31059 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31060 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31061
31062 // free the descriptor
31063 kfree (tx_descr);
31064 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31065 dump_skb ("<<<", vc, skb);
31066
31067 // VC layer stats
31068 - atomic_inc(&atm_vcc->stats->rx);
31069 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31070 __net_timestamp(skb);
31071 // end of our responsibility
31072 atm_vcc->push (atm_vcc, skb);
31073 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
31074 } else {
31075 PRINTK (KERN_INFO, "dropped over-size frame");
31076 // should we count this?
31077 - atomic_inc(&atm_vcc->stats->rx_drop);
31078 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31079 }
31080
31081 } else {
31082 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
31083 }
31084
31085 if (check_area (skb->data, skb->len)) {
31086 - atomic_inc(&atm_vcc->stats->tx_err);
31087 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
31088 return -ENOMEM; // ?
31089 }
31090
31091 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
31092 index b22d71c..d6e1049 100644
31093 --- a/drivers/atm/atmtcp.c
31094 +++ b/drivers/atm/atmtcp.c
31095 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31096 if (vcc->pop) vcc->pop(vcc,skb);
31097 else dev_kfree_skb(skb);
31098 if (dev_data) return 0;
31099 - atomic_inc(&vcc->stats->tx_err);
31100 + atomic_inc_unchecked(&vcc->stats->tx_err);
31101 return -ENOLINK;
31102 }
31103 size = skb->len+sizeof(struct atmtcp_hdr);
31104 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31105 if (!new_skb) {
31106 if (vcc->pop) vcc->pop(vcc,skb);
31107 else dev_kfree_skb(skb);
31108 - atomic_inc(&vcc->stats->tx_err);
31109 + atomic_inc_unchecked(&vcc->stats->tx_err);
31110 return -ENOBUFS;
31111 }
31112 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
31113 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
31114 if (vcc->pop) vcc->pop(vcc,skb);
31115 else dev_kfree_skb(skb);
31116 out_vcc->push(out_vcc,new_skb);
31117 - atomic_inc(&vcc->stats->tx);
31118 - atomic_inc(&out_vcc->stats->rx);
31119 + atomic_inc_unchecked(&vcc->stats->tx);
31120 + atomic_inc_unchecked(&out_vcc->stats->rx);
31121 return 0;
31122 }
31123
31124 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31125 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
31126 read_unlock(&vcc_sklist_lock);
31127 if (!out_vcc) {
31128 - atomic_inc(&vcc->stats->tx_err);
31129 + atomic_inc_unchecked(&vcc->stats->tx_err);
31130 goto done;
31131 }
31132 skb_pull(skb,sizeof(struct atmtcp_hdr));
31133 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
31134 __net_timestamp(new_skb);
31135 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
31136 out_vcc->push(out_vcc,new_skb);
31137 - atomic_inc(&vcc->stats->tx);
31138 - atomic_inc(&out_vcc->stats->rx);
31139 + atomic_inc_unchecked(&vcc->stats->tx);
31140 + atomic_inc_unchecked(&out_vcc->stats->rx);
31141 done:
31142 if (vcc->pop) vcc->pop(vcc,skb);
31143 else dev_kfree_skb(skb);
31144 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
31145 index c1eb6fa..4c71be9 100644
31146 --- a/drivers/atm/eni.c
31147 +++ b/drivers/atm/eni.c
31148 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
31149 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
31150 vcc->dev->number);
31151 length = 0;
31152 - atomic_inc(&vcc->stats->rx_err);
31153 + atomic_inc_unchecked(&vcc->stats->rx_err);
31154 }
31155 else {
31156 length = ATM_CELL_SIZE-1; /* no HEC */
31157 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31158 size);
31159 }
31160 eff = length = 0;
31161 - atomic_inc(&vcc->stats->rx_err);
31162 + atomic_inc_unchecked(&vcc->stats->rx_err);
31163 }
31164 else {
31165 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
31166 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
31167 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
31168 vcc->dev->number,vcc->vci,length,size << 2,descr);
31169 length = eff = 0;
31170 - atomic_inc(&vcc->stats->rx_err);
31171 + atomic_inc_unchecked(&vcc->stats->rx_err);
31172 }
31173 }
31174 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
31175 @@ -767,7 +767,7 @@ rx_dequeued++;
31176 vcc->push(vcc,skb);
31177 pushed++;
31178 }
31179 - atomic_inc(&vcc->stats->rx);
31180 + atomic_inc_unchecked(&vcc->stats->rx);
31181 }
31182 wake_up(&eni_dev->rx_wait);
31183 }
31184 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
31185 PCI_DMA_TODEVICE);
31186 if (vcc->pop) vcc->pop(vcc,skb);
31187 else dev_kfree_skb_irq(skb);
31188 - atomic_inc(&vcc->stats->tx);
31189 + atomic_inc_unchecked(&vcc->stats->tx);
31190 wake_up(&eni_dev->tx_wait);
31191 dma_complete++;
31192 }
31193 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
31194 index b41c948..a002b17 100644
31195 --- a/drivers/atm/firestream.c
31196 +++ b/drivers/atm/firestream.c
31197 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
31198 }
31199 }
31200
31201 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31202 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31203
31204 fs_dprintk (FS_DEBUG_TXMEM, "i");
31205 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
31206 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31207 #endif
31208 skb_put (skb, qe->p1 & 0xffff);
31209 ATM_SKB(skb)->vcc = atm_vcc;
31210 - atomic_inc(&atm_vcc->stats->rx);
31211 + atomic_inc_unchecked(&atm_vcc->stats->rx);
31212 __net_timestamp(skb);
31213 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
31214 atm_vcc->push (atm_vcc, skb);
31215 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
31216 kfree (pe);
31217 }
31218 if (atm_vcc)
31219 - atomic_inc(&atm_vcc->stats->rx_drop);
31220 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31221 break;
31222 case 0x1f: /* Reassembly abort: no buffers. */
31223 /* Silently increment error counter. */
31224 if (atm_vcc)
31225 - atomic_inc(&atm_vcc->stats->rx_drop);
31226 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
31227 break;
31228 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
31229 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
31230 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
31231 index 204814e..cede831 100644
31232 --- a/drivers/atm/fore200e.c
31233 +++ b/drivers/atm/fore200e.c
31234 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
31235 #endif
31236 /* check error condition */
31237 if (*entry->status & STATUS_ERROR)
31238 - atomic_inc(&vcc->stats->tx_err);
31239 + atomic_inc_unchecked(&vcc->stats->tx_err);
31240 else
31241 - atomic_inc(&vcc->stats->tx);
31242 + atomic_inc_unchecked(&vcc->stats->tx);
31243 }
31244 }
31245
31246 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31247 if (skb == NULL) {
31248 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
31249
31250 - atomic_inc(&vcc->stats->rx_drop);
31251 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31252 return -ENOMEM;
31253 }
31254
31255 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
31256
31257 dev_kfree_skb_any(skb);
31258
31259 - atomic_inc(&vcc->stats->rx_drop);
31260 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31261 return -ENOMEM;
31262 }
31263
31264 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31265
31266 vcc->push(vcc, skb);
31267 - atomic_inc(&vcc->stats->rx);
31268 + atomic_inc_unchecked(&vcc->stats->rx);
31269
31270 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
31271
31272 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
31273 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
31274 fore200e->atm_dev->number,
31275 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
31276 - atomic_inc(&vcc->stats->rx_err);
31277 + atomic_inc_unchecked(&vcc->stats->rx_err);
31278 }
31279 }
31280
31281 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
31282 goto retry_here;
31283 }
31284
31285 - atomic_inc(&vcc->stats->tx_err);
31286 + atomic_inc_unchecked(&vcc->stats->tx_err);
31287
31288 fore200e->tx_sat++;
31289 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
31290 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
31291 index 72b6960..cf9167a 100644
31292 --- a/drivers/atm/he.c
31293 +++ b/drivers/atm/he.c
31294 @@ -1699,7 +1699,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31295
31296 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
31297 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
31298 - atomic_inc(&vcc->stats->rx_drop);
31299 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31300 goto return_host_buffers;
31301 }
31302
31303 @@ -1726,7 +1726,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31304 RBRQ_LEN_ERR(he_dev->rbrq_head)
31305 ? "LEN_ERR" : "",
31306 vcc->vpi, vcc->vci);
31307 - atomic_inc(&vcc->stats->rx_err);
31308 + atomic_inc_unchecked(&vcc->stats->rx_err);
31309 goto return_host_buffers;
31310 }
31311
31312 @@ -1778,7 +1778,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
31313 vcc->push(vcc, skb);
31314 spin_lock(&he_dev->global_lock);
31315
31316 - atomic_inc(&vcc->stats->rx);
31317 + atomic_inc_unchecked(&vcc->stats->rx);
31318
31319 return_host_buffers:
31320 ++pdus_assembled;
31321 @@ -2104,7 +2104,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
31322 tpd->vcc->pop(tpd->vcc, tpd->skb);
31323 else
31324 dev_kfree_skb_any(tpd->skb);
31325 - atomic_inc(&tpd->vcc->stats->tx_err);
31326 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
31327 }
31328 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
31329 return;
31330 @@ -2516,7 +2516,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31331 vcc->pop(vcc, skb);
31332 else
31333 dev_kfree_skb_any(skb);
31334 - atomic_inc(&vcc->stats->tx_err);
31335 + atomic_inc_unchecked(&vcc->stats->tx_err);
31336 return -EINVAL;
31337 }
31338
31339 @@ -2527,7 +2527,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31340 vcc->pop(vcc, skb);
31341 else
31342 dev_kfree_skb_any(skb);
31343 - atomic_inc(&vcc->stats->tx_err);
31344 + atomic_inc_unchecked(&vcc->stats->tx_err);
31345 return -EINVAL;
31346 }
31347 #endif
31348 @@ -2539,7 +2539,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31349 vcc->pop(vcc, skb);
31350 else
31351 dev_kfree_skb_any(skb);
31352 - atomic_inc(&vcc->stats->tx_err);
31353 + atomic_inc_unchecked(&vcc->stats->tx_err);
31354 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31355 return -ENOMEM;
31356 }
31357 @@ -2581,7 +2581,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31358 vcc->pop(vcc, skb);
31359 else
31360 dev_kfree_skb_any(skb);
31361 - atomic_inc(&vcc->stats->tx_err);
31362 + atomic_inc_unchecked(&vcc->stats->tx_err);
31363 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31364 return -ENOMEM;
31365 }
31366 @@ -2612,7 +2612,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
31367 __enqueue_tpd(he_dev, tpd, cid);
31368 spin_unlock_irqrestore(&he_dev->global_lock, flags);
31369
31370 - atomic_inc(&vcc->stats->tx);
31371 + atomic_inc_unchecked(&vcc->stats->tx);
31372
31373 return 0;
31374 }
31375 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
31376 index 1dc0519..1aadaf7 100644
31377 --- a/drivers/atm/horizon.c
31378 +++ b/drivers/atm/horizon.c
31379 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
31380 {
31381 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
31382 // VC layer stats
31383 - atomic_inc(&vcc->stats->rx);
31384 + atomic_inc_unchecked(&vcc->stats->rx);
31385 __net_timestamp(skb);
31386 // end of our responsibility
31387 vcc->push (vcc, skb);
31388 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
31389 dev->tx_iovec = NULL;
31390
31391 // VC layer stats
31392 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
31393 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
31394
31395 // free the skb
31396 hrz_kfree_skb (skb);
31397 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
31398 index 272f009..a18ba55 100644
31399 --- a/drivers/atm/idt77252.c
31400 +++ b/drivers/atm/idt77252.c
31401 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
31402 else
31403 dev_kfree_skb(skb);
31404
31405 - atomic_inc(&vcc->stats->tx);
31406 + atomic_inc_unchecked(&vcc->stats->tx);
31407 }
31408
31409 atomic_dec(&scq->used);
31410 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31411 if ((sb = dev_alloc_skb(64)) == NULL) {
31412 printk("%s: Can't allocate buffers for aal0.\n",
31413 card->name);
31414 - atomic_add(i, &vcc->stats->rx_drop);
31415 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31416 break;
31417 }
31418 if (!atm_charge(vcc, sb->truesize)) {
31419 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
31420 card->name);
31421 - atomic_add(i - 1, &vcc->stats->rx_drop);
31422 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
31423 dev_kfree_skb(sb);
31424 break;
31425 }
31426 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31427 ATM_SKB(sb)->vcc = vcc;
31428 __net_timestamp(sb);
31429 vcc->push(vcc, sb);
31430 - atomic_inc(&vcc->stats->rx);
31431 + atomic_inc_unchecked(&vcc->stats->rx);
31432
31433 cell += ATM_CELL_PAYLOAD;
31434 }
31435 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31436 "(CDC: %08x)\n",
31437 card->name, len, rpp->len, readl(SAR_REG_CDC));
31438 recycle_rx_pool_skb(card, rpp);
31439 - atomic_inc(&vcc->stats->rx_err);
31440 + atomic_inc_unchecked(&vcc->stats->rx_err);
31441 return;
31442 }
31443 if (stat & SAR_RSQE_CRC) {
31444 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
31445 recycle_rx_pool_skb(card, rpp);
31446 - atomic_inc(&vcc->stats->rx_err);
31447 + atomic_inc_unchecked(&vcc->stats->rx_err);
31448 return;
31449 }
31450 if (skb_queue_len(&rpp->queue) > 1) {
31451 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31452 RXPRINTK("%s: Can't alloc RX skb.\n",
31453 card->name);
31454 recycle_rx_pool_skb(card, rpp);
31455 - atomic_inc(&vcc->stats->rx_err);
31456 + atomic_inc_unchecked(&vcc->stats->rx_err);
31457 return;
31458 }
31459 if (!atm_charge(vcc, skb->truesize)) {
31460 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31461 __net_timestamp(skb);
31462
31463 vcc->push(vcc, skb);
31464 - atomic_inc(&vcc->stats->rx);
31465 + atomic_inc_unchecked(&vcc->stats->rx);
31466
31467 return;
31468 }
31469 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
31470 __net_timestamp(skb);
31471
31472 vcc->push(vcc, skb);
31473 - atomic_inc(&vcc->stats->rx);
31474 + atomic_inc_unchecked(&vcc->stats->rx);
31475
31476 if (skb->truesize > SAR_FB_SIZE_3)
31477 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
31478 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
31479 if (vcc->qos.aal != ATM_AAL0) {
31480 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
31481 card->name, vpi, vci);
31482 - atomic_inc(&vcc->stats->rx_drop);
31483 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31484 goto drop;
31485 }
31486
31487 if ((sb = dev_alloc_skb(64)) == NULL) {
31488 printk("%s: Can't allocate buffers for AAL0.\n",
31489 card->name);
31490 - atomic_inc(&vcc->stats->rx_err);
31491 + atomic_inc_unchecked(&vcc->stats->rx_err);
31492 goto drop;
31493 }
31494
31495 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
31496 ATM_SKB(sb)->vcc = vcc;
31497 __net_timestamp(sb);
31498 vcc->push(vcc, sb);
31499 - atomic_inc(&vcc->stats->rx);
31500 + atomic_inc_unchecked(&vcc->stats->rx);
31501
31502 drop:
31503 skb_pull(queue, 64);
31504 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31505
31506 if (vc == NULL) {
31507 printk("%s: NULL connection in send().\n", card->name);
31508 - atomic_inc(&vcc->stats->tx_err);
31509 + atomic_inc_unchecked(&vcc->stats->tx_err);
31510 dev_kfree_skb(skb);
31511 return -EINVAL;
31512 }
31513 if (!test_bit(VCF_TX, &vc->flags)) {
31514 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
31515 - atomic_inc(&vcc->stats->tx_err);
31516 + atomic_inc_unchecked(&vcc->stats->tx_err);
31517 dev_kfree_skb(skb);
31518 return -EINVAL;
31519 }
31520 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31521 break;
31522 default:
31523 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
31524 - atomic_inc(&vcc->stats->tx_err);
31525 + atomic_inc_unchecked(&vcc->stats->tx_err);
31526 dev_kfree_skb(skb);
31527 return -EINVAL;
31528 }
31529
31530 if (skb_shinfo(skb)->nr_frags != 0) {
31531 printk("%s: No scatter-gather yet.\n", card->name);
31532 - atomic_inc(&vcc->stats->tx_err);
31533 + atomic_inc_unchecked(&vcc->stats->tx_err);
31534 dev_kfree_skb(skb);
31535 return -EINVAL;
31536 }
31537 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
31538
31539 err = queue_skb(card, vc, skb, oam);
31540 if (err) {
31541 - atomic_inc(&vcc->stats->tx_err);
31542 + atomic_inc_unchecked(&vcc->stats->tx_err);
31543 dev_kfree_skb(skb);
31544 return err;
31545 }
31546 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
31547 skb = dev_alloc_skb(64);
31548 if (!skb) {
31549 printk("%s: Out of memory in send_oam().\n", card->name);
31550 - atomic_inc(&vcc->stats->tx_err);
31551 + atomic_inc_unchecked(&vcc->stats->tx_err);
31552 return -ENOMEM;
31553 }
31554 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
31555 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
31556 index 4217f29..88f547a 100644
31557 --- a/drivers/atm/iphase.c
31558 +++ b/drivers/atm/iphase.c
31559 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
31560 status = (u_short) (buf_desc_ptr->desc_mode);
31561 if (status & (RX_CER | RX_PTE | RX_OFL))
31562 {
31563 - atomic_inc(&vcc->stats->rx_err);
31564 + atomic_inc_unchecked(&vcc->stats->rx_err);
31565 IF_ERR(printk("IA: bad packet, dropping it");)
31566 if (status & RX_CER) {
31567 IF_ERR(printk(" cause: packet CRC error\n");)
31568 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
31569 len = dma_addr - buf_addr;
31570 if (len > iadev->rx_buf_sz) {
31571 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
31572 - atomic_inc(&vcc->stats->rx_err);
31573 + atomic_inc_unchecked(&vcc->stats->rx_err);
31574 goto out_free_desc;
31575 }
31576
31577 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31578 ia_vcc = INPH_IA_VCC(vcc);
31579 if (ia_vcc == NULL)
31580 {
31581 - atomic_inc(&vcc->stats->rx_err);
31582 + atomic_inc_unchecked(&vcc->stats->rx_err);
31583 atm_return(vcc, skb->truesize);
31584 dev_kfree_skb_any(skb);
31585 goto INCR_DLE;
31586 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31587 if ((length > iadev->rx_buf_sz) || (length >
31588 (skb->len - sizeof(struct cpcs_trailer))))
31589 {
31590 - atomic_inc(&vcc->stats->rx_err);
31591 + atomic_inc_unchecked(&vcc->stats->rx_err);
31592 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
31593 length, skb->len);)
31594 atm_return(vcc, skb->truesize);
31595 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
31596
31597 IF_RX(printk("rx_dle_intr: skb push");)
31598 vcc->push(vcc,skb);
31599 - atomic_inc(&vcc->stats->rx);
31600 + atomic_inc_unchecked(&vcc->stats->rx);
31601 iadev->rx_pkt_cnt++;
31602 }
31603 INCR_DLE:
31604 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
31605 {
31606 struct k_sonet_stats *stats;
31607 stats = &PRIV(_ia_dev[board])->sonet_stats;
31608 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
31609 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
31610 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
31611 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
31612 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
31613 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
31614 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
31615 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
31616 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
31617 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
31618 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
31619 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
31620 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
31621 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
31622 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
31623 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
31624 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
31625 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
31626 }
31627 ia_cmds.status = 0;
31628 break;
31629 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31630 if ((desc == 0) || (desc > iadev->num_tx_desc))
31631 {
31632 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
31633 - atomic_inc(&vcc->stats->tx);
31634 + atomic_inc_unchecked(&vcc->stats->tx);
31635 if (vcc->pop)
31636 vcc->pop(vcc, skb);
31637 else
31638 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
31639 ATM_DESC(skb) = vcc->vci;
31640 skb_queue_tail(&iadev->tx_dma_q, skb);
31641
31642 - atomic_inc(&vcc->stats->tx);
31643 + atomic_inc_unchecked(&vcc->stats->tx);
31644 iadev->tx_pkt_cnt++;
31645 /* Increment transaction counter */
31646 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
31647
31648 #if 0
31649 /* add flow control logic */
31650 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
31651 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
31652 if (iavcc->vc_desc_cnt > 10) {
31653 vcc->tx_quota = vcc->tx_quota * 3 / 4;
31654 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
31655 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
31656 index fa7d701..1e404c7 100644
31657 --- a/drivers/atm/lanai.c
31658 +++ b/drivers/atm/lanai.c
31659 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
31660 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
31661 lanai_endtx(lanai, lvcc);
31662 lanai_free_skb(lvcc->tx.atmvcc, skb);
31663 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
31664 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
31665 }
31666
31667 /* Try to fill the buffer - don't call unless there is backlog */
31668 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
31669 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
31670 __net_timestamp(skb);
31671 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
31672 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
31673 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
31674 out:
31675 lvcc->rx.buf.ptr = end;
31676 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
31677 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31678 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
31679 "vcc %d\n", lanai->number, (unsigned int) s, vci);
31680 lanai->stats.service_rxnotaal5++;
31681 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31682 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31683 return 0;
31684 }
31685 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
31686 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31687 int bytes;
31688 read_unlock(&vcc_sklist_lock);
31689 DPRINTK("got trashed rx pdu on vci %d\n", vci);
31690 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31691 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31692 lvcc->stats.x.aal5.service_trash++;
31693 bytes = (SERVICE_GET_END(s) * 16) -
31694 (((unsigned long) lvcc->rx.buf.ptr) -
31695 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31696 }
31697 if (s & SERVICE_STREAM) {
31698 read_unlock(&vcc_sklist_lock);
31699 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31700 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31701 lvcc->stats.x.aal5.service_stream++;
31702 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
31703 "PDU on VCI %d!\n", lanai->number, vci);
31704 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
31705 return 0;
31706 }
31707 DPRINTK("got rx crc error on vci %d\n", vci);
31708 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
31709 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
31710 lvcc->stats.x.aal5.service_rxcrc++;
31711 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
31712 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
31713 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
31714 index ed1d2b7..8cffc1f 100644
31715 --- a/drivers/atm/nicstar.c
31716 +++ b/drivers/atm/nicstar.c
31717 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31718 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
31719 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
31720 card->index);
31721 - atomic_inc(&vcc->stats->tx_err);
31722 + atomic_inc_unchecked(&vcc->stats->tx_err);
31723 dev_kfree_skb_any(skb);
31724 return -EINVAL;
31725 }
31726 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31727 if (!vc->tx) {
31728 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
31729 card->index);
31730 - atomic_inc(&vcc->stats->tx_err);
31731 + atomic_inc_unchecked(&vcc->stats->tx_err);
31732 dev_kfree_skb_any(skb);
31733 return -EINVAL;
31734 }
31735 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31736 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
31737 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
31738 card->index);
31739 - atomic_inc(&vcc->stats->tx_err);
31740 + atomic_inc_unchecked(&vcc->stats->tx_err);
31741 dev_kfree_skb_any(skb);
31742 return -EINVAL;
31743 }
31744
31745 if (skb_shinfo(skb)->nr_frags != 0) {
31746 printk("nicstar%d: No scatter-gather yet.\n", card->index);
31747 - atomic_inc(&vcc->stats->tx_err);
31748 + atomic_inc_unchecked(&vcc->stats->tx_err);
31749 dev_kfree_skb_any(skb);
31750 return -EINVAL;
31751 }
31752 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
31753 }
31754
31755 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
31756 - atomic_inc(&vcc->stats->tx_err);
31757 + atomic_inc_unchecked(&vcc->stats->tx_err);
31758 dev_kfree_skb_any(skb);
31759 return -EIO;
31760 }
31761 - atomic_inc(&vcc->stats->tx);
31762 + atomic_inc_unchecked(&vcc->stats->tx);
31763
31764 return 0;
31765 }
31766 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31767 printk
31768 ("nicstar%d: Can't allocate buffers for aal0.\n",
31769 card->index);
31770 - atomic_add(i, &vcc->stats->rx_drop);
31771 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
31772 break;
31773 }
31774 if (!atm_charge(vcc, sb->truesize)) {
31775 RXPRINTK
31776 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
31777 card->index);
31778 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31779 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
31780 dev_kfree_skb_any(sb);
31781 break;
31782 }
31783 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31784 ATM_SKB(sb)->vcc = vcc;
31785 __net_timestamp(sb);
31786 vcc->push(vcc, sb);
31787 - atomic_inc(&vcc->stats->rx);
31788 + atomic_inc_unchecked(&vcc->stats->rx);
31789 cell += ATM_CELL_PAYLOAD;
31790 }
31791
31792 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31793 if (iovb == NULL) {
31794 printk("nicstar%d: Out of iovec buffers.\n",
31795 card->index);
31796 - atomic_inc(&vcc->stats->rx_drop);
31797 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31798 recycle_rx_buf(card, skb);
31799 return;
31800 }
31801 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31802 small or large buffer itself. */
31803 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
31804 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
31805 - atomic_inc(&vcc->stats->rx_err);
31806 + atomic_inc_unchecked(&vcc->stats->rx_err);
31807 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31808 NS_MAX_IOVECS);
31809 NS_PRV_IOVCNT(iovb) = 0;
31810 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31811 ("nicstar%d: Expected a small buffer, and this is not one.\n",
31812 card->index);
31813 which_list(card, skb);
31814 - atomic_inc(&vcc->stats->rx_err);
31815 + atomic_inc_unchecked(&vcc->stats->rx_err);
31816 recycle_rx_buf(card, skb);
31817 vc->rx_iov = NULL;
31818 recycle_iov_buf(card, iovb);
31819 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31820 ("nicstar%d: Expected a large buffer, and this is not one.\n",
31821 card->index);
31822 which_list(card, skb);
31823 - atomic_inc(&vcc->stats->rx_err);
31824 + atomic_inc_unchecked(&vcc->stats->rx_err);
31825 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31826 NS_PRV_IOVCNT(iovb));
31827 vc->rx_iov = NULL;
31828 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31829 printk(" - PDU size mismatch.\n");
31830 else
31831 printk(".\n");
31832 - atomic_inc(&vcc->stats->rx_err);
31833 + atomic_inc_unchecked(&vcc->stats->rx_err);
31834 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
31835 NS_PRV_IOVCNT(iovb));
31836 vc->rx_iov = NULL;
31837 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31838 /* skb points to a small buffer */
31839 if (!atm_charge(vcc, skb->truesize)) {
31840 push_rxbufs(card, skb);
31841 - atomic_inc(&vcc->stats->rx_drop);
31842 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31843 } else {
31844 skb_put(skb, len);
31845 dequeue_sm_buf(card, skb);
31846 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31847 ATM_SKB(skb)->vcc = vcc;
31848 __net_timestamp(skb);
31849 vcc->push(vcc, skb);
31850 - atomic_inc(&vcc->stats->rx);
31851 + atomic_inc_unchecked(&vcc->stats->rx);
31852 }
31853 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
31854 struct sk_buff *sb;
31855 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31856 if (len <= NS_SMBUFSIZE) {
31857 if (!atm_charge(vcc, sb->truesize)) {
31858 push_rxbufs(card, sb);
31859 - atomic_inc(&vcc->stats->rx_drop);
31860 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31861 } else {
31862 skb_put(sb, len);
31863 dequeue_sm_buf(card, sb);
31864 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31865 ATM_SKB(sb)->vcc = vcc;
31866 __net_timestamp(sb);
31867 vcc->push(vcc, sb);
31868 - atomic_inc(&vcc->stats->rx);
31869 + atomic_inc_unchecked(&vcc->stats->rx);
31870 }
31871
31872 push_rxbufs(card, skb);
31873 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31874
31875 if (!atm_charge(vcc, skb->truesize)) {
31876 push_rxbufs(card, skb);
31877 - atomic_inc(&vcc->stats->rx_drop);
31878 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31879 } else {
31880 dequeue_lg_buf(card, skb);
31881 #ifdef NS_USE_DESTRUCTORS
31882 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31883 ATM_SKB(skb)->vcc = vcc;
31884 __net_timestamp(skb);
31885 vcc->push(vcc, skb);
31886 - atomic_inc(&vcc->stats->rx);
31887 + atomic_inc_unchecked(&vcc->stats->rx);
31888 }
31889
31890 push_rxbufs(card, sb);
31891 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31892 printk
31893 ("nicstar%d: Out of huge buffers.\n",
31894 card->index);
31895 - atomic_inc(&vcc->stats->rx_drop);
31896 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31897 recycle_iovec_rx_bufs(card,
31898 (struct iovec *)
31899 iovb->data,
31900 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31901 card->hbpool.count++;
31902 } else
31903 dev_kfree_skb_any(hb);
31904 - atomic_inc(&vcc->stats->rx_drop);
31905 + atomic_inc_unchecked(&vcc->stats->rx_drop);
31906 } else {
31907 /* Copy the small buffer to the huge buffer */
31908 sb = (struct sk_buff *)iov->iov_base;
31909 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
31910 #endif /* NS_USE_DESTRUCTORS */
31911 __net_timestamp(hb);
31912 vcc->push(vcc, hb);
31913 - atomic_inc(&vcc->stats->rx);
31914 + atomic_inc_unchecked(&vcc->stats->rx);
31915 }
31916 }
31917
31918 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
31919 index 0474a89..06ea4a1 100644
31920 --- a/drivers/atm/solos-pci.c
31921 +++ b/drivers/atm/solos-pci.c
31922 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
31923 }
31924 atm_charge(vcc, skb->truesize);
31925 vcc->push(vcc, skb);
31926 - atomic_inc(&vcc->stats->rx);
31927 + atomic_inc_unchecked(&vcc->stats->rx);
31928 break;
31929
31930 case PKT_STATUS:
31931 @@ -1117,7 +1117,7 @@ static uint32_t fpga_tx(struct solos_card *card)
31932 vcc = SKB_CB(oldskb)->vcc;
31933
31934 if (vcc) {
31935 - atomic_inc(&vcc->stats->tx);
31936 + atomic_inc_unchecked(&vcc->stats->tx);
31937 solos_pop(vcc, oldskb);
31938 } else {
31939 dev_kfree_skb_irq(oldskb);
31940 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
31941 index 0215934..ce9f5b1 100644
31942 --- a/drivers/atm/suni.c
31943 +++ b/drivers/atm/suni.c
31944 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
31945
31946
31947 #define ADD_LIMITED(s,v) \
31948 - atomic_add((v),&stats->s); \
31949 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
31950 + atomic_add_unchecked((v),&stats->s); \
31951 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
31952
31953
31954 static void suni_hz(unsigned long from_timer)
31955 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
31956 index 5120a96..e2572bd 100644
31957 --- a/drivers/atm/uPD98402.c
31958 +++ b/drivers/atm/uPD98402.c
31959 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
31960 struct sonet_stats tmp;
31961 int error = 0;
31962
31963 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31964 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
31965 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
31966 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
31967 if (zero && !error) {
31968 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
31969
31970
31971 #define ADD_LIMITED(s,v) \
31972 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
31973 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
31974 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31975 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
31976 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
31977 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
31978
31979
31980 static void stat_event(struct atm_dev *dev)
31981 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
31982 if (reason & uPD98402_INT_PFM) stat_event(dev);
31983 if (reason & uPD98402_INT_PCO) {
31984 (void) GET(PCOCR); /* clear interrupt cause */
31985 - atomic_add(GET(HECCT),
31986 + atomic_add_unchecked(GET(HECCT),
31987 &PRIV(dev)->sonet_stats.uncorr_hcs);
31988 }
31989 if ((reason & uPD98402_INT_RFO) &&
31990 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31991 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31992 uPD98402_INT_LOS),PIMR); /* enable them */
31993 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31994 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31995 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31996 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31997 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31998 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31999 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
32000 return 0;
32001 }
32002
32003 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
32004 index 969c3c2..9b72956 100644
32005 --- a/drivers/atm/zatm.c
32006 +++ b/drivers/atm/zatm.c
32007 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32008 }
32009 if (!size) {
32010 dev_kfree_skb_irq(skb);
32011 - if (vcc) atomic_inc(&vcc->stats->rx_err);
32012 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
32013 continue;
32014 }
32015 if (!atm_charge(vcc,skb->truesize)) {
32016 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
32017 skb->len = size;
32018 ATM_SKB(skb)->vcc = vcc;
32019 vcc->push(vcc,skb);
32020 - atomic_inc(&vcc->stats->rx);
32021 + atomic_inc_unchecked(&vcc->stats->rx);
32022 }
32023 zout(pos & 0xffff,MTA(mbx));
32024 #if 0 /* probably a stupid idea */
32025 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
32026 skb_queue_head(&zatm_vcc->backlog,skb);
32027 break;
32028 }
32029 - atomic_inc(&vcc->stats->tx);
32030 + atomic_inc_unchecked(&vcc->stats->tx);
32031 wake_up(&zatm_vcc->tx_wait);
32032 }
32033
32034 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
32035 index 17cf7ca..7e553e1 100644
32036 --- a/drivers/base/devtmpfs.c
32037 +++ b/drivers/base/devtmpfs.c
32038 @@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
32039 if (!thread)
32040 return 0;
32041
32042 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
32043 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
32044 if (err)
32045 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
32046 else
32047 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
32048 index e6ee5e8..98ad7fc 100644
32049 --- a/drivers/base/power/wakeup.c
32050 +++ b/drivers/base/power/wakeup.c
32051 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
32052 * They need to be modified together atomically, so it's better to use one
32053 * atomic variable to hold them both.
32054 */
32055 -static atomic_t combined_event_count = ATOMIC_INIT(0);
32056 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
32057
32058 #define IN_PROGRESS_BITS (sizeof(int) * 4)
32059 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
32060
32061 static void split_counters(unsigned int *cnt, unsigned int *inpr)
32062 {
32063 - unsigned int comb = atomic_read(&combined_event_count);
32064 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
32065
32066 *cnt = (comb >> IN_PROGRESS_BITS);
32067 *inpr = comb & MAX_IN_PROGRESS;
32068 @@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
32069 ws->start_prevent_time = ws->last_time;
32070
32071 /* Increment the counter of events in progress. */
32072 - cec = atomic_inc_return(&combined_event_count);
32073 + cec = atomic_inc_return_unchecked(&combined_event_count);
32074
32075 trace_wakeup_source_activate(ws->name, cec);
32076 }
32077 @@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
32078 * Increment the counter of registered wakeup events and decrement the
32079 * couter of wakeup events in progress simultaneously.
32080 */
32081 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
32082 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
32083 trace_wakeup_source_deactivate(ws->name, cec);
32084
32085 split_counters(&cnt, &inpr);
32086 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
32087 index ade58bc..867143d 100644
32088 --- a/drivers/block/cciss.c
32089 +++ b/drivers/block/cciss.c
32090 @@ -1196,6 +1196,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
32091 int err;
32092 u32 cp;
32093
32094 + memset(&arg64, 0, sizeof(arg64));
32095 +
32096 err = 0;
32097 err |=
32098 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
32099 @@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
32100 while (!list_empty(&h->reqQ)) {
32101 c = list_entry(h->reqQ.next, CommandList_struct, list);
32102 /* can't do anything if fifo is full */
32103 - if ((h->access.fifo_full(h))) {
32104 + if ((h->access->fifo_full(h))) {
32105 dev_warn(&h->pdev->dev, "fifo full\n");
32106 break;
32107 }
32108 @@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
32109 h->Qdepth--;
32110
32111 /* Tell the controller execute command */
32112 - h->access.submit_command(h, c);
32113 + h->access->submit_command(h, c);
32114
32115 /* Put job onto the completed Q */
32116 addQ(&h->cmpQ, c);
32117 @@ -3441,17 +3443,17 @@ startio:
32118
32119 static inline unsigned long get_next_completion(ctlr_info_t *h)
32120 {
32121 - return h->access.command_completed(h);
32122 + return h->access->command_completed(h);
32123 }
32124
32125 static inline int interrupt_pending(ctlr_info_t *h)
32126 {
32127 - return h->access.intr_pending(h);
32128 + return h->access->intr_pending(h);
32129 }
32130
32131 static inline long interrupt_not_for_us(ctlr_info_t *h)
32132 {
32133 - return ((h->access.intr_pending(h) == 0) ||
32134 + return ((h->access->intr_pending(h) == 0) ||
32135 (h->interrupts_enabled == 0));
32136 }
32137
32138 @@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
32139 u32 a;
32140
32141 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
32142 - return h->access.command_completed(h);
32143 + return h->access->command_completed(h);
32144
32145 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
32146 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
32147 @@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
32148 trans_support & CFGTBL_Trans_use_short_tags);
32149
32150 /* Change the access methods to the performant access methods */
32151 - h->access = SA5_performant_access;
32152 + h->access = &SA5_performant_access;
32153 h->transMethod = CFGTBL_Trans_Performant;
32154
32155 return;
32156 @@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
32157 if (prod_index < 0)
32158 return -ENODEV;
32159 h->product_name = products[prod_index].product_name;
32160 - h->access = *(products[prod_index].access);
32161 + h->access = products[prod_index].access;
32162
32163 if (cciss_board_disabled(h)) {
32164 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
32165 @@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
32166 }
32167
32168 /* make sure the board interrupts are off */
32169 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32170 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32171 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
32172 if (rc)
32173 goto clean2;
32174 @@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
32175 * fake ones to scoop up any residual completions.
32176 */
32177 spin_lock_irqsave(&h->lock, flags);
32178 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32179 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32180 spin_unlock_irqrestore(&h->lock, flags);
32181 free_irq(h->intr[h->intr_mode], h);
32182 rc = cciss_request_irq(h, cciss_msix_discard_completions,
32183 @@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
32184 dev_info(&h->pdev->dev, "Board READY.\n");
32185 dev_info(&h->pdev->dev,
32186 "Waiting for stale completions to drain.\n");
32187 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32188 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32189 msleep(10000);
32190 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32191 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32192
32193 rc = controller_reset_failed(h->cfgtable);
32194 if (rc)
32195 @@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
32196 cciss_scsi_setup(h);
32197
32198 /* Turn the interrupts on so we can service requests */
32199 - h->access.set_intr_mask(h, CCISS_INTR_ON);
32200 + h->access->set_intr_mask(h, CCISS_INTR_ON);
32201
32202 /* Get the firmware version */
32203 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
32204 @@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
32205 kfree(flush_buf);
32206 if (return_code != IO_OK)
32207 dev_warn(&h->pdev->dev, "Error flushing cache\n");
32208 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
32209 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
32210 free_irq(h->intr[h->intr_mode], h);
32211 }
32212
32213 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
32214 index 7fda30e..eb5dfe0 100644
32215 --- a/drivers/block/cciss.h
32216 +++ b/drivers/block/cciss.h
32217 @@ -101,7 +101,7 @@ struct ctlr_info
32218 /* information about each logical volume */
32219 drive_info_struct *drv[CISS_MAX_LUN];
32220
32221 - struct access_method access;
32222 + struct access_method *access;
32223
32224 /* queue and queue Info */
32225 struct list_head reqQ;
32226 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
32227 index 3f08713..56a586a 100644
32228 --- a/drivers/block/cpqarray.c
32229 +++ b/drivers/block/cpqarray.c
32230 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32231 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
32232 goto Enomem4;
32233 }
32234 - hba[i]->access.set_intr_mask(hba[i], 0);
32235 + hba[i]->access->set_intr_mask(hba[i], 0);
32236 if (request_irq(hba[i]->intr, do_ida_intr,
32237 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
32238 {
32239 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
32240 add_timer(&hba[i]->timer);
32241
32242 /* Enable IRQ now that spinlock and rate limit timer are set up */
32243 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32244 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
32245
32246 for(j=0; j<NWD; j++) {
32247 struct gendisk *disk = ida_gendisk[i][j];
32248 @@ -694,7 +694,7 @@ DBGINFO(
32249 for(i=0; i<NR_PRODUCTS; i++) {
32250 if (board_id == products[i].board_id) {
32251 c->product_name = products[i].product_name;
32252 - c->access = *(products[i].access);
32253 + c->access = products[i].access;
32254 break;
32255 }
32256 }
32257 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
32258 hba[ctlr]->intr = intr;
32259 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
32260 hba[ctlr]->product_name = products[j].product_name;
32261 - hba[ctlr]->access = *(products[j].access);
32262 + hba[ctlr]->access = products[j].access;
32263 hba[ctlr]->ctlr = ctlr;
32264 hba[ctlr]->board_id = board_id;
32265 hba[ctlr]->pci_dev = NULL; /* not PCI */
32266 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
32267
32268 while((c = h->reqQ) != NULL) {
32269 /* Can't do anything if we're busy */
32270 - if (h->access.fifo_full(h) == 0)
32271 + if (h->access->fifo_full(h) == 0)
32272 return;
32273
32274 /* Get the first entry from the request Q */
32275 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
32276 h->Qdepth--;
32277
32278 /* Tell the controller to do our bidding */
32279 - h->access.submit_command(h, c);
32280 + h->access->submit_command(h, c);
32281
32282 /* Get onto the completion Q */
32283 addQ(&h->cmpQ, c);
32284 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32285 unsigned long flags;
32286 __u32 a,a1;
32287
32288 - istat = h->access.intr_pending(h);
32289 + istat = h->access->intr_pending(h);
32290 /* Is this interrupt for us? */
32291 if (istat == 0)
32292 return IRQ_NONE;
32293 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
32294 */
32295 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
32296 if (istat & FIFO_NOT_EMPTY) {
32297 - while((a = h->access.command_completed(h))) {
32298 + while((a = h->access->command_completed(h))) {
32299 a1 = a; a &= ~3;
32300 if ((c = h->cmpQ) == NULL)
32301 {
32302 @@ -1449,11 +1449,11 @@ static int sendcmd(
32303 /*
32304 * Disable interrupt
32305 */
32306 - info_p->access.set_intr_mask(info_p, 0);
32307 + info_p->access->set_intr_mask(info_p, 0);
32308 /* Make sure there is room in the command FIFO */
32309 /* Actually it should be completely empty at this time. */
32310 for (i = 200000; i > 0; i--) {
32311 - temp = info_p->access.fifo_full(info_p);
32312 + temp = info_p->access->fifo_full(info_p);
32313 if (temp != 0) {
32314 break;
32315 }
32316 @@ -1466,7 +1466,7 @@ DBG(
32317 /*
32318 * Send the cmd
32319 */
32320 - info_p->access.submit_command(info_p, c);
32321 + info_p->access->submit_command(info_p, c);
32322 complete = pollcomplete(ctlr);
32323
32324 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
32325 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
32326 * we check the new geometry. Then turn interrupts back on when
32327 * we're done.
32328 */
32329 - host->access.set_intr_mask(host, 0);
32330 + host->access->set_intr_mask(host, 0);
32331 getgeometry(ctlr);
32332 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
32333 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
32334
32335 for(i=0; i<NWD; i++) {
32336 struct gendisk *disk = ida_gendisk[ctlr][i];
32337 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
32338 /* Wait (up to 2 seconds) for a command to complete */
32339
32340 for (i = 200000; i > 0; i--) {
32341 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
32342 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
32343 if (done == 0) {
32344 udelay(10); /* a short fixed delay */
32345 } else
32346 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
32347 index be73e9d..7fbf140 100644
32348 --- a/drivers/block/cpqarray.h
32349 +++ b/drivers/block/cpqarray.h
32350 @@ -99,7 +99,7 @@ struct ctlr_info {
32351 drv_info_t drv[NWD];
32352 struct proc_dir_entry *proc;
32353
32354 - struct access_method access;
32355 + struct access_method *access;
32356
32357 cmdlist_t *reqQ;
32358 cmdlist_t *cmpQ;
32359 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
32360 index 6b51afa..17e1191 100644
32361 --- a/drivers/block/drbd/drbd_int.h
32362 +++ b/drivers/block/drbd/drbd_int.h
32363 @@ -582,7 +582,7 @@ struct drbd_epoch {
32364 struct drbd_tconn *tconn;
32365 struct list_head list;
32366 unsigned int barrier_nr;
32367 - atomic_t epoch_size; /* increased on every request added. */
32368 + atomic_unchecked_t epoch_size; /* increased on every request added. */
32369 atomic_t active; /* increased on every req. added, and dec on every finished. */
32370 unsigned long flags;
32371 };
32372 @@ -1011,7 +1011,7 @@ struct drbd_conf {
32373 int al_tr_cycle;
32374 int al_tr_pos; /* position of the next transaction in the journal */
32375 wait_queue_head_t seq_wait;
32376 - atomic_t packet_seq;
32377 + atomic_unchecked_t packet_seq;
32378 unsigned int peer_seq;
32379 spinlock_t peer_seq_lock;
32380 unsigned int minor;
32381 @@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
32382 char __user *uoptval;
32383 int err;
32384
32385 - uoptval = (char __user __force *)optval;
32386 + uoptval = (char __force_user *)optval;
32387
32388 set_fs(KERNEL_DS);
32389 if (level == SOL_SOCKET)
32390 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
32391 index 8c13eeb..217adee 100644
32392 --- a/drivers/block/drbd/drbd_main.c
32393 +++ b/drivers/block/drbd/drbd_main.c
32394 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
32395 p->sector = sector;
32396 p->block_id = block_id;
32397 p->blksize = blksize;
32398 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32399 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32400 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
32401 }
32402
32403 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
32404 return -EIO;
32405 p->sector = cpu_to_be64(req->i.sector);
32406 p->block_id = (unsigned long)req;
32407 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
32408 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
32409 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
32410 if (mdev->state.conn >= C_SYNC_SOURCE &&
32411 mdev->state.conn <= C_PAUSED_SYNC_T)
32412 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
32413 {
32414 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
32415
32416 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
32417 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
32418 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
32419 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
32420 kfree(tconn->current_epoch);
32421
32422 idr_destroy(&tconn->volumes);
32423 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
32424 index a9eccfc..68e4533 100644
32425 --- a/drivers/block/drbd/drbd_receiver.c
32426 +++ b/drivers/block/drbd/drbd_receiver.c
32427 @@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
32428 {
32429 int err;
32430
32431 - atomic_set(&mdev->packet_seq, 0);
32432 + atomic_set_unchecked(&mdev->packet_seq, 0);
32433 mdev->peer_seq = 0;
32434
32435 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
32436 @@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32437 do {
32438 next_epoch = NULL;
32439
32440 - epoch_size = atomic_read(&epoch->epoch_size);
32441 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
32442
32443 switch (ev & ~EV_CLEANUP) {
32444 case EV_PUT:
32445 @@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
32446 rv = FE_DESTROYED;
32447 } else {
32448 epoch->flags = 0;
32449 - atomic_set(&epoch->epoch_size, 0);
32450 + atomic_set_unchecked(&epoch->epoch_size, 0);
32451 /* atomic_set(&epoch->active, 0); is already zero */
32452 if (rv == FE_STILL_LIVE)
32453 rv = FE_RECYCLED;
32454 @@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32455 conn_wait_active_ee_empty(tconn);
32456 drbd_flush(tconn);
32457
32458 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32459 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32460 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
32461 if (epoch)
32462 break;
32463 @@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
32464 }
32465
32466 epoch->flags = 0;
32467 - atomic_set(&epoch->epoch_size, 0);
32468 + atomic_set_unchecked(&epoch->epoch_size, 0);
32469 atomic_set(&epoch->active, 0);
32470
32471 spin_lock(&tconn->epoch_lock);
32472 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
32473 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
32474 list_add(&epoch->list, &tconn->current_epoch->list);
32475 tconn->current_epoch = epoch;
32476 tconn->epochs++;
32477 @@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32478
32479 err = wait_for_and_update_peer_seq(mdev, peer_seq);
32480 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
32481 - atomic_inc(&tconn->current_epoch->epoch_size);
32482 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
32483 err2 = drbd_drain_block(mdev, pi->size);
32484 if (!err)
32485 err = err2;
32486 @@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
32487
32488 spin_lock(&tconn->epoch_lock);
32489 peer_req->epoch = tconn->current_epoch;
32490 - atomic_inc(&peer_req->epoch->epoch_size);
32491 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
32492 atomic_inc(&peer_req->epoch->active);
32493 spin_unlock(&tconn->epoch_lock);
32494
32495 @@ -4466,7 +4466,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
32496 if (!list_empty(&tconn->current_epoch->list))
32497 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
32498 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
32499 - atomic_set(&tconn->current_epoch->epoch_size, 0);
32500 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
32501 tconn->send.seen_any_write_yet = false;
32502
32503 conn_info(tconn, "Connection closed\n");
32504 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
32505 index ae12512..37fa397 100644
32506 --- a/drivers/block/loop.c
32507 +++ b/drivers/block/loop.c
32508 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
32509 mm_segment_t old_fs = get_fs();
32510
32511 set_fs(get_ds());
32512 - bw = file->f_op->write(file, buf, len, &pos);
32513 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
32514 set_fs(old_fs);
32515 if (likely(bw == len))
32516 return 0;
32517 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
32518 index d620b44..587561e 100644
32519 --- a/drivers/cdrom/cdrom.c
32520 +++ b/drivers/cdrom/cdrom.c
32521 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
32522 ENSURE(reset, CDC_RESET);
32523 ENSURE(generic_packet, CDC_GENERIC_PACKET);
32524 cdi->mc_flags = 0;
32525 - cdo->n_minors = 0;
32526 cdi->options = CDO_USE_FFLAGS;
32527
32528 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
32529 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
32530 else
32531 cdi->cdda_method = CDDA_OLD;
32532
32533 - if (!cdo->generic_packet)
32534 - cdo->generic_packet = cdrom_dummy_generic_packet;
32535 + if (!cdo->generic_packet) {
32536 + pax_open_kernel();
32537 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
32538 + pax_close_kernel();
32539 + }
32540
32541 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
32542 mutex_lock(&cdrom_mutex);
32543 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
32544 if (cdi->exit)
32545 cdi->exit(cdi);
32546
32547 - cdi->ops->n_minors--;
32548 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
32549 }
32550
32551 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
32552 index d59cdcb..11afddf 100644
32553 --- a/drivers/cdrom/gdrom.c
32554 +++ b/drivers/cdrom/gdrom.c
32555 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
32556 .audio_ioctl = gdrom_audio_ioctl,
32557 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
32558 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
32559 - .n_minors = 1,
32560 };
32561
32562 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
32563 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
32564 index 72bedad..8181ce1 100644
32565 --- a/drivers/char/Kconfig
32566 +++ b/drivers/char/Kconfig
32567 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
32568
32569 config DEVKMEM
32570 bool "/dev/kmem virtual device support"
32571 - default y
32572 + default n
32573 + depends on !GRKERNSEC_KMEM
32574 help
32575 Say Y here if you want to support the /dev/kmem device. The
32576 /dev/kmem device is rarely used, but can be used for certain
32577 @@ -581,6 +582,7 @@ config DEVPORT
32578 bool
32579 depends on !M68K
32580 depends on ISA || PCI
32581 + depends on !GRKERNSEC_KMEM
32582 default y
32583
32584 source "drivers/s390/char/Kconfig"
32585 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
32586 index 2e04433..22afc64 100644
32587 --- a/drivers/char/agp/frontend.c
32588 +++ b/drivers/char/agp/frontend.c
32589 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
32590 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
32591 return -EFAULT;
32592
32593 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
32594 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
32595 return -EFAULT;
32596
32597 client = agp_find_client_by_pid(reserve.pid);
32598 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
32599 index 21cb980..f15107c 100644
32600 --- a/drivers/char/genrtc.c
32601 +++ b/drivers/char/genrtc.c
32602 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
32603 switch (cmd) {
32604
32605 case RTC_PLL_GET:
32606 + memset(&pll, 0, sizeof(pll));
32607 if (get_rtc_pll(&pll))
32608 return -EINVAL;
32609 else
32610 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
32611 index fe6d4be..89f32100 100644
32612 --- a/drivers/char/hpet.c
32613 +++ b/drivers/char/hpet.c
32614 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
32615 }
32616
32617 static int
32618 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
32619 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
32620 struct hpet_info *info)
32621 {
32622 struct hpet_timer __iomem *timer;
32623 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
32624 index 053201b0..8335cce 100644
32625 --- a/drivers/char/ipmi/ipmi_msghandler.c
32626 +++ b/drivers/char/ipmi/ipmi_msghandler.c
32627 @@ -420,7 +420,7 @@ struct ipmi_smi {
32628 struct proc_dir_entry *proc_dir;
32629 char proc_dir_name[10];
32630
32631 - atomic_t stats[IPMI_NUM_STATS];
32632 + atomic_unchecked_t stats[IPMI_NUM_STATS];
32633
32634 /*
32635 * run_to_completion duplicate of smb_info, smi_info
32636 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
32637
32638
32639 #define ipmi_inc_stat(intf, stat) \
32640 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
32641 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
32642 #define ipmi_get_stat(intf, stat) \
32643 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
32644 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
32645
32646 static int is_lan_addr(struct ipmi_addr *addr)
32647 {
32648 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
32649 INIT_LIST_HEAD(&intf->cmd_rcvrs);
32650 init_waitqueue_head(&intf->waitq);
32651 for (i = 0; i < IPMI_NUM_STATS; i++)
32652 - atomic_set(&intf->stats[i], 0);
32653 + atomic_set_unchecked(&intf->stats[i], 0);
32654
32655 intf->proc_dir = NULL;
32656
32657 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
32658 index 1c7fdcd..4899100 100644
32659 --- a/drivers/char/ipmi/ipmi_si_intf.c
32660 +++ b/drivers/char/ipmi/ipmi_si_intf.c
32661 @@ -275,7 +275,7 @@ struct smi_info {
32662 unsigned char slave_addr;
32663
32664 /* Counters and things for the proc filesystem. */
32665 - atomic_t stats[SI_NUM_STATS];
32666 + atomic_unchecked_t stats[SI_NUM_STATS];
32667
32668 struct task_struct *thread;
32669
32670 @@ -284,9 +284,9 @@ struct smi_info {
32671 };
32672
32673 #define smi_inc_stat(smi, stat) \
32674 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
32675 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
32676 #define smi_get_stat(smi, stat) \
32677 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
32678 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
32679
32680 #define SI_MAX_PARMS 4
32681
32682 @@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
32683 atomic_set(&new_smi->req_events, 0);
32684 new_smi->run_to_completion = 0;
32685 for (i = 0; i < SI_NUM_STATS; i++)
32686 - atomic_set(&new_smi->stats[i], 0);
32687 + atomic_set_unchecked(&new_smi->stats[i], 0);
32688
32689 new_smi->interrupt_disabled = 1;
32690 atomic_set(&new_smi->stop_operation, 0);
32691 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
32692 index c6fa3bc..4ca3e42 100644
32693 --- a/drivers/char/mem.c
32694 +++ b/drivers/char/mem.c
32695 @@ -18,6 +18,7 @@
32696 #include <linux/raw.h>
32697 #include <linux/tty.h>
32698 #include <linux/capability.h>
32699 +#include <linux/security.h>
32700 #include <linux/ptrace.h>
32701 #include <linux/device.h>
32702 #include <linux/highmem.h>
32703 @@ -37,6 +38,10 @@
32704
32705 #define DEVPORT_MINOR 4
32706
32707 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32708 +extern const struct file_operations grsec_fops;
32709 +#endif
32710 +
32711 static inline unsigned long size_inside_page(unsigned long start,
32712 unsigned long size)
32713 {
32714 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32715
32716 while (cursor < to) {
32717 if (!devmem_is_allowed(pfn)) {
32718 +#ifdef CONFIG_GRKERNSEC_KMEM
32719 + gr_handle_mem_readwrite(from, to);
32720 +#else
32721 printk(KERN_INFO
32722 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
32723 current->comm, from, to);
32724 +#endif
32725 return 0;
32726 }
32727 cursor += PAGE_SIZE;
32728 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32729 }
32730 return 1;
32731 }
32732 +#elif defined(CONFIG_GRKERNSEC_KMEM)
32733 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32734 +{
32735 + return 0;
32736 +}
32737 #else
32738 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32739 {
32740 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32741
32742 while (count > 0) {
32743 unsigned long remaining;
32744 + char *temp;
32745
32746 sz = size_inside_page(p, count);
32747
32748 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
32749 if (!ptr)
32750 return -EFAULT;
32751
32752 - remaining = copy_to_user(buf, ptr, sz);
32753 +#ifdef CONFIG_PAX_USERCOPY
32754 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32755 + if (!temp) {
32756 + unxlate_dev_mem_ptr(p, ptr);
32757 + return -ENOMEM;
32758 + }
32759 + memcpy(temp, ptr, sz);
32760 +#else
32761 + temp = ptr;
32762 +#endif
32763 +
32764 + remaining = copy_to_user(buf, temp, sz);
32765 +
32766 +#ifdef CONFIG_PAX_USERCOPY
32767 + kfree(temp);
32768 +#endif
32769 +
32770 unxlate_dev_mem_ptr(p, ptr);
32771 if (remaining)
32772 return -EFAULT;
32773 @@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32774 size_t count, loff_t *ppos)
32775 {
32776 unsigned long p = *ppos;
32777 - ssize_t low_count, read, sz;
32778 + ssize_t low_count, read, sz, err = 0;
32779 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
32780 - int err = 0;
32781
32782 read = 0;
32783 if (p < (unsigned long) high_memory) {
32784 @@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32785 }
32786 #endif
32787 while (low_count > 0) {
32788 + char *temp;
32789 +
32790 sz = size_inside_page(p, low_count);
32791
32792 /*
32793 @@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
32794 */
32795 kbuf = xlate_dev_kmem_ptr((char *)p);
32796
32797 - if (copy_to_user(buf, kbuf, sz))
32798 +#ifdef CONFIG_PAX_USERCOPY
32799 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
32800 + if (!temp)
32801 + return -ENOMEM;
32802 + memcpy(temp, kbuf, sz);
32803 +#else
32804 + temp = kbuf;
32805 +#endif
32806 +
32807 + err = copy_to_user(buf, temp, sz);
32808 +
32809 +#ifdef CONFIG_PAX_USERCOPY
32810 + kfree(temp);
32811 +#endif
32812 +
32813 + if (err)
32814 return -EFAULT;
32815 buf += sz;
32816 p += sz;
32817 @@ -833,6 +880,9 @@ static const struct memdev {
32818 #ifdef CONFIG_CRASH_DUMP
32819 [12] = { "oldmem", 0, &oldmem_fops, NULL },
32820 #endif
32821 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
32822 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
32823 +#endif
32824 };
32825
32826 static int memory_open(struct inode *inode, struct file *filp)
32827 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
32828 index 9df78e2..01ba9ae 100644
32829 --- a/drivers/char/nvram.c
32830 +++ b/drivers/char/nvram.c
32831 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
32832
32833 spin_unlock_irq(&rtc_lock);
32834
32835 - if (copy_to_user(buf, contents, tmp - contents))
32836 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
32837 return -EFAULT;
32838
32839 *ppos = i;
32840 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
32841 index b66eaa0..2619d1b 100644
32842 --- a/drivers/char/pcmcia/synclink_cs.c
32843 +++ b/drivers/char/pcmcia/synclink_cs.c
32844 @@ -2348,9 +2348,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32845
32846 if (debug_level >= DEBUG_LEVEL_INFO)
32847 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
32848 - __FILE__,__LINE__, info->device_name, port->count);
32849 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
32850
32851 - WARN_ON(!port->count);
32852 + WARN_ON(!atomic_read(&port->count));
32853
32854 if (tty_port_close_start(port, tty, filp) == 0)
32855 goto cleanup;
32856 @@ -2368,7 +2368,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
32857 cleanup:
32858 if (debug_level >= DEBUG_LEVEL_INFO)
32859 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
32860 - tty->driver->name, port->count);
32861 + tty->driver->name, atomic_read(&port->count));
32862 }
32863
32864 /* Wait until the transmitter is empty.
32865 @@ -2510,7 +2510,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32866
32867 if (debug_level >= DEBUG_LEVEL_INFO)
32868 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
32869 - __FILE__,__LINE__,tty->driver->name, port->count);
32870 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
32871
32872 /* If port is closing, signal caller to try again */
32873 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
32874 @@ -2530,11 +2530,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
32875 goto cleanup;
32876 }
32877 spin_lock(&port->lock);
32878 - port->count++;
32879 + atomic_inc(&port->count);
32880 spin_unlock(&port->lock);
32881 spin_unlock_irqrestore(&info->netlock, flags);
32882
32883 - if (port->count == 1) {
32884 + if (atomic_read(&port->count) == 1) {
32885 /* 1st open on this device, init hardware */
32886 retval = startup(info, tty);
32887 if (retval < 0)
32888 @@ -3889,7 +3889,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
32889 unsigned short new_crctype;
32890
32891 /* return error if TTY interface open */
32892 - if (info->port.count)
32893 + if (atomic_read(&info->port.count))
32894 return -EBUSY;
32895
32896 switch (encoding)
32897 @@ -3992,7 +3992,7 @@ static int hdlcdev_open(struct net_device *dev)
32898
32899 /* arbitrate between network and tty opens */
32900 spin_lock_irqsave(&info->netlock, flags);
32901 - if (info->port.count != 0 || info->netcount != 0) {
32902 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32903 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32904 spin_unlock_irqrestore(&info->netlock, flags);
32905 return -EBUSY;
32906 @@ -4081,7 +4081,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32907 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32908
32909 /* return error if TTY interface open */
32910 - if (info->port.count)
32911 + if (atomic_read(&info->port.count))
32912 return -EBUSY;
32913
32914 if (cmd != SIOCWANDEV)
32915 diff --git a/drivers/char/random.c b/drivers/char/random.c
32916 index 85e81ec..bce8b97 100644
32917 --- a/drivers/char/random.c
32918 +++ b/drivers/char/random.c
32919 @@ -272,8 +272,13 @@
32920 /*
32921 * Configuration information
32922 */
32923 +#ifdef CONFIG_GRKERNSEC_RANDNET
32924 +#define INPUT_POOL_WORDS 512
32925 +#define OUTPUT_POOL_WORDS 128
32926 +#else
32927 #define INPUT_POOL_WORDS 128
32928 #define OUTPUT_POOL_WORDS 32
32929 +#endif
32930 #define SEC_XFER_SIZE 512
32931 #define EXTRACT_SIZE 10
32932
32933 @@ -313,10 +318,17 @@ static struct poolinfo {
32934 int poolwords;
32935 int tap1, tap2, tap3, tap4, tap5;
32936 } poolinfo_table[] = {
32937 +#ifdef CONFIG_GRKERNSEC_RANDNET
32938 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32939 + { 512, 411, 308, 208, 104, 1 },
32940 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32941 + { 128, 103, 76, 51, 25, 1 },
32942 +#else
32943 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32944 { 128, 103, 76, 51, 25, 1 },
32945 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32946 { 32, 26, 20, 14, 7, 1 },
32947 +#endif
32948 #if 0
32949 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32950 { 2048, 1638, 1231, 819, 411, 1 },
32951 @@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32952 input_rotate += i ? 7 : 14;
32953 }
32954
32955 - ACCESS_ONCE(r->input_rotate) = input_rotate;
32956 - ACCESS_ONCE(r->add_ptr) = i;
32957 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32958 + ACCESS_ONCE_RW(r->add_ptr) = i;
32959 smp_wmb();
32960
32961 if (out)
32962 @@ -1020,7 +1032,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32963
32964 extract_buf(r, tmp);
32965 i = min_t(int, nbytes, EXTRACT_SIZE);
32966 - if (copy_to_user(buf, tmp, i)) {
32967 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32968 ret = -EFAULT;
32969 break;
32970 }
32971 @@ -1356,7 +1368,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32972 #include <linux/sysctl.h>
32973
32974 static int min_read_thresh = 8, min_write_thresh;
32975 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
32976 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32977 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32978 static char sysctl_bootid[16];
32979
32980 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32981 index d780295..b29f3a8 100644
32982 --- a/drivers/char/sonypi.c
32983 +++ b/drivers/char/sonypi.c
32984 @@ -54,6 +54,7 @@
32985
32986 #include <asm/uaccess.h>
32987 #include <asm/io.h>
32988 +#include <asm/local.h>
32989
32990 #include <linux/sonypi.h>
32991
32992 @@ -490,7 +491,7 @@ static struct sonypi_device {
32993 spinlock_t fifo_lock;
32994 wait_queue_head_t fifo_proc_list;
32995 struct fasync_struct *fifo_async;
32996 - int open_count;
32997 + local_t open_count;
32998 int model;
32999 struct input_dev *input_jog_dev;
33000 struct input_dev *input_key_dev;
33001 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
33002 static int sonypi_misc_release(struct inode *inode, struct file *file)
33003 {
33004 mutex_lock(&sonypi_device.lock);
33005 - sonypi_device.open_count--;
33006 + local_dec(&sonypi_device.open_count);
33007 mutex_unlock(&sonypi_device.lock);
33008 return 0;
33009 }
33010 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
33011 {
33012 mutex_lock(&sonypi_device.lock);
33013 /* Flush input queue on first open */
33014 - if (!sonypi_device.open_count)
33015 + if (!local_read(&sonypi_device.open_count))
33016 kfifo_reset(&sonypi_device.fifo);
33017 - sonypi_device.open_count++;
33018 + local_inc(&sonypi_device.open_count);
33019 mutex_unlock(&sonypi_device.lock);
33020
33021 return 0;
33022 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
33023 index 93211df..c7805f7 100644
33024 --- a/drivers/char/tpm/tpm.c
33025 +++ b/drivers/char/tpm/tpm.c
33026 @@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
33027 chip->vendor.req_complete_val)
33028 goto out_recv;
33029
33030 - if ((status == chip->vendor.req_canceled)) {
33031 + if (status == chip->vendor.req_canceled) {
33032 dev_err(chip->dev, "Operation Canceled\n");
33033 rc = -ECANCELED;
33034 goto out;
33035 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
33036 index 56051d0..11cf3b7 100644
33037 --- a/drivers/char/tpm/tpm_acpi.c
33038 +++ b/drivers/char/tpm/tpm_acpi.c
33039 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
33040 virt = acpi_os_map_memory(start, len);
33041 if (!virt) {
33042 kfree(log->bios_event_log);
33043 + log->bios_event_log = NULL;
33044 printk("%s: ERROR - Unable to map memory\n", __func__);
33045 return -EIO;
33046 }
33047
33048 - memcpy_fromio(log->bios_event_log, virt, len);
33049 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
33050
33051 acpi_os_unmap_memory(virt, len);
33052 return 0;
33053 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
33054 index 84ddc55..1d32f1e 100644
33055 --- a/drivers/char/tpm/tpm_eventlog.c
33056 +++ b/drivers/char/tpm/tpm_eventlog.c
33057 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
33058 event = addr;
33059
33060 if ((event->event_type == 0 && event->event_size == 0) ||
33061 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
33062 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
33063 return NULL;
33064
33065 return addr;
33066 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
33067 return NULL;
33068
33069 if ((event->event_type == 0 && event->event_size == 0) ||
33070 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
33071 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
33072 return NULL;
33073
33074 (*pos)++;
33075 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
33076 int i;
33077
33078 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
33079 - seq_putc(m, data[i]);
33080 + if (!seq_putc(m, data[i]))
33081 + return -EFAULT;
33082
33083 return 0;
33084 }
33085 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
33086 index ee4dbea..69c817b 100644
33087 --- a/drivers/char/virtio_console.c
33088 +++ b/drivers/char/virtio_console.c
33089 @@ -681,7 +681,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
33090 if (to_user) {
33091 ssize_t ret;
33092
33093 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
33094 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
33095 if (ret)
33096 return -EFAULT;
33097 } else {
33098 @@ -780,7 +780,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
33099 if (!port_has_data(port) && !port->host_connected)
33100 return 0;
33101
33102 - return fill_readbuf(port, ubuf, count, true);
33103 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
33104 }
33105
33106 static int wait_port_writable(struct port *port, bool nonblock)
33107 diff --git a/drivers/clocksource/arm_generic.c b/drivers/clocksource/arm_generic.c
33108 index 8ae1a61..9c00613 100644
33109 --- a/drivers/clocksource/arm_generic.c
33110 +++ b/drivers/clocksource/arm_generic.c
33111 @@ -181,7 +181,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
33112 return NOTIFY_OK;
33113 }
33114
33115 -static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
33116 +static struct notifier_block arch_timer_cpu_nb = {
33117 .notifier_call = arch_timer_cpu_notify,
33118 };
33119
33120 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
33121 index 1f93dbd..edf95ff 100644
33122 --- a/drivers/cpufreq/cpufreq.c
33123 +++ b/drivers/cpufreq/cpufreq.c
33124 @@ -1843,7 +1843,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
33125 return NOTIFY_OK;
33126 }
33127
33128 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
33129 +static struct notifier_block cpufreq_cpu_notifier = {
33130 .notifier_call = cpufreq_cpu_callback,
33131 };
33132
33133 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
33134 index 9d7732b..0b1a793 100644
33135 --- a/drivers/cpufreq/cpufreq_stats.c
33136 +++ b/drivers/cpufreq/cpufreq_stats.c
33137 @@ -340,7 +340,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
33138 }
33139
33140 /* priority=1 so this will get called before cpufreq_remove_dev */
33141 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
33142 +static struct notifier_block cpufreq_stat_cpu_notifier = {
33143 .notifier_call = cpufreq_stat_cpu_callback,
33144 .priority = 1,
33145 };
33146 diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
33147 index 3315e4b..fc38316 100644
33148 --- a/drivers/dma/sh/shdma.c
33149 +++ b/drivers/dma/sh/shdma.c
33150 @@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
33151 return ret;
33152 }
33153
33154 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
33155 +static struct notifier_block sh_dmae_nmi_notifier = {
33156 .notifier_call = sh_dmae_nmi_handler,
33157
33158 /* Run before NMI debug handler and KGDB */
33159 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
33160 index 0056c4d..725934f 100644
33161 --- a/drivers/edac/edac_pci_sysfs.c
33162 +++ b/drivers/edac/edac_pci_sysfs.c
33163 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
33164 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
33165 static int edac_pci_poll_msec = 1000; /* one second workq period */
33166
33167 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
33168 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
33169 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
33170 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
33171
33172 static struct kobject *edac_pci_top_main_kobj;
33173 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
33174 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33175 edac_printk(KERN_CRIT, EDAC_PCI,
33176 "Signaled System Error on %s\n",
33177 pci_name(dev));
33178 - atomic_inc(&pci_nonparity_count);
33179 + atomic_inc_unchecked(&pci_nonparity_count);
33180 }
33181
33182 if (status & (PCI_STATUS_PARITY)) {
33183 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33184 "Master Data Parity Error on %s\n",
33185 pci_name(dev));
33186
33187 - atomic_inc(&pci_parity_count);
33188 + atomic_inc_unchecked(&pci_parity_count);
33189 }
33190
33191 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33192 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33193 "Detected Parity Error on %s\n",
33194 pci_name(dev));
33195
33196 - atomic_inc(&pci_parity_count);
33197 + atomic_inc_unchecked(&pci_parity_count);
33198 }
33199 }
33200
33201 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33202 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
33203 "Signaled System Error on %s\n",
33204 pci_name(dev));
33205 - atomic_inc(&pci_nonparity_count);
33206 + atomic_inc_unchecked(&pci_nonparity_count);
33207 }
33208
33209 if (status & (PCI_STATUS_PARITY)) {
33210 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33211 "Master Data Parity Error on "
33212 "%s\n", pci_name(dev));
33213
33214 - atomic_inc(&pci_parity_count);
33215 + atomic_inc_unchecked(&pci_parity_count);
33216 }
33217
33218 if (status & (PCI_STATUS_DETECTED_PARITY)) {
33219 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
33220 "Detected Parity Error on %s\n",
33221 pci_name(dev));
33222
33223 - atomic_inc(&pci_parity_count);
33224 + atomic_inc_unchecked(&pci_parity_count);
33225 }
33226 }
33227 }
33228 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
33229 if (!check_pci_errors)
33230 return;
33231
33232 - before_count = atomic_read(&pci_parity_count);
33233 + before_count = atomic_read_unchecked(&pci_parity_count);
33234
33235 /* scan all PCI devices looking for a Parity Error on devices and
33236 * bridges.
33237 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
33238 /* Only if operator has selected panic on PCI Error */
33239 if (edac_pci_get_panic_on_pe()) {
33240 /* If the count is different 'after' from 'before' */
33241 - if (before_count != atomic_read(&pci_parity_count))
33242 + if (before_count != atomic_read_unchecked(&pci_parity_count))
33243 panic("EDAC: PCI Parity Error");
33244 }
33245 }
33246 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
33247 index 6796799..99e8377 100644
33248 --- a/drivers/edac/mce_amd.h
33249 +++ b/drivers/edac/mce_amd.h
33250 @@ -78,7 +78,7 @@ extern const char * const ii_msgs[];
33251 struct amd_decoder_ops {
33252 bool (*mc0_mce)(u16, u8);
33253 bool (*mc1_mce)(u16, u8);
33254 -};
33255 +} __no_const;
33256
33257 void amd_report_gart_errors(bool);
33258 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
33259 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
33260 index 57ea7f4..789e3c3 100644
33261 --- a/drivers/firewire/core-card.c
33262 +++ b/drivers/firewire/core-card.c
33263 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
33264
33265 void fw_core_remove_card(struct fw_card *card)
33266 {
33267 - struct fw_card_driver dummy_driver = dummy_driver_template;
33268 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
33269
33270 card->driver->update_phy_reg(card, 4,
33271 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
33272 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
33273 index f8d2287..5aaf4db 100644
33274 --- a/drivers/firewire/core-cdev.c
33275 +++ b/drivers/firewire/core-cdev.c
33276 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
33277 int ret;
33278
33279 if ((request->channels == 0 && request->bandwidth == 0) ||
33280 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
33281 - request->bandwidth < 0)
33282 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
33283 return -EINVAL;
33284
33285 r = kmalloc(sizeof(*r), GFP_KERNEL);
33286 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
33287 index 28a94c7..58da63a 100644
33288 --- a/drivers/firewire/core-transaction.c
33289 +++ b/drivers/firewire/core-transaction.c
33290 @@ -38,6 +38,7 @@
33291 #include <linux/timer.h>
33292 #include <linux/types.h>
33293 #include <linux/workqueue.h>
33294 +#include <linux/sched.h>
33295
33296 #include <asm/byteorder.h>
33297
33298 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
33299 index 515a42c..5ecf3ba 100644
33300 --- a/drivers/firewire/core.h
33301 +++ b/drivers/firewire/core.h
33302 @@ -111,6 +111,7 @@ struct fw_card_driver {
33303
33304 int (*stop_iso)(struct fw_iso_context *ctx);
33305 };
33306 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
33307
33308 void fw_card_initialize(struct fw_card *card,
33309 const struct fw_card_driver *driver, struct device *device);
33310 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
33311 index 982f1f5..d21e5da 100644
33312 --- a/drivers/firmware/dmi_scan.c
33313 +++ b/drivers/firmware/dmi_scan.c
33314 @@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
33315 }
33316 }
33317 else {
33318 - /*
33319 - * no iounmap() for that ioremap(); it would be a no-op, but
33320 - * it's so early in setup that sucker gets confused into doing
33321 - * what it shouldn't if we actually call it.
33322 - */
33323 p = dmi_ioremap(0xF0000, 0x10000);
33324 if (p == NULL)
33325 goto error;
33326 @@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
33327 if (buf == NULL)
33328 return -1;
33329
33330 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
33331 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
33332
33333 iounmap(buf);
33334 return 0;
33335 diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
33336 index f5596db..9355ce6 100644
33337 --- a/drivers/firmware/efivars.c
33338 +++ b/drivers/firmware/efivars.c
33339 @@ -132,7 +132,7 @@ struct efivar_attribute {
33340 };
33341
33342 static struct efivars __efivars;
33343 -static struct efivar_operations ops;
33344 +static efivar_operations_no_const ops __read_only;
33345
33346 #define PSTORE_EFI_ATTRIBUTES \
33347 (EFI_VARIABLE_NON_VOLATILE | \
33348 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
33349 index 9902732..64b62dd 100644
33350 --- a/drivers/gpio/gpio-vr41xx.c
33351 +++ b/drivers/gpio/gpio-vr41xx.c
33352 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
33353 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
33354 maskl, pendl, maskh, pendh);
33355
33356 - atomic_inc(&irq_err_count);
33357 + atomic_inc_unchecked(&irq_err_count);
33358
33359 return -EINVAL;
33360 }
33361 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
33362 index 7b2d378..cc947ea 100644
33363 --- a/drivers/gpu/drm/drm_crtc_helper.c
33364 +++ b/drivers/gpu/drm/drm_crtc_helper.c
33365 @@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
33366 struct drm_crtc *tmp;
33367 int crtc_mask = 1;
33368
33369 - WARN(!crtc, "checking null crtc?\n");
33370 + BUG_ON(!crtc);
33371
33372 dev = crtc->dev;
33373
33374 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
33375 index be174ca..0bcbb71 100644
33376 --- a/drivers/gpu/drm/drm_drv.c
33377 +++ b/drivers/gpu/drm/drm_drv.c
33378 @@ -307,7 +307,7 @@ module_exit(drm_core_exit);
33379 /**
33380 * Copy and IOCTL return string to user space
33381 */
33382 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
33383 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
33384 {
33385 int len;
33386
33387 @@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
33388 return -ENODEV;
33389
33390 atomic_inc(&dev->ioctl_count);
33391 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
33392 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
33393 ++file_priv->ioctl_count;
33394
33395 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
33396 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
33397 index 133b413..fd68225 100644
33398 --- a/drivers/gpu/drm/drm_fops.c
33399 +++ b/drivers/gpu/drm/drm_fops.c
33400 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
33401 }
33402
33403 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
33404 - atomic_set(&dev->counts[i], 0);
33405 + atomic_set_unchecked(&dev->counts[i], 0);
33406
33407 dev->sigdata.lock = NULL;
33408
33409 @@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
33410 if (drm_device_is_unplugged(dev))
33411 return -ENODEV;
33412
33413 - if (!dev->open_count++)
33414 + if (local_inc_return(&dev->open_count) == 1)
33415 need_setup = 1;
33416 mutex_lock(&dev->struct_mutex);
33417 old_mapping = dev->dev_mapping;
33418 @@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
33419 retcode = drm_open_helper(inode, filp, dev);
33420 if (retcode)
33421 goto err_undo;
33422 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
33423 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
33424 if (need_setup) {
33425 retcode = drm_setup(dev);
33426 if (retcode)
33427 @@ -164,7 +164,7 @@ err_undo:
33428 iput(container_of(dev->dev_mapping, struct inode, i_data));
33429 dev->dev_mapping = old_mapping;
33430 mutex_unlock(&dev->struct_mutex);
33431 - dev->open_count--;
33432 + local_dec(&dev->open_count);
33433 return retcode;
33434 }
33435 EXPORT_SYMBOL(drm_open);
33436 @@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
33437
33438 mutex_lock(&drm_global_mutex);
33439
33440 - DRM_DEBUG("open_count = %d\n", dev->open_count);
33441 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
33442
33443 if (dev->driver->preclose)
33444 dev->driver->preclose(dev, file_priv);
33445 @@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
33446 * Begin inline drm_release
33447 */
33448
33449 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
33450 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
33451 task_pid_nr(current),
33452 (long)old_encode_dev(file_priv->minor->device),
33453 - dev->open_count);
33454 + local_read(&dev->open_count));
33455
33456 /* Release any auth tokens that might point to this file_priv,
33457 (do that under the drm_global_mutex) */
33458 @@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
33459 * End inline drm_release
33460 */
33461
33462 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
33463 - if (!--dev->open_count) {
33464 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
33465 + if (local_dec_and_test(&dev->open_count)) {
33466 if (atomic_read(&dev->ioctl_count)) {
33467 DRM_ERROR("Device busy: %d\n",
33468 atomic_read(&dev->ioctl_count));
33469 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
33470 index f731116..629842c 100644
33471 --- a/drivers/gpu/drm/drm_global.c
33472 +++ b/drivers/gpu/drm/drm_global.c
33473 @@ -36,7 +36,7 @@
33474 struct drm_global_item {
33475 struct mutex mutex;
33476 void *object;
33477 - int refcount;
33478 + atomic_t refcount;
33479 };
33480
33481 static struct drm_global_item glob[DRM_GLOBAL_NUM];
33482 @@ -49,7 +49,7 @@ void drm_global_init(void)
33483 struct drm_global_item *item = &glob[i];
33484 mutex_init(&item->mutex);
33485 item->object = NULL;
33486 - item->refcount = 0;
33487 + atomic_set(&item->refcount, 0);
33488 }
33489 }
33490
33491 @@ -59,7 +59,7 @@ void drm_global_release(void)
33492 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
33493 struct drm_global_item *item = &glob[i];
33494 BUG_ON(item->object != NULL);
33495 - BUG_ON(item->refcount != 0);
33496 + BUG_ON(atomic_read(&item->refcount) != 0);
33497 }
33498 }
33499
33500 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33501 void *object;
33502
33503 mutex_lock(&item->mutex);
33504 - if (item->refcount == 0) {
33505 + if (atomic_read(&item->refcount) == 0) {
33506 item->object = kzalloc(ref->size, GFP_KERNEL);
33507 if (unlikely(item->object == NULL)) {
33508 ret = -ENOMEM;
33509 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
33510 goto out_err;
33511
33512 }
33513 - ++item->refcount;
33514 + atomic_inc(&item->refcount);
33515 ref->object = item->object;
33516 object = item->object;
33517 mutex_unlock(&item->mutex);
33518 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
33519 struct drm_global_item *item = &glob[ref->global_type];
33520
33521 mutex_lock(&item->mutex);
33522 - BUG_ON(item->refcount == 0);
33523 + BUG_ON(atomic_read(&item->refcount) == 0);
33524 BUG_ON(ref->object != item->object);
33525 - if (--item->refcount == 0) {
33526 + if (atomic_dec_and_test(&item->refcount)) {
33527 ref->release(ref);
33528 item->object = NULL;
33529 }
33530 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
33531 index d4b20ce..77a8d41 100644
33532 --- a/drivers/gpu/drm/drm_info.c
33533 +++ b/drivers/gpu/drm/drm_info.c
33534 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
33535 struct drm_local_map *map;
33536 struct drm_map_list *r_list;
33537
33538 - /* Hardcoded from _DRM_FRAME_BUFFER,
33539 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
33540 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
33541 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
33542 + static const char * const types[] = {
33543 + [_DRM_FRAME_BUFFER] = "FB",
33544 + [_DRM_REGISTERS] = "REG",
33545 + [_DRM_SHM] = "SHM",
33546 + [_DRM_AGP] = "AGP",
33547 + [_DRM_SCATTER_GATHER] = "SG",
33548 + [_DRM_CONSISTENT] = "PCI",
33549 + [_DRM_GEM] = "GEM" };
33550 const char *type;
33551 int i;
33552
33553 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
33554 map = r_list->map;
33555 if (!map)
33556 continue;
33557 - if (map->type < 0 || map->type > 5)
33558 + if (map->type >= ARRAY_SIZE(types))
33559 type = "??";
33560 else
33561 type = types[map->type];
33562 @@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
33563 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
33564 vma->vm_flags & VM_LOCKED ? 'l' : '-',
33565 vma->vm_flags & VM_IO ? 'i' : '-',
33566 +#ifdef CONFIG_GRKERNSEC_HIDESYM
33567 + 0);
33568 +#else
33569 vma->vm_pgoff);
33570 +#endif
33571
33572 #if defined(__i386__)
33573 pgprot = pgprot_val(vma->vm_page_prot);
33574 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
33575 index 2f4c434..764794b 100644
33576 --- a/drivers/gpu/drm/drm_ioc32.c
33577 +++ b/drivers/gpu/drm/drm_ioc32.c
33578 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
33579 request = compat_alloc_user_space(nbytes);
33580 if (!access_ok(VERIFY_WRITE, request, nbytes))
33581 return -EFAULT;
33582 - list = (struct drm_buf_desc *) (request + 1);
33583 + list = (struct drm_buf_desc __user *) (request + 1);
33584
33585 if (__put_user(count, &request->count)
33586 || __put_user(list, &request->list))
33587 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
33588 request = compat_alloc_user_space(nbytes);
33589 if (!access_ok(VERIFY_WRITE, request, nbytes))
33590 return -EFAULT;
33591 - list = (struct drm_buf_pub *) (request + 1);
33592 + list = (struct drm_buf_pub __user *) (request + 1);
33593
33594 if (__put_user(count, &request->count)
33595 || __put_user(list, &request->list))
33596 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
33597 index e77bd8b..1571b85 100644
33598 --- a/drivers/gpu/drm/drm_ioctl.c
33599 +++ b/drivers/gpu/drm/drm_ioctl.c
33600 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
33601 stats->data[i].value =
33602 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
33603 else
33604 - stats->data[i].value = atomic_read(&dev->counts[i]);
33605 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
33606 stats->data[i].type = dev->types[i];
33607 }
33608
33609 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
33610 index d752c96..fe08455 100644
33611 --- a/drivers/gpu/drm/drm_lock.c
33612 +++ b/drivers/gpu/drm/drm_lock.c
33613 @@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33614 if (drm_lock_take(&master->lock, lock->context)) {
33615 master->lock.file_priv = file_priv;
33616 master->lock.lock_time = jiffies;
33617 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
33618 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
33619 break; /* Got lock */
33620 }
33621
33622 @@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
33623 return -EINVAL;
33624 }
33625
33626 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
33627 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
33628
33629 if (drm_lock_free(&master->lock, lock->context)) {
33630 /* FIXME: Should really bail out here. */
33631 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
33632 index 200e104..59facda 100644
33633 --- a/drivers/gpu/drm/drm_stub.c
33634 +++ b/drivers/gpu/drm/drm_stub.c
33635 @@ -516,7 +516,7 @@ void drm_unplug_dev(struct drm_device *dev)
33636
33637 drm_device_set_unplugged(dev);
33638
33639 - if (dev->open_count == 0) {
33640 + if (local_read(&dev->open_count) == 0) {
33641 drm_put_dev(dev);
33642 }
33643 mutex_unlock(&drm_global_mutex);
33644 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
33645 index 004ecdf..db1f6e0 100644
33646 --- a/drivers/gpu/drm/i810/i810_dma.c
33647 +++ b/drivers/gpu/drm/i810/i810_dma.c
33648 @@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
33649 dma->buflist[vertex->idx],
33650 vertex->discard, vertex->used);
33651
33652 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33653 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33654 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
33655 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33656 sarea_priv->last_enqueue = dev_priv->counter - 1;
33657 sarea_priv->last_dispatch = (int)hw_status[5];
33658
33659 @@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
33660 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
33661 mc->last_render);
33662
33663 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33664 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
33665 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
33666 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
33667 sarea_priv->last_enqueue = dev_priv->counter - 1;
33668 sarea_priv->last_dispatch = (int)hw_status[5];
33669
33670 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
33671 index 6e0acad..93c8289 100644
33672 --- a/drivers/gpu/drm/i810/i810_drv.h
33673 +++ b/drivers/gpu/drm/i810/i810_drv.h
33674 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
33675 int page_flipping;
33676
33677 wait_queue_head_t irq_queue;
33678 - atomic_t irq_received;
33679 - atomic_t irq_emitted;
33680 + atomic_unchecked_t irq_received;
33681 + atomic_unchecked_t irq_emitted;
33682
33683 int front_offset;
33684 } drm_i810_private_t;
33685 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
33686 index 9d4a2c2..32a119f 100644
33687 --- a/drivers/gpu/drm/i915/i915_debugfs.c
33688 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
33689 @@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
33690 I915_READ(GTIMR));
33691 }
33692 seq_printf(m, "Interrupts received: %d\n",
33693 - atomic_read(&dev_priv->irq_received));
33694 + atomic_read_unchecked(&dev_priv->irq_received));
33695 for_each_ring(ring, dev_priv, i) {
33696 if (IS_GEN6(dev) || IS_GEN7(dev)) {
33697 seq_printf(m,
33698 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
33699 index 99daa89..84ebd44 100644
33700 --- a/drivers/gpu/drm/i915/i915_dma.c
33701 +++ b/drivers/gpu/drm/i915/i915_dma.c
33702 @@ -1253,7 +1253,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
33703 bool can_switch;
33704
33705 spin_lock(&dev->count_lock);
33706 - can_switch = (dev->open_count == 0);
33707 + can_switch = (local_read(&dev->open_count) == 0);
33708 spin_unlock(&dev->count_lock);
33709 return can_switch;
33710 }
33711 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
33712 index 12ab3bd..b3bed3b 100644
33713 --- a/drivers/gpu/drm/i915/i915_drv.h
33714 +++ b/drivers/gpu/drm/i915/i915_drv.h
33715 @@ -656,7 +656,7 @@ typedef struct drm_i915_private {
33716 drm_dma_handle_t *status_page_dmah;
33717 struct resource mch_res;
33718
33719 - atomic_t irq_received;
33720 + atomic_unchecked_t irq_received;
33721
33722 /* protects the irq masks */
33723 spinlock_t irq_lock;
33724 @@ -1102,7 +1102,7 @@ struct drm_i915_gem_object {
33725 * will be page flipped away on the next vblank. When it
33726 * reaches 0, dev_priv->pending_flip_queue will be woken up.
33727 */
33728 - atomic_t pending_flip;
33729 + atomic_unchecked_t pending_flip;
33730 };
33731 #define to_gem_object(obj) (&((struct drm_i915_gem_object *)(obj))->base)
33732
33733 @@ -1633,7 +1633,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
33734 struct drm_i915_private *dev_priv, unsigned port);
33735 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
33736 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
33737 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33738 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
33739 {
33740 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
33741 }
33742 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33743 index 26d08bb..fccb984 100644
33744 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33745 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
33746 @@ -672,7 +672,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
33747 i915_gem_clflush_object(obj);
33748
33749 if (obj->base.pending_write_domain)
33750 - flips |= atomic_read(&obj->pending_flip);
33751 + flips |= atomic_read_unchecked(&obj->pending_flip);
33752
33753 flush_domains |= obj->base.write_domain;
33754 }
33755 @@ -703,9 +703,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
33756
33757 static int
33758 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
33759 - int count)
33760 + unsigned int count)
33761 {
33762 - int i;
33763 + unsigned int i;
33764
33765 for (i = 0; i < count; i++) {
33766 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
33767 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
33768 index fe84338..a863190 100644
33769 --- a/drivers/gpu/drm/i915/i915_irq.c
33770 +++ b/drivers/gpu/drm/i915/i915_irq.c
33771 @@ -535,7 +535,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
33772 u32 pipe_stats[I915_MAX_PIPES];
33773 bool blc_event;
33774
33775 - atomic_inc(&dev_priv->irq_received);
33776 + atomic_inc_unchecked(&dev_priv->irq_received);
33777
33778 while (true) {
33779 iir = I915_READ(VLV_IIR);
33780 @@ -688,7 +688,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
33781 irqreturn_t ret = IRQ_NONE;
33782 int i;
33783
33784 - atomic_inc(&dev_priv->irq_received);
33785 + atomic_inc_unchecked(&dev_priv->irq_received);
33786
33787 /* disable master interrupt before clearing iir */
33788 de_ier = I915_READ(DEIER);
33789 @@ -760,7 +760,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
33790 int ret = IRQ_NONE;
33791 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
33792
33793 - atomic_inc(&dev_priv->irq_received);
33794 + atomic_inc_unchecked(&dev_priv->irq_received);
33795
33796 /* disable master interrupt before clearing iir */
33797 de_ier = I915_READ(DEIER);
33798 @@ -1787,7 +1787,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
33799 {
33800 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33801
33802 - atomic_set(&dev_priv->irq_received, 0);
33803 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33804
33805 I915_WRITE(HWSTAM, 0xeffe);
33806
33807 @@ -1813,7 +1813,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
33808 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33809 int pipe;
33810
33811 - atomic_set(&dev_priv->irq_received, 0);
33812 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33813
33814 /* VLV magic */
33815 I915_WRITE(VLV_IMR, 0);
33816 @@ -2108,7 +2108,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
33817 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33818 int pipe;
33819
33820 - atomic_set(&dev_priv->irq_received, 0);
33821 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33822
33823 for_each_pipe(pipe)
33824 I915_WRITE(PIPESTAT(pipe), 0);
33825 @@ -2159,7 +2159,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
33826 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
33827 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
33828
33829 - atomic_inc(&dev_priv->irq_received);
33830 + atomic_inc_unchecked(&dev_priv->irq_received);
33831
33832 iir = I915_READ16(IIR);
33833 if (iir == 0)
33834 @@ -2244,7 +2244,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
33835 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33836 int pipe;
33837
33838 - atomic_set(&dev_priv->irq_received, 0);
33839 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33840
33841 if (I915_HAS_HOTPLUG(dev)) {
33842 I915_WRITE(PORT_HOTPLUG_EN, 0);
33843 @@ -2339,7 +2339,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
33844 };
33845 int pipe, ret = IRQ_NONE;
33846
33847 - atomic_inc(&dev_priv->irq_received);
33848 + atomic_inc_unchecked(&dev_priv->irq_received);
33849
33850 iir = I915_READ(IIR);
33851 do {
33852 @@ -2465,7 +2465,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
33853 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
33854 int pipe;
33855
33856 - atomic_set(&dev_priv->irq_received, 0);
33857 + atomic_set_unchecked(&dev_priv->irq_received, 0);
33858
33859 I915_WRITE(PORT_HOTPLUG_EN, 0);
33860 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
33861 @@ -2572,7 +2572,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
33862 int irq_received;
33863 int ret = IRQ_NONE, pipe;
33864
33865 - atomic_inc(&dev_priv->irq_received);
33866 + atomic_inc_unchecked(&dev_priv->irq_received);
33867
33868 iir = I915_READ(IIR);
33869
33870 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
33871 index da1ad9c..10d368b 100644
33872 --- a/drivers/gpu/drm/i915/intel_display.c
33873 +++ b/drivers/gpu/drm/i915/intel_display.c
33874 @@ -2244,7 +2244,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
33875
33876 wait_event(dev_priv->pending_flip_queue,
33877 atomic_read(&dev_priv->mm.wedged) ||
33878 - atomic_read(&obj->pending_flip) == 0);
33879 + atomic_read_unchecked(&obj->pending_flip) == 0);
33880
33881 /* Big Hammer, we also need to ensure that any pending
33882 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
33883 @@ -7109,8 +7109,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
33884
33885 obj = work->old_fb_obj;
33886
33887 - atomic_clear_mask(1 << intel_crtc->plane,
33888 - &obj->pending_flip.counter);
33889 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
33890 wake_up(&dev_priv->pending_flip_queue);
33891
33892 queue_work(dev_priv->wq, &work->work);
33893 @@ -7477,7 +7476,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33894 /* Block clients from rendering to the new back buffer until
33895 * the flip occurs and the object is no longer visible.
33896 */
33897 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33898 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33899 atomic_inc(&intel_crtc->unpin_work_count);
33900
33901 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33902 @@ -7494,7 +7493,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33903
33904 cleanup_pending:
33905 atomic_dec(&intel_crtc->unpin_work_count);
33906 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33907 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33908 drm_gem_object_unreference(&work->old_fb_obj->base);
33909 drm_gem_object_unreference(&obj->base);
33910 mutex_unlock(&dev->struct_mutex);
33911 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33912 index 54558a0..2d97005 100644
33913 --- a/drivers/gpu/drm/mga/mga_drv.h
33914 +++ b/drivers/gpu/drm/mga/mga_drv.h
33915 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33916 u32 clear_cmd;
33917 u32 maccess;
33918
33919 - atomic_t vbl_received; /**< Number of vblanks received. */
33920 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33921 wait_queue_head_t fence_queue;
33922 - atomic_t last_fence_retired;
33923 + atomic_unchecked_t last_fence_retired;
33924 u32 next_fence_to_post;
33925
33926 unsigned int fb_cpp;
33927 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33928 index 598c281..60d590e 100644
33929 --- a/drivers/gpu/drm/mga/mga_irq.c
33930 +++ b/drivers/gpu/drm/mga/mga_irq.c
33931 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33932 if (crtc != 0)
33933 return 0;
33934
33935 - return atomic_read(&dev_priv->vbl_received);
33936 + return atomic_read_unchecked(&dev_priv->vbl_received);
33937 }
33938
33939
33940 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33941 /* VBLANK interrupt */
33942 if (status & MGA_VLINEPEN) {
33943 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33944 - atomic_inc(&dev_priv->vbl_received);
33945 + atomic_inc_unchecked(&dev_priv->vbl_received);
33946 drm_handle_vblank(dev, 0);
33947 handled = 1;
33948 }
33949 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33950 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33951 MGA_WRITE(MGA_PRIMEND, prim_end);
33952
33953 - atomic_inc(&dev_priv->last_fence_retired);
33954 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
33955 DRM_WAKEUP(&dev_priv->fence_queue);
33956 handled = 1;
33957 }
33958 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33959 * using fences.
33960 */
33961 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33962 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33963 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33964 - *sequence) <= (1 << 23)));
33965
33966 *sequence = cur_fence;
33967 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33968 index 865eddf..62c4cc3 100644
33969 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33970 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33971 @@ -1015,7 +1015,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33972 struct bit_table {
33973 const char id;
33974 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33975 -};
33976 +} __no_const;
33977
33978 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33979
33980 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33981 index aa89eb9..d45d38b 100644
33982 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33983 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33984 @@ -80,7 +80,7 @@ struct nouveau_drm {
33985 struct drm_global_reference mem_global_ref;
33986 struct ttm_bo_global_ref bo_global_ref;
33987 struct ttm_bo_device bdev;
33988 - atomic_t validate_sequence;
33989 + atomic_unchecked_t validate_sequence;
33990 int (*move)(struct nouveau_channel *,
33991 struct ttm_buffer_object *,
33992 struct ttm_mem_reg *, struct ttm_mem_reg *);
33993 diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33994 index cdb83ac..27f0a16 100644
33995 --- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33996 +++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33997 @@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33998 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33999 struct nouveau_channel *);
34000 u32 (*read)(struct nouveau_channel *);
34001 -};
34002 +} __no_const;
34003
34004 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
34005
34006 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
34007 index 8bf695c..9fbc90a 100644
34008 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
34009 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
34010 @@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
34011 int trycnt = 0;
34012 int ret, i;
34013
34014 - sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
34015 + sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
34016 retry:
34017 if (++trycnt > 100000) {
34018 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
34019 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
34020 index 25d3495..d81aaf6 100644
34021 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
34022 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
34023 @@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
34024 bool can_switch;
34025
34026 spin_lock(&dev->count_lock);
34027 - can_switch = (dev->open_count == 0);
34028 + can_switch = (local_read(&dev->open_count) == 0);
34029 spin_unlock(&dev->count_lock);
34030 return can_switch;
34031 }
34032 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
34033 index d4660cf..70dbe65 100644
34034 --- a/drivers/gpu/drm/r128/r128_cce.c
34035 +++ b/drivers/gpu/drm/r128/r128_cce.c
34036 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
34037
34038 /* GH: Simple idle check.
34039 */
34040 - atomic_set(&dev_priv->idle_count, 0);
34041 + atomic_set_unchecked(&dev_priv->idle_count, 0);
34042
34043 /* We don't support anything other than bus-mastering ring mode,
34044 * but the ring can be in either AGP or PCI space for the ring
34045 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
34046 index 930c71b..499aded 100644
34047 --- a/drivers/gpu/drm/r128/r128_drv.h
34048 +++ b/drivers/gpu/drm/r128/r128_drv.h
34049 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
34050 int is_pci;
34051 unsigned long cce_buffers_offset;
34052
34053 - atomic_t idle_count;
34054 + atomic_unchecked_t idle_count;
34055
34056 int page_flipping;
34057 int current_page;
34058 u32 crtc_offset;
34059 u32 crtc_offset_cntl;
34060
34061 - atomic_t vbl_received;
34062 + atomic_unchecked_t vbl_received;
34063
34064 u32 color_fmt;
34065 unsigned int front_offset;
34066 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
34067 index 2ea4f09..d391371 100644
34068 --- a/drivers/gpu/drm/r128/r128_irq.c
34069 +++ b/drivers/gpu/drm/r128/r128_irq.c
34070 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
34071 if (crtc != 0)
34072 return 0;
34073
34074 - return atomic_read(&dev_priv->vbl_received);
34075 + return atomic_read_unchecked(&dev_priv->vbl_received);
34076 }
34077
34078 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34079 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
34080 /* VBLANK interrupt */
34081 if (status & R128_CRTC_VBLANK_INT) {
34082 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
34083 - atomic_inc(&dev_priv->vbl_received);
34084 + atomic_inc_unchecked(&dev_priv->vbl_received);
34085 drm_handle_vblank(dev, 0);
34086 return IRQ_HANDLED;
34087 }
34088 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
34089 index 19bb7e6..de7e2a2 100644
34090 --- a/drivers/gpu/drm/r128/r128_state.c
34091 +++ b/drivers/gpu/drm/r128/r128_state.c
34092 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
34093
34094 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
34095 {
34096 - if (atomic_read(&dev_priv->idle_count) == 0)
34097 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
34098 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
34099 else
34100 - atomic_set(&dev_priv->idle_count, 0);
34101 + atomic_set_unchecked(&dev_priv->idle_count, 0);
34102 }
34103
34104 #endif
34105 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
34106 index 5a82b6b..9e69c73 100644
34107 --- a/drivers/gpu/drm/radeon/mkregtable.c
34108 +++ b/drivers/gpu/drm/radeon/mkregtable.c
34109 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
34110 regex_t mask_rex;
34111 regmatch_t match[4];
34112 char buf[1024];
34113 - size_t end;
34114 + long end;
34115 int len;
34116 int done = 0;
34117 int r;
34118 unsigned o;
34119 struct offset *offset;
34120 char last_reg_s[10];
34121 - int last_reg;
34122 + unsigned long last_reg;
34123
34124 if (regcomp
34125 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
34126 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
34127 index 0d6562b..a154330 100644
34128 --- a/drivers/gpu/drm/radeon/radeon_device.c
34129 +++ b/drivers/gpu/drm/radeon/radeon_device.c
34130 @@ -969,7 +969,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
34131 bool can_switch;
34132
34133 spin_lock(&dev->count_lock);
34134 - can_switch = (dev->open_count == 0);
34135 + can_switch = (local_read(&dev->open_count) == 0);
34136 spin_unlock(&dev->count_lock);
34137 return can_switch;
34138 }
34139 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
34140 index e7fdf16..f4f6490 100644
34141 --- a/drivers/gpu/drm/radeon/radeon_drv.h
34142 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
34143 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
34144
34145 /* SW interrupt */
34146 wait_queue_head_t swi_queue;
34147 - atomic_t swi_emitted;
34148 + atomic_unchecked_t swi_emitted;
34149 int vblank_crtc;
34150 uint32_t irq_enable_reg;
34151 uint32_t r500_disp_irq_reg;
34152 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
34153 index c180df8..cd80dd2d 100644
34154 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
34155 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
34156 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
34157 request = compat_alloc_user_space(sizeof(*request));
34158 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
34159 || __put_user(req32.param, &request->param)
34160 - || __put_user((void __user *)(unsigned long)req32.value,
34161 + || __put_user((unsigned long)req32.value,
34162 &request->value))
34163 return -EFAULT;
34164
34165 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
34166 index e771033..a0bc6b3 100644
34167 --- a/drivers/gpu/drm/radeon/radeon_irq.c
34168 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
34169 @@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
34170 unsigned int ret;
34171 RING_LOCALS;
34172
34173 - atomic_inc(&dev_priv->swi_emitted);
34174 - ret = atomic_read(&dev_priv->swi_emitted);
34175 + atomic_inc_unchecked(&dev_priv->swi_emitted);
34176 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
34177
34178 BEGIN_RING(4);
34179 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
34180 @@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
34181 drm_radeon_private_t *dev_priv =
34182 (drm_radeon_private_t *) dev->dev_private;
34183
34184 - atomic_set(&dev_priv->swi_emitted, 0);
34185 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
34186 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
34187
34188 dev->max_vblank_count = 0x001fffff;
34189 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
34190 index 8e9057b..af6dacb 100644
34191 --- a/drivers/gpu/drm/radeon/radeon_state.c
34192 +++ b/drivers/gpu/drm/radeon/radeon_state.c
34193 @@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
34194 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
34195 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
34196
34197 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34198 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
34199 sarea_priv->nbox * sizeof(depth_boxes[0])))
34200 return -EFAULT;
34201
34202 @@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
34203 {
34204 drm_radeon_private_t *dev_priv = dev->dev_private;
34205 drm_radeon_getparam_t *param = data;
34206 - int value;
34207 + int value = 0;
34208
34209 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
34210
34211 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
34212 index 93f760e..33d9839 100644
34213 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
34214 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
34215 @@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
34216 man->size = size >> PAGE_SHIFT;
34217 }
34218
34219 -static struct vm_operations_struct radeon_ttm_vm_ops;
34220 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
34221 static const struct vm_operations_struct *ttm_vm_ops = NULL;
34222
34223 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
34224 @@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
34225 }
34226 if (unlikely(ttm_vm_ops == NULL)) {
34227 ttm_vm_ops = vma->vm_ops;
34228 + pax_open_kernel();
34229 radeon_ttm_vm_ops = *ttm_vm_ops;
34230 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
34231 + pax_close_kernel();
34232 }
34233 vma->vm_ops = &radeon_ttm_vm_ops;
34234 return 0;
34235 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
34236 index 5706d2a..17aedaa 100644
34237 --- a/drivers/gpu/drm/radeon/rs690.c
34238 +++ b/drivers/gpu/drm/radeon/rs690.c
34239 @@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
34240 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
34241 rdev->pm.sideport_bandwidth.full)
34242 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
34243 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
34244 + read_delay_latency.full = dfixed_const(800 * 1000);
34245 read_delay_latency.full = dfixed_div(read_delay_latency,
34246 rdev->pm.igp_sideport_mclk);
34247 + a.full = dfixed_const(370);
34248 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
34249 } else {
34250 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
34251 rdev->pm.k8_bandwidth.full)
34252 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34253 index bd2a3b4..122d9ad 100644
34254 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
34255 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
34256 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
34257 static int ttm_pool_mm_shrink(struct shrinker *shrink,
34258 struct shrink_control *sc)
34259 {
34260 - static atomic_t start_pool = ATOMIC_INIT(0);
34261 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
34262 unsigned i;
34263 - unsigned pool_offset = atomic_add_return(1, &start_pool);
34264 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
34265 struct ttm_page_pool *pool;
34266 int shrink_pages = sc->nr_to_scan;
34267
34268 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
34269 index 893a650..6190d3b 100644
34270 --- a/drivers/gpu/drm/via/via_drv.h
34271 +++ b/drivers/gpu/drm/via/via_drv.h
34272 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
34273 typedef uint32_t maskarray_t[5];
34274
34275 typedef struct drm_via_irq {
34276 - atomic_t irq_received;
34277 + atomic_unchecked_t irq_received;
34278 uint32_t pending_mask;
34279 uint32_t enable_mask;
34280 wait_queue_head_t irq_queue;
34281 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
34282 struct timeval last_vblank;
34283 int last_vblank_valid;
34284 unsigned usec_per_vblank;
34285 - atomic_t vbl_received;
34286 + atomic_unchecked_t vbl_received;
34287 drm_via_state_t hc_state;
34288 char pci_buf[VIA_PCI_BUF_SIZE];
34289 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
34290 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
34291 index ac98964..5dbf512 100644
34292 --- a/drivers/gpu/drm/via/via_irq.c
34293 +++ b/drivers/gpu/drm/via/via_irq.c
34294 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
34295 if (crtc != 0)
34296 return 0;
34297
34298 - return atomic_read(&dev_priv->vbl_received);
34299 + return atomic_read_unchecked(&dev_priv->vbl_received);
34300 }
34301
34302 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34303 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34304
34305 status = VIA_READ(VIA_REG_INTERRUPT);
34306 if (status & VIA_IRQ_VBLANK_PENDING) {
34307 - atomic_inc(&dev_priv->vbl_received);
34308 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
34309 + atomic_inc_unchecked(&dev_priv->vbl_received);
34310 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
34311 do_gettimeofday(&cur_vblank);
34312 if (dev_priv->last_vblank_valid) {
34313 dev_priv->usec_per_vblank =
34314 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34315 dev_priv->last_vblank = cur_vblank;
34316 dev_priv->last_vblank_valid = 1;
34317 }
34318 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
34319 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
34320 DRM_DEBUG("US per vblank is: %u\n",
34321 dev_priv->usec_per_vblank);
34322 }
34323 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
34324
34325 for (i = 0; i < dev_priv->num_irqs; ++i) {
34326 if (status & cur_irq->pending_mask) {
34327 - atomic_inc(&cur_irq->irq_received);
34328 + atomic_inc_unchecked(&cur_irq->irq_received);
34329 DRM_WAKEUP(&cur_irq->irq_queue);
34330 handled = 1;
34331 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
34332 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
34333 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34334 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
34335 masks[irq][4]));
34336 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
34337 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
34338 } else {
34339 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
34340 (((cur_irq_sequence =
34341 - atomic_read(&cur_irq->irq_received)) -
34342 + atomic_read_unchecked(&cur_irq->irq_received)) -
34343 *sequence) <= (1 << 23)));
34344 }
34345 *sequence = cur_irq_sequence;
34346 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
34347 }
34348
34349 for (i = 0; i < dev_priv->num_irqs; ++i) {
34350 - atomic_set(&cur_irq->irq_received, 0);
34351 + atomic_set_unchecked(&cur_irq->irq_received, 0);
34352 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
34353 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
34354 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
34355 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
34356 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
34357 case VIA_IRQ_RELATIVE:
34358 irqwait->request.sequence +=
34359 - atomic_read(&cur_irq->irq_received);
34360 + atomic_read_unchecked(&cur_irq->irq_received);
34361 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
34362 case VIA_IRQ_ABSOLUTE:
34363 break;
34364 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34365 index 13aeda7..4a952d1 100644
34366 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34367 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
34368 @@ -290,7 +290,7 @@ struct vmw_private {
34369 * Fencing and IRQs.
34370 */
34371
34372 - atomic_t marker_seq;
34373 + atomic_unchecked_t marker_seq;
34374 wait_queue_head_t fence_queue;
34375 wait_queue_head_t fifo_queue;
34376 int fence_queue_waiters; /* Protected by hw_mutex */
34377 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34378 index 3eb1486..0a47ee9 100644
34379 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34380 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
34381 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
34382 (unsigned int) min,
34383 (unsigned int) fifo->capabilities);
34384
34385 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34386 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
34387 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
34388 vmw_marker_queue_init(&fifo->marker_queue);
34389 return vmw_fifo_send_fence(dev_priv, &dummy);
34390 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
34391 if (reserveable)
34392 iowrite32(bytes, fifo_mem +
34393 SVGA_FIFO_RESERVED);
34394 - return fifo_mem + (next_cmd >> 2);
34395 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
34396 } else {
34397 need_bounce = true;
34398 }
34399 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34400
34401 fm = vmw_fifo_reserve(dev_priv, bytes);
34402 if (unlikely(fm == NULL)) {
34403 - *seqno = atomic_read(&dev_priv->marker_seq);
34404 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34405 ret = -ENOMEM;
34406 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
34407 false, 3*HZ);
34408 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
34409 }
34410
34411 do {
34412 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
34413 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
34414 } while (*seqno == 0);
34415
34416 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
34417 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34418 index 4640adb..e1384ed 100644
34419 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34420 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
34421 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
34422 * emitted. Then the fence is stale and signaled.
34423 */
34424
34425 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
34426 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
34427 > VMW_FENCE_WRAP);
34428
34429 return ret;
34430 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
34431
34432 if (fifo_idle)
34433 down_read(&fifo_state->rwsem);
34434 - signal_seq = atomic_read(&dev_priv->marker_seq);
34435 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
34436 ret = 0;
34437
34438 for (;;) {
34439 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34440 index 8a8725c..afed796 100644
34441 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34442 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
34443 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
34444 while (!vmw_lag_lt(queue, us)) {
34445 spin_lock(&queue->lock);
34446 if (list_empty(&queue->head))
34447 - seqno = atomic_read(&dev_priv->marker_seq);
34448 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
34449 else {
34450 marker = list_first_entry(&queue->head,
34451 struct vmw_marker, head);
34452 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
34453 index eb2ee11..6cc50ab 100644
34454 --- a/drivers/hid/hid-core.c
34455 +++ b/drivers/hid/hid-core.c
34456 @@ -2240,7 +2240,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
34457
34458 int hid_add_device(struct hid_device *hdev)
34459 {
34460 - static atomic_t id = ATOMIC_INIT(0);
34461 + static atomic_unchecked_t id = ATOMIC_INIT(0);
34462 int ret;
34463
34464 if (WARN_ON(hdev->status & HID_STAT_ADDED))
34465 @@ -2274,7 +2274,7 @@ int hid_add_device(struct hid_device *hdev)
34466 /* XXX hack, any other cleaner solution after the driver core
34467 * is converted to allow more than 20 bytes as the device name? */
34468 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
34469 - hdev->vendor, hdev->product, atomic_inc_return(&id));
34470 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
34471
34472 hid_debug_register(hdev, dev_name(&hdev->dev));
34473 ret = device_add(&hdev->dev);
34474 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
34475 index eec3291..8ed706b 100644
34476 --- a/drivers/hid/hid-wiimote-debug.c
34477 +++ b/drivers/hid/hid-wiimote-debug.c
34478 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
34479 else if (size == 0)
34480 return -EIO;
34481
34482 - if (copy_to_user(u, buf, size))
34483 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
34484 return -EFAULT;
34485
34486 *off += size;
34487 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
34488 index 773a2f2..7ce08bc 100644
34489 --- a/drivers/hv/channel.c
34490 +++ b/drivers/hv/channel.c
34491 @@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
34492 int ret = 0;
34493 int t;
34494
34495 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
34496 - atomic_inc(&vmbus_connection.next_gpadl_handle);
34497 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
34498 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
34499
34500 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
34501 if (ret)
34502 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
34503 index 3648f8f..30ef30d 100644
34504 --- a/drivers/hv/hv.c
34505 +++ b/drivers/hv/hv.c
34506 @@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
34507 u64 output_address = (output) ? virt_to_phys(output) : 0;
34508 u32 output_address_hi = output_address >> 32;
34509 u32 output_address_lo = output_address & 0xFFFFFFFF;
34510 - void *hypercall_page = hv_context.hypercall_page;
34511 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
34512
34513 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
34514 "=a"(hv_status_lo) : "d" (control_hi),
34515 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
34516 index d8d1fad..b91caf7 100644
34517 --- a/drivers/hv/hyperv_vmbus.h
34518 +++ b/drivers/hv/hyperv_vmbus.h
34519 @@ -594,7 +594,7 @@ enum vmbus_connect_state {
34520 struct vmbus_connection {
34521 enum vmbus_connect_state conn_state;
34522
34523 - atomic_t next_gpadl_handle;
34524 + atomic_unchecked_t next_gpadl_handle;
34525
34526 /*
34527 * Represents channel interrupts. Each bit position represents a
34528 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
34529 index 8e1a9ec..4687821 100644
34530 --- a/drivers/hv/vmbus_drv.c
34531 +++ b/drivers/hv/vmbus_drv.c
34532 @@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
34533 {
34534 int ret = 0;
34535
34536 - static atomic_t device_num = ATOMIC_INIT(0);
34537 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
34538
34539 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
34540 - atomic_inc_return(&device_num));
34541 + atomic_inc_return_unchecked(&device_num));
34542
34543 child_device_obj->device.bus = &hv_bus;
34544 child_device_obj->device.parent = &hv_acpi_dev->dev;
34545 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
34546 index d64923d..72591e8 100644
34547 --- a/drivers/hwmon/coretemp.c
34548 +++ b/drivers/hwmon/coretemp.c
34549 @@ -790,7 +790,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
34550 return NOTIFY_OK;
34551 }
34552
34553 -static struct notifier_block coretemp_cpu_notifier __refdata = {
34554 +static struct notifier_block coretemp_cpu_notifier = {
34555 .notifier_call = coretemp_cpu_callback,
34556 };
34557
34558 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
34559 index 1c85d39..55ed3cf 100644
34560 --- a/drivers/hwmon/sht15.c
34561 +++ b/drivers/hwmon/sht15.c
34562 @@ -169,7 +169,7 @@ struct sht15_data {
34563 int supply_uV;
34564 bool supply_uV_valid;
34565 struct work_struct update_supply_work;
34566 - atomic_t interrupt_handled;
34567 + atomic_unchecked_t interrupt_handled;
34568 };
34569
34570 /**
34571 @@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
34572 return ret;
34573
34574 gpio_direction_input(data->pdata->gpio_data);
34575 - atomic_set(&data->interrupt_handled, 0);
34576 + atomic_set_unchecked(&data->interrupt_handled, 0);
34577
34578 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34579 if (gpio_get_value(data->pdata->gpio_data) == 0) {
34580 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
34581 /* Only relevant if the interrupt hasn't occurred. */
34582 - if (!atomic_read(&data->interrupt_handled))
34583 + if (!atomic_read_unchecked(&data->interrupt_handled))
34584 schedule_work(&data->read_work);
34585 }
34586 ret = wait_event_timeout(data->wait_queue,
34587 @@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
34588
34589 /* First disable the interrupt */
34590 disable_irq_nosync(irq);
34591 - atomic_inc(&data->interrupt_handled);
34592 + atomic_inc_unchecked(&data->interrupt_handled);
34593 /* Then schedule a reading work struct */
34594 if (data->state != SHT15_READING_NOTHING)
34595 schedule_work(&data->read_work);
34596 @@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
34597 * If not, then start the interrupt again - care here as could
34598 * have gone low in meantime so verify it hasn't!
34599 */
34600 - atomic_set(&data->interrupt_handled, 0);
34601 + atomic_set_unchecked(&data->interrupt_handled, 0);
34602 enable_irq(gpio_to_irq(data->pdata->gpio_data));
34603 /* If still not occurred or another handler was scheduled */
34604 if (gpio_get_value(data->pdata->gpio_data)
34605 - || atomic_read(&data->interrupt_handled))
34606 + || atomic_read_unchecked(&data->interrupt_handled))
34607 return;
34608 }
34609
34610 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
34611 index 76f157b..9c0db1b 100644
34612 --- a/drivers/hwmon/via-cputemp.c
34613 +++ b/drivers/hwmon/via-cputemp.c
34614 @@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
34615 return NOTIFY_OK;
34616 }
34617
34618 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
34619 +static struct notifier_block via_cputemp_cpu_notifier = {
34620 .notifier_call = via_cputemp_cpu_callback,
34621 };
34622
34623 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
34624 index 378fcb5..5e91fa8 100644
34625 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
34626 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
34627 @@ -43,7 +43,7 @@
34628 extern struct i2c_adapter amd756_smbus;
34629
34630 static struct i2c_adapter *s4882_adapter;
34631 -static struct i2c_algorithm *s4882_algo;
34632 +static i2c_algorithm_no_const *s4882_algo;
34633
34634 /* Wrapper access functions for multiplexed SMBus */
34635 static DEFINE_MUTEX(amd756_lock);
34636 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
34637 index 29015eb..af2d8e9 100644
34638 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
34639 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
34640 @@ -41,7 +41,7 @@
34641 extern struct i2c_adapter *nforce2_smbus;
34642
34643 static struct i2c_adapter *s4985_adapter;
34644 -static struct i2c_algorithm *s4985_algo;
34645 +static i2c_algorithm_no_const *s4985_algo;
34646
34647 /* Wrapper access functions for multiplexed SMBus */
34648 static DEFINE_MUTEX(nforce2_lock);
34649 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
34650 index 8126824..55a2798 100644
34651 --- a/drivers/ide/ide-cd.c
34652 +++ b/drivers/ide/ide-cd.c
34653 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
34654 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
34655 if ((unsigned long)buf & alignment
34656 || blk_rq_bytes(rq) & q->dma_pad_mask
34657 - || object_is_on_stack(buf))
34658 + || object_starts_on_stack(buf))
34659 drive->dma = 0;
34660 }
34661 }
34662 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
34663 index 394fea2..c833880 100644
34664 --- a/drivers/infiniband/core/cm.c
34665 +++ b/drivers/infiniband/core/cm.c
34666 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
34667
34668 struct cm_counter_group {
34669 struct kobject obj;
34670 - atomic_long_t counter[CM_ATTR_COUNT];
34671 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
34672 };
34673
34674 struct cm_counter_attribute {
34675 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
34676 struct ib_mad_send_buf *msg = NULL;
34677 int ret;
34678
34679 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34680 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34681 counter[CM_REQ_COUNTER]);
34682
34683 /* Quick state check to discard duplicate REQs. */
34684 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
34685 if (!cm_id_priv)
34686 return;
34687
34688 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34689 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34690 counter[CM_REP_COUNTER]);
34691 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
34692 if (ret)
34693 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
34694 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
34695 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
34696 spin_unlock_irq(&cm_id_priv->lock);
34697 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34698 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34699 counter[CM_RTU_COUNTER]);
34700 goto out;
34701 }
34702 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
34703 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
34704 dreq_msg->local_comm_id);
34705 if (!cm_id_priv) {
34706 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34707 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34708 counter[CM_DREQ_COUNTER]);
34709 cm_issue_drep(work->port, work->mad_recv_wc);
34710 return -EINVAL;
34711 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
34712 case IB_CM_MRA_REP_RCVD:
34713 break;
34714 case IB_CM_TIMEWAIT:
34715 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34716 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34717 counter[CM_DREQ_COUNTER]);
34718 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34719 goto unlock;
34720 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
34721 cm_free_msg(msg);
34722 goto deref;
34723 case IB_CM_DREQ_RCVD:
34724 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34725 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34726 counter[CM_DREQ_COUNTER]);
34727 goto unlock;
34728 default:
34729 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
34730 ib_modify_mad(cm_id_priv->av.port->mad_agent,
34731 cm_id_priv->msg, timeout)) {
34732 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
34733 - atomic_long_inc(&work->port->
34734 + atomic_long_inc_unchecked(&work->port->
34735 counter_group[CM_RECV_DUPLICATES].
34736 counter[CM_MRA_COUNTER]);
34737 goto out;
34738 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
34739 break;
34740 case IB_CM_MRA_REQ_RCVD:
34741 case IB_CM_MRA_REP_RCVD:
34742 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34743 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34744 counter[CM_MRA_COUNTER]);
34745 /* fall through */
34746 default:
34747 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
34748 case IB_CM_LAP_IDLE:
34749 break;
34750 case IB_CM_MRA_LAP_SENT:
34751 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34752 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34753 counter[CM_LAP_COUNTER]);
34754 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
34755 goto unlock;
34756 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
34757 cm_free_msg(msg);
34758 goto deref;
34759 case IB_CM_LAP_RCVD:
34760 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34761 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34762 counter[CM_LAP_COUNTER]);
34763 goto unlock;
34764 default:
34765 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
34766 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
34767 if (cur_cm_id_priv) {
34768 spin_unlock_irq(&cm.lock);
34769 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
34770 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
34771 counter[CM_SIDR_REQ_COUNTER]);
34772 goto out; /* Duplicate message. */
34773 }
34774 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
34775 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
34776 msg->retries = 1;
34777
34778 - atomic_long_add(1 + msg->retries,
34779 + atomic_long_add_unchecked(1 + msg->retries,
34780 &port->counter_group[CM_XMIT].counter[attr_index]);
34781 if (msg->retries)
34782 - atomic_long_add(msg->retries,
34783 + atomic_long_add_unchecked(msg->retries,
34784 &port->counter_group[CM_XMIT_RETRIES].
34785 counter[attr_index]);
34786
34787 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
34788 }
34789
34790 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
34791 - atomic_long_inc(&port->counter_group[CM_RECV].
34792 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
34793 counter[attr_id - CM_ATTR_ID_OFFSET]);
34794
34795 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
34796 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
34797 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
34798
34799 return sprintf(buf, "%ld\n",
34800 - atomic_long_read(&group->counter[cm_attr->index]));
34801 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
34802 }
34803
34804 static const struct sysfs_ops cm_counter_ops = {
34805 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
34806 index 176c8f9..2627b62 100644
34807 --- a/drivers/infiniband/core/fmr_pool.c
34808 +++ b/drivers/infiniband/core/fmr_pool.c
34809 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
34810
34811 struct task_struct *thread;
34812
34813 - atomic_t req_ser;
34814 - atomic_t flush_ser;
34815 + atomic_unchecked_t req_ser;
34816 + atomic_unchecked_t flush_ser;
34817
34818 wait_queue_head_t force_wait;
34819 };
34820 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34821 struct ib_fmr_pool *pool = pool_ptr;
34822
34823 do {
34824 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
34825 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
34826 ib_fmr_batch_release(pool);
34827
34828 - atomic_inc(&pool->flush_ser);
34829 + atomic_inc_unchecked(&pool->flush_ser);
34830 wake_up_interruptible(&pool->force_wait);
34831
34832 if (pool->flush_function)
34833 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
34834 }
34835
34836 set_current_state(TASK_INTERRUPTIBLE);
34837 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
34838 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
34839 !kthread_should_stop())
34840 schedule();
34841 __set_current_state(TASK_RUNNING);
34842 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
34843 pool->dirty_watermark = params->dirty_watermark;
34844 pool->dirty_len = 0;
34845 spin_lock_init(&pool->pool_lock);
34846 - atomic_set(&pool->req_ser, 0);
34847 - atomic_set(&pool->flush_ser, 0);
34848 + atomic_set_unchecked(&pool->req_ser, 0);
34849 + atomic_set_unchecked(&pool->flush_ser, 0);
34850 init_waitqueue_head(&pool->force_wait);
34851
34852 pool->thread = kthread_run(ib_fmr_cleanup_thread,
34853 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
34854 }
34855 spin_unlock_irq(&pool->pool_lock);
34856
34857 - serial = atomic_inc_return(&pool->req_ser);
34858 + serial = atomic_inc_return_unchecked(&pool->req_ser);
34859 wake_up_process(pool->thread);
34860
34861 if (wait_event_interruptible(pool->force_wait,
34862 - atomic_read(&pool->flush_ser) - serial >= 0))
34863 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
34864 return -EINTR;
34865
34866 return 0;
34867 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
34868 } else {
34869 list_add_tail(&fmr->list, &pool->dirty_list);
34870 if (++pool->dirty_len >= pool->dirty_watermark) {
34871 - atomic_inc(&pool->req_ser);
34872 + atomic_inc_unchecked(&pool->req_ser);
34873 wake_up_process(pool->thread);
34874 }
34875 }
34876 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34877 index afd8179..598063f 100644
34878 --- a/drivers/infiniband/hw/cxgb4/mem.c
34879 +++ b/drivers/infiniband/hw/cxgb4/mem.c
34880 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34881 int err;
34882 struct fw_ri_tpte tpt;
34883 u32 stag_idx;
34884 - static atomic_t key;
34885 + static atomic_unchecked_t key;
34886
34887 if (c4iw_fatal_error(rdev))
34888 return -EIO;
34889 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34890 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34891 rdev->stats.stag.max = rdev->stats.stag.cur;
34892 mutex_unlock(&rdev->stats.lock);
34893 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34894 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34895 }
34896 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34897 __func__, stag_state, type, pdid, stag_idx);
34898 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34899 index 79b3dbc..96e5fcc 100644
34900 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
34901 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34902 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34903 struct ib_atomic_eth *ateth;
34904 struct ipath_ack_entry *e;
34905 u64 vaddr;
34906 - atomic64_t *maddr;
34907 + atomic64_unchecked_t *maddr;
34908 u64 sdata;
34909 u32 rkey;
34910 u8 next;
34911 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34912 IB_ACCESS_REMOTE_ATOMIC)))
34913 goto nack_acc_unlck;
34914 /* Perform atomic OP and save result. */
34915 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34916 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34917 sdata = be64_to_cpu(ateth->swap_data);
34918 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34919 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34920 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34921 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34922 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34923 be64_to_cpu(ateth->compare_data),
34924 sdata);
34925 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34926 index 1f95bba..9530f87 100644
34927 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34928 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34929 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34930 unsigned long flags;
34931 struct ib_wc wc;
34932 u64 sdata;
34933 - atomic64_t *maddr;
34934 + atomic64_unchecked_t *maddr;
34935 enum ib_wc_status send_status;
34936
34937 /*
34938 @@ -382,11 +382,11 @@ again:
34939 IB_ACCESS_REMOTE_ATOMIC)))
34940 goto acc_err;
34941 /* Perform atomic OP and save result. */
34942 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34943 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34944 sdata = wqe->wr.wr.atomic.compare_add;
34945 *(u64 *) sqp->s_sge.sge.vaddr =
34946 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34947 - (u64) atomic64_add_return(sdata, maddr) - sdata :
34948 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34949 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34950 sdata, wqe->wr.wr.atomic.swap);
34951 goto send_comp;
34952 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34953 index 5b152a3..c1f3e83 100644
34954 --- a/drivers/infiniband/hw/nes/nes.c
34955 +++ b/drivers/infiniband/hw/nes/nes.c
34956 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34957 LIST_HEAD(nes_adapter_list);
34958 static LIST_HEAD(nes_dev_list);
34959
34960 -atomic_t qps_destroyed;
34961 +atomic_unchecked_t qps_destroyed;
34962
34963 static unsigned int ee_flsh_adapter;
34964 static unsigned int sysfs_nonidx_addr;
34965 @@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34966 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34967 struct nes_adapter *nesadapter = nesdev->nesadapter;
34968
34969 - atomic_inc(&qps_destroyed);
34970 + atomic_inc_unchecked(&qps_destroyed);
34971
34972 /* Free the control structures */
34973
34974 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34975 index 33cc589..3bd6538 100644
34976 --- a/drivers/infiniband/hw/nes/nes.h
34977 +++ b/drivers/infiniband/hw/nes/nes.h
34978 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34979 extern unsigned int wqm_quanta;
34980 extern struct list_head nes_adapter_list;
34981
34982 -extern atomic_t cm_connects;
34983 -extern atomic_t cm_accepts;
34984 -extern atomic_t cm_disconnects;
34985 -extern atomic_t cm_closes;
34986 -extern atomic_t cm_connecteds;
34987 -extern atomic_t cm_connect_reqs;
34988 -extern atomic_t cm_rejects;
34989 -extern atomic_t mod_qp_timouts;
34990 -extern atomic_t qps_created;
34991 -extern atomic_t qps_destroyed;
34992 -extern atomic_t sw_qps_destroyed;
34993 +extern atomic_unchecked_t cm_connects;
34994 +extern atomic_unchecked_t cm_accepts;
34995 +extern atomic_unchecked_t cm_disconnects;
34996 +extern atomic_unchecked_t cm_closes;
34997 +extern atomic_unchecked_t cm_connecteds;
34998 +extern atomic_unchecked_t cm_connect_reqs;
34999 +extern atomic_unchecked_t cm_rejects;
35000 +extern atomic_unchecked_t mod_qp_timouts;
35001 +extern atomic_unchecked_t qps_created;
35002 +extern atomic_unchecked_t qps_destroyed;
35003 +extern atomic_unchecked_t sw_qps_destroyed;
35004 extern u32 mh_detected;
35005 extern u32 mh_pauses_sent;
35006 extern u32 cm_packets_sent;
35007 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
35008 extern u32 cm_packets_received;
35009 extern u32 cm_packets_dropped;
35010 extern u32 cm_packets_retrans;
35011 -extern atomic_t cm_listens_created;
35012 -extern atomic_t cm_listens_destroyed;
35013 +extern atomic_unchecked_t cm_listens_created;
35014 +extern atomic_unchecked_t cm_listens_destroyed;
35015 extern u32 cm_backlog_drops;
35016 -extern atomic_t cm_loopbacks;
35017 -extern atomic_t cm_nodes_created;
35018 -extern atomic_t cm_nodes_destroyed;
35019 -extern atomic_t cm_accel_dropped_pkts;
35020 -extern atomic_t cm_resets_recvd;
35021 -extern atomic_t pau_qps_created;
35022 -extern atomic_t pau_qps_destroyed;
35023 +extern atomic_unchecked_t cm_loopbacks;
35024 +extern atomic_unchecked_t cm_nodes_created;
35025 +extern atomic_unchecked_t cm_nodes_destroyed;
35026 +extern atomic_unchecked_t cm_accel_dropped_pkts;
35027 +extern atomic_unchecked_t cm_resets_recvd;
35028 +extern atomic_unchecked_t pau_qps_created;
35029 +extern atomic_unchecked_t pau_qps_destroyed;
35030
35031 extern u32 int_mod_timer_init;
35032 extern u32 int_mod_cq_depth_256;
35033 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
35034 index 22ea67e..dcbe3bc 100644
35035 --- a/drivers/infiniband/hw/nes/nes_cm.c
35036 +++ b/drivers/infiniband/hw/nes/nes_cm.c
35037 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
35038 u32 cm_packets_retrans;
35039 u32 cm_packets_created;
35040 u32 cm_packets_received;
35041 -atomic_t cm_listens_created;
35042 -atomic_t cm_listens_destroyed;
35043 +atomic_unchecked_t cm_listens_created;
35044 +atomic_unchecked_t cm_listens_destroyed;
35045 u32 cm_backlog_drops;
35046 -atomic_t cm_loopbacks;
35047 -atomic_t cm_nodes_created;
35048 -atomic_t cm_nodes_destroyed;
35049 -atomic_t cm_accel_dropped_pkts;
35050 -atomic_t cm_resets_recvd;
35051 +atomic_unchecked_t cm_loopbacks;
35052 +atomic_unchecked_t cm_nodes_created;
35053 +atomic_unchecked_t cm_nodes_destroyed;
35054 +atomic_unchecked_t cm_accel_dropped_pkts;
35055 +atomic_unchecked_t cm_resets_recvd;
35056
35057 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
35058 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
35059 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
35060
35061 static struct nes_cm_core *g_cm_core;
35062
35063 -atomic_t cm_connects;
35064 -atomic_t cm_accepts;
35065 -atomic_t cm_disconnects;
35066 -atomic_t cm_closes;
35067 -atomic_t cm_connecteds;
35068 -atomic_t cm_connect_reqs;
35069 -atomic_t cm_rejects;
35070 +atomic_unchecked_t cm_connects;
35071 +atomic_unchecked_t cm_accepts;
35072 +atomic_unchecked_t cm_disconnects;
35073 +atomic_unchecked_t cm_closes;
35074 +atomic_unchecked_t cm_connecteds;
35075 +atomic_unchecked_t cm_connect_reqs;
35076 +atomic_unchecked_t cm_rejects;
35077
35078 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
35079 {
35080 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
35081 kfree(listener);
35082 listener = NULL;
35083 ret = 0;
35084 - atomic_inc(&cm_listens_destroyed);
35085 + atomic_inc_unchecked(&cm_listens_destroyed);
35086 } else {
35087 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
35088 }
35089 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
35090 cm_node->rem_mac);
35091
35092 add_hte_node(cm_core, cm_node);
35093 - atomic_inc(&cm_nodes_created);
35094 + atomic_inc_unchecked(&cm_nodes_created);
35095
35096 return cm_node;
35097 }
35098 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
35099 }
35100
35101 atomic_dec(&cm_core->node_cnt);
35102 - atomic_inc(&cm_nodes_destroyed);
35103 + atomic_inc_unchecked(&cm_nodes_destroyed);
35104 nesqp = cm_node->nesqp;
35105 if (nesqp) {
35106 nesqp->cm_node = NULL;
35107 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
35108
35109 static void drop_packet(struct sk_buff *skb)
35110 {
35111 - atomic_inc(&cm_accel_dropped_pkts);
35112 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
35113 dev_kfree_skb_any(skb);
35114 }
35115
35116 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
35117 {
35118
35119 int reset = 0; /* whether to send reset in case of err.. */
35120 - atomic_inc(&cm_resets_recvd);
35121 + atomic_inc_unchecked(&cm_resets_recvd);
35122 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
35123 " refcnt=%d\n", cm_node, cm_node->state,
35124 atomic_read(&cm_node->ref_count));
35125 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
35126 rem_ref_cm_node(cm_node->cm_core, cm_node);
35127 return NULL;
35128 }
35129 - atomic_inc(&cm_loopbacks);
35130 + atomic_inc_unchecked(&cm_loopbacks);
35131 loopbackremotenode->loopbackpartner = cm_node;
35132 loopbackremotenode->tcp_cntxt.rcv_wscale =
35133 NES_CM_DEFAULT_RCV_WND_SCALE;
35134 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
35135 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
35136 else {
35137 rem_ref_cm_node(cm_core, cm_node);
35138 - atomic_inc(&cm_accel_dropped_pkts);
35139 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
35140 dev_kfree_skb_any(skb);
35141 }
35142 break;
35143 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35144
35145 if ((cm_id) && (cm_id->event_handler)) {
35146 if (issue_disconn) {
35147 - atomic_inc(&cm_disconnects);
35148 + atomic_inc_unchecked(&cm_disconnects);
35149 cm_event.event = IW_CM_EVENT_DISCONNECT;
35150 cm_event.status = disconn_status;
35151 cm_event.local_addr = cm_id->local_addr;
35152 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
35153 }
35154
35155 if (issue_close) {
35156 - atomic_inc(&cm_closes);
35157 + atomic_inc_unchecked(&cm_closes);
35158 nes_disconnect(nesqp, 1);
35159
35160 cm_id->provider_data = nesqp;
35161 @@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35162
35163 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
35164 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
35165 - atomic_inc(&cm_accepts);
35166 + atomic_inc_unchecked(&cm_accepts);
35167
35168 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
35169 netdev_refcnt_read(nesvnic->netdev));
35170 @@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
35171 struct nes_cm_core *cm_core;
35172 u8 *start_buff;
35173
35174 - atomic_inc(&cm_rejects);
35175 + atomic_inc_unchecked(&cm_rejects);
35176 cm_node = (struct nes_cm_node *)cm_id->provider_data;
35177 loopback = cm_node->loopbackpartner;
35178 cm_core = cm_node->cm_core;
35179 @@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
35180 ntohl(cm_id->local_addr.sin_addr.s_addr),
35181 ntohs(cm_id->local_addr.sin_port));
35182
35183 - atomic_inc(&cm_connects);
35184 + atomic_inc_unchecked(&cm_connects);
35185 nesqp->active_conn = 1;
35186
35187 /* cache the cm_id in the qp */
35188 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
35189 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
35190 return err;
35191 }
35192 - atomic_inc(&cm_listens_created);
35193 + atomic_inc_unchecked(&cm_listens_created);
35194 }
35195
35196 cm_id->add_ref(cm_id);
35197 @@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
35198
35199 if (nesqp->destroyed)
35200 return;
35201 - atomic_inc(&cm_connecteds);
35202 + atomic_inc_unchecked(&cm_connecteds);
35203 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
35204 " local port 0x%04X. jiffies = %lu.\n",
35205 nesqp->hwqp.qp_id,
35206 @@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
35207
35208 cm_id->add_ref(cm_id);
35209 ret = cm_id->event_handler(cm_id, &cm_event);
35210 - atomic_inc(&cm_closes);
35211 + atomic_inc_unchecked(&cm_closes);
35212 cm_event.event = IW_CM_EVENT_CLOSE;
35213 cm_event.status = 0;
35214 cm_event.provider_data = cm_id->provider_data;
35215 @@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
35216 return;
35217 cm_id = cm_node->cm_id;
35218
35219 - atomic_inc(&cm_connect_reqs);
35220 + atomic_inc_unchecked(&cm_connect_reqs);
35221 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35222 cm_node, cm_id, jiffies);
35223
35224 @@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
35225 return;
35226 cm_id = cm_node->cm_id;
35227
35228 - atomic_inc(&cm_connect_reqs);
35229 + atomic_inc_unchecked(&cm_connect_reqs);
35230 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
35231 cm_node, cm_id, jiffies);
35232
35233 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
35234 index 4166452..fc952c3 100644
35235 --- a/drivers/infiniband/hw/nes/nes_mgt.c
35236 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
35237 @@ -40,8 +40,8 @@
35238 #include "nes.h"
35239 #include "nes_mgt.h"
35240
35241 -atomic_t pau_qps_created;
35242 -atomic_t pau_qps_destroyed;
35243 +atomic_unchecked_t pau_qps_created;
35244 +atomic_unchecked_t pau_qps_destroyed;
35245
35246 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
35247 {
35248 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
35249 {
35250 struct sk_buff *skb;
35251 unsigned long flags;
35252 - atomic_inc(&pau_qps_destroyed);
35253 + atomic_inc_unchecked(&pau_qps_destroyed);
35254
35255 /* Free packets that have not yet been forwarded */
35256 /* Lock is acquired by skb_dequeue when removing the skb */
35257 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
35258 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
35259 skb_queue_head_init(&nesqp->pau_list);
35260 spin_lock_init(&nesqp->pau_lock);
35261 - atomic_inc(&pau_qps_created);
35262 + atomic_inc_unchecked(&pau_qps_created);
35263 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
35264 }
35265
35266 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
35267 index 9542e16..a008c40 100644
35268 --- a/drivers/infiniband/hw/nes/nes_nic.c
35269 +++ b/drivers/infiniband/hw/nes/nes_nic.c
35270 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
35271 target_stat_values[++index] = mh_detected;
35272 target_stat_values[++index] = mh_pauses_sent;
35273 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
35274 - target_stat_values[++index] = atomic_read(&cm_connects);
35275 - target_stat_values[++index] = atomic_read(&cm_accepts);
35276 - target_stat_values[++index] = atomic_read(&cm_disconnects);
35277 - target_stat_values[++index] = atomic_read(&cm_connecteds);
35278 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
35279 - target_stat_values[++index] = atomic_read(&cm_rejects);
35280 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
35281 - target_stat_values[++index] = atomic_read(&qps_created);
35282 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
35283 - target_stat_values[++index] = atomic_read(&qps_destroyed);
35284 - target_stat_values[++index] = atomic_read(&cm_closes);
35285 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
35286 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
35287 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
35288 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
35289 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
35290 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
35291 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
35292 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
35293 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
35294 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
35295 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
35296 target_stat_values[++index] = cm_packets_sent;
35297 target_stat_values[++index] = cm_packets_bounced;
35298 target_stat_values[++index] = cm_packets_created;
35299 target_stat_values[++index] = cm_packets_received;
35300 target_stat_values[++index] = cm_packets_dropped;
35301 target_stat_values[++index] = cm_packets_retrans;
35302 - target_stat_values[++index] = atomic_read(&cm_listens_created);
35303 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
35304 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
35305 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
35306 target_stat_values[++index] = cm_backlog_drops;
35307 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
35308 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
35309 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
35310 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
35311 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
35312 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
35313 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
35314 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
35315 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
35316 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
35317 target_stat_values[++index] = nesadapter->free_4kpbl;
35318 target_stat_values[++index] = nesadapter->free_256pbl;
35319 target_stat_values[++index] = int_mod_timer_init;
35320 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
35321 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
35322 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
35323 - target_stat_values[++index] = atomic_read(&pau_qps_created);
35324 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
35325 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
35326 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
35327 }
35328
35329 /**
35330 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
35331 index 07e4fba..685f041 100644
35332 --- a/drivers/infiniband/hw/nes/nes_verbs.c
35333 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
35334 @@ -46,9 +46,9 @@
35335
35336 #include <rdma/ib_umem.h>
35337
35338 -atomic_t mod_qp_timouts;
35339 -atomic_t qps_created;
35340 -atomic_t sw_qps_destroyed;
35341 +atomic_unchecked_t mod_qp_timouts;
35342 +atomic_unchecked_t qps_created;
35343 +atomic_unchecked_t sw_qps_destroyed;
35344
35345 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
35346
35347 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
35348 if (init_attr->create_flags)
35349 return ERR_PTR(-EINVAL);
35350
35351 - atomic_inc(&qps_created);
35352 + atomic_inc_unchecked(&qps_created);
35353 switch (init_attr->qp_type) {
35354 case IB_QPT_RC:
35355 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
35356 @@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
35357 struct iw_cm_event cm_event;
35358 int ret = 0;
35359
35360 - atomic_inc(&sw_qps_destroyed);
35361 + atomic_inc_unchecked(&sw_qps_destroyed);
35362 nesqp->destroyed = 1;
35363
35364 /* Blow away the connection if it exists. */
35365 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
35366 index 4d11575..3e890e5 100644
35367 --- a/drivers/infiniband/hw/qib/qib.h
35368 +++ b/drivers/infiniband/hw/qib/qib.h
35369 @@ -51,6 +51,7 @@
35370 #include <linux/completion.h>
35371 #include <linux/kref.h>
35372 #include <linux/sched.h>
35373 +#include <linux/slab.h>
35374
35375 #include "qib_common.h"
35376 #include "qib_verbs.h"
35377 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
35378 index da739d9..da1c7f4 100644
35379 --- a/drivers/input/gameport/gameport.c
35380 +++ b/drivers/input/gameport/gameport.c
35381 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
35382 */
35383 static void gameport_init_port(struct gameport *gameport)
35384 {
35385 - static atomic_t gameport_no = ATOMIC_INIT(0);
35386 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
35387
35388 __module_get(THIS_MODULE);
35389
35390 mutex_init(&gameport->drv_mutex);
35391 device_initialize(&gameport->dev);
35392 dev_set_name(&gameport->dev, "gameport%lu",
35393 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
35394 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
35395 gameport->dev.bus = &gameport_bus;
35396 gameport->dev.release = gameport_release_port;
35397 if (gameport->parent)
35398 diff --git a/drivers/input/input.c b/drivers/input/input.c
35399 index c044699..174d71a 100644
35400 --- a/drivers/input/input.c
35401 +++ b/drivers/input/input.c
35402 @@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
35403 */
35404 int input_register_device(struct input_dev *dev)
35405 {
35406 - static atomic_t input_no = ATOMIC_INIT(0);
35407 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
35408 struct input_devres *devres = NULL;
35409 struct input_handler *handler;
35410 unsigned int packet_size;
35411 @@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
35412 dev->setkeycode = input_default_setkeycode;
35413
35414 dev_set_name(&dev->dev, "input%ld",
35415 - (unsigned long) atomic_inc_return(&input_no) - 1);
35416 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
35417
35418 error = device_add(&dev->dev);
35419 if (error)
35420 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
35421 index 04c69af..5f92d00 100644
35422 --- a/drivers/input/joystick/sidewinder.c
35423 +++ b/drivers/input/joystick/sidewinder.c
35424 @@ -30,6 +30,7 @@
35425 #include <linux/kernel.h>
35426 #include <linux/module.h>
35427 #include <linux/slab.h>
35428 +#include <linux/sched.h>
35429 #include <linux/init.h>
35430 #include <linux/input.h>
35431 #include <linux/gameport.h>
35432 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
35433 index d6cbfe9..6225402 100644
35434 --- a/drivers/input/joystick/xpad.c
35435 +++ b/drivers/input/joystick/xpad.c
35436 @@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
35437
35438 static int xpad_led_probe(struct usb_xpad *xpad)
35439 {
35440 - static atomic_t led_seq = ATOMIC_INIT(0);
35441 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
35442 long led_no;
35443 struct xpad_led *led;
35444 struct led_classdev *led_cdev;
35445 @@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
35446 if (!led)
35447 return -ENOMEM;
35448
35449 - led_no = (long)atomic_inc_return(&led_seq) - 1;
35450 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
35451
35452 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
35453 led->xpad = xpad;
35454 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
35455 index 4c842c3..590b0bf 100644
35456 --- a/drivers/input/mousedev.c
35457 +++ b/drivers/input/mousedev.c
35458 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
35459
35460 spin_unlock_irq(&client->packet_lock);
35461
35462 - if (copy_to_user(buffer, data, count))
35463 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
35464 return -EFAULT;
35465
35466 return count;
35467 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
35468 index 25fc597..558bf3b 100644
35469 --- a/drivers/input/serio/serio.c
35470 +++ b/drivers/input/serio/serio.c
35471 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
35472 */
35473 static void serio_init_port(struct serio *serio)
35474 {
35475 - static atomic_t serio_no = ATOMIC_INIT(0);
35476 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
35477
35478 __module_get(THIS_MODULE);
35479
35480 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
35481 mutex_init(&serio->drv_mutex);
35482 device_initialize(&serio->dev);
35483 dev_set_name(&serio->dev, "serio%ld",
35484 - (long)atomic_inc_return(&serio_no) - 1);
35485 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
35486 serio->dev.bus = &serio_bus;
35487 serio->dev.release = serio_release_port;
35488 serio->dev.groups = serio_device_attr_groups;
35489 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
35490 index 89562a8..218999b 100644
35491 --- a/drivers/isdn/capi/capi.c
35492 +++ b/drivers/isdn/capi/capi.c
35493 @@ -81,8 +81,8 @@ struct capiminor {
35494
35495 struct capi20_appl *ap;
35496 u32 ncci;
35497 - atomic_t datahandle;
35498 - atomic_t msgid;
35499 + atomic_unchecked_t datahandle;
35500 + atomic_unchecked_t msgid;
35501
35502 struct tty_port port;
35503 int ttyinstop;
35504 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
35505 capimsg_setu16(s, 2, mp->ap->applid);
35506 capimsg_setu8 (s, 4, CAPI_DATA_B3);
35507 capimsg_setu8 (s, 5, CAPI_RESP);
35508 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
35509 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
35510 capimsg_setu32(s, 8, mp->ncci);
35511 capimsg_setu16(s, 12, datahandle);
35512 }
35513 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
35514 mp->outbytes -= len;
35515 spin_unlock_bh(&mp->outlock);
35516
35517 - datahandle = atomic_inc_return(&mp->datahandle);
35518 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
35519 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
35520 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35521 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
35522 capimsg_setu16(skb->data, 2, mp->ap->applid);
35523 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
35524 capimsg_setu8 (skb->data, 5, CAPI_REQ);
35525 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
35526 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
35527 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
35528 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
35529 capimsg_setu16(skb->data, 16, len); /* Data length */
35530 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
35531 index 67abf3f..076b3a6 100644
35532 --- a/drivers/isdn/gigaset/interface.c
35533 +++ b/drivers/isdn/gigaset/interface.c
35534 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
35535 }
35536 tty->driver_data = cs;
35537
35538 - ++cs->port.count;
35539 + atomic_inc(&cs->port.count);
35540
35541 - if (cs->port.count == 1) {
35542 + if (atomic_read(&cs->port.count) == 1) {
35543 tty_port_tty_set(&cs->port, tty);
35544 tty->low_latency = 1;
35545 }
35546 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
35547
35548 if (!cs->connected)
35549 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
35550 - else if (!cs->port.count)
35551 + else if (!atomic_read(&cs->port.count))
35552 dev_warn(cs->dev, "%s: device not opened\n", __func__);
35553 - else if (!--cs->port.count)
35554 + else if (!atomic_dec_return(&cs->port.count))
35555 tty_port_tty_set(&cs->port, NULL);
35556
35557 mutex_unlock(&cs->mutex);
35558 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
35559 index 821f7ac..28d4030 100644
35560 --- a/drivers/isdn/hardware/avm/b1.c
35561 +++ b/drivers/isdn/hardware/avm/b1.c
35562 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
35563 }
35564 if (left) {
35565 if (t4file->user) {
35566 - if (copy_from_user(buf, dp, left))
35567 + if (left > sizeof buf || copy_from_user(buf, dp, left))
35568 return -EFAULT;
35569 } else {
35570 memcpy(buf, dp, left);
35571 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
35572 }
35573 if (left) {
35574 if (config->user) {
35575 - if (copy_from_user(buf, dp, left))
35576 + if (left > sizeof buf || copy_from_user(buf, dp, left))
35577 return -EFAULT;
35578 } else {
35579 memcpy(buf, dp, left);
35580 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
35581 index e09dc8a..15e2efb 100644
35582 --- a/drivers/isdn/i4l/isdn_tty.c
35583 +++ b/drivers/isdn/i4l/isdn_tty.c
35584 @@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
35585
35586 #ifdef ISDN_DEBUG_MODEM_OPEN
35587 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
35588 - port->count);
35589 + atomic_read(&port->count));
35590 #endif
35591 - port->count++;
35592 + atomic_inc(&port->count);
35593 port->tty = tty;
35594 /*
35595 * Start up serial port
35596 @@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35597 #endif
35598 return;
35599 }
35600 - if ((tty->count == 1) && (port->count != 1)) {
35601 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
35602 /*
35603 * Uh, oh. tty->count is 1, which means that the tty
35604 * structure will be freed. Info->count should always
35605 @@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
35606 * serial port won't be shutdown.
35607 */
35608 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
35609 - "info->count is %d\n", port->count);
35610 - port->count = 1;
35611 + "info->count is %d\n", atomic_read(&port->count));
35612 + atomic_set(&port->count, 1);
35613 }
35614 - if (--port->count < 0) {
35615 + if (atomic_dec_return(&port->count) < 0) {
35616 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
35617 - info->line, port->count);
35618 - port->count = 0;
35619 + info->line, atomic_read(&port->count));
35620 + atomic_set(&port->count, 0);
35621 }
35622 - if (port->count) {
35623 + if (atomic_read(&port->count)) {
35624 #ifdef ISDN_DEBUG_MODEM_OPEN
35625 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
35626 #endif
35627 @@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
35628 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
35629 return;
35630 isdn_tty_shutdown(info);
35631 - port->count = 0;
35632 + atomic_set(&port->count, 0);
35633 port->flags &= ~ASYNC_NORMAL_ACTIVE;
35634 port->tty = NULL;
35635 wake_up_interruptible(&port->open_wait);
35636 @@ -1975,7 +1975,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
35637 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
35638 modem_info *info = &dev->mdm.info[i];
35639
35640 - if (info->port.count == 0)
35641 + if (atomic_read(&info->port.count) == 0)
35642 continue;
35643 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
35644 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
35645 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
35646 index e74df7c..03a03ba 100644
35647 --- a/drivers/isdn/icn/icn.c
35648 +++ b/drivers/isdn/icn/icn.c
35649 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
35650 if (count > len)
35651 count = len;
35652 if (user) {
35653 - if (copy_from_user(msg, buf, count))
35654 + if (count > sizeof msg || copy_from_user(msg, buf, count))
35655 return -EFAULT;
35656 } else
35657 memcpy(msg, buf, count);
35658 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
35659 index a5ebc00..982886f 100644
35660 --- a/drivers/lguest/core.c
35661 +++ b/drivers/lguest/core.c
35662 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
35663 * it's worked so far. The end address needs +1 because __get_vm_area
35664 * allocates an extra guard page, so we need space for that.
35665 */
35666 +
35667 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
35668 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35669 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
35670 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35671 +#else
35672 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
35673 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
35674 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
35675 +#endif
35676 +
35677 if (!switcher_vma) {
35678 err = -ENOMEM;
35679 printk("lguest: could not map switcher pages high\n");
35680 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
35681 * Now the Switcher is mapped at the right address, we can't fail!
35682 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
35683 */
35684 - memcpy(switcher_vma->addr, start_switcher_text,
35685 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
35686 end_switcher_text - start_switcher_text);
35687
35688 printk(KERN_INFO "lguest: mapped switcher at %p\n",
35689 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
35690 index 4af12e1..0e89afe 100644
35691 --- a/drivers/lguest/x86/core.c
35692 +++ b/drivers/lguest/x86/core.c
35693 @@ -59,7 +59,7 @@ static struct {
35694 /* Offset from where switcher.S was compiled to where we've copied it */
35695 static unsigned long switcher_offset(void)
35696 {
35697 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
35698 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
35699 }
35700
35701 /* This cpu's struct lguest_pages. */
35702 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
35703 * These copies are pretty cheap, so we do them unconditionally: */
35704 /* Save the current Host top-level page directory.
35705 */
35706 +
35707 +#ifdef CONFIG_PAX_PER_CPU_PGD
35708 + pages->state.host_cr3 = read_cr3();
35709 +#else
35710 pages->state.host_cr3 = __pa(current->mm->pgd);
35711 +#endif
35712 +
35713 /*
35714 * Set up the Guest's page tables to see this CPU's pages (and no
35715 * other CPU's pages).
35716 @@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
35717 * compiled-in switcher code and the high-mapped copy we just made.
35718 */
35719 for (i = 0; i < IDT_ENTRIES; i++)
35720 - default_idt_entries[i] += switcher_offset();
35721 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
35722
35723 /*
35724 * Set up the Switcher's per-cpu areas.
35725 @@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
35726 * it will be undisturbed when we switch. To change %cs and jump we
35727 * need this structure to feed to Intel's "lcall" instruction.
35728 */
35729 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
35730 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
35731 lguest_entry.segment = LGUEST_CS;
35732
35733 /*
35734 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
35735 index 40634b0..4f5855e 100644
35736 --- a/drivers/lguest/x86/switcher_32.S
35737 +++ b/drivers/lguest/x86/switcher_32.S
35738 @@ -87,6 +87,7 @@
35739 #include <asm/page.h>
35740 #include <asm/segment.h>
35741 #include <asm/lguest.h>
35742 +#include <asm/processor-flags.h>
35743
35744 // We mark the start of the code to copy
35745 // It's placed in .text tho it's never run here
35746 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
35747 // Changes type when we load it: damn Intel!
35748 // For after we switch over our page tables
35749 // That entry will be read-only: we'd crash.
35750 +
35751 +#ifdef CONFIG_PAX_KERNEXEC
35752 + mov %cr0, %edx
35753 + xor $X86_CR0_WP, %edx
35754 + mov %edx, %cr0
35755 +#endif
35756 +
35757 movl $(GDT_ENTRY_TSS*8), %edx
35758 ltr %dx
35759
35760 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
35761 // Let's clear it again for our return.
35762 // The GDT descriptor of the Host
35763 // Points to the table after two "size" bytes
35764 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
35765 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
35766 // Clear "used" from type field (byte 5, bit 2)
35767 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
35768 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
35769 +
35770 +#ifdef CONFIG_PAX_KERNEXEC
35771 + mov %cr0, %eax
35772 + xor $X86_CR0_WP, %eax
35773 + mov %eax, %cr0
35774 +#endif
35775
35776 // Once our page table's switched, the Guest is live!
35777 // The Host fades as we run this final step.
35778 @@ -295,13 +309,12 @@ deliver_to_host:
35779 // I consulted gcc, and it gave
35780 // These instructions, which I gladly credit:
35781 leal (%edx,%ebx,8), %eax
35782 - movzwl (%eax),%edx
35783 - movl 4(%eax), %eax
35784 - xorw %ax, %ax
35785 - orl %eax, %edx
35786 + movl 4(%eax), %edx
35787 + movw (%eax), %dx
35788 // Now the address of the handler's in %edx
35789 // We call it now: its "iret" drops us home.
35790 - jmp *%edx
35791 + ljmp $__KERNEL_CS, $1f
35792 +1: jmp *%edx
35793
35794 // Every interrupt can come to us here
35795 // But we must truly tell each apart.
35796 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
35797 index 7155945..4bcc562 100644
35798 --- a/drivers/md/bitmap.c
35799 +++ b/drivers/md/bitmap.c
35800 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
35801 chunk_kb ? "KB" : "B");
35802 if (bitmap->storage.file) {
35803 seq_printf(seq, ", file: ");
35804 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
35805 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
35806 }
35807
35808 seq_printf(seq, "\n");
35809 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
35810 index 0666b5d..ed82cb4 100644
35811 --- a/drivers/md/dm-ioctl.c
35812 +++ b/drivers/md/dm-ioctl.c
35813 @@ -1628,7 +1628,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
35814 cmd == DM_LIST_VERSIONS_CMD)
35815 return 0;
35816
35817 - if ((cmd == DM_DEV_CREATE_CMD)) {
35818 + if (cmd == DM_DEV_CREATE_CMD) {
35819 if (!*param->name) {
35820 DMWARN("name not supplied when creating device");
35821 return -EINVAL;
35822 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
35823 index fa51918..c26253c 100644
35824 --- a/drivers/md/dm-raid1.c
35825 +++ b/drivers/md/dm-raid1.c
35826 @@ -40,7 +40,7 @@ enum dm_raid1_error {
35827
35828 struct mirror {
35829 struct mirror_set *ms;
35830 - atomic_t error_count;
35831 + atomic_unchecked_t error_count;
35832 unsigned long error_type;
35833 struct dm_dev *dev;
35834 sector_t offset;
35835 @@ -183,7 +183,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
35836 struct mirror *m;
35837
35838 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35839 - if (!atomic_read(&m->error_count))
35840 + if (!atomic_read_unchecked(&m->error_count))
35841 return m;
35842
35843 return NULL;
35844 @@ -215,7 +215,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35845 * simple way to tell if a device has encountered
35846 * errors.
35847 */
35848 - atomic_inc(&m->error_count);
35849 + atomic_inc_unchecked(&m->error_count);
35850
35851 if (test_and_set_bit(error_type, &m->error_type))
35852 return;
35853 @@ -406,7 +406,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35854 struct mirror *m = get_default_mirror(ms);
35855
35856 do {
35857 - if (likely(!atomic_read(&m->error_count)))
35858 + if (likely(!atomic_read_unchecked(&m->error_count)))
35859 return m;
35860
35861 if (m-- == ms->mirror)
35862 @@ -420,7 +420,7 @@ static int default_ok(struct mirror *m)
35863 {
35864 struct mirror *default_mirror = get_default_mirror(m->ms);
35865
35866 - return !atomic_read(&default_mirror->error_count);
35867 + return !atomic_read_unchecked(&default_mirror->error_count);
35868 }
35869
35870 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35871 @@ -557,7 +557,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35872 */
35873 if (likely(region_in_sync(ms, region, 1)))
35874 m = choose_mirror(ms, bio->bi_sector);
35875 - else if (m && atomic_read(&m->error_count))
35876 + else if (m && atomic_read_unchecked(&m->error_count))
35877 m = NULL;
35878
35879 if (likely(m))
35880 @@ -924,7 +924,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35881 }
35882
35883 ms->mirror[mirror].ms = ms;
35884 - atomic_set(&(ms->mirror[mirror].error_count), 0);
35885 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35886 ms->mirror[mirror].error_type = 0;
35887 ms->mirror[mirror].offset = offset;
35888
35889 @@ -1337,7 +1337,7 @@ static void mirror_resume(struct dm_target *ti)
35890 */
35891 static char device_status_char(struct mirror *m)
35892 {
35893 - if (!atomic_read(&(m->error_count)))
35894 + if (!atomic_read_unchecked(&(m->error_count)))
35895 return 'A';
35896
35897 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35898 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35899 index c89cde8..9d184cf 100644
35900 --- a/drivers/md/dm-stripe.c
35901 +++ b/drivers/md/dm-stripe.c
35902 @@ -20,7 +20,7 @@ struct stripe {
35903 struct dm_dev *dev;
35904 sector_t physical_start;
35905
35906 - atomic_t error_count;
35907 + atomic_unchecked_t error_count;
35908 };
35909
35910 struct stripe_c {
35911 @@ -184,7 +184,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35912 kfree(sc);
35913 return r;
35914 }
35915 - atomic_set(&(sc->stripe[i].error_count), 0);
35916 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35917 }
35918
35919 ti->private = sc;
35920 @@ -325,7 +325,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35921 DMEMIT("%d ", sc->stripes);
35922 for (i = 0; i < sc->stripes; i++) {
35923 DMEMIT("%s ", sc->stripe[i].dev->name);
35924 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35925 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35926 'D' : 'A';
35927 }
35928 buffer[i] = '\0';
35929 @@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
35930 */
35931 for (i = 0; i < sc->stripes; i++)
35932 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35933 - atomic_inc(&(sc->stripe[i].error_count));
35934 - if (atomic_read(&(sc->stripe[i].error_count)) <
35935 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
35936 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35937 DM_IO_ERROR_THRESHOLD)
35938 schedule_work(&sc->trigger_event);
35939 }
35940 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35941 index daf25d0..d74f49f 100644
35942 --- a/drivers/md/dm-table.c
35943 +++ b/drivers/md/dm-table.c
35944 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35945 if (!dev_size)
35946 return 0;
35947
35948 - if ((start >= dev_size) || (start + len > dev_size)) {
35949 + if ((start >= dev_size) || (len > dev_size - start)) {
35950 DMWARN("%s: %s too small for target: "
35951 "start=%llu, len=%llu, dev_size=%llu",
35952 dm_device_name(ti->table->md), bdevname(bdev, b),
35953 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35954 index 4d6e853..a234157 100644
35955 --- a/drivers/md/dm-thin-metadata.c
35956 +++ b/drivers/md/dm-thin-metadata.c
35957 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35958 {
35959 pmd->info.tm = pmd->tm;
35960 pmd->info.levels = 2;
35961 - pmd->info.value_type.context = pmd->data_sm;
35962 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35963 pmd->info.value_type.size = sizeof(__le64);
35964 pmd->info.value_type.inc = data_block_inc;
35965 pmd->info.value_type.dec = data_block_dec;
35966 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35967
35968 pmd->bl_info.tm = pmd->tm;
35969 pmd->bl_info.levels = 1;
35970 - pmd->bl_info.value_type.context = pmd->data_sm;
35971 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35972 pmd->bl_info.value_type.size = sizeof(__le64);
35973 pmd->bl_info.value_type.inc = data_block_inc;
35974 pmd->bl_info.value_type.dec = data_block_dec;
35975 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35976 index 314a0e2..1376406 100644
35977 --- a/drivers/md/dm.c
35978 +++ b/drivers/md/dm.c
35979 @@ -170,9 +170,9 @@ struct mapped_device {
35980 /*
35981 * Event handling.
35982 */
35983 - atomic_t event_nr;
35984 + atomic_unchecked_t event_nr;
35985 wait_queue_head_t eventq;
35986 - atomic_t uevent_seq;
35987 + atomic_unchecked_t uevent_seq;
35988 struct list_head uevent_list;
35989 spinlock_t uevent_lock; /* Protect access to uevent_list */
35990
35991 @@ -1872,8 +1872,8 @@ static struct mapped_device *alloc_dev(int minor)
35992 rwlock_init(&md->map_lock);
35993 atomic_set(&md->holders, 1);
35994 atomic_set(&md->open_count, 0);
35995 - atomic_set(&md->event_nr, 0);
35996 - atomic_set(&md->uevent_seq, 0);
35997 + atomic_set_unchecked(&md->event_nr, 0);
35998 + atomic_set_unchecked(&md->uevent_seq, 0);
35999 INIT_LIST_HEAD(&md->uevent_list);
36000 spin_lock_init(&md->uevent_lock);
36001
36002 @@ -2014,7 +2014,7 @@ static void event_callback(void *context)
36003
36004 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
36005
36006 - atomic_inc(&md->event_nr);
36007 + atomic_inc_unchecked(&md->event_nr);
36008 wake_up(&md->eventq);
36009 }
36010
36011 @@ -2669,18 +2669,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
36012
36013 uint32_t dm_next_uevent_seq(struct mapped_device *md)
36014 {
36015 - return atomic_add_return(1, &md->uevent_seq);
36016 + return atomic_add_return_unchecked(1, &md->uevent_seq);
36017 }
36018
36019 uint32_t dm_get_event_nr(struct mapped_device *md)
36020 {
36021 - return atomic_read(&md->event_nr);
36022 + return atomic_read_unchecked(&md->event_nr);
36023 }
36024
36025 int dm_wait_event(struct mapped_device *md, int event_nr)
36026 {
36027 return wait_event_interruptible(md->eventq,
36028 - (event_nr != atomic_read(&md->event_nr)));
36029 + (event_nr != atomic_read_unchecked(&md->event_nr)));
36030 }
36031
36032 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
36033 diff --git a/drivers/md/md.c b/drivers/md/md.c
36034 index 3db3d1b..9487468 100644
36035 --- a/drivers/md/md.c
36036 +++ b/drivers/md/md.c
36037 @@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
36038 * start build, activate spare
36039 */
36040 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
36041 -static atomic_t md_event_count;
36042 +static atomic_unchecked_t md_event_count;
36043 void md_new_event(struct mddev *mddev)
36044 {
36045 - atomic_inc(&md_event_count);
36046 + atomic_inc_unchecked(&md_event_count);
36047 wake_up(&md_event_waiters);
36048 }
36049 EXPORT_SYMBOL_GPL(md_new_event);
36050 @@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
36051 */
36052 static void md_new_event_inintr(struct mddev *mddev)
36053 {
36054 - atomic_inc(&md_event_count);
36055 + atomic_inc_unchecked(&md_event_count);
36056 wake_up(&md_event_waiters);
36057 }
36058
36059 @@ -1503,7 +1503,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
36060 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
36061 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
36062 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
36063 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36064 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
36065
36066 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
36067 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
36068 @@ -1747,7 +1747,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
36069 else
36070 sb->resync_offset = cpu_to_le64(0);
36071
36072 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
36073 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
36074
36075 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
36076 sb->size = cpu_to_le64(mddev->dev_sectors);
36077 @@ -2747,7 +2747,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
36078 static ssize_t
36079 errors_show(struct md_rdev *rdev, char *page)
36080 {
36081 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
36082 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
36083 }
36084
36085 static ssize_t
36086 @@ -2756,7 +2756,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
36087 char *e;
36088 unsigned long n = simple_strtoul(buf, &e, 10);
36089 if (*buf && (*e == 0 || *e == '\n')) {
36090 - atomic_set(&rdev->corrected_errors, n);
36091 + atomic_set_unchecked(&rdev->corrected_errors, n);
36092 return len;
36093 }
36094 return -EINVAL;
36095 @@ -3203,8 +3203,8 @@ int md_rdev_init(struct md_rdev *rdev)
36096 rdev->sb_loaded = 0;
36097 rdev->bb_page = NULL;
36098 atomic_set(&rdev->nr_pending, 0);
36099 - atomic_set(&rdev->read_errors, 0);
36100 - atomic_set(&rdev->corrected_errors, 0);
36101 + atomic_set_unchecked(&rdev->read_errors, 0);
36102 + atomic_set_unchecked(&rdev->corrected_errors, 0);
36103
36104 INIT_LIST_HEAD(&rdev->same_set);
36105 init_waitqueue_head(&rdev->blocked_wait);
36106 @@ -6980,7 +6980,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
36107
36108 spin_unlock(&pers_lock);
36109 seq_printf(seq, "\n");
36110 - seq->poll_event = atomic_read(&md_event_count);
36111 + seq->poll_event = atomic_read_unchecked(&md_event_count);
36112 return 0;
36113 }
36114 if (v == (void*)2) {
36115 @@ -7083,7 +7083,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
36116 return error;
36117
36118 seq = file->private_data;
36119 - seq->poll_event = atomic_read(&md_event_count);
36120 + seq->poll_event = atomic_read_unchecked(&md_event_count);
36121 return error;
36122 }
36123
36124 @@ -7097,7 +7097,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
36125 /* always allow read */
36126 mask = POLLIN | POLLRDNORM;
36127
36128 - if (seq->poll_event != atomic_read(&md_event_count))
36129 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
36130 mask |= POLLERR | POLLPRI;
36131 return mask;
36132 }
36133 @@ -7141,7 +7141,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
36134 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
36135 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
36136 (int)part_stat_read(&disk->part0, sectors[1]) -
36137 - atomic_read(&disk->sync_io);
36138 + atomic_read_unchecked(&disk->sync_io);
36139 /* sync IO will cause sync_io to increase before the disk_stats
36140 * as sync_io is counted when a request starts, and
36141 * disk_stats is counted when it completes.
36142 diff --git a/drivers/md/md.h b/drivers/md/md.h
36143 index eca59c3..7c42285 100644
36144 --- a/drivers/md/md.h
36145 +++ b/drivers/md/md.h
36146 @@ -94,13 +94,13 @@ struct md_rdev {
36147 * only maintained for arrays that
36148 * support hot removal
36149 */
36150 - atomic_t read_errors; /* number of consecutive read errors that
36151 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
36152 * we have tried to ignore.
36153 */
36154 struct timespec last_read_error; /* monotonic time since our
36155 * last read error
36156 */
36157 - atomic_t corrected_errors; /* number of corrected read errors,
36158 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
36159 * for reporting to userspace and storing
36160 * in superblock.
36161 */
36162 @@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
36163
36164 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
36165 {
36166 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36167 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
36168 }
36169
36170 struct md_personality
36171 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
36172 index 1cbfc6b..56e1dbb 100644
36173 --- a/drivers/md/persistent-data/dm-space-map.h
36174 +++ b/drivers/md/persistent-data/dm-space-map.h
36175 @@ -60,6 +60,7 @@ struct dm_space_map {
36176 int (*root_size)(struct dm_space_map *sm, size_t *result);
36177 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
36178 };
36179 +typedef struct dm_space_map __no_const dm_space_map_no_const;
36180
36181 /*----------------------------------------------------------------*/
36182
36183 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
36184 index d5bddfc..b079b4b 100644
36185 --- a/drivers/md/raid1.c
36186 +++ b/drivers/md/raid1.c
36187 @@ -1818,7 +1818,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
36188 if (r1_sync_page_io(rdev, sect, s,
36189 bio->bi_io_vec[idx].bv_page,
36190 READ) != 0)
36191 - atomic_add(s, &rdev->corrected_errors);
36192 + atomic_add_unchecked(s, &rdev->corrected_errors);
36193 }
36194 sectors -= s;
36195 sect += s;
36196 @@ -2040,7 +2040,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
36197 test_bit(In_sync, &rdev->flags)) {
36198 if (r1_sync_page_io(rdev, sect, s,
36199 conf->tmppage, READ)) {
36200 - atomic_add(s, &rdev->corrected_errors);
36201 + atomic_add_unchecked(s, &rdev->corrected_errors);
36202 printk(KERN_INFO
36203 "md/raid1:%s: read error corrected "
36204 "(%d sectors at %llu on %s)\n",
36205 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
36206 index 64d4824..8b9ea57 100644
36207 --- a/drivers/md/raid10.c
36208 +++ b/drivers/md/raid10.c
36209 @@ -1877,7 +1877,7 @@ static void end_sync_read(struct bio *bio, int error)
36210 /* The write handler will notice the lack of
36211 * R10BIO_Uptodate and record any errors etc
36212 */
36213 - atomic_add(r10_bio->sectors,
36214 + atomic_add_unchecked(r10_bio->sectors,
36215 &conf->mirrors[d].rdev->corrected_errors);
36216
36217 /* for reconstruct, we always reschedule after a read.
36218 @@ -2226,7 +2226,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36219 {
36220 struct timespec cur_time_mon;
36221 unsigned long hours_since_last;
36222 - unsigned int read_errors = atomic_read(&rdev->read_errors);
36223 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
36224
36225 ktime_get_ts(&cur_time_mon);
36226
36227 @@ -2248,9 +2248,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
36228 * overflowing the shift of read_errors by hours_since_last.
36229 */
36230 if (hours_since_last >= 8 * sizeof(read_errors))
36231 - atomic_set(&rdev->read_errors, 0);
36232 + atomic_set_unchecked(&rdev->read_errors, 0);
36233 else
36234 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
36235 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
36236 }
36237
36238 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
36239 @@ -2304,8 +2304,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36240 return;
36241
36242 check_decay_read_errors(mddev, rdev);
36243 - atomic_inc(&rdev->read_errors);
36244 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
36245 + atomic_inc_unchecked(&rdev->read_errors);
36246 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
36247 char b[BDEVNAME_SIZE];
36248 bdevname(rdev->bdev, b);
36249
36250 @@ -2313,7 +2313,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36251 "md/raid10:%s: %s: Raid device exceeded "
36252 "read_error threshold [cur %d:max %d]\n",
36253 mdname(mddev), b,
36254 - atomic_read(&rdev->read_errors), max_read_errors);
36255 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
36256 printk(KERN_NOTICE
36257 "md/raid10:%s: %s: Failing raid device\n",
36258 mdname(mddev), b);
36259 @@ -2468,7 +2468,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
36260 sect +
36261 choose_data_offset(r10_bio, rdev)),
36262 bdevname(rdev->bdev, b));
36263 - atomic_add(s, &rdev->corrected_errors);
36264 + atomic_add_unchecked(s, &rdev->corrected_errors);
36265 }
36266
36267 rdev_dec_pending(rdev, mddev);
36268 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
36269 index 19d77a0..56051b92 100644
36270 --- a/drivers/md/raid5.c
36271 +++ b/drivers/md/raid5.c
36272 @@ -1797,21 +1797,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
36273 mdname(conf->mddev), STRIPE_SECTORS,
36274 (unsigned long long)s,
36275 bdevname(rdev->bdev, b));
36276 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
36277 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
36278 clear_bit(R5_ReadError, &sh->dev[i].flags);
36279 clear_bit(R5_ReWrite, &sh->dev[i].flags);
36280 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
36281 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
36282
36283 - if (atomic_read(&rdev->read_errors))
36284 - atomic_set(&rdev->read_errors, 0);
36285 + if (atomic_read_unchecked(&rdev->read_errors))
36286 + atomic_set_unchecked(&rdev->read_errors, 0);
36287 } else {
36288 const char *bdn = bdevname(rdev->bdev, b);
36289 int retry = 0;
36290 int set_bad = 0;
36291
36292 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
36293 - atomic_inc(&rdev->read_errors);
36294 + atomic_inc_unchecked(&rdev->read_errors);
36295 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
36296 printk_ratelimited(
36297 KERN_WARNING
36298 @@ -1839,7 +1839,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
36299 mdname(conf->mddev),
36300 (unsigned long long)s,
36301 bdn);
36302 - } else if (atomic_read(&rdev->read_errors)
36303 + } else if (atomic_read_unchecked(&rdev->read_errors)
36304 > conf->max_nr_stripes)
36305 printk(KERN_WARNING
36306 "md/raid:%s: Too many read errors, failing device %s.\n",
36307 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
36308 index d33101a..6b13069 100644
36309 --- a/drivers/media/dvb-core/dvbdev.c
36310 +++ b/drivers/media/dvb-core/dvbdev.c
36311 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
36312 const struct dvb_device *template, void *priv, int type)
36313 {
36314 struct dvb_device *dvbdev;
36315 - struct file_operations *dvbdevfops;
36316 + file_operations_no_const *dvbdevfops;
36317 struct device *clsdev;
36318 int minor;
36319 int id;
36320 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
36321 index 404f63a..4796533 100644
36322 --- a/drivers/media/dvb-frontends/dib3000.h
36323 +++ b/drivers/media/dvb-frontends/dib3000.h
36324 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
36325 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
36326 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
36327 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
36328 -};
36329 +} __no_const;
36330
36331 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
36332 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
36333 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
36334 index 35cc526..9d90d83 100644
36335 --- a/drivers/media/platform/omap/omap_vout.c
36336 +++ b/drivers/media/platform/omap/omap_vout.c
36337 @@ -63,7 +63,6 @@ enum omap_vout_channels {
36338 OMAP_VIDEO2,
36339 };
36340
36341 -static struct videobuf_queue_ops video_vbq_ops;
36342 /* Variables configurable through module params*/
36343 static u32 video1_numbuffers = 3;
36344 static u32 video2_numbuffers = 3;
36345 @@ -1010,6 +1009,12 @@ static int omap_vout_open(struct file *file)
36346 {
36347 struct videobuf_queue *q;
36348 struct omap_vout_device *vout = NULL;
36349 + static struct videobuf_queue_ops video_vbq_ops = {
36350 + .buf_setup = omap_vout_buffer_setup,
36351 + .buf_prepare = omap_vout_buffer_prepare,
36352 + .buf_release = omap_vout_buffer_release,
36353 + .buf_queue = omap_vout_buffer_queue,
36354 + };
36355
36356 vout = video_drvdata(file);
36357 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
36358 @@ -1027,10 +1032,6 @@ static int omap_vout_open(struct file *file)
36359 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
36360
36361 q = &vout->vbq;
36362 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
36363 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
36364 - video_vbq_ops.buf_release = omap_vout_buffer_release;
36365 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
36366 spin_lock_init(&vout->vbq_lock);
36367
36368 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
36369 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
36370 index b671e20..34088b7 100644
36371 --- a/drivers/media/platform/s5p-tv/mixer.h
36372 +++ b/drivers/media/platform/s5p-tv/mixer.h
36373 @@ -155,7 +155,7 @@ struct mxr_layer {
36374 /** layer index (unique identifier) */
36375 int idx;
36376 /** callbacks for layer methods */
36377 - struct mxr_layer_ops ops;
36378 + struct mxr_layer_ops *ops;
36379 /** format array */
36380 const struct mxr_format **fmt_array;
36381 /** size of format array */
36382 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36383 index b93a21f..2535195 100644
36384 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36385 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
36386 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
36387 {
36388 struct mxr_layer *layer;
36389 int ret;
36390 - struct mxr_layer_ops ops = {
36391 + static struct mxr_layer_ops ops = {
36392 .release = mxr_graph_layer_release,
36393 .buffer_set = mxr_graph_buffer_set,
36394 .stream_set = mxr_graph_stream_set,
36395 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
36396 index 3b1670a..595c939 100644
36397 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
36398 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
36399 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
36400 layer->update_buf = next;
36401 }
36402
36403 - layer->ops.buffer_set(layer, layer->update_buf);
36404 + layer->ops->buffer_set(layer, layer->update_buf);
36405
36406 if (done && done != layer->shadow_buf)
36407 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
36408 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
36409 index 1f3b743..e839271 100644
36410 --- a/drivers/media/platform/s5p-tv/mixer_video.c
36411 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
36412 @@ -208,7 +208,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
36413 layer->geo.src.height = layer->geo.src.full_height;
36414
36415 mxr_geometry_dump(mdev, &layer->geo);
36416 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36417 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36418 mxr_geometry_dump(mdev, &layer->geo);
36419 }
36420
36421 @@ -226,7 +226,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
36422 layer->geo.dst.full_width = mbus_fmt.width;
36423 layer->geo.dst.full_height = mbus_fmt.height;
36424 layer->geo.dst.field = mbus_fmt.field;
36425 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36426 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
36427
36428 mxr_geometry_dump(mdev, &layer->geo);
36429 }
36430 @@ -332,7 +332,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
36431 /* set source size to highest accepted value */
36432 geo->src.full_width = max(geo->dst.full_width, pix->width);
36433 geo->src.full_height = max(geo->dst.full_height, pix->height);
36434 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36435 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36436 mxr_geometry_dump(mdev, &layer->geo);
36437 /* set cropping to total visible screen */
36438 geo->src.width = pix->width;
36439 @@ -340,12 +340,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
36440 geo->src.x_offset = 0;
36441 geo->src.y_offset = 0;
36442 /* assure consistency of geometry */
36443 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36444 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
36445 mxr_geometry_dump(mdev, &layer->geo);
36446 /* set full size to lowest possible value */
36447 geo->src.full_width = 0;
36448 geo->src.full_height = 0;
36449 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36450 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
36451 mxr_geometry_dump(mdev, &layer->geo);
36452
36453 /* returning results */
36454 @@ -472,7 +472,7 @@ static int mxr_s_selection(struct file *file, void *fh,
36455 target->width = s->r.width;
36456 target->height = s->r.height;
36457
36458 - layer->ops.fix_geometry(layer, stage, s->flags);
36459 + layer->ops->fix_geometry(layer, stage, s->flags);
36460
36461 /* retrieve update selection rectangle */
36462 res.left = target->x_offset;
36463 @@ -937,13 +937,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
36464 mxr_output_get(mdev);
36465
36466 mxr_layer_update_output(layer);
36467 - layer->ops.format_set(layer);
36468 + layer->ops->format_set(layer);
36469 /* enabling layer in hardware */
36470 spin_lock_irqsave(&layer->enq_slock, flags);
36471 layer->state = MXR_LAYER_STREAMING;
36472 spin_unlock_irqrestore(&layer->enq_slock, flags);
36473
36474 - layer->ops.stream_set(layer, MXR_ENABLE);
36475 + layer->ops->stream_set(layer, MXR_ENABLE);
36476 mxr_streamer_get(mdev);
36477
36478 return 0;
36479 @@ -1013,7 +1013,7 @@ static int stop_streaming(struct vb2_queue *vq)
36480 spin_unlock_irqrestore(&layer->enq_slock, flags);
36481
36482 /* disabling layer in hardware */
36483 - layer->ops.stream_set(layer, MXR_DISABLE);
36484 + layer->ops->stream_set(layer, MXR_DISABLE);
36485 /* remove one streamer */
36486 mxr_streamer_put(mdev);
36487 /* allow changes in output configuration */
36488 @@ -1052,8 +1052,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
36489
36490 void mxr_layer_release(struct mxr_layer *layer)
36491 {
36492 - if (layer->ops.release)
36493 - layer->ops.release(layer);
36494 + if (layer->ops->release)
36495 + layer->ops->release(layer);
36496 }
36497
36498 void mxr_base_layer_release(struct mxr_layer *layer)
36499 @@ -1079,7 +1079,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
36500
36501 layer->mdev = mdev;
36502 layer->idx = idx;
36503 - layer->ops = *ops;
36504 + layer->ops = ops;
36505
36506 spin_lock_init(&layer->enq_slock);
36507 INIT_LIST_HEAD(&layer->enq_list);
36508 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36509 index 3d13a63..da31bf1 100644
36510 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36511 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
36512 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
36513 {
36514 struct mxr_layer *layer;
36515 int ret;
36516 - struct mxr_layer_ops ops = {
36517 + static struct mxr_layer_ops ops = {
36518 .release = mxr_vp_layer_release,
36519 .buffer_set = mxr_vp_buffer_set,
36520 .stream_set = mxr_vp_stream_set,
36521 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
36522 index 643d80a..56bb96b 100644
36523 --- a/drivers/media/radio/radio-cadet.c
36524 +++ b/drivers/media/radio/radio-cadet.c
36525 @@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36526 unsigned char readbuf[RDS_BUFFER];
36527 int i = 0;
36528
36529 + if (count > RDS_BUFFER)
36530 + return -EFAULT;
36531 mutex_lock(&dev->lock);
36532 if (dev->rdsstat == 0)
36533 cadet_start_rds(dev);
36534 @@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
36535 while (i < count && dev->rdsin != dev->rdsout)
36536 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
36537
36538 - if (i && copy_to_user(data, readbuf, i))
36539 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
36540 i = -EFAULT;
36541 unlock:
36542 mutex_unlock(&dev->lock);
36543 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
36544 index 3940bb0..fb3952a 100644
36545 --- a/drivers/media/usb/dvb-usb/cxusb.c
36546 +++ b/drivers/media/usb/dvb-usb/cxusb.c
36547 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
36548
36549 struct dib0700_adapter_state {
36550 int (*set_param_save) (struct dvb_frontend *);
36551 -};
36552 +} __no_const;
36553
36554 static int dib7070_set_param_override(struct dvb_frontend *fe)
36555 {
36556 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
36557 index 9382895..ac8093c 100644
36558 --- a/drivers/media/usb/dvb-usb/dw2102.c
36559 +++ b/drivers/media/usb/dvb-usb/dw2102.c
36560 @@ -95,7 +95,7 @@ struct su3000_state {
36561
36562 struct s6x0_state {
36563 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
36564 -};
36565 +} __no_const;
36566
36567 /* debug */
36568 static int dvb_usb_dw2102_debug;
36569 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
36570 index fb69baa..cf7ad22 100644
36571 --- a/drivers/message/fusion/mptbase.c
36572 +++ b/drivers/message/fusion/mptbase.c
36573 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
36574 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
36575 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
36576
36577 +#ifdef CONFIG_GRKERNSEC_HIDESYM
36578 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
36579 +#else
36580 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
36581 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
36582 +#endif
36583 +
36584 /*
36585 * Rounding UP to nearest 4-kB boundary here...
36586 */
36587 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
36588 index fa43c39..daeb158 100644
36589 --- a/drivers/message/fusion/mptsas.c
36590 +++ b/drivers/message/fusion/mptsas.c
36591 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
36592 return 0;
36593 }
36594
36595 +static inline void
36596 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36597 +{
36598 + if (phy_info->port_details) {
36599 + phy_info->port_details->rphy = rphy;
36600 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36601 + ioc->name, rphy));
36602 + }
36603 +
36604 + if (rphy) {
36605 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36606 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36607 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36608 + ioc->name, rphy, rphy->dev.release));
36609 + }
36610 +}
36611 +
36612 /* no mutex */
36613 static void
36614 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
36615 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
36616 return NULL;
36617 }
36618
36619 -static inline void
36620 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
36621 -{
36622 - if (phy_info->port_details) {
36623 - phy_info->port_details->rphy = rphy;
36624 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
36625 - ioc->name, rphy));
36626 - }
36627 -
36628 - if (rphy) {
36629 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
36630 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
36631 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
36632 - ioc->name, rphy, rphy->dev.release));
36633 - }
36634 -}
36635 -
36636 static inline struct sas_port *
36637 mptsas_get_port(struct mptsas_phyinfo *phy_info)
36638 {
36639 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
36640 index 164afa7..b6b2e74 100644
36641 --- a/drivers/message/fusion/mptscsih.c
36642 +++ b/drivers/message/fusion/mptscsih.c
36643 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
36644
36645 h = shost_priv(SChost);
36646
36647 - if (h) {
36648 - if (h->info_kbuf == NULL)
36649 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36650 - return h->info_kbuf;
36651 - h->info_kbuf[0] = '\0';
36652 + if (!h)
36653 + return NULL;
36654
36655 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36656 - h->info_kbuf[size-1] = '\0';
36657 - }
36658 + if (h->info_kbuf == NULL)
36659 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
36660 + return h->info_kbuf;
36661 + h->info_kbuf[0] = '\0';
36662 +
36663 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
36664 + h->info_kbuf[size-1] = '\0';
36665
36666 return h->info_kbuf;
36667 }
36668 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
36669 index 8001aa6..b137580 100644
36670 --- a/drivers/message/i2o/i2o_proc.c
36671 +++ b/drivers/message/i2o/i2o_proc.c
36672 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
36673 "Array Controller Device"
36674 };
36675
36676 -static char *chtostr(char *tmp, u8 *chars, int n)
36677 -{
36678 - tmp[0] = 0;
36679 - return strncat(tmp, (char *)chars, n);
36680 -}
36681 -
36682 static int i2o_report_query_status(struct seq_file *seq, int block_status,
36683 char *group)
36684 {
36685 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36686 } *result;
36687
36688 i2o_exec_execute_ddm_table ddm_table;
36689 - char tmp[28 + 1];
36690
36691 result = kmalloc(sizeof(*result), GFP_KERNEL);
36692 if (!result)
36693 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
36694
36695 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
36696 seq_printf(seq, "%-#8x", ddm_table.module_id);
36697 - seq_printf(seq, "%-29s",
36698 - chtostr(tmp, ddm_table.module_name_version, 28));
36699 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
36700 seq_printf(seq, "%9d ", ddm_table.data_size);
36701 seq_printf(seq, "%8d", ddm_table.code_size);
36702
36703 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36704
36705 i2o_driver_result_table *result;
36706 i2o_driver_store_table *dst;
36707 - char tmp[28 + 1];
36708
36709 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
36710 if (result == NULL)
36711 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
36712
36713 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
36714 seq_printf(seq, "%-#8x", dst->module_id);
36715 - seq_printf(seq, "%-29s",
36716 - chtostr(tmp, dst->module_name_version, 28));
36717 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
36718 + seq_printf(seq, "%-.28s", dst->module_name_version);
36719 + seq_printf(seq, "%-.8s", dst->date);
36720 seq_printf(seq, "%8d ", dst->module_size);
36721 seq_printf(seq, "%8d ", dst->mpb_size);
36722 seq_printf(seq, "0x%04x", dst->module_flags);
36723 @@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36724 // == (allow) 512d bytes (max)
36725 static u16 *work16 = (u16 *) work32;
36726 int token;
36727 - char tmp[16 + 1];
36728
36729 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
36730
36731 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
36732 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
36733 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
36734 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
36735 - seq_printf(seq, "Vendor info : %s\n",
36736 - chtostr(tmp, (u8 *) (work32 + 2), 16));
36737 - seq_printf(seq, "Product info : %s\n",
36738 - chtostr(tmp, (u8 *) (work32 + 6), 16));
36739 - seq_printf(seq, "Description : %s\n",
36740 - chtostr(tmp, (u8 *) (work32 + 10), 16));
36741 - seq_printf(seq, "Product rev. : %s\n",
36742 - chtostr(tmp, (u8 *) (work32 + 14), 8));
36743 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
36744 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
36745 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
36746 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
36747
36748 seq_printf(seq, "Serial number : ");
36749 print_serial_number(seq, (u8 *) (work32 + 16),
36750 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36751 u8 pad[256]; // allow up to 256 byte (max) serial number
36752 } result;
36753
36754 - char tmp[24 + 1];
36755 -
36756 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
36757
36758 if (token < 0) {
36759 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
36760 }
36761
36762 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
36763 - seq_printf(seq, "Module name : %s\n",
36764 - chtostr(tmp, result.module_name, 24));
36765 - seq_printf(seq, "Module revision : %s\n",
36766 - chtostr(tmp, result.module_rev, 8));
36767 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
36768 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
36769
36770 seq_printf(seq, "Serial number : ");
36771 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
36772 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36773 u8 instance_number[4];
36774 } result;
36775
36776 - char tmp[64 + 1];
36777 -
36778 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
36779
36780 if (token < 0) {
36781 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
36782 return 0;
36783 }
36784
36785 - seq_printf(seq, "Device name : %s\n",
36786 - chtostr(tmp, result.device_name, 64));
36787 - seq_printf(seq, "Service name : %s\n",
36788 - chtostr(tmp, result.service_name, 64));
36789 - seq_printf(seq, "Physical name : %s\n",
36790 - chtostr(tmp, result.physical_location, 64));
36791 - seq_printf(seq, "Instance number : %s\n",
36792 - chtostr(tmp, result.instance_number, 4));
36793 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
36794 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
36795 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
36796 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
36797
36798 return 0;
36799 }
36800 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
36801 index a8c08f3..155fe3d 100644
36802 --- a/drivers/message/i2o/iop.c
36803 +++ b/drivers/message/i2o/iop.c
36804 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
36805
36806 spin_lock_irqsave(&c->context_list_lock, flags);
36807
36808 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
36809 - atomic_inc(&c->context_list_counter);
36810 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
36811 + atomic_inc_unchecked(&c->context_list_counter);
36812
36813 - entry->context = atomic_read(&c->context_list_counter);
36814 + entry->context = atomic_read_unchecked(&c->context_list_counter);
36815
36816 list_add(&entry->list, &c->context_list);
36817
36818 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
36819
36820 #if BITS_PER_LONG == 64
36821 spin_lock_init(&c->context_list_lock);
36822 - atomic_set(&c->context_list_counter, 0);
36823 + atomic_set_unchecked(&c->context_list_counter, 0);
36824 INIT_LIST_HEAD(&c->context_list);
36825 #endif
36826
36827 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
36828 index 45ece11..8efa218 100644
36829 --- a/drivers/mfd/janz-cmodio.c
36830 +++ b/drivers/mfd/janz-cmodio.c
36831 @@ -13,6 +13,7 @@
36832
36833 #include <linux/kernel.h>
36834 #include <linux/module.h>
36835 +#include <linux/slab.h>
36836 #include <linux/init.h>
36837 #include <linux/pci.h>
36838 #include <linux/interrupt.h>
36839 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
36840 index 3aa9a96..59cf685 100644
36841 --- a/drivers/misc/kgdbts.c
36842 +++ b/drivers/misc/kgdbts.c
36843 @@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
36844 char before[BREAK_INSTR_SIZE];
36845 char after[BREAK_INSTR_SIZE];
36846
36847 - probe_kernel_read(before, (char *)kgdbts_break_test,
36848 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
36849 BREAK_INSTR_SIZE);
36850 init_simple_test();
36851 ts.tst = plant_and_detach_test;
36852 @@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
36853 /* Activate test with initial breakpoint */
36854 if (!is_early)
36855 kgdb_breakpoint();
36856 - probe_kernel_read(after, (char *)kgdbts_break_test,
36857 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
36858 BREAK_INSTR_SIZE);
36859 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
36860 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
36861 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
36862 index 4a87e5c..76bdf5c 100644
36863 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
36864 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
36865 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
36866 * the lid is closed. This leads to interrupts as soon as a little move
36867 * is done.
36868 */
36869 - atomic_inc(&lis3->count);
36870 + atomic_inc_unchecked(&lis3->count);
36871
36872 wake_up_interruptible(&lis3->misc_wait);
36873 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
36874 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
36875 if (lis3->pm_dev)
36876 pm_runtime_get_sync(lis3->pm_dev);
36877
36878 - atomic_set(&lis3->count, 0);
36879 + atomic_set_unchecked(&lis3->count, 0);
36880 return 0;
36881 }
36882
36883 @@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
36884 add_wait_queue(&lis3->misc_wait, &wait);
36885 while (true) {
36886 set_current_state(TASK_INTERRUPTIBLE);
36887 - data = atomic_xchg(&lis3->count, 0);
36888 + data = atomic_xchg_unchecked(&lis3->count, 0);
36889 if (data)
36890 break;
36891
36892 @@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
36893 struct lis3lv02d, miscdev);
36894
36895 poll_wait(file, &lis3->misc_wait, wait);
36896 - if (atomic_read(&lis3->count))
36897 + if (atomic_read_unchecked(&lis3->count))
36898 return POLLIN | POLLRDNORM;
36899 return 0;
36900 }
36901 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
36902 index c439c82..1f20f57 100644
36903 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
36904 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
36905 @@ -297,7 +297,7 @@ struct lis3lv02d {
36906 struct input_polled_dev *idev; /* input device */
36907 struct platform_device *pdev; /* platform device */
36908 struct regulator_bulk_data regulators[2];
36909 - atomic_t count; /* interrupt count after last read */
36910 + atomic_unchecked_t count; /* interrupt count after last read */
36911 union axis_conversion ac; /* hw -> logical axis */
36912 int mapped_btns[3];
36913
36914 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
36915 index 2f30bad..c4c13d0 100644
36916 --- a/drivers/misc/sgi-gru/gruhandles.c
36917 +++ b/drivers/misc/sgi-gru/gruhandles.c
36918 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
36919 unsigned long nsec;
36920
36921 nsec = CLKS2NSEC(clks);
36922 - atomic_long_inc(&mcs_op_statistics[op].count);
36923 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
36924 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
36925 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
36926 if (mcs_op_statistics[op].max < nsec)
36927 mcs_op_statistics[op].max = nsec;
36928 }
36929 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36930 index 950dbe9..eeef0f8 100644
36931 --- a/drivers/misc/sgi-gru/gruprocfs.c
36932 +++ b/drivers/misc/sgi-gru/gruprocfs.c
36933 @@ -32,9 +32,9 @@
36934
36935 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36936
36937 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36938 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36939 {
36940 - unsigned long val = atomic_long_read(v);
36941 + unsigned long val = atomic_long_read_unchecked(v);
36942
36943 seq_printf(s, "%16lu %s\n", val, id);
36944 }
36945 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36946
36947 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36948 for (op = 0; op < mcsop_last; op++) {
36949 - count = atomic_long_read(&mcs_op_statistics[op].count);
36950 - total = atomic_long_read(&mcs_op_statistics[op].total);
36951 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36952 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36953 max = mcs_op_statistics[op].max;
36954 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36955 count ? total / count : 0, max);
36956 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36957 index 5c3ce24..4915ccb 100644
36958 --- a/drivers/misc/sgi-gru/grutables.h
36959 +++ b/drivers/misc/sgi-gru/grutables.h
36960 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36961 * GRU statistics.
36962 */
36963 struct gru_stats_s {
36964 - atomic_long_t vdata_alloc;
36965 - atomic_long_t vdata_free;
36966 - atomic_long_t gts_alloc;
36967 - atomic_long_t gts_free;
36968 - atomic_long_t gms_alloc;
36969 - atomic_long_t gms_free;
36970 - atomic_long_t gts_double_allocate;
36971 - atomic_long_t assign_context;
36972 - atomic_long_t assign_context_failed;
36973 - atomic_long_t free_context;
36974 - atomic_long_t load_user_context;
36975 - atomic_long_t load_kernel_context;
36976 - atomic_long_t lock_kernel_context;
36977 - atomic_long_t unlock_kernel_context;
36978 - atomic_long_t steal_user_context;
36979 - atomic_long_t steal_kernel_context;
36980 - atomic_long_t steal_context_failed;
36981 - atomic_long_t nopfn;
36982 - atomic_long_t asid_new;
36983 - atomic_long_t asid_next;
36984 - atomic_long_t asid_wrap;
36985 - atomic_long_t asid_reuse;
36986 - atomic_long_t intr;
36987 - atomic_long_t intr_cbr;
36988 - atomic_long_t intr_tfh;
36989 - atomic_long_t intr_spurious;
36990 - atomic_long_t intr_mm_lock_failed;
36991 - atomic_long_t call_os;
36992 - atomic_long_t call_os_wait_queue;
36993 - atomic_long_t user_flush_tlb;
36994 - atomic_long_t user_unload_context;
36995 - atomic_long_t user_exception;
36996 - atomic_long_t set_context_option;
36997 - atomic_long_t check_context_retarget_intr;
36998 - atomic_long_t check_context_unload;
36999 - atomic_long_t tlb_dropin;
37000 - atomic_long_t tlb_preload_page;
37001 - atomic_long_t tlb_dropin_fail_no_asid;
37002 - atomic_long_t tlb_dropin_fail_upm;
37003 - atomic_long_t tlb_dropin_fail_invalid;
37004 - atomic_long_t tlb_dropin_fail_range_active;
37005 - atomic_long_t tlb_dropin_fail_idle;
37006 - atomic_long_t tlb_dropin_fail_fmm;
37007 - atomic_long_t tlb_dropin_fail_no_exception;
37008 - atomic_long_t tfh_stale_on_fault;
37009 - atomic_long_t mmu_invalidate_range;
37010 - atomic_long_t mmu_invalidate_page;
37011 - atomic_long_t flush_tlb;
37012 - atomic_long_t flush_tlb_gru;
37013 - atomic_long_t flush_tlb_gru_tgh;
37014 - atomic_long_t flush_tlb_gru_zero_asid;
37015 + atomic_long_unchecked_t vdata_alloc;
37016 + atomic_long_unchecked_t vdata_free;
37017 + atomic_long_unchecked_t gts_alloc;
37018 + atomic_long_unchecked_t gts_free;
37019 + atomic_long_unchecked_t gms_alloc;
37020 + atomic_long_unchecked_t gms_free;
37021 + atomic_long_unchecked_t gts_double_allocate;
37022 + atomic_long_unchecked_t assign_context;
37023 + atomic_long_unchecked_t assign_context_failed;
37024 + atomic_long_unchecked_t free_context;
37025 + atomic_long_unchecked_t load_user_context;
37026 + atomic_long_unchecked_t load_kernel_context;
37027 + atomic_long_unchecked_t lock_kernel_context;
37028 + atomic_long_unchecked_t unlock_kernel_context;
37029 + atomic_long_unchecked_t steal_user_context;
37030 + atomic_long_unchecked_t steal_kernel_context;
37031 + atomic_long_unchecked_t steal_context_failed;
37032 + atomic_long_unchecked_t nopfn;
37033 + atomic_long_unchecked_t asid_new;
37034 + atomic_long_unchecked_t asid_next;
37035 + atomic_long_unchecked_t asid_wrap;
37036 + atomic_long_unchecked_t asid_reuse;
37037 + atomic_long_unchecked_t intr;
37038 + atomic_long_unchecked_t intr_cbr;
37039 + atomic_long_unchecked_t intr_tfh;
37040 + atomic_long_unchecked_t intr_spurious;
37041 + atomic_long_unchecked_t intr_mm_lock_failed;
37042 + atomic_long_unchecked_t call_os;
37043 + atomic_long_unchecked_t call_os_wait_queue;
37044 + atomic_long_unchecked_t user_flush_tlb;
37045 + atomic_long_unchecked_t user_unload_context;
37046 + atomic_long_unchecked_t user_exception;
37047 + atomic_long_unchecked_t set_context_option;
37048 + atomic_long_unchecked_t check_context_retarget_intr;
37049 + atomic_long_unchecked_t check_context_unload;
37050 + atomic_long_unchecked_t tlb_dropin;
37051 + atomic_long_unchecked_t tlb_preload_page;
37052 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
37053 + atomic_long_unchecked_t tlb_dropin_fail_upm;
37054 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
37055 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
37056 + atomic_long_unchecked_t tlb_dropin_fail_idle;
37057 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
37058 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
37059 + atomic_long_unchecked_t tfh_stale_on_fault;
37060 + atomic_long_unchecked_t mmu_invalidate_range;
37061 + atomic_long_unchecked_t mmu_invalidate_page;
37062 + atomic_long_unchecked_t flush_tlb;
37063 + atomic_long_unchecked_t flush_tlb_gru;
37064 + atomic_long_unchecked_t flush_tlb_gru_tgh;
37065 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
37066
37067 - atomic_long_t copy_gpa;
37068 - atomic_long_t read_gpa;
37069 + atomic_long_unchecked_t copy_gpa;
37070 + atomic_long_unchecked_t read_gpa;
37071
37072 - atomic_long_t mesq_receive;
37073 - atomic_long_t mesq_receive_none;
37074 - atomic_long_t mesq_send;
37075 - atomic_long_t mesq_send_failed;
37076 - atomic_long_t mesq_noop;
37077 - atomic_long_t mesq_send_unexpected_error;
37078 - atomic_long_t mesq_send_lb_overflow;
37079 - atomic_long_t mesq_send_qlimit_reached;
37080 - atomic_long_t mesq_send_amo_nacked;
37081 - atomic_long_t mesq_send_put_nacked;
37082 - atomic_long_t mesq_page_overflow;
37083 - atomic_long_t mesq_qf_locked;
37084 - atomic_long_t mesq_qf_noop_not_full;
37085 - atomic_long_t mesq_qf_switch_head_failed;
37086 - atomic_long_t mesq_qf_unexpected_error;
37087 - atomic_long_t mesq_noop_unexpected_error;
37088 - atomic_long_t mesq_noop_lb_overflow;
37089 - atomic_long_t mesq_noop_qlimit_reached;
37090 - atomic_long_t mesq_noop_amo_nacked;
37091 - atomic_long_t mesq_noop_put_nacked;
37092 - atomic_long_t mesq_noop_page_overflow;
37093 + atomic_long_unchecked_t mesq_receive;
37094 + atomic_long_unchecked_t mesq_receive_none;
37095 + atomic_long_unchecked_t mesq_send;
37096 + atomic_long_unchecked_t mesq_send_failed;
37097 + atomic_long_unchecked_t mesq_noop;
37098 + atomic_long_unchecked_t mesq_send_unexpected_error;
37099 + atomic_long_unchecked_t mesq_send_lb_overflow;
37100 + atomic_long_unchecked_t mesq_send_qlimit_reached;
37101 + atomic_long_unchecked_t mesq_send_amo_nacked;
37102 + atomic_long_unchecked_t mesq_send_put_nacked;
37103 + atomic_long_unchecked_t mesq_page_overflow;
37104 + atomic_long_unchecked_t mesq_qf_locked;
37105 + atomic_long_unchecked_t mesq_qf_noop_not_full;
37106 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
37107 + atomic_long_unchecked_t mesq_qf_unexpected_error;
37108 + atomic_long_unchecked_t mesq_noop_unexpected_error;
37109 + atomic_long_unchecked_t mesq_noop_lb_overflow;
37110 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
37111 + atomic_long_unchecked_t mesq_noop_amo_nacked;
37112 + atomic_long_unchecked_t mesq_noop_put_nacked;
37113 + atomic_long_unchecked_t mesq_noop_page_overflow;
37114
37115 };
37116
37117 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
37118 tghop_invalidate, mcsop_last};
37119
37120 struct mcs_op_statistic {
37121 - atomic_long_t count;
37122 - atomic_long_t total;
37123 + atomic_long_unchecked_t count;
37124 + atomic_long_unchecked_t total;
37125 unsigned long max;
37126 };
37127
37128 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
37129
37130 #define STAT(id) do { \
37131 if (gru_options & OPT_STATS) \
37132 - atomic_long_inc(&gru_stats.id); \
37133 + atomic_long_inc_unchecked(&gru_stats.id); \
37134 } while (0)
37135
37136 #ifdef CONFIG_SGI_GRU_DEBUG
37137 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
37138 index c862cd4..0d176fe 100644
37139 --- a/drivers/misc/sgi-xp/xp.h
37140 +++ b/drivers/misc/sgi-xp/xp.h
37141 @@ -288,7 +288,7 @@ struct xpc_interface {
37142 xpc_notify_func, void *);
37143 void (*received) (short, int, void *);
37144 enum xp_retval (*partid_to_nasids) (short, void *);
37145 -};
37146 +} __no_const;
37147
37148 extern struct xpc_interface xpc_interface;
37149
37150 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
37151 index b94d5f7..7f494c5 100644
37152 --- a/drivers/misc/sgi-xp/xpc.h
37153 +++ b/drivers/misc/sgi-xp/xpc.h
37154 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
37155 void (*received_payload) (struct xpc_channel *, void *);
37156 void (*notify_senders_of_disconnect) (struct xpc_channel *);
37157 };
37158 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
37159
37160 /* struct xpc_partition act_state values (for XPC HB) */
37161
37162 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
37163 /* found in xpc_main.c */
37164 extern struct device *xpc_part;
37165 extern struct device *xpc_chan;
37166 -extern struct xpc_arch_operations xpc_arch_ops;
37167 +extern xpc_arch_operations_no_const xpc_arch_ops;
37168 extern int xpc_disengage_timelimit;
37169 extern int xpc_disengage_timedout;
37170 extern int xpc_activate_IRQ_rcvd;
37171 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
37172 index d971817..33bdca5 100644
37173 --- a/drivers/misc/sgi-xp/xpc_main.c
37174 +++ b/drivers/misc/sgi-xp/xpc_main.c
37175 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
37176 .notifier_call = xpc_system_die,
37177 };
37178
37179 -struct xpc_arch_operations xpc_arch_ops;
37180 +xpc_arch_operations_no_const xpc_arch_ops;
37181
37182 /*
37183 * Timer function to enforce the timelimit on the partition disengage.
37184 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
37185
37186 if (((die_args->trapnr == X86_TRAP_MF) ||
37187 (die_args->trapnr == X86_TRAP_XF)) &&
37188 - !user_mode_vm(die_args->regs))
37189 + !user_mode(die_args->regs))
37190 xpc_die_deactivate();
37191
37192 break;
37193 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
37194 index 6d8f701..35b6369 100644
37195 --- a/drivers/mmc/core/mmc_ops.c
37196 +++ b/drivers/mmc/core/mmc_ops.c
37197 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
37198 void *data_buf;
37199 int is_on_stack;
37200
37201 - is_on_stack = object_is_on_stack(buf);
37202 + is_on_stack = object_starts_on_stack(buf);
37203 if (is_on_stack) {
37204 /*
37205 * dma onto stack is unsafe/nonportable, but callers to this
37206 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
37207 index 53b8fd9..615b462 100644
37208 --- a/drivers/mmc/host/dw_mmc.h
37209 +++ b/drivers/mmc/host/dw_mmc.h
37210 @@ -205,5 +205,5 @@ struct dw_mci_drv_data {
37211 int (*parse_dt)(struct dw_mci *host);
37212 int (*setup_bus)(struct dw_mci *host,
37213 struct device_node *slot_np, u8 bus_width);
37214 -};
37215 +} __do_const;
37216 #endif /* _DW_MMC_H_ */
37217 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
37218 index 82a8de1..3c56ccb 100644
37219 --- a/drivers/mmc/host/sdhci-s3c.c
37220 +++ b/drivers/mmc/host/sdhci-s3c.c
37221 @@ -721,9 +721,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
37222 * we can use overriding functions instead of default.
37223 */
37224 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
37225 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37226 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37227 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37228 + pax_open_kernel();
37229 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
37230 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
37231 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
37232 + pax_close_kernel();
37233 }
37234
37235 /* It supports additional host capabilities if needed */
37236 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
37237 index a4eb8b5..8c0628f 100644
37238 --- a/drivers/mtd/devices/doc2000.c
37239 +++ b/drivers/mtd/devices/doc2000.c
37240 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
37241
37242 /* The ECC will not be calculated correctly if less than 512 is written */
37243 /* DBB-
37244 - if (len != 0x200 && eccbuf)
37245 + if (len != 0x200)
37246 printk(KERN_WARNING
37247 "ECC needs a full sector write (adr: %lx size %lx)\n",
37248 (long) to, (long) len);
37249 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
37250 index 0c8bb6b..6f35deb 100644
37251 --- a/drivers/mtd/nand/denali.c
37252 +++ b/drivers/mtd/nand/denali.c
37253 @@ -24,6 +24,7 @@
37254 #include <linux/slab.h>
37255 #include <linux/mtd/mtd.h>
37256 #include <linux/module.h>
37257 +#include <linux/slab.h>
37258
37259 #include "denali.h"
37260
37261 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
37262 index 51b9d6a..52af9a7 100644
37263 --- a/drivers/mtd/nftlmount.c
37264 +++ b/drivers/mtd/nftlmount.c
37265 @@ -24,6 +24,7 @@
37266 #include <asm/errno.h>
37267 #include <linux/delay.h>
37268 #include <linux/slab.h>
37269 +#include <linux/sched.h>
37270 #include <linux/mtd/mtd.h>
37271 #include <linux/mtd/nand.h>
37272 #include <linux/mtd/nftl.h>
37273 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
37274 index 70dba5d..11a0919 100644
37275 --- a/drivers/net/ethernet/8390/ax88796.c
37276 +++ b/drivers/net/ethernet/8390/ax88796.c
37277 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
37278 if (ax->plat->reg_offsets)
37279 ei_local->reg_offset = ax->plat->reg_offsets;
37280 else {
37281 + resource_size_t _mem_size = mem_size;
37282 + do_div(_mem_size, 0x18);
37283 ei_local->reg_offset = ax->reg_offsets;
37284 for (ret = 0; ret < 0x18; ret++)
37285 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
37286 + ax->reg_offsets[ret] = _mem_size * ret;
37287 }
37288
37289 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
37290 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37291 index 0991534..8098e92 100644
37292 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37293 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
37294 @@ -1094,7 +1094,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
37295 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
37296 {
37297 /* RX_MODE controlling object */
37298 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
37299 + bnx2x_init_rx_mode_obj(bp);
37300
37301 /* multicast configuration controlling object */
37302 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
37303 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37304 index 09b625e..15b16fe 100644
37305 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37306 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
37307 @@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
37308 return rc;
37309 }
37310
37311 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37312 - struct bnx2x_rx_mode_obj *o)
37313 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
37314 {
37315 if (CHIP_IS_E1x(bp)) {
37316 - o->wait_comp = bnx2x_empty_rx_mode_wait;
37317 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
37318 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
37319 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
37320 } else {
37321 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
37322 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
37323 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
37324 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
37325 }
37326 }
37327
37328 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37329 index adbd91b..58ec94a 100644
37330 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37331 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
37332 @@ -1293,8 +1293,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
37333
37334 /********************* RX MODE ****************/
37335
37336 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
37337 - struct bnx2x_rx_mode_obj *o);
37338 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
37339
37340 /**
37341 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
37342 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
37343 index d330e81..ce1fb9a 100644
37344 --- a/drivers/net/ethernet/broadcom/tg3.h
37345 +++ b/drivers/net/ethernet/broadcom/tg3.h
37346 @@ -146,6 +146,7 @@
37347 #define CHIPREV_ID_5750_A0 0x4000
37348 #define CHIPREV_ID_5750_A1 0x4001
37349 #define CHIPREV_ID_5750_A3 0x4003
37350 +#define CHIPREV_ID_5750_C1 0x4201
37351 #define CHIPREV_ID_5750_C2 0x4202
37352 #define CHIPREV_ID_5752_A0_HW 0x5000
37353 #define CHIPREV_ID_5752_A0 0x6000
37354 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37355 index 8cffcdf..aadf043 100644
37356 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37357 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
37358 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
37359 */
37360 struct l2t_skb_cb {
37361 arp_failure_handler_func arp_failure_handler;
37362 -};
37363 +} __no_const;
37364
37365 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
37366
37367 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
37368 index 4c83003..2a2a5b9 100644
37369 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
37370 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
37371 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37372 for (i=0; i<ETH_ALEN; i++) {
37373 tmp.addr[i] = dev->dev_addr[i];
37374 }
37375 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37376 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
37377 break;
37378
37379 case DE4X5_SET_HWADDR: /* Set the hardware address */
37380 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
37381 spin_lock_irqsave(&lp->lock, flags);
37382 memcpy(&statbuf, &lp->pktStats, ioc->len);
37383 spin_unlock_irqrestore(&lp->lock, flags);
37384 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
37385 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
37386 return -EFAULT;
37387 break;
37388 }
37389 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
37390 index 4d6f3c5..6169e60 100644
37391 --- a/drivers/net/ethernet/emulex/benet/be_main.c
37392 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
37393 @@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
37394
37395 if (wrapped)
37396 newacc += 65536;
37397 - ACCESS_ONCE(*acc) = newacc;
37398 + ACCESS_ONCE_RW(*acc) = newacc;
37399 }
37400
37401 void be_parse_stats(struct be_adapter *adapter)
37402 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
37403 index 74d749e..eefb1bd 100644
37404 --- a/drivers/net/ethernet/faraday/ftgmac100.c
37405 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
37406 @@ -31,6 +31,8 @@
37407 #include <linux/netdevice.h>
37408 #include <linux/phy.h>
37409 #include <linux/platform_device.h>
37410 +#include <linux/interrupt.h>
37411 +#include <linux/irqreturn.h>
37412 #include <net/ip.h>
37413
37414 #include "ftgmac100.h"
37415 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
37416 index b901a01..1ff32ee 100644
37417 --- a/drivers/net/ethernet/faraday/ftmac100.c
37418 +++ b/drivers/net/ethernet/faraday/ftmac100.c
37419 @@ -31,6 +31,8 @@
37420 #include <linux/module.h>
37421 #include <linux/netdevice.h>
37422 #include <linux/platform_device.h>
37423 +#include <linux/interrupt.h>
37424 +#include <linux/irqreturn.h>
37425
37426 #include "ftmac100.h"
37427
37428 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37429 index bb9256a..56d8752 100644
37430 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37431 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
37432 @@ -806,7 +806,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
37433 }
37434
37435 /* update the base incval used to calculate frequency adjustment */
37436 - ACCESS_ONCE(adapter->base_incval) = incval;
37437 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
37438 smp_mb();
37439
37440 /* need lock to prevent incorrect read while modifying cyclecounter */
37441 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37442 index fbe5363..266b4e3 100644
37443 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
37444 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
37445 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37446 struct __vxge_hw_fifo *fifo;
37447 struct vxge_hw_fifo_config *config;
37448 u32 txdl_size, txdl_per_memblock;
37449 - struct vxge_hw_mempool_cbs fifo_mp_callback;
37450 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
37451 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
37452 + };
37453 +
37454 struct __vxge_hw_virtualpath *vpath;
37455
37456 if ((vp == NULL) || (attr == NULL)) {
37457 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
37458 goto exit;
37459 }
37460
37461 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
37462 -
37463 fifo->mempool =
37464 __vxge_hw_mempool_create(vpath->hldev,
37465 fifo->config->memblock_size,
37466 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
37467 index 998974f..ecd26db 100644
37468 --- a/drivers/net/ethernet/realtek/r8169.c
37469 +++ b/drivers/net/ethernet/realtek/r8169.c
37470 @@ -741,22 +741,22 @@ struct rtl8169_private {
37471 struct mdio_ops {
37472 void (*write)(struct rtl8169_private *, int, int);
37473 int (*read)(struct rtl8169_private *, int);
37474 - } mdio_ops;
37475 + } __no_const mdio_ops;
37476
37477 struct pll_power_ops {
37478 void (*down)(struct rtl8169_private *);
37479 void (*up)(struct rtl8169_private *);
37480 - } pll_power_ops;
37481 + } __no_const pll_power_ops;
37482
37483 struct jumbo_ops {
37484 void (*enable)(struct rtl8169_private *);
37485 void (*disable)(struct rtl8169_private *);
37486 - } jumbo_ops;
37487 + } __no_const jumbo_ops;
37488
37489 struct csi_ops {
37490 void (*write)(struct rtl8169_private *, int, int);
37491 u32 (*read)(struct rtl8169_private *, int);
37492 - } csi_ops;
37493 + } __no_const csi_ops;
37494
37495 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
37496 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
37497 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
37498 index 0767043f..08c2553 100644
37499 --- a/drivers/net/ethernet/sfc/ptp.c
37500 +++ b/drivers/net/ethernet/sfc/ptp.c
37501 @@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
37502 (u32)((u64)ptp->start.dma_addr >> 32));
37503
37504 /* Clear flag that signals MC ready */
37505 - ACCESS_ONCE(*start) = 0;
37506 + ACCESS_ONCE_RW(*start) = 0;
37507 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
37508 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
37509
37510 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37511 index 0c74a70..3bc6f68 100644
37512 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37513 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
37514 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
37515
37516 writel(value, ioaddr + MMC_CNTRL);
37517
37518 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37519 - MMC_CNTRL, value);
37520 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
37521 +// MMC_CNTRL, value);
37522 }
37523
37524 /* To mask all all interrupts.*/
37525 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
37526 index e6fe0d8..2b7d752 100644
37527 --- a/drivers/net/hyperv/hyperv_net.h
37528 +++ b/drivers/net/hyperv/hyperv_net.h
37529 @@ -101,7 +101,7 @@ struct rndis_device {
37530
37531 enum rndis_device_state state;
37532 bool link_state;
37533 - atomic_t new_req_id;
37534 + atomic_unchecked_t new_req_id;
37535
37536 spinlock_t request_lock;
37537 struct list_head req_list;
37538 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
37539 index 2b657d4..9903bc0 100644
37540 --- a/drivers/net/hyperv/rndis_filter.c
37541 +++ b/drivers/net/hyperv/rndis_filter.c
37542 @@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
37543 * template
37544 */
37545 set = &rndis_msg->msg.set_req;
37546 - set->req_id = atomic_inc_return(&dev->new_req_id);
37547 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37548
37549 /* Add to the request list */
37550 spin_lock_irqsave(&dev->request_lock, flags);
37551 @@ -758,7 +758,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
37552
37553 /* Setup the rndis set */
37554 halt = &request->request_msg.msg.halt_req;
37555 - halt->req_id = atomic_inc_return(&dev->new_req_id);
37556 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
37557
37558 /* Ignore return since this msg is optional. */
37559 rndis_filter_send_request(dev, request);
37560 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
37561 index 1e9cb0b..7839125 100644
37562 --- a/drivers/net/ieee802154/fakehard.c
37563 +++ b/drivers/net/ieee802154/fakehard.c
37564 @@ -386,7 +386,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
37565 phy->transmit_power = 0xbf;
37566
37567 dev->netdev_ops = &fake_ops;
37568 - dev->ml_priv = &fake_mlme;
37569 + dev->ml_priv = (void *)&fake_mlme;
37570
37571 priv = netdev_priv(dev);
37572 priv->phy = phy;
37573 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
37574 index d3fb97d..e229d3e 100644
37575 --- a/drivers/net/macvlan.c
37576 +++ b/drivers/net/macvlan.c
37577 @@ -913,7 +913,7 @@ static int macvlan_device_event(struct notifier_block *unused,
37578 return NOTIFY_DONE;
37579 }
37580
37581 -static struct notifier_block macvlan_notifier_block __read_mostly = {
37582 +static struct notifier_block macvlan_notifier_block = {
37583 .notifier_call = macvlan_device_event,
37584 };
37585
37586 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
37587 index 0f0f9ce..0ca5819 100644
37588 --- a/drivers/net/macvtap.c
37589 +++ b/drivers/net/macvtap.c
37590 @@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
37591 return NOTIFY_DONE;
37592 }
37593
37594 -static struct notifier_block macvtap_notifier_block __read_mostly = {
37595 +static struct notifier_block macvtap_notifier_block = {
37596 .notifier_call = macvtap_device_event,
37597 };
37598
37599 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
37600 index daec9b0..6428fcb 100644
37601 --- a/drivers/net/phy/mdio-bitbang.c
37602 +++ b/drivers/net/phy/mdio-bitbang.c
37603 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
37604 struct mdiobb_ctrl *ctrl = bus->priv;
37605
37606 module_put(ctrl->ops->owner);
37607 + mdiobus_unregister(bus);
37608 mdiobus_free(bus);
37609 }
37610 EXPORT_SYMBOL(free_mdio_bitbang);
37611 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
37612 index 0b2706a..ba1430d 100644
37613 --- a/drivers/net/ppp/ppp_generic.c
37614 +++ b/drivers/net/ppp/ppp_generic.c
37615 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37616 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
37617 struct ppp_stats stats;
37618 struct ppp_comp_stats cstats;
37619 - char *vers;
37620
37621 switch (cmd) {
37622 case SIOCGPPPSTATS:
37623 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37624 break;
37625
37626 case SIOCGPPPVER:
37627 - vers = PPP_VERSION;
37628 - if (copy_to_user(addr, vers, strlen(vers) + 1))
37629 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
37630 break;
37631 err = 0;
37632 break;
37633 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
37634 index ad86660..9fd0884 100644
37635 --- a/drivers/net/team/team.c
37636 +++ b/drivers/net/team/team.c
37637 @@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
37638 return NOTIFY_DONE;
37639 }
37640
37641 -static struct notifier_block team_notifier_block __read_mostly = {
37642 +static struct notifier_block team_notifier_block = {
37643 .notifier_call = team_device_event,
37644 };
37645
37646 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
37647 index 2917a86..edd463f 100644
37648 --- a/drivers/net/tun.c
37649 +++ b/drivers/net/tun.c
37650 @@ -1836,7 +1836,7 @@ unlock:
37651 }
37652
37653 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37654 - unsigned long arg, int ifreq_len)
37655 + unsigned long arg, size_t ifreq_len)
37656 {
37657 struct tun_file *tfile = file->private_data;
37658 struct tun_struct *tun;
37659 @@ -1848,6 +1848,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
37660 int vnet_hdr_sz;
37661 int ret;
37662
37663 + if (ifreq_len > sizeof ifr)
37664 + return -EFAULT;
37665 +
37666 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
37667 if (copy_from_user(&ifr, argp, ifreq_len))
37668 return -EFAULT;
37669 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
37670 index cd8ccb2..cff5144 100644
37671 --- a/drivers/net/usb/hso.c
37672 +++ b/drivers/net/usb/hso.c
37673 @@ -71,7 +71,7 @@
37674 #include <asm/byteorder.h>
37675 #include <linux/serial_core.h>
37676 #include <linux/serial.h>
37677 -
37678 +#include <asm/local.h>
37679
37680 #define MOD_AUTHOR "Option Wireless"
37681 #define MOD_DESCRIPTION "USB High Speed Option driver"
37682 @@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
37683 struct urb *urb;
37684
37685 urb = serial->rx_urb[0];
37686 - if (serial->port.count > 0) {
37687 + if (atomic_read(&serial->port.count) > 0) {
37688 count = put_rxbuf_data(urb, serial);
37689 if (count == -1)
37690 return;
37691 @@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
37692 DUMP1(urb->transfer_buffer, urb->actual_length);
37693
37694 /* Anyone listening? */
37695 - if (serial->port.count == 0)
37696 + if (atomic_read(&serial->port.count) == 0)
37697 return;
37698
37699 if (status == 0) {
37700 @@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37701 tty_port_tty_set(&serial->port, tty);
37702
37703 /* check for port already opened, if not set the termios */
37704 - serial->port.count++;
37705 - if (serial->port.count == 1) {
37706 + if (atomic_inc_return(&serial->port.count) == 1) {
37707 serial->rx_state = RX_IDLE;
37708 /* Force default termio settings */
37709 _hso_serial_set_termios(tty, NULL);
37710 @@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
37711 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
37712 if (result) {
37713 hso_stop_serial_device(serial->parent);
37714 - serial->port.count--;
37715 + atomic_dec(&serial->port.count);
37716 kref_put(&serial->parent->ref, hso_serial_ref_free);
37717 }
37718 } else {
37719 @@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
37720
37721 /* reset the rts and dtr */
37722 /* do the actual close */
37723 - serial->port.count--;
37724 + atomic_dec(&serial->port.count);
37725
37726 - if (serial->port.count <= 0) {
37727 - serial->port.count = 0;
37728 + if (atomic_read(&serial->port.count) <= 0) {
37729 + atomic_set(&serial->port.count, 0);
37730 tty_port_tty_set(&serial->port, NULL);
37731 if (!usb_gone)
37732 hso_stop_serial_device(serial->parent);
37733 @@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
37734
37735 /* the actual setup */
37736 spin_lock_irqsave(&serial->serial_lock, flags);
37737 - if (serial->port.count)
37738 + if (atomic_read(&serial->port.count))
37739 _hso_serial_set_termios(tty, old);
37740 else
37741 tty->termios = *old;
37742 @@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
37743 D1("Pending read interrupt on port %d\n", i);
37744 spin_lock(&serial->serial_lock);
37745 if (serial->rx_state == RX_IDLE &&
37746 - serial->port.count > 0) {
37747 + atomic_read(&serial->port.count) > 0) {
37748 /* Setup and send a ctrl req read on
37749 * port i */
37750 if (!serial->rx_urb_filled[0]) {
37751 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
37752 /* Start all serial ports */
37753 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
37754 if (serial_table[i] && (serial_table[i]->interface == iface)) {
37755 - if (dev2ser(serial_table[i])->port.count) {
37756 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
37757 result =
37758 hso_start_serial_device(serial_table[i], GFP_NOIO);
37759 hso_kick_transmit(dev2ser(serial_table[i]));
37760 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37761 index 8d78253..bebbb68 100644
37762 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37763 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
37764 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37765 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
37766 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
37767
37768 - ACCESS_ONCE(ads->ds_link) = i->link;
37769 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
37770 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
37771 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
37772
37773 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
37774 ctl6 = SM(i->keytype, AR_EncrType);
37775 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37776
37777 if ((i->is_first || i->is_last) &&
37778 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
37779 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
37780 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
37781 | set11nTries(i->rates, 1)
37782 | set11nTries(i->rates, 2)
37783 | set11nTries(i->rates, 3)
37784 | (i->dur_update ? AR_DurUpdateEna : 0)
37785 | SM(0, AR_BurstDur);
37786
37787 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
37788 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
37789 | set11nRate(i->rates, 1)
37790 | set11nRate(i->rates, 2)
37791 | set11nRate(i->rates, 3);
37792 } else {
37793 - ACCESS_ONCE(ads->ds_ctl2) = 0;
37794 - ACCESS_ONCE(ads->ds_ctl3) = 0;
37795 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
37796 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
37797 }
37798
37799 if (!i->is_first) {
37800 - ACCESS_ONCE(ads->ds_ctl0) = 0;
37801 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37802 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37803 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
37804 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37805 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37806 return;
37807 }
37808
37809 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37810 break;
37811 }
37812
37813 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37814 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
37815 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37816 | SM(i->txpower, AR_XmitPower)
37817 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37818 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37819 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
37820 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
37821
37822 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
37823 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
37824 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
37825 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
37826
37827 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
37828 return;
37829
37830 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37831 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
37832 | set11nPktDurRTSCTS(i->rates, 1);
37833
37834 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37835 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
37836 | set11nPktDurRTSCTS(i->rates, 3);
37837
37838 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37839 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
37840 | set11nRateFlags(i->rates, 1)
37841 | set11nRateFlags(i->rates, 2)
37842 | set11nRateFlags(i->rates, 3)
37843 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37844 index 301bf72..3f5654f 100644
37845 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37846 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
37847 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37848 (i->qcu << AR_TxQcuNum_S) | desc_len;
37849
37850 checksum += val;
37851 - ACCESS_ONCE(ads->info) = val;
37852 + ACCESS_ONCE_RW(ads->info) = val;
37853
37854 checksum += i->link;
37855 - ACCESS_ONCE(ads->link) = i->link;
37856 + ACCESS_ONCE_RW(ads->link) = i->link;
37857
37858 checksum += i->buf_addr[0];
37859 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
37860 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
37861 checksum += i->buf_addr[1];
37862 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
37863 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
37864 checksum += i->buf_addr[2];
37865 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
37866 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
37867 checksum += i->buf_addr[3];
37868 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
37869 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
37870
37871 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
37872 - ACCESS_ONCE(ads->ctl3) = val;
37873 + ACCESS_ONCE_RW(ads->ctl3) = val;
37874 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
37875 - ACCESS_ONCE(ads->ctl5) = val;
37876 + ACCESS_ONCE_RW(ads->ctl5) = val;
37877 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
37878 - ACCESS_ONCE(ads->ctl7) = val;
37879 + ACCESS_ONCE_RW(ads->ctl7) = val;
37880 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
37881 - ACCESS_ONCE(ads->ctl9) = val;
37882 + ACCESS_ONCE_RW(ads->ctl9) = val;
37883
37884 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
37885 - ACCESS_ONCE(ads->ctl10) = checksum;
37886 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
37887
37888 if (i->is_first || i->is_last) {
37889 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
37890 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
37891 | set11nTries(i->rates, 1)
37892 | set11nTries(i->rates, 2)
37893 | set11nTries(i->rates, 3)
37894 | (i->dur_update ? AR_DurUpdateEna : 0)
37895 | SM(0, AR_BurstDur);
37896
37897 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
37898 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
37899 | set11nRate(i->rates, 1)
37900 | set11nRate(i->rates, 2)
37901 | set11nRate(i->rates, 3);
37902 } else {
37903 - ACCESS_ONCE(ads->ctl13) = 0;
37904 - ACCESS_ONCE(ads->ctl14) = 0;
37905 + ACCESS_ONCE_RW(ads->ctl13) = 0;
37906 + ACCESS_ONCE_RW(ads->ctl14) = 0;
37907 }
37908
37909 ads->ctl20 = 0;
37910 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37911
37912 ctl17 = SM(i->keytype, AR_EncrType);
37913 if (!i->is_first) {
37914 - ACCESS_ONCE(ads->ctl11) = 0;
37915 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37916 - ACCESS_ONCE(ads->ctl15) = 0;
37917 - ACCESS_ONCE(ads->ctl16) = 0;
37918 - ACCESS_ONCE(ads->ctl17) = ctl17;
37919 - ACCESS_ONCE(ads->ctl18) = 0;
37920 - ACCESS_ONCE(ads->ctl19) = 0;
37921 + ACCESS_ONCE_RW(ads->ctl11) = 0;
37922 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
37923 + ACCESS_ONCE_RW(ads->ctl15) = 0;
37924 + ACCESS_ONCE_RW(ads->ctl16) = 0;
37925 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37926 + ACCESS_ONCE_RW(ads->ctl18) = 0;
37927 + ACCESS_ONCE_RW(ads->ctl19) = 0;
37928 return;
37929 }
37930
37931 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37932 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
37933 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
37934 | SM(i->txpower, AR_XmitPower)
37935 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
37936 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
37937 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
37938 ctl12 |= SM(val, AR_PAPRDChainMask);
37939
37940 - ACCESS_ONCE(ads->ctl12) = ctl12;
37941 - ACCESS_ONCE(ads->ctl17) = ctl17;
37942 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
37943 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
37944
37945 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37946 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
37947 | set11nPktDurRTSCTS(i->rates, 1);
37948
37949 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37950 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
37951 | set11nPktDurRTSCTS(i->rates, 3);
37952
37953 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
37954 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
37955 | set11nRateFlags(i->rates, 1)
37956 | set11nRateFlags(i->rates, 2)
37957 | set11nRateFlags(i->rates, 3)
37958 | SM(i->rtscts_rate, AR_RTSCTSRate);
37959
37960 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37961 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37962 }
37963
37964 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37965 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37966 index 9d26fc5..60d9f14 100644
37967 --- a/drivers/net/wireless/ath/ath9k/hw.h
37968 +++ b/drivers/net/wireless/ath/ath9k/hw.h
37969 @@ -658,7 +658,7 @@ struct ath_hw_private_ops {
37970
37971 /* ANI */
37972 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37973 -};
37974 +} __no_const;
37975
37976 /**
37977 * struct ath_hw_ops - callbacks used by hardware code and driver code
37978 @@ -688,7 +688,7 @@ struct ath_hw_ops {
37979 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37980 struct ath_hw_antcomb_conf *antconf);
37981 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37982 -};
37983 +} __no_const;
37984
37985 struct ath_nf_limits {
37986 s16 max;
37987 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37988 index 3726cd6..b655808 100644
37989 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
37990 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37991 @@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37992 */
37993 if (il3945_mod_params.disable_hw_scan) {
37994 D_INFO("Disabling hw_scan\n");
37995 - il3945_mac_ops.hw_scan = NULL;
37996 + pax_open_kernel();
37997 + *(void **)&il3945_mac_ops.hw_scan = NULL;
37998 + pax_close_kernel();
37999 }
38000
38001 D_INFO("*** LOAD DRIVER ***\n");
38002 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38003 index 5b9533e..7733880 100644
38004 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38005 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
38006 @@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
38007 {
38008 struct iwl_priv *priv = file->private_data;
38009 char buf[64];
38010 - int buf_size;
38011 + size_t buf_size;
38012 u32 offset, len;
38013
38014 memset(buf, 0, sizeof(buf));
38015 @@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
38016 struct iwl_priv *priv = file->private_data;
38017
38018 char buf[8];
38019 - int buf_size;
38020 + size_t buf_size;
38021 u32 reset_flag;
38022
38023 memset(buf, 0, sizeof(buf));
38024 @@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
38025 {
38026 struct iwl_priv *priv = file->private_data;
38027 char buf[8];
38028 - int buf_size;
38029 + size_t buf_size;
38030 int ht40;
38031
38032 memset(buf, 0, sizeof(buf));
38033 @@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
38034 {
38035 struct iwl_priv *priv = file->private_data;
38036 char buf[8];
38037 - int buf_size;
38038 + size_t buf_size;
38039 int value;
38040
38041 memset(buf, 0, sizeof(buf));
38042 @@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
38043 {
38044 struct iwl_priv *priv = file->private_data;
38045 char buf[8];
38046 - int buf_size;
38047 + size_t buf_size;
38048 int clear;
38049
38050 memset(buf, 0, sizeof(buf));
38051 @@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
38052 {
38053 struct iwl_priv *priv = file->private_data;
38054 char buf[8];
38055 - int buf_size;
38056 + size_t buf_size;
38057 int trace;
38058
38059 memset(buf, 0, sizeof(buf));
38060 @@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
38061 {
38062 struct iwl_priv *priv = file->private_data;
38063 char buf[8];
38064 - int buf_size;
38065 + size_t buf_size;
38066 int missed;
38067
38068 memset(buf, 0, sizeof(buf));
38069 @@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
38070
38071 struct iwl_priv *priv = file->private_data;
38072 char buf[8];
38073 - int buf_size;
38074 + size_t buf_size;
38075 int plcp;
38076
38077 memset(buf, 0, sizeof(buf));
38078 @@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
38079
38080 struct iwl_priv *priv = file->private_data;
38081 char buf[8];
38082 - int buf_size;
38083 + size_t buf_size;
38084 int flush;
38085
38086 memset(buf, 0, sizeof(buf));
38087 @@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
38088
38089 struct iwl_priv *priv = file->private_data;
38090 char buf[8];
38091 - int buf_size;
38092 + size_t buf_size;
38093 int rts;
38094
38095 if (!priv->cfg->ht_params)
38096 @@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
38097 {
38098 struct iwl_priv *priv = file->private_data;
38099 char buf[8];
38100 - int buf_size;
38101 + size_t buf_size;
38102
38103 memset(buf, 0, sizeof(buf));
38104 buf_size = min(count, sizeof(buf) - 1);
38105 @@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
38106 struct iwl_priv *priv = file->private_data;
38107 u32 event_log_flag;
38108 char buf[8];
38109 - int buf_size;
38110 + size_t buf_size;
38111
38112 /* check that the interface is up */
38113 if (!iwl_is_ready(priv))
38114 @@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
38115 struct iwl_priv *priv = file->private_data;
38116 char buf[8];
38117 u32 calib_disabled;
38118 - int buf_size;
38119 + size_t buf_size;
38120
38121 memset(buf, 0, sizeof(buf));
38122 buf_size = min(count, sizeof(buf) - 1);
38123 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
38124 index 35708b9..31f7754 100644
38125 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
38126 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
38127 @@ -1100,7 +1100,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
38128 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
38129
38130 char buf[8];
38131 - int buf_size;
38132 + size_t buf_size;
38133 u32 reset_flag;
38134
38135 memset(buf, 0, sizeof(buf));
38136 @@ -1121,7 +1121,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
38137 {
38138 struct iwl_trans *trans = file->private_data;
38139 char buf[8];
38140 - int buf_size;
38141 + size_t buf_size;
38142 int csr;
38143
38144 memset(buf, 0, sizeof(buf));
38145 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
38146 index ff90855..e46d223 100644
38147 --- a/drivers/net/wireless/mac80211_hwsim.c
38148 +++ b/drivers/net/wireless/mac80211_hwsim.c
38149 @@ -2062,25 +2062,19 @@ static int __init init_mac80211_hwsim(void)
38150
38151 if (channels > 1) {
38152 hwsim_if_comb.num_different_channels = channels;
38153 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38154 - mac80211_hwsim_ops.cancel_hw_scan =
38155 - mac80211_hwsim_cancel_hw_scan;
38156 - mac80211_hwsim_ops.sw_scan_start = NULL;
38157 - mac80211_hwsim_ops.sw_scan_complete = NULL;
38158 - mac80211_hwsim_ops.remain_on_channel =
38159 - mac80211_hwsim_roc;
38160 - mac80211_hwsim_ops.cancel_remain_on_channel =
38161 - mac80211_hwsim_croc;
38162 - mac80211_hwsim_ops.add_chanctx =
38163 - mac80211_hwsim_add_chanctx;
38164 - mac80211_hwsim_ops.remove_chanctx =
38165 - mac80211_hwsim_remove_chanctx;
38166 - mac80211_hwsim_ops.change_chanctx =
38167 - mac80211_hwsim_change_chanctx;
38168 - mac80211_hwsim_ops.assign_vif_chanctx =
38169 - mac80211_hwsim_assign_vif_chanctx;
38170 - mac80211_hwsim_ops.unassign_vif_chanctx =
38171 - mac80211_hwsim_unassign_vif_chanctx;
38172 + pax_open_kernel();
38173 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
38174 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
38175 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
38176 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
38177 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
38178 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
38179 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
38180 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
38181 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
38182 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
38183 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
38184 + pax_close_kernel();
38185 }
38186
38187 spin_lock_init(&hwsim_radio_lock);
38188 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
38189 index abe1d03..fb02c22 100644
38190 --- a/drivers/net/wireless/rndis_wlan.c
38191 +++ b/drivers/net/wireless/rndis_wlan.c
38192 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
38193
38194 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
38195
38196 - if (rts_threshold < 0 || rts_threshold > 2347)
38197 + if (rts_threshold > 2347)
38198 rts_threshold = 2347;
38199
38200 tmp = cpu_to_le32(rts_threshold);
38201 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
38202 index 0751b35..246ba3e 100644
38203 --- a/drivers/net/wireless/rt2x00/rt2x00.h
38204 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
38205 @@ -398,7 +398,7 @@ struct rt2x00_intf {
38206 * for hardware which doesn't support hardware
38207 * sequence counting.
38208 */
38209 - atomic_t seqno;
38210 + atomic_unchecked_t seqno;
38211 };
38212
38213 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
38214 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
38215 index e488b94..14b6a0c 100644
38216 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
38217 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
38218 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
38219 * sequence counter given by mac80211.
38220 */
38221 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
38222 - seqno = atomic_add_return(0x10, &intf->seqno);
38223 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
38224 else
38225 - seqno = atomic_read(&intf->seqno);
38226 + seqno = atomic_read_unchecked(&intf->seqno);
38227
38228 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
38229 hdr->seq_ctrl |= cpu_to_le16(seqno);
38230 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
38231 index e57ee48..541cf6c 100644
38232 --- a/drivers/net/wireless/ti/wl1251/sdio.c
38233 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
38234 @@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
38235
38236 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
38237
38238 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38239 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38240 + pax_open_kernel();
38241 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
38242 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
38243 + pax_close_kernel();
38244
38245 wl1251_info("using dedicated interrupt line");
38246 } else {
38247 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38248 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38249 + pax_open_kernel();
38250 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
38251 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
38252 + pax_close_kernel();
38253
38254 wl1251_info("using SDIO interrupt");
38255 }
38256 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
38257 index e5f5f8f..fdf15b7 100644
38258 --- a/drivers/net/wireless/ti/wl12xx/main.c
38259 +++ b/drivers/net/wireless/ti/wl12xx/main.c
38260 @@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38261 sizeof(wl->conf.mem));
38262
38263 /* read data preparation is only needed by wl127x */
38264 - wl->ops->prepare_read = wl127x_prepare_read;
38265 + pax_open_kernel();
38266 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38267 + pax_close_kernel();
38268
38269 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38270 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38271 @@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
38272 sizeof(wl->conf.mem));
38273
38274 /* read data preparation is only needed by wl127x */
38275 - wl->ops->prepare_read = wl127x_prepare_read;
38276 + pax_open_kernel();
38277 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
38278 + pax_close_kernel();
38279
38280 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
38281 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
38282 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
38283 index 8d8c1f8..e754844 100644
38284 --- a/drivers/net/wireless/ti/wl18xx/main.c
38285 +++ b/drivers/net/wireless/ti/wl18xx/main.c
38286 @@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
38287 }
38288
38289 if (!checksum_param) {
38290 - wl18xx_ops.set_rx_csum = NULL;
38291 - wl18xx_ops.init_vif = NULL;
38292 + pax_open_kernel();
38293 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
38294 + *(void **)&wl18xx_ops.init_vif = NULL;
38295 + pax_close_kernel();
38296 }
38297
38298 /* Enable 11a Band only if we have 5G antennas */
38299 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
38300 index d93b2b6..ae50401 100644
38301 --- a/drivers/oprofile/buffer_sync.c
38302 +++ b/drivers/oprofile/buffer_sync.c
38303 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
38304 if (cookie == NO_COOKIE)
38305 offset = pc;
38306 if (cookie == INVALID_COOKIE) {
38307 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38308 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38309 offset = pc;
38310 }
38311 if (cookie != last_cookie) {
38312 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
38313 /* add userspace sample */
38314
38315 if (!mm) {
38316 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
38317 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
38318 return 0;
38319 }
38320
38321 cookie = lookup_dcookie(mm, s->eip, &offset);
38322
38323 if (cookie == INVALID_COOKIE) {
38324 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
38325 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
38326 return 0;
38327 }
38328
38329 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
38330 /* ignore backtraces if failed to add a sample */
38331 if (state == sb_bt_start) {
38332 state = sb_bt_ignore;
38333 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
38334 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
38335 }
38336 }
38337 release_mm(mm);
38338 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
38339 index c0cc4e7..44d4e54 100644
38340 --- a/drivers/oprofile/event_buffer.c
38341 +++ b/drivers/oprofile/event_buffer.c
38342 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
38343 }
38344
38345 if (buffer_pos == buffer_size) {
38346 - atomic_inc(&oprofile_stats.event_lost_overflow);
38347 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
38348 return;
38349 }
38350
38351 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
38352 index ed2c3ec..deda85a 100644
38353 --- a/drivers/oprofile/oprof.c
38354 +++ b/drivers/oprofile/oprof.c
38355 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
38356 if (oprofile_ops.switch_events())
38357 return;
38358
38359 - atomic_inc(&oprofile_stats.multiplex_counter);
38360 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
38361 start_switch_worker();
38362 }
38363
38364 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
38365 index 917d28e..d62d981 100644
38366 --- a/drivers/oprofile/oprofile_stats.c
38367 +++ b/drivers/oprofile/oprofile_stats.c
38368 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
38369 cpu_buf->sample_invalid_eip = 0;
38370 }
38371
38372 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
38373 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
38374 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
38375 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
38376 - atomic_set(&oprofile_stats.multiplex_counter, 0);
38377 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
38378 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
38379 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
38380 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
38381 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
38382 }
38383
38384
38385 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
38386 index 38b6fc0..b5cbfce 100644
38387 --- a/drivers/oprofile/oprofile_stats.h
38388 +++ b/drivers/oprofile/oprofile_stats.h
38389 @@ -13,11 +13,11 @@
38390 #include <linux/atomic.h>
38391
38392 struct oprofile_stat_struct {
38393 - atomic_t sample_lost_no_mm;
38394 - atomic_t sample_lost_no_mapping;
38395 - atomic_t bt_lost_no_mapping;
38396 - atomic_t event_lost_overflow;
38397 - atomic_t multiplex_counter;
38398 + atomic_unchecked_t sample_lost_no_mm;
38399 + atomic_unchecked_t sample_lost_no_mapping;
38400 + atomic_unchecked_t bt_lost_no_mapping;
38401 + atomic_unchecked_t event_lost_overflow;
38402 + atomic_unchecked_t multiplex_counter;
38403 };
38404
38405 extern struct oprofile_stat_struct oprofile_stats;
38406 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
38407 index 849357c..b83c1e0 100644
38408 --- a/drivers/oprofile/oprofilefs.c
38409 +++ b/drivers/oprofile/oprofilefs.c
38410 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
38411
38412
38413 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
38414 - char const *name, atomic_t *val)
38415 + char const *name, atomic_unchecked_t *val)
38416 {
38417 return __oprofilefs_create_file(sb, root, name,
38418 &atomic_ro_fops, 0444, val);
38419 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
38420 index 93404f7..4a313d8 100644
38421 --- a/drivers/oprofile/timer_int.c
38422 +++ b/drivers/oprofile/timer_int.c
38423 @@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
38424 return NOTIFY_OK;
38425 }
38426
38427 -static struct notifier_block __refdata oprofile_cpu_notifier = {
38428 +static struct notifier_block oprofile_cpu_notifier = {
38429 .notifier_call = oprofile_cpu_notify,
38430 };
38431
38432 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
38433 index 3f56bc0..707d642 100644
38434 --- a/drivers/parport/procfs.c
38435 +++ b/drivers/parport/procfs.c
38436 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
38437
38438 *ppos += len;
38439
38440 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
38441 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
38442 }
38443
38444 #ifdef CONFIG_PARPORT_1284
38445 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
38446
38447 *ppos += len;
38448
38449 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
38450 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
38451 }
38452 #endif /* IEEE1284.3 support. */
38453
38454 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
38455 index a6a71c4..c91097b 100644
38456 --- a/drivers/pci/hotplug/cpcihp_generic.c
38457 +++ b/drivers/pci/hotplug/cpcihp_generic.c
38458 @@ -73,7 +73,6 @@ static u16 port;
38459 static unsigned int enum_bit;
38460 static u8 enum_mask;
38461
38462 -static struct cpci_hp_controller_ops generic_hpc_ops;
38463 static struct cpci_hp_controller generic_hpc;
38464
38465 static int __init validate_parameters(void)
38466 @@ -139,6 +138,10 @@ static int query_enum(void)
38467 return ((value & enum_mask) == enum_mask);
38468 }
38469
38470 +static struct cpci_hp_controller_ops generic_hpc_ops = {
38471 + .query_enum = query_enum,
38472 +};
38473 +
38474 static int __init cpcihp_generic_init(void)
38475 {
38476 int status;
38477 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
38478 pci_dev_put(dev);
38479
38480 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
38481 - generic_hpc_ops.query_enum = query_enum;
38482 generic_hpc.ops = &generic_hpc_ops;
38483
38484 status = cpci_hp_register_controller(&generic_hpc);
38485 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
38486 index 449b4bb..257e2e8 100644
38487 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
38488 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
38489 @@ -59,7 +59,6 @@
38490 /* local variables */
38491 static bool debug;
38492 static bool poll;
38493 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
38494 static struct cpci_hp_controller zt5550_hpc;
38495
38496 /* Primary cPCI bus bridge device */
38497 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
38498 return 0;
38499 }
38500
38501 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
38502 + .query_enum = zt5550_hc_query_enum,
38503 +};
38504 +
38505 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
38506 {
38507 int status;
38508 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
38509 dbg("returned from zt5550_hc_config");
38510
38511 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
38512 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
38513 zt5550_hpc.ops = &zt5550_hpc_ops;
38514 if(!poll) {
38515 zt5550_hpc.irq = hc_dev->irq;
38516 zt5550_hpc.irq_flags = IRQF_SHARED;
38517 zt5550_hpc.dev_id = hc_dev;
38518
38519 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38520 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38521 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38522 + pax_open_kernel();
38523 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
38524 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
38525 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
38526 + pax_open_kernel();
38527 } else {
38528 info("using ENUM# polling mode");
38529 }
38530 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
38531 index 76ba8a1..20ca857 100644
38532 --- a/drivers/pci/hotplug/cpqphp_nvram.c
38533 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
38534 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
38535
38536 void compaq_nvram_init (void __iomem *rom_start)
38537 {
38538 +
38539 +#ifndef CONFIG_PAX_KERNEXEC
38540 if (rom_start) {
38541 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
38542 }
38543 +#endif
38544 +
38545 dbg("int15 entry = %p\n", compaq_int15_entry_point);
38546
38547 /* initialize our int15 lock */
38548 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
38549 index 8474b6a..ee81993 100644
38550 --- a/drivers/pci/pcie/aspm.c
38551 +++ b/drivers/pci/pcie/aspm.c
38552 @@ -27,9 +27,9 @@
38553 #define MODULE_PARAM_PREFIX "pcie_aspm."
38554
38555 /* Note: those are not register definitions */
38556 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
38557 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
38558 -#define ASPM_STATE_L1 (4) /* L1 state */
38559 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
38560 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
38561 +#define ASPM_STATE_L1 (4U) /* L1 state */
38562 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
38563 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
38564
38565 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
38566 index 6186f03..1a78714 100644
38567 --- a/drivers/pci/probe.c
38568 +++ b/drivers/pci/probe.c
38569 @@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
38570 struct pci_bus_region region;
38571 bool bar_too_big = false, bar_disabled = false;
38572
38573 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
38574 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
38575
38576 /* No printks while decoding is disabled! */
38577 if (!dev->mmio_always_on) {
38578 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
38579 index 9b8505c..f00870a 100644
38580 --- a/drivers/pci/proc.c
38581 +++ b/drivers/pci/proc.c
38582 @@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
38583 static int __init pci_proc_init(void)
38584 {
38585 struct pci_dev *dev = NULL;
38586 +
38587 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
38588 +#ifdef CONFIG_GRKERNSEC_PROC_USER
38589 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
38590 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
38591 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
38592 +#endif
38593 +#else
38594 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
38595 +#endif
38596 proc_create("devices", 0, proc_bus_pci_dir,
38597 &proc_bus_pci_dev_operations);
38598 proc_initialized = 1;
38599 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
38600 index f946ca7..f25c833 100644
38601 --- a/drivers/platform/x86/thinkpad_acpi.c
38602 +++ b/drivers/platform/x86/thinkpad_acpi.c
38603 @@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
38604 return 0;
38605 }
38606
38607 -void static hotkey_mask_warn_incomplete_mask(void)
38608 +static void hotkey_mask_warn_incomplete_mask(void)
38609 {
38610 /* log only what the user can fix... */
38611 const u32 wantedmask = hotkey_driver_mask &
38612 @@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
38613 }
38614 }
38615
38616 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38617 - struct tp_nvram_state *newn,
38618 - const u32 event_mask)
38619 -{
38620 -
38621 #define TPACPI_COMPARE_KEY(__scancode, __member) \
38622 do { \
38623 if ((event_mask & (1 << __scancode)) && \
38624 @@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38625 tpacpi_hotkey_send_key(__scancode); \
38626 } while (0)
38627
38628 - void issue_volchange(const unsigned int oldvol,
38629 - const unsigned int newvol)
38630 - {
38631 - unsigned int i = oldvol;
38632 +static void issue_volchange(const unsigned int oldvol,
38633 + const unsigned int newvol,
38634 + const u32 event_mask)
38635 +{
38636 + unsigned int i = oldvol;
38637
38638 - while (i > newvol) {
38639 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38640 - i--;
38641 - }
38642 - while (i < newvol) {
38643 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38644 - i++;
38645 - }
38646 + while (i > newvol) {
38647 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
38648 + i--;
38649 }
38650 + while (i < newvol) {
38651 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38652 + i++;
38653 + }
38654 +}
38655
38656 - void issue_brightnesschange(const unsigned int oldbrt,
38657 - const unsigned int newbrt)
38658 - {
38659 - unsigned int i = oldbrt;
38660 +static void issue_brightnesschange(const unsigned int oldbrt,
38661 + const unsigned int newbrt,
38662 + const u32 event_mask)
38663 +{
38664 + unsigned int i = oldbrt;
38665
38666 - while (i > newbrt) {
38667 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38668 - i--;
38669 - }
38670 - while (i < newbrt) {
38671 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38672 - i++;
38673 - }
38674 + while (i > newbrt) {
38675 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
38676 + i--;
38677 + }
38678 + while (i < newbrt) {
38679 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38680 + i++;
38681 }
38682 +}
38683
38684 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38685 + struct tp_nvram_state *newn,
38686 + const u32 event_mask)
38687 +{
38688 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
38689 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
38690 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
38691 @@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38692 oldn->volume_level != newn->volume_level) {
38693 /* recently muted, or repeated mute keypress, or
38694 * multiple presses ending in mute */
38695 - issue_volchange(oldn->volume_level, newn->volume_level);
38696 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38697 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
38698 }
38699 } else {
38700 @@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38701 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
38702 }
38703 if (oldn->volume_level != newn->volume_level) {
38704 - issue_volchange(oldn->volume_level, newn->volume_level);
38705 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
38706 } else if (oldn->volume_toggle != newn->volume_toggle) {
38707 /* repeated vol up/down keypress at end of scale ? */
38708 if (newn->volume_level == 0)
38709 @@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38710 /* handle brightness */
38711 if (oldn->brightness_level != newn->brightness_level) {
38712 issue_brightnesschange(oldn->brightness_level,
38713 - newn->brightness_level);
38714 + newn->brightness_level,
38715 + event_mask);
38716 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
38717 /* repeated key presses that didn't change state */
38718 if (newn->brightness_level == 0)
38719 @@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
38720 && !tp_features.bright_unkfw)
38721 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
38722 }
38723 +}
38724
38725 #undef TPACPI_COMPARE_KEY
38726 #undef TPACPI_MAY_SEND_KEY
38727 -}
38728
38729 /*
38730 * Polling driver
38731 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
38732 index 769d265..a3a05ca 100644
38733 --- a/drivers/pnp/pnpbios/bioscalls.c
38734 +++ b/drivers/pnp/pnpbios/bioscalls.c
38735 @@ -58,7 +58,7 @@ do { \
38736 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
38737 } while(0)
38738
38739 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
38740 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
38741 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
38742
38743 /*
38744 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38745
38746 cpu = get_cpu();
38747 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
38748 +
38749 + pax_open_kernel();
38750 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
38751 + pax_close_kernel();
38752
38753 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
38754 spin_lock_irqsave(&pnp_bios_lock, flags);
38755 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
38756 :"memory");
38757 spin_unlock_irqrestore(&pnp_bios_lock, flags);
38758
38759 + pax_open_kernel();
38760 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
38761 + pax_close_kernel();
38762 +
38763 put_cpu();
38764
38765 /* If we get here and this is set then the PnP BIOS faulted on us. */
38766 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
38767 return status;
38768 }
38769
38770 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
38771 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
38772 {
38773 int i;
38774
38775 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38776 pnp_bios_callpoint.offset = header->fields.pm16offset;
38777 pnp_bios_callpoint.segment = PNP_CS16;
38778
38779 + pax_open_kernel();
38780 +
38781 for_each_possible_cpu(i) {
38782 struct desc_struct *gdt = get_cpu_gdt_table(i);
38783 if (!gdt)
38784 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
38785 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
38786 (unsigned long)__va(header->fields.pm16dseg));
38787 }
38788 +
38789 + pax_close_kernel();
38790 }
38791 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
38792 index 3e6db1c..1fbbdae 100644
38793 --- a/drivers/pnp/resource.c
38794 +++ b/drivers/pnp/resource.c
38795 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
38796 return 1;
38797
38798 /* check if the resource is valid */
38799 - if (*irq < 0 || *irq > 15)
38800 + if (*irq > 15)
38801 return 0;
38802
38803 /* check if the resource is reserved */
38804 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
38805 return 1;
38806
38807 /* check if the resource is valid */
38808 - if (*dma < 0 || *dma == 4 || *dma > 7)
38809 + if (*dma == 4 || *dma > 7)
38810 return 0;
38811
38812 /* check if the resource is reserved */
38813 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
38814 index 7df7c5f..bd48c47 100644
38815 --- a/drivers/power/pda_power.c
38816 +++ b/drivers/power/pda_power.c
38817 @@ -37,7 +37,11 @@ static int polling;
38818
38819 #ifdef CONFIG_USB_OTG_UTILS
38820 static struct usb_phy *transceiver;
38821 -static struct notifier_block otg_nb;
38822 +static int otg_handle_notification(struct notifier_block *nb,
38823 + unsigned long event, void *unused);
38824 +static struct notifier_block otg_nb = {
38825 + .notifier_call = otg_handle_notification
38826 +};
38827 #endif
38828
38829 static struct regulator *ac_draw;
38830 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
38831
38832 #ifdef CONFIG_USB_OTG_UTILS
38833 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
38834 - otg_nb.notifier_call = otg_handle_notification;
38835 ret = usb_register_notifier(transceiver, &otg_nb);
38836 if (ret) {
38837 dev_err(dev, "failure to register otg notifier\n");
38838 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
38839 index 4d7c635..9860196 100644
38840 --- a/drivers/regulator/max8660.c
38841 +++ b/drivers/regulator/max8660.c
38842 @@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
38843 max8660->shadow_regs[MAX8660_OVER1] = 5;
38844 } else {
38845 /* Otherwise devices can be toggled via software */
38846 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
38847 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
38848 + pax_open_kernel();
38849 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
38850 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
38851 + pax_close_kernel();
38852 }
38853
38854 /*
38855 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
38856 index 9a8ea91..c483dd9 100644
38857 --- a/drivers/regulator/max8973-regulator.c
38858 +++ b/drivers/regulator/max8973-regulator.c
38859 @@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
38860 if (!pdata->enable_ext_control) {
38861 max->desc.enable_reg = MAX8973_VOUT;
38862 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
38863 - max8973_dcdc_ops.enable = regulator_enable_regmap;
38864 - max8973_dcdc_ops.disable = regulator_disable_regmap;
38865 - max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38866 + pax_open_kernel();
38867 + *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
38868 + *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
38869 + *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
38870 + pax_close_kernel();
38871 }
38872
38873 max->enable_external_control = pdata->enable_ext_control;
38874 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
38875 index 0d84b1f..c2da6ac 100644
38876 --- a/drivers/regulator/mc13892-regulator.c
38877 +++ b/drivers/regulator/mc13892-regulator.c
38878 @@ -540,10 +540,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
38879 }
38880 mc13xxx_unlock(mc13892);
38881
38882 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38883 + pax_open_kernel();
38884 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
38885 = mc13892_vcam_set_mode;
38886 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38887 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
38888 = mc13892_vcam_get_mode;
38889 + pax_close_kernel();
38890
38891 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
38892 ARRAY_SIZE(mc13892_regulators));
38893 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
38894 index 9a86b4b..3a383dc 100644
38895 --- a/drivers/rtc/rtc-dev.c
38896 +++ b/drivers/rtc/rtc-dev.c
38897 @@ -14,6 +14,7 @@
38898 #include <linux/module.h>
38899 #include <linux/rtc.h>
38900 #include <linux/sched.h>
38901 +#include <linux/grsecurity.h>
38902 #include "rtc-core.h"
38903
38904 static dev_t rtc_devt;
38905 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
38906 if (copy_from_user(&tm, uarg, sizeof(tm)))
38907 return -EFAULT;
38908
38909 + gr_log_timechange();
38910 +
38911 return rtc_set_time(rtc, &tm);
38912
38913 case RTC_PIE_ON:
38914 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
38915 index 4ad7e36..d004679 100644
38916 --- a/drivers/scsi/bfa/bfa.h
38917 +++ b/drivers/scsi/bfa/bfa.h
38918 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
38919 u32 *end);
38920 int cpe_vec_q0;
38921 int rme_vec_q0;
38922 -};
38923 +} __no_const;
38924 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
38925
38926 struct bfa_faa_cbfn_s {
38927 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
38928 index e693af6..2e525b6 100644
38929 --- a/drivers/scsi/bfa/bfa_fcpim.h
38930 +++ b/drivers/scsi/bfa/bfa_fcpim.h
38931 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
38932
38933 struct bfa_itn_s {
38934 bfa_isr_func_t isr;
38935 -};
38936 +} __no_const;
38937
38938 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
38939 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
38940 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
38941 index 23a90e7..9cf04ee 100644
38942 --- a/drivers/scsi/bfa/bfa_ioc.h
38943 +++ b/drivers/scsi/bfa/bfa_ioc.h
38944 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
38945 bfa_ioc_disable_cbfn_t disable_cbfn;
38946 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
38947 bfa_ioc_reset_cbfn_t reset_cbfn;
38948 -};
38949 +} __no_const;
38950
38951 /*
38952 * IOC event notification mechanism.
38953 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
38954 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
38955 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
38956 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
38957 -};
38958 +} __no_const;
38959
38960 /*
38961 * Queue element to wait for room in request queue. FIFO order is
38962 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
38963 index 593085a..47aa999 100644
38964 --- a/drivers/scsi/hosts.c
38965 +++ b/drivers/scsi/hosts.c
38966 @@ -42,7 +42,7 @@
38967 #include "scsi_logging.h"
38968
38969
38970 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38971 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
38972
38973
38974 static void scsi_host_cls_release(struct device *dev)
38975 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
38976 * subtract one because we increment first then return, but we need to
38977 * know what the next host number was before increment
38978 */
38979 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
38980 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
38981 shost->dma_channel = 0xff;
38982
38983 /* These three are default values which can be overridden */
38984 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
38985 index 4f33806..afd6f60 100644
38986 --- a/drivers/scsi/hpsa.c
38987 +++ b/drivers/scsi/hpsa.c
38988 @@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
38989 unsigned long flags;
38990
38991 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38992 - return h->access.command_completed(h, q);
38993 + return h->access->command_completed(h, q);
38994
38995 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38996 a = rq->head[rq->current_entry];
38997 @@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38998 while (!list_empty(&h->reqQ)) {
38999 c = list_entry(h->reqQ.next, struct CommandList, list);
39000 /* can't do anything if fifo is full */
39001 - if ((h->access.fifo_full(h))) {
39002 + if ((h->access->fifo_full(h))) {
39003 dev_warn(&h->pdev->dev, "fifo full\n");
39004 break;
39005 }
39006 @@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
39007
39008 /* Tell the controller execute command */
39009 spin_unlock_irqrestore(&h->lock, flags);
39010 - h->access.submit_command(h, c);
39011 + h->access->submit_command(h, c);
39012 spin_lock_irqsave(&h->lock, flags);
39013 }
39014 spin_unlock_irqrestore(&h->lock, flags);
39015 @@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
39016
39017 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
39018 {
39019 - return h->access.command_completed(h, q);
39020 + return h->access->command_completed(h, q);
39021 }
39022
39023 static inline bool interrupt_pending(struct ctlr_info *h)
39024 {
39025 - return h->access.intr_pending(h);
39026 + return h->access->intr_pending(h);
39027 }
39028
39029 static inline long interrupt_not_for_us(struct ctlr_info *h)
39030 {
39031 - return (h->access.intr_pending(h) == 0) ||
39032 + return (h->access->intr_pending(h) == 0) ||
39033 (h->interrupts_enabled == 0);
39034 }
39035
39036 @@ -4316,7 +4316,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
39037 if (prod_index < 0)
39038 return -ENODEV;
39039 h->product_name = products[prod_index].product_name;
39040 - h->access = *(products[prod_index].access);
39041 + h->access = products[prod_index].access;
39042
39043 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
39044 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
39045 @@ -4598,7 +4598,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
39046
39047 assert_spin_locked(&lockup_detector_lock);
39048 remove_ctlr_from_lockup_detector_list(h);
39049 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39050 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39051 spin_lock_irqsave(&h->lock, flags);
39052 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
39053 spin_unlock_irqrestore(&h->lock, flags);
39054 @@ -4775,7 +4775,7 @@ reinit_after_soft_reset:
39055 }
39056
39057 /* make sure the board interrupts are off */
39058 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39059 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39060
39061 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
39062 goto clean2;
39063 @@ -4809,7 +4809,7 @@ reinit_after_soft_reset:
39064 * fake ones to scoop up any residual completions.
39065 */
39066 spin_lock_irqsave(&h->lock, flags);
39067 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39068 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39069 spin_unlock_irqrestore(&h->lock, flags);
39070 free_irqs(h);
39071 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
39072 @@ -4828,9 +4828,9 @@ reinit_after_soft_reset:
39073 dev_info(&h->pdev->dev, "Board READY.\n");
39074 dev_info(&h->pdev->dev,
39075 "Waiting for stale completions to drain.\n");
39076 - h->access.set_intr_mask(h, HPSA_INTR_ON);
39077 + h->access->set_intr_mask(h, HPSA_INTR_ON);
39078 msleep(10000);
39079 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39080 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39081
39082 rc = controller_reset_failed(h->cfgtable);
39083 if (rc)
39084 @@ -4851,7 +4851,7 @@ reinit_after_soft_reset:
39085 }
39086
39087 /* Turn the interrupts on so we can service requests */
39088 - h->access.set_intr_mask(h, HPSA_INTR_ON);
39089 + h->access->set_intr_mask(h, HPSA_INTR_ON);
39090
39091 hpsa_hba_inquiry(h);
39092 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
39093 @@ -4903,7 +4903,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
39094 * To write all data in the battery backed cache to disks
39095 */
39096 hpsa_flush_cache(h);
39097 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
39098 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
39099 hpsa_free_irqs_and_disable_msix(h);
39100 }
39101
39102 @@ -5071,7 +5071,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
39103 return;
39104 }
39105 /* Change the access methods to the performant access methods */
39106 - h->access = SA5_performant_access;
39107 + h->access = &SA5_performant_access;
39108 h->transMethod = CFGTBL_Trans_Performant;
39109 }
39110
39111 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
39112 index 9816479..c5d4e97 100644
39113 --- a/drivers/scsi/hpsa.h
39114 +++ b/drivers/scsi/hpsa.h
39115 @@ -79,7 +79,7 @@ struct ctlr_info {
39116 unsigned int msix_vector;
39117 unsigned int msi_vector;
39118 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
39119 - struct access_method access;
39120 + struct access_method *access;
39121
39122 /* queue and queue Info */
39123 struct list_head reqQ;
39124 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
39125 index c772d8d..35c362c 100644
39126 --- a/drivers/scsi/libfc/fc_exch.c
39127 +++ b/drivers/scsi/libfc/fc_exch.c
39128 @@ -100,12 +100,12 @@ struct fc_exch_mgr {
39129 u16 pool_max_index;
39130
39131 struct {
39132 - atomic_t no_free_exch;
39133 - atomic_t no_free_exch_xid;
39134 - atomic_t xid_not_found;
39135 - atomic_t xid_busy;
39136 - atomic_t seq_not_found;
39137 - atomic_t non_bls_resp;
39138 + atomic_unchecked_t no_free_exch;
39139 + atomic_unchecked_t no_free_exch_xid;
39140 + atomic_unchecked_t xid_not_found;
39141 + atomic_unchecked_t xid_busy;
39142 + atomic_unchecked_t seq_not_found;
39143 + atomic_unchecked_t non_bls_resp;
39144 } stats;
39145 };
39146
39147 @@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
39148 /* allocate memory for exchange */
39149 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
39150 if (!ep) {
39151 - atomic_inc(&mp->stats.no_free_exch);
39152 + atomic_inc_unchecked(&mp->stats.no_free_exch);
39153 goto out;
39154 }
39155 memset(ep, 0, sizeof(*ep));
39156 @@ -786,7 +786,7 @@ out:
39157 return ep;
39158 err:
39159 spin_unlock_bh(&pool->lock);
39160 - atomic_inc(&mp->stats.no_free_exch_xid);
39161 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
39162 mempool_free(ep, mp->ep_pool);
39163 return NULL;
39164 }
39165 @@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39166 xid = ntohs(fh->fh_ox_id); /* we originated exch */
39167 ep = fc_exch_find(mp, xid);
39168 if (!ep) {
39169 - atomic_inc(&mp->stats.xid_not_found);
39170 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39171 reject = FC_RJT_OX_ID;
39172 goto out;
39173 }
39174 @@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39175 ep = fc_exch_find(mp, xid);
39176 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
39177 if (ep) {
39178 - atomic_inc(&mp->stats.xid_busy);
39179 + atomic_inc_unchecked(&mp->stats.xid_busy);
39180 reject = FC_RJT_RX_ID;
39181 goto rel;
39182 }
39183 @@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39184 }
39185 xid = ep->xid; /* get our XID */
39186 } else if (!ep) {
39187 - atomic_inc(&mp->stats.xid_not_found);
39188 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39189 reject = FC_RJT_RX_ID; /* XID not found */
39190 goto out;
39191 }
39192 @@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
39193 } else {
39194 sp = &ep->seq;
39195 if (sp->id != fh->fh_seq_id) {
39196 - atomic_inc(&mp->stats.seq_not_found);
39197 + atomic_inc_unchecked(&mp->stats.seq_not_found);
39198 if (f_ctl & FC_FC_END_SEQ) {
39199 /*
39200 * Update sequence_id based on incoming last
39201 @@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39202
39203 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
39204 if (!ep) {
39205 - atomic_inc(&mp->stats.xid_not_found);
39206 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39207 goto out;
39208 }
39209 if (ep->esb_stat & ESB_ST_COMPLETE) {
39210 - atomic_inc(&mp->stats.xid_not_found);
39211 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39212 goto rel;
39213 }
39214 if (ep->rxid == FC_XID_UNKNOWN)
39215 ep->rxid = ntohs(fh->fh_rx_id);
39216 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
39217 - atomic_inc(&mp->stats.xid_not_found);
39218 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39219 goto rel;
39220 }
39221 if (ep->did != ntoh24(fh->fh_s_id) &&
39222 ep->did != FC_FID_FLOGI) {
39223 - atomic_inc(&mp->stats.xid_not_found);
39224 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39225 goto rel;
39226 }
39227 sof = fr_sof(fp);
39228 @@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39229 sp->ssb_stat |= SSB_ST_RESP;
39230 sp->id = fh->fh_seq_id;
39231 } else if (sp->id != fh->fh_seq_id) {
39232 - atomic_inc(&mp->stats.seq_not_found);
39233 + atomic_inc_unchecked(&mp->stats.seq_not_found);
39234 goto rel;
39235 }
39236
39237 @@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
39238 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
39239
39240 if (!sp)
39241 - atomic_inc(&mp->stats.xid_not_found);
39242 + atomic_inc_unchecked(&mp->stats.xid_not_found);
39243 else
39244 - atomic_inc(&mp->stats.non_bls_resp);
39245 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
39246
39247 fc_frame_free(fp);
39248 }
39249 @@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
39250
39251 list_for_each_entry(ema, &lport->ema_list, ema_list) {
39252 mp = ema->mp;
39253 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
39254 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
39255 st->fc_no_free_exch_xid +=
39256 - atomic_read(&mp->stats.no_free_exch_xid);
39257 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
39258 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
39259 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
39260 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
39261 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
39262 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
39263 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
39264 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
39265 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
39266 }
39267 }
39268 EXPORT_SYMBOL(fc_exch_update_stats);
39269 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
39270 index bdb81cd..d3c7c2c 100644
39271 --- a/drivers/scsi/libsas/sas_ata.c
39272 +++ b/drivers/scsi/libsas/sas_ata.c
39273 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
39274 .postreset = ata_std_postreset,
39275 .error_handler = ata_std_error_handler,
39276 .post_internal_cmd = sas_ata_post_internal,
39277 - .qc_defer = ata_std_qc_defer,
39278 + .qc_defer = ata_std_qc_defer,
39279 .qc_prep = ata_noop_qc_prep,
39280 .qc_issue = sas_ata_qc_issue,
39281 .qc_fill_rtf = sas_ata_qc_fill_rtf,
39282 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
39283 index df4c13a..a51e90c 100644
39284 --- a/drivers/scsi/lpfc/lpfc.h
39285 +++ b/drivers/scsi/lpfc/lpfc.h
39286 @@ -424,7 +424,7 @@ struct lpfc_vport {
39287 struct dentry *debug_nodelist;
39288 struct dentry *vport_debugfs_root;
39289 struct lpfc_debugfs_trc *disc_trc;
39290 - atomic_t disc_trc_cnt;
39291 + atomic_unchecked_t disc_trc_cnt;
39292 #endif
39293 uint8_t stat_data_enabled;
39294 uint8_t stat_data_blocked;
39295 @@ -842,8 +842,8 @@ struct lpfc_hba {
39296 struct timer_list fabric_block_timer;
39297 unsigned long bit_flags;
39298 #define FABRIC_COMANDS_BLOCKED 0
39299 - atomic_t num_rsrc_err;
39300 - atomic_t num_cmd_success;
39301 + atomic_unchecked_t num_rsrc_err;
39302 + atomic_unchecked_t num_cmd_success;
39303 unsigned long last_rsrc_error_time;
39304 unsigned long last_ramp_down_time;
39305 unsigned long last_ramp_up_time;
39306 @@ -879,7 +879,7 @@ struct lpfc_hba {
39307
39308 struct dentry *debug_slow_ring_trc;
39309 struct lpfc_debugfs_trc *slow_ring_trc;
39310 - atomic_t slow_ring_trc_cnt;
39311 + atomic_unchecked_t slow_ring_trc_cnt;
39312 /* iDiag debugfs sub-directory */
39313 struct dentry *idiag_root;
39314 struct dentry *idiag_pci_cfg;
39315 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
39316 index f63f5ff..de29189 100644
39317 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
39318 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
39319 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
39320
39321 #include <linux/debugfs.h>
39322
39323 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39324 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
39325 static unsigned long lpfc_debugfs_start_time = 0L;
39326
39327 /* iDiag */
39328 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
39329 lpfc_debugfs_enable = 0;
39330
39331 len = 0;
39332 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
39333 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
39334 (lpfc_debugfs_max_disc_trc - 1);
39335 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
39336 dtp = vport->disc_trc + i;
39337 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
39338 lpfc_debugfs_enable = 0;
39339
39340 len = 0;
39341 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
39342 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
39343 (lpfc_debugfs_max_slow_ring_trc - 1);
39344 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
39345 dtp = phba->slow_ring_trc + i;
39346 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
39347 !vport || !vport->disc_trc)
39348 return;
39349
39350 - index = atomic_inc_return(&vport->disc_trc_cnt) &
39351 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
39352 (lpfc_debugfs_max_disc_trc - 1);
39353 dtp = vport->disc_trc + index;
39354 dtp->fmt = fmt;
39355 dtp->data1 = data1;
39356 dtp->data2 = data2;
39357 dtp->data3 = data3;
39358 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39359 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39360 dtp->jif = jiffies;
39361 #endif
39362 return;
39363 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
39364 !phba || !phba->slow_ring_trc)
39365 return;
39366
39367 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
39368 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
39369 (lpfc_debugfs_max_slow_ring_trc - 1);
39370 dtp = phba->slow_ring_trc + index;
39371 dtp->fmt = fmt;
39372 dtp->data1 = data1;
39373 dtp->data2 = data2;
39374 dtp->data3 = data3;
39375 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
39376 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
39377 dtp->jif = jiffies;
39378 #endif
39379 return;
39380 @@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39381 "slow_ring buffer\n");
39382 goto debug_failed;
39383 }
39384 - atomic_set(&phba->slow_ring_trc_cnt, 0);
39385 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
39386 memset(phba->slow_ring_trc, 0,
39387 (sizeof(struct lpfc_debugfs_trc) *
39388 lpfc_debugfs_max_slow_ring_trc));
39389 @@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
39390 "buffer\n");
39391 goto debug_failed;
39392 }
39393 - atomic_set(&vport->disc_trc_cnt, 0);
39394 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
39395
39396 snprintf(name, sizeof(name), "discovery_trace");
39397 vport->debug_disc_trc =
39398 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
39399 index 89ad558..76956c4 100644
39400 --- a/drivers/scsi/lpfc/lpfc_init.c
39401 +++ b/drivers/scsi/lpfc/lpfc_init.c
39402 @@ -10618,8 +10618,10 @@ lpfc_init(void)
39403 "misc_register returned with status %d", error);
39404
39405 if (lpfc_enable_npiv) {
39406 - lpfc_transport_functions.vport_create = lpfc_vport_create;
39407 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39408 + pax_open_kernel();
39409 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
39410 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
39411 + pax_close_kernel();
39412 }
39413 lpfc_transport_template =
39414 fc_attach_transport(&lpfc_transport_functions);
39415 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
39416 index 60e5a17..ff7a793 100644
39417 --- a/drivers/scsi/lpfc/lpfc_scsi.c
39418 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
39419 @@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
39420 uint32_t evt_posted;
39421
39422 spin_lock_irqsave(&phba->hbalock, flags);
39423 - atomic_inc(&phba->num_rsrc_err);
39424 + atomic_inc_unchecked(&phba->num_rsrc_err);
39425 phba->last_rsrc_error_time = jiffies;
39426
39427 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
39428 @@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
39429 unsigned long flags;
39430 struct lpfc_hba *phba = vport->phba;
39431 uint32_t evt_posted;
39432 - atomic_inc(&phba->num_cmd_success);
39433 + atomic_inc_unchecked(&phba->num_cmd_success);
39434
39435 if (vport->cfg_lun_queue_depth <= queue_depth)
39436 return;
39437 @@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39438 unsigned long num_rsrc_err, num_cmd_success;
39439 int i;
39440
39441 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
39442 - num_cmd_success = atomic_read(&phba->num_cmd_success);
39443 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
39444 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
39445
39446 /*
39447 * The error and success command counters are global per
39448 @@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
39449 }
39450 }
39451 lpfc_destroy_vport_work_array(phba, vports);
39452 - atomic_set(&phba->num_rsrc_err, 0);
39453 - atomic_set(&phba->num_cmd_success, 0);
39454 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
39455 + atomic_set_unchecked(&phba->num_cmd_success, 0);
39456 }
39457
39458 /**
39459 @@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
39460 }
39461 }
39462 lpfc_destroy_vport_work_array(phba, vports);
39463 - atomic_set(&phba->num_rsrc_err, 0);
39464 - atomic_set(&phba->num_cmd_success, 0);
39465 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
39466 + atomic_set_unchecked(&phba->num_cmd_success, 0);
39467 }
39468
39469 /**
39470 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
39471 index b46f5e9..c4c4ccb 100644
39472 --- a/drivers/scsi/pmcraid.c
39473 +++ b/drivers/scsi/pmcraid.c
39474 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
39475 res->scsi_dev = scsi_dev;
39476 scsi_dev->hostdata = res;
39477 res->change_detected = 0;
39478 - atomic_set(&res->read_failures, 0);
39479 - atomic_set(&res->write_failures, 0);
39480 + atomic_set_unchecked(&res->read_failures, 0);
39481 + atomic_set_unchecked(&res->write_failures, 0);
39482 rc = 0;
39483 }
39484 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
39485 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
39486
39487 /* If this was a SCSI read/write command keep count of errors */
39488 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
39489 - atomic_inc(&res->read_failures);
39490 + atomic_inc_unchecked(&res->read_failures);
39491 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
39492 - atomic_inc(&res->write_failures);
39493 + atomic_inc_unchecked(&res->write_failures);
39494
39495 if (!RES_IS_GSCSI(res->cfg_entry) &&
39496 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
39497 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
39498 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39499 * hrrq_id assigned here in queuecommand
39500 */
39501 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39502 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39503 pinstance->num_hrrq;
39504 cmd->cmd_done = pmcraid_io_done;
39505
39506 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
39507 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
39508 * hrrq_id assigned here in queuecommand
39509 */
39510 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
39511 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
39512 pinstance->num_hrrq;
39513
39514 if (request_size) {
39515 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
39516
39517 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
39518 /* add resources only after host is added into system */
39519 - if (!atomic_read(&pinstance->expose_resources))
39520 + if (!atomic_read_unchecked(&pinstance->expose_resources))
39521 return;
39522
39523 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
39524 @@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
39525 init_waitqueue_head(&pinstance->reset_wait_q);
39526
39527 atomic_set(&pinstance->outstanding_cmds, 0);
39528 - atomic_set(&pinstance->last_message_id, 0);
39529 - atomic_set(&pinstance->expose_resources, 0);
39530 + atomic_set_unchecked(&pinstance->last_message_id, 0);
39531 + atomic_set_unchecked(&pinstance->expose_resources, 0);
39532
39533 INIT_LIST_HEAD(&pinstance->free_res_q);
39534 INIT_LIST_HEAD(&pinstance->used_res_q);
39535 @@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
39536 /* Schedule worker thread to handle CCN and take care of adding and
39537 * removing devices to OS
39538 */
39539 - atomic_set(&pinstance->expose_resources, 1);
39540 + atomic_set_unchecked(&pinstance->expose_resources, 1);
39541 schedule_work(&pinstance->worker_q);
39542 return rc;
39543
39544 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
39545 index e1d150f..6c6df44 100644
39546 --- a/drivers/scsi/pmcraid.h
39547 +++ b/drivers/scsi/pmcraid.h
39548 @@ -748,7 +748,7 @@ struct pmcraid_instance {
39549 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
39550
39551 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
39552 - atomic_t last_message_id;
39553 + atomic_unchecked_t last_message_id;
39554
39555 /* configuration table */
39556 struct pmcraid_config_table *cfg_table;
39557 @@ -777,7 +777,7 @@ struct pmcraid_instance {
39558 atomic_t outstanding_cmds;
39559
39560 /* should add/delete resources to mid-layer now ?*/
39561 - atomic_t expose_resources;
39562 + atomic_unchecked_t expose_resources;
39563
39564
39565
39566 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
39567 struct pmcraid_config_table_entry_ext cfg_entry_ext;
39568 };
39569 struct scsi_device *scsi_dev; /* Link scsi_device structure */
39570 - atomic_t read_failures; /* count of failed READ commands */
39571 - atomic_t write_failures; /* count of failed WRITE commands */
39572 + atomic_unchecked_t read_failures; /* count of failed READ commands */
39573 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
39574
39575 /* To indicate add/delete/modify during CCN */
39576 u8 change_detected;
39577 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
39578 index 83d7984..a27d947 100644
39579 --- a/drivers/scsi/qla2xxx/qla_attr.c
39580 +++ b/drivers/scsi/qla2xxx/qla_attr.c
39581 @@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
39582 return 0;
39583 }
39584
39585 -struct fc_function_template qla2xxx_transport_functions = {
39586 +fc_function_template_no_const qla2xxx_transport_functions = {
39587
39588 .show_host_node_name = 1,
39589 .show_host_port_name = 1,
39590 @@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
39591 .bsg_timeout = qla24xx_bsg_timeout,
39592 };
39593
39594 -struct fc_function_template qla2xxx_transport_vport_functions = {
39595 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
39596
39597 .show_host_node_name = 1,
39598 .show_host_port_name = 1,
39599 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
39600 index 2411d1a..4673766 100644
39601 --- a/drivers/scsi/qla2xxx/qla_gbl.h
39602 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
39603 @@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
39604 struct device_attribute;
39605 extern struct device_attribute *qla2x00_host_attrs[];
39606 struct fc_function_template;
39607 -extern struct fc_function_template qla2xxx_transport_functions;
39608 -extern struct fc_function_template qla2xxx_transport_vport_functions;
39609 +extern fc_function_template_no_const qla2xxx_transport_functions;
39610 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
39611 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
39612 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
39613 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
39614 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
39615 index 10d23f8..a7d5d4c 100644
39616 --- a/drivers/scsi/qla2xxx/qla_os.c
39617 +++ b/drivers/scsi/qla2xxx/qla_os.c
39618 @@ -1472,8 +1472,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
39619 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
39620 /* Ok, a 64bit DMA mask is applicable. */
39621 ha->flags.enable_64bit_addressing = 1;
39622 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39623 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39624 + pax_open_kernel();
39625 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
39626 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
39627 + pax_close_kernel();
39628 return;
39629 }
39630 }
39631 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
39632 index 329d553..f20d31d 100644
39633 --- a/drivers/scsi/qla4xxx/ql4_def.h
39634 +++ b/drivers/scsi/qla4xxx/ql4_def.h
39635 @@ -273,7 +273,7 @@ struct ddb_entry {
39636 * (4000 only) */
39637 atomic_t relogin_timer; /* Max Time to wait for
39638 * relogin to complete */
39639 - atomic_t relogin_retry_count; /* Num of times relogin has been
39640 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
39641 * retried */
39642 uint32_t default_time2wait; /* Default Min time between
39643 * relogins (+aens) */
39644 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
39645 index 4cec123..7c1329f 100644
39646 --- a/drivers/scsi/qla4xxx/ql4_os.c
39647 +++ b/drivers/scsi/qla4xxx/ql4_os.c
39648 @@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
39649 */
39650 if (!iscsi_is_session_online(cls_sess)) {
39651 /* Reset retry relogin timer */
39652 - atomic_inc(&ddb_entry->relogin_retry_count);
39653 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
39654 DEBUG2(ql4_printk(KERN_INFO, ha,
39655 "%s: index[%d] relogin timed out-retrying"
39656 " relogin (%d), retry (%d)\n", __func__,
39657 ddb_entry->fw_ddb_index,
39658 - atomic_read(&ddb_entry->relogin_retry_count),
39659 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
39660 ddb_entry->default_time2wait + 4));
39661 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
39662 atomic_set(&ddb_entry->retry_relogin_timer,
39663 @@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
39664
39665 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
39666 atomic_set(&ddb_entry->relogin_timer, 0);
39667 - atomic_set(&ddb_entry->relogin_retry_count, 0);
39668 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
39669 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
39670 ddb_entry->default_relogin_timeout =
39671 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
39672 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
39673 index 2c0d0ec..4e8681a 100644
39674 --- a/drivers/scsi/scsi.c
39675 +++ b/drivers/scsi/scsi.c
39676 @@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
39677 unsigned long timeout;
39678 int rtn = 0;
39679
39680 - atomic_inc(&cmd->device->iorequest_cnt);
39681 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39682
39683 /* check if the device is still usable */
39684 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
39685 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
39686 index f1bf5af..f67e943 100644
39687 --- a/drivers/scsi/scsi_lib.c
39688 +++ b/drivers/scsi/scsi_lib.c
39689 @@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
39690 shost = sdev->host;
39691 scsi_init_cmd_errh(cmd);
39692 cmd->result = DID_NO_CONNECT << 16;
39693 - atomic_inc(&cmd->device->iorequest_cnt);
39694 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
39695
39696 /*
39697 * SCSI request completion path will do scsi_device_unbusy(),
39698 @@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
39699
39700 INIT_LIST_HEAD(&cmd->eh_entry);
39701
39702 - atomic_inc(&cmd->device->iodone_cnt);
39703 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
39704 if (cmd->result)
39705 - atomic_inc(&cmd->device->ioerr_cnt);
39706 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
39707
39708 disposition = scsi_decide_disposition(cmd);
39709 if (disposition != SUCCESS &&
39710 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
39711 index 931a7d9..0c2a754 100644
39712 --- a/drivers/scsi/scsi_sysfs.c
39713 +++ b/drivers/scsi/scsi_sysfs.c
39714 @@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
39715 char *buf) \
39716 { \
39717 struct scsi_device *sdev = to_scsi_device(dev); \
39718 - unsigned long long count = atomic_read(&sdev->field); \
39719 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
39720 return snprintf(buf, 20, "0x%llx\n", count); \
39721 } \
39722 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
39723 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
39724 index 84a1fdf..693b0d6 100644
39725 --- a/drivers/scsi/scsi_tgt_lib.c
39726 +++ b/drivers/scsi/scsi_tgt_lib.c
39727 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
39728 int err;
39729
39730 dprintk("%lx %u\n", uaddr, len);
39731 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
39732 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
39733 if (err) {
39734 /*
39735 * TODO: need to fixup sg_tablesize, max_segment_size,
39736 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
39737 index e894ca7..de9d7660 100644
39738 --- a/drivers/scsi/scsi_transport_fc.c
39739 +++ b/drivers/scsi/scsi_transport_fc.c
39740 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
39741 * Netlink Infrastructure
39742 */
39743
39744 -static atomic_t fc_event_seq;
39745 +static atomic_unchecked_t fc_event_seq;
39746
39747 /**
39748 * fc_get_event_number - Obtain the next sequential FC event number
39749 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
39750 u32
39751 fc_get_event_number(void)
39752 {
39753 - return atomic_add_return(1, &fc_event_seq);
39754 + return atomic_add_return_unchecked(1, &fc_event_seq);
39755 }
39756 EXPORT_SYMBOL(fc_get_event_number);
39757
39758 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
39759 {
39760 int error;
39761
39762 - atomic_set(&fc_event_seq, 0);
39763 + atomic_set_unchecked(&fc_event_seq, 0);
39764
39765 error = transport_class_register(&fc_host_class);
39766 if (error)
39767 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
39768 char *cp;
39769
39770 *val = simple_strtoul(buf, &cp, 0);
39771 - if ((*cp && (*cp != '\n')) || (*val < 0))
39772 + if (*cp && (*cp != '\n'))
39773 return -EINVAL;
39774 /*
39775 * Check for overflow; dev_loss_tmo is u32
39776 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
39777 index 31969f2..2b348f0 100644
39778 --- a/drivers/scsi/scsi_transport_iscsi.c
39779 +++ b/drivers/scsi/scsi_transport_iscsi.c
39780 @@ -79,7 +79,7 @@ struct iscsi_internal {
39781 struct transport_container session_cont;
39782 };
39783
39784 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
39785 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
39786 static struct workqueue_struct *iscsi_eh_timer_workq;
39787
39788 static DEFINE_IDA(iscsi_sess_ida);
39789 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
39790 int err;
39791
39792 ihost = shost->shost_data;
39793 - session->sid = atomic_add_return(1, &iscsi_session_nr);
39794 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
39795
39796 if (target_id == ISCSI_MAX_TARGET) {
39797 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
39798 @@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
39799 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
39800 ISCSI_TRANSPORT_VERSION);
39801
39802 - atomic_set(&iscsi_session_nr, 0);
39803 + atomic_set_unchecked(&iscsi_session_nr, 0);
39804
39805 err = class_register(&iscsi_transport_class);
39806 if (err)
39807 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
39808 index f379c7f..e8fc69c 100644
39809 --- a/drivers/scsi/scsi_transport_srp.c
39810 +++ b/drivers/scsi/scsi_transport_srp.c
39811 @@ -33,7 +33,7 @@
39812 #include "scsi_transport_srp_internal.h"
39813
39814 struct srp_host_attrs {
39815 - atomic_t next_port_id;
39816 + atomic_unchecked_t next_port_id;
39817 };
39818 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
39819
39820 @@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
39821 struct Scsi_Host *shost = dev_to_shost(dev);
39822 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
39823
39824 - atomic_set(&srp_host->next_port_id, 0);
39825 + atomic_set_unchecked(&srp_host->next_port_id, 0);
39826 return 0;
39827 }
39828
39829 @@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
39830 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
39831 rport->roles = ids->roles;
39832
39833 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
39834 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
39835 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
39836
39837 transport_setup_device(&rport->dev);
39838 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
39839 index 7992635..609faf8 100644
39840 --- a/drivers/scsi/sd.c
39841 +++ b/drivers/scsi/sd.c
39842 @@ -2909,7 +2909,7 @@ static int sd_probe(struct device *dev)
39843 sdkp->disk = gd;
39844 sdkp->index = index;
39845 atomic_set(&sdkp->openers, 0);
39846 - atomic_set(&sdkp->device->ioerr_cnt, 0);
39847 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
39848
39849 if (!sdp->request_queue->rq_timeout) {
39850 if (sdp->type != TYPE_MOD)
39851 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
39852 index be2c9a6..275525c 100644
39853 --- a/drivers/scsi/sg.c
39854 +++ b/drivers/scsi/sg.c
39855 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
39856 sdp->disk->disk_name,
39857 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
39858 NULL,
39859 - (char *)arg);
39860 + (char __user *)arg);
39861 case BLKTRACESTART:
39862 return blk_trace_startstop(sdp->device->request_queue, 1);
39863 case BLKTRACESTOP:
39864 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
39865 index 19ee901..6e8c2ef 100644
39866 --- a/drivers/spi/spi.c
39867 +++ b/drivers/spi/spi.c
39868 @@ -1616,7 +1616,7 @@ int spi_bus_unlock(struct spi_master *master)
39869 EXPORT_SYMBOL_GPL(spi_bus_unlock);
39870
39871 /* portable code must never pass more than 32 bytes */
39872 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
39873 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
39874
39875 static u8 *buf;
39876
39877 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
39878 index 34afc16..ffe44dd 100644
39879 --- a/drivers/staging/octeon/ethernet-rx.c
39880 +++ b/drivers/staging/octeon/ethernet-rx.c
39881 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39882 /* Increment RX stats for virtual ports */
39883 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
39884 #ifdef CONFIG_64BIT
39885 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
39886 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
39887 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
39888 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
39889 #else
39890 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
39891 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
39892 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
39893 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
39894 #endif
39895 }
39896 netif_receive_skb(skb);
39897 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
39898 dev->name);
39899 */
39900 #ifdef CONFIG_64BIT
39901 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
39902 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39903 #else
39904 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
39905 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
39906 #endif
39907 dev_kfree_skb_irq(skb);
39908 }
39909 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
39910 index ef32dc1..a159d68 100644
39911 --- a/drivers/staging/octeon/ethernet.c
39912 +++ b/drivers/staging/octeon/ethernet.c
39913 @@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
39914 * since the RX tasklet also increments it.
39915 */
39916 #ifdef CONFIG_64BIT
39917 - atomic64_add(rx_status.dropped_packets,
39918 - (atomic64_t *)&priv->stats.rx_dropped);
39919 + atomic64_add_unchecked(rx_status.dropped_packets,
39920 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
39921 #else
39922 - atomic_add(rx_status.dropped_packets,
39923 - (atomic_t *)&priv->stats.rx_dropped);
39924 + atomic_add_unchecked(rx_status.dropped_packets,
39925 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
39926 #endif
39927 }
39928
39929 diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
39930 index a2b7e03..aaf3630 100644
39931 --- a/drivers/staging/ramster/tmem.c
39932 +++ b/drivers/staging/ramster/tmem.c
39933 @@ -50,25 +50,25 @@
39934 * A tmem host implementation must use this function to register callbacks
39935 * for memory allocation.
39936 */
39937 -static struct tmem_hostops tmem_hostops;
39938 +static struct tmem_hostops *tmem_hostops;
39939
39940 static void tmem_objnode_tree_init(void);
39941
39942 void tmem_register_hostops(struct tmem_hostops *m)
39943 {
39944 tmem_objnode_tree_init();
39945 - tmem_hostops = *m;
39946 + tmem_hostops = m;
39947 }
39948
39949 /*
39950 * A tmem host implementation must use this function to register
39951 * callbacks for a page-accessible memory (PAM) implementation.
39952 */
39953 -static struct tmem_pamops tmem_pamops;
39954 +static struct tmem_pamops *tmem_pamops;
39955
39956 void tmem_register_pamops(struct tmem_pamops *m)
39957 {
39958 - tmem_pamops = *m;
39959 + tmem_pamops = m;
39960 }
39961
39962 /*
39963 @@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
39964 obj->pampd_count = 0;
39965 #ifdef CONFIG_RAMSTER
39966 if (tmem_pamops.new_obj != NULL)
39967 - (*tmem_pamops.new_obj)(obj);
39968 + (tmem_pamops->new_obj)(obj);
39969 #endif
39970 SET_SENTINEL(obj, OBJ);
39971
39972 @@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
39973 rbnode = rb_next(rbnode);
39974 tmem_pampd_destroy_all_in_obj(obj, true);
39975 tmem_obj_free(obj, hb);
39976 - (*tmem_hostops.obj_free)(obj, pool);
39977 + (tmem_hostops->obj_free)(obj, pool);
39978 }
39979 spin_unlock(&hb->lock);
39980 }
39981 @@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
39982 ASSERT_SENTINEL(obj, OBJ);
39983 BUG_ON(obj->pool == NULL);
39984 ASSERT_SENTINEL(obj->pool, POOL);
39985 - objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
39986 + objnode = (tmem_hostops->objnode_alloc)(obj->pool);
39987 if (unlikely(objnode == NULL))
39988 goto out;
39989 objnode->obj = obj;
39990 @@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
39991 ASSERT_SENTINEL(pool, POOL);
39992 objnode->obj->objnode_count--;
39993 objnode->obj = NULL;
39994 - (*tmem_hostops.objnode_free)(objnode, pool);
39995 + (tmem_hostops->objnode_free)(objnode, pool);
39996 }
39997
39998 /*
39999 @@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
40000 void *old_pampd = *(void **)slot;
40001 *(void **)slot = new_pampd;
40002 if (!no_free)
40003 - (*tmem_pamops.free)(old_pampd, obj->pool,
40004 + (tmem_pamops->free)(old_pampd, obj->pool,
40005 NULL, 0, false);
40006 ret = new_pampd;
40007 }
40008 @@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
40009 if (objnode->slots[i]) {
40010 if (ht == 1) {
40011 obj->pampd_count--;
40012 - (*tmem_pamops.free)(objnode->slots[i],
40013 + (tmem_pamops->free)(objnode->slots[i],
40014 obj->pool, NULL, 0, true);
40015 objnode->slots[i] = NULL;
40016 continue;
40017 @@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40018 return;
40019 if (obj->objnode_tree_height == 0) {
40020 obj->pampd_count--;
40021 - (*tmem_pamops.free)(obj->objnode_tree_root,
40022 + (tmem_pamops->free)(obj->objnode_tree_root,
40023 obj->pool, NULL, 0, true);
40024 } else {
40025 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
40026 @@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
40027 obj->objnode_tree_root = NULL;
40028 #ifdef CONFIG_RAMSTER
40029 if (tmem_pamops.free_obj != NULL)
40030 - (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
40031 + (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
40032 #endif
40033 }
40034
40035 @@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40036 /* if found, is a dup put, flush the old one */
40037 pampd_del = tmem_pampd_delete_from_obj(obj, index);
40038 BUG_ON(pampd_del != pampd);
40039 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40040 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
40041 if (obj->pampd_count == 0) {
40042 objnew = obj;
40043 objfound = NULL;
40044 @@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40045 pampd = NULL;
40046 }
40047 } else {
40048 - obj = objnew = (*tmem_hostops.obj_alloc)(pool);
40049 + obj = objnew = (tmem_hostops->obj_alloc)(pool);
40050 if (unlikely(obj == NULL)) {
40051 ret = -ENOMEM;
40052 goto out;
40053 @@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40054 if (unlikely(ret == -ENOMEM))
40055 /* may have partially built objnode tree ("stump") */
40056 goto delete_and_free;
40057 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
40058 + (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
40059 goto out;
40060
40061 delete_and_free:
40062 (void)tmem_pampd_delete_from_obj(obj, index);
40063 if (pampd)
40064 - (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
40065 + (tmem_pamops->free)(pampd, pool, NULL, 0, true);
40066 if (objnew) {
40067 tmem_obj_free(objnew, hb);
40068 - (*tmem_hostops.obj_free)(objnew, pool);
40069 + (tmem_hostops->obj_free)(objnew, pool);
40070 }
40071 out:
40072 spin_unlock(&hb->lock);
40073 @@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
40074 if (pampd != NULL) {
40075 BUG_ON(obj == NULL);
40076 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
40077 - (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
40078 + (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
40079 } else if (delete) {
40080 BUG_ON(obj == NULL);
40081 (void)tmem_pampd_delete_from_obj(obj, index);
40082 @@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40083 int ret = 0;
40084
40085 if (!is_ephemeral(pool))
40086 - new_pampd = (*tmem_pamops.repatriate_preload)(
40087 + new_pampd = (tmem_pamops->repatriate_preload)(
40088 old_pampd, pool, oidp, index, &intransit);
40089 if (intransit)
40090 ret = -EAGAIN;
40091 @@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
40092 /* must release the hb->lock else repatriate can't sleep */
40093 spin_unlock(&hb->lock);
40094 if (!intransit)
40095 - ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
40096 + ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
40097 oidp, index, free, data);
40098 if (ret == -EAGAIN) {
40099 /* rare I think, but should cond_resched()??? */
40100 @@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
40101 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
40102 /* if we bug here, pamops wasn't properly set up for ramster */
40103 BUG_ON(tmem_pamops.replace_in_obj == NULL);
40104 - ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
40105 + ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
40106 out:
40107 spin_unlock(&hb->lock);
40108 return ret;
40109 @@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
40110 if (free) {
40111 if (obj->pampd_count == 0) {
40112 tmem_obj_free(obj, hb);
40113 - (*tmem_hostops.obj_free)(obj, pool);
40114 + (tmem_hostops->obj_free)(obj, pool);
40115 obj = NULL;
40116 }
40117 }
40118 if (free)
40119 - ret = (*tmem_pamops.get_data_and_free)(
40120 + ret = (tmem_pamops->get_data_and_free)(
40121 data, sizep, raw, pampd, pool, oidp, index);
40122 else
40123 - ret = (*tmem_pamops.get_data)(
40124 + ret = (tmem_pamops->get_data)(
40125 data, sizep, raw, pampd, pool, oidp, index);
40126 if (ret < 0)
40127 goto out;
40128 @@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
40129 pampd = tmem_pampd_delete_from_obj(obj, index);
40130 if (pampd == NULL)
40131 goto out;
40132 - (*tmem_pamops.free)(pampd, pool, oidp, index, true);
40133 + (tmem_pamops->free)(pampd, pool, oidp, index, true);
40134 if (obj->pampd_count == 0) {
40135 tmem_obj_free(obj, hb);
40136 - (*tmem_hostops.obj_free)(obj, pool);
40137 + (tmem_hostops->obj_free)(obj, pool);
40138 }
40139 ret = 0;
40140
40141 @@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
40142 goto out;
40143 tmem_pampd_destroy_all_in_obj(obj, false);
40144 tmem_obj_free(obj, hb);
40145 - (*tmem_hostops.obj_free)(obj, pool);
40146 + (tmem_hostops->obj_free)(obj, pool);
40147 ret = 0;
40148
40149 out:
40150 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
40151 index dc23395..cf7e9b1 100644
40152 --- a/drivers/staging/rtl8712/rtl871x_io.h
40153 +++ b/drivers/staging/rtl8712/rtl871x_io.h
40154 @@ -108,7 +108,7 @@ struct _io_ops {
40155 u8 *pmem);
40156 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
40157 u8 *pmem);
40158 -};
40159 +} __no_const;
40160
40161 struct io_req {
40162 struct list_head list;
40163 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
40164 index 1f5088b..0e59820 100644
40165 --- a/drivers/staging/sbe-2t3e3/netdev.c
40166 +++ b/drivers/staging/sbe-2t3e3/netdev.c
40167 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40168 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
40169
40170 if (rlen)
40171 - if (copy_to_user(data, &resp, rlen))
40172 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
40173 return -EFAULT;
40174
40175 return 0;
40176 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
40177 index 5dddc4d..34fcb2f 100644
40178 --- a/drivers/staging/usbip/vhci.h
40179 +++ b/drivers/staging/usbip/vhci.h
40180 @@ -83,7 +83,7 @@ struct vhci_hcd {
40181 unsigned resuming:1;
40182 unsigned long re_timeout;
40183
40184 - atomic_t seqnum;
40185 + atomic_unchecked_t seqnum;
40186
40187 /*
40188 * NOTE:
40189 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
40190 index c3aa219..bf8b3de 100644
40191 --- a/drivers/staging/usbip/vhci_hcd.c
40192 +++ b/drivers/staging/usbip/vhci_hcd.c
40193 @@ -451,7 +451,7 @@ static void vhci_tx_urb(struct urb *urb)
40194 return;
40195 }
40196
40197 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
40198 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40199 if (priv->seqnum == 0xffff)
40200 dev_info(&urb->dev->dev, "seqnum max\n");
40201
40202 @@ -703,7 +703,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
40203 return -ENOMEM;
40204 }
40205
40206 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
40207 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
40208 if (unlink->seqnum == 0xffff)
40209 pr_info("seqnum max\n");
40210
40211 @@ -907,7 +907,7 @@ static int vhci_start(struct usb_hcd *hcd)
40212 vdev->rhport = rhport;
40213 }
40214
40215 - atomic_set(&vhci->seqnum, 0);
40216 + atomic_set_unchecked(&vhci->seqnum, 0);
40217 spin_lock_init(&vhci->lock);
40218
40219 hcd->power_budget = 0; /* no limit */
40220 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
40221 index ba5f1c0..11d8122 100644
40222 --- a/drivers/staging/usbip/vhci_rx.c
40223 +++ b/drivers/staging/usbip/vhci_rx.c
40224 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
40225 if (!urb) {
40226 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
40227 pr_info("max seqnum %d\n",
40228 - atomic_read(&the_controller->seqnum));
40229 + atomic_read_unchecked(&the_controller->seqnum));
40230 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
40231 return;
40232 }
40233 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
40234 index 5f13890..36a044b 100644
40235 --- a/drivers/staging/vt6655/hostap.c
40236 +++ b/drivers/staging/vt6655/hostap.c
40237 @@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
40238 *
40239 */
40240
40241 +static net_device_ops_no_const apdev_netdev_ops;
40242 +
40243 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40244 {
40245 PSDevice apdev_priv;
40246 struct net_device *dev = pDevice->dev;
40247 int ret;
40248 - const struct net_device_ops apdev_netdev_ops = {
40249 - .ndo_start_xmit = pDevice->tx_80211,
40250 - };
40251
40252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40253
40254 @@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40255 *apdev_priv = *pDevice;
40256 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40257
40258 + /* only half broken now */
40259 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40260 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40261
40262 pDevice->apdev->type = ARPHRD_IEEE80211;
40263 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
40264 index 26a7d0e..897b083 100644
40265 --- a/drivers/staging/vt6656/hostap.c
40266 +++ b/drivers/staging/vt6656/hostap.c
40267 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
40268 *
40269 */
40270
40271 +static net_device_ops_no_const apdev_netdev_ops;
40272 +
40273 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40274 {
40275 PSDevice apdev_priv;
40276 struct net_device *dev = pDevice->dev;
40277 int ret;
40278 - const struct net_device_ops apdev_netdev_ops = {
40279 - .ndo_start_xmit = pDevice->tx_80211,
40280 - };
40281
40282 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
40283
40284 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
40285 *apdev_priv = *pDevice;
40286 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
40287
40288 + /* only half broken now */
40289 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
40290 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
40291
40292 pDevice->apdev->type = ARPHRD_IEEE80211;
40293 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
40294 index 56c8e60..1920c63 100644
40295 --- a/drivers/staging/zcache/tmem.c
40296 +++ b/drivers/staging/zcache/tmem.c
40297 @@ -39,7 +39,7 @@
40298 * A tmem host implementation must use this function to register callbacks
40299 * for memory allocation.
40300 */
40301 -static struct tmem_hostops tmem_hostops;
40302 +static tmem_hostops_no_const tmem_hostops;
40303
40304 static void tmem_objnode_tree_init(void);
40305
40306 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
40307 * A tmem host implementation must use this function to register
40308 * callbacks for a page-accessible memory (PAM) implementation
40309 */
40310 -static struct tmem_pamops tmem_pamops;
40311 +static tmem_pamops_no_const tmem_pamops;
40312
40313 void tmem_register_pamops(struct tmem_pamops *m)
40314 {
40315 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
40316 index 0d4aa82..f7832d4 100644
40317 --- a/drivers/staging/zcache/tmem.h
40318 +++ b/drivers/staging/zcache/tmem.h
40319 @@ -180,6 +180,7 @@ struct tmem_pamops {
40320 void (*new_obj)(struct tmem_obj *);
40321 int (*replace_in_obj)(void *, struct tmem_obj *);
40322 };
40323 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
40324 extern void tmem_register_pamops(struct tmem_pamops *m);
40325
40326 /* memory allocation methods provided by the host implementation */
40327 @@ -189,6 +190,7 @@ struct tmem_hostops {
40328 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
40329 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
40330 };
40331 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
40332 extern void tmem_register_hostops(struct tmem_hostops *m);
40333
40334 /* core tmem accessor functions */
40335 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
40336 index f2aa754..11337b1 100644
40337 --- a/drivers/target/target_core_device.c
40338 +++ b/drivers/target/target_core_device.c
40339 @@ -1375,7 +1375,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
40340 spin_lock_init(&dev->se_port_lock);
40341 spin_lock_init(&dev->se_tmr_lock);
40342 spin_lock_init(&dev->qf_cmd_lock);
40343 - atomic_set(&dev->dev_ordered_id, 0);
40344 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
40345 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
40346 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
40347 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
40348 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
40349 index bd587b7..173daf3 100644
40350 --- a/drivers/target/target_core_transport.c
40351 +++ b/drivers/target/target_core_transport.c
40352 @@ -1077,7 +1077,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
40353 * Used to determine when ORDERED commands should go from
40354 * Dormant to Active status.
40355 */
40356 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
40357 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
40358 smp_mb__after_atomic_inc();
40359 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
40360 cmd->se_ordered_id, cmd->sam_task_attr,
40361 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
40362 index b09c8d1f..c4225c0 100644
40363 --- a/drivers/tty/cyclades.c
40364 +++ b/drivers/tty/cyclades.c
40365 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
40366 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
40367 info->port.count);
40368 #endif
40369 - info->port.count++;
40370 + atomic_inc(&info->port.count);
40371 #ifdef CY_DEBUG_COUNT
40372 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
40373 - current->pid, info->port.count);
40374 + current->pid, atomic_read(&info->port.count));
40375 #endif
40376
40377 /*
40378 @@ -3991,7 +3991,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
40379 for (j = 0; j < cy_card[i].nports; j++) {
40380 info = &cy_card[i].ports[j];
40381
40382 - if (info->port.count) {
40383 + if (atomic_read(&info->port.count)) {
40384 /* XXX is the ldisc num worth this? */
40385 struct tty_struct *tty;
40386 struct tty_ldisc *ld;
40387 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
40388 index 13ee53b..418d164 100644
40389 --- a/drivers/tty/hvc/hvc_console.c
40390 +++ b/drivers/tty/hvc/hvc_console.c
40391 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
40392
40393 spin_lock_irqsave(&hp->port.lock, flags);
40394 /* Check and then increment for fast path open. */
40395 - if (hp->port.count++ > 0) {
40396 + if (atomic_inc_return(&hp->port.count) > 1) {
40397 spin_unlock_irqrestore(&hp->port.lock, flags);
40398 hvc_kick();
40399 return 0;
40400 @@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40401
40402 spin_lock_irqsave(&hp->port.lock, flags);
40403
40404 - if (--hp->port.count == 0) {
40405 + if (atomic_dec_return(&hp->port.count) == 0) {
40406 spin_unlock_irqrestore(&hp->port.lock, flags);
40407 /* We are done with the tty pointer now. */
40408 tty_port_tty_set(&hp->port, NULL);
40409 @@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
40410 */
40411 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
40412 } else {
40413 - if (hp->port.count < 0)
40414 + if (atomic_read(&hp->port.count) < 0)
40415 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
40416 - hp->vtermno, hp->port.count);
40417 + hp->vtermno, atomic_read(&hp->port.count));
40418 spin_unlock_irqrestore(&hp->port.lock, flags);
40419 }
40420 }
40421 @@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
40422 * open->hangup case this can be called after the final close so prevent
40423 * that from happening for now.
40424 */
40425 - if (hp->port.count <= 0) {
40426 + if (atomic_read(&hp->port.count) <= 0) {
40427 spin_unlock_irqrestore(&hp->port.lock, flags);
40428 return;
40429 }
40430
40431 - hp->port.count = 0;
40432 + atomic_set(&hp->port.count, 0);
40433 spin_unlock_irqrestore(&hp->port.lock, flags);
40434 tty_port_tty_set(&hp->port, NULL);
40435
40436 @@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
40437 return -EPIPE;
40438
40439 /* FIXME what's this (unprotected) check for? */
40440 - if (hp->port.count <= 0)
40441 + if (atomic_read(&hp->port.count) <= 0)
40442 return -EIO;
40443
40444 spin_lock_irqsave(&hp->lock, flags);
40445 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
40446 index 8776357..b2d4afd 100644
40447 --- a/drivers/tty/hvc/hvcs.c
40448 +++ b/drivers/tty/hvc/hvcs.c
40449 @@ -83,6 +83,7 @@
40450 #include <asm/hvcserver.h>
40451 #include <asm/uaccess.h>
40452 #include <asm/vio.h>
40453 +#include <asm/local.h>
40454
40455 /*
40456 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
40457 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
40458
40459 spin_lock_irqsave(&hvcsd->lock, flags);
40460
40461 - if (hvcsd->port.count > 0) {
40462 + if (atomic_read(&hvcsd->port.count) > 0) {
40463 spin_unlock_irqrestore(&hvcsd->lock, flags);
40464 printk(KERN_INFO "HVCS: vterm state unchanged. "
40465 "The hvcs device node is still in use.\n");
40466 @@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
40467 }
40468 }
40469
40470 - hvcsd->port.count = 0;
40471 + atomic_set(&hvcsd->port.count, 0);
40472 hvcsd->port.tty = tty;
40473 tty->driver_data = hvcsd;
40474
40475 @@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
40476 unsigned long flags;
40477
40478 spin_lock_irqsave(&hvcsd->lock, flags);
40479 - hvcsd->port.count++;
40480 + atomic_inc(&hvcsd->port.count);
40481 hvcsd->todo_mask |= HVCS_SCHED_READ;
40482 spin_unlock_irqrestore(&hvcsd->lock, flags);
40483
40484 @@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40485 hvcsd = tty->driver_data;
40486
40487 spin_lock_irqsave(&hvcsd->lock, flags);
40488 - if (--hvcsd->port.count == 0) {
40489 + if (atomic_dec_and_test(&hvcsd->port.count)) {
40490
40491 vio_disable_interrupts(hvcsd->vdev);
40492
40493 @@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
40494
40495 free_irq(irq, hvcsd);
40496 return;
40497 - } else if (hvcsd->port.count < 0) {
40498 + } else if (atomic_read(&hvcsd->port.count) < 0) {
40499 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
40500 " is missmanaged.\n",
40501 - hvcsd->vdev->unit_address, hvcsd->port.count);
40502 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
40503 }
40504
40505 spin_unlock_irqrestore(&hvcsd->lock, flags);
40506 @@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40507
40508 spin_lock_irqsave(&hvcsd->lock, flags);
40509 /* Preserve this so that we know how many kref refs to put */
40510 - temp_open_count = hvcsd->port.count;
40511 + temp_open_count = atomic_read(&hvcsd->port.count);
40512
40513 /*
40514 * Don't kref put inside the spinlock because the destruction
40515 @@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
40516 tty->driver_data = NULL;
40517 hvcsd->port.tty = NULL;
40518
40519 - hvcsd->port.count = 0;
40520 + atomic_set(&hvcsd->port.count, 0);
40521
40522 /* This will drop any buffered data on the floor which is OK in a hangup
40523 * scenario. */
40524 @@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
40525 * the middle of a write operation? This is a crummy place to do this
40526 * but we want to keep it all in the spinlock.
40527 */
40528 - if (hvcsd->port.count <= 0) {
40529 + if (atomic_read(&hvcsd->port.count) <= 0) {
40530 spin_unlock_irqrestore(&hvcsd->lock, flags);
40531 return -ENODEV;
40532 }
40533 @@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
40534 {
40535 struct hvcs_struct *hvcsd = tty->driver_data;
40536
40537 - if (!hvcsd || hvcsd->port.count <= 0)
40538 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
40539 return 0;
40540
40541 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
40542 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
40543 index 2cde13d..645d78f 100644
40544 --- a/drivers/tty/ipwireless/tty.c
40545 +++ b/drivers/tty/ipwireless/tty.c
40546 @@ -29,6 +29,7 @@
40547 #include <linux/tty_driver.h>
40548 #include <linux/tty_flip.h>
40549 #include <linux/uaccess.h>
40550 +#include <asm/local.h>
40551
40552 #include "tty.h"
40553 #include "network.h"
40554 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40555 mutex_unlock(&tty->ipw_tty_mutex);
40556 return -ENODEV;
40557 }
40558 - if (tty->port.count == 0)
40559 + if (atomic_read(&tty->port.count) == 0)
40560 tty->tx_bytes_queued = 0;
40561
40562 - tty->port.count++;
40563 + atomic_inc(&tty->port.count);
40564
40565 tty->port.tty = linux_tty;
40566 linux_tty->driver_data = tty;
40567 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
40568
40569 static void do_ipw_close(struct ipw_tty *tty)
40570 {
40571 - tty->port.count--;
40572 -
40573 - if (tty->port.count == 0) {
40574 + if (atomic_dec_return(&tty->port.count) == 0) {
40575 struct tty_struct *linux_tty = tty->port.tty;
40576
40577 if (linux_tty != NULL) {
40578 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
40579 return;
40580
40581 mutex_lock(&tty->ipw_tty_mutex);
40582 - if (tty->port.count == 0) {
40583 + if (atomic_read(&tty->port.count) == 0) {
40584 mutex_unlock(&tty->ipw_tty_mutex);
40585 return;
40586 }
40587 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
40588 return;
40589 }
40590
40591 - if (!tty->port.count) {
40592 + if (!atomic_read(&tty->port.count)) {
40593 mutex_unlock(&tty->ipw_tty_mutex);
40594 return;
40595 }
40596 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
40597 return -ENODEV;
40598
40599 mutex_lock(&tty->ipw_tty_mutex);
40600 - if (!tty->port.count) {
40601 + if (!atomic_read(&tty->port.count)) {
40602 mutex_unlock(&tty->ipw_tty_mutex);
40603 return -EINVAL;
40604 }
40605 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
40606 if (!tty)
40607 return -ENODEV;
40608
40609 - if (!tty->port.count)
40610 + if (!atomic_read(&tty->port.count))
40611 return -EINVAL;
40612
40613 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
40614 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
40615 if (!tty)
40616 return 0;
40617
40618 - if (!tty->port.count)
40619 + if (!atomic_read(&tty->port.count))
40620 return 0;
40621
40622 return tty->tx_bytes_queued;
40623 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
40624 if (!tty)
40625 return -ENODEV;
40626
40627 - if (!tty->port.count)
40628 + if (!atomic_read(&tty->port.count))
40629 return -EINVAL;
40630
40631 return get_control_lines(tty);
40632 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
40633 if (!tty)
40634 return -ENODEV;
40635
40636 - if (!tty->port.count)
40637 + if (!atomic_read(&tty->port.count))
40638 return -EINVAL;
40639
40640 return set_control_lines(tty, set, clear);
40641 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
40642 if (!tty)
40643 return -ENODEV;
40644
40645 - if (!tty->port.count)
40646 + if (!atomic_read(&tty->port.count))
40647 return -EINVAL;
40648
40649 /* FIXME: Exactly how is the tty object locked here .. */
40650 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
40651 * are gone */
40652 mutex_lock(&ttyj->ipw_tty_mutex);
40653 }
40654 - while (ttyj->port.count)
40655 + while (atomic_read(&ttyj->port.count))
40656 do_ipw_close(ttyj);
40657 ipwireless_disassociate_network_ttys(network,
40658 ttyj->channel_idx);
40659 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
40660 index f9d2850..b006f04 100644
40661 --- a/drivers/tty/moxa.c
40662 +++ b/drivers/tty/moxa.c
40663 @@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
40664 }
40665
40666 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
40667 - ch->port.count++;
40668 + atomic_inc(&ch->port.count);
40669 tty->driver_data = ch;
40670 tty_port_tty_set(&ch->port, tty);
40671 mutex_lock(&ch->port.mutex);
40672 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
40673 index dcc0430..040bef9 100644
40674 --- a/drivers/tty/n_gsm.c
40675 +++ b/drivers/tty/n_gsm.c
40676 @@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
40677 spin_lock_init(&dlci->lock);
40678 mutex_init(&dlci->mutex);
40679 dlci->fifo = &dlci->_fifo;
40680 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
40681 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
40682 kfree(dlci);
40683 return NULL;
40684 }
40685 @@ -2924,7 +2924,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
40686 struct gsm_dlci *dlci = tty->driver_data;
40687 struct tty_port *port = &dlci->port;
40688
40689 - port->count++;
40690 + atomic_inc(&port->count);
40691 dlci_get(dlci);
40692 dlci_get(dlci->gsm->dlci[0]);
40693 mux_get(dlci->gsm);
40694 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
40695 index 19083ef..6e34e97 100644
40696 --- a/drivers/tty/n_tty.c
40697 +++ b/drivers/tty/n_tty.c
40698 @@ -2196,6 +2196,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
40699 {
40700 *ops = tty_ldisc_N_TTY;
40701 ops->owner = NULL;
40702 - ops->refcount = ops->flags = 0;
40703 + atomic_set(&ops->refcount, 0);
40704 + ops->flags = 0;
40705 }
40706 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
40707 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
40708 index 79ff3a5..1fe9399 100644
40709 --- a/drivers/tty/pty.c
40710 +++ b/drivers/tty/pty.c
40711 @@ -791,8 +791,10 @@ static void __init unix98_pty_init(void)
40712 panic("Couldn't register Unix98 pts driver");
40713
40714 /* Now create the /dev/ptmx special device */
40715 + pax_open_kernel();
40716 tty_default_fops(&ptmx_fops);
40717 - ptmx_fops.open = ptmx_open;
40718 + *(void **)&ptmx_fops.open = ptmx_open;
40719 + pax_close_kernel();
40720
40721 cdev_init(&ptmx_cdev, &ptmx_fops);
40722 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
40723 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
40724 index e42009a..566a036 100644
40725 --- a/drivers/tty/rocket.c
40726 +++ b/drivers/tty/rocket.c
40727 @@ -925,7 +925,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40728 tty->driver_data = info;
40729 tty_port_tty_set(port, tty);
40730
40731 - if (port->count++ == 0) {
40732 + if (atomic_inc_return(&port->count) == 1) {
40733 atomic_inc(&rp_num_ports_open);
40734
40735 #ifdef ROCKET_DEBUG_OPEN
40736 @@ -934,7 +934,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
40737 #endif
40738 }
40739 #ifdef ROCKET_DEBUG_OPEN
40740 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
40741 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
40742 #endif
40743
40744 /*
40745 @@ -1529,7 +1529,7 @@ static void rp_hangup(struct tty_struct *tty)
40746 spin_unlock_irqrestore(&info->port.lock, flags);
40747 return;
40748 }
40749 - if (info->port.count)
40750 + if (atomic_read(&info->port.count))
40751 atomic_dec(&rp_num_ports_open);
40752 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
40753 spin_unlock_irqrestore(&info->port.lock, flags);
40754 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
40755 index 1002054..dd644a8 100644
40756 --- a/drivers/tty/serial/kgdboc.c
40757 +++ b/drivers/tty/serial/kgdboc.c
40758 @@ -24,8 +24,9 @@
40759 #define MAX_CONFIG_LEN 40
40760
40761 static struct kgdb_io kgdboc_io_ops;
40762 +static struct kgdb_io kgdboc_io_ops_console;
40763
40764 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
40765 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
40766 static int configured = -1;
40767
40768 static char config[MAX_CONFIG_LEN];
40769 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
40770 kgdboc_unregister_kbd();
40771 if (configured == 1)
40772 kgdb_unregister_io_module(&kgdboc_io_ops);
40773 + else if (configured == 2)
40774 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
40775 }
40776
40777 static int configure_kgdboc(void)
40778 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
40779 int err;
40780 char *cptr = config;
40781 struct console *cons;
40782 + int is_console = 0;
40783
40784 err = kgdboc_option_setup(config);
40785 if (err || !strlen(config) || isspace(config[0]))
40786 goto noconfig;
40787
40788 err = -ENODEV;
40789 - kgdboc_io_ops.is_console = 0;
40790 kgdb_tty_driver = NULL;
40791
40792 kgdboc_use_kms = 0;
40793 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
40794 int idx;
40795 if (cons->device && cons->device(cons, &idx) == p &&
40796 idx == tty_line) {
40797 - kgdboc_io_ops.is_console = 1;
40798 + is_console = 1;
40799 break;
40800 }
40801 cons = cons->next;
40802 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
40803 kgdb_tty_line = tty_line;
40804
40805 do_register:
40806 - err = kgdb_register_io_module(&kgdboc_io_ops);
40807 + if (is_console) {
40808 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
40809 + configured = 2;
40810 + } else {
40811 + err = kgdb_register_io_module(&kgdboc_io_ops);
40812 + configured = 1;
40813 + }
40814 if (err)
40815 goto noconfig;
40816
40817 @@ -205,8 +214,6 @@ do_register:
40818 if (err)
40819 goto nmi_con_failed;
40820
40821 - configured = 1;
40822 -
40823 return 0;
40824
40825 nmi_con_failed:
40826 @@ -223,7 +230,7 @@ noconfig:
40827 static int __init init_kgdboc(void)
40828 {
40829 /* Already configured? */
40830 - if (configured == 1)
40831 + if (configured >= 1)
40832 return 0;
40833
40834 return configure_kgdboc();
40835 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
40836 if (config[len - 1] == '\n')
40837 config[len - 1] = '\0';
40838
40839 - if (configured == 1)
40840 + if (configured >= 1)
40841 cleanup_kgdboc();
40842
40843 /* Go and configure with the new params. */
40844 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
40845 .post_exception = kgdboc_post_exp_handler,
40846 };
40847
40848 +static struct kgdb_io kgdboc_io_ops_console = {
40849 + .name = "kgdboc",
40850 + .read_char = kgdboc_get_char,
40851 + .write_char = kgdboc_put_char,
40852 + .pre_exception = kgdboc_pre_exp_handler,
40853 + .post_exception = kgdboc_post_exp_handler,
40854 + .is_console = 1
40855 +};
40856 +
40857 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
40858 /* This is only available if kgdboc is a built in for early debugging */
40859 static int __init kgdboc_early_init(char *opt)
40860 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
40861 index e514b3a..c73d614 100644
40862 --- a/drivers/tty/serial/samsung.c
40863 +++ b/drivers/tty/serial/samsung.c
40864 @@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
40865 }
40866 }
40867
40868 +static int s3c64xx_serial_startup(struct uart_port *port);
40869 static int s3c24xx_serial_startup(struct uart_port *port)
40870 {
40871 struct s3c24xx_uart_port *ourport = to_ourport(port);
40872 int ret;
40873
40874 + /* Startup sequence is different for s3c64xx and higher SoC's */
40875 + if (s3c24xx_serial_has_interrupt_mask(port))
40876 + return s3c64xx_serial_startup(port);
40877 +
40878 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
40879 port->mapbase, port->membase);
40880
40881 @@ -1122,10 +1127,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
40882 /* setup info for port */
40883 port->dev = &platdev->dev;
40884
40885 - /* Startup sequence is different for s3c64xx and higher SoC's */
40886 - if (s3c24xx_serial_has_interrupt_mask(port))
40887 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
40888 -
40889 port->uartclk = 1;
40890
40891 if (cfg->uart_flags & UPF_CONS_FLOW) {
40892 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
40893 index 2c7230a..2104f16 100644
40894 --- a/drivers/tty/serial/serial_core.c
40895 +++ b/drivers/tty/serial/serial_core.c
40896 @@ -1455,7 +1455,7 @@ static void uart_hangup(struct tty_struct *tty)
40897 uart_flush_buffer(tty);
40898 uart_shutdown(tty, state);
40899 spin_lock_irqsave(&port->lock, flags);
40900 - port->count = 0;
40901 + atomic_set(&port->count, 0);
40902 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
40903 spin_unlock_irqrestore(&port->lock, flags);
40904 tty_port_tty_set(port, NULL);
40905 @@ -1551,7 +1551,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40906 goto end;
40907 }
40908
40909 - port->count++;
40910 + atomic_inc(&port->count);
40911 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
40912 retval = -ENXIO;
40913 goto err_dec_count;
40914 @@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40915 /*
40916 * Make sure the device is in D0 state.
40917 */
40918 - if (port->count == 1)
40919 + if (atomic_read(&port->count) == 1)
40920 uart_change_pm(state, 0);
40921
40922 /*
40923 @@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
40924 end:
40925 return retval;
40926 err_dec_count:
40927 - port->count--;
40928 + atomic_inc(&port->count);
40929 mutex_unlock(&port->mutex);
40930 goto end;
40931 }
40932 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
40933 index 9e071f6..f30ae69 100644
40934 --- a/drivers/tty/synclink.c
40935 +++ b/drivers/tty/synclink.c
40936 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40937
40938 if (debug_level >= DEBUG_LEVEL_INFO)
40939 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
40940 - __FILE__,__LINE__, info->device_name, info->port.count);
40941 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40942
40943 if (tty_port_close_start(&info->port, tty, filp) == 0)
40944 goto cleanup;
40945 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
40946 cleanup:
40947 if (debug_level >= DEBUG_LEVEL_INFO)
40948 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
40949 - tty->driver->name, info->port.count);
40950 + tty->driver->name, atomic_read(&info->port.count));
40951
40952 } /* end of mgsl_close() */
40953
40954 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
40955
40956 mgsl_flush_buffer(tty);
40957 shutdown(info);
40958 -
40959 - info->port.count = 0;
40960 +
40961 + atomic_set(&info->port.count, 0);
40962 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40963 info->port.tty = NULL;
40964
40965 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40966
40967 if (debug_level >= DEBUG_LEVEL_INFO)
40968 printk("%s(%d):block_til_ready before block on %s count=%d\n",
40969 - __FILE__,__LINE__, tty->driver->name, port->count );
40970 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40971
40972 spin_lock_irqsave(&info->irq_spinlock, flags);
40973 if (!tty_hung_up_p(filp)) {
40974 extra_count = true;
40975 - port->count--;
40976 + atomic_dec(&port->count);
40977 }
40978 spin_unlock_irqrestore(&info->irq_spinlock, flags);
40979 port->blocked_open++;
40980 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40981
40982 if (debug_level >= DEBUG_LEVEL_INFO)
40983 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
40984 - __FILE__,__LINE__, tty->driver->name, port->count );
40985 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40986
40987 tty_unlock(tty);
40988 schedule();
40989 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
40990
40991 /* FIXME: Racy on hangup during close wait */
40992 if (extra_count)
40993 - port->count++;
40994 + atomic_inc(&port->count);
40995 port->blocked_open--;
40996
40997 if (debug_level >= DEBUG_LEVEL_INFO)
40998 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40999 - __FILE__,__LINE__, tty->driver->name, port->count );
41000 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41001
41002 if (!retval)
41003 port->flags |= ASYNC_NORMAL_ACTIVE;
41004 @@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41005
41006 if (debug_level >= DEBUG_LEVEL_INFO)
41007 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
41008 - __FILE__,__LINE__,tty->driver->name, info->port.count);
41009 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41010
41011 /* If port is closing, signal caller to try again */
41012 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41013 @@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
41014 spin_unlock_irqrestore(&info->netlock, flags);
41015 goto cleanup;
41016 }
41017 - info->port.count++;
41018 + atomic_inc(&info->port.count);
41019 spin_unlock_irqrestore(&info->netlock, flags);
41020
41021 - if (info->port.count == 1) {
41022 + if (atomic_read(&info->port.count) == 1) {
41023 /* 1st open on this device, init hardware */
41024 retval = startup(info);
41025 if (retval < 0)
41026 @@ -3451,8 +3451,8 @@ cleanup:
41027 if (retval) {
41028 if (tty->count == 1)
41029 info->port.tty = NULL; /* tty layer will release tty struct */
41030 - if(info->port.count)
41031 - info->port.count--;
41032 + if (atomic_read(&info->port.count))
41033 + atomic_dec(&info->port.count);
41034 }
41035
41036 return retval;
41037 @@ -7662,7 +7662,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41038 unsigned short new_crctype;
41039
41040 /* return error if TTY interface open */
41041 - if (info->port.count)
41042 + if (atomic_read(&info->port.count))
41043 return -EBUSY;
41044
41045 switch (encoding)
41046 @@ -7757,7 +7757,7 @@ static int hdlcdev_open(struct net_device *dev)
41047
41048 /* arbitrate between network and tty opens */
41049 spin_lock_irqsave(&info->netlock, flags);
41050 - if (info->port.count != 0 || info->netcount != 0) {
41051 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41052 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41053 spin_unlock_irqrestore(&info->netlock, flags);
41054 return -EBUSY;
41055 @@ -7843,7 +7843,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41056 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41057
41058 /* return error if TTY interface open */
41059 - if (info->port.count)
41060 + if (atomic_read(&info->port.count))
41061 return -EBUSY;
41062
41063 if (cmd != SIOCWANDEV)
41064 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
41065 index aba1e59..877ac33 100644
41066 --- a/drivers/tty/synclink_gt.c
41067 +++ b/drivers/tty/synclink_gt.c
41068 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41069 tty->driver_data = info;
41070 info->port.tty = tty;
41071
41072 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
41073 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
41074
41075 /* If port is closing, signal caller to try again */
41076 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41077 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41078 mutex_unlock(&info->port.mutex);
41079 goto cleanup;
41080 }
41081 - info->port.count++;
41082 + atomic_inc(&info->port.count);
41083 spin_unlock_irqrestore(&info->netlock, flags);
41084
41085 - if (info->port.count == 1) {
41086 + if (atomic_read(&info->port.count) == 1) {
41087 /* 1st open on this device, init hardware */
41088 retval = startup(info);
41089 if (retval < 0) {
41090 @@ -716,8 +716,8 @@ cleanup:
41091 if (retval) {
41092 if (tty->count == 1)
41093 info->port.tty = NULL; /* tty layer will release tty struct */
41094 - if(info->port.count)
41095 - info->port.count--;
41096 + if(atomic_read(&info->port.count))
41097 + atomic_dec(&info->port.count);
41098 }
41099
41100 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
41101 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41102
41103 if (sanity_check(info, tty->name, "close"))
41104 return;
41105 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
41106 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
41107
41108 if (tty_port_close_start(&info->port, tty, filp) == 0)
41109 goto cleanup;
41110 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41111 tty_port_close_end(&info->port, tty);
41112 info->port.tty = NULL;
41113 cleanup:
41114 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
41115 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
41116 }
41117
41118 static void hangup(struct tty_struct *tty)
41119 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
41120 shutdown(info);
41121
41122 spin_lock_irqsave(&info->port.lock, flags);
41123 - info->port.count = 0;
41124 + atomic_set(&info->port.count, 0);
41125 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41126 info->port.tty = NULL;
41127 spin_unlock_irqrestore(&info->port.lock, flags);
41128 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41129 unsigned short new_crctype;
41130
41131 /* return error if TTY interface open */
41132 - if (info->port.count)
41133 + if (atomic_read(&info->port.count))
41134 return -EBUSY;
41135
41136 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
41137 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
41138
41139 /* arbitrate between network and tty opens */
41140 spin_lock_irqsave(&info->netlock, flags);
41141 - if (info->port.count != 0 || info->netcount != 0) {
41142 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41143 DBGINFO(("%s hdlc_open busy\n", dev->name));
41144 spin_unlock_irqrestore(&info->netlock, flags);
41145 return -EBUSY;
41146 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41147 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
41148
41149 /* return error if TTY interface open */
41150 - if (info->port.count)
41151 + if (atomic_read(&info->port.count))
41152 return -EBUSY;
41153
41154 if (cmd != SIOCWANDEV)
41155 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
41156 if (port == NULL)
41157 continue;
41158 spin_lock(&port->lock);
41159 - if ((port->port.count || port->netcount) &&
41160 + if ((atomic_read(&port->port.count) || port->netcount) &&
41161 port->pending_bh && !port->bh_running &&
41162 !port->bh_requested) {
41163 DBGISR(("%s bh queued\n", port->device_name));
41164 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41165 spin_lock_irqsave(&info->lock, flags);
41166 if (!tty_hung_up_p(filp)) {
41167 extra_count = true;
41168 - port->count--;
41169 + atomic_dec(&port->count);
41170 }
41171 spin_unlock_irqrestore(&info->lock, flags);
41172 port->blocked_open++;
41173 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41174 remove_wait_queue(&port->open_wait, &wait);
41175
41176 if (extra_count)
41177 - port->count++;
41178 + atomic_inc(&port->count);
41179 port->blocked_open--;
41180
41181 if (!retval)
41182 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
41183 index fd43fb6..34704ad 100644
41184 --- a/drivers/tty/synclinkmp.c
41185 +++ b/drivers/tty/synclinkmp.c
41186 @@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
41187
41188 if (debug_level >= DEBUG_LEVEL_INFO)
41189 printk("%s(%d):%s open(), old ref count = %d\n",
41190 - __FILE__,__LINE__,tty->driver->name, info->port.count);
41191 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
41192
41193 /* If port is closing, signal caller to try again */
41194 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
41195 @@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
41196 spin_unlock_irqrestore(&info->netlock, flags);
41197 goto cleanup;
41198 }
41199 - info->port.count++;
41200 + atomic_inc(&info->port.count);
41201 spin_unlock_irqrestore(&info->netlock, flags);
41202
41203 - if (info->port.count == 1) {
41204 + if (atomic_read(&info->port.count) == 1) {
41205 /* 1st open on this device, init hardware */
41206 retval = startup(info);
41207 if (retval < 0)
41208 @@ -797,8 +797,8 @@ cleanup:
41209 if (retval) {
41210 if (tty->count == 1)
41211 info->port.tty = NULL; /* tty layer will release tty struct */
41212 - if(info->port.count)
41213 - info->port.count--;
41214 + if(atomic_read(&info->port.count))
41215 + atomic_dec(&info->port.count);
41216 }
41217
41218 return retval;
41219 @@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41220
41221 if (debug_level >= DEBUG_LEVEL_INFO)
41222 printk("%s(%d):%s close() entry, count=%d\n",
41223 - __FILE__,__LINE__, info->device_name, info->port.count);
41224 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
41225
41226 if (tty_port_close_start(&info->port, tty, filp) == 0)
41227 goto cleanup;
41228 @@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
41229 cleanup:
41230 if (debug_level >= DEBUG_LEVEL_INFO)
41231 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
41232 - tty->driver->name, info->port.count);
41233 + tty->driver->name, atomic_read(&info->port.count));
41234 }
41235
41236 /* Called by tty_hangup() when a hangup is signaled.
41237 @@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
41238 shutdown(info);
41239
41240 spin_lock_irqsave(&info->port.lock, flags);
41241 - info->port.count = 0;
41242 + atomic_set(&info->port.count, 0);
41243 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
41244 info->port.tty = NULL;
41245 spin_unlock_irqrestore(&info->port.lock, flags);
41246 @@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
41247 unsigned short new_crctype;
41248
41249 /* return error if TTY interface open */
41250 - if (info->port.count)
41251 + if (atomic_read(&info->port.count))
41252 return -EBUSY;
41253
41254 switch (encoding)
41255 @@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
41256
41257 /* arbitrate between network and tty opens */
41258 spin_lock_irqsave(&info->netlock, flags);
41259 - if (info->port.count != 0 || info->netcount != 0) {
41260 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
41261 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
41262 spin_unlock_irqrestore(&info->netlock, flags);
41263 return -EBUSY;
41264 @@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
41265 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
41266
41267 /* return error if TTY interface open */
41268 - if (info->port.count)
41269 + if (atomic_read(&info->port.count))
41270 return -EBUSY;
41271
41272 if (cmd != SIOCWANDEV)
41273 @@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
41274 * do not request bottom half processing if the
41275 * device is not open in a normal mode.
41276 */
41277 - if ( port && (port->port.count || port->netcount) &&
41278 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
41279 port->pending_bh && !port->bh_running &&
41280 !port->bh_requested ) {
41281 if ( debug_level >= DEBUG_LEVEL_ISR )
41282 @@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41283
41284 if (debug_level >= DEBUG_LEVEL_INFO)
41285 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
41286 - __FILE__,__LINE__, tty->driver->name, port->count );
41287 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41288
41289 spin_lock_irqsave(&info->lock, flags);
41290 if (!tty_hung_up_p(filp)) {
41291 extra_count = true;
41292 - port->count--;
41293 + atomic_dec(&port->count);
41294 }
41295 spin_unlock_irqrestore(&info->lock, flags);
41296 port->blocked_open++;
41297 @@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41298
41299 if (debug_level >= DEBUG_LEVEL_INFO)
41300 printk("%s(%d):%s block_til_ready() count=%d\n",
41301 - __FILE__,__LINE__, tty->driver->name, port->count );
41302 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41303
41304 tty_unlock(tty);
41305 schedule();
41306 @@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
41307 remove_wait_queue(&port->open_wait, &wait);
41308
41309 if (extra_count)
41310 - port->count++;
41311 + atomic_inc(&port->count);
41312 port->blocked_open--;
41313
41314 if (debug_level >= DEBUG_LEVEL_INFO)
41315 printk("%s(%d):%s block_til_ready() after, count=%d\n",
41316 - __FILE__,__LINE__, tty->driver->name, port->count );
41317 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
41318
41319 if (!retval)
41320 port->flags |= ASYNC_NORMAL_ACTIVE;
41321 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
41322 index b3c4a25..723916f 100644
41323 --- a/drivers/tty/sysrq.c
41324 +++ b/drivers/tty/sysrq.c
41325 @@ -867,7 +867,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
41326 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
41327 size_t count, loff_t *ppos)
41328 {
41329 - if (count) {
41330 + if (count && capable(CAP_SYS_ADMIN)) {
41331 char c;
41332
41333 if (get_user(c, buf))
41334 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
41335 index da9fde8..c07975f 100644
41336 --- a/drivers/tty/tty_io.c
41337 +++ b/drivers/tty/tty_io.c
41338 @@ -3391,7 +3391,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
41339
41340 void tty_default_fops(struct file_operations *fops)
41341 {
41342 - *fops = tty_fops;
41343 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
41344 }
41345
41346 /*
41347 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
41348 index c578229..45aa9ee 100644
41349 --- a/drivers/tty/tty_ldisc.c
41350 +++ b/drivers/tty/tty_ldisc.c
41351 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
41352 if (atomic_dec_and_test(&ld->users)) {
41353 struct tty_ldisc_ops *ldo = ld->ops;
41354
41355 - ldo->refcount--;
41356 + atomic_dec(&ldo->refcount);
41357 module_put(ldo->owner);
41358 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41359
41360 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
41361 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41362 tty_ldiscs[disc] = new_ldisc;
41363 new_ldisc->num = disc;
41364 - new_ldisc->refcount = 0;
41365 + atomic_set(&new_ldisc->refcount, 0);
41366 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41367
41368 return ret;
41369 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
41370 return -EINVAL;
41371
41372 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41373 - if (tty_ldiscs[disc]->refcount)
41374 + if (atomic_read(&tty_ldiscs[disc]->refcount))
41375 ret = -EBUSY;
41376 else
41377 tty_ldiscs[disc] = NULL;
41378 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
41379 if (ldops) {
41380 ret = ERR_PTR(-EAGAIN);
41381 if (try_module_get(ldops->owner)) {
41382 - ldops->refcount++;
41383 + atomic_inc(&ldops->refcount);
41384 ret = ldops;
41385 }
41386 }
41387 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
41388 unsigned long flags;
41389
41390 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
41391 - ldops->refcount--;
41392 + atomic_dec(&ldops->refcount);
41393 module_put(ldops->owner);
41394 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
41395 }
41396 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
41397 index b7ff59d..7c6105e 100644
41398 --- a/drivers/tty/tty_port.c
41399 +++ b/drivers/tty/tty_port.c
41400 @@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
41401 unsigned long flags;
41402
41403 spin_lock_irqsave(&port->lock, flags);
41404 - port->count = 0;
41405 + atomic_set(&port->count, 0);
41406 port->flags &= ~ASYNC_NORMAL_ACTIVE;
41407 if (port->tty) {
41408 set_bit(TTY_IO_ERROR, &port->tty->flags);
41409 @@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41410 /* The port lock protects the port counts */
41411 spin_lock_irqsave(&port->lock, flags);
41412 if (!tty_hung_up_p(filp))
41413 - port->count--;
41414 + atomic_dec(&port->count);
41415 port->blocked_open++;
41416 spin_unlock_irqrestore(&port->lock, flags);
41417
41418 @@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
41419 we must not mess that up further */
41420 spin_lock_irqsave(&port->lock, flags);
41421 if (!tty_hung_up_p(filp))
41422 - port->count++;
41423 + atomic_inc(&port->count);
41424 port->blocked_open--;
41425 if (retval == 0)
41426 port->flags |= ASYNC_NORMAL_ACTIVE;
41427 @@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
41428 return 0;
41429 }
41430
41431 - if (tty->count == 1 && port->count != 1) {
41432 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
41433 printk(KERN_WARNING
41434 "tty_port_close_start: tty->count = 1 port count = %d.\n",
41435 - port->count);
41436 - port->count = 1;
41437 + atomic_read(&port->count));
41438 + atomic_set(&port->count, 1);
41439 }
41440 - if (--port->count < 0) {
41441 + if (atomic_dec_return(&port->count) < 0) {
41442 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
41443 - port->count);
41444 - port->count = 0;
41445 + atomic_read(&port->count));
41446 + atomic_set(&port->count, 0);
41447 }
41448
41449 - if (port->count) {
41450 + if (atomic_read(&port->count)) {
41451 spin_unlock_irqrestore(&port->lock, flags);
41452 if (port->ops->drop)
41453 port->ops->drop(port);
41454 @@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
41455 {
41456 spin_lock_irq(&port->lock);
41457 if (!tty_hung_up_p(filp))
41458 - ++port->count;
41459 + atomic_inc(&port->count);
41460 spin_unlock_irq(&port->lock);
41461 tty_port_tty_set(port, tty);
41462
41463 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
41464 index 681765b..d3ccdf2 100644
41465 --- a/drivers/tty/vt/keyboard.c
41466 +++ b/drivers/tty/vt/keyboard.c
41467 @@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
41468 kbd->kbdmode == VC_OFF) &&
41469 value != KVAL(K_SAK))
41470 return; /* SAK is allowed even in raw mode */
41471 +
41472 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
41473 + {
41474 + void *func = fn_handler[value];
41475 + if (func == fn_show_state || func == fn_show_ptregs ||
41476 + func == fn_show_mem)
41477 + return;
41478 + }
41479 +#endif
41480 +
41481 fn_handler[value](vc);
41482 }
41483
41484 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41485 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
41486 return -EFAULT;
41487
41488 - if (!capable(CAP_SYS_TTY_CONFIG))
41489 - perm = 0;
41490 -
41491 switch (cmd) {
41492 case KDGKBENT:
41493 /* Ensure another thread doesn't free it under us */
41494 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
41495 spin_unlock_irqrestore(&kbd_event_lock, flags);
41496 return put_user(val, &user_kbe->kb_value);
41497 case KDSKBENT:
41498 + if (!capable(CAP_SYS_TTY_CONFIG))
41499 + perm = 0;
41500 +
41501 if (!perm)
41502 return -EPERM;
41503 if (!i && v == K_NOSUCHMAP) {
41504 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41505 int i, j, k;
41506 int ret;
41507
41508 - if (!capable(CAP_SYS_TTY_CONFIG))
41509 - perm = 0;
41510 -
41511 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
41512 if (!kbs) {
41513 ret = -ENOMEM;
41514 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
41515 kfree(kbs);
41516 return ((p && *p) ? -EOVERFLOW : 0);
41517 case KDSKBSENT:
41518 + if (!capable(CAP_SYS_TTY_CONFIG))
41519 + perm = 0;
41520 +
41521 if (!perm) {
41522 ret = -EPERM;
41523 goto reterr;
41524 diff --git a/drivers/tty/vt/vt.c b/drivers/tty/vt/vt.c
41525 index 8fd8968..3614c9c 100644
41526 --- a/drivers/tty/vt/vt.c
41527 +++ b/drivers/tty/vt/vt.c
41528 @@ -539,7 +539,7 @@ static void insert_char(struct vc_data *vc, unsigned int nr)
41529 {
41530 unsigned short *p = (unsigned short *) vc->vc_pos;
41531
41532 - scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x) * 2);
41533 + scr_memmovew(p + nr, p, (vc->vc_cols - vc->vc_x - nr) * 2);
41534 scr_memsetw(p, vc->vc_video_erase_char, nr * 2);
41535 vc->vc_need_wrap = 0;
41536 if (DO_UPDATE(vc))
41537 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
41538 index 5110f36..8dc0a74 100644
41539 --- a/drivers/uio/uio.c
41540 +++ b/drivers/uio/uio.c
41541 @@ -25,6 +25,7 @@
41542 #include <linux/kobject.h>
41543 #include <linux/cdev.h>
41544 #include <linux/uio_driver.h>
41545 +#include <asm/local.h>
41546
41547 #define UIO_MAX_DEVICES (1U << MINORBITS)
41548
41549 @@ -32,10 +33,10 @@ struct uio_device {
41550 struct module *owner;
41551 struct device *dev;
41552 int minor;
41553 - atomic_t event;
41554 + atomic_unchecked_t event;
41555 struct fasync_struct *async_queue;
41556 wait_queue_head_t wait;
41557 - int vma_count;
41558 + local_t vma_count;
41559 struct uio_info *info;
41560 struct kobject *map_dir;
41561 struct kobject *portio_dir;
41562 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
41563 struct device_attribute *attr, char *buf)
41564 {
41565 struct uio_device *idev = dev_get_drvdata(dev);
41566 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
41567 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
41568 }
41569
41570 static struct device_attribute uio_class_attributes[] = {
41571 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
41572 {
41573 struct uio_device *idev = info->uio_dev;
41574
41575 - atomic_inc(&idev->event);
41576 + atomic_inc_unchecked(&idev->event);
41577 wake_up_interruptible(&idev->wait);
41578 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
41579 }
41580 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
41581 }
41582
41583 listener->dev = idev;
41584 - listener->event_count = atomic_read(&idev->event);
41585 + listener->event_count = atomic_read_unchecked(&idev->event);
41586 filep->private_data = listener;
41587
41588 if (idev->info->open) {
41589 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
41590 return -EIO;
41591
41592 poll_wait(filep, &idev->wait, wait);
41593 - if (listener->event_count != atomic_read(&idev->event))
41594 + if (listener->event_count != atomic_read_unchecked(&idev->event))
41595 return POLLIN | POLLRDNORM;
41596 return 0;
41597 }
41598 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
41599 do {
41600 set_current_state(TASK_INTERRUPTIBLE);
41601
41602 - event_count = atomic_read(&idev->event);
41603 + event_count = atomic_read_unchecked(&idev->event);
41604 if (event_count != listener->event_count) {
41605 if (copy_to_user(buf, &event_count, count))
41606 retval = -EFAULT;
41607 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
41608 static void uio_vma_open(struct vm_area_struct *vma)
41609 {
41610 struct uio_device *idev = vma->vm_private_data;
41611 - idev->vma_count++;
41612 + local_inc(&idev->vma_count);
41613 }
41614
41615 static void uio_vma_close(struct vm_area_struct *vma)
41616 {
41617 struct uio_device *idev = vma->vm_private_data;
41618 - idev->vma_count--;
41619 + local_dec(&idev->vma_count);
41620 }
41621
41622 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41623 @@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
41624 idev->owner = owner;
41625 idev->info = info;
41626 init_waitqueue_head(&idev->wait);
41627 - atomic_set(&idev->event, 0);
41628 + atomic_set_unchecked(&idev->event, 0);
41629
41630 ret = uio_get_minor(idev);
41631 if (ret)
41632 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
41633 index b7eb86a..36d28af 100644
41634 --- a/drivers/usb/atm/cxacru.c
41635 +++ b/drivers/usb/atm/cxacru.c
41636 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
41637 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
41638 if (ret < 2)
41639 return -EINVAL;
41640 - if (index < 0 || index > 0x7f)
41641 + if (index > 0x7f)
41642 return -EINVAL;
41643 pos += tmp;
41644
41645 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
41646 index 35f10bf..6a38a0b 100644
41647 --- a/drivers/usb/atm/usbatm.c
41648 +++ b/drivers/usb/atm/usbatm.c
41649 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41650 if (printk_ratelimit())
41651 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
41652 __func__, vpi, vci);
41653 - atomic_inc(&vcc->stats->rx_err);
41654 + atomic_inc_unchecked(&vcc->stats->rx_err);
41655 return;
41656 }
41657
41658 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41659 if (length > ATM_MAX_AAL5_PDU) {
41660 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
41661 __func__, length, vcc);
41662 - atomic_inc(&vcc->stats->rx_err);
41663 + atomic_inc_unchecked(&vcc->stats->rx_err);
41664 goto out;
41665 }
41666
41667 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41668 if (sarb->len < pdu_length) {
41669 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
41670 __func__, pdu_length, sarb->len, vcc);
41671 - atomic_inc(&vcc->stats->rx_err);
41672 + atomic_inc_unchecked(&vcc->stats->rx_err);
41673 goto out;
41674 }
41675
41676 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
41677 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
41678 __func__, vcc);
41679 - atomic_inc(&vcc->stats->rx_err);
41680 + atomic_inc_unchecked(&vcc->stats->rx_err);
41681 goto out;
41682 }
41683
41684 @@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41685 if (printk_ratelimit())
41686 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
41687 __func__, length);
41688 - atomic_inc(&vcc->stats->rx_drop);
41689 + atomic_inc_unchecked(&vcc->stats->rx_drop);
41690 goto out;
41691 }
41692
41693 @@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
41694
41695 vcc->push(vcc, skb);
41696
41697 - atomic_inc(&vcc->stats->rx);
41698 + atomic_inc_unchecked(&vcc->stats->rx);
41699 out:
41700 skb_trim(sarb, 0);
41701 }
41702 @@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
41703 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
41704
41705 usbatm_pop(vcc, skb);
41706 - atomic_inc(&vcc->stats->tx);
41707 + atomic_inc_unchecked(&vcc->stats->tx);
41708
41709 skb = skb_dequeue(&instance->sndqueue);
41710 }
41711 @@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
41712 if (!left--)
41713 return sprintf(page,
41714 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
41715 - atomic_read(&atm_dev->stats.aal5.tx),
41716 - atomic_read(&atm_dev->stats.aal5.tx_err),
41717 - atomic_read(&atm_dev->stats.aal5.rx),
41718 - atomic_read(&atm_dev->stats.aal5.rx_err),
41719 - atomic_read(&atm_dev->stats.aal5.rx_drop));
41720 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
41721 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
41722 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
41723 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
41724 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
41725
41726 if (!left--) {
41727 if (instance->disconnected)
41728 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
41729 index cbacea9..246cccd 100644
41730 --- a/drivers/usb/core/devices.c
41731 +++ b/drivers/usb/core/devices.c
41732 @@ -126,7 +126,7 @@ static const char format_endpt[] =
41733 * time it gets called.
41734 */
41735 static struct device_connect_event {
41736 - atomic_t count;
41737 + atomic_unchecked_t count;
41738 wait_queue_head_t wait;
41739 } device_event = {
41740 .count = ATOMIC_INIT(1),
41741 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
41742
41743 void usbfs_conn_disc_event(void)
41744 {
41745 - atomic_add(2, &device_event.count);
41746 + atomic_add_unchecked(2, &device_event.count);
41747 wake_up(&device_event.wait);
41748 }
41749
41750 @@ -645,7 +645,7 @@ static unsigned int usb_device_poll(struct file *file,
41751
41752 poll_wait(file, &device_event.wait, wait);
41753
41754 - event_count = atomic_read(&device_event.count);
41755 + event_count = atomic_read_unchecked(&device_event.count);
41756 if (file->f_version != event_count) {
41757 file->f_version = event_count;
41758 return POLLIN | POLLRDNORM;
41759 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
41760 index 8e64adf..9a33a3c 100644
41761 --- a/drivers/usb/core/hcd.c
41762 +++ b/drivers/usb/core/hcd.c
41763 @@ -1522,7 +1522,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41764 */
41765 usb_get_urb(urb);
41766 atomic_inc(&urb->use_count);
41767 - atomic_inc(&urb->dev->urbnum);
41768 + atomic_inc_unchecked(&urb->dev->urbnum);
41769 usbmon_urb_submit(&hcd->self, urb);
41770
41771 /* NOTE requirements on root-hub callers (usbfs and the hub
41772 @@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
41773 urb->hcpriv = NULL;
41774 INIT_LIST_HEAD(&urb->urb_list);
41775 atomic_dec(&urb->use_count);
41776 - atomic_dec(&urb->dev->urbnum);
41777 + atomic_dec_unchecked(&urb->dev->urbnum);
41778 if (atomic_read(&urb->reject))
41779 wake_up(&usb_kill_urb_queue);
41780 usb_put_urb(urb);
41781 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
41782 index 818e4a0..0fc9589 100644
41783 --- a/drivers/usb/core/sysfs.c
41784 +++ b/drivers/usb/core/sysfs.c
41785 @@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
41786 struct usb_device *udev;
41787
41788 udev = to_usb_device(dev);
41789 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
41790 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
41791 }
41792 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
41793
41794 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
41795 index f81b925..78d22ec 100644
41796 --- a/drivers/usb/core/usb.c
41797 +++ b/drivers/usb/core/usb.c
41798 @@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
41799 set_dev_node(&dev->dev, dev_to_node(bus->controller));
41800 dev->state = USB_STATE_ATTACHED;
41801 dev->lpm_disable_count = 1;
41802 - atomic_set(&dev->urbnum, 0);
41803 + atomic_set_unchecked(&dev->urbnum, 0);
41804
41805 INIT_LIST_HEAD(&dev->ep0.urb_list);
41806 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
41807 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
41808 index 5e29dde..eca992f 100644
41809 --- a/drivers/usb/early/ehci-dbgp.c
41810 +++ b/drivers/usb/early/ehci-dbgp.c
41811 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
41812
41813 #ifdef CONFIG_KGDB
41814 static struct kgdb_io kgdbdbgp_io_ops;
41815 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
41816 +static struct kgdb_io kgdbdbgp_io_ops_console;
41817 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
41818 #else
41819 #define dbgp_kgdb_mode (0)
41820 #endif
41821 @@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
41822 .write_char = kgdbdbgp_write_char,
41823 };
41824
41825 +static struct kgdb_io kgdbdbgp_io_ops_console = {
41826 + .name = "kgdbdbgp",
41827 + .read_char = kgdbdbgp_read_char,
41828 + .write_char = kgdbdbgp_write_char,
41829 + .is_console = 1
41830 +};
41831 +
41832 static int kgdbdbgp_wait_time;
41833
41834 static int __init kgdbdbgp_parse_config(char *str)
41835 @@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
41836 ptr++;
41837 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
41838 }
41839 - kgdb_register_io_module(&kgdbdbgp_io_ops);
41840 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
41841 + if (early_dbgp_console.index != -1)
41842 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
41843 + else
41844 + kgdb_register_io_module(&kgdbdbgp_io_ops);
41845
41846 return 0;
41847 }
41848 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
41849 index 598dcc1..032dd4f 100644
41850 --- a/drivers/usb/gadget/u_serial.c
41851 +++ b/drivers/usb/gadget/u_serial.c
41852 @@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41853 spin_lock_irq(&port->port_lock);
41854
41855 /* already open? Great. */
41856 - if (port->port.count) {
41857 + if (atomic_read(&port->port.count)) {
41858 status = 0;
41859 - port->port.count++;
41860 + atomic_inc(&port->port.count);
41861
41862 /* currently opening/closing? wait ... */
41863 } else if (port->openclose) {
41864 @@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
41865 tty->driver_data = port;
41866 port->port.tty = tty;
41867
41868 - port->port.count = 1;
41869 + atomic_set(&port->port.count, 1);
41870 port->openclose = false;
41871
41872 /* if connected, start the I/O stream */
41873 @@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41874
41875 spin_lock_irq(&port->port_lock);
41876
41877 - if (port->port.count != 1) {
41878 - if (port->port.count == 0)
41879 + if (atomic_read(&port->port.count) != 1) {
41880 + if (atomic_read(&port->port.count) == 0)
41881 WARN_ON(1);
41882 else
41883 - --port->port.count;
41884 + atomic_dec(&port->port.count);
41885 goto exit;
41886 }
41887
41888 @@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
41889 * and sleep if necessary
41890 */
41891 port->openclose = true;
41892 - port->port.count = 0;
41893 + atomic_set(&port->port.count, 0);
41894
41895 gser = port->port_usb;
41896 if (gser && gser->disconnect)
41897 @@ -1159,7 +1159,7 @@ static int gs_closed(struct gs_port *port)
41898 int cond;
41899
41900 spin_lock_irq(&port->port_lock);
41901 - cond = (port->port.count == 0) && !port->openclose;
41902 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
41903 spin_unlock_irq(&port->port_lock);
41904 return cond;
41905 }
41906 @@ -1273,7 +1273,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
41907 /* if it's already open, start I/O ... and notify the serial
41908 * protocol about open/close status (connect/disconnect).
41909 */
41910 - if (port->port.count) {
41911 + if (atomic_read(&port->port.count)) {
41912 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
41913 gs_start_io(port);
41914 if (gser->connect)
41915 @@ -1320,7 +1320,7 @@ void gserial_disconnect(struct gserial *gser)
41916
41917 port->port_usb = NULL;
41918 gser->ioport = NULL;
41919 - if (port->port.count > 0 || port->openclose) {
41920 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
41921 wake_up_interruptible(&port->drain_wait);
41922 if (port->port.tty)
41923 tty_hangup(port->port.tty);
41924 @@ -1336,7 +1336,7 @@ void gserial_disconnect(struct gserial *gser)
41925
41926 /* finally, free any unused/unusable I/O buffers */
41927 spin_lock_irqsave(&port->port_lock, flags);
41928 - if (port->port.count == 0 && !port->openclose)
41929 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
41930 gs_buf_free(&port->port_write_buf);
41931 gs_free_requests(gser->out, &port->read_pool, NULL);
41932 gs_free_requests(gser->out, &port->read_queue, NULL);
41933 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
41934 index 5f3bcd3..bfca43f 100644
41935 --- a/drivers/usb/serial/console.c
41936 +++ b/drivers/usb/serial/console.c
41937 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
41938
41939 info->port = port;
41940
41941 - ++port->port.count;
41942 + atomic_inc(&port->port.count);
41943 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
41944 if (serial->type->set_termios) {
41945 /*
41946 @@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
41947 }
41948 /* Now that any required fake tty operations are completed restore
41949 * the tty port count */
41950 - --port->port.count;
41951 + atomic_dec(&port->port.count);
41952 /* The console is special in terms of closing the device so
41953 * indicate this port is now acting as a system console. */
41954 port->port.console = 1;
41955 @@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
41956 free_tty:
41957 kfree(tty);
41958 reset_open_count:
41959 - port->port.count = 0;
41960 + atomic_set(&port->port.count, 0);
41961 usb_autopm_put_interface(serial->interface);
41962 error_get_interface:
41963 usb_serial_put(serial);
41964 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
41965 index d6bea3e..60b250e 100644
41966 --- a/drivers/usb/wusbcore/wa-hc.h
41967 +++ b/drivers/usb/wusbcore/wa-hc.h
41968 @@ -192,7 +192,7 @@ struct wahc {
41969 struct list_head xfer_delayed_list;
41970 spinlock_t xfer_list_lock;
41971 struct work_struct xfer_work;
41972 - atomic_t xfer_id_count;
41973 + atomic_unchecked_t xfer_id_count;
41974 };
41975
41976
41977 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
41978 INIT_LIST_HEAD(&wa->xfer_delayed_list);
41979 spin_lock_init(&wa->xfer_list_lock);
41980 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
41981 - atomic_set(&wa->xfer_id_count, 1);
41982 + atomic_set_unchecked(&wa->xfer_id_count, 1);
41983 }
41984
41985 /**
41986 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
41987 index 57c01ab..8a05959 100644
41988 --- a/drivers/usb/wusbcore/wa-xfer.c
41989 +++ b/drivers/usb/wusbcore/wa-xfer.c
41990 @@ -296,7 +296,7 @@ out:
41991 */
41992 static void wa_xfer_id_init(struct wa_xfer *xfer)
41993 {
41994 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
41995 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
41996 }
41997
41998 /*
41999 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
42000 index 8c55011..eed4ae1a 100644
42001 --- a/drivers/video/aty/aty128fb.c
42002 +++ b/drivers/video/aty/aty128fb.c
42003 @@ -149,7 +149,7 @@ enum {
42004 };
42005
42006 /* Must match above enum */
42007 -static char * const r128_family[] = {
42008 +static const char * const r128_family[] = {
42009 "AGP",
42010 "PCI",
42011 "PRO AGP",
42012 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
42013 index 5c3960d..15cf8fc 100644
42014 --- a/drivers/video/fbcmap.c
42015 +++ b/drivers/video/fbcmap.c
42016 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
42017 rc = -ENODEV;
42018 goto out;
42019 }
42020 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
42021 - !info->fbops->fb_setcmap)) {
42022 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
42023 rc = -EINVAL;
42024 goto out1;
42025 }
42026 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
42027 index 3ff0105..7589d98 100644
42028 --- a/drivers/video/fbmem.c
42029 +++ b/drivers/video/fbmem.c
42030 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42031 image->dx += image->width + 8;
42032 }
42033 } else if (rotate == FB_ROTATE_UD) {
42034 - for (x = 0; x < num && image->dx >= 0; x++) {
42035 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
42036 info->fbops->fb_imageblit(info, image);
42037 image->dx -= image->width + 8;
42038 }
42039 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
42040 image->dy += image->height + 8;
42041 }
42042 } else if (rotate == FB_ROTATE_CCW) {
42043 - for (x = 0; x < num && image->dy >= 0; x++) {
42044 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
42045 info->fbops->fb_imageblit(info, image);
42046 image->dy -= image->height + 8;
42047 }
42048 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
42049 return -EFAULT;
42050 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
42051 return -EINVAL;
42052 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
42053 + if (con2fb.framebuffer >= FB_MAX)
42054 return -EINVAL;
42055 if (!registered_fb[con2fb.framebuffer])
42056 request_module("fb%d", con2fb.framebuffer);
42057 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
42058 index 7672d2e..b56437f 100644
42059 --- a/drivers/video/i810/i810_accel.c
42060 +++ b/drivers/video/i810/i810_accel.c
42061 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
42062 }
42063 }
42064 printk("ringbuffer lockup!!!\n");
42065 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
42066 i810_report_error(mmio);
42067 par->dev_flags |= LOCKUP;
42068 info->pixmap.scan_align = 1;
42069 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
42070 index 3c14e43..eafa544 100644
42071 --- a/drivers/video/logo/logo_linux_clut224.ppm
42072 +++ b/drivers/video/logo/logo_linux_clut224.ppm
42073 @@ -1,1604 +1,1123 @@
42074 P3
42075 -# Standard 224-color Linux logo
42076 80 80
42077 255
42078 - 0 0 0 0 0 0 0 0 0 0 0 0
42079 - 0 0 0 0 0 0 0 0 0 0 0 0
42080 - 0 0 0 0 0 0 0 0 0 0 0 0
42081 - 0 0 0 0 0 0 0 0 0 0 0 0
42082 - 0 0 0 0 0 0 0 0 0 0 0 0
42083 - 0 0 0 0 0 0 0 0 0 0 0 0
42084 - 0 0 0 0 0 0 0 0 0 0 0 0
42085 - 0 0 0 0 0 0 0 0 0 0 0 0
42086 - 0 0 0 0 0 0 0 0 0 0 0 0
42087 - 6 6 6 6 6 6 10 10 10 10 10 10
42088 - 10 10 10 6 6 6 6 6 6 6 6 6
42089 - 0 0 0 0 0 0 0 0 0 0 0 0
42090 - 0 0 0 0 0 0 0 0 0 0 0 0
42091 - 0 0 0 0 0 0 0 0 0 0 0 0
42092 - 0 0 0 0 0 0 0 0 0 0 0 0
42093 - 0 0 0 0 0 0 0 0 0 0 0 0
42094 - 0 0 0 0 0 0 0 0 0 0 0 0
42095 - 0 0 0 0 0 0 0 0 0 0 0 0
42096 - 0 0 0 0 0 0 0 0 0 0 0 0
42097 - 0 0 0 0 0 0 0 0 0 0 0 0
42098 - 0 0 0 0 0 0 0 0 0 0 0 0
42099 - 0 0 0 0 0 0 0 0 0 0 0 0
42100 - 0 0 0 0 0 0 0 0 0 0 0 0
42101 - 0 0 0 0 0 0 0 0 0 0 0 0
42102 - 0 0 0 0 0 0 0 0 0 0 0 0
42103 - 0 0 0 0 0 0 0 0 0 0 0 0
42104 - 0 0 0 0 0 0 0 0 0 0 0 0
42105 - 0 0 0 0 0 0 0 0 0 0 0 0
42106 - 0 0 0 6 6 6 10 10 10 14 14 14
42107 - 22 22 22 26 26 26 30 30 30 34 34 34
42108 - 30 30 30 30 30 30 26 26 26 18 18 18
42109 - 14 14 14 10 10 10 6 6 6 0 0 0
42110 - 0 0 0 0 0 0 0 0 0 0 0 0
42111 - 0 0 0 0 0 0 0 0 0 0 0 0
42112 - 0 0 0 0 0 0 0 0 0 0 0 0
42113 - 0 0 0 0 0 0 0 0 0 0 0 0
42114 - 0 0 0 0 0 0 0 0 0 0 0 0
42115 - 0 0 0 0 0 0 0 0 0 0 0 0
42116 - 0 0 0 0 0 0 0 0 0 0 0 0
42117 - 0 0 0 0 0 0 0 0 0 0 0 0
42118 - 0 0 0 0 0 0 0 0 0 0 0 0
42119 - 0 0 0 0 0 1 0 0 1 0 0 0
42120 - 0 0 0 0 0 0 0 0 0 0 0 0
42121 - 0 0 0 0 0 0 0 0 0 0 0 0
42122 - 0 0 0 0 0 0 0 0 0 0 0 0
42123 - 0 0 0 0 0 0 0 0 0 0 0 0
42124 - 0 0 0 0 0 0 0 0 0 0 0 0
42125 - 0 0 0 0 0 0 0 0 0 0 0 0
42126 - 6 6 6 14 14 14 26 26 26 42 42 42
42127 - 54 54 54 66 66 66 78 78 78 78 78 78
42128 - 78 78 78 74 74 74 66 66 66 54 54 54
42129 - 42 42 42 26 26 26 18 18 18 10 10 10
42130 - 6 6 6 0 0 0 0 0 0 0 0 0
42131 - 0 0 0 0 0 0 0 0 0 0 0 0
42132 - 0 0 0 0 0 0 0 0 0 0 0 0
42133 - 0 0 0 0 0 0 0 0 0 0 0 0
42134 - 0 0 0 0 0 0 0 0 0 0 0 0
42135 - 0 0 0 0 0 0 0 0 0 0 0 0
42136 - 0 0 0 0 0 0 0 0 0 0 0 0
42137 - 0 0 0 0 0 0 0 0 0 0 0 0
42138 - 0 0 0 0 0 0 0 0 0 0 0 0
42139 - 0 0 1 0 0 0 0 0 0 0 0 0
42140 - 0 0 0 0 0 0 0 0 0 0 0 0
42141 - 0 0 0 0 0 0 0 0 0 0 0 0
42142 - 0 0 0 0 0 0 0 0 0 0 0 0
42143 - 0 0 0 0 0 0 0 0 0 0 0 0
42144 - 0 0 0 0 0 0 0 0 0 0 0 0
42145 - 0 0 0 0 0 0 0 0 0 10 10 10
42146 - 22 22 22 42 42 42 66 66 66 86 86 86
42147 - 66 66 66 38 38 38 38 38 38 22 22 22
42148 - 26 26 26 34 34 34 54 54 54 66 66 66
42149 - 86 86 86 70 70 70 46 46 46 26 26 26
42150 - 14 14 14 6 6 6 0 0 0 0 0 0
42151 - 0 0 0 0 0 0 0 0 0 0 0 0
42152 - 0 0 0 0 0 0 0 0 0 0 0 0
42153 - 0 0 0 0 0 0 0 0 0 0 0 0
42154 - 0 0 0 0 0 0 0 0 0 0 0 0
42155 - 0 0 0 0 0 0 0 0 0 0 0 0
42156 - 0 0 0 0 0 0 0 0 0 0 0 0
42157 - 0 0 0 0 0 0 0 0 0 0 0 0
42158 - 0 0 0 0 0 0 0 0 0 0 0 0
42159 - 0 0 1 0 0 1 0 0 1 0 0 0
42160 - 0 0 0 0 0 0 0 0 0 0 0 0
42161 - 0 0 0 0 0 0 0 0 0 0 0 0
42162 - 0 0 0 0 0 0 0 0 0 0 0 0
42163 - 0 0 0 0 0 0 0 0 0 0 0 0
42164 - 0 0 0 0 0 0 0 0 0 0 0 0
42165 - 0 0 0 0 0 0 10 10 10 26 26 26
42166 - 50 50 50 82 82 82 58 58 58 6 6 6
42167 - 2 2 6 2 2 6 2 2 6 2 2 6
42168 - 2 2 6 2 2 6 2 2 6 2 2 6
42169 - 6 6 6 54 54 54 86 86 86 66 66 66
42170 - 38 38 38 18 18 18 6 6 6 0 0 0
42171 - 0 0 0 0 0 0 0 0 0 0 0 0
42172 - 0 0 0 0 0 0 0 0 0 0 0 0
42173 - 0 0 0 0 0 0 0 0 0 0 0 0
42174 - 0 0 0 0 0 0 0 0 0 0 0 0
42175 - 0 0 0 0 0 0 0 0 0 0 0 0
42176 - 0 0 0 0 0 0 0 0 0 0 0 0
42177 - 0 0 0 0 0 0 0 0 0 0 0 0
42178 - 0 0 0 0 0 0 0 0 0 0 0 0
42179 - 0 0 0 0 0 0 0 0 0 0 0 0
42180 - 0 0 0 0 0 0 0 0 0 0 0 0
42181 - 0 0 0 0 0 0 0 0 0 0 0 0
42182 - 0 0 0 0 0 0 0 0 0 0 0 0
42183 - 0 0 0 0 0 0 0 0 0 0 0 0
42184 - 0 0 0 0 0 0 0 0 0 0 0 0
42185 - 0 0 0 6 6 6 22 22 22 50 50 50
42186 - 78 78 78 34 34 34 2 2 6 2 2 6
42187 - 2 2 6 2 2 6 2 2 6 2 2 6
42188 - 2 2 6 2 2 6 2 2 6 2 2 6
42189 - 2 2 6 2 2 6 6 6 6 70 70 70
42190 - 78 78 78 46 46 46 22 22 22 6 6 6
42191 - 0 0 0 0 0 0 0 0 0 0 0 0
42192 - 0 0 0 0 0 0 0 0 0 0 0 0
42193 - 0 0 0 0 0 0 0 0 0 0 0 0
42194 - 0 0 0 0 0 0 0 0 0 0 0 0
42195 - 0 0 0 0 0 0 0 0 0 0 0 0
42196 - 0 0 0 0 0 0 0 0 0 0 0 0
42197 - 0 0 0 0 0 0 0 0 0 0 0 0
42198 - 0 0 0 0 0 0 0 0 0 0 0 0
42199 - 0 0 1 0 0 1 0 0 1 0 0 0
42200 - 0 0 0 0 0 0 0 0 0 0 0 0
42201 - 0 0 0 0 0 0 0 0 0 0 0 0
42202 - 0 0 0 0 0 0 0 0 0 0 0 0
42203 - 0 0 0 0 0 0 0 0 0 0 0 0
42204 - 0 0 0 0 0 0 0 0 0 0 0 0
42205 - 6 6 6 18 18 18 42 42 42 82 82 82
42206 - 26 26 26 2 2 6 2 2 6 2 2 6
42207 - 2 2 6 2 2 6 2 2 6 2 2 6
42208 - 2 2 6 2 2 6 2 2 6 14 14 14
42209 - 46 46 46 34 34 34 6 6 6 2 2 6
42210 - 42 42 42 78 78 78 42 42 42 18 18 18
42211 - 6 6 6 0 0 0 0 0 0 0 0 0
42212 - 0 0 0 0 0 0 0 0 0 0 0 0
42213 - 0 0 0 0 0 0 0 0 0 0 0 0
42214 - 0 0 0 0 0 0 0 0 0 0 0 0
42215 - 0 0 0 0 0 0 0 0 0 0 0 0
42216 - 0 0 0 0 0 0 0 0 0 0 0 0
42217 - 0 0 0 0 0 0 0 0 0 0 0 0
42218 - 0 0 0 0 0 0 0 0 0 0 0 0
42219 - 0 0 1 0 0 0 0 0 1 0 0 0
42220 - 0 0 0 0 0 0 0 0 0 0 0 0
42221 - 0 0 0 0 0 0 0 0 0 0 0 0
42222 - 0 0 0 0 0 0 0 0 0 0 0 0
42223 - 0 0 0 0 0 0 0 0 0 0 0 0
42224 - 0 0 0 0 0 0 0 0 0 0 0 0
42225 - 10 10 10 30 30 30 66 66 66 58 58 58
42226 - 2 2 6 2 2 6 2 2 6 2 2 6
42227 - 2 2 6 2 2 6 2 2 6 2 2 6
42228 - 2 2 6 2 2 6 2 2 6 26 26 26
42229 - 86 86 86 101 101 101 46 46 46 10 10 10
42230 - 2 2 6 58 58 58 70 70 70 34 34 34
42231 - 10 10 10 0 0 0 0 0 0 0 0 0
42232 - 0 0 0 0 0 0 0 0 0 0 0 0
42233 - 0 0 0 0 0 0 0 0 0 0 0 0
42234 - 0 0 0 0 0 0 0 0 0 0 0 0
42235 - 0 0 0 0 0 0 0 0 0 0 0 0
42236 - 0 0 0 0 0 0 0 0 0 0 0 0
42237 - 0 0 0 0 0 0 0 0 0 0 0 0
42238 - 0 0 0 0 0 0 0 0 0 0 0 0
42239 - 0 0 1 0 0 1 0 0 1 0 0 0
42240 - 0 0 0 0 0 0 0 0 0 0 0 0
42241 - 0 0 0 0 0 0 0 0 0 0 0 0
42242 - 0 0 0 0 0 0 0 0 0 0 0 0
42243 - 0 0 0 0 0 0 0 0 0 0 0 0
42244 - 0 0 0 0 0 0 0 0 0 0 0 0
42245 - 14 14 14 42 42 42 86 86 86 10 10 10
42246 - 2 2 6 2 2 6 2 2 6 2 2 6
42247 - 2 2 6 2 2 6 2 2 6 2 2 6
42248 - 2 2 6 2 2 6 2 2 6 30 30 30
42249 - 94 94 94 94 94 94 58 58 58 26 26 26
42250 - 2 2 6 6 6 6 78 78 78 54 54 54
42251 - 22 22 22 6 6 6 0 0 0 0 0 0
42252 - 0 0 0 0 0 0 0 0 0 0 0 0
42253 - 0 0 0 0 0 0 0 0 0 0 0 0
42254 - 0 0 0 0 0 0 0 0 0 0 0 0
42255 - 0 0 0 0 0 0 0 0 0 0 0 0
42256 - 0 0 0 0 0 0 0 0 0 0 0 0
42257 - 0 0 0 0 0 0 0 0 0 0 0 0
42258 - 0 0 0 0 0 0 0 0 0 0 0 0
42259 - 0 0 0 0 0 0 0 0 0 0 0 0
42260 - 0 0 0 0 0 0 0 0 0 0 0 0
42261 - 0 0 0 0 0 0 0 0 0 0 0 0
42262 - 0 0 0 0 0 0 0 0 0 0 0 0
42263 - 0 0 0 0 0 0 0 0 0 0 0 0
42264 - 0 0 0 0 0 0 0 0 0 6 6 6
42265 - 22 22 22 62 62 62 62 62 62 2 2 6
42266 - 2 2 6 2 2 6 2 2 6 2 2 6
42267 - 2 2 6 2 2 6 2 2 6 2 2 6
42268 - 2 2 6 2 2 6 2 2 6 26 26 26
42269 - 54 54 54 38 38 38 18 18 18 10 10 10
42270 - 2 2 6 2 2 6 34 34 34 82 82 82
42271 - 38 38 38 14 14 14 0 0 0 0 0 0
42272 - 0 0 0 0 0 0 0 0 0 0 0 0
42273 - 0 0 0 0 0 0 0 0 0 0 0 0
42274 - 0 0 0 0 0 0 0 0 0 0 0 0
42275 - 0 0 0 0 0 0 0 0 0 0 0 0
42276 - 0 0 0 0 0 0 0 0 0 0 0 0
42277 - 0 0 0 0 0 0 0 0 0 0 0 0
42278 - 0 0 0 0 0 0 0 0 0 0 0 0
42279 - 0 0 0 0 0 1 0 0 1 0 0 0
42280 - 0 0 0 0 0 0 0 0 0 0 0 0
42281 - 0 0 0 0 0 0 0 0 0 0 0 0
42282 - 0 0 0 0 0 0 0 0 0 0 0 0
42283 - 0 0 0 0 0 0 0 0 0 0 0 0
42284 - 0 0 0 0 0 0 0 0 0 6 6 6
42285 - 30 30 30 78 78 78 30 30 30 2 2 6
42286 - 2 2 6 2 2 6 2 2 6 2 2 6
42287 - 2 2 6 2 2 6 2 2 6 2 2 6
42288 - 2 2 6 2 2 6 2 2 6 10 10 10
42289 - 10 10 10 2 2 6 2 2 6 2 2 6
42290 - 2 2 6 2 2 6 2 2 6 78 78 78
42291 - 50 50 50 18 18 18 6 6 6 0 0 0
42292 - 0 0 0 0 0 0 0 0 0 0 0 0
42293 - 0 0 0 0 0 0 0 0 0 0 0 0
42294 - 0 0 0 0 0 0 0 0 0 0 0 0
42295 - 0 0 0 0 0 0 0 0 0 0 0 0
42296 - 0 0 0 0 0 0 0 0 0 0 0 0
42297 - 0 0 0 0 0 0 0 0 0 0 0 0
42298 - 0 0 0 0 0 0 0 0 0 0 0 0
42299 - 0 0 1 0 0 0 0 0 0 0 0 0
42300 - 0 0 0 0 0 0 0 0 0 0 0 0
42301 - 0 0 0 0 0 0 0 0 0 0 0 0
42302 - 0 0 0 0 0 0 0 0 0 0 0 0
42303 - 0 0 0 0 0 0 0 0 0 0 0 0
42304 - 0 0 0 0 0 0 0 0 0 10 10 10
42305 - 38 38 38 86 86 86 14 14 14 2 2 6
42306 - 2 2 6 2 2 6 2 2 6 2 2 6
42307 - 2 2 6 2 2 6 2 2 6 2 2 6
42308 - 2 2 6 2 2 6 2 2 6 2 2 6
42309 - 2 2 6 2 2 6 2 2 6 2 2 6
42310 - 2 2 6 2 2 6 2 2 6 54 54 54
42311 - 66 66 66 26 26 26 6 6 6 0 0 0
42312 - 0 0 0 0 0 0 0 0 0 0 0 0
42313 - 0 0 0 0 0 0 0 0 0 0 0 0
42314 - 0 0 0 0 0 0 0 0 0 0 0 0
42315 - 0 0 0 0 0 0 0 0 0 0 0 0
42316 - 0 0 0 0 0 0 0 0 0 0 0 0
42317 - 0 0 0 0 0 0 0 0 0 0 0 0
42318 - 0 0 0 0 0 0 0 0 0 0 0 0
42319 - 0 0 0 0 0 1 0 0 1 0 0 0
42320 - 0 0 0 0 0 0 0 0 0 0 0 0
42321 - 0 0 0 0 0 0 0 0 0 0 0 0
42322 - 0 0 0 0 0 0 0 0 0 0 0 0
42323 - 0 0 0 0 0 0 0 0 0 0 0 0
42324 - 0 0 0 0 0 0 0 0 0 14 14 14
42325 - 42 42 42 82 82 82 2 2 6 2 2 6
42326 - 2 2 6 6 6 6 10 10 10 2 2 6
42327 - 2 2 6 2 2 6 2 2 6 2 2 6
42328 - 2 2 6 2 2 6 2 2 6 6 6 6
42329 - 14 14 14 10 10 10 2 2 6 2 2 6
42330 - 2 2 6 2 2 6 2 2 6 18 18 18
42331 - 82 82 82 34 34 34 10 10 10 0 0 0
42332 - 0 0 0 0 0 0 0 0 0 0 0 0
42333 - 0 0 0 0 0 0 0 0 0 0 0 0
42334 - 0 0 0 0 0 0 0 0 0 0 0 0
42335 - 0 0 0 0 0 0 0 0 0 0 0 0
42336 - 0 0 0 0 0 0 0 0 0 0 0 0
42337 - 0 0 0 0 0 0 0 0 0 0 0 0
42338 - 0 0 0 0 0 0 0 0 0 0 0 0
42339 - 0 0 1 0 0 0 0 0 0 0 0 0
42340 - 0 0 0 0 0 0 0 0 0 0 0 0
42341 - 0 0 0 0 0 0 0 0 0 0 0 0
42342 - 0 0 0 0 0 0 0 0 0 0 0 0
42343 - 0 0 0 0 0 0 0 0 0 0 0 0
42344 - 0 0 0 0 0 0 0 0 0 14 14 14
42345 - 46 46 46 86 86 86 2 2 6 2 2 6
42346 - 6 6 6 6 6 6 22 22 22 34 34 34
42347 - 6 6 6 2 2 6 2 2 6 2 2 6
42348 - 2 2 6 2 2 6 18 18 18 34 34 34
42349 - 10 10 10 50 50 50 22 22 22 2 2 6
42350 - 2 2 6 2 2 6 2 2 6 10 10 10
42351 - 86 86 86 42 42 42 14 14 14 0 0 0
42352 - 0 0 0 0 0 0 0 0 0 0 0 0
42353 - 0 0 0 0 0 0 0 0 0 0 0 0
42354 - 0 0 0 0 0 0 0 0 0 0 0 0
42355 - 0 0 0 0 0 0 0 0 0 0 0 0
42356 - 0 0 0 0 0 0 0 0 0 0 0 0
42357 - 0 0 0 0 0 0 0 0 0 0 0 0
42358 - 0 0 0 0 0 0 0 0 0 0 0 0
42359 - 0 0 1 0 0 1 0 0 1 0 0 0
42360 - 0 0 0 0 0 0 0 0 0 0 0 0
42361 - 0 0 0 0 0 0 0 0 0 0 0 0
42362 - 0 0 0 0 0 0 0 0 0 0 0 0
42363 - 0 0 0 0 0 0 0 0 0 0 0 0
42364 - 0 0 0 0 0 0 0 0 0 14 14 14
42365 - 46 46 46 86 86 86 2 2 6 2 2 6
42366 - 38 38 38 116 116 116 94 94 94 22 22 22
42367 - 22 22 22 2 2 6 2 2 6 2 2 6
42368 - 14 14 14 86 86 86 138 138 138 162 162 162
42369 -154 154 154 38 38 38 26 26 26 6 6 6
42370 - 2 2 6 2 2 6 2 2 6 2 2 6
42371 - 86 86 86 46 46 46 14 14 14 0 0 0
42372 - 0 0 0 0 0 0 0 0 0 0 0 0
42373 - 0 0 0 0 0 0 0 0 0 0 0 0
42374 - 0 0 0 0 0 0 0 0 0 0 0 0
42375 - 0 0 0 0 0 0 0 0 0 0 0 0
42376 - 0 0 0 0 0 0 0 0 0 0 0 0
42377 - 0 0 0 0 0 0 0 0 0 0 0 0
42378 - 0 0 0 0 0 0 0 0 0 0 0 0
42379 - 0 0 0 0 0 0 0 0 0 0 0 0
42380 - 0 0 0 0 0 0 0 0 0 0 0 0
42381 - 0 0 0 0 0 0 0 0 0 0 0 0
42382 - 0 0 0 0 0 0 0 0 0 0 0 0
42383 - 0 0 0 0 0 0 0 0 0 0 0 0
42384 - 0 0 0 0 0 0 0 0 0 14 14 14
42385 - 46 46 46 86 86 86 2 2 6 14 14 14
42386 -134 134 134 198 198 198 195 195 195 116 116 116
42387 - 10 10 10 2 2 6 2 2 6 6 6 6
42388 -101 98 89 187 187 187 210 210 210 218 218 218
42389 -214 214 214 134 134 134 14 14 14 6 6 6
42390 - 2 2 6 2 2 6 2 2 6 2 2 6
42391 - 86 86 86 50 50 50 18 18 18 6 6 6
42392 - 0 0 0 0 0 0 0 0 0 0 0 0
42393 - 0 0 0 0 0 0 0 0 0 0 0 0
42394 - 0 0 0 0 0 0 0 0 0 0 0 0
42395 - 0 0 0 0 0 0 0 0 0 0 0 0
42396 - 0 0 0 0 0 0 0 0 0 0 0 0
42397 - 0 0 0 0 0 0 0 0 0 0 0 0
42398 - 0 0 0 0 0 0 0 0 1 0 0 0
42399 - 0 0 1 0 0 1 0 0 1 0 0 0
42400 - 0 0 0 0 0 0 0 0 0 0 0 0
42401 - 0 0 0 0 0 0 0 0 0 0 0 0
42402 - 0 0 0 0 0 0 0 0 0 0 0 0
42403 - 0 0 0 0 0 0 0 0 0 0 0 0
42404 - 0 0 0 0 0 0 0 0 0 14 14 14
42405 - 46 46 46 86 86 86 2 2 6 54 54 54
42406 -218 218 218 195 195 195 226 226 226 246 246 246
42407 - 58 58 58 2 2 6 2 2 6 30 30 30
42408 -210 210 210 253 253 253 174 174 174 123 123 123
42409 -221 221 221 234 234 234 74 74 74 2 2 6
42410 - 2 2 6 2 2 6 2 2 6 2 2 6
42411 - 70 70 70 58 58 58 22 22 22 6 6 6
42412 - 0 0 0 0 0 0 0 0 0 0 0 0
42413 - 0 0 0 0 0 0 0 0 0 0 0 0
42414 - 0 0 0 0 0 0 0 0 0 0 0 0
42415 - 0 0 0 0 0 0 0 0 0 0 0 0
42416 - 0 0 0 0 0 0 0 0 0 0 0 0
42417 - 0 0 0 0 0 0 0 0 0 0 0 0
42418 - 0 0 0 0 0 0 0 0 0 0 0 0
42419 - 0 0 0 0 0 0 0 0 0 0 0 0
42420 - 0 0 0 0 0 0 0 0 0 0 0 0
42421 - 0 0 0 0 0 0 0 0 0 0 0 0
42422 - 0 0 0 0 0 0 0 0 0 0 0 0
42423 - 0 0 0 0 0 0 0 0 0 0 0 0
42424 - 0 0 0 0 0 0 0 0 0 14 14 14
42425 - 46 46 46 82 82 82 2 2 6 106 106 106
42426 -170 170 170 26 26 26 86 86 86 226 226 226
42427 -123 123 123 10 10 10 14 14 14 46 46 46
42428 -231 231 231 190 190 190 6 6 6 70 70 70
42429 - 90 90 90 238 238 238 158 158 158 2 2 6
42430 - 2 2 6 2 2 6 2 2 6 2 2 6
42431 - 70 70 70 58 58 58 22 22 22 6 6 6
42432 - 0 0 0 0 0 0 0 0 0 0 0 0
42433 - 0 0 0 0 0 0 0 0 0 0 0 0
42434 - 0 0 0 0 0 0 0 0 0 0 0 0
42435 - 0 0 0 0 0 0 0 0 0 0 0 0
42436 - 0 0 0 0 0 0 0 0 0 0 0 0
42437 - 0 0 0 0 0 0 0 0 0 0 0 0
42438 - 0 0 0 0 0 0 0 0 1 0 0 0
42439 - 0 0 1 0 0 1 0 0 1 0 0 0
42440 - 0 0 0 0 0 0 0 0 0 0 0 0
42441 - 0 0 0 0 0 0 0 0 0 0 0 0
42442 - 0 0 0 0 0 0 0 0 0 0 0 0
42443 - 0 0 0 0 0 0 0 0 0 0 0 0
42444 - 0 0 0 0 0 0 0 0 0 14 14 14
42445 - 42 42 42 86 86 86 6 6 6 116 116 116
42446 -106 106 106 6 6 6 70 70 70 149 149 149
42447 -128 128 128 18 18 18 38 38 38 54 54 54
42448 -221 221 221 106 106 106 2 2 6 14 14 14
42449 - 46 46 46 190 190 190 198 198 198 2 2 6
42450 - 2 2 6 2 2 6 2 2 6 2 2 6
42451 - 74 74 74 62 62 62 22 22 22 6 6 6
42452 - 0 0 0 0 0 0 0 0 0 0 0 0
42453 - 0 0 0 0 0 0 0 0 0 0 0 0
42454 - 0 0 0 0 0 0 0 0 0 0 0 0
42455 - 0 0 0 0 0 0 0 0 0 0 0 0
42456 - 0 0 0 0 0 0 0 0 0 0 0 0
42457 - 0 0 0 0 0 0 0 0 0 0 0 0
42458 - 0 0 0 0 0 0 0 0 1 0 0 0
42459 - 0 0 1 0 0 0 0 0 1 0 0 0
42460 - 0 0 0 0 0 0 0 0 0 0 0 0
42461 - 0 0 0 0 0 0 0 0 0 0 0 0
42462 - 0 0 0 0 0 0 0 0 0 0 0 0
42463 - 0 0 0 0 0 0 0 0 0 0 0 0
42464 - 0 0 0 0 0 0 0 0 0 14 14 14
42465 - 42 42 42 94 94 94 14 14 14 101 101 101
42466 -128 128 128 2 2 6 18 18 18 116 116 116
42467 -118 98 46 121 92 8 121 92 8 98 78 10
42468 -162 162 162 106 106 106 2 2 6 2 2 6
42469 - 2 2 6 195 195 195 195 195 195 6 6 6
42470 - 2 2 6 2 2 6 2 2 6 2 2 6
42471 - 74 74 74 62 62 62 22 22 22 6 6 6
42472 - 0 0 0 0 0 0 0 0 0 0 0 0
42473 - 0 0 0 0 0 0 0 0 0 0 0 0
42474 - 0 0 0 0 0 0 0 0 0 0 0 0
42475 - 0 0 0 0 0 0 0 0 0 0 0 0
42476 - 0 0 0 0 0 0 0 0 0 0 0 0
42477 - 0 0 0 0 0 0 0 0 0 0 0 0
42478 - 0 0 0 0 0 0 0 0 1 0 0 1
42479 - 0 0 1 0 0 0 0 0 1 0 0 0
42480 - 0 0 0 0 0 0 0 0 0 0 0 0
42481 - 0 0 0 0 0 0 0 0 0 0 0 0
42482 - 0 0 0 0 0 0 0 0 0 0 0 0
42483 - 0 0 0 0 0 0 0 0 0 0 0 0
42484 - 0 0 0 0 0 0 0 0 0 10 10 10
42485 - 38 38 38 90 90 90 14 14 14 58 58 58
42486 -210 210 210 26 26 26 54 38 6 154 114 10
42487 -226 170 11 236 186 11 225 175 15 184 144 12
42488 -215 174 15 175 146 61 37 26 9 2 2 6
42489 - 70 70 70 246 246 246 138 138 138 2 2 6
42490 - 2 2 6 2 2 6 2 2 6 2 2 6
42491 - 70 70 70 66 66 66 26 26 26 6 6 6
42492 - 0 0 0 0 0 0 0 0 0 0 0 0
42493 - 0 0 0 0 0 0 0 0 0 0 0 0
42494 - 0 0 0 0 0 0 0 0 0 0 0 0
42495 - 0 0 0 0 0 0 0 0 0 0 0 0
42496 - 0 0 0 0 0 0 0 0 0 0 0 0
42497 - 0 0 0 0 0 0 0 0 0 0 0 0
42498 - 0 0 0 0 0 0 0 0 0 0 0 0
42499 - 0 0 0 0 0 0 0 0 0 0 0 0
42500 - 0 0 0 0 0 0 0 0 0 0 0 0
42501 - 0 0 0 0 0 0 0 0 0 0 0 0
42502 - 0 0 0 0 0 0 0 0 0 0 0 0
42503 - 0 0 0 0 0 0 0 0 0 0 0 0
42504 - 0 0 0 0 0 0 0 0 0 10 10 10
42505 - 38 38 38 86 86 86 14 14 14 10 10 10
42506 -195 195 195 188 164 115 192 133 9 225 175 15
42507 -239 182 13 234 190 10 232 195 16 232 200 30
42508 -245 207 45 241 208 19 232 195 16 184 144 12
42509 -218 194 134 211 206 186 42 42 42 2 2 6
42510 - 2 2 6 2 2 6 2 2 6 2 2 6
42511 - 50 50 50 74 74 74 30 30 30 6 6 6
42512 - 0 0 0 0 0 0 0 0 0 0 0 0
42513 - 0 0 0 0 0 0 0 0 0 0 0 0
42514 - 0 0 0 0 0 0 0 0 0 0 0 0
42515 - 0 0 0 0 0 0 0 0 0 0 0 0
42516 - 0 0 0 0 0 0 0 0 0 0 0 0
42517 - 0 0 0 0 0 0 0 0 0 0 0 0
42518 - 0 0 0 0 0 0 0 0 0 0 0 0
42519 - 0 0 0 0 0 0 0 0 0 0 0 0
42520 - 0 0 0 0 0 0 0 0 0 0 0 0
42521 - 0 0 0 0 0 0 0 0 0 0 0 0
42522 - 0 0 0 0 0 0 0 0 0 0 0 0
42523 - 0 0 0 0 0 0 0 0 0 0 0 0
42524 - 0 0 0 0 0 0 0 0 0 10 10 10
42525 - 34 34 34 86 86 86 14 14 14 2 2 6
42526 -121 87 25 192 133 9 219 162 10 239 182 13
42527 -236 186 11 232 195 16 241 208 19 244 214 54
42528 -246 218 60 246 218 38 246 215 20 241 208 19
42529 -241 208 19 226 184 13 121 87 25 2 2 6
42530 - 2 2 6 2 2 6 2 2 6 2 2 6
42531 - 50 50 50 82 82 82 34 34 34 10 10 10
42532 - 0 0 0 0 0 0 0 0 0 0 0 0
42533 - 0 0 0 0 0 0 0 0 0 0 0 0
42534 - 0 0 0 0 0 0 0 0 0 0 0 0
42535 - 0 0 0 0 0 0 0 0 0 0 0 0
42536 - 0 0 0 0 0 0 0 0 0 0 0 0
42537 - 0 0 0 0 0 0 0 0 0 0 0 0
42538 - 0 0 0 0 0 0 0 0 0 0 0 0
42539 - 0 0 0 0 0 0 0 0 0 0 0 0
42540 - 0 0 0 0 0 0 0 0 0 0 0 0
42541 - 0 0 0 0 0 0 0 0 0 0 0 0
42542 - 0 0 0 0 0 0 0 0 0 0 0 0
42543 - 0 0 0 0 0 0 0 0 0 0 0 0
42544 - 0 0 0 0 0 0 0 0 0 10 10 10
42545 - 34 34 34 82 82 82 30 30 30 61 42 6
42546 -180 123 7 206 145 10 230 174 11 239 182 13
42547 -234 190 10 238 202 15 241 208 19 246 218 74
42548 -246 218 38 246 215 20 246 215 20 246 215 20
42549 -226 184 13 215 174 15 184 144 12 6 6 6
42550 - 2 2 6 2 2 6 2 2 6 2 2 6
42551 - 26 26 26 94 94 94 42 42 42 14 14 14
42552 - 0 0 0 0 0 0 0 0 0 0 0 0
42553 - 0 0 0 0 0 0 0 0 0 0 0 0
42554 - 0 0 0 0 0 0 0 0 0 0 0 0
42555 - 0 0 0 0 0 0 0 0 0 0 0 0
42556 - 0 0 0 0 0 0 0 0 0 0 0 0
42557 - 0 0 0 0 0 0 0 0 0 0 0 0
42558 - 0 0 0 0 0 0 0 0 0 0 0 0
42559 - 0 0 0 0 0 0 0 0 0 0 0 0
42560 - 0 0 0 0 0 0 0 0 0 0 0 0
42561 - 0 0 0 0 0 0 0 0 0 0 0 0
42562 - 0 0 0 0 0 0 0 0 0 0 0 0
42563 - 0 0 0 0 0 0 0 0 0 0 0 0
42564 - 0 0 0 0 0 0 0 0 0 10 10 10
42565 - 30 30 30 78 78 78 50 50 50 104 69 6
42566 -192 133 9 216 158 10 236 178 12 236 186 11
42567 -232 195 16 241 208 19 244 214 54 245 215 43
42568 -246 215 20 246 215 20 241 208 19 198 155 10
42569 -200 144 11 216 158 10 156 118 10 2 2 6
42570 - 2 2 6 2 2 6 2 2 6 2 2 6
42571 - 6 6 6 90 90 90 54 54 54 18 18 18
42572 - 6 6 6 0 0 0 0 0 0 0 0 0
42573 - 0 0 0 0 0 0 0 0 0 0 0 0
42574 - 0 0 0 0 0 0 0 0 0 0 0 0
42575 - 0 0 0 0 0 0 0 0 0 0 0 0
42576 - 0 0 0 0 0 0 0 0 0 0 0 0
42577 - 0 0 0 0 0 0 0 0 0 0 0 0
42578 - 0 0 0 0 0 0 0 0 0 0 0 0
42579 - 0 0 0 0 0 0 0 0 0 0 0 0
42580 - 0 0 0 0 0 0 0 0 0 0 0 0
42581 - 0 0 0 0 0 0 0 0 0 0 0 0
42582 - 0 0 0 0 0 0 0 0 0 0 0 0
42583 - 0 0 0 0 0 0 0 0 0 0 0 0
42584 - 0 0 0 0 0 0 0 0 0 10 10 10
42585 - 30 30 30 78 78 78 46 46 46 22 22 22
42586 -137 92 6 210 162 10 239 182 13 238 190 10
42587 -238 202 15 241 208 19 246 215 20 246 215 20
42588 -241 208 19 203 166 17 185 133 11 210 150 10
42589 -216 158 10 210 150 10 102 78 10 2 2 6
42590 - 6 6 6 54 54 54 14 14 14 2 2 6
42591 - 2 2 6 62 62 62 74 74 74 30 30 30
42592 - 10 10 10 0 0 0 0 0 0 0 0 0
42593 - 0 0 0 0 0 0 0 0 0 0 0 0
42594 - 0 0 0 0 0 0 0 0 0 0 0 0
42595 - 0 0 0 0 0 0 0 0 0 0 0 0
42596 - 0 0 0 0 0 0 0 0 0 0 0 0
42597 - 0 0 0 0 0 0 0 0 0 0 0 0
42598 - 0 0 0 0 0 0 0 0 0 0 0 0
42599 - 0 0 0 0 0 0 0 0 0 0 0 0
42600 - 0 0 0 0 0 0 0 0 0 0 0 0
42601 - 0 0 0 0 0 0 0 0 0 0 0 0
42602 - 0 0 0 0 0 0 0 0 0 0 0 0
42603 - 0 0 0 0 0 0 0 0 0 0 0 0
42604 - 0 0 0 0 0 0 0 0 0 10 10 10
42605 - 34 34 34 78 78 78 50 50 50 6 6 6
42606 - 94 70 30 139 102 15 190 146 13 226 184 13
42607 -232 200 30 232 195 16 215 174 15 190 146 13
42608 -168 122 10 192 133 9 210 150 10 213 154 11
42609 -202 150 34 182 157 106 101 98 89 2 2 6
42610 - 2 2 6 78 78 78 116 116 116 58 58 58
42611 - 2 2 6 22 22 22 90 90 90 46 46 46
42612 - 18 18 18 6 6 6 0 0 0 0 0 0
42613 - 0 0 0 0 0 0 0 0 0 0 0 0
42614 - 0 0 0 0 0 0 0 0 0 0 0 0
42615 - 0 0 0 0 0 0 0 0 0 0 0 0
42616 - 0 0 0 0 0 0 0 0 0 0 0 0
42617 - 0 0 0 0 0 0 0 0 0 0 0 0
42618 - 0 0 0 0 0 0 0 0 0 0 0 0
42619 - 0 0 0 0 0 0 0 0 0 0 0 0
42620 - 0 0 0 0 0 0 0 0 0 0 0 0
42621 - 0 0 0 0 0 0 0 0 0 0 0 0
42622 - 0 0 0 0 0 0 0 0 0 0 0 0
42623 - 0 0 0 0 0 0 0 0 0 0 0 0
42624 - 0 0 0 0 0 0 0 0 0 10 10 10
42625 - 38 38 38 86 86 86 50 50 50 6 6 6
42626 -128 128 128 174 154 114 156 107 11 168 122 10
42627 -198 155 10 184 144 12 197 138 11 200 144 11
42628 -206 145 10 206 145 10 197 138 11 188 164 115
42629 -195 195 195 198 198 198 174 174 174 14 14 14
42630 - 2 2 6 22 22 22 116 116 116 116 116 116
42631 - 22 22 22 2 2 6 74 74 74 70 70 70
42632 - 30 30 30 10 10 10 0 0 0 0 0 0
42633 - 0 0 0 0 0 0 0 0 0 0 0 0
42634 - 0 0 0 0 0 0 0 0 0 0 0 0
42635 - 0 0 0 0 0 0 0 0 0 0 0 0
42636 - 0 0 0 0 0 0 0 0 0 0 0 0
42637 - 0 0 0 0 0 0 0 0 0 0 0 0
42638 - 0 0 0 0 0 0 0 0 0 0 0 0
42639 - 0 0 0 0 0 0 0 0 0 0 0 0
42640 - 0 0 0 0 0 0 0 0 0 0 0 0
42641 - 0 0 0 0 0 0 0 0 0 0 0 0
42642 - 0 0 0 0 0 0 0 0 0 0 0 0
42643 - 0 0 0 0 0 0 0 0 0 0 0 0
42644 - 0 0 0 0 0 0 6 6 6 18 18 18
42645 - 50 50 50 101 101 101 26 26 26 10 10 10
42646 -138 138 138 190 190 190 174 154 114 156 107 11
42647 -197 138 11 200 144 11 197 138 11 192 133 9
42648 -180 123 7 190 142 34 190 178 144 187 187 187
42649 -202 202 202 221 221 221 214 214 214 66 66 66
42650 - 2 2 6 2 2 6 50 50 50 62 62 62
42651 - 6 6 6 2 2 6 10 10 10 90 90 90
42652 - 50 50 50 18 18 18 6 6 6 0 0 0
42653 - 0 0 0 0 0 0 0 0 0 0 0 0
42654 - 0 0 0 0 0 0 0 0 0 0 0 0
42655 - 0 0 0 0 0 0 0 0 0 0 0 0
42656 - 0 0 0 0 0 0 0 0 0 0 0 0
42657 - 0 0 0 0 0 0 0 0 0 0 0 0
42658 - 0 0 0 0 0 0 0 0 0 0 0 0
42659 - 0 0 0 0 0 0 0 0 0 0 0 0
42660 - 0 0 0 0 0 0 0 0 0 0 0 0
42661 - 0 0 0 0 0 0 0 0 0 0 0 0
42662 - 0 0 0 0 0 0 0 0 0 0 0 0
42663 - 0 0 0 0 0 0 0 0 0 0 0 0
42664 - 0 0 0 0 0 0 10 10 10 34 34 34
42665 - 74 74 74 74 74 74 2 2 6 6 6 6
42666 -144 144 144 198 198 198 190 190 190 178 166 146
42667 -154 121 60 156 107 11 156 107 11 168 124 44
42668 -174 154 114 187 187 187 190 190 190 210 210 210
42669 -246 246 246 253 253 253 253 253 253 182 182 182
42670 - 6 6 6 2 2 6 2 2 6 2 2 6
42671 - 2 2 6 2 2 6 2 2 6 62 62 62
42672 - 74 74 74 34 34 34 14 14 14 0 0 0
42673 - 0 0 0 0 0 0 0 0 0 0 0 0
42674 - 0 0 0 0 0 0 0 0 0 0 0 0
42675 - 0 0 0 0 0 0 0 0 0 0 0 0
42676 - 0 0 0 0 0 0 0 0 0 0 0 0
42677 - 0 0 0 0 0 0 0 0 0 0 0 0
42678 - 0 0 0 0 0 0 0 0 0 0 0 0
42679 - 0 0 0 0 0 0 0 0 0 0 0 0
42680 - 0 0 0 0 0 0 0 0 0 0 0 0
42681 - 0 0 0 0 0 0 0 0 0 0 0 0
42682 - 0 0 0 0 0 0 0 0 0 0 0 0
42683 - 0 0 0 0 0 0 0 0 0 0 0 0
42684 - 0 0 0 10 10 10 22 22 22 54 54 54
42685 - 94 94 94 18 18 18 2 2 6 46 46 46
42686 -234 234 234 221 221 221 190 190 190 190 190 190
42687 -190 190 190 187 187 187 187 187 187 190 190 190
42688 -190 190 190 195 195 195 214 214 214 242 242 242
42689 -253 253 253 253 253 253 253 253 253 253 253 253
42690 - 82 82 82 2 2 6 2 2 6 2 2 6
42691 - 2 2 6 2 2 6 2 2 6 14 14 14
42692 - 86 86 86 54 54 54 22 22 22 6 6 6
42693 - 0 0 0 0 0 0 0 0 0 0 0 0
42694 - 0 0 0 0 0 0 0 0 0 0 0 0
42695 - 0 0 0 0 0 0 0 0 0 0 0 0
42696 - 0 0 0 0 0 0 0 0 0 0 0 0
42697 - 0 0 0 0 0 0 0 0 0 0 0 0
42698 - 0 0 0 0 0 0 0 0 0 0 0 0
42699 - 0 0 0 0 0 0 0 0 0 0 0 0
42700 - 0 0 0 0 0 0 0 0 0 0 0 0
42701 - 0 0 0 0 0 0 0 0 0 0 0 0
42702 - 0 0 0 0 0 0 0 0 0 0 0 0
42703 - 0 0 0 0 0 0 0 0 0 0 0 0
42704 - 6 6 6 18 18 18 46 46 46 90 90 90
42705 - 46 46 46 18 18 18 6 6 6 182 182 182
42706 -253 253 253 246 246 246 206 206 206 190 190 190
42707 -190 190 190 190 190 190 190 190 190 190 190 190
42708 -206 206 206 231 231 231 250 250 250 253 253 253
42709 -253 253 253 253 253 253 253 253 253 253 253 253
42710 -202 202 202 14 14 14 2 2 6 2 2 6
42711 - 2 2 6 2 2 6 2 2 6 2 2 6
42712 - 42 42 42 86 86 86 42 42 42 18 18 18
42713 - 6 6 6 0 0 0 0 0 0 0 0 0
42714 - 0 0 0 0 0 0 0 0 0 0 0 0
42715 - 0 0 0 0 0 0 0 0 0 0 0 0
42716 - 0 0 0 0 0 0 0 0 0 0 0 0
42717 - 0 0 0 0 0 0 0 0 0 0 0 0
42718 - 0 0 0 0 0 0 0 0 0 0 0 0
42719 - 0 0 0 0 0 0 0 0 0 0 0 0
42720 - 0 0 0 0 0 0 0 0 0 0 0 0
42721 - 0 0 0 0 0 0 0 0 0 0 0 0
42722 - 0 0 0 0 0 0 0 0 0 0 0 0
42723 - 0 0 0 0 0 0 0 0 0 6 6 6
42724 - 14 14 14 38 38 38 74 74 74 66 66 66
42725 - 2 2 6 6 6 6 90 90 90 250 250 250
42726 -253 253 253 253 253 253 238 238 238 198 198 198
42727 -190 190 190 190 190 190 195 195 195 221 221 221
42728 -246 246 246 253 253 253 253 253 253 253 253 253
42729 -253 253 253 253 253 253 253 253 253 253 253 253
42730 -253 253 253 82 82 82 2 2 6 2 2 6
42731 - 2 2 6 2 2 6 2 2 6 2 2 6
42732 - 2 2 6 78 78 78 70 70 70 34 34 34
42733 - 14 14 14 6 6 6 0 0 0 0 0 0
42734 - 0 0 0 0 0 0 0 0 0 0 0 0
42735 - 0 0 0 0 0 0 0 0 0 0 0 0
42736 - 0 0 0 0 0 0 0 0 0 0 0 0
42737 - 0 0 0 0 0 0 0 0 0 0 0 0
42738 - 0 0 0 0 0 0 0 0 0 0 0 0
42739 - 0 0 0 0 0 0 0 0 0 0 0 0
42740 - 0 0 0 0 0 0 0 0 0 0 0 0
42741 - 0 0 0 0 0 0 0 0 0 0 0 0
42742 - 0 0 0 0 0 0 0 0 0 0 0 0
42743 - 0 0 0 0 0 0 0 0 0 14 14 14
42744 - 34 34 34 66 66 66 78 78 78 6 6 6
42745 - 2 2 6 18 18 18 218 218 218 253 253 253
42746 -253 253 253 253 253 253 253 253 253 246 246 246
42747 -226 226 226 231 231 231 246 246 246 253 253 253
42748 -253 253 253 253 253 253 253 253 253 253 253 253
42749 -253 253 253 253 253 253 253 253 253 253 253 253
42750 -253 253 253 178 178 178 2 2 6 2 2 6
42751 - 2 2 6 2 2 6 2 2 6 2 2 6
42752 - 2 2 6 18 18 18 90 90 90 62 62 62
42753 - 30 30 30 10 10 10 0 0 0 0 0 0
42754 - 0 0 0 0 0 0 0 0 0 0 0 0
42755 - 0 0 0 0 0 0 0 0 0 0 0 0
42756 - 0 0 0 0 0 0 0 0 0 0 0 0
42757 - 0 0 0 0 0 0 0 0 0 0 0 0
42758 - 0 0 0 0 0 0 0 0 0 0 0 0
42759 - 0 0 0 0 0 0 0 0 0 0 0 0
42760 - 0 0 0 0 0 0 0 0 0 0 0 0
42761 - 0 0 0 0 0 0 0 0 0 0 0 0
42762 - 0 0 0 0 0 0 0 0 0 0 0 0
42763 - 0 0 0 0 0 0 10 10 10 26 26 26
42764 - 58 58 58 90 90 90 18 18 18 2 2 6
42765 - 2 2 6 110 110 110 253 253 253 253 253 253
42766 -253 253 253 253 253 253 253 253 253 253 253 253
42767 -250 250 250 253 253 253 253 253 253 253 253 253
42768 -253 253 253 253 253 253 253 253 253 253 253 253
42769 -253 253 253 253 253 253 253 253 253 253 253 253
42770 -253 253 253 231 231 231 18 18 18 2 2 6
42771 - 2 2 6 2 2 6 2 2 6 2 2 6
42772 - 2 2 6 2 2 6 18 18 18 94 94 94
42773 - 54 54 54 26 26 26 10 10 10 0 0 0
42774 - 0 0 0 0 0 0 0 0 0 0 0 0
42775 - 0 0 0 0 0 0 0 0 0 0 0 0
42776 - 0 0 0 0 0 0 0 0 0 0 0 0
42777 - 0 0 0 0 0 0 0 0 0 0 0 0
42778 - 0 0 0 0 0 0 0 0 0 0 0 0
42779 - 0 0 0 0 0 0 0 0 0 0 0 0
42780 - 0 0 0 0 0 0 0 0 0 0 0 0
42781 - 0 0 0 0 0 0 0 0 0 0 0 0
42782 - 0 0 0 0 0 0 0 0 0 0 0 0
42783 - 0 0 0 6 6 6 22 22 22 50 50 50
42784 - 90 90 90 26 26 26 2 2 6 2 2 6
42785 - 14 14 14 195 195 195 250 250 250 253 253 253
42786 -253 253 253 253 253 253 253 253 253 253 253 253
42787 -253 253 253 253 253 253 253 253 253 253 253 253
42788 -253 253 253 253 253 253 253 253 253 253 253 253
42789 -253 253 253 253 253 253 253 253 253 253 253 253
42790 -250 250 250 242 242 242 54 54 54 2 2 6
42791 - 2 2 6 2 2 6 2 2 6 2 2 6
42792 - 2 2 6 2 2 6 2 2 6 38 38 38
42793 - 86 86 86 50 50 50 22 22 22 6 6 6
42794 - 0 0 0 0 0 0 0 0 0 0 0 0
42795 - 0 0 0 0 0 0 0 0 0 0 0 0
42796 - 0 0 0 0 0 0 0 0 0 0 0 0
42797 - 0 0 0 0 0 0 0 0 0 0 0 0
42798 - 0 0 0 0 0 0 0 0 0 0 0 0
42799 - 0 0 0 0 0 0 0 0 0 0 0 0
42800 - 0 0 0 0 0 0 0 0 0 0 0 0
42801 - 0 0 0 0 0 0 0 0 0 0 0 0
42802 - 0 0 0 0 0 0 0 0 0 0 0 0
42803 - 6 6 6 14 14 14 38 38 38 82 82 82
42804 - 34 34 34 2 2 6 2 2 6 2 2 6
42805 - 42 42 42 195 195 195 246 246 246 253 253 253
42806 -253 253 253 253 253 253 253 253 253 250 250 250
42807 -242 242 242 242 242 242 250 250 250 253 253 253
42808 -253 253 253 253 253 253 253 253 253 253 253 253
42809 -253 253 253 250 250 250 246 246 246 238 238 238
42810 -226 226 226 231 231 231 101 101 101 6 6 6
42811 - 2 2 6 2 2 6 2 2 6 2 2 6
42812 - 2 2 6 2 2 6 2 2 6 2 2 6
42813 - 38 38 38 82 82 82 42 42 42 14 14 14
42814 - 6 6 6 0 0 0 0 0 0 0 0 0
42815 - 0 0 0 0 0 0 0 0 0 0 0 0
42816 - 0 0 0 0 0 0 0 0 0 0 0 0
42817 - 0 0 0 0 0 0 0 0 0 0 0 0
42818 - 0 0 0 0 0 0 0 0 0 0 0 0
42819 - 0 0 0 0 0 0 0 0 0 0 0 0
42820 - 0 0 0 0 0 0 0 0 0 0 0 0
42821 - 0 0 0 0 0 0 0 0 0 0 0 0
42822 - 0 0 0 0 0 0 0 0 0 0 0 0
42823 - 10 10 10 26 26 26 62 62 62 66 66 66
42824 - 2 2 6 2 2 6 2 2 6 6 6 6
42825 - 70 70 70 170 170 170 206 206 206 234 234 234
42826 -246 246 246 250 250 250 250 250 250 238 238 238
42827 -226 226 226 231 231 231 238 238 238 250 250 250
42828 -250 250 250 250 250 250 246 246 246 231 231 231
42829 -214 214 214 206 206 206 202 202 202 202 202 202
42830 -198 198 198 202 202 202 182 182 182 18 18 18
42831 - 2 2 6 2 2 6 2 2 6 2 2 6
42832 - 2 2 6 2 2 6 2 2 6 2 2 6
42833 - 2 2 6 62 62 62 66 66 66 30 30 30
42834 - 10 10 10 0 0 0 0 0 0 0 0 0
42835 - 0 0 0 0 0 0 0 0 0 0 0 0
42836 - 0 0 0 0 0 0 0 0 0 0 0 0
42837 - 0 0 0 0 0 0 0 0 0 0 0 0
42838 - 0 0 0 0 0 0 0 0 0 0 0 0
42839 - 0 0 0 0 0 0 0 0 0 0 0 0
42840 - 0 0 0 0 0 0 0 0 0 0 0 0
42841 - 0 0 0 0 0 0 0 0 0 0 0 0
42842 - 0 0 0 0 0 0 0 0 0 0 0 0
42843 - 14 14 14 42 42 42 82 82 82 18 18 18
42844 - 2 2 6 2 2 6 2 2 6 10 10 10
42845 - 94 94 94 182 182 182 218 218 218 242 242 242
42846 -250 250 250 253 253 253 253 253 253 250 250 250
42847 -234 234 234 253 253 253 253 253 253 253 253 253
42848 -253 253 253 253 253 253 253 253 253 246 246 246
42849 -238 238 238 226 226 226 210 210 210 202 202 202
42850 -195 195 195 195 195 195 210 210 210 158 158 158
42851 - 6 6 6 14 14 14 50 50 50 14 14 14
42852 - 2 2 6 2 2 6 2 2 6 2 2 6
42853 - 2 2 6 6 6 6 86 86 86 46 46 46
42854 - 18 18 18 6 6 6 0 0 0 0 0 0
42855 - 0 0 0 0 0 0 0 0 0 0 0 0
42856 - 0 0 0 0 0 0 0 0 0 0 0 0
42857 - 0 0 0 0 0 0 0 0 0 0 0 0
42858 - 0 0 0 0 0 0 0 0 0 0 0 0
42859 - 0 0 0 0 0 0 0 0 0 0 0 0
42860 - 0 0 0 0 0 0 0 0 0 0 0 0
42861 - 0 0 0 0 0 0 0 0 0 0 0 0
42862 - 0 0 0 0 0 0 0 0 0 6 6 6
42863 - 22 22 22 54 54 54 70 70 70 2 2 6
42864 - 2 2 6 10 10 10 2 2 6 22 22 22
42865 -166 166 166 231 231 231 250 250 250 253 253 253
42866 -253 253 253 253 253 253 253 253 253 250 250 250
42867 -242 242 242 253 253 253 253 253 253 253 253 253
42868 -253 253 253 253 253 253 253 253 253 253 253 253
42869 -253 253 253 253 253 253 253 253 253 246 246 246
42870 -231 231 231 206 206 206 198 198 198 226 226 226
42871 - 94 94 94 2 2 6 6 6 6 38 38 38
42872 - 30 30 30 2 2 6 2 2 6 2 2 6
42873 - 2 2 6 2 2 6 62 62 62 66 66 66
42874 - 26 26 26 10 10 10 0 0 0 0 0 0
42875 - 0 0 0 0 0 0 0 0 0 0 0 0
42876 - 0 0 0 0 0 0 0 0 0 0 0 0
42877 - 0 0 0 0 0 0 0 0 0 0 0 0
42878 - 0 0 0 0 0 0 0 0 0 0 0 0
42879 - 0 0 0 0 0 0 0 0 0 0 0 0
42880 - 0 0 0 0 0 0 0 0 0 0 0 0
42881 - 0 0 0 0 0 0 0 0 0 0 0 0
42882 - 0 0 0 0 0 0 0 0 0 10 10 10
42883 - 30 30 30 74 74 74 50 50 50 2 2 6
42884 - 26 26 26 26 26 26 2 2 6 106 106 106
42885 -238 238 238 253 253 253 253 253 253 253 253 253
42886 -253 253 253 253 253 253 253 253 253 253 253 253
42887 -253 253 253 253 253 253 253 253 253 253 253 253
42888 -253 253 253 253 253 253 253 253 253 253 253 253
42889 -253 253 253 253 253 253 253 253 253 253 253 253
42890 -253 253 253 246 246 246 218 218 218 202 202 202
42891 -210 210 210 14 14 14 2 2 6 2 2 6
42892 - 30 30 30 22 22 22 2 2 6 2 2 6
42893 - 2 2 6 2 2 6 18 18 18 86 86 86
42894 - 42 42 42 14 14 14 0 0 0 0 0 0
42895 - 0 0 0 0 0 0 0 0 0 0 0 0
42896 - 0 0 0 0 0 0 0 0 0 0 0 0
42897 - 0 0 0 0 0 0 0 0 0 0 0 0
42898 - 0 0 0 0 0 0 0 0 0 0 0 0
42899 - 0 0 0 0 0 0 0 0 0 0 0 0
42900 - 0 0 0 0 0 0 0 0 0 0 0 0
42901 - 0 0 0 0 0 0 0 0 0 0 0 0
42902 - 0 0 0 0 0 0 0 0 0 14 14 14
42903 - 42 42 42 90 90 90 22 22 22 2 2 6
42904 - 42 42 42 2 2 6 18 18 18 218 218 218
42905 -253 253 253 253 253 253 253 253 253 253 253 253
42906 -253 253 253 253 253 253 253 253 253 253 253 253
42907 -253 253 253 253 253 253 253 253 253 253 253 253
42908 -253 253 253 253 253 253 253 253 253 253 253 253
42909 -253 253 253 253 253 253 253 253 253 253 253 253
42910 -253 253 253 253 253 253 250 250 250 221 221 221
42911 -218 218 218 101 101 101 2 2 6 14 14 14
42912 - 18 18 18 38 38 38 10 10 10 2 2 6
42913 - 2 2 6 2 2 6 2 2 6 78 78 78
42914 - 58 58 58 22 22 22 6 6 6 0 0 0
42915 - 0 0 0 0 0 0 0 0 0 0 0 0
42916 - 0 0 0 0 0 0 0 0 0 0 0 0
42917 - 0 0 0 0 0 0 0 0 0 0 0 0
42918 - 0 0 0 0 0 0 0 0 0 0 0 0
42919 - 0 0 0 0 0 0 0 0 0 0 0 0
42920 - 0 0 0 0 0 0 0 0 0 0 0 0
42921 - 0 0 0 0 0 0 0 0 0 0 0 0
42922 - 0 0 0 0 0 0 6 6 6 18 18 18
42923 - 54 54 54 82 82 82 2 2 6 26 26 26
42924 - 22 22 22 2 2 6 123 123 123 253 253 253
42925 -253 253 253 253 253 253 253 253 253 253 253 253
42926 -253 253 253 253 253 253 253 253 253 253 253 253
42927 -253 253 253 253 253 253 253 253 253 253 253 253
42928 -253 253 253 253 253 253 253 253 253 253 253 253
42929 -253 253 253 253 253 253 253 253 253 253 253 253
42930 -253 253 253 253 253 253 253 253 253 250 250 250
42931 -238 238 238 198 198 198 6 6 6 38 38 38
42932 - 58 58 58 26 26 26 38 38 38 2 2 6
42933 - 2 2 6 2 2 6 2 2 6 46 46 46
42934 - 78 78 78 30 30 30 10 10 10 0 0 0
42935 - 0 0 0 0 0 0 0 0 0 0 0 0
42936 - 0 0 0 0 0 0 0 0 0 0 0 0
42937 - 0 0 0 0 0 0 0 0 0 0 0 0
42938 - 0 0 0 0 0 0 0 0 0 0 0 0
42939 - 0 0 0 0 0 0 0 0 0 0 0 0
42940 - 0 0 0 0 0 0 0 0 0 0 0 0
42941 - 0 0 0 0 0 0 0 0 0 0 0 0
42942 - 0 0 0 0 0 0 10 10 10 30 30 30
42943 - 74 74 74 58 58 58 2 2 6 42 42 42
42944 - 2 2 6 22 22 22 231 231 231 253 253 253
42945 -253 253 253 253 253 253 253 253 253 253 253 253
42946 -253 253 253 253 253 253 253 253 253 250 250 250
42947 -253 253 253 253 253 253 253 253 253 253 253 253
42948 -253 253 253 253 253 253 253 253 253 253 253 253
42949 -253 253 253 253 253 253 253 253 253 253 253 253
42950 -253 253 253 253 253 253 253 253 253 253 253 253
42951 -253 253 253 246 246 246 46 46 46 38 38 38
42952 - 42 42 42 14 14 14 38 38 38 14 14 14
42953 - 2 2 6 2 2 6 2 2 6 6 6 6
42954 - 86 86 86 46 46 46 14 14 14 0 0 0
42955 - 0 0 0 0 0 0 0 0 0 0 0 0
42956 - 0 0 0 0 0 0 0 0 0 0 0 0
42957 - 0 0 0 0 0 0 0 0 0 0 0 0
42958 - 0 0 0 0 0 0 0 0 0 0 0 0
42959 - 0 0 0 0 0 0 0 0 0 0 0 0
42960 - 0 0 0 0 0 0 0 0 0 0 0 0
42961 - 0 0 0 0 0 0 0 0 0 0 0 0
42962 - 0 0 0 6 6 6 14 14 14 42 42 42
42963 - 90 90 90 18 18 18 18 18 18 26 26 26
42964 - 2 2 6 116 116 116 253 253 253 253 253 253
42965 -253 253 253 253 253 253 253 253 253 253 253 253
42966 -253 253 253 253 253 253 250 250 250 238 238 238
42967 -253 253 253 253 253 253 253 253 253 253 253 253
42968 -253 253 253 253 253 253 253 253 253 253 253 253
42969 -253 253 253 253 253 253 253 253 253 253 253 253
42970 -253 253 253 253 253 253 253 253 253 253 253 253
42971 -253 253 253 253 253 253 94 94 94 6 6 6
42972 - 2 2 6 2 2 6 10 10 10 34 34 34
42973 - 2 2 6 2 2 6 2 2 6 2 2 6
42974 - 74 74 74 58 58 58 22 22 22 6 6 6
42975 - 0 0 0 0 0 0 0 0 0 0 0 0
42976 - 0 0 0 0 0 0 0 0 0 0 0 0
42977 - 0 0 0 0 0 0 0 0 0 0 0 0
42978 - 0 0 0 0 0 0 0 0 0 0 0 0
42979 - 0 0 0 0 0 0 0 0 0 0 0 0
42980 - 0 0 0 0 0 0 0 0 0 0 0 0
42981 - 0 0 0 0 0 0 0 0 0 0 0 0
42982 - 0 0 0 10 10 10 26 26 26 66 66 66
42983 - 82 82 82 2 2 6 38 38 38 6 6 6
42984 - 14 14 14 210 210 210 253 253 253 253 253 253
42985 -253 253 253 253 253 253 253 253 253 253 253 253
42986 -253 253 253 253 253 253 246 246 246 242 242 242
42987 -253 253 253 253 253 253 253 253 253 253 253 253
42988 -253 253 253 253 253 253 253 253 253 253 253 253
42989 -253 253 253 253 253 253 253 253 253 253 253 253
42990 -253 253 253 253 253 253 253 253 253 253 253 253
42991 -253 253 253 253 253 253 144 144 144 2 2 6
42992 - 2 2 6 2 2 6 2 2 6 46 46 46
42993 - 2 2 6 2 2 6 2 2 6 2 2 6
42994 - 42 42 42 74 74 74 30 30 30 10 10 10
42995 - 0 0 0 0 0 0 0 0 0 0 0 0
42996 - 0 0 0 0 0 0 0 0 0 0 0 0
42997 - 0 0 0 0 0 0 0 0 0 0 0 0
42998 - 0 0 0 0 0 0 0 0 0 0 0 0
42999 - 0 0 0 0 0 0 0 0 0 0 0 0
43000 - 0 0 0 0 0 0 0 0 0 0 0 0
43001 - 0 0 0 0 0 0 0 0 0 0 0 0
43002 - 6 6 6 14 14 14 42 42 42 90 90 90
43003 - 26 26 26 6 6 6 42 42 42 2 2 6
43004 - 74 74 74 250 250 250 253 253 253 253 253 253
43005 -253 253 253 253 253 253 253 253 253 253 253 253
43006 -253 253 253 253 253 253 242 242 242 242 242 242
43007 -253 253 253 253 253 253 253 253 253 253 253 253
43008 -253 253 253 253 253 253 253 253 253 253 253 253
43009 -253 253 253 253 253 253 253 253 253 253 253 253
43010 -253 253 253 253 253 253 253 253 253 253 253 253
43011 -253 253 253 253 253 253 182 182 182 2 2 6
43012 - 2 2 6 2 2 6 2 2 6 46 46 46
43013 - 2 2 6 2 2 6 2 2 6 2 2 6
43014 - 10 10 10 86 86 86 38 38 38 10 10 10
43015 - 0 0 0 0 0 0 0 0 0 0 0 0
43016 - 0 0 0 0 0 0 0 0 0 0 0 0
43017 - 0 0 0 0 0 0 0 0 0 0 0 0
43018 - 0 0 0 0 0 0 0 0 0 0 0 0
43019 - 0 0 0 0 0 0 0 0 0 0 0 0
43020 - 0 0 0 0 0 0 0 0 0 0 0 0
43021 - 0 0 0 0 0 0 0 0 0 0 0 0
43022 - 10 10 10 26 26 26 66 66 66 82 82 82
43023 - 2 2 6 22 22 22 18 18 18 2 2 6
43024 -149 149 149 253 253 253 253 253 253 253 253 253
43025 -253 253 253 253 253 253 253 253 253 253 253 253
43026 -253 253 253 253 253 253 234 234 234 242 242 242
43027 -253 253 253 253 253 253 253 253 253 253 253 253
43028 -253 253 253 253 253 253 253 253 253 253 253 253
43029 -253 253 253 253 253 253 253 253 253 253 253 253
43030 -253 253 253 253 253 253 253 253 253 253 253 253
43031 -253 253 253 253 253 253 206 206 206 2 2 6
43032 - 2 2 6 2 2 6 2 2 6 38 38 38
43033 - 2 2 6 2 2 6 2 2 6 2 2 6
43034 - 6 6 6 86 86 86 46 46 46 14 14 14
43035 - 0 0 0 0 0 0 0 0 0 0 0 0
43036 - 0 0 0 0 0 0 0 0 0 0 0 0
43037 - 0 0 0 0 0 0 0 0 0 0 0 0
43038 - 0 0 0 0 0 0 0 0 0 0 0 0
43039 - 0 0 0 0 0 0 0 0 0 0 0 0
43040 - 0 0 0 0 0 0 0 0 0 0 0 0
43041 - 0 0 0 0 0 0 0 0 0 6 6 6
43042 - 18 18 18 46 46 46 86 86 86 18 18 18
43043 - 2 2 6 34 34 34 10 10 10 6 6 6
43044 -210 210 210 253 253 253 253 253 253 253 253 253
43045 -253 253 253 253 253 253 253 253 253 253 253 253
43046 -253 253 253 253 253 253 234 234 234 242 242 242
43047 -253 253 253 253 253 253 253 253 253 253 253 253
43048 -253 253 253 253 253 253 253 253 253 253 253 253
43049 -253 253 253 253 253 253 253 253 253 253 253 253
43050 -253 253 253 253 253 253 253 253 253 253 253 253
43051 -253 253 253 253 253 253 221 221 221 6 6 6
43052 - 2 2 6 2 2 6 6 6 6 30 30 30
43053 - 2 2 6 2 2 6 2 2 6 2 2 6
43054 - 2 2 6 82 82 82 54 54 54 18 18 18
43055 - 6 6 6 0 0 0 0 0 0 0 0 0
43056 - 0 0 0 0 0 0 0 0 0 0 0 0
43057 - 0 0 0 0 0 0 0 0 0 0 0 0
43058 - 0 0 0 0 0 0 0 0 0 0 0 0
43059 - 0 0 0 0 0 0 0 0 0 0 0 0
43060 - 0 0 0 0 0 0 0 0 0 0 0 0
43061 - 0 0 0 0 0 0 0 0 0 10 10 10
43062 - 26 26 26 66 66 66 62 62 62 2 2 6
43063 - 2 2 6 38 38 38 10 10 10 26 26 26
43064 -238 238 238 253 253 253 253 253 253 253 253 253
43065 -253 253 253 253 253 253 253 253 253 253 253 253
43066 -253 253 253 253 253 253 231 231 231 238 238 238
43067 -253 253 253 253 253 253 253 253 253 253 253 253
43068 -253 253 253 253 253 253 253 253 253 253 253 253
43069 -253 253 253 253 253 253 253 253 253 253 253 253
43070 -253 253 253 253 253 253 253 253 253 253 253 253
43071 -253 253 253 253 253 253 231 231 231 6 6 6
43072 - 2 2 6 2 2 6 10 10 10 30 30 30
43073 - 2 2 6 2 2 6 2 2 6 2 2 6
43074 - 2 2 6 66 66 66 58 58 58 22 22 22
43075 - 6 6 6 0 0 0 0 0 0 0 0 0
43076 - 0 0 0 0 0 0 0 0 0 0 0 0
43077 - 0 0 0 0 0 0 0 0 0 0 0 0
43078 - 0 0 0 0 0 0 0 0 0 0 0 0
43079 - 0 0 0 0 0 0 0 0 0 0 0 0
43080 - 0 0 0 0 0 0 0 0 0 0 0 0
43081 - 0 0 0 0 0 0 0 0 0 10 10 10
43082 - 38 38 38 78 78 78 6 6 6 2 2 6
43083 - 2 2 6 46 46 46 14 14 14 42 42 42
43084 -246 246 246 253 253 253 253 253 253 253 253 253
43085 -253 253 253 253 253 253 253 253 253 253 253 253
43086 -253 253 253 253 253 253 231 231 231 242 242 242
43087 -253 253 253 253 253 253 253 253 253 253 253 253
43088 -253 253 253 253 253 253 253 253 253 253 253 253
43089 -253 253 253 253 253 253 253 253 253 253 253 253
43090 -253 253 253 253 253 253 253 253 253 253 253 253
43091 -253 253 253 253 253 253 234 234 234 10 10 10
43092 - 2 2 6 2 2 6 22 22 22 14 14 14
43093 - 2 2 6 2 2 6 2 2 6 2 2 6
43094 - 2 2 6 66 66 66 62 62 62 22 22 22
43095 - 6 6 6 0 0 0 0 0 0 0 0 0
43096 - 0 0 0 0 0 0 0 0 0 0 0 0
43097 - 0 0 0 0 0 0 0 0 0 0 0 0
43098 - 0 0 0 0 0 0 0 0 0 0 0 0
43099 - 0 0 0 0 0 0 0 0 0 0 0 0
43100 - 0 0 0 0 0 0 0 0 0 0 0 0
43101 - 0 0 0 0 0 0 6 6 6 18 18 18
43102 - 50 50 50 74 74 74 2 2 6 2 2 6
43103 - 14 14 14 70 70 70 34 34 34 62 62 62
43104 -250 250 250 253 253 253 253 253 253 253 253 253
43105 -253 253 253 253 253 253 253 253 253 253 253 253
43106 -253 253 253 253 253 253 231 231 231 246 246 246
43107 -253 253 253 253 253 253 253 253 253 253 253 253
43108 -253 253 253 253 253 253 253 253 253 253 253 253
43109 -253 253 253 253 253 253 253 253 253 253 253 253
43110 -253 253 253 253 253 253 253 253 253 253 253 253
43111 -253 253 253 253 253 253 234 234 234 14 14 14
43112 - 2 2 6 2 2 6 30 30 30 2 2 6
43113 - 2 2 6 2 2 6 2 2 6 2 2 6
43114 - 2 2 6 66 66 66 62 62 62 22 22 22
43115 - 6 6 6 0 0 0 0 0 0 0 0 0
43116 - 0 0 0 0 0 0 0 0 0 0 0 0
43117 - 0 0 0 0 0 0 0 0 0 0 0 0
43118 - 0 0 0 0 0 0 0 0 0 0 0 0
43119 - 0 0 0 0 0 0 0 0 0 0 0 0
43120 - 0 0 0 0 0 0 0 0 0 0 0 0
43121 - 0 0 0 0 0 0 6 6 6 18 18 18
43122 - 54 54 54 62 62 62 2 2 6 2 2 6
43123 - 2 2 6 30 30 30 46 46 46 70 70 70
43124 -250 250 250 253 253 253 253 253 253 253 253 253
43125 -253 253 253 253 253 253 253 253 253 253 253 253
43126 -253 253 253 253 253 253 231 231 231 246 246 246
43127 -253 253 253 253 253 253 253 253 253 253 253 253
43128 -253 253 253 253 253 253 253 253 253 253 253 253
43129 -253 253 253 253 253 253 253 253 253 253 253 253
43130 -253 253 253 253 253 253 253 253 253 253 253 253
43131 -253 253 253 253 253 253 226 226 226 10 10 10
43132 - 2 2 6 6 6 6 30 30 30 2 2 6
43133 - 2 2 6 2 2 6 2 2 6 2 2 6
43134 - 2 2 6 66 66 66 58 58 58 22 22 22
43135 - 6 6 6 0 0 0 0 0 0 0 0 0
43136 - 0 0 0 0 0 0 0 0 0 0 0 0
43137 - 0 0 0 0 0 0 0 0 0 0 0 0
43138 - 0 0 0 0 0 0 0 0 0 0 0 0
43139 - 0 0 0 0 0 0 0 0 0 0 0 0
43140 - 0 0 0 0 0 0 0 0 0 0 0 0
43141 - 0 0 0 0 0 0 6 6 6 22 22 22
43142 - 58 58 58 62 62 62 2 2 6 2 2 6
43143 - 2 2 6 2 2 6 30 30 30 78 78 78
43144 -250 250 250 253 253 253 253 253 253 253 253 253
43145 -253 253 253 253 253 253 253 253 253 253 253 253
43146 -253 253 253 253 253 253 231 231 231 246 246 246
43147 -253 253 253 253 253 253 253 253 253 253 253 253
43148 -253 253 253 253 253 253 253 253 253 253 253 253
43149 -253 253 253 253 253 253 253 253 253 253 253 253
43150 -253 253 253 253 253 253 253 253 253 253 253 253
43151 -253 253 253 253 253 253 206 206 206 2 2 6
43152 - 22 22 22 34 34 34 18 14 6 22 22 22
43153 - 26 26 26 18 18 18 6 6 6 2 2 6
43154 - 2 2 6 82 82 82 54 54 54 18 18 18
43155 - 6 6 6 0 0 0 0 0 0 0 0 0
43156 - 0 0 0 0 0 0 0 0 0 0 0 0
43157 - 0 0 0 0 0 0 0 0 0 0 0 0
43158 - 0 0 0 0 0 0 0 0 0 0 0 0
43159 - 0 0 0 0 0 0 0 0 0 0 0 0
43160 - 0 0 0 0 0 0 0 0 0 0 0 0
43161 - 0 0 0 0 0 0 6 6 6 26 26 26
43162 - 62 62 62 106 106 106 74 54 14 185 133 11
43163 -210 162 10 121 92 8 6 6 6 62 62 62
43164 -238 238 238 253 253 253 253 253 253 253 253 253
43165 -253 253 253 253 253 253 253 253 253 253 253 253
43166 -253 253 253 253 253 253 231 231 231 246 246 246
43167 -253 253 253 253 253 253 253 253 253 253 253 253
43168 -253 253 253 253 253 253 253 253 253 253 253 253
43169 -253 253 253 253 253 253 253 253 253 253 253 253
43170 -253 253 253 253 253 253 253 253 253 253 253 253
43171 -253 253 253 253 253 253 158 158 158 18 18 18
43172 - 14 14 14 2 2 6 2 2 6 2 2 6
43173 - 6 6 6 18 18 18 66 66 66 38 38 38
43174 - 6 6 6 94 94 94 50 50 50 18 18 18
43175 - 6 6 6 0 0 0 0 0 0 0 0 0
43176 - 0 0 0 0 0 0 0 0 0 0 0 0
43177 - 0 0 0 0 0 0 0 0 0 0 0 0
43178 - 0 0 0 0 0 0 0 0 0 0 0 0
43179 - 0 0 0 0 0 0 0 0 0 0 0 0
43180 - 0 0 0 0 0 0 0 0 0 6 6 6
43181 - 10 10 10 10 10 10 18 18 18 38 38 38
43182 - 78 78 78 142 134 106 216 158 10 242 186 14
43183 -246 190 14 246 190 14 156 118 10 10 10 10
43184 - 90 90 90 238 238 238 253 253 253 253 253 253
43185 -253 253 253 253 253 253 253 253 253 253 253 253
43186 -253 253 253 253 253 253 231 231 231 250 250 250
43187 -253 253 253 253 253 253 253 253 253 253 253 253
43188 -253 253 253 253 253 253 253 253 253 253 253 253
43189 -253 253 253 253 253 253 253 253 253 253 253 253
43190 -253 253 253 253 253 253 253 253 253 246 230 190
43191 -238 204 91 238 204 91 181 142 44 37 26 9
43192 - 2 2 6 2 2 6 2 2 6 2 2 6
43193 - 2 2 6 2 2 6 38 38 38 46 46 46
43194 - 26 26 26 106 106 106 54 54 54 18 18 18
43195 - 6 6 6 0 0 0 0 0 0 0 0 0
43196 - 0 0 0 0 0 0 0 0 0 0 0 0
43197 - 0 0 0 0 0 0 0 0 0 0 0 0
43198 - 0 0 0 0 0 0 0 0 0 0 0 0
43199 - 0 0 0 0 0 0 0 0 0 0 0 0
43200 - 0 0 0 6 6 6 14 14 14 22 22 22
43201 - 30 30 30 38 38 38 50 50 50 70 70 70
43202 -106 106 106 190 142 34 226 170 11 242 186 14
43203 -246 190 14 246 190 14 246 190 14 154 114 10
43204 - 6 6 6 74 74 74 226 226 226 253 253 253
43205 -253 253 253 253 253 253 253 253 253 253 253 253
43206 -253 253 253 253 253 253 231 231 231 250 250 250
43207 -253 253 253 253 253 253 253 253 253 253 253 253
43208 -253 253 253 253 253 253 253 253 253 253 253 253
43209 -253 253 253 253 253 253 253 253 253 253 253 253
43210 -253 253 253 253 253 253 253 253 253 228 184 62
43211 -241 196 14 241 208 19 232 195 16 38 30 10
43212 - 2 2 6 2 2 6 2 2 6 2 2 6
43213 - 2 2 6 6 6 6 30 30 30 26 26 26
43214 -203 166 17 154 142 90 66 66 66 26 26 26
43215 - 6 6 6 0 0 0 0 0 0 0 0 0
43216 - 0 0 0 0 0 0 0 0 0 0 0 0
43217 - 0 0 0 0 0 0 0 0 0 0 0 0
43218 - 0 0 0 0 0 0 0 0 0 0 0 0
43219 - 0 0 0 0 0 0 0 0 0 0 0 0
43220 - 6 6 6 18 18 18 38 38 38 58 58 58
43221 - 78 78 78 86 86 86 101 101 101 123 123 123
43222 -175 146 61 210 150 10 234 174 13 246 186 14
43223 -246 190 14 246 190 14 246 190 14 238 190 10
43224 -102 78 10 2 2 6 46 46 46 198 198 198
43225 -253 253 253 253 253 253 253 253 253 253 253 253
43226 -253 253 253 253 253 253 234 234 234 242 242 242
43227 -253 253 253 253 253 253 253 253 253 253 253 253
43228 -253 253 253 253 253 253 253 253 253 253 253 253
43229 -253 253 253 253 253 253 253 253 253 253 253 253
43230 -253 253 253 253 253 253 253 253 253 224 178 62
43231 -242 186 14 241 196 14 210 166 10 22 18 6
43232 - 2 2 6 2 2 6 2 2 6 2 2 6
43233 - 2 2 6 2 2 6 6 6 6 121 92 8
43234 -238 202 15 232 195 16 82 82 82 34 34 34
43235 - 10 10 10 0 0 0 0 0 0 0 0 0
43236 - 0 0 0 0 0 0 0 0 0 0 0 0
43237 - 0 0 0 0 0 0 0 0 0 0 0 0
43238 - 0 0 0 0 0 0 0 0 0 0 0 0
43239 - 0 0 0 0 0 0 0 0 0 0 0 0
43240 - 14 14 14 38 38 38 70 70 70 154 122 46
43241 -190 142 34 200 144 11 197 138 11 197 138 11
43242 -213 154 11 226 170 11 242 186 14 246 190 14
43243 -246 190 14 246 190 14 246 190 14 246 190 14
43244 -225 175 15 46 32 6 2 2 6 22 22 22
43245 -158 158 158 250 250 250 253 253 253 253 253 253
43246 -253 253 253 253 253 253 253 253 253 253 253 253
43247 -253 253 253 253 253 253 253 253 253 253 253 253
43248 -253 253 253 253 253 253 253 253 253 253 253 253
43249 -253 253 253 253 253 253 253 253 253 253 253 253
43250 -253 253 253 250 250 250 242 242 242 224 178 62
43251 -239 182 13 236 186 11 213 154 11 46 32 6
43252 - 2 2 6 2 2 6 2 2 6 2 2 6
43253 - 2 2 6 2 2 6 61 42 6 225 175 15
43254 -238 190 10 236 186 11 112 100 78 42 42 42
43255 - 14 14 14 0 0 0 0 0 0 0 0 0
43256 - 0 0 0 0 0 0 0 0 0 0 0 0
43257 - 0 0 0 0 0 0 0 0 0 0 0 0
43258 - 0 0 0 0 0 0 0 0 0 0 0 0
43259 - 0 0 0 0 0 0 0 0 0 6 6 6
43260 - 22 22 22 54 54 54 154 122 46 213 154 11
43261 -226 170 11 230 174 11 226 170 11 226 170 11
43262 -236 178 12 242 186 14 246 190 14 246 190 14
43263 -246 190 14 246 190 14 246 190 14 246 190 14
43264 -241 196 14 184 144 12 10 10 10 2 2 6
43265 - 6 6 6 116 116 116 242 242 242 253 253 253
43266 -253 253 253 253 253 253 253 253 253 253 253 253
43267 -253 253 253 253 253 253 253 253 253 253 253 253
43268 -253 253 253 253 253 253 253 253 253 253 253 253
43269 -253 253 253 253 253 253 253 253 253 253 253 253
43270 -253 253 253 231 231 231 198 198 198 214 170 54
43271 -236 178 12 236 178 12 210 150 10 137 92 6
43272 - 18 14 6 2 2 6 2 2 6 2 2 6
43273 - 6 6 6 70 47 6 200 144 11 236 178 12
43274 -239 182 13 239 182 13 124 112 88 58 58 58
43275 - 22 22 22 6 6 6 0 0 0 0 0 0
43276 - 0 0 0 0 0 0 0 0 0 0 0 0
43277 - 0 0 0 0 0 0 0 0 0 0 0 0
43278 - 0 0 0 0 0 0 0 0 0 0 0 0
43279 - 0 0 0 0 0 0 0 0 0 10 10 10
43280 - 30 30 30 70 70 70 180 133 36 226 170 11
43281 -239 182 13 242 186 14 242 186 14 246 186 14
43282 -246 190 14 246 190 14 246 190 14 246 190 14
43283 -246 190 14 246 190 14 246 190 14 246 190 14
43284 -246 190 14 232 195 16 98 70 6 2 2 6
43285 - 2 2 6 2 2 6 66 66 66 221 221 221
43286 -253 253 253 253 253 253 253 253 253 253 253 253
43287 -253 253 253 253 253 253 253 253 253 253 253 253
43288 -253 253 253 253 253 253 253 253 253 253 253 253
43289 -253 253 253 253 253 253 253 253 253 253 253 253
43290 -253 253 253 206 206 206 198 198 198 214 166 58
43291 -230 174 11 230 174 11 216 158 10 192 133 9
43292 -163 110 8 116 81 8 102 78 10 116 81 8
43293 -167 114 7 197 138 11 226 170 11 239 182 13
43294 -242 186 14 242 186 14 162 146 94 78 78 78
43295 - 34 34 34 14 14 14 6 6 6 0 0 0
43296 - 0 0 0 0 0 0 0 0 0 0 0 0
43297 - 0 0 0 0 0 0 0 0 0 0 0 0
43298 - 0 0 0 0 0 0 0 0 0 0 0 0
43299 - 0 0 0 0 0 0 0 0 0 6 6 6
43300 - 30 30 30 78 78 78 190 142 34 226 170 11
43301 -239 182 13 246 190 14 246 190 14 246 190 14
43302 -246 190 14 246 190 14 246 190 14 246 190 14
43303 -246 190 14 246 190 14 246 190 14 246 190 14
43304 -246 190 14 241 196 14 203 166 17 22 18 6
43305 - 2 2 6 2 2 6 2 2 6 38 38 38
43306 -218 218 218 253 253 253 253 253 253 253 253 253
43307 -253 253 253 253 253 253 253 253 253 253 253 253
43308 -253 253 253 253 253 253 253 253 253 253 253 253
43309 -253 253 253 253 253 253 253 253 253 253 253 253
43310 -250 250 250 206 206 206 198 198 198 202 162 69
43311 -226 170 11 236 178 12 224 166 10 210 150 10
43312 -200 144 11 197 138 11 192 133 9 197 138 11
43313 -210 150 10 226 170 11 242 186 14 246 190 14
43314 -246 190 14 246 186 14 225 175 15 124 112 88
43315 - 62 62 62 30 30 30 14 14 14 6 6 6
43316 - 0 0 0 0 0 0 0 0 0 0 0 0
43317 - 0 0 0 0 0 0 0 0 0 0 0 0
43318 - 0 0 0 0 0 0 0 0 0 0 0 0
43319 - 0 0 0 0 0 0 0 0 0 10 10 10
43320 - 30 30 30 78 78 78 174 135 50 224 166 10
43321 -239 182 13 246 190 14 246 190 14 246 190 14
43322 -246 190 14 246 190 14 246 190 14 246 190 14
43323 -246 190 14 246 190 14 246 190 14 246 190 14
43324 -246 190 14 246 190 14 241 196 14 139 102 15
43325 - 2 2 6 2 2 6 2 2 6 2 2 6
43326 - 78 78 78 250 250 250 253 253 253 253 253 253
43327 -253 253 253 253 253 253 253 253 253 253 253 253
43328 -253 253 253 253 253 253 253 253 253 253 253 253
43329 -253 253 253 253 253 253 253 253 253 253 253 253
43330 -250 250 250 214 214 214 198 198 198 190 150 46
43331 -219 162 10 236 178 12 234 174 13 224 166 10
43332 -216 158 10 213 154 11 213 154 11 216 158 10
43333 -226 170 11 239 182 13 246 190 14 246 190 14
43334 -246 190 14 246 190 14 242 186 14 206 162 42
43335 -101 101 101 58 58 58 30 30 30 14 14 14
43336 - 6 6 6 0 0 0 0 0 0 0 0 0
43337 - 0 0 0 0 0 0 0 0 0 0 0 0
43338 - 0 0 0 0 0 0 0 0 0 0 0 0
43339 - 0 0 0 0 0 0 0 0 0 10 10 10
43340 - 30 30 30 74 74 74 174 135 50 216 158 10
43341 -236 178 12 246 190 14 246 190 14 246 190 14
43342 -246 190 14 246 190 14 246 190 14 246 190 14
43343 -246 190 14 246 190 14 246 190 14 246 190 14
43344 -246 190 14 246 190 14 241 196 14 226 184 13
43345 - 61 42 6 2 2 6 2 2 6 2 2 6
43346 - 22 22 22 238 238 238 253 253 253 253 253 253
43347 -253 253 253 253 253 253 253 253 253 253 253 253
43348 -253 253 253 253 253 253 253 253 253 253 253 253
43349 -253 253 253 253 253 253 253 253 253 253 253 253
43350 -253 253 253 226 226 226 187 187 187 180 133 36
43351 -216 158 10 236 178 12 239 182 13 236 178 12
43352 -230 174 11 226 170 11 226 170 11 230 174 11
43353 -236 178 12 242 186 14 246 190 14 246 190 14
43354 -246 190 14 246 190 14 246 186 14 239 182 13
43355 -206 162 42 106 106 106 66 66 66 34 34 34
43356 - 14 14 14 6 6 6 0 0 0 0 0 0
43357 - 0 0 0 0 0 0 0 0 0 0 0 0
43358 - 0 0 0 0 0 0 0 0 0 0 0 0
43359 - 0 0 0 0 0 0 0 0 0 6 6 6
43360 - 26 26 26 70 70 70 163 133 67 213 154 11
43361 -236 178 12 246 190 14 246 190 14 246 190 14
43362 -246 190 14 246 190 14 246 190 14 246 190 14
43363 -246 190 14 246 190 14 246 190 14 246 190 14
43364 -246 190 14 246 190 14 246 190 14 241 196 14
43365 -190 146 13 18 14 6 2 2 6 2 2 6
43366 - 46 46 46 246 246 246 253 253 253 253 253 253
43367 -253 253 253 253 253 253 253 253 253 253 253 253
43368 -253 253 253 253 253 253 253 253 253 253 253 253
43369 -253 253 253 253 253 253 253 253 253 253 253 253
43370 -253 253 253 221 221 221 86 86 86 156 107 11
43371 -216 158 10 236 178 12 242 186 14 246 186 14
43372 -242 186 14 239 182 13 239 182 13 242 186 14
43373 -242 186 14 246 186 14 246 190 14 246 190 14
43374 -246 190 14 246 190 14 246 190 14 246 190 14
43375 -242 186 14 225 175 15 142 122 72 66 66 66
43376 - 30 30 30 10 10 10 0 0 0 0 0 0
43377 - 0 0 0 0 0 0 0 0 0 0 0 0
43378 - 0 0 0 0 0 0 0 0 0 0 0 0
43379 - 0 0 0 0 0 0 0 0 0 6 6 6
43380 - 26 26 26 70 70 70 163 133 67 210 150 10
43381 -236 178 12 246 190 14 246 190 14 246 190 14
43382 -246 190 14 246 190 14 246 190 14 246 190 14
43383 -246 190 14 246 190 14 246 190 14 246 190 14
43384 -246 190 14 246 190 14 246 190 14 246 190 14
43385 -232 195 16 121 92 8 34 34 34 106 106 106
43386 -221 221 221 253 253 253 253 253 253 253 253 253
43387 -253 253 253 253 253 253 253 253 253 253 253 253
43388 -253 253 253 253 253 253 253 253 253 253 253 253
43389 -253 253 253 253 253 253 253 253 253 253 253 253
43390 -242 242 242 82 82 82 18 14 6 163 110 8
43391 -216 158 10 236 178 12 242 186 14 246 190 14
43392 -246 190 14 246 190 14 246 190 14 246 190 14
43393 -246 190 14 246 190 14 246 190 14 246 190 14
43394 -246 190 14 246 190 14 246 190 14 246 190 14
43395 -246 190 14 246 190 14 242 186 14 163 133 67
43396 - 46 46 46 18 18 18 6 6 6 0 0 0
43397 - 0 0 0 0 0 0 0 0 0 0 0 0
43398 - 0 0 0 0 0 0 0 0 0 0 0 0
43399 - 0 0 0 0 0 0 0 0 0 10 10 10
43400 - 30 30 30 78 78 78 163 133 67 210 150 10
43401 -236 178 12 246 186 14 246 190 14 246 190 14
43402 -246 190 14 246 190 14 246 190 14 246 190 14
43403 -246 190 14 246 190 14 246 190 14 246 190 14
43404 -246 190 14 246 190 14 246 190 14 246 190 14
43405 -241 196 14 215 174 15 190 178 144 253 253 253
43406 -253 253 253 253 253 253 253 253 253 253 253 253
43407 -253 253 253 253 253 253 253 253 253 253 253 253
43408 -253 253 253 253 253 253 253 253 253 253 253 253
43409 -253 253 253 253 253 253 253 253 253 218 218 218
43410 - 58 58 58 2 2 6 22 18 6 167 114 7
43411 -216 158 10 236 178 12 246 186 14 246 190 14
43412 -246 190 14 246 190 14 246 190 14 246 190 14
43413 -246 190 14 246 190 14 246 190 14 246 190 14
43414 -246 190 14 246 190 14 246 190 14 246 190 14
43415 -246 190 14 246 186 14 242 186 14 190 150 46
43416 - 54 54 54 22 22 22 6 6 6 0 0 0
43417 - 0 0 0 0 0 0 0 0 0 0 0 0
43418 - 0 0 0 0 0 0 0 0 0 0 0 0
43419 - 0 0 0 0 0 0 0 0 0 14 14 14
43420 - 38 38 38 86 86 86 180 133 36 213 154 11
43421 -236 178 12 246 186 14 246 190 14 246 190 14
43422 -246 190 14 246 190 14 246 190 14 246 190 14
43423 -246 190 14 246 190 14 246 190 14 246 190 14
43424 -246 190 14 246 190 14 246 190 14 246 190 14
43425 -246 190 14 232 195 16 190 146 13 214 214 214
43426 -253 253 253 253 253 253 253 253 253 253 253 253
43427 -253 253 253 253 253 253 253 253 253 253 253 253
43428 -253 253 253 253 253 253 253 253 253 253 253 253
43429 -253 253 253 250 250 250 170 170 170 26 26 26
43430 - 2 2 6 2 2 6 37 26 9 163 110 8
43431 -219 162 10 239 182 13 246 186 14 246 190 14
43432 -246 190 14 246 190 14 246 190 14 246 190 14
43433 -246 190 14 246 190 14 246 190 14 246 190 14
43434 -246 190 14 246 190 14 246 190 14 246 190 14
43435 -246 186 14 236 178 12 224 166 10 142 122 72
43436 - 46 46 46 18 18 18 6 6 6 0 0 0
43437 - 0 0 0 0 0 0 0 0 0 0 0 0
43438 - 0 0 0 0 0 0 0 0 0 0 0 0
43439 - 0 0 0 0 0 0 6 6 6 18 18 18
43440 - 50 50 50 109 106 95 192 133 9 224 166 10
43441 -242 186 14 246 190 14 246 190 14 246 190 14
43442 -246 190 14 246 190 14 246 190 14 246 190 14
43443 -246 190 14 246 190 14 246 190 14 246 190 14
43444 -246 190 14 246 190 14 246 190 14 246 190 14
43445 -242 186 14 226 184 13 210 162 10 142 110 46
43446 -226 226 226 253 253 253 253 253 253 253 253 253
43447 -253 253 253 253 253 253 253 253 253 253 253 253
43448 -253 253 253 253 253 253 253 253 253 253 253 253
43449 -198 198 198 66 66 66 2 2 6 2 2 6
43450 - 2 2 6 2 2 6 50 34 6 156 107 11
43451 -219 162 10 239 182 13 246 186 14 246 190 14
43452 -246 190 14 246 190 14 246 190 14 246 190 14
43453 -246 190 14 246 190 14 246 190 14 246 190 14
43454 -246 190 14 246 190 14 246 190 14 242 186 14
43455 -234 174 13 213 154 11 154 122 46 66 66 66
43456 - 30 30 30 10 10 10 0 0 0 0 0 0
43457 - 0 0 0 0 0 0 0 0 0 0 0 0
43458 - 0 0 0 0 0 0 0 0 0 0 0 0
43459 - 0 0 0 0 0 0 6 6 6 22 22 22
43460 - 58 58 58 154 121 60 206 145 10 234 174 13
43461 -242 186 14 246 186 14 246 190 14 246 190 14
43462 -246 190 14 246 190 14 246 190 14 246 190 14
43463 -246 190 14 246 190 14 246 190 14 246 190 14
43464 -246 190 14 246 190 14 246 190 14 246 190 14
43465 -246 186 14 236 178 12 210 162 10 163 110 8
43466 - 61 42 6 138 138 138 218 218 218 250 250 250
43467 -253 253 253 253 253 253 253 253 253 250 250 250
43468 -242 242 242 210 210 210 144 144 144 66 66 66
43469 - 6 6 6 2 2 6 2 2 6 2 2 6
43470 - 2 2 6 2 2 6 61 42 6 163 110 8
43471 -216 158 10 236 178 12 246 190 14 246 190 14
43472 -246 190 14 246 190 14 246 190 14 246 190 14
43473 -246 190 14 246 190 14 246 190 14 246 190 14
43474 -246 190 14 239 182 13 230 174 11 216 158 10
43475 -190 142 34 124 112 88 70 70 70 38 38 38
43476 - 18 18 18 6 6 6 0 0 0 0 0 0
43477 - 0 0 0 0 0 0 0 0 0 0 0 0
43478 - 0 0 0 0 0 0 0 0 0 0 0 0
43479 - 0 0 0 0 0 0 6 6 6 22 22 22
43480 - 62 62 62 168 124 44 206 145 10 224 166 10
43481 -236 178 12 239 182 13 242 186 14 242 186 14
43482 -246 186 14 246 190 14 246 190 14 246 190 14
43483 -246 190 14 246 190 14 246 190 14 246 190 14
43484 -246 190 14 246 190 14 246 190 14 246 190 14
43485 -246 190 14 236 178 12 216 158 10 175 118 6
43486 - 80 54 7 2 2 6 6 6 6 30 30 30
43487 - 54 54 54 62 62 62 50 50 50 38 38 38
43488 - 14 14 14 2 2 6 2 2 6 2 2 6
43489 - 2 2 6 2 2 6 2 2 6 2 2 6
43490 - 2 2 6 6 6 6 80 54 7 167 114 7
43491 -213 154 11 236 178 12 246 190 14 246 190 14
43492 -246 190 14 246 190 14 246 190 14 246 190 14
43493 -246 190 14 242 186 14 239 182 13 239 182 13
43494 -230 174 11 210 150 10 174 135 50 124 112 88
43495 - 82 82 82 54 54 54 34 34 34 18 18 18
43496 - 6 6 6 0 0 0 0 0 0 0 0 0
43497 - 0 0 0 0 0 0 0 0 0 0 0 0
43498 - 0 0 0 0 0 0 0 0 0 0 0 0
43499 - 0 0 0 0 0 0 6 6 6 18 18 18
43500 - 50 50 50 158 118 36 192 133 9 200 144 11
43501 -216 158 10 219 162 10 224 166 10 226 170 11
43502 -230 174 11 236 178 12 239 182 13 239 182 13
43503 -242 186 14 246 186 14 246 190 14 246 190 14
43504 -246 190 14 246 190 14 246 190 14 246 190 14
43505 -246 186 14 230 174 11 210 150 10 163 110 8
43506 -104 69 6 10 10 10 2 2 6 2 2 6
43507 - 2 2 6 2 2 6 2 2 6 2 2 6
43508 - 2 2 6 2 2 6 2 2 6 2 2 6
43509 - 2 2 6 2 2 6 2 2 6 2 2 6
43510 - 2 2 6 6 6 6 91 60 6 167 114 7
43511 -206 145 10 230 174 11 242 186 14 246 190 14
43512 -246 190 14 246 190 14 246 186 14 242 186 14
43513 -239 182 13 230 174 11 224 166 10 213 154 11
43514 -180 133 36 124 112 88 86 86 86 58 58 58
43515 - 38 38 38 22 22 22 10 10 10 6 6 6
43516 - 0 0 0 0 0 0 0 0 0 0 0 0
43517 - 0 0 0 0 0 0 0 0 0 0 0 0
43518 - 0 0 0 0 0 0 0 0 0 0 0 0
43519 - 0 0 0 0 0 0 0 0 0 14 14 14
43520 - 34 34 34 70 70 70 138 110 50 158 118 36
43521 -167 114 7 180 123 7 192 133 9 197 138 11
43522 -200 144 11 206 145 10 213 154 11 219 162 10
43523 -224 166 10 230 174 11 239 182 13 242 186 14
43524 -246 186 14 246 186 14 246 186 14 246 186 14
43525 -239 182 13 216 158 10 185 133 11 152 99 6
43526 -104 69 6 18 14 6 2 2 6 2 2 6
43527 - 2 2 6 2 2 6 2 2 6 2 2 6
43528 - 2 2 6 2 2 6 2 2 6 2 2 6
43529 - 2 2 6 2 2 6 2 2 6 2 2 6
43530 - 2 2 6 6 6 6 80 54 7 152 99 6
43531 -192 133 9 219 162 10 236 178 12 239 182 13
43532 -246 186 14 242 186 14 239 182 13 236 178 12
43533 -224 166 10 206 145 10 192 133 9 154 121 60
43534 - 94 94 94 62 62 62 42 42 42 22 22 22
43535 - 14 14 14 6 6 6 0 0 0 0 0 0
43536 - 0 0 0 0 0 0 0 0 0 0 0 0
43537 - 0 0 0 0 0 0 0 0 0 0 0 0
43538 - 0 0 0 0 0 0 0 0 0 0 0 0
43539 - 0 0 0 0 0 0 0 0 0 6 6 6
43540 - 18 18 18 34 34 34 58 58 58 78 78 78
43541 -101 98 89 124 112 88 142 110 46 156 107 11
43542 -163 110 8 167 114 7 175 118 6 180 123 7
43543 -185 133 11 197 138 11 210 150 10 219 162 10
43544 -226 170 11 236 178 12 236 178 12 234 174 13
43545 -219 162 10 197 138 11 163 110 8 130 83 6
43546 - 91 60 6 10 10 10 2 2 6 2 2 6
43547 - 18 18 18 38 38 38 38 38 38 38 38 38
43548 - 38 38 38 38 38 38 38 38 38 38 38 38
43549 - 38 38 38 38 38 38 26 26 26 2 2 6
43550 - 2 2 6 6 6 6 70 47 6 137 92 6
43551 -175 118 6 200 144 11 219 162 10 230 174 11
43552 -234 174 13 230 174 11 219 162 10 210 150 10
43553 -192 133 9 163 110 8 124 112 88 82 82 82
43554 - 50 50 50 30 30 30 14 14 14 6 6 6
43555 - 0 0 0 0 0 0 0 0 0 0 0 0
43556 - 0 0 0 0 0 0 0 0 0 0 0 0
43557 - 0 0 0 0 0 0 0 0 0 0 0 0
43558 - 0 0 0 0 0 0 0 0 0 0 0 0
43559 - 0 0 0 0 0 0 0 0 0 0 0 0
43560 - 6 6 6 14 14 14 22 22 22 34 34 34
43561 - 42 42 42 58 58 58 74 74 74 86 86 86
43562 -101 98 89 122 102 70 130 98 46 121 87 25
43563 -137 92 6 152 99 6 163 110 8 180 123 7
43564 -185 133 11 197 138 11 206 145 10 200 144 11
43565 -180 123 7 156 107 11 130 83 6 104 69 6
43566 - 50 34 6 54 54 54 110 110 110 101 98 89
43567 - 86 86 86 82 82 82 78 78 78 78 78 78
43568 - 78 78 78 78 78 78 78 78 78 78 78 78
43569 - 78 78 78 82 82 82 86 86 86 94 94 94
43570 -106 106 106 101 101 101 86 66 34 124 80 6
43571 -156 107 11 180 123 7 192 133 9 200 144 11
43572 -206 145 10 200 144 11 192 133 9 175 118 6
43573 -139 102 15 109 106 95 70 70 70 42 42 42
43574 - 22 22 22 10 10 10 0 0 0 0 0 0
43575 - 0 0 0 0 0 0 0 0 0 0 0 0
43576 - 0 0 0 0 0 0 0 0 0 0 0 0
43577 - 0 0 0 0 0 0 0 0 0 0 0 0
43578 - 0 0 0 0 0 0 0 0 0 0 0 0
43579 - 0 0 0 0 0 0 0 0 0 0 0 0
43580 - 0 0 0 0 0 0 6 6 6 10 10 10
43581 - 14 14 14 22 22 22 30 30 30 38 38 38
43582 - 50 50 50 62 62 62 74 74 74 90 90 90
43583 -101 98 89 112 100 78 121 87 25 124 80 6
43584 -137 92 6 152 99 6 152 99 6 152 99 6
43585 -138 86 6 124 80 6 98 70 6 86 66 30
43586 -101 98 89 82 82 82 58 58 58 46 46 46
43587 - 38 38 38 34 34 34 34 34 34 34 34 34
43588 - 34 34 34 34 34 34 34 34 34 34 34 34
43589 - 34 34 34 34 34 34 38 38 38 42 42 42
43590 - 54 54 54 82 82 82 94 86 76 91 60 6
43591 -134 86 6 156 107 11 167 114 7 175 118 6
43592 -175 118 6 167 114 7 152 99 6 121 87 25
43593 -101 98 89 62 62 62 34 34 34 18 18 18
43594 - 6 6 6 0 0 0 0 0 0 0 0 0
43595 - 0 0 0 0 0 0 0 0 0 0 0 0
43596 - 0 0 0 0 0 0 0 0 0 0 0 0
43597 - 0 0 0 0 0 0 0 0 0 0 0 0
43598 - 0 0 0 0 0 0 0 0 0 0 0 0
43599 - 0 0 0 0 0 0 0 0 0 0 0 0
43600 - 0 0 0 0 0 0 0 0 0 0 0 0
43601 - 0 0 0 6 6 6 6 6 6 10 10 10
43602 - 18 18 18 22 22 22 30 30 30 42 42 42
43603 - 50 50 50 66 66 66 86 86 86 101 98 89
43604 -106 86 58 98 70 6 104 69 6 104 69 6
43605 -104 69 6 91 60 6 82 62 34 90 90 90
43606 - 62 62 62 38 38 38 22 22 22 14 14 14
43607 - 10 10 10 10 10 10 10 10 10 10 10 10
43608 - 10 10 10 10 10 10 6 6 6 10 10 10
43609 - 10 10 10 10 10 10 10 10 10 14 14 14
43610 - 22 22 22 42 42 42 70 70 70 89 81 66
43611 - 80 54 7 104 69 6 124 80 6 137 92 6
43612 -134 86 6 116 81 8 100 82 52 86 86 86
43613 - 58 58 58 30 30 30 14 14 14 6 6 6
43614 - 0 0 0 0 0 0 0 0 0 0 0 0
43615 - 0 0 0 0 0 0 0 0 0 0 0 0
43616 - 0 0 0 0 0 0 0 0 0 0 0 0
43617 - 0 0 0 0 0 0 0 0 0 0 0 0
43618 - 0 0 0 0 0 0 0 0 0 0 0 0
43619 - 0 0 0 0 0 0 0 0 0 0 0 0
43620 - 0 0 0 0 0 0 0 0 0 0 0 0
43621 - 0 0 0 0 0 0 0 0 0 0 0 0
43622 - 0 0 0 6 6 6 10 10 10 14 14 14
43623 - 18 18 18 26 26 26 38 38 38 54 54 54
43624 - 70 70 70 86 86 86 94 86 76 89 81 66
43625 - 89 81 66 86 86 86 74 74 74 50 50 50
43626 - 30 30 30 14 14 14 6 6 6 0 0 0
43627 - 0 0 0 0 0 0 0 0 0 0 0 0
43628 - 0 0 0 0 0 0 0 0 0 0 0 0
43629 - 0 0 0 0 0 0 0 0 0 0 0 0
43630 - 6 6 6 18 18 18 34 34 34 58 58 58
43631 - 82 82 82 89 81 66 89 81 66 89 81 66
43632 - 94 86 66 94 86 76 74 74 74 50 50 50
43633 - 26 26 26 14 14 14 6 6 6 0 0 0
43634 - 0 0 0 0 0 0 0 0 0 0 0 0
43635 - 0 0 0 0 0 0 0 0 0 0 0 0
43636 - 0 0 0 0 0 0 0 0 0 0 0 0
43637 - 0 0 0 0 0 0 0 0 0 0 0 0
43638 - 0 0 0 0 0 0 0 0 0 0 0 0
43639 - 0 0 0 0 0 0 0 0 0 0 0 0
43640 - 0 0 0 0 0 0 0 0 0 0 0 0
43641 - 0 0 0 0 0 0 0 0 0 0 0 0
43642 - 0 0 0 0 0 0 0 0 0 0 0 0
43643 - 6 6 6 6 6 6 14 14 14 18 18 18
43644 - 30 30 30 38 38 38 46 46 46 54 54 54
43645 - 50 50 50 42 42 42 30 30 30 18 18 18
43646 - 10 10 10 0 0 0 0 0 0 0 0 0
43647 - 0 0 0 0 0 0 0 0 0 0 0 0
43648 - 0 0 0 0 0 0 0 0 0 0 0 0
43649 - 0 0 0 0 0 0 0 0 0 0 0 0
43650 - 0 0 0 6 6 6 14 14 14 26 26 26
43651 - 38 38 38 50 50 50 58 58 58 58 58 58
43652 - 54 54 54 42 42 42 30 30 30 18 18 18
43653 - 10 10 10 0 0 0 0 0 0 0 0 0
43654 - 0 0 0 0 0 0 0 0 0 0 0 0
43655 - 0 0 0 0 0 0 0 0 0 0 0 0
43656 - 0 0 0 0 0 0 0 0 0 0 0 0
43657 - 0 0 0 0 0 0 0 0 0 0 0 0
43658 - 0 0 0 0 0 0 0 0 0 0 0 0
43659 - 0 0 0 0 0 0 0 0 0 0 0 0
43660 - 0 0 0 0 0 0 0 0 0 0 0 0
43661 - 0 0 0 0 0 0 0 0 0 0 0 0
43662 - 0 0 0 0 0 0 0 0 0 0 0 0
43663 - 0 0 0 0 0 0 0 0 0 6 6 6
43664 - 6 6 6 10 10 10 14 14 14 18 18 18
43665 - 18 18 18 14 14 14 10 10 10 6 6 6
43666 - 0 0 0 0 0 0 0 0 0 0 0 0
43667 - 0 0 0 0 0 0 0 0 0 0 0 0
43668 - 0 0 0 0 0 0 0 0 0 0 0 0
43669 - 0 0 0 0 0 0 0 0 0 0 0 0
43670 - 0 0 0 0 0 0 0 0 0 6 6 6
43671 - 14 14 14 18 18 18 22 22 22 22 22 22
43672 - 18 18 18 14 14 14 10 10 10 6 6 6
43673 - 0 0 0 0 0 0 0 0 0 0 0 0
43674 - 0 0 0 0 0 0 0 0 0 0 0 0
43675 - 0 0 0 0 0 0 0 0 0 0 0 0
43676 - 0 0 0 0 0 0 0 0 0 0 0 0
43677 - 0 0 0 0 0 0 0 0 0 0 0 0
43678 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43685 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43689 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43690 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691 +4 4 4 4 4 4
43692 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43699 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43703 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43704 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43705 +4 4 4 4 4 4
43706 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43713 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43717 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43718 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43719 +4 4 4 4 4 4
43720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43727 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43732 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43733 +4 4 4 4 4 4
43734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43741 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43746 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747 +4 4 4 4 4 4
43748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43755 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43760 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43761 +4 4 4 4 4 4
43762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43766 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
43767 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
43768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43769 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43771 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
43772 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43773 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
43774 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775 +4 4 4 4 4 4
43776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
43781 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
43782 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43783 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43785 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
43786 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
43787 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
43788 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43789 +4 4 4 4 4 4
43790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
43795 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
43796 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43797 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43799 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
43800 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
43801 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
43802 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
43803 +4 4 4 4 4 4
43804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43807 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
43808 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
43809 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
43810 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
43811 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43812 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43813 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
43814 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
43815 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
43816 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
43817 +4 4 4 4 4 4
43818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43821 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
43822 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
43823 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
43824 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
43825 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43826 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
43827 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
43828 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
43829 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
43830 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
43831 +4 4 4 4 4 4
43832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43835 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
43836 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
43837 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
43838 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
43839 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43840 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
43841 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
43842 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
43843 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
43844 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
43845 +4 4 4 4 4 4
43846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43848 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
43849 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
43850 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
43851 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
43852 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
43853 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
43854 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
43855 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
43856 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
43857 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
43858 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
43859 +4 4 4 4 4 4
43860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43862 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
43863 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
43864 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
43865 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
43866 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
43867 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
43868 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
43869 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
43870 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
43871 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
43872 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
43873 +4 4 4 4 4 4
43874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43876 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
43877 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
43878 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
43879 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
43880 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
43881 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
43882 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
43883 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
43884 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
43885 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
43886 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
43887 +4 4 4 4 4 4
43888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43890 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
43891 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
43892 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
43893 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
43894 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
43895 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
43896 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
43897 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
43898 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
43899 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
43900 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
43901 +4 4 4 4 4 4
43902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43903 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
43904 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
43905 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
43906 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
43907 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
43908 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
43909 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
43910 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
43911 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
43912 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
43913 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
43914 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
43915 +4 4 4 4 4 4
43916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43917 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
43918 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
43919 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
43920 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43921 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
43922 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
43923 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
43924 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
43925 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
43926 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
43927 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
43928 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
43929 +0 0 0 4 4 4
43930 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
43931 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
43932 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
43933 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
43934 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
43935 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
43936 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
43937 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
43938 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
43939 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
43940 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
43941 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
43942 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
43943 +2 0 0 0 0 0
43944 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
43945 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
43946 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
43947 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
43948 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
43949 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
43950 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
43951 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
43952 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
43953 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
43954 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
43955 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
43956 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
43957 +37 38 37 0 0 0
43958 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43959 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
43960 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
43961 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
43962 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
43963 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
43964 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
43965 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
43966 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
43967 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
43968 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
43969 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
43970 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
43971 +85 115 134 4 0 0
43972 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
43973 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
43974 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
43975 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
43976 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
43977 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
43978 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
43979 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
43980 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
43981 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
43982 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
43983 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
43984 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
43985 +60 73 81 4 0 0
43986 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
43987 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
43988 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
43989 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
43990 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
43991 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
43992 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
43993 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
43994 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
43995 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
43996 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
43997 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
43998 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43999 +16 19 21 4 0 0
44000 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
44001 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
44002 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
44003 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
44004 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
44005 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
44006 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
44007 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
44008 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
44009 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
44010 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
44011 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
44012 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
44013 +4 0 0 4 3 3
44014 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
44015 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
44016 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
44017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
44018 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
44019 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
44020 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
44021 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
44022 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
44023 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
44024 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
44025 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
44026 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
44027 +3 2 2 4 4 4
44028 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
44029 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
44030 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
44031 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
44032 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
44033 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
44034 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
44035 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
44036 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
44037 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
44038 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
44039 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
44040 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
44041 +4 4 4 4 4 4
44042 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
44043 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
44044 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
44045 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
44046 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
44047 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
44048 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
44049 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
44050 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
44051 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
44052 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
44053 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
44054 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
44055 +4 4 4 4 4 4
44056 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
44057 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
44058 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
44059 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
44060 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
44061 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44062 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
44063 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
44064 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
44065 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
44066 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
44067 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
44068 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
44069 +5 5 5 5 5 5
44070 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
44071 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
44072 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
44073 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
44074 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
44075 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44076 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
44077 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
44078 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
44079 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
44080 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
44081 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
44082 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44083 +5 5 5 4 4 4
44084 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
44085 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
44086 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
44087 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
44088 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44089 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
44090 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
44091 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
44092 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
44093 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
44094 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
44095 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44096 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44097 +4 4 4 4 4 4
44098 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
44099 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
44100 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
44101 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
44102 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
44103 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44104 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44105 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
44106 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
44107 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
44108 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
44109 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
44110 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44111 +4 4 4 4 4 4
44112 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
44113 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
44114 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
44115 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
44116 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44117 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
44118 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
44119 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
44120 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
44121 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
44122 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
44123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44124 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44125 +4 4 4 4 4 4
44126 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
44127 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
44128 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
44129 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
44130 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44131 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44132 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
44133 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
44134 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
44135 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
44136 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
44137 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44138 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44139 +4 4 4 4 4 4
44140 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
44141 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
44142 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
44143 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
44144 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44145 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
44146 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
44147 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
44148 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
44149 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
44150 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44151 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44153 +4 4 4 4 4 4
44154 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
44155 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
44156 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
44157 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
44158 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
44159 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
44160 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
44161 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
44162 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
44163 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
44164 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
44165 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44167 +4 4 4 4 4 4
44168 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
44169 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
44170 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
44171 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
44172 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
44173 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
44174 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
44175 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
44176 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
44177 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
44178 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
44179 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44181 +4 4 4 4 4 4
44182 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
44183 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
44184 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
44185 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44186 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
44187 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
44188 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
44189 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
44190 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
44191 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
44192 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44195 +4 4 4 4 4 4
44196 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
44197 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
44198 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
44199 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44200 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44201 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
44202 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
44203 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
44204 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
44205 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
44206 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44209 +4 4 4 4 4 4
44210 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
44211 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
44212 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44213 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
44214 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44215 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
44216 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
44217 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
44218 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
44219 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
44220 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44223 +4 4 4 4 4 4
44224 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
44225 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
44226 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44227 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
44228 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44229 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
44230 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
44231 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
44232 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44233 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44234 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44237 +4 4 4 4 4 4
44238 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44239 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
44240 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
44241 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
44242 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
44243 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
44244 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
44245 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
44246 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44247 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44248 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44251 +4 4 4 4 4 4
44252 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
44253 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
44254 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
44255 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
44256 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44257 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
44258 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
44259 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
44260 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44261 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44262 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44265 +4 4 4 4 4 4
44266 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
44267 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
44268 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44269 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
44270 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
44271 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
44272 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
44273 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
44274 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44275 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44276 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44279 +4 4 4 4 4 4
44280 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
44281 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
44282 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44283 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
44284 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
44285 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
44286 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
44287 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
44288 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
44289 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44290 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44293 +4 4 4 4 4 4
44294 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44295 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
44296 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
44297 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
44298 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
44299 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
44300 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
44301 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
44302 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44303 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44304 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44307 +4 4 4 4 4 4
44308 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
44309 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
44310 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44311 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
44312 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
44313 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
44314 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
44315 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
44316 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
44317 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44318 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44321 +4 4 4 4 4 4
44322 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
44323 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
44324 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
44325 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
44326 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
44327 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
44328 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
44329 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
44330 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44331 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44332 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44335 +4 4 4 4 4 4
44336 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44337 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
44338 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
44339 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
44340 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
44341 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
44342 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
44343 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
44344 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44345 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44346 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44349 +4 4 4 4 4 4
44350 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44351 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
44352 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
44353 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
44354 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
44355 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
44356 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44357 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
44358 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
44359 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44360 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44363 +4 4 4 4 4 4
44364 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44365 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
44366 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
44367 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44368 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
44369 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
44370 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
44371 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
44372 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
44373 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44374 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44377 +4 4 4 4 4 4
44378 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
44379 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
44380 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
44381 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
44382 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
44383 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
44384 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
44385 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
44386 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
44387 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44388 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44391 +4 4 4 4 4 4
44392 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44393 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
44394 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
44395 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
44396 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
44397 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
44398 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
44399 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
44400 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
44401 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44402 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44405 +4 4 4 4 4 4
44406 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
44407 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
44408 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
44409 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
44410 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
44411 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
44412 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
44413 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
44414 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
44415 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44416 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44418 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44419 +4 4 4 4 4 4
44420 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
44421 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
44422 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
44423 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
44424 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
44425 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
44426 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
44427 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
44428 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
44429 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
44430 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44432 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44433 +4 4 4 4 4 4
44434 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
44435 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
44436 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
44437 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
44438 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
44439 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
44440 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
44441 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
44442 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
44443 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
44444 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44445 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44446 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44447 +4 4 4 4 4 4
44448 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
44449 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44450 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
44451 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
44452 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
44453 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
44454 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
44455 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
44456 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
44457 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
44458 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44459 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44460 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44461 +4 4 4 4 4 4
44462 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
44463 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
44464 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
44465 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
44466 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
44467 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
44468 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44469 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
44470 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
44471 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
44472 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44473 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44474 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44475 +4 4 4 4 4 4
44476 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
44477 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
44478 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
44479 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
44480 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
44481 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
44482 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
44483 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
44484 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
44485 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
44486 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44487 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44488 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44489 +4 4 4 4 4 4
44490 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
44491 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
44492 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44493 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
44494 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
44495 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
44496 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
44497 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
44498 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
44499 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
44500 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44501 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44502 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44503 +4 4 4 4 4 4
44504 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44505 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
44506 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
44507 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
44508 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
44509 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
44510 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
44511 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
44512 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
44513 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44514 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44515 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44516 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44517 +4 4 4 4 4 4
44518 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
44519 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
44520 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
44521 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
44522 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
44523 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
44524 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
44525 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
44526 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
44527 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
44528 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44529 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44530 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44531 +4 4 4 4 4 4
44532 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
44533 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
44534 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
44535 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
44536 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
44537 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
44538 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
44539 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
44540 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
44541 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44542 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44543 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44544 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44545 +4 4 4 4 4 4
44546 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
44547 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44548 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
44549 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
44550 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
44551 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
44552 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
44553 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
44554 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
44555 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44556 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44557 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44558 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44559 +4 4 4 4 4 4
44560 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
44561 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
44562 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
44563 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
44564 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
44565 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
44566 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
44567 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
44568 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
44569 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44570 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44571 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44572 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44573 +4 4 4 4 4 4
44574 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44575 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
44576 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
44577 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
44578 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
44579 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
44580 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
44581 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
44582 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44583 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44584 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44585 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44586 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44587 +4 4 4 4 4 4
44588 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
44589 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
44590 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44591 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
44592 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
44593 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
44594 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
44595 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
44596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44597 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44598 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44599 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44600 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44601 +4 4 4 4 4 4
44602 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44603 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
44604 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
44605 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
44606 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
44607 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
44608 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
44609 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
44610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44611 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44612 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44613 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44615 +4 4 4 4 4 4
44616 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44617 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
44618 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44619 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
44620 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
44621 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
44622 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
44623 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
44624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44625 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44626 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44627 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44628 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44629 +4 4 4 4 4 4
44630 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44631 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
44632 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
44633 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
44634 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
44635 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
44636 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
44637 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
44638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44639 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44640 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44641 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44642 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44643 +4 4 4 4 4 4
44644 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44645 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
44646 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
44647 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44648 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
44649 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
44650 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
44651 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44653 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44654 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44655 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44656 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44657 +4 4 4 4 4 4
44658 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44659 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44660 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44661 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
44662 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
44663 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
44664 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
44665 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
44666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44667 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44668 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44669 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44670 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44671 +4 4 4 4 4 4
44672 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44673 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44674 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44675 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44676 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
44677 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
44678 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
44679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44681 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44682 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44683 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44684 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44685 +4 4 4 4 4 4
44686 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44687 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44688 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44689 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
44690 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
44691 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
44692 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
44693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44695 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44696 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44697 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44698 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44699 +4 4 4 4 4 4
44700 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44701 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44703 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
44704 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
44705 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
44706 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
44707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44709 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44710 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44711 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44712 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44713 +4 4 4 4 4 4
44714 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44715 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44717 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
44718 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
44719 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
44720 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
44721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44723 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44724 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44725 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44726 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44727 +4 4 4 4 4 4
44728 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44731 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
44732 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
44733 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
44734 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
44735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44737 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44738 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44739 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44740 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44741 +4 4 4 4 4 4
44742 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44745 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44746 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
44747 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
44748 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
44749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44751 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44752 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44753 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44754 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44755 +4 4 4 4 4 4
44756 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44759 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44760 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
44761 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
44762 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44765 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44766 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44767 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44768 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44769 +4 4 4 4 4 4
44770 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44773 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44774 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
44775 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
44776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44779 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44780 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44781 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44782 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44783 +4 4 4 4 4 4
44784 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44787 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44788 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
44789 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
44790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44793 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44794 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44795 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44796 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
44797 +4 4 4 4 4 4
44798 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
44799 index 86d449e..af6a7f7 100644
44800 --- a/drivers/video/udlfb.c
44801 +++ b/drivers/video/udlfb.c
44802 @@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
44803 dlfb_urb_completion(urb);
44804
44805 error:
44806 - atomic_add(bytes_sent, &dev->bytes_sent);
44807 - atomic_add(bytes_identical, &dev->bytes_identical);
44808 - atomic_add(width*height*2, &dev->bytes_rendered);
44809 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44810 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44811 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
44812 end_cycles = get_cycles();
44813 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44814 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44815 >> 10)), /* Kcycles */
44816 &dev->cpu_kcycles_used);
44817
44818 @@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
44819 dlfb_urb_completion(urb);
44820
44821 error:
44822 - atomic_add(bytes_sent, &dev->bytes_sent);
44823 - atomic_add(bytes_identical, &dev->bytes_identical);
44824 - atomic_add(bytes_rendered, &dev->bytes_rendered);
44825 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
44826 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
44827 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
44828 end_cycles = get_cycles();
44829 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
44830 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
44831 >> 10)), /* Kcycles */
44832 &dev->cpu_kcycles_used);
44833 }
44834 @@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
44835 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44836 struct dlfb_data *dev = fb_info->par;
44837 return snprintf(buf, PAGE_SIZE, "%u\n",
44838 - atomic_read(&dev->bytes_rendered));
44839 + atomic_read_unchecked(&dev->bytes_rendered));
44840 }
44841
44842 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44843 @@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
44844 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44845 struct dlfb_data *dev = fb_info->par;
44846 return snprintf(buf, PAGE_SIZE, "%u\n",
44847 - atomic_read(&dev->bytes_identical));
44848 + atomic_read_unchecked(&dev->bytes_identical));
44849 }
44850
44851 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44852 @@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
44853 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44854 struct dlfb_data *dev = fb_info->par;
44855 return snprintf(buf, PAGE_SIZE, "%u\n",
44856 - atomic_read(&dev->bytes_sent));
44857 + atomic_read_unchecked(&dev->bytes_sent));
44858 }
44859
44860 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44861 @@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
44862 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44863 struct dlfb_data *dev = fb_info->par;
44864 return snprintf(buf, PAGE_SIZE, "%u\n",
44865 - atomic_read(&dev->cpu_kcycles_used));
44866 + atomic_read_unchecked(&dev->cpu_kcycles_used));
44867 }
44868
44869 static ssize_t edid_show(
44870 @@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
44871 struct fb_info *fb_info = dev_get_drvdata(fbdev);
44872 struct dlfb_data *dev = fb_info->par;
44873
44874 - atomic_set(&dev->bytes_rendered, 0);
44875 - atomic_set(&dev->bytes_identical, 0);
44876 - atomic_set(&dev->bytes_sent, 0);
44877 - atomic_set(&dev->cpu_kcycles_used, 0);
44878 + atomic_set_unchecked(&dev->bytes_rendered, 0);
44879 + atomic_set_unchecked(&dev->bytes_identical, 0);
44880 + atomic_set_unchecked(&dev->bytes_sent, 0);
44881 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
44882
44883 return count;
44884 }
44885 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
44886 index b75db01..5631c6d 100644
44887 --- a/drivers/video/uvesafb.c
44888 +++ b/drivers/video/uvesafb.c
44889 @@ -19,6 +19,7 @@
44890 #include <linux/io.h>
44891 #include <linux/mutex.h>
44892 #include <linux/slab.h>
44893 +#include <linux/moduleloader.h>
44894 #include <video/edid.h>
44895 #include <video/uvesafb.h>
44896 #ifdef CONFIG_X86
44897 @@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
44898 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
44899 par->pmi_setpal = par->ypan = 0;
44900 } else {
44901 +
44902 +#ifdef CONFIG_PAX_KERNEXEC
44903 +#ifdef CONFIG_MODULES
44904 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
44905 +#endif
44906 + if (!par->pmi_code) {
44907 + par->pmi_setpal = par->ypan = 0;
44908 + return 0;
44909 + }
44910 +#endif
44911 +
44912 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
44913 + task->t.regs.edi);
44914 +
44915 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44916 + pax_open_kernel();
44917 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
44918 + pax_close_kernel();
44919 +
44920 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
44921 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
44922 +#else
44923 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
44924 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
44925 +#endif
44926 +
44927 printk(KERN_INFO "uvesafb: protected mode interface info at "
44928 "%04x:%04x\n",
44929 (u16)task->t.regs.es, (u16)task->t.regs.edi);
44930 @@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
44931 par->ypan = ypan;
44932
44933 if (par->pmi_setpal || par->ypan) {
44934 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
44935 if (__supported_pte_mask & _PAGE_NX) {
44936 par->pmi_setpal = par->ypan = 0;
44937 printk(KERN_WARNING "uvesafb: NX protection is actively."
44938 "We have better not to use the PMI.\n");
44939 - } else {
44940 + } else
44941 +#endif
44942 uvesafb_vbe_getpmi(task, par);
44943 - }
44944 }
44945 #else
44946 /* The protected mode interface is not available on non-x86. */
44947 @@ -1836,6 +1860,11 @@ out:
44948 if (par->vbe_modes)
44949 kfree(par->vbe_modes);
44950
44951 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44952 + if (par->pmi_code)
44953 + module_free_exec(NULL, par->pmi_code);
44954 +#endif
44955 +
44956 framebuffer_release(info);
44957 return err;
44958 }
44959 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
44960 kfree(par->vbe_state_orig);
44961 if (par->vbe_state_saved)
44962 kfree(par->vbe_state_saved);
44963 +
44964 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44965 + if (par->pmi_code)
44966 + module_free_exec(NULL, par->pmi_code);
44967 +#endif
44968 +
44969 }
44970
44971 framebuffer_release(info);
44972 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
44973 index 501b340..86bd4cf 100644
44974 --- a/drivers/video/vesafb.c
44975 +++ b/drivers/video/vesafb.c
44976 @@ -9,6 +9,7 @@
44977 */
44978
44979 #include <linux/module.h>
44980 +#include <linux/moduleloader.h>
44981 #include <linux/kernel.h>
44982 #include <linux/errno.h>
44983 #include <linux/string.h>
44984 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
44985 static int vram_total __initdata; /* Set total amount of memory */
44986 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
44987 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
44988 -static void (*pmi_start)(void) __read_mostly;
44989 -static void (*pmi_pal) (void) __read_mostly;
44990 +static void (*pmi_start)(void) __read_only;
44991 +static void (*pmi_pal) (void) __read_only;
44992 static int depth __read_mostly;
44993 static int vga_compat __read_mostly;
44994 /* --------------------------------------------------------------------- */
44995 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
44996 unsigned int size_vmode;
44997 unsigned int size_remap;
44998 unsigned int size_total;
44999 + void *pmi_code = NULL;
45000
45001 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
45002 return -ENODEV;
45003 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
45004 size_remap = size_total;
45005 vesafb_fix.smem_len = size_remap;
45006
45007 -#ifndef __i386__
45008 - screen_info.vesapm_seg = 0;
45009 -#endif
45010 -
45011 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
45012 printk(KERN_WARNING
45013 "vesafb: cannot reserve video memory at 0x%lx\n",
45014 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
45015 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
45016 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
45017
45018 +#ifdef __i386__
45019 +
45020 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45021 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
45022 + if (!pmi_code)
45023 +#elif !defined(CONFIG_PAX_KERNEXEC)
45024 + if (0)
45025 +#endif
45026 +
45027 +#endif
45028 + screen_info.vesapm_seg = 0;
45029 +
45030 if (screen_info.vesapm_seg) {
45031 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
45032 - screen_info.vesapm_seg,screen_info.vesapm_off);
45033 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
45034 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
45035 }
45036
45037 if (screen_info.vesapm_seg < 0xc000)
45038 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
45039
45040 if (ypan || pmi_setpal) {
45041 unsigned short *pmi_base;
45042 +
45043 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
45044 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
45045 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
45046 +
45047 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45048 + pax_open_kernel();
45049 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
45050 +#else
45051 + pmi_code = pmi_base;
45052 +#endif
45053 +
45054 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
45055 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
45056 +
45057 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45058 + pmi_start = ktva_ktla(pmi_start);
45059 + pmi_pal = ktva_ktla(pmi_pal);
45060 + pax_close_kernel();
45061 +#endif
45062 +
45063 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
45064 if (pmi_base[3]) {
45065 printk(KERN_INFO "vesafb: pmi: ports = ");
45066 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
45067 info->node, info->fix.id);
45068 return 0;
45069 err:
45070 +
45071 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
45072 + module_free_exec(NULL, pmi_code);
45073 +#endif
45074 +
45075 if (info->screen_base)
45076 iounmap(info->screen_base);
45077 framebuffer_release(info);
45078 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
45079 index 88714ae..16c2e11 100644
45080 --- a/drivers/video/via/via_clock.h
45081 +++ b/drivers/video/via/via_clock.h
45082 @@ -56,7 +56,7 @@ struct via_clock {
45083
45084 void (*set_engine_pll_state)(u8 state);
45085 void (*set_engine_pll)(struct via_pll_config config);
45086 -};
45087 +} __no_const;
45088
45089
45090 static inline u32 get_pll_internal_frequency(u32 ref_freq,
45091 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
45092 index fef20db..d28b1ab 100644
45093 --- a/drivers/xen/xenfs/xenstored.c
45094 +++ b/drivers/xen/xenfs/xenstored.c
45095 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
45096 static int xsd_kva_open(struct inode *inode, struct file *file)
45097 {
45098 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
45099 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45100 + NULL);
45101 +#else
45102 xen_store_interface);
45103 +#endif
45104 +
45105 if (!file->private_data)
45106 return -ENOMEM;
45107 return 0;
45108 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
45109 index 890bed5..17ae73e 100644
45110 --- a/fs/9p/vfs_inode.c
45111 +++ b/fs/9p/vfs_inode.c
45112 @@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
45113 void
45114 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45115 {
45116 - char *s = nd_get_link(nd);
45117 + const char *s = nd_get_link(nd);
45118
45119 p9_debug(P9_DEBUG_VFS, " %s %s\n",
45120 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
45121 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
45122 index 0efd152..b5802ad 100644
45123 --- a/fs/Kconfig.binfmt
45124 +++ b/fs/Kconfig.binfmt
45125 @@ -89,7 +89,7 @@ config HAVE_AOUT
45126
45127 config BINFMT_AOUT
45128 tristate "Kernel support for a.out and ECOFF binaries"
45129 - depends on HAVE_AOUT
45130 + depends on HAVE_AOUT && BROKEN
45131 ---help---
45132 A.out (Assembler.OUTput) is a set of formats for libraries and
45133 executables used in the earliest versions of UNIX. Linux used
45134 diff --git a/fs/aio.c b/fs/aio.c
45135 index 71f613c..9d01f1f 100644
45136 --- a/fs/aio.c
45137 +++ b/fs/aio.c
45138 @@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
45139 size += sizeof(struct io_event) * nr_events;
45140 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
45141
45142 - if (nr_pages < 0)
45143 + if (nr_pages <= 0)
45144 return -EINVAL;
45145
45146 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
45147 @@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
45148 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45149 {
45150 ssize_t ret;
45151 + struct iovec iovstack;
45152
45153 #ifdef CONFIG_COMPAT
45154 if (compat)
45155 ret = compat_rw_copy_check_uvector(type,
45156 (struct compat_iovec __user *)kiocb->ki_buf,
45157 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45158 + kiocb->ki_nbytes, 1, &iovstack,
45159 &kiocb->ki_iovec);
45160 else
45161 #endif
45162 ret = rw_copy_check_uvector(type,
45163 (struct iovec __user *)kiocb->ki_buf,
45164 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
45165 + kiocb->ki_nbytes, 1, &iovstack,
45166 &kiocb->ki_iovec);
45167 if (ret < 0)
45168 goto out;
45169 @@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
45170 if (ret < 0)
45171 goto out;
45172
45173 + if (kiocb->ki_iovec == &iovstack) {
45174 + kiocb->ki_inline_vec = iovstack;
45175 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
45176 + }
45177 kiocb->ki_nr_segs = kiocb->ki_nbytes;
45178 kiocb->ki_cur_seg = 0;
45179 /* ki_nbytes/left now reflect bytes instead of segs */
45180 diff --git a/fs/attr.c b/fs/attr.c
45181 index 1449adb..a2038c2 100644
45182 --- a/fs/attr.c
45183 +++ b/fs/attr.c
45184 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
45185 unsigned long limit;
45186
45187 limit = rlimit(RLIMIT_FSIZE);
45188 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
45189 if (limit != RLIM_INFINITY && offset > limit)
45190 goto out_sig;
45191 if (offset > inode->i_sb->s_maxbytes)
45192 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
45193 index 03bc1d3..6205356 100644
45194 --- a/fs/autofs4/waitq.c
45195 +++ b/fs/autofs4/waitq.c
45196 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
45197 {
45198 unsigned long sigpipe, flags;
45199 mm_segment_t fs;
45200 - const char *data = (const char *)addr;
45201 + const char __user *data = (const char __force_user *)addr;
45202 ssize_t wr = 0;
45203
45204 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
45205 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
45206 return 1;
45207 }
45208
45209 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45210 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
45211 +#endif
45212 +
45213 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45214 enum autofs_notify notify)
45215 {
45216 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
45217
45218 /* If this is a direct mount request create a dummy name */
45219 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
45220 +#ifdef CONFIG_GRKERNSEC_HIDESYM
45221 + /* this name does get written to userland via autofs4_write() */
45222 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
45223 +#else
45224 qstr.len = sprintf(name, "%p", dentry);
45225 +#endif
45226 else {
45227 qstr.len = autofs4_getpath(sbi, dentry, &name);
45228 if (!qstr.len) {
45229 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
45230 index 2b3bda8..6a2d4be 100644
45231 --- a/fs/befs/linuxvfs.c
45232 +++ b/fs/befs/linuxvfs.c
45233 @@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
45234 {
45235 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
45236 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
45237 - char *link = nd_get_link(nd);
45238 + const char *link = nd_get_link(nd);
45239 if (!IS_ERR(link))
45240 kfree(link);
45241 }
45242 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
45243 index 6043567..16a9239 100644
45244 --- a/fs/binfmt_aout.c
45245 +++ b/fs/binfmt_aout.c
45246 @@ -16,6 +16,7 @@
45247 #include <linux/string.h>
45248 #include <linux/fs.h>
45249 #include <linux/file.h>
45250 +#include <linux/security.h>
45251 #include <linux/stat.h>
45252 #include <linux/fcntl.h>
45253 #include <linux/ptrace.h>
45254 @@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
45255 #endif
45256 # define START_STACK(u) ((void __user *)u.start_stack)
45257
45258 + memset(&dump, 0, sizeof(dump));
45259 +
45260 fs = get_fs();
45261 set_fs(KERNEL_DS);
45262 has_dumped = 1;
45263 @@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
45264
45265 /* If the size of the dump file exceeds the rlimit, then see what would happen
45266 if we wrote the stack, but not the data area. */
45267 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
45268 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
45269 dump.u_dsize = 0;
45270
45271 /* Make sure we have enough room to write the stack and data areas. */
45272 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
45273 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
45274 dump.u_ssize = 0;
45275
45276 @@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
45277 rlim = rlimit(RLIMIT_DATA);
45278 if (rlim >= RLIM_INFINITY)
45279 rlim = ~0;
45280 +
45281 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
45282 if (ex.a_data + ex.a_bss > rlim)
45283 return -ENOMEM;
45284
45285 @@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
45286
45287 install_exec_creds(bprm);
45288
45289 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45290 + current->mm->pax_flags = 0UL;
45291 +#endif
45292 +
45293 +#ifdef CONFIG_PAX_PAGEEXEC
45294 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
45295 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
45296 +
45297 +#ifdef CONFIG_PAX_EMUTRAMP
45298 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
45299 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
45300 +#endif
45301 +
45302 +#ifdef CONFIG_PAX_MPROTECT
45303 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
45304 + current->mm->pax_flags |= MF_PAX_MPROTECT;
45305 +#endif
45306 +
45307 + }
45308 +#endif
45309 +
45310 if (N_MAGIC(ex) == OMAGIC) {
45311 unsigned long text_addr, map_size;
45312 loff_t pos;
45313 @@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
45314 }
45315
45316 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
45317 - PROT_READ | PROT_WRITE | PROT_EXEC,
45318 + PROT_READ | PROT_WRITE,
45319 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
45320 fd_offset + ex.a_text);
45321 if (error != N_DATADDR(ex)) {
45322 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
45323 index 0c42cdb..f4be023 100644
45324 --- a/fs/binfmt_elf.c
45325 +++ b/fs/binfmt_elf.c
45326 @@ -33,6 +33,7 @@
45327 #include <linux/elf.h>
45328 #include <linux/utsname.h>
45329 #include <linux/coredump.h>
45330 +#include <linux/xattr.h>
45331 #include <asm/uaccess.h>
45332 #include <asm/param.h>
45333 #include <asm/page.h>
45334 @@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
45335 #define elf_core_dump NULL
45336 #endif
45337
45338 +#ifdef CONFIG_PAX_MPROTECT
45339 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
45340 +#endif
45341 +
45342 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
45343 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
45344 #else
45345 @@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
45346 .load_binary = load_elf_binary,
45347 .load_shlib = load_elf_library,
45348 .core_dump = elf_core_dump,
45349 +
45350 +#ifdef CONFIG_PAX_MPROTECT
45351 + .handle_mprotect= elf_handle_mprotect,
45352 +#endif
45353 +
45354 .min_coredump = ELF_EXEC_PAGESIZE,
45355 };
45356
45357 @@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
45358
45359 static int set_brk(unsigned long start, unsigned long end)
45360 {
45361 + unsigned long e = end;
45362 +
45363 start = ELF_PAGEALIGN(start);
45364 end = ELF_PAGEALIGN(end);
45365 if (end > start) {
45366 @@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
45367 if (BAD_ADDR(addr))
45368 return addr;
45369 }
45370 - current->mm->start_brk = current->mm->brk = end;
45371 + current->mm->start_brk = current->mm->brk = e;
45372 return 0;
45373 }
45374
45375 @@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45376 elf_addr_t __user *u_rand_bytes;
45377 const char *k_platform = ELF_PLATFORM;
45378 const char *k_base_platform = ELF_BASE_PLATFORM;
45379 - unsigned char k_rand_bytes[16];
45380 + u32 k_rand_bytes[4];
45381 int items;
45382 elf_addr_t *elf_info;
45383 int ei_index = 0;
45384 const struct cred *cred = current_cred();
45385 struct vm_area_struct *vma;
45386 + unsigned long saved_auxv[AT_VECTOR_SIZE];
45387
45388 /*
45389 * In some cases (e.g. Hyper-Threading), we want to avoid L1
45390 @@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45391 * Generate 16 random bytes for userspace PRNG seeding.
45392 */
45393 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
45394 - u_rand_bytes = (elf_addr_t __user *)
45395 - STACK_ALLOC(p, sizeof(k_rand_bytes));
45396 + srandom32(k_rand_bytes[0] ^ random32());
45397 + srandom32(k_rand_bytes[1] ^ random32());
45398 + srandom32(k_rand_bytes[2] ^ random32());
45399 + srandom32(k_rand_bytes[3] ^ random32());
45400 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
45401 + u_rand_bytes = (elf_addr_t __user *) p;
45402 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
45403 return -EFAULT;
45404
45405 @@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
45406 return -EFAULT;
45407 current->mm->env_end = p;
45408
45409 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
45410 +
45411 /* Put the elf_info on the stack in the right place. */
45412 sp = (elf_addr_t __user *)envp + 1;
45413 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
45414 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
45415 return -EFAULT;
45416 return 0;
45417 }
45418 @@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
45419 an ELF header */
45420
45421 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45422 - struct file *interpreter, unsigned long *interp_map_addr,
45423 - unsigned long no_base)
45424 + struct file *interpreter, unsigned long no_base)
45425 {
45426 struct elf_phdr *elf_phdata;
45427 struct elf_phdr *eppnt;
45428 - unsigned long load_addr = 0;
45429 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
45430 int load_addr_set = 0;
45431 unsigned long last_bss = 0, elf_bss = 0;
45432 - unsigned long error = ~0UL;
45433 + unsigned long error = -EINVAL;
45434 unsigned long total_size;
45435 int retval, i, size;
45436
45437 @@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45438 goto out_close;
45439 }
45440
45441 +#ifdef CONFIG_PAX_SEGMEXEC
45442 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
45443 + pax_task_size = SEGMEXEC_TASK_SIZE;
45444 +#endif
45445 +
45446 eppnt = elf_phdata;
45447 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
45448 if (eppnt->p_type == PT_LOAD) {
45449 @@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45450 map_addr = elf_map(interpreter, load_addr + vaddr,
45451 eppnt, elf_prot, elf_type, total_size);
45452 total_size = 0;
45453 - if (!*interp_map_addr)
45454 - *interp_map_addr = map_addr;
45455 error = map_addr;
45456 if (BAD_ADDR(map_addr))
45457 goto out_close;
45458 @@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
45459 k = load_addr + eppnt->p_vaddr;
45460 if (BAD_ADDR(k) ||
45461 eppnt->p_filesz > eppnt->p_memsz ||
45462 - eppnt->p_memsz > TASK_SIZE ||
45463 - TASK_SIZE - eppnt->p_memsz < k) {
45464 + eppnt->p_memsz > pax_task_size ||
45465 + pax_task_size - eppnt->p_memsz < k) {
45466 error = -ENOMEM;
45467 goto out_close;
45468 }
45469 @@ -530,6 +551,315 @@ out:
45470 return error;
45471 }
45472
45473 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
45474 +#ifdef CONFIG_PAX_SOFTMODE
45475 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
45476 +{
45477 + unsigned long pax_flags = 0UL;
45478 +
45479 +#ifdef CONFIG_PAX_PAGEEXEC
45480 + if (elf_phdata->p_flags & PF_PAGEEXEC)
45481 + pax_flags |= MF_PAX_PAGEEXEC;
45482 +#endif
45483 +
45484 +#ifdef CONFIG_PAX_SEGMEXEC
45485 + if (elf_phdata->p_flags & PF_SEGMEXEC)
45486 + pax_flags |= MF_PAX_SEGMEXEC;
45487 +#endif
45488 +
45489 +#ifdef CONFIG_PAX_EMUTRAMP
45490 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
45491 + pax_flags |= MF_PAX_EMUTRAMP;
45492 +#endif
45493 +
45494 +#ifdef CONFIG_PAX_MPROTECT
45495 + if (elf_phdata->p_flags & PF_MPROTECT)
45496 + pax_flags |= MF_PAX_MPROTECT;
45497 +#endif
45498 +
45499 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45500 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
45501 + pax_flags |= MF_PAX_RANDMMAP;
45502 +#endif
45503 +
45504 + return pax_flags;
45505 +}
45506 +#endif
45507 +
45508 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
45509 +{
45510 + unsigned long pax_flags = 0UL;
45511 +
45512 +#ifdef CONFIG_PAX_PAGEEXEC
45513 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
45514 + pax_flags |= MF_PAX_PAGEEXEC;
45515 +#endif
45516 +
45517 +#ifdef CONFIG_PAX_SEGMEXEC
45518 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
45519 + pax_flags |= MF_PAX_SEGMEXEC;
45520 +#endif
45521 +
45522 +#ifdef CONFIG_PAX_EMUTRAMP
45523 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
45524 + pax_flags |= MF_PAX_EMUTRAMP;
45525 +#endif
45526 +
45527 +#ifdef CONFIG_PAX_MPROTECT
45528 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
45529 + pax_flags |= MF_PAX_MPROTECT;
45530 +#endif
45531 +
45532 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45533 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
45534 + pax_flags |= MF_PAX_RANDMMAP;
45535 +#endif
45536 +
45537 + return pax_flags;
45538 +}
45539 +#endif
45540 +
45541 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45542 +#ifdef CONFIG_PAX_SOFTMODE
45543 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
45544 +{
45545 + unsigned long pax_flags = 0UL;
45546 +
45547 +#ifdef CONFIG_PAX_PAGEEXEC
45548 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
45549 + pax_flags |= MF_PAX_PAGEEXEC;
45550 +#endif
45551 +
45552 +#ifdef CONFIG_PAX_SEGMEXEC
45553 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
45554 + pax_flags |= MF_PAX_SEGMEXEC;
45555 +#endif
45556 +
45557 +#ifdef CONFIG_PAX_EMUTRAMP
45558 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
45559 + pax_flags |= MF_PAX_EMUTRAMP;
45560 +#endif
45561 +
45562 +#ifdef CONFIG_PAX_MPROTECT
45563 + if (pax_flags_softmode & MF_PAX_MPROTECT)
45564 + pax_flags |= MF_PAX_MPROTECT;
45565 +#endif
45566 +
45567 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45568 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
45569 + pax_flags |= MF_PAX_RANDMMAP;
45570 +#endif
45571 +
45572 + return pax_flags;
45573 +}
45574 +#endif
45575 +
45576 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
45577 +{
45578 + unsigned long pax_flags = 0UL;
45579 +
45580 +#ifdef CONFIG_PAX_PAGEEXEC
45581 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
45582 + pax_flags |= MF_PAX_PAGEEXEC;
45583 +#endif
45584 +
45585 +#ifdef CONFIG_PAX_SEGMEXEC
45586 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
45587 + pax_flags |= MF_PAX_SEGMEXEC;
45588 +#endif
45589 +
45590 +#ifdef CONFIG_PAX_EMUTRAMP
45591 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
45592 + pax_flags |= MF_PAX_EMUTRAMP;
45593 +#endif
45594 +
45595 +#ifdef CONFIG_PAX_MPROTECT
45596 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
45597 + pax_flags |= MF_PAX_MPROTECT;
45598 +#endif
45599 +
45600 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
45601 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
45602 + pax_flags |= MF_PAX_RANDMMAP;
45603 +#endif
45604 +
45605 + return pax_flags;
45606 +}
45607 +#endif
45608 +
45609 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45610 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
45611 +{
45612 + unsigned long pax_flags = 0UL;
45613 +
45614 +#ifdef CONFIG_PAX_EI_PAX
45615 +
45616 +#ifdef CONFIG_PAX_PAGEEXEC
45617 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
45618 + pax_flags |= MF_PAX_PAGEEXEC;
45619 +#endif
45620 +
45621 +#ifdef CONFIG_PAX_SEGMEXEC
45622 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
45623 + pax_flags |= MF_PAX_SEGMEXEC;
45624 +#endif
45625 +
45626 +#ifdef CONFIG_PAX_EMUTRAMP
45627 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
45628 + pax_flags |= MF_PAX_EMUTRAMP;
45629 +#endif
45630 +
45631 +#ifdef CONFIG_PAX_MPROTECT
45632 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
45633 + pax_flags |= MF_PAX_MPROTECT;
45634 +#endif
45635 +
45636 +#ifdef CONFIG_PAX_ASLR
45637 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
45638 + pax_flags |= MF_PAX_RANDMMAP;
45639 +#endif
45640 +
45641 +#else
45642 +
45643 +#ifdef CONFIG_PAX_PAGEEXEC
45644 + pax_flags |= MF_PAX_PAGEEXEC;
45645 +#endif
45646 +
45647 +#ifdef CONFIG_PAX_SEGMEXEC
45648 + pax_flags |= MF_PAX_SEGMEXEC;
45649 +#endif
45650 +
45651 +#ifdef CONFIG_PAX_MPROTECT
45652 + pax_flags |= MF_PAX_MPROTECT;
45653 +#endif
45654 +
45655 +#ifdef CONFIG_PAX_RANDMMAP
45656 + if (randomize_va_space)
45657 + pax_flags |= MF_PAX_RANDMMAP;
45658 +#endif
45659 +
45660 +#endif
45661 +
45662 + return pax_flags;
45663 +}
45664 +
45665 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
45666 +{
45667 +
45668 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
45669 + unsigned long i;
45670 +
45671 + for (i = 0UL; i < elf_ex->e_phnum; i++)
45672 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
45673 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
45674 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
45675 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
45676 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
45677 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
45678 + return ~0UL;
45679 +
45680 +#ifdef CONFIG_PAX_SOFTMODE
45681 + if (pax_softmode)
45682 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
45683 + else
45684 +#endif
45685 +
45686 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
45687 + break;
45688 + }
45689 +#endif
45690 +
45691 + return ~0UL;
45692 +}
45693 +
45694 +static unsigned long pax_parse_xattr_pax(struct file * const file)
45695 +{
45696 +
45697 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
45698 + ssize_t xattr_size, i;
45699 + unsigned char xattr_value[5];
45700 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
45701 +
45702 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
45703 + if (xattr_size <= 0 || xattr_size > 5)
45704 + return ~0UL;
45705 +
45706 + for (i = 0; i < xattr_size; i++)
45707 + switch (xattr_value[i]) {
45708 + default:
45709 + return ~0UL;
45710 +
45711 +#define parse_flag(option1, option2, flag) \
45712 + case option1: \
45713 + if (pax_flags_hardmode & MF_PAX_##flag) \
45714 + return ~0UL; \
45715 + pax_flags_hardmode |= MF_PAX_##flag; \
45716 + break; \
45717 + case option2: \
45718 + if (pax_flags_softmode & MF_PAX_##flag) \
45719 + return ~0UL; \
45720 + pax_flags_softmode |= MF_PAX_##flag; \
45721 + break;
45722 +
45723 + parse_flag('p', 'P', PAGEEXEC);
45724 + parse_flag('e', 'E', EMUTRAMP);
45725 + parse_flag('m', 'M', MPROTECT);
45726 + parse_flag('r', 'R', RANDMMAP);
45727 + parse_flag('s', 'S', SEGMEXEC);
45728 +
45729 +#undef parse_flag
45730 + }
45731 +
45732 + if (pax_flags_hardmode & pax_flags_softmode)
45733 + return ~0UL;
45734 +
45735 +#ifdef CONFIG_PAX_SOFTMODE
45736 + if (pax_softmode)
45737 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
45738 + else
45739 +#endif
45740 +
45741 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
45742 +#else
45743 + return ~0UL;
45744 +#endif
45745 +
45746 +}
45747 +
45748 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
45749 +{
45750 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
45751 +
45752 + pax_flags = pax_parse_ei_pax(elf_ex);
45753 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
45754 + xattr_pax_flags = pax_parse_xattr_pax(file);
45755 +
45756 + if (pt_pax_flags == ~0UL)
45757 + pt_pax_flags = xattr_pax_flags;
45758 + else if (xattr_pax_flags == ~0UL)
45759 + xattr_pax_flags = pt_pax_flags;
45760 + if (pt_pax_flags != xattr_pax_flags)
45761 + return -EINVAL;
45762 + if (pt_pax_flags != ~0UL)
45763 + pax_flags = pt_pax_flags;
45764 +
45765 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
45766 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45767 + if ((__supported_pte_mask & _PAGE_NX))
45768 + pax_flags &= ~MF_PAX_SEGMEXEC;
45769 + else
45770 + pax_flags &= ~MF_PAX_PAGEEXEC;
45771 + }
45772 +#endif
45773 +
45774 + if (0 > pax_check_flags(&pax_flags))
45775 + return -EINVAL;
45776 +
45777 + current->mm->pax_flags = pax_flags;
45778 + return 0;
45779 +}
45780 +#endif
45781 +
45782 /*
45783 * These are the functions used to load ELF style executables and shared
45784 * libraries. There is no binary dependent code anywhere else.
45785 @@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
45786 {
45787 unsigned int random_variable = 0;
45788
45789 +#ifdef CONFIG_PAX_RANDUSTACK
45790 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
45791 + return stack_top - current->mm->delta_stack;
45792 +#endif
45793 +
45794 if ((current->flags & PF_RANDOMIZE) &&
45795 !(current->personality & ADDR_NO_RANDOMIZE)) {
45796 random_variable = get_random_int() & STACK_RND_MASK;
45797 @@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
45798 unsigned long load_addr = 0, load_bias = 0;
45799 int load_addr_set = 0;
45800 char * elf_interpreter = NULL;
45801 - unsigned long error;
45802 + unsigned long error = 0;
45803 struct elf_phdr *elf_ppnt, *elf_phdata;
45804 unsigned long elf_bss, elf_brk;
45805 int retval, i;
45806 @@ -574,12 +909,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
45807 unsigned long start_code, end_code, start_data, end_data;
45808 unsigned long reloc_func_desc __maybe_unused = 0;
45809 int executable_stack = EXSTACK_DEFAULT;
45810 - unsigned long def_flags = 0;
45811 struct pt_regs *regs = current_pt_regs();
45812 struct {
45813 struct elfhdr elf_ex;
45814 struct elfhdr interp_elf_ex;
45815 } *loc;
45816 + unsigned long pax_task_size = TASK_SIZE;
45817
45818 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
45819 if (!loc) {
45820 @@ -715,11 +1050,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
45821 goto out_free_dentry;
45822
45823 /* OK, This is the point of no return */
45824 - current->mm->def_flags = def_flags;
45825 +
45826 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45827 + current->mm->pax_flags = 0UL;
45828 +#endif
45829 +
45830 +#ifdef CONFIG_PAX_DLRESOLVE
45831 + current->mm->call_dl_resolve = 0UL;
45832 +#endif
45833 +
45834 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
45835 + current->mm->call_syscall = 0UL;
45836 +#endif
45837 +
45838 +#ifdef CONFIG_PAX_ASLR
45839 + current->mm->delta_mmap = 0UL;
45840 + current->mm->delta_stack = 0UL;
45841 +#endif
45842 +
45843 + current->mm->def_flags = 0;
45844 +
45845 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
45846 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
45847 + send_sig(SIGKILL, current, 0);
45848 + goto out_free_dentry;
45849 + }
45850 +#endif
45851 +
45852 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
45853 + pax_set_initial_flags(bprm);
45854 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
45855 + if (pax_set_initial_flags_func)
45856 + (pax_set_initial_flags_func)(bprm);
45857 +#endif
45858 +
45859 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
45860 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
45861 + current->mm->context.user_cs_limit = PAGE_SIZE;
45862 + current->mm->def_flags |= VM_PAGEEXEC;
45863 + }
45864 +#endif
45865 +
45866 +#ifdef CONFIG_PAX_SEGMEXEC
45867 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
45868 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
45869 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
45870 + pax_task_size = SEGMEXEC_TASK_SIZE;
45871 + current->mm->def_flags |= VM_NOHUGEPAGE;
45872 + }
45873 +#endif
45874 +
45875 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
45876 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45877 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
45878 + put_cpu();
45879 + }
45880 +#endif
45881
45882 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
45883 may depend on the personality. */
45884 SET_PERSONALITY(loc->elf_ex);
45885 +
45886 +#ifdef CONFIG_PAX_ASLR
45887 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45888 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
45889 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
45890 + }
45891 +#endif
45892 +
45893 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45894 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45895 + executable_stack = EXSTACK_DISABLE_X;
45896 + current->personality &= ~READ_IMPLIES_EXEC;
45897 + } else
45898 +#endif
45899 +
45900 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
45901 current->personality |= READ_IMPLIES_EXEC;
45902
45903 @@ -810,6 +1215,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
45904 #else
45905 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
45906 #endif
45907 +
45908 +#ifdef CONFIG_PAX_RANDMMAP
45909 + /* PaX: randomize base address at the default exe base if requested */
45910 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
45911 +#ifdef CONFIG_SPARC64
45912 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
45913 +#else
45914 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
45915 +#endif
45916 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
45917 + elf_flags |= MAP_FIXED;
45918 + }
45919 +#endif
45920 +
45921 }
45922
45923 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
45924 @@ -842,9 +1261,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
45925 * allowed task size. Note that p_filesz must always be
45926 * <= p_memsz so it is only necessary to check p_memsz.
45927 */
45928 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45929 - elf_ppnt->p_memsz > TASK_SIZE ||
45930 - TASK_SIZE - elf_ppnt->p_memsz < k) {
45931 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
45932 + elf_ppnt->p_memsz > pax_task_size ||
45933 + pax_task_size - elf_ppnt->p_memsz < k) {
45934 /* set_brk can never work. Avoid overflows. */
45935 send_sig(SIGKILL, current, 0);
45936 retval = -EINVAL;
45937 @@ -883,17 +1302,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
45938 goto out_free_dentry;
45939 }
45940 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
45941 - send_sig(SIGSEGV, current, 0);
45942 - retval = -EFAULT; /* Nobody gets to see this, but.. */
45943 - goto out_free_dentry;
45944 + /*
45945 + * This bss-zeroing can fail if the ELF
45946 + * file specifies odd protections. So
45947 + * we don't check the return value
45948 + */
45949 }
45950
45951 +#ifdef CONFIG_PAX_RANDMMAP
45952 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
45953 + unsigned long start, size;
45954 +
45955 + start = ELF_PAGEALIGN(elf_brk);
45956 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
45957 + down_read(&current->mm->mmap_sem);
45958 + retval = -ENOMEM;
45959 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
45960 + unsigned long prot = PROT_NONE;
45961 +
45962 + up_read(&current->mm->mmap_sem);
45963 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
45964 +// if (current->personality & ADDR_NO_RANDOMIZE)
45965 +// prot = PROT_READ;
45966 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
45967 + retval = IS_ERR_VALUE(start) ? start : 0;
45968 + } else
45969 + up_read(&current->mm->mmap_sem);
45970 + if (retval == 0)
45971 + retval = set_brk(start + size, start + size + PAGE_SIZE);
45972 + if (retval < 0) {
45973 + send_sig(SIGKILL, current, 0);
45974 + goto out_free_dentry;
45975 + }
45976 + }
45977 +#endif
45978 +
45979 if (elf_interpreter) {
45980 - unsigned long interp_map_addr = 0;
45981 -
45982 elf_entry = load_elf_interp(&loc->interp_elf_ex,
45983 interpreter,
45984 - &interp_map_addr,
45985 load_bias);
45986 if (!IS_ERR((void *)elf_entry)) {
45987 /*
45988 @@ -1115,7 +1561,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45989 * Decide what to dump of a segment, part, all or none.
45990 */
45991 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45992 - unsigned long mm_flags)
45993 + unsigned long mm_flags, long signr)
45994 {
45995 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45996
45997 @@ -1152,7 +1598,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45998 if (vma->vm_file == NULL)
45999 return 0;
46000
46001 - if (FILTER(MAPPED_PRIVATE))
46002 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
46003 goto whole;
46004
46005 /*
46006 @@ -1374,9 +1820,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
46007 {
46008 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
46009 int i = 0;
46010 - do
46011 + do {
46012 i += 2;
46013 - while (auxv[i - 2] != AT_NULL);
46014 + } while (auxv[i - 2] != AT_NULL);
46015 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
46016 }
46017
46018 @@ -2006,14 +2452,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
46019 }
46020
46021 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
46022 - unsigned long mm_flags)
46023 + struct coredump_params *cprm)
46024 {
46025 struct vm_area_struct *vma;
46026 size_t size = 0;
46027
46028 for (vma = first_vma(current, gate_vma); vma != NULL;
46029 vma = next_vma(vma, gate_vma))
46030 - size += vma_dump_size(vma, mm_flags);
46031 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46032 return size;
46033 }
46034
46035 @@ -2107,7 +2553,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46036
46037 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
46038
46039 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
46040 + offset += elf_core_vma_data_size(gate_vma, cprm);
46041 offset += elf_core_extra_data_size();
46042 e_shoff = offset;
46043
46044 @@ -2121,10 +2567,12 @@ static int elf_core_dump(struct coredump_params *cprm)
46045 offset = dataoff;
46046
46047 size += sizeof(*elf);
46048 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46049 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
46050 goto end_coredump;
46051
46052 size += sizeof(*phdr4note);
46053 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46054 if (size > cprm->limit
46055 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
46056 goto end_coredump;
46057 @@ -2138,7 +2586,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46058 phdr.p_offset = offset;
46059 phdr.p_vaddr = vma->vm_start;
46060 phdr.p_paddr = 0;
46061 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
46062 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46063 phdr.p_memsz = vma->vm_end - vma->vm_start;
46064 offset += phdr.p_filesz;
46065 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
46066 @@ -2149,6 +2597,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46067 phdr.p_align = ELF_EXEC_PAGESIZE;
46068
46069 size += sizeof(phdr);
46070 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46071 if (size > cprm->limit
46072 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
46073 goto end_coredump;
46074 @@ -2173,7 +2622,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46075 unsigned long addr;
46076 unsigned long end;
46077
46078 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
46079 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
46080
46081 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
46082 struct page *page;
46083 @@ -2182,6 +2631,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46084 page = get_dump_page(addr);
46085 if (page) {
46086 void *kaddr = kmap(page);
46087 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
46088 stop = ((size += PAGE_SIZE) > cprm->limit) ||
46089 !dump_write(cprm->file, kaddr,
46090 PAGE_SIZE);
46091 @@ -2199,6 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
46092
46093 if (e_phnum == PN_XNUM) {
46094 size += sizeof(*shdr4extnum);
46095 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
46096 if (size > cprm->limit
46097 || !dump_write(cprm->file, shdr4extnum,
46098 sizeof(*shdr4extnum)))
46099 @@ -2219,6 +2670,97 @@ out:
46100
46101 #endif /* CONFIG_ELF_CORE */
46102
46103 +#ifdef CONFIG_PAX_MPROTECT
46104 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
46105 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
46106 + * we'll remove VM_MAYWRITE for good on RELRO segments.
46107 + *
46108 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
46109 + * basis because we want to allow the common case and not the special ones.
46110 + */
46111 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
46112 +{
46113 + struct elfhdr elf_h;
46114 + struct elf_phdr elf_p;
46115 + unsigned long i;
46116 + unsigned long oldflags;
46117 + bool is_textrel_rw, is_textrel_rx, is_relro;
46118 +
46119 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
46120 + return;
46121 +
46122 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
46123 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
46124 +
46125 +#ifdef CONFIG_PAX_ELFRELOCS
46126 + /* possible TEXTREL */
46127 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
46128 + 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);
46129 +#else
46130 + is_textrel_rw = false;
46131 + is_textrel_rx = false;
46132 +#endif
46133 +
46134 + /* possible RELRO */
46135 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
46136 +
46137 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
46138 + return;
46139 +
46140 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
46141 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
46142 +
46143 +#ifdef CONFIG_PAX_ETEXECRELOCS
46144 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46145 +#else
46146 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
46147 +#endif
46148 +
46149 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
46150 + !elf_check_arch(&elf_h) ||
46151 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
46152 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
46153 + return;
46154 +
46155 + for (i = 0UL; i < elf_h.e_phnum; i++) {
46156 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
46157 + return;
46158 + switch (elf_p.p_type) {
46159 + case PT_DYNAMIC:
46160 + if (!is_textrel_rw && !is_textrel_rx)
46161 + continue;
46162 + i = 0UL;
46163 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
46164 + elf_dyn dyn;
46165 +
46166 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
46167 + return;
46168 + if (dyn.d_tag == DT_NULL)
46169 + return;
46170 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
46171 + gr_log_textrel(vma);
46172 + if (is_textrel_rw)
46173 + vma->vm_flags |= VM_MAYWRITE;
46174 + else
46175 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
46176 + vma->vm_flags &= ~VM_MAYWRITE;
46177 + return;
46178 + }
46179 + i++;
46180 + }
46181 + return;
46182 +
46183 + case PT_GNU_RELRO:
46184 + if (!is_relro)
46185 + continue;
46186 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
46187 + vma->vm_flags &= ~VM_MAYWRITE;
46188 + return;
46189 + }
46190 + }
46191 +}
46192 +#endif
46193 +
46194 static int __init init_elf_binfmt(void)
46195 {
46196 register_binfmt(&elf_format);
46197 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
46198 index b563719..3868998 100644
46199 --- a/fs/binfmt_flat.c
46200 +++ b/fs/binfmt_flat.c
46201 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
46202 realdatastart = (unsigned long) -ENOMEM;
46203 printk("Unable to allocate RAM for process data, errno %d\n",
46204 (int)-realdatastart);
46205 + down_write(&current->mm->mmap_sem);
46206 vm_munmap(textpos, text_len);
46207 + up_write(&current->mm->mmap_sem);
46208 ret = realdatastart;
46209 goto err;
46210 }
46211 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46212 }
46213 if (IS_ERR_VALUE(result)) {
46214 printk("Unable to read data+bss, errno %d\n", (int)-result);
46215 + down_write(&current->mm->mmap_sem);
46216 vm_munmap(textpos, text_len);
46217 vm_munmap(realdatastart, len);
46218 + up_write(&current->mm->mmap_sem);
46219 ret = result;
46220 goto err;
46221 }
46222 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
46223 }
46224 if (IS_ERR_VALUE(result)) {
46225 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
46226 + down_write(&current->mm->mmap_sem);
46227 vm_munmap(textpos, text_len + data_len + extra +
46228 MAX_SHARED_LIBS * sizeof(unsigned long));
46229 + up_write(&current->mm->mmap_sem);
46230 ret = result;
46231 goto err;
46232 }
46233 diff --git a/fs/bio.c b/fs/bio.c
46234 index b96fc6c..431d628 100644
46235 --- a/fs/bio.c
46236 +++ b/fs/bio.c
46237 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
46238 /*
46239 * Overflow, abort
46240 */
46241 - if (end < start)
46242 + if (end < start || end - start > INT_MAX - nr_pages)
46243 return ERR_PTR(-EINVAL);
46244
46245 nr_pages += end - start;
46246 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
46247 /*
46248 * Overflow, abort
46249 */
46250 - if (end < start)
46251 + if (end < start || end - start > INT_MAX - nr_pages)
46252 return ERR_PTR(-EINVAL);
46253
46254 nr_pages += end - start;
46255 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
46256 const int read = bio_data_dir(bio) == READ;
46257 struct bio_map_data *bmd = bio->bi_private;
46258 int i;
46259 - char *p = bmd->sgvecs[0].iov_base;
46260 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
46261
46262 __bio_for_each_segment(bvec, bio, i, 0) {
46263 char *addr = page_address(bvec->bv_page);
46264 diff --git a/fs/block_dev.c b/fs/block_dev.c
46265 index 172f849..6efbf24 100644
46266 --- a/fs/block_dev.c
46267 +++ b/fs/block_dev.c
46268 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
46269 else if (bdev->bd_contains == bdev)
46270 return true; /* is a whole device which isn't held */
46271
46272 - else if (whole->bd_holder == bd_may_claim)
46273 + else if (whole->bd_holder == (void *)bd_may_claim)
46274 return true; /* is a partition of a device that is being partitioned */
46275 else if (whole->bd_holder != NULL)
46276 return false; /* is a partition of a held device */
46277 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
46278 index eea5da7..88fead70 100644
46279 --- a/fs/btrfs/ctree.c
46280 +++ b/fs/btrfs/ctree.c
46281 @@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
46282 free_extent_buffer(buf);
46283 add_root_to_dirty_list(root);
46284 } else {
46285 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
46286 - parent_start = parent->start;
46287 - else
46288 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
46289 + if (parent)
46290 + parent_start = parent->start;
46291 + else
46292 + parent_start = 0;
46293 + } else
46294 parent_start = 0;
46295
46296 WARN_ON(trans->transid != btrfs_header_generation(parent));
46297 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
46298 index cc93b23..f3c42bf 100644
46299 --- a/fs/btrfs/inode.c
46300 +++ b/fs/btrfs/inode.c
46301 @@ -7296,7 +7296,7 @@ fail:
46302 return -ENOMEM;
46303 }
46304
46305 -static int btrfs_getattr(struct vfsmount *mnt,
46306 +int btrfs_getattr(struct vfsmount *mnt,
46307 struct dentry *dentry, struct kstat *stat)
46308 {
46309 struct inode *inode = dentry->d_inode;
46310 @@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
46311 return 0;
46312 }
46313
46314 +EXPORT_SYMBOL(btrfs_getattr);
46315 +
46316 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
46317 +{
46318 + return BTRFS_I(inode)->root->anon_dev;
46319 +}
46320 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
46321 +
46322 /*
46323 * If a file is moved, it will inherit the cow and compression flags of the new
46324 * directory.
46325 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
46326 index 338f259..b657640 100644
46327 --- a/fs/btrfs/ioctl.c
46328 +++ b/fs/btrfs/ioctl.c
46329 @@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46330 for (i = 0; i < num_types; i++) {
46331 struct btrfs_space_info *tmp;
46332
46333 + /* Don't copy in more than we allocated */
46334 if (!slot_count)
46335 break;
46336
46337 + slot_count--;
46338 +
46339 info = NULL;
46340 rcu_read_lock();
46341 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
46342 @@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
46343 memcpy(dest, &space, sizeof(space));
46344 dest++;
46345 space_args.total_spaces++;
46346 - slot_count--;
46347 }
46348 - if (!slot_count)
46349 - break;
46350 }
46351 up_read(&info->groups_sem);
46352 }
46353 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
46354 index 300e09a..9fe4539 100644
46355 --- a/fs/btrfs/relocation.c
46356 +++ b/fs/btrfs/relocation.c
46357 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
46358 }
46359 spin_unlock(&rc->reloc_root_tree.lock);
46360
46361 - BUG_ON((struct btrfs_root *)node->data != root);
46362 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
46363
46364 if (!del) {
46365 spin_lock(&rc->reloc_root_tree.lock);
46366 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
46367 index d8982e9..29a85fa 100644
46368 --- a/fs/btrfs/super.c
46369 +++ b/fs/btrfs/super.c
46370 @@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
46371 function, line, errstr);
46372 return;
46373 }
46374 - ACCESS_ONCE(trans->transaction->aborted) = errno;
46375 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
46376 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
46377 }
46378 /*
46379 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
46380 index 622f469..e8d2d55 100644
46381 --- a/fs/cachefiles/bind.c
46382 +++ b/fs/cachefiles/bind.c
46383 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
46384 args);
46385
46386 /* start by checking things over */
46387 - ASSERT(cache->fstop_percent >= 0 &&
46388 - cache->fstop_percent < cache->fcull_percent &&
46389 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
46390 cache->fcull_percent < cache->frun_percent &&
46391 cache->frun_percent < 100);
46392
46393 - ASSERT(cache->bstop_percent >= 0 &&
46394 - cache->bstop_percent < cache->bcull_percent &&
46395 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
46396 cache->bcull_percent < cache->brun_percent &&
46397 cache->brun_percent < 100);
46398
46399 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
46400 index 0a1467b..6a53245 100644
46401 --- a/fs/cachefiles/daemon.c
46402 +++ b/fs/cachefiles/daemon.c
46403 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
46404 if (n > buflen)
46405 return -EMSGSIZE;
46406
46407 - if (copy_to_user(_buffer, buffer, n) != 0)
46408 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
46409 return -EFAULT;
46410
46411 return n;
46412 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
46413 if (test_bit(CACHEFILES_DEAD, &cache->flags))
46414 return -EIO;
46415
46416 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
46417 + if (datalen > PAGE_SIZE - 1)
46418 return -EOPNOTSUPP;
46419
46420 /* drag the command string into the kernel so we can parse it */
46421 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
46422 if (args[0] != '%' || args[1] != '\0')
46423 return -EINVAL;
46424
46425 - if (fstop < 0 || fstop >= cache->fcull_percent)
46426 + if (fstop >= cache->fcull_percent)
46427 return cachefiles_daemon_range_error(cache, args);
46428
46429 cache->fstop_percent = fstop;
46430 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
46431 if (args[0] != '%' || args[1] != '\0')
46432 return -EINVAL;
46433
46434 - if (bstop < 0 || bstop >= cache->bcull_percent)
46435 + if (bstop >= cache->bcull_percent)
46436 return cachefiles_daemon_range_error(cache, args);
46437
46438 cache->bstop_percent = bstop;
46439 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
46440 index 4938251..7e01445 100644
46441 --- a/fs/cachefiles/internal.h
46442 +++ b/fs/cachefiles/internal.h
46443 @@ -59,7 +59,7 @@ struct cachefiles_cache {
46444 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
46445 struct rb_root active_nodes; /* active nodes (can't be culled) */
46446 rwlock_t active_lock; /* lock for active_nodes */
46447 - atomic_t gravecounter; /* graveyard uniquifier */
46448 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
46449 unsigned frun_percent; /* when to stop culling (% files) */
46450 unsigned fcull_percent; /* when to start culling (% files) */
46451 unsigned fstop_percent; /* when to stop allocating (% files) */
46452 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
46453 * proc.c
46454 */
46455 #ifdef CONFIG_CACHEFILES_HISTOGRAM
46456 -extern atomic_t cachefiles_lookup_histogram[HZ];
46457 -extern atomic_t cachefiles_mkdir_histogram[HZ];
46458 -extern atomic_t cachefiles_create_histogram[HZ];
46459 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46460 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46461 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
46462
46463 extern int __init cachefiles_proc_init(void);
46464 extern void cachefiles_proc_cleanup(void);
46465 static inline
46466 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
46467 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
46468 {
46469 unsigned long jif = jiffies - start_jif;
46470 if (jif >= HZ)
46471 jif = HZ - 1;
46472 - atomic_inc(&histogram[jif]);
46473 + atomic_inc_unchecked(&histogram[jif]);
46474 }
46475
46476 #else
46477 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
46478 index 8c01c5fc..15f982e 100644
46479 --- a/fs/cachefiles/namei.c
46480 +++ b/fs/cachefiles/namei.c
46481 @@ -317,7 +317,7 @@ try_again:
46482 /* first step is to make up a grave dentry in the graveyard */
46483 sprintf(nbuffer, "%08x%08x",
46484 (uint32_t) get_seconds(),
46485 - (uint32_t) atomic_inc_return(&cache->gravecounter));
46486 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
46487
46488 /* do the multiway lock magic */
46489 trap = lock_rename(cache->graveyard, dir);
46490 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
46491 index eccd339..4c1d995 100644
46492 --- a/fs/cachefiles/proc.c
46493 +++ b/fs/cachefiles/proc.c
46494 @@ -14,9 +14,9 @@
46495 #include <linux/seq_file.h>
46496 #include "internal.h"
46497
46498 -atomic_t cachefiles_lookup_histogram[HZ];
46499 -atomic_t cachefiles_mkdir_histogram[HZ];
46500 -atomic_t cachefiles_create_histogram[HZ];
46501 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
46502 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
46503 +atomic_unchecked_t cachefiles_create_histogram[HZ];
46504
46505 /*
46506 * display the latency histogram
46507 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
46508 return 0;
46509 default:
46510 index = (unsigned long) v - 3;
46511 - x = atomic_read(&cachefiles_lookup_histogram[index]);
46512 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
46513 - z = atomic_read(&cachefiles_create_histogram[index]);
46514 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
46515 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
46516 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
46517 if (x == 0 && y == 0 && z == 0)
46518 return 0;
46519
46520 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
46521 index 4809922..aab2c39 100644
46522 --- a/fs/cachefiles/rdwr.c
46523 +++ b/fs/cachefiles/rdwr.c
46524 @@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
46525 old_fs = get_fs();
46526 set_fs(KERNEL_DS);
46527 ret = file->f_op->write(
46528 - file, (const void __user *) data, len, &pos);
46529 + file, (const void __force_user *) data, len, &pos);
46530 set_fs(old_fs);
46531 kunmap(page);
46532 if (ret != len)
46533 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
46534 index 8c1aabe..bbf856a 100644
46535 --- a/fs/ceph/dir.c
46536 +++ b/fs/ceph/dir.c
46537 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
46538 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
46539 struct ceph_mds_client *mdsc = fsc->mdsc;
46540 unsigned frag = fpos_frag(filp->f_pos);
46541 - int off = fpos_off(filp->f_pos);
46542 + unsigned int off = fpos_off(filp->f_pos);
46543 int err;
46544 u32 ftype;
46545 struct ceph_mds_reply_info_parsed *rinfo;
46546 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
46547 index d9ea6ed..1e6c8ac 100644
46548 --- a/fs/cifs/cifs_debug.c
46549 +++ b/fs/cifs/cifs_debug.c
46550 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46551
46552 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
46553 #ifdef CONFIG_CIFS_STATS2
46554 - atomic_set(&totBufAllocCount, 0);
46555 - atomic_set(&totSmBufAllocCount, 0);
46556 + atomic_set_unchecked(&totBufAllocCount, 0);
46557 + atomic_set_unchecked(&totSmBufAllocCount, 0);
46558 #endif /* CONFIG_CIFS_STATS2 */
46559 spin_lock(&cifs_tcp_ses_lock);
46560 list_for_each(tmp1, &cifs_tcp_ses_list) {
46561 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
46562 tcon = list_entry(tmp3,
46563 struct cifs_tcon,
46564 tcon_list);
46565 - atomic_set(&tcon->num_smbs_sent, 0);
46566 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
46567 if (server->ops->clear_stats)
46568 server->ops->clear_stats(tcon);
46569 }
46570 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46571 smBufAllocCount.counter, cifs_min_small);
46572 #ifdef CONFIG_CIFS_STATS2
46573 seq_printf(m, "Total Large %d Small %d Allocations\n",
46574 - atomic_read(&totBufAllocCount),
46575 - atomic_read(&totSmBufAllocCount));
46576 + atomic_read_unchecked(&totBufAllocCount),
46577 + atomic_read_unchecked(&totSmBufAllocCount));
46578 #endif /* CONFIG_CIFS_STATS2 */
46579
46580 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
46581 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
46582 if (tcon->need_reconnect)
46583 seq_puts(m, "\tDISCONNECTED ");
46584 seq_printf(m, "\nSMBs: %d",
46585 - atomic_read(&tcon->num_smbs_sent));
46586 + atomic_read_unchecked(&tcon->num_smbs_sent));
46587 if (server->ops->print_stats)
46588 server->ops->print_stats(m, tcon);
46589 }
46590 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
46591 index de7f916..6cb22a9 100644
46592 --- a/fs/cifs/cifsfs.c
46593 +++ b/fs/cifs/cifsfs.c
46594 @@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
46595 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
46596 cifs_req_cachep = kmem_cache_create("cifs_request",
46597 CIFSMaxBufSize + max_hdr_size, 0,
46598 - SLAB_HWCACHE_ALIGN, NULL);
46599 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
46600 if (cifs_req_cachep == NULL)
46601 return -ENOMEM;
46602
46603 @@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
46604 efficient to alloc 1 per page off the slab compared to 17K (5page)
46605 alloc of large cifs buffers even when page debugging is on */
46606 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
46607 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
46608 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
46609 NULL);
46610 if (cifs_sm_req_cachep == NULL) {
46611 mempool_destroy(cifs_req_poolp);
46612 @@ -1109,8 +1109,8 @@ init_cifs(void)
46613 atomic_set(&bufAllocCount, 0);
46614 atomic_set(&smBufAllocCount, 0);
46615 #ifdef CONFIG_CIFS_STATS2
46616 - atomic_set(&totBufAllocCount, 0);
46617 - atomic_set(&totSmBufAllocCount, 0);
46618 + atomic_set_unchecked(&totBufAllocCount, 0);
46619 + atomic_set_unchecked(&totSmBufAllocCount, 0);
46620 #endif /* CONFIG_CIFS_STATS2 */
46621
46622 atomic_set(&midCount, 0);
46623 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
46624 index e6899ce..d6b2920 100644
46625 --- a/fs/cifs/cifsglob.h
46626 +++ b/fs/cifs/cifsglob.h
46627 @@ -751,35 +751,35 @@ struct cifs_tcon {
46628 __u16 Flags; /* optional support bits */
46629 enum statusEnum tidStatus;
46630 #ifdef CONFIG_CIFS_STATS
46631 - atomic_t num_smbs_sent;
46632 + atomic_unchecked_t num_smbs_sent;
46633 union {
46634 struct {
46635 - atomic_t num_writes;
46636 - atomic_t num_reads;
46637 - atomic_t num_flushes;
46638 - atomic_t num_oplock_brks;
46639 - atomic_t num_opens;
46640 - atomic_t num_closes;
46641 - atomic_t num_deletes;
46642 - atomic_t num_mkdirs;
46643 - atomic_t num_posixopens;
46644 - atomic_t num_posixmkdirs;
46645 - atomic_t num_rmdirs;
46646 - atomic_t num_renames;
46647 - atomic_t num_t2renames;
46648 - atomic_t num_ffirst;
46649 - atomic_t num_fnext;
46650 - atomic_t num_fclose;
46651 - atomic_t num_hardlinks;
46652 - atomic_t num_symlinks;
46653 - atomic_t num_locks;
46654 - atomic_t num_acl_get;
46655 - atomic_t num_acl_set;
46656 + atomic_unchecked_t num_writes;
46657 + atomic_unchecked_t num_reads;
46658 + atomic_unchecked_t num_flushes;
46659 + atomic_unchecked_t num_oplock_brks;
46660 + atomic_unchecked_t num_opens;
46661 + atomic_unchecked_t num_closes;
46662 + atomic_unchecked_t num_deletes;
46663 + atomic_unchecked_t num_mkdirs;
46664 + atomic_unchecked_t num_posixopens;
46665 + atomic_unchecked_t num_posixmkdirs;
46666 + atomic_unchecked_t num_rmdirs;
46667 + atomic_unchecked_t num_renames;
46668 + atomic_unchecked_t num_t2renames;
46669 + atomic_unchecked_t num_ffirst;
46670 + atomic_unchecked_t num_fnext;
46671 + atomic_unchecked_t num_fclose;
46672 + atomic_unchecked_t num_hardlinks;
46673 + atomic_unchecked_t num_symlinks;
46674 + atomic_unchecked_t num_locks;
46675 + atomic_unchecked_t num_acl_get;
46676 + atomic_unchecked_t num_acl_set;
46677 } cifs_stats;
46678 #ifdef CONFIG_CIFS_SMB2
46679 struct {
46680 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46681 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46682 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
46683 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
46684 } smb2_stats;
46685 #endif /* CONFIG_CIFS_SMB2 */
46686 } stats;
46687 @@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
46688 }
46689
46690 #ifdef CONFIG_CIFS_STATS
46691 -#define cifs_stats_inc atomic_inc
46692 +#define cifs_stats_inc atomic_inc_unchecked
46693
46694 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
46695 unsigned int bytes)
46696 @@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
46697 /* Various Debug counters */
46698 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
46699 #ifdef CONFIG_CIFS_STATS2
46700 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
46701 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
46702 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
46703 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
46704 #endif
46705 GLOBAL_EXTERN atomic_t smBufAllocCount;
46706 GLOBAL_EXTERN atomic_t midCount;
46707 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
46708 index 51dc2fb..1e12a33 100644
46709 --- a/fs/cifs/link.c
46710 +++ b/fs/cifs/link.c
46711 @@ -616,7 +616,7 @@ symlink_exit:
46712
46713 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
46714 {
46715 - char *p = nd_get_link(nd);
46716 + const char *p = nd_get_link(nd);
46717 if (!IS_ERR(p))
46718 kfree(p);
46719 }
46720 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
46721 index 3a00c0d..42d901c 100644
46722 --- a/fs/cifs/misc.c
46723 +++ b/fs/cifs/misc.c
46724 @@ -169,7 +169,7 @@ cifs_buf_get(void)
46725 memset(ret_buf, 0, buf_size + 3);
46726 atomic_inc(&bufAllocCount);
46727 #ifdef CONFIG_CIFS_STATS2
46728 - atomic_inc(&totBufAllocCount);
46729 + atomic_inc_unchecked(&totBufAllocCount);
46730 #endif /* CONFIG_CIFS_STATS2 */
46731 }
46732
46733 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
46734 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
46735 atomic_inc(&smBufAllocCount);
46736 #ifdef CONFIG_CIFS_STATS2
46737 - atomic_inc(&totSmBufAllocCount);
46738 + atomic_inc_unchecked(&totSmBufAllocCount);
46739 #endif /* CONFIG_CIFS_STATS2 */
46740
46741 }
46742 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
46743 index 47bc5a8..10decbe 100644
46744 --- a/fs/cifs/smb1ops.c
46745 +++ b/fs/cifs/smb1ops.c
46746 @@ -586,27 +586,27 @@ static void
46747 cifs_clear_stats(struct cifs_tcon *tcon)
46748 {
46749 #ifdef CONFIG_CIFS_STATS
46750 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
46751 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
46752 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
46753 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46754 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
46755 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
46756 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46757 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
46758 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
46759 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
46760 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
46761 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
46762 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
46763 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
46764 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
46765 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
46766 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
46767 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
46768 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
46769 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
46770 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
46771 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
46772 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
46773 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
46774 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
46775 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
46776 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
46777 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
46778 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
46779 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
46780 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
46781 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
46782 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
46783 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
46784 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
46785 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
46786 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
46787 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
46788 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
46789 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
46790 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
46791 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
46792 #endif
46793 }
46794
46795 @@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46796 {
46797 #ifdef CONFIG_CIFS_STATS
46798 seq_printf(m, " Oplocks breaks: %d",
46799 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
46800 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
46801 seq_printf(m, "\nReads: %d Bytes: %llu",
46802 - atomic_read(&tcon->stats.cifs_stats.num_reads),
46803 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
46804 (long long)(tcon->bytes_read));
46805 seq_printf(m, "\nWrites: %d Bytes: %llu",
46806 - atomic_read(&tcon->stats.cifs_stats.num_writes),
46807 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
46808 (long long)(tcon->bytes_written));
46809 seq_printf(m, "\nFlushes: %d",
46810 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
46811 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
46812 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
46813 - atomic_read(&tcon->stats.cifs_stats.num_locks),
46814 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
46815 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
46816 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
46817 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
46818 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
46819 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
46820 - atomic_read(&tcon->stats.cifs_stats.num_opens),
46821 - atomic_read(&tcon->stats.cifs_stats.num_closes),
46822 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
46823 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
46824 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
46825 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
46826 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
46827 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
46828 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
46829 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
46830 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
46831 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
46832 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
46833 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
46834 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
46835 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
46836 seq_printf(m, "\nRenames: %d T2 Renames %d",
46837 - atomic_read(&tcon->stats.cifs_stats.num_renames),
46838 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
46839 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
46840 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
46841 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
46842 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
46843 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
46844 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
46845 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
46846 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
46847 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
46848 #endif
46849 }
46850
46851 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
46852 index c9c7aa7..065056a 100644
46853 --- a/fs/cifs/smb2ops.c
46854 +++ b/fs/cifs/smb2ops.c
46855 @@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
46856 #ifdef CONFIG_CIFS_STATS
46857 int i;
46858 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
46859 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46860 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46861 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
46862 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
46863 }
46864 #endif
46865 }
46866 @@ -284,66 +284,66 @@ static void
46867 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
46868 {
46869 #ifdef CONFIG_CIFS_STATS
46870 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46871 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46872 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
46873 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
46874 seq_printf(m, "\nNegotiates: %d sent %d failed",
46875 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
46876 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
46877 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
46878 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
46879 seq_printf(m, "\nSessionSetups: %d sent %d failed",
46880 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
46881 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
46882 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
46883 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
46884 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
46885 seq_printf(m, "\nLogoffs: %d sent %d failed",
46886 - atomic_read(&sent[SMB2_LOGOFF_HE]),
46887 - atomic_read(&failed[SMB2_LOGOFF_HE]));
46888 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
46889 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
46890 seq_printf(m, "\nTreeConnects: %d sent %d failed",
46891 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
46892 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
46893 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
46894 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
46895 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
46896 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
46897 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
46898 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
46899 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
46900 seq_printf(m, "\nCreates: %d sent %d failed",
46901 - atomic_read(&sent[SMB2_CREATE_HE]),
46902 - atomic_read(&failed[SMB2_CREATE_HE]));
46903 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
46904 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
46905 seq_printf(m, "\nCloses: %d sent %d failed",
46906 - atomic_read(&sent[SMB2_CLOSE_HE]),
46907 - atomic_read(&failed[SMB2_CLOSE_HE]));
46908 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
46909 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
46910 seq_printf(m, "\nFlushes: %d sent %d failed",
46911 - atomic_read(&sent[SMB2_FLUSH_HE]),
46912 - atomic_read(&failed[SMB2_FLUSH_HE]));
46913 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
46914 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
46915 seq_printf(m, "\nReads: %d sent %d failed",
46916 - atomic_read(&sent[SMB2_READ_HE]),
46917 - atomic_read(&failed[SMB2_READ_HE]));
46918 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
46919 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
46920 seq_printf(m, "\nWrites: %d sent %d failed",
46921 - atomic_read(&sent[SMB2_WRITE_HE]),
46922 - atomic_read(&failed[SMB2_WRITE_HE]));
46923 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
46924 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
46925 seq_printf(m, "\nLocks: %d sent %d failed",
46926 - atomic_read(&sent[SMB2_LOCK_HE]),
46927 - atomic_read(&failed[SMB2_LOCK_HE]));
46928 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
46929 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
46930 seq_printf(m, "\nIOCTLs: %d sent %d failed",
46931 - atomic_read(&sent[SMB2_IOCTL_HE]),
46932 - atomic_read(&failed[SMB2_IOCTL_HE]));
46933 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
46934 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
46935 seq_printf(m, "\nCancels: %d sent %d failed",
46936 - atomic_read(&sent[SMB2_CANCEL_HE]),
46937 - atomic_read(&failed[SMB2_CANCEL_HE]));
46938 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
46939 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
46940 seq_printf(m, "\nEchos: %d sent %d failed",
46941 - atomic_read(&sent[SMB2_ECHO_HE]),
46942 - atomic_read(&failed[SMB2_ECHO_HE]));
46943 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
46944 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
46945 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
46946 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
46947 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
46948 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
46949 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
46950 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
46951 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
46952 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
46953 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
46954 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
46955 seq_printf(m, "\nQueryInfos: %d sent %d failed",
46956 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
46957 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
46958 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
46959 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
46960 seq_printf(m, "\nSetInfos: %d sent %d failed",
46961 - atomic_read(&sent[SMB2_SET_INFO_HE]),
46962 - atomic_read(&failed[SMB2_SET_INFO_HE]));
46963 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
46964 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
46965 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
46966 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
46967 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
46968 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
46969 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
46970 #endif
46971 }
46972
46973 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
46974 index 41d9d07..dbb4772 100644
46975 --- a/fs/cifs/smb2pdu.c
46976 +++ b/fs/cifs/smb2pdu.c
46977 @@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
46978 default:
46979 cERROR(1, "info level %u isn't supported",
46980 srch_inf->info_level);
46981 - rc = -EINVAL;
46982 - goto qdir_exit;
46983 + return -EINVAL;
46984 }
46985
46986 req->FileIndex = cpu_to_le32(index);
46987 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
46988 index 958ae0e..505c9d0 100644
46989 --- a/fs/coda/cache.c
46990 +++ b/fs/coda/cache.c
46991 @@ -24,7 +24,7 @@
46992 #include "coda_linux.h"
46993 #include "coda_cache.h"
46994
46995 -static atomic_t permission_epoch = ATOMIC_INIT(0);
46996 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
46997
46998 /* replace or extend an acl cache hit */
46999 void coda_cache_enter(struct inode *inode, int mask)
47000 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
47001 struct coda_inode_info *cii = ITOC(inode);
47002
47003 spin_lock(&cii->c_lock);
47004 - cii->c_cached_epoch = atomic_read(&permission_epoch);
47005 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
47006 if (cii->c_uid != current_fsuid()) {
47007 cii->c_uid = current_fsuid();
47008 cii->c_cached_perm = mask;
47009 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
47010 {
47011 struct coda_inode_info *cii = ITOC(inode);
47012 spin_lock(&cii->c_lock);
47013 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
47014 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
47015 spin_unlock(&cii->c_lock);
47016 }
47017
47018 /* remove all acl caches */
47019 void coda_cache_clear_all(struct super_block *sb)
47020 {
47021 - atomic_inc(&permission_epoch);
47022 + atomic_inc_unchecked(&permission_epoch);
47023 }
47024
47025
47026 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
47027 spin_lock(&cii->c_lock);
47028 hit = (mask & cii->c_cached_perm) == mask &&
47029 cii->c_uid == current_fsuid() &&
47030 - cii->c_cached_epoch == atomic_read(&permission_epoch);
47031 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
47032 spin_unlock(&cii->c_lock);
47033
47034 return hit;
47035 diff --git a/fs/compat.c b/fs/compat.c
47036 index 015e1e1..5ce8e54 100644
47037 --- a/fs/compat.c
47038 +++ b/fs/compat.c
47039 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
47040
47041 set_fs(KERNEL_DS);
47042 /* The __user pointer cast is valid because of the set_fs() */
47043 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
47044 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
47045 set_fs(oldfs);
47046 /* truncating is ok because it's a user address */
47047 if (!ret)
47048 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
47049 goto out;
47050
47051 ret = -EINVAL;
47052 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
47053 + if (nr_segs > UIO_MAXIOV)
47054 goto out;
47055 if (nr_segs > fast_segs) {
47056 ret = -ENOMEM;
47057 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
47058
47059 struct compat_readdir_callback {
47060 struct compat_old_linux_dirent __user *dirent;
47061 + struct file * file;
47062 int result;
47063 };
47064
47065 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
47066 buf->result = -EOVERFLOW;
47067 return -EOVERFLOW;
47068 }
47069 +
47070 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47071 + return 0;
47072 +
47073 buf->result++;
47074 dirent = buf->dirent;
47075 if (!access_ok(VERIFY_WRITE, dirent,
47076 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
47077
47078 buf.result = 0;
47079 buf.dirent = dirent;
47080 + buf.file = f.file;
47081
47082 error = vfs_readdir(f.file, compat_fillonedir, &buf);
47083 if (buf.result)
47084 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
47085 struct compat_getdents_callback {
47086 struct compat_linux_dirent __user *current_dir;
47087 struct compat_linux_dirent __user *previous;
47088 + struct file * file;
47089 int count;
47090 int error;
47091 };
47092 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
47093 buf->error = -EOVERFLOW;
47094 return -EOVERFLOW;
47095 }
47096 +
47097 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47098 + return 0;
47099 +
47100 dirent = buf->previous;
47101 if (dirent) {
47102 if (__put_user(offset, &dirent->d_off))
47103 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47104 buf.previous = NULL;
47105 buf.count = count;
47106 buf.error = 0;
47107 + buf.file = f.file;
47108
47109 error = vfs_readdir(f.file, compat_filldir, &buf);
47110 if (error >= 0)
47111 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
47112 struct compat_getdents_callback64 {
47113 struct linux_dirent64 __user *current_dir;
47114 struct linux_dirent64 __user *previous;
47115 + struct file * file;
47116 int count;
47117 int error;
47118 };
47119 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
47120 buf->error = -EINVAL; /* only used if we fail.. */
47121 if (reclen > buf->count)
47122 return -EINVAL;
47123 +
47124 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
47125 + return 0;
47126 +
47127 dirent = buf->previous;
47128
47129 if (dirent) {
47130 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
47131 buf.previous = NULL;
47132 buf.count = count;
47133 buf.error = 0;
47134 + buf.file = f.file;
47135
47136 error = vfs_readdir(f.file, compat_filldir64, &buf);
47137 if (error >= 0)
47138 error = buf.error;
47139 lastdirent = buf.previous;
47140 if (lastdirent) {
47141 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
47142 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
47143 if (__put_user_unaligned(d_off, &lastdirent->d_off))
47144 error = -EFAULT;
47145 else
47146 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
47147 index a81147e..20bf2b5 100644
47148 --- a/fs/compat_binfmt_elf.c
47149 +++ b/fs/compat_binfmt_elf.c
47150 @@ -30,11 +30,13 @@
47151 #undef elf_phdr
47152 #undef elf_shdr
47153 #undef elf_note
47154 +#undef elf_dyn
47155 #undef elf_addr_t
47156 #define elfhdr elf32_hdr
47157 #define elf_phdr elf32_phdr
47158 #define elf_shdr elf32_shdr
47159 #define elf_note elf32_note
47160 +#define elf_dyn Elf32_Dyn
47161 #define elf_addr_t Elf32_Addr
47162
47163 /*
47164 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
47165 index e2f57a0..3c78771 100644
47166 --- a/fs/compat_ioctl.c
47167 +++ b/fs/compat_ioctl.c
47168 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
47169 return -EFAULT;
47170 if (__get_user(udata, &ss32->iomem_base))
47171 return -EFAULT;
47172 - ss.iomem_base = compat_ptr(udata);
47173 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
47174 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
47175 __get_user(ss.port_high, &ss32->port_high))
47176 return -EFAULT;
47177 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
47178 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
47179 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
47180 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
47181 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47182 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
47183 return -EFAULT;
47184
47185 return ioctl_preallocate(file, p);
47186 @@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
47187 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
47188 {
47189 unsigned int a, b;
47190 - a = *(unsigned int *)p;
47191 - b = *(unsigned int *)q;
47192 + a = *(const unsigned int *)p;
47193 + b = *(const unsigned int *)q;
47194 if (a > b)
47195 return 1;
47196 if (a < b)
47197 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
47198 index 712b10f..c33c4ca 100644
47199 --- a/fs/configfs/dir.c
47200 +++ b/fs/configfs/dir.c
47201 @@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
47202 static int configfs_depend_prep(struct dentry *origin,
47203 struct config_item *target)
47204 {
47205 - struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
47206 + struct configfs_dirent *child_sd, *sd;
47207 int ret = 0;
47208
47209 - BUG_ON(!origin || !sd);
47210 + BUG_ON(!origin || !origin->d_fsdata);
47211 + sd = origin->d_fsdata;
47212
47213 if (sd->s_element == target) /* Boo-yah */
47214 goto out;
47215 @@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47216 }
47217 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
47218 struct configfs_dirent *next;
47219 - const char * name;
47220 + const unsigned char * name;
47221 + char d_name[sizeof(next->s_dentry->d_iname)];
47222 int len;
47223 struct inode *inode = NULL;
47224
47225 @@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
47226 continue;
47227
47228 name = configfs_get_name(next);
47229 - len = strlen(name);
47230 + if (next->s_dentry && name == next->s_dentry->d_iname) {
47231 + len = next->s_dentry->d_name.len;
47232 + memcpy(d_name, name, len);
47233 + name = d_name;
47234 + } else
47235 + len = strlen(name);
47236
47237 /*
47238 * We'll have a dentry and an inode for
47239 diff --git a/fs/coredump.c b/fs/coredump.c
47240 index 1774932..5812106 100644
47241 --- a/fs/coredump.c
47242 +++ b/fs/coredump.c
47243 @@ -52,7 +52,7 @@ struct core_name {
47244 char *corename;
47245 int used, size;
47246 };
47247 -static atomic_t call_count = ATOMIC_INIT(1);
47248 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
47249
47250 /* The maximal length of core_pattern is also specified in sysctl.c */
47251
47252 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
47253 {
47254 char *old_corename = cn->corename;
47255
47256 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
47257 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
47258 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
47259
47260 if (!cn->corename) {
47261 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
47262 int pid_in_pattern = 0;
47263 int err = 0;
47264
47265 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
47266 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
47267 cn->corename = kmalloc(cn->size, GFP_KERNEL);
47268 cn->used = 0;
47269
47270 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
47271 pipe = file->f_path.dentry->d_inode->i_pipe;
47272
47273 pipe_lock(pipe);
47274 - pipe->readers++;
47275 - pipe->writers--;
47276 + atomic_inc(&pipe->readers);
47277 + atomic_dec(&pipe->writers);
47278
47279 - while ((pipe->readers > 1) && (!signal_pending(current))) {
47280 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
47281 wake_up_interruptible_sync(&pipe->wait);
47282 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
47283 pipe_wait(pipe);
47284 }
47285
47286 - pipe->readers--;
47287 - pipe->writers++;
47288 + atomic_dec(&pipe->readers);
47289 + atomic_inc(&pipe->writers);
47290 pipe_unlock(pipe);
47291
47292 }
47293 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
47294 int ispipe;
47295 struct files_struct *displaced;
47296 bool need_nonrelative = false;
47297 - static atomic_t core_dump_count = ATOMIC_INIT(0);
47298 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
47299 + long signr = siginfo->si_signo;
47300 struct coredump_params cprm = {
47301 .siginfo = siginfo,
47302 .regs = signal_pt_regs(),
47303 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
47304 .mm_flags = mm->flags,
47305 };
47306
47307 - audit_core_dumps(siginfo->si_signo);
47308 + audit_core_dumps(signr);
47309 +
47310 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
47311 + gr_handle_brute_attach(cprm.mm_flags);
47312
47313 binfmt = mm->binfmt;
47314 if (!binfmt || !binfmt->core_dump)
47315 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
47316 need_nonrelative = true;
47317 }
47318
47319 - retval = coredump_wait(siginfo->si_signo, &core_state);
47320 + retval = coredump_wait(signr, &core_state);
47321 if (retval < 0)
47322 goto fail_creds;
47323
47324 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
47325 }
47326 cprm.limit = RLIM_INFINITY;
47327
47328 - dump_count = atomic_inc_return(&core_dump_count);
47329 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
47330 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
47331 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
47332 task_tgid_vnr(current), current->comm);
47333 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
47334 } else {
47335 struct inode *inode;
47336
47337 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
47338 +
47339 if (cprm.limit < binfmt->min_coredump)
47340 goto fail_unlock;
47341
47342 @@ -640,7 +646,7 @@ close_fail:
47343 filp_close(cprm.file, NULL);
47344 fail_dropcount:
47345 if (ispipe)
47346 - atomic_dec(&core_dump_count);
47347 + atomic_dec_unchecked(&core_dump_count);
47348 fail_unlock:
47349 kfree(cn.corename);
47350 fail_corename:
47351 @@ -659,7 +665,7 @@ fail:
47352 */
47353 int dump_write(struct file *file, const void *addr, int nr)
47354 {
47355 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
47356 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
47357 }
47358 EXPORT_SYMBOL(dump_write);
47359
47360 diff --git a/fs/dcache.c b/fs/dcache.c
47361 index 19153a0..428c2f5 100644
47362 --- a/fs/dcache.c
47363 +++ b/fs/dcache.c
47364 @@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
47365 mempages -= reserve;
47366
47367 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
47368 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
47369 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
47370
47371 dcache_init();
47372 inode_init();
47373 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
47374 index a5f12b7..4ee8a6f 100644
47375 --- a/fs/debugfs/inode.c
47376 +++ b/fs/debugfs/inode.c
47377 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
47378 */
47379 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
47380 {
47381 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
47382 + return __create_file(name, S_IFDIR | S_IRWXU,
47383 +#else
47384 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
47385 +#endif
47386 parent, NULL, NULL);
47387 }
47388 EXPORT_SYMBOL_GPL(debugfs_create_dir);
47389 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
47390 index cc7709e..7e7211f 100644
47391 --- a/fs/ecryptfs/inode.c
47392 +++ b/fs/ecryptfs/inode.c
47393 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
47394 old_fs = get_fs();
47395 set_fs(get_ds());
47396 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
47397 - (char __user *)lower_buf,
47398 + (char __force_user *)lower_buf,
47399 PATH_MAX);
47400 set_fs(old_fs);
47401 if (rc < 0)
47402 @@ -706,7 +706,7 @@ out:
47403 static void
47404 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
47405 {
47406 - char *buf = nd_get_link(nd);
47407 + const char *buf = nd_get_link(nd);
47408 if (!IS_ERR(buf)) {
47409 /* Free the char* */
47410 kfree(buf);
47411 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
47412 index 412e6ed..4292d22 100644
47413 --- a/fs/ecryptfs/miscdev.c
47414 +++ b/fs/ecryptfs/miscdev.c
47415 @@ -315,7 +315,7 @@ check_list:
47416 goto out_unlock_msg_ctx;
47417 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
47418 if (msg_ctx->msg) {
47419 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
47420 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
47421 goto out_unlock_msg_ctx;
47422 i += packet_length_size;
47423 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
47424 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
47425 index b2a34a1..162fa69 100644
47426 --- a/fs/ecryptfs/read_write.c
47427 +++ b/fs/ecryptfs/read_write.c
47428 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
47429 return -EIO;
47430 fs_save = get_fs();
47431 set_fs(get_ds());
47432 - rc = vfs_write(lower_file, data, size, &offset);
47433 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
47434 set_fs(fs_save);
47435 mark_inode_dirty_sync(ecryptfs_inode);
47436 return rc;
47437 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
47438 return -EIO;
47439 fs_save = get_fs();
47440 set_fs(get_ds());
47441 - rc = vfs_read(lower_file, data, size, &offset);
47442 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
47443 set_fs(fs_save);
47444 return rc;
47445 }
47446 diff --git a/fs/exec.c b/fs/exec.c
47447 index 20df02c..1dff97d 100644
47448 --- a/fs/exec.c
47449 +++ b/fs/exec.c
47450 @@ -55,6 +55,17 @@
47451 #include <linux/pipe_fs_i.h>
47452 #include <linux/oom.h>
47453 #include <linux/compat.h>
47454 +#include <linux/random.h>
47455 +#include <linux/seq_file.h>
47456 +#include <linux/coredump.h>
47457 +#include <linux/mman.h>
47458 +
47459 +#ifdef CONFIG_PAX_REFCOUNT
47460 +#include <linux/kallsyms.h>
47461 +#include <linux/kdebug.h>
47462 +#endif
47463 +
47464 +#include <trace/events/fs.h>
47465
47466 #include <asm/uaccess.h>
47467 #include <asm/mmu_context.h>
47468 @@ -66,6 +77,18 @@
47469
47470 #include <trace/events/sched.h>
47471
47472 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47473 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
47474 +{
47475 + 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");
47476 +}
47477 +#endif
47478 +
47479 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
47480 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
47481 +EXPORT_SYMBOL(pax_set_initial_flags_func);
47482 +#endif
47483 +
47484 int suid_dumpable = 0;
47485
47486 static LIST_HEAD(formats);
47487 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47488 int write)
47489 {
47490 struct page *page;
47491 - int ret;
47492
47493 -#ifdef CONFIG_STACK_GROWSUP
47494 - if (write) {
47495 - ret = expand_downwards(bprm->vma, pos);
47496 - if (ret < 0)
47497 - return NULL;
47498 - }
47499 -#endif
47500 - ret = get_user_pages(current, bprm->mm, pos,
47501 - 1, write, 1, &page, NULL);
47502 - if (ret <= 0)
47503 + if (0 > expand_downwards(bprm->vma, pos))
47504 + return NULL;
47505 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
47506 return NULL;
47507
47508 if (write) {
47509 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
47510 if (size <= ARG_MAX)
47511 return page;
47512
47513 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47514 + // only allow 512KB for argv+env on suid/sgid binaries
47515 + // to prevent easy ASLR exhaustion
47516 + if (((bprm->cred->euid != current_euid()) ||
47517 + (bprm->cred->egid != current_egid())) &&
47518 + (size > (512 * 1024))) {
47519 + put_page(page);
47520 + return NULL;
47521 + }
47522 +#endif
47523 +
47524 /*
47525 * Limit to 1/4-th the stack size for the argv+env strings.
47526 * This ensures that:
47527 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47528 vma->vm_end = STACK_TOP_MAX;
47529 vma->vm_start = vma->vm_end - PAGE_SIZE;
47530 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
47531 +
47532 +#ifdef CONFIG_PAX_SEGMEXEC
47533 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
47534 +#endif
47535 +
47536 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
47537 INIT_LIST_HEAD(&vma->anon_vma_chain);
47538
47539 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
47540 mm->stack_vm = mm->total_vm = 1;
47541 up_write(&mm->mmap_sem);
47542 bprm->p = vma->vm_end - sizeof(void *);
47543 +
47544 +#ifdef CONFIG_PAX_RANDUSTACK
47545 + if (randomize_va_space)
47546 + bprm->p ^= random32() & ~PAGE_MASK;
47547 +#endif
47548 +
47549 return 0;
47550 err:
47551 up_write(&mm->mmap_sem);
47552 @@ -384,19 +421,7 @@ err:
47553 return err;
47554 }
47555
47556 -struct user_arg_ptr {
47557 -#ifdef CONFIG_COMPAT
47558 - bool is_compat;
47559 -#endif
47560 - union {
47561 - const char __user *const __user *native;
47562 -#ifdef CONFIG_COMPAT
47563 - const compat_uptr_t __user *compat;
47564 -#endif
47565 - } ptr;
47566 -};
47567 -
47568 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47569 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47570 {
47571 const char __user *native;
47572
47573 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
47574 compat_uptr_t compat;
47575
47576 if (get_user(compat, argv.ptr.compat + nr))
47577 - return ERR_PTR(-EFAULT);
47578 + return (const char __force_user *)ERR_PTR(-EFAULT);
47579
47580 return compat_ptr(compat);
47581 }
47582 #endif
47583
47584 if (get_user(native, argv.ptr.native + nr))
47585 - return ERR_PTR(-EFAULT);
47586 + return (const char __force_user *)ERR_PTR(-EFAULT);
47587
47588 return native;
47589 }
47590 @@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
47591 if (!p)
47592 break;
47593
47594 - if (IS_ERR(p))
47595 + if (IS_ERR((const char __force_kernel *)p))
47596 return -EFAULT;
47597
47598 if (i >= max)
47599 @@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
47600
47601 ret = -EFAULT;
47602 str = get_user_arg_ptr(argv, argc);
47603 - if (IS_ERR(str))
47604 + if (IS_ERR((const char __force_kernel *)str))
47605 goto out;
47606
47607 len = strnlen_user(str, MAX_ARG_STRLEN);
47608 @@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
47609 int r;
47610 mm_segment_t oldfs = get_fs();
47611 struct user_arg_ptr argv = {
47612 - .ptr.native = (const char __user *const __user *)__argv,
47613 + .ptr.native = (const char __force_user *const __force_user *)__argv,
47614 };
47615
47616 set_fs(KERNEL_DS);
47617 @@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47618 unsigned long new_end = old_end - shift;
47619 struct mmu_gather tlb;
47620
47621 - BUG_ON(new_start > new_end);
47622 + if (new_start >= new_end || new_start < mmap_min_addr)
47623 + return -ENOMEM;
47624
47625 /*
47626 * ensure there are no vmas between where we want to go
47627 @@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
47628 if (vma != find_vma(mm, new_start))
47629 return -EFAULT;
47630
47631 +#ifdef CONFIG_PAX_SEGMEXEC
47632 + BUG_ON(pax_find_mirror_vma(vma));
47633 +#endif
47634 +
47635 /*
47636 * cover the whole range: [new_start, old_end)
47637 */
47638 @@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47639 stack_top = arch_align_stack(stack_top);
47640 stack_top = PAGE_ALIGN(stack_top);
47641
47642 - if (unlikely(stack_top < mmap_min_addr) ||
47643 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
47644 - return -ENOMEM;
47645 -
47646 stack_shift = vma->vm_end - stack_top;
47647
47648 bprm->p -= stack_shift;
47649 @@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
47650 bprm->exec -= stack_shift;
47651
47652 down_write(&mm->mmap_sem);
47653 +
47654 + /* Move stack pages down in memory. */
47655 + if (stack_shift) {
47656 + ret = shift_arg_pages(vma, stack_shift);
47657 + if (ret)
47658 + goto out_unlock;
47659 + }
47660 +
47661 vm_flags = VM_STACK_FLAGS;
47662
47663 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47664 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47665 + vm_flags &= ~VM_EXEC;
47666 +
47667 +#ifdef CONFIG_PAX_MPROTECT
47668 + if (mm->pax_flags & MF_PAX_MPROTECT)
47669 + vm_flags &= ~VM_MAYEXEC;
47670 +#endif
47671 +
47672 + }
47673 +#endif
47674 +
47675 /*
47676 * Adjust stack execute permissions; explicitly enable for
47677 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
47678 @@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
47679 goto out_unlock;
47680 BUG_ON(prev != vma);
47681
47682 - /* Move stack pages down in memory. */
47683 - if (stack_shift) {
47684 - ret = shift_arg_pages(vma, stack_shift);
47685 - if (ret)
47686 - goto out_unlock;
47687 - }
47688 -
47689 /* mprotect_fixup is overkill to remove the temporary stack flags */
47690 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
47691
47692 @@ -737,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
47693 #endif
47694 current->mm->start_stack = bprm->p;
47695 ret = expand_stack(vma, stack_base);
47696 +
47697 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
47698 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
47699 + unsigned long size, flags, vm_flags;
47700 +
47701 + size = STACK_TOP - vma->vm_end;
47702 + flags = MAP_FIXED | MAP_PRIVATE;
47703 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
47704 +
47705 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
47706 +
47707 +#ifdef CONFIG_X86
47708 + if (!ret) {
47709 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
47710 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
47711 + }
47712 +#endif
47713 +
47714 + }
47715 +#endif
47716 +
47717 if (ret)
47718 ret = -EFAULT;
47719
47720 @@ -772,6 +832,8 @@ struct file *open_exec(const char *name)
47721
47722 fsnotify_open(file);
47723
47724 + trace_open_exec(name);
47725 +
47726 err = deny_write_access(file);
47727 if (err)
47728 goto exit;
47729 @@ -795,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
47730 old_fs = get_fs();
47731 set_fs(get_ds());
47732 /* The cast to a user pointer is valid due to the set_fs() */
47733 - result = vfs_read(file, (void __user *)addr, count, &pos);
47734 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
47735 set_fs(old_fs);
47736 return result;
47737 }
47738 @@ -1247,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
47739 }
47740 rcu_read_unlock();
47741
47742 - if (p->fs->users > n_fs) {
47743 + if (atomic_read(&p->fs->users) > n_fs) {
47744 bprm->unsafe |= LSM_UNSAFE_SHARE;
47745 } else {
47746 res = -EAGAIN;
47747 @@ -1447,6 +1509,28 @@ int search_binary_handler(struct linux_binprm *bprm)
47748
47749 EXPORT_SYMBOL(search_binary_handler);
47750
47751 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47752 +static DEFINE_PER_CPU(u64, exec_counter);
47753 +static int __init init_exec_counters(void)
47754 +{
47755 + unsigned int cpu;
47756 +
47757 + for_each_possible_cpu(cpu) {
47758 + per_cpu(exec_counter, cpu) = (u64)cpu;
47759 + }
47760 +
47761 + return 0;
47762 +}
47763 +early_initcall(init_exec_counters);
47764 +static inline void increment_exec_counter(void)
47765 +{
47766 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
47767 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
47768 +}
47769 +#else
47770 +static inline void increment_exec_counter(void) {}
47771 +#endif
47772 +
47773 /*
47774 * sys_execve() executes a new program.
47775 */
47776 @@ -1454,6 +1538,11 @@ static int do_execve_common(const char *filename,
47777 struct user_arg_ptr argv,
47778 struct user_arg_ptr envp)
47779 {
47780 +#ifdef CONFIG_GRKERNSEC
47781 + struct file *old_exec_file;
47782 + struct acl_subject_label *old_acl;
47783 + struct rlimit old_rlim[RLIM_NLIMITS];
47784 +#endif
47785 struct linux_binprm *bprm;
47786 struct file *file;
47787 struct files_struct *displaced;
47788 @@ -1461,6 +1550,8 @@ static int do_execve_common(const char *filename,
47789 int retval;
47790 const struct cred *cred = current_cred();
47791
47792 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
47793 +
47794 /*
47795 * We move the actual failure in case of RLIMIT_NPROC excess from
47796 * set*uid() to execve() because too many poorly written programs
47797 @@ -1501,12 +1592,27 @@ static int do_execve_common(const char *filename,
47798 if (IS_ERR(file))
47799 goto out_unmark;
47800
47801 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
47802 + retval = -EPERM;
47803 + goto out_file;
47804 + }
47805 +
47806 sched_exec();
47807
47808 bprm->file = file;
47809 bprm->filename = filename;
47810 bprm->interp = filename;
47811
47812 + if (gr_process_user_ban()) {
47813 + retval = -EPERM;
47814 + goto out_file;
47815 + }
47816 +
47817 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
47818 + retval = -EACCES;
47819 + goto out_file;
47820 + }
47821 +
47822 retval = bprm_mm_init(bprm);
47823 if (retval)
47824 goto out_file;
47825 @@ -1523,24 +1629,65 @@ static int do_execve_common(const char *filename,
47826 if (retval < 0)
47827 goto out;
47828
47829 +#ifdef CONFIG_GRKERNSEC
47830 + old_acl = current->acl;
47831 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
47832 + old_exec_file = current->exec_file;
47833 + get_file(file);
47834 + current->exec_file = file;
47835 +#endif
47836 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
47837 + /* limit suid stack to 8MB
47838 + * we saved the old limits above and will restore them if this exec fails
47839 + */
47840 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
47841 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
47842 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
47843 +#endif
47844 +
47845 + if (!gr_tpe_allow(file)) {
47846 + retval = -EACCES;
47847 + goto out_fail;
47848 + }
47849 +
47850 + if (gr_check_crash_exec(file)) {
47851 + retval = -EACCES;
47852 + goto out_fail;
47853 + }
47854 +
47855 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
47856 + bprm->unsafe);
47857 + if (retval < 0)
47858 + goto out_fail;
47859 +
47860 retval = copy_strings_kernel(1, &bprm->filename, bprm);
47861 if (retval < 0)
47862 - goto out;
47863 + goto out_fail;
47864
47865 bprm->exec = bprm->p;
47866 retval = copy_strings(bprm->envc, envp, bprm);
47867 if (retval < 0)
47868 - goto out;
47869 + goto out_fail;
47870
47871 retval = copy_strings(bprm->argc, argv, bprm);
47872 if (retval < 0)
47873 - goto out;
47874 + goto out_fail;
47875 +
47876 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
47877 +
47878 + gr_handle_exec_args(bprm, argv);
47879
47880 retval = search_binary_handler(bprm);
47881 if (retval < 0)
47882 - goto out;
47883 + goto out_fail;
47884 +#ifdef CONFIG_GRKERNSEC
47885 + if (old_exec_file)
47886 + fput(old_exec_file);
47887 +#endif
47888
47889 /* execve succeeded */
47890 +
47891 + increment_exec_counter();
47892 current->fs->in_exec = 0;
47893 current->in_execve = 0;
47894 acct_update_integrals(current);
47895 @@ -1549,6 +1696,14 @@ static int do_execve_common(const char *filename,
47896 put_files_struct(displaced);
47897 return retval;
47898
47899 +out_fail:
47900 +#ifdef CONFIG_GRKERNSEC
47901 + current->acl = old_acl;
47902 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
47903 + fput(current->exec_file);
47904 + current->exec_file = old_exec_file;
47905 +#endif
47906 +
47907 out:
47908 if (bprm->mm) {
47909 acct_arg_size(bprm, 0);
47910 @@ -1697,3 +1852,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
47911 return error;
47912 }
47913 #endif
47914 +
47915 +int pax_check_flags(unsigned long *flags)
47916 +{
47917 + int retval = 0;
47918 +
47919 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
47920 + if (*flags & MF_PAX_SEGMEXEC)
47921 + {
47922 + *flags &= ~MF_PAX_SEGMEXEC;
47923 + retval = -EINVAL;
47924 + }
47925 +#endif
47926 +
47927 + if ((*flags & MF_PAX_PAGEEXEC)
47928 +
47929 +#ifdef CONFIG_PAX_PAGEEXEC
47930 + && (*flags & MF_PAX_SEGMEXEC)
47931 +#endif
47932 +
47933 + )
47934 + {
47935 + *flags &= ~MF_PAX_PAGEEXEC;
47936 + retval = -EINVAL;
47937 + }
47938 +
47939 + if ((*flags & MF_PAX_MPROTECT)
47940 +
47941 +#ifdef CONFIG_PAX_MPROTECT
47942 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47943 +#endif
47944 +
47945 + )
47946 + {
47947 + *flags &= ~MF_PAX_MPROTECT;
47948 + retval = -EINVAL;
47949 + }
47950 +
47951 + if ((*flags & MF_PAX_EMUTRAMP)
47952 +
47953 +#ifdef CONFIG_PAX_EMUTRAMP
47954 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
47955 +#endif
47956 +
47957 + )
47958 + {
47959 + *flags &= ~MF_PAX_EMUTRAMP;
47960 + retval = -EINVAL;
47961 + }
47962 +
47963 + return retval;
47964 +}
47965 +
47966 +EXPORT_SYMBOL(pax_check_flags);
47967 +
47968 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47969 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
47970 +{
47971 + struct task_struct *tsk = current;
47972 + struct mm_struct *mm = current->mm;
47973 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
47974 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
47975 + char *path_exec = NULL;
47976 + char *path_fault = NULL;
47977 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
47978 + siginfo_t info = { };
47979 +
47980 + if (buffer_exec && buffer_fault) {
47981 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
47982 +
47983 + down_read(&mm->mmap_sem);
47984 + vma = mm->mmap;
47985 + while (vma && (!vma_exec || !vma_fault)) {
47986 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
47987 + vma_exec = vma;
47988 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
47989 + vma_fault = vma;
47990 + vma = vma->vm_next;
47991 + }
47992 + if (vma_exec) {
47993 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
47994 + if (IS_ERR(path_exec))
47995 + path_exec = "<path too long>";
47996 + else {
47997 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
47998 + if (path_exec) {
47999 + *path_exec = 0;
48000 + path_exec = buffer_exec;
48001 + } else
48002 + path_exec = "<path too long>";
48003 + }
48004 + }
48005 + if (vma_fault) {
48006 + start = vma_fault->vm_start;
48007 + end = vma_fault->vm_end;
48008 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
48009 + if (vma_fault->vm_file) {
48010 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
48011 + if (IS_ERR(path_fault))
48012 + path_fault = "<path too long>";
48013 + else {
48014 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
48015 + if (path_fault) {
48016 + *path_fault = 0;
48017 + path_fault = buffer_fault;
48018 + } else
48019 + path_fault = "<path too long>";
48020 + }
48021 + } else
48022 + path_fault = "<anonymous mapping>";
48023 + }
48024 + up_read(&mm->mmap_sem);
48025 + }
48026 + if (tsk->signal->curr_ip)
48027 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
48028 + else
48029 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
48030 + 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),
48031 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
48032 + free_page((unsigned long)buffer_exec);
48033 + free_page((unsigned long)buffer_fault);
48034 + pax_report_insns(regs, pc, sp);
48035 + info.si_signo = SIGKILL;
48036 + info.si_errno = 0;
48037 + info.si_code = SI_KERNEL;
48038 + info.si_pid = 0;
48039 + info.si_uid = 0;
48040 + do_coredump(&info);
48041 +}
48042 +#endif
48043 +
48044 +#ifdef CONFIG_PAX_REFCOUNT
48045 +void pax_report_refcount_overflow(struct pt_regs *regs)
48046 +{
48047 + if (current->signal->curr_ip)
48048 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
48049 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
48050 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48051 + else
48052 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
48053 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
48054 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
48055 + show_regs(regs);
48056 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
48057 +}
48058 +#endif
48059 +
48060 +#ifdef CONFIG_PAX_USERCOPY
48061 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
48062 +static noinline int check_stack_object(const void *obj, unsigned long len)
48063 +{
48064 + const void * const stack = task_stack_page(current);
48065 + const void * const stackend = stack + THREAD_SIZE;
48066 +
48067 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48068 + const void *frame = NULL;
48069 + const void *oldframe;
48070 +#endif
48071 +
48072 + if (obj + len < obj)
48073 + return -1;
48074 +
48075 + if (obj + len <= stack || stackend <= obj)
48076 + return 0;
48077 +
48078 + if (obj < stack || stackend < obj + len)
48079 + return -1;
48080 +
48081 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
48082 + oldframe = __builtin_frame_address(1);
48083 + if (oldframe)
48084 + frame = __builtin_frame_address(2);
48085 + /*
48086 + low ----------------------------------------------> high
48087 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
48088 + ^----------------^
48089 + allow copies only within here
48090 + */
48091 + while (stack <= frame && frame < stackend) {
48092 + /* if obj + len extends past the last frame, this
48093 + check won't pass and the next frame will be 0,
48094 + causing us to bail out and correctly report
48095 + the copy as invalid
48096 + */
48097 + if (obj + len <= frame)
48098 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
48099 + oldframe = frame;
48100 + frame = *(const void * const *)frame;
48101 + }
48102 + return -1;
48103 +#else
48104 + return 1;
48105 +#endif
48106 +}
48107 +
48108 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
48109 +{
48110 + if (current->signal->curr_ip)
48111 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48112 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48113 + else
48114 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
48115 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
48116 + dump_stack();
48117 + gr_handle_kernel_exploit();
48118 + do_group_exit(SIGKILL);
48119 +}
48120 +#endif
48121 +
48122 +void __check_object_size(const void *ptr, unsigned long n, bool to)
48123 +{
48124 +
48125 +#ifdef CONFIG_PAX_USERCOPY
48126 + const char *type;
48127 +
48128 + if (!n)
48129 + return;
48130 +
48131 + type = check_heap_object(ptr, n);
48132 + if (!type) {
48133 + if (check_stack_object(ptr, n) != -1)
48134 + return;
48135 + type = "<process stack>";
48136 + }
48137 +
48138 + pax_report_usercopy(ptr, n, to, type);
48139 +#endif
48140 +
48141 +}
48142 +EXPORT_SYMBOL(__check_object_size);
48143 +
48144 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
48145 +void pax_track_stack(void)
48146 +{
48147 + unsigned long sp = (unsigned long)&sp;
48148 + if (sp < current_thread_info()->lowest_stack &&
48149 + sp > (unsigned long)task_stack_page(current))
48150 + current_thread_info()->lowest_stack = sp;
48151 +}
48152 +EXPORT_SYMBOL(pax_track_stack);
48153 +#endif
48154 +
48155 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
48156 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
48157 +{
48158 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
48159 + dump_stack();
48160 + do_group_exit(SIGKILL);
48161 +}
48162 +EXPORT_SYMBOL(report_size_overflow);
48163 +#endif
48164 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
48165 index 2616d0e..2ffdec9 100644
48166 --- a/fs/ext2/balloc.c
48167 +++ b/fs/ext2/balloc.c
48168 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
48169
48170 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48171 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48172 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48173 + if (free_blocks < root_blocks + 1 &&
48174 !uid_eq(sbi->s_resuid, current_fsuid()) &&
48175 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48176 - !in_group_p (sbi->s_resgid))) {
48177 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48178 return 0;
48179 }
48180 return 1;
48181 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
48182 index 22548f5..41521d8 100644
48183 --- a/fs/ext3/balloc.c
48184 +++ b/fs/ext3/balloc.c
48185 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
48186
48187 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
48188 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
48189 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
48190 + if (free_blocks < root_blocks + 1 &&
48191 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
48192 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
48193 - !in_group_p (sbi->s_resgid))) {
48194 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
48195 return 0;
48196 }
48197 return 1;
48198 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
48199 index cf18217..8f6b9c3 100644
48200 --- a/fs/ext4/balloc.c
48201 +++ b/fs/ext4/balloc.c
48202 @@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
48203 /* Hm, nope. Are (enough) root reserved clusters available? */
48204 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
48205 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
48206 - capable(CAP_SYS_RESOURCE) ||
48207 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
48208 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
48209 + capable_nolog(CAP_SYS_RESOURCE)) {
48210
48211 if (free_clusters >= (nclusters + dirty_clusters))
48212 return 1;
48213 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
48214 index 8462eb3..4a71af6 100644
48215 --- a/fs/ext4/ext4.h
48216 +++ b/fs/ext4/ext4.h
48217 @@ -1265,19 +1265,19 @@ struct ext4_sb_info {
48218 unsigned long s_mb_last_start;
48219
48220 /* stats for buddy allocator */
48221 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
48222 - atomic_t s_bal_success; /* we found long enough chunks */
48223 - atomic_t s_bal_allocated; /* in blocks */
48224 - atomic_t s_bal_ex_scanned; /* total extents scanned */
48225 - atomic_t s_bal_goals; /* goal hits */
48226 - atomic_t s_bal_breaks; /* too long searches */
48227 - atomic_t s_bal_2orders; /* 2^order hits */
48228 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
48229 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
48230 + atomic_unchecked_t s_bal_allocated; /* in blocks */
48231 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
48232 + atomic_unchecked_t s_bal_goals; /* goal hits */
48233 + atomic_unchecked_t s_bal_breaks; /* too long searches */
48234 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
48235 spinlock_t s_bal_lock;
48236 unsigned long s_mb_buddies_generated;
48237 unsigned long long s_mb_generation_time;
48238 - atomic_t s_mb_lost_chunks;
48239 - atomic_t s_mb_preallocated;
48240 - atomic_t s_mb_discarded;
48241 + atomic_unchecked_t s_mb_lost_chunks;
48242 + atomic_unchecked_t s_mb_preallocated;
48243 + atomic_unchecked_t s_mb_discarded;
48244 atomic_t s_lock_busy;
48245
48246 /* locality groups */
48247 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
48248 index 1bf6fe7..1a5bdef 100644
48249 --- a/fs/ext4/mballoc.c
48250 +++ b/fs/ext4/mballoc.c
48251 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
48252 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
48253
48254 if (EXT4_SB(sb)->s_mb_stats)
48255 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
48256 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
48257
48258 break;
48259 }
48260 @@ -2044,7 +2044,7 @@ repeat:
48261 ac->ac_status = AC_STATUS_CONTINUE;
48262 ac->ac_flags |= EXT4_MB_HINT_FIRST;
48263 cr = 3;
48264 - atomic_inc(&sbi->s_mb_lost_chunks);
48265 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
48266 goto repeat;
48267 }
48268 }
48269 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
48270 if (sbi->s_mb_stats) {
48271 ext4_msg(sb, KERN_INFO,
48272 "mballoc: %u blocks %u reqs (%u success)",
48273 - atomic_read(&sbi->s_bal_allocated),
48274 - atomic_read(&sbi->s_bal_reqs),
48275 - atomic_read(&sbi->s_bal_success));
48276 + atomic_read_unchecked(&sbi->s_bal_allocated),
48277 + atomic_read_unchecked(&sbi->s_bal_reqs),
48278 + atomic_read_unchecked(&sbi->s_bal_success));
48279 ext4_msg(sb, KERN_INFO,
48280 "mballoc: %u extents scanned, %u goal hits, "
48281 "%u 2^N hits, %u breaks, %u lost",
48282 - atomic_read(&sbi->s_bal_ex_scanned),
48283 - atomic_read(&sbi->s_bal_goals),
48284 - atomic_read(&sbi->s_bal_2orders),
48285 - atomic_read(&sbi->s_bal_breaks),
48286 - atomic_read(&sbi->s_mb_lost_chunks));
48287 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
48288 + atomic_read_unchecked(&sbi->s_bal_goals),
48289 + atomic_read_unchecked(&sbi->s_bal_2orders),
48290 + atomic_read_unchecked(&sbi->s_bal_breaks),
48291 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
48292 ext4_msg(sb, KERN_INFO,
48293 "mballoc: %lu generated and it took %Lu",
48294 sbi->s_mb_buddies_generated,
48295 sbi->s_mb_generation_time);
48296 ext4_msg(sb, KERN_INFO,
48297 "mballoc: %u preallocated, %u discarded",
48298 - atomic_read(&sbi->s_mb_preallocated),
48299 - atomic_read(&sbi->s_mb_discarded));
48300 + atomic_read_unchecked(&sbi->s_mb_preallocated),
48301 + atomic_read_unchecked(&sbi->s_mb_discarded));
48302 }
48303
48304 free_percpu(sbi->s_locality_groups);
48305 @@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
48306 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
48307
48308 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
48309 - atomic_inc(&sbi->s_bal_reqs);
48310 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48311 + atomic_inc_unchecked(&sbi->s_bal_reqs);
48312 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
48313 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
48314 - atomic_inc(&sbi->s_bal_success);
48315 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
48316 + atomic_inc_unchecked(&sbi->s_bal_success);
48317 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
48318 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
48319 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
48320 - atomic_inc(&sbi->s_bal_goals);
48321 + atomic_inc_unchecked(&sbi->s_bal_goals);
48322 if (ac->ac_found > sbi->s_mb_max_to_scan)
48323 - atomic_inc(&sbi->s_bal_breaks);
48324 + atomic_inc_unchecked(&sbi->s_bal_breaks);
48325 }
48326
48327 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
48328 @@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
48329 trace_ext4_mb_new_inode_pa(ac, pa);
48330
48331 ext4_mb_use_inode_pa(ac, pa);
48332 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
48333 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
48334
48335 ei = EXT4_I(ac->ac_inode);
48336 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48337 @@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
48338 trace_ext4_mb_new_group_pa(ac, pa);
48339
48340 ext4_mb_use_group_pa(ac, pa);
48341 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48342 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
48343
48344 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
48345 lg = ac->ac_lg;
48346 @@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
48347 * from the bitmap and continue.
48348 */
48349 }
48350 - atomic_add(free, &sbi->s_mb_discarded);
48351 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
48352
48353 return err;
48354 }
48355 @@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
48356 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
48357 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
48358 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
48359 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48360 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
48361 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
48362
48363 return 0;
48364 diff --git a/fs/fcntl.c b/fs/fcntl.c
48365 index 71a600a..20d87b1 100644
48366 --- a/fs/fcntl.c
48367 +++ b/fs/fcntl.c
48368 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
48369 if (err)
48370 return err;
48371
48372 + if (gr_handle_chroot_fowner(pid, type))
48373 + return -ENOENT;
48374 + if (gr_check_protected_task_fowner(pid, type))
48375 + return -EACCES;
48376 +
48377 f_modown(filp, pid, type, force);
48378 return 0;
48379 }
48380 diff --git a/fs/fhandle.c b/fs/fhandle.c
48381 index 999ff5c..41f4109 100644
48382 --- a/fs/fhandle.c
48383 +++ b/fs/fhandle.c
48384 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
48385 } else
48386 retval = 0;
48387 /* copy the mount id */
48388 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
48389 - sizeof(*mnt_id)) ||
48390 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
48391 copy_to_user(ufh, handle,
48392 sizeof(struct file_handle) + handle_bytes))
48393 retval = -EFAULT;
48394 diff --git a/fs/fifo.c b/fs/fifo.c
48395 index cf6f434..3d7942c 100644
48396 --- a/fs/fifo.c
48397 +++ b/fs/fifo.c
48398 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
48399 */
48400 filp->f_op = &read_pipefifo_fops;
48401 pipe->r_counter++;
48402 - if (pipe->readers++ == 0)
48403 + if (atomic_inc_return(&pipe->readers) == 1)
48404 wake_up_partner(inode);
48405
48406 - if (!pipe->writers) {
48407 + if (!atomic_read(&pipe->writers)) {
48408 if ((filp->f_flags & O_NONBLOCK)) {
48409 /* suppress POLLHUP until we have
48410 * seen a writer */
48411 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
48412 * errno=ENXIO when there is no process reading the FIFO.
48413 */
48414 ret = -ENXIO;
48415 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
48416 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
48417 goto err;
48418
48419 filp->f_op = &write_pipefifo_fops;
48420 pipe->w_counter++;
48421 - if (!pipe->writers++)
48422 + if (atomic_inc_return(&pipe->writers) == 1)
48423 wake_up_partner(inode);
48424
48425 - if (!pipe->readers) {
48426 + if (!atomic_read(&pipe->readers)) {
48427 if (wait_for_partner(inode, &pipe->r_counter))
48428 goto err_wr;
48429 }
48430 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
48431 */
48432 filp->f_op = &rdwr_pipefifo_fops;
48433
48434 - pipe->readers++;
48435 - pipe->writers++;
48436 + atomic_inc(&pipe->readers);
48437 + atomic_inc(&pipe->writers);
48438 pipe->r_counter++;
48439 pipe->w_counter++;
48440 - if (pipe->readers == 1 || pipe->writers == 1)
48441 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
48442 wake_up_partner(inode);
48443 break;
48444
48445 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
48446 return 0;
48447
48448 err_rd:
48449 - if (!--pipe->readers)
48450 + if (atomic_dec_and_test(&pipe->readers))
48451 wake_up_interruptible(&pipe->wait);
48452 ret = -ERESTARTSYS;
48453 goto err;
48454
48455 err_wr:
48456 - if (!--pipe->writers)
48457 + if (atomic_dec_and_test(&pipe->writers))
48458 wake_up_interruptible(&pipe->wait);
48459 ret = -ERESTARTSYS;
48460 goto err;
48461
48462 err:
48463 - if (!pipe->readers && !pipe->writers)
48464 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
48465 free_pipe_info(inode);
48466
48467 err_nocleanup:
48468 diff --git a/fs/file.c b/fs/file.c
48469 index 2b3570b..c57924b 100644
48470 --- a/fs/file.c
48471 +++ b/fs/file.c
48472 @@ -16,6 +16,7 @@
48473 #include <linux/slab.h>
48474 #include <linux/vmalloc.h>
48475 #include <linux/file.h>
48476 +#include <linux/security.h>
48477 #include <linux/fdtable.h>
48478 #include <linux/bitops.h>
48479 #include <linux/interrupt.h>
48480 @@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
48481 if (!file)
48482 return __close_fd(files, fd);
48483
48484 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
48485 if (fd >= rlimit(RLIMIT_NOFILE))
48486 return -EBADF;
48487
48488 @@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
48489 if (unlikely(oldfd == newfd))
48490 return -EINVAL;
48491
48492 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
48493 if (newfd >= rlimit(RLIMIT_NOFILE))
48494 return -EBADF;
48495
48496 @@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
48497 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
48498 {
48499 int err;
48500 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
48501 if (from >= rlimit(RLIMIT_NOFILE))
48502 return -EINVAL;
48503 err = alloc_fd(from, flags);
48504 diff --git a/fs/filesystems.c b/fs/filesystems.c
48505 index da165f6..3671bdb 100644
48506 --- a/fs/filesystems.c
48507 +++ b/fs/filesystems.c
48508 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
48509 int len = dot ? dot - name : strlen(name);
48510
48511 fs = __get_fs_type(name, len);
48512 +
48513 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
48514 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
48515 +#else
48516 if (!fs && (request_module("%.*s", len, name) == 0))
48517 +#endif
48518 fs = __get_fs_type(name, len);
48519
48520 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
48521 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
48522 index fe6ca58..65318cf 100644
48523 --- a/fs/fs_struct.c
48524 +++ b/fs/fs_struct.c
48525 @@ -4,6 +4,7 @@
48526 #include <linux/path.h>
48527 #include <linux/slab.h>
48528 #include <linux/fs_struct.h>
48529 +#include <linux/grsecurity.h>
48530 #include "internal.h"
48531
48532 /*
48533 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
48534 write_seqcount_begin(&fs->seq);
48535 old_root = fs->root;
48536 fs->root = *path;
48537 + gr_set_chroot_entries(current, path);
48538 write_seqcount_end(&fs->seq);
48539 spin_unlock(&fs->lock);
48540 if (old_root.dentry)
48541 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
48542 return 1;
48543 }
48544
48545 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
48546 +{
48547 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
48548 + return 0;
48549 + *p = *new;
48550 +
48551 + /* This function is only called from pivot_root(). Leave our
48552 + gr_chroot_dentry and is_chrooted flags as-is, so that a
48553 + pivoted root isn't treated as a chroot
48554 + */
48555 + //gr_set_chroot_entries(task, new);
48556 +
48557 + return 1;
48558 +}
48559 +
48560 void chroot_fs_refs(struct path *old_root, struct path *new_root)
48561 {
48562 struct task_struct *g, *p;
48563 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
48564 int hits = 0;
48565 spin_lock(&fs->lock);
48566 write_seqcount_begin(&fs->seq);
48567 - hits += replace_path(&fs->root, old_root, new_root);
48568 + hits += replace_root_path(p, &fs->root, old_root, new_root);
48569 hits += replace_path(&fs->pwd, old_root, new_root);
48570 write_seqcount_end(&fs->seq);
48571 while (hits--) {
48572 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
48573 task_lock(tsk);
48574 spin_lock(&fs->lock);
48575 tsk->fs = NULL;
48576 - kill = !--fs->users;
48577 + gr_clear_chroot_entries(tsk);
48578 + kill = !atomic_dec_return(&fs->users);
48579 spin_unlock(&fs->lock);
48580 task_unlock(tsk);
48581 if (kill)
48582 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48583 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
48584 /* We don't need to lock fs - think why ;-) */
48585 if (fs) {
48586 - fs->users = 1;
48587 + atomic_set(&fs->users, 1);
48588 fs->in_exec = 0;
48589 spin_lock_init(&fs->lock);
48590 seqcount_init(&fs->seq);
48591 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
48592 spin_lock(&old->lock);
48593 fs->root = old->root;
48594 path_get(&fs->root);
48595 + /* instead of calling gr_set_chroot_entries here,
48596 + we call it from every caller of this function
48597 + */
48598 fs->pwd = old->pwd;
48599 path_get(&fs->pwd);
48600 spin_unlock(&old->lock);
48601 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
48602
48603 task_lock(current);
48604 spin_lock(&fs->lock);
48605 - kill = !--fs->users;
48606 + kill = !atomic_dec_return(&fs->users);
48607 current->fs = new_fs;
48608 + gr_set_chroot_entries(current, &new_fs->root);
48609 spin_unlock(&fs->lock);
48610 task_unlock(current);
48611
48612 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
48613
48614 int current_umask(void)
48615 {
48616 - return current->fs->umask;
48617 + return current->fs->umask | gr_acl_umask();
48618 }
48619 EXPORT_SYMBOL(current_umask);
48620
48621 /* to be mentioned only in INIT_TASK */
48622 struct fs_struct init_fs = {
48623 - .users = 1,
48624 + .users = ATOMIC_INIT(1),
48625 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
48626 .seq = SEQCNT_ZERO,
48627 .umask = 0022,
48628 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
48629 index 8dcb114..b1072e2 100644
48630 --- a/fs/fscache/cookie.c
48631 +++ b/fs/fscache/cookie.c
48632 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
48633 parent ? (char *) parent->def->name : "<no-parent>",
48634 def->name, netfs_data);
48635
48636 - fscache_stat(&fscache_n_acquires);
48637 + fscache_stat_unchecked(&fscache_n_acquires);
48638
48639 /* if there's no parent cookie, then we don't create one here either */
48640 if (!parent) {
48641 - fscache_stat(&fscache_n_acquires_null);
48642 + fscache_stat_unchecked(&fscache_n_acquires_null);
48643 _leave(" [no parent]");
48644 return NULL;
48645 }
48646 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
48647 /* allocate and initialise a cookie */
48648 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
48649 if (!cookie) {
48650 - fscache_stat(&fscache_n_acquires_oom);
48651 + fscache_stat_unchecked(&fscache_n_acquires_oom);
48652 _leave(" [ENOMEM]");
48653 return NULL;
48654 }
48655 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48656
48657 switch (cookie->def->type) {
48658 case FSCACHE_COOKIE_TYPE_INDEX:
48659 - fscache_stat(&fscache_n_cookie_index);
48660 + fscache_stat_unchecked(&fscache_n_cookie_index);
48661 break;
48662 case FSCACHE_COOKIE_TYPE_DATAFILE:
48663 - fscache_stat(&fscache_n_cookie_data);
48664 + fscache_stat_unchecked(&fscache_n_cookie_data);
48665 break;
48666 default:
48667 - fscache_stat(&fscache_n_cookie_special);
48668 + fscache_stat_unchecked(&fscache_n_cookie_special);
48669 break;
48670 }
48671
48672 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
48673 if (fscache_acquire_non_index_cookie(cookie) < 0) {
48674 atomic_dec(&parent->n_children);
48675 __fscache_cookie_put(cookie);
48676 - fscache_stat(&fscache_n_acquires_nobufs);
48677 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
48678 _leave(" = NULL");
48679 return NULL;
48680 }
48681 }
48682
48683 - fscache_stat(&fscache_n_acquires_ok);
48684 + fscache_stat_unchecked(&fscache_n_acquires_ok);
48685 _leave(" = %p", cookie);
48686 return cookie;
48687 }
48688 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
48689 cache = fscache_select_cache_for_object(cookie->parent);
48690 if (!cache) {
48691 up_read(&fscache_addremove_sem);
48692 - fscache_stat(&fscache_n_acquires_no_cache);
48693 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
48694 _leave(" = -ENOMEDIUM [no cache]");
48695 return -ENOMEDIUM;
48696 }
48697 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
48698 object = cache->ops->alloc_object(cache, cookie);
48699 fscache_stat_d(&fscache_n_cop_alloc_object);
48700 if (IS_ERR(object)) {
48701 - fscache_stat(&fscache_n_object_no_alloc);
48702 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
48703 ret = PTR_ERR(object);
48704 goto error;
48705 }
48706
48707 - fscache_stat(&fscache_n_object_alloc);
48708 + fscache_stat_unchecked(&fscache_n_object_alloc);
48709
48710 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
48711
48712 @@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
48713
48714 _enter("{%s}", cookie->def->name);
48715
48716 - fscache_stat(&fscache_n_invalidates);
48717 + fscache_stat_unchecked(&fscache_n_invalidates);
48718
48719 /* Only permit invalidation of data files. Invalidating an index will
48720 * require the caller to release all its attachments to the tree rooted
48721 @@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
48722 struct fscache_object *object;
48723 struct hlist_node *_p;
48724
48725 - fscache_stat(&fscache_n_updates);
48726 + fscache_stat_unchecked(&fscache_n_updates);
48727
48728 if (!cookie) {
48729 - fscache_stat(&fscache_n_updates_null);
48730 + fscache_stat_unchecked(&fscache_n_updates_null);
48731 _leave(" [no cookie]");
48732 return;
48733 }
48734 @@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48735 struct fscache_object *object;
48736 unsigned long event;
48737
48738 - fscache_stat(&fscache_n_relinquishes);
48739 + fscache_stat_unchecked(&fscache_n_relinquishes);
48740 if (retire)
48741 - fscache_stat(&fscache_n_relinquishes_retire);
48742 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
48743
48744 if (!cookie) {
48745 - fscache_stat(&fscache_n_relinquishes_null);
48746 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
48747 _leave(" [no cookie]");
48748 return;
48749 }
48750 @@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
48751
48752 /* wait for the cookie to finish being instantiated (or to fail) */
48753 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
48754 - fscache_stat(&fscache_n_relinquishes_waitcrt);
48755 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
48756 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
48757 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
48758 }
48759 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
48760 index ee38fef..0a326d4 100644
48761 --- a/fs/fscache/internal.h
48762 +++ b/fs/fscache/internal.h
48763 @@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
48764 * stats.c
48765 */
48766 #ifdef CONFIG_FSCACHE_STATS
48767 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48768 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48769 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
48770 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
48771
48772 -extern atomic_t fscache_n_op_pend;
48773 -extern atomic_t fscache_n_op_run;
48774 -extern atomic_t fscache_n_op_enqueue;
48775 -extern atomic_t fscache_n_op_deferred_release;
48776 -extern atomic_t fscache_n_op_release;
48777 -extern atomic_t fscache_n_op_gc;
48778 -extern atomic_t fscache_n_op_cancelled;
48779 -extern atomic_t fscache_n_op_rejected;
48780 +extern atomic_unchecked_t fscache_n_op_pend;
48781 +extern atomic_unchecked_t fscache_n_op_run;
48782 +extern atomic_unchecked_t fscache_n_op_enqueue;
48783 +extern atomic_unchecked_t fscache_n_op_deferred_release;
48784 +extern atomic_unchecked_t fscache_n_op_release;
48785 +extern atomic_unchecked_t fscache_n_op_gc;
48786 +extern atomic_unchecked_t fscache_n_op_cancelled;
48787 +extern atomic_unchecked_t fscache_n_op_rejected;
48788
48789 -extern atomic_t fscache_n_attr_changed;
48790 -extern atomic_t fscache_n_attr_changed_ok;
48791 -extern atomic_t fscache_n_attr_changed_nobufs;
48792 -extern atomic_t fscache_n_attr_changed_nomem;
48793 -extern atomic_t fscache_n_attr_changed_calls;
48794 +extern atomic_unchecked_t fscache_n_attr_changed;
48795 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
48796 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
48797 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
48798 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
48799
48800 -extern atomic_t fscache_n_allocs;
48801 -extern atomic_t fscache_n_allocs_ok;
48802 -extern atomic_t fscache_n_allocs_wait;
48803 -extern atomic_t fscache_n_allocs_nobufs;
48804 -extern atomic_t fscache_n_allocs_intr;
48805 -extern atomic_t fscache_n_allocs_object_dead;
48806 -extern atomic_t fscache_n_alloc_ops;
48807 -extern atomic_t fscache_n_alloc_op_waits;
48808 +extern atomic_unchecked_t fscache_n_allocs;
48809 +extern atomic_unchecked_t fscache_n_allocs_ok;
48810 +extern atomic_unchecked_t fscache_n_allocs_wait;
48811 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
48812 +extern atomic_unchecked_t fscache_n_allocs_intr;
48813 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
48814 +extern atomic_unchecked_t fscache_n_alloc_ops;
48815 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
48816
48817 -extern atomic_t fscache_n_retrievals;
48818 -extern atomic_t fscache_n_retrievals_ok;
48819 -extern atomic_t fscache_n_retrievals_wait;
48820 -extern atomic_t fscache_n_retrievals_nodata;
48821 -extern atomic_t fscache_n_retrievals_nobufs;
48822 -extern atomic_t fscache_n_retrievals_intr;
48823 -extern atomic_t fscache_n_retrievals_nomem;
48824 -extern atomic_t fscache_n_retrievals_object_dead;
48825 -extern atomic_t fscache_n_retrieval_ops;
48826 -extern atomic_t fscache_n_retrieval_op_waits;
48827 +extern atomic_unchecked_t fscache_n_retrievals;
48828 +extern atomic_unchecked_t fscache_n_retrievals_ok;
48829 +extern atomic_unchecked_t fscache_n_retrievals_wait;
48830 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
48831 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
48832 +extern atomic_unchecked_t fscache_n_retrievals_intr;
48833 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
48834 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
48835 +extern atomic_unchecked_t fscache_n_retrieval_ops;
48836 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
48837
48838 -extern atomic_t fscache_n_stores;
48839 -extern atomic_t fscache_n_stores_ok;
48840 -extern atomic_t fscache_n_stores_again;
48841 -extern atomic_t fscache_n_stores_nobufs;
48842 -extern atomic_t fscache_n_stores_oom;
48843 -extern atomic_t fscache_n_store_ops;
48844 -extern atomic_t fscache_n_store_calls;
48845 -extern atomic_t fscache_n_store_pages;
48846 -extern atomic_t fscache_n_store_radix_deletes;
48847 -extern atomic_t fscache_n_store_pages_over_limit;
48848 +extern atomic_unchecked_t fscache_n_stores;
48849 +extern atomic_unchecked_t fscache_n_stores_ok;
48850 +extern atomic_unchecked_t fscache_n_stores_again;
48851 +extern atomic_unchecked_t fscache_n_stores_nobufs;
48852 +extern atomic_unchecked_t fscache_n_stores_oom;
48853 +extern atomic_unchecked_t fscache_n_store_ops;
48854 +extern atomic_unchecked_t fscache_n_store_calls;
48855 +extern atomic_unchecked_t fscache_n_store_pages;
48856 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
48857 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
48858
48859 -extern atomic_t fscache_n_store_vmscan_not_storing;
48860 -extern atomic_t fscache_n_store_vmscan_gone;
48861 -extern atomic_t fscache_n_store_vmscan_busy;
48862 -extern atomic_t fscache_n_store_vmscan_cancelled;
48863 -extern atomic_t fscache_n_store_vmscan_wait;
48864 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48865 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
48866 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
48867 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48868 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
48869
48870 -extern atomic_t fscache_n_marks;
48871 -extern atomic_t fscache_n_uncaches;
48872 +extern atomic_unchecked_t fscache_n_marks;
48873 +extern atomic_unchecked_t fscache_n_uncaches;
48874
48875 -extern atomic_t fscache_n_acquires;
48876 -extern atomic_t fscache_n_acquires_null;
48877 -extern atomic_t fscache_n_acquires_no_cache;
48878 -extern atomic_t fscache_n_acquires_ok;
48879 -extern atomic_t fscache_n_acquires_nobufs;
48880 -extern atomic_t fscache_n_acquires_oom;
48881 +extern atomic_unchecked_t fscache_n_acquires;
48882 +extern atomic_unchecked_t fscache_n_acquires_null;
48883 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
48884 +extern atomic_unchecked_t fscache_n_acquires_ok;
48885 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
48886 +extern atomic_unchecked_t fscache_n_acquires_oom;
48887
48888 -extern atomic_t fscache_n_invalidates;
48889 -extern atomic_t fscache_n_invalidates_run;
48890 +extern atomic_unchecked_t fscache_n_invalidates;
48891 +extern atomic_unchecked_t fscache_n_invalidates_run;
48892
48893 -extern atomic_t fscache_n_updates;
48894 -extern atomic_t fscache_n_updates_null;
48895 -extern atomic_t fscache_n_updates_run;
48896 +extern atomic_unchecked_t fscache_n_updates;
48897 +extern atomic_unchecked_t fscache_n_updates_null;
48898 +extern atomic_unchecked_t fscache_n_updates_run;
48899
48900 -extern atomic_t fscache_n_relinquishes;
48901 -extern atomic_t fscache_n_relinquishes_null;
48902 -extern atomic_t fscache_n_relinquishes_waitcrt;
48903 -extern atomic_t fscache_n_relinquishes_retire;
48904 +extern atomic_unchecked_t fscache_n_relinquishes;
48905 +extern atomic_unchecked_t fscache_n_relinquishes_null;
48906 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48907 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
48908
48909 -extern atomic_t fscache_n_cookie_index;
48910 -extern atomic_t fscache_n_cookie_data;
48911 -extern atomic_t fscache_n_cookie_special;
48912 +extern atomic_unchecked_t fscache_n_cookie_index;
48913 +extern atomic_unchecked_t fscache_n_cookie_data;
48914 +extern atomic_unchecked_t fscache_n_cookie_special;
48915
48916 -extern atomic_t fscache_n_object_alloc;
48917 -extern atomic_t fscache_n_object_no_alloc;
48918 -extern atomic_t fscache_n_object_lookups;
48919 -extern atomic_t fscache_n_object_lookups_negative;
48920 -extern atomic_t fscache_n_object_lookups_positive;
48921 -extern atomic_t fscache_n_object_lookups_timed_out;
48922 -extern atomic_t fscache_n_object_created;
48923 -extern atomic_t fscache_n_object_avail;
48924 -extern atomic_t fscache_n_object_dead;
48925 +extern atomic_unchecked_t fscache_n_object_alloc;
48926 +extern atomic_unchecked_t fscache_n_object_no_alloc;
48927 +extern atomic_unchecked_t fscache_n_object_lookups;
48928 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
48929 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
48930 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
48931 +extern atomic_unchecked_t fscache_n_object_created;
48932 +extern atomic_unchecked_t fscache_n_object_avail;
48933 +extern atomic_unchecked_t fscache_n_object_dead;
48934
48935 -extern atomic_t fscache_n_checkaux_none;
48936 -extern atomic_t fscache_n_checkaux_okay;
48937 -extern atomic_t fscache_n_checkaux_update;
48938 -extern atomic_t fscache_n_checkaux_obsolete;
48939 +extern atomic_unchecked_t fscache_n_checkaux_none;
48940 +extern atomic_unchecked_t fscache_n_checkaux_okay;
48941 +extern atomic_unchecked_t fscache_n_checkaux_update;
48942 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
48943
48944 extern atomic_t fscache_n_cop_alloc_object;
48945 extern atomic_t fscache_n_cop_lookup_object;
48946 @@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
48947 atomic_inc(stat);
48948 }
48949
48950 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
48951 +{
48952 + atomic_inc_unchecked(stat);
48953 +}
48954 +
48955 static inline void fscache_stat_d(atomic_t *stat)
48956 {
48957 atomic_dec(stat);
48958 @@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
48959
48960 #define __fscache_stat(stat) (NULL)
48961 #define fscache_stat(stat) do {} while (0)
48962 +#define fscache_stat_unchecked(stat) do {} while (0)
48963 #define fscache_stat_d(stat) do {} while (0)
48964 #endif
48965
48966 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
48967 index 50d41c1..10ee117 100644
48968 --- a/fs/fscache/object.c
48969 +++ b/fs/fscache/object.c
48970 @@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48971 /* Invalidate an object on disk */
48972 case FSCACHE_OBJECT_INVALIDATING:
48973 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
48974 - fscache_stat(&fscache_n_invalidates_run);
48975 + fscache_stat_unchecked(&fscache_n_invalidates_run);
48976 fscache_stat(&fscache_n_cop_invalidate_object);
48977 fscache_invalidate_object(object);
48978 fscache_stat_d(&fscache_n_cop_invalidate_object);
48979 @@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48980 /* update the object metadata on disk */
48981 case FSCACHE_OBJECT_UPDATING:
48982 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
48983 - fscache_stat(&fscache_n_updates_run);
48984 + fscache_stat_unchecked(&fscache_n_updates_run);
48985 fscache_stat(&fscache_n_cop_update_object);
48986 object->cache->ops->update_object(object);
48987 fscache_stat_d(&fscache_n_cop_update_object);
48988 @@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48989 spin_lock(&object->lock);
48990 object->state = FSCACHE_OBJECT_DEAD;
48991 spin_unlock(&object->lock);
48992 - fscache_stat(&fscache_n_object_dead);
48993 + fscache_stat_unchecked(&fscache_n_object_dead);
48994 goto terminal_transit;
48995
48996 /* handle the parent cache of this object being withdrawn from
48997 @@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
48998 spin_lock(&object->lock);
48999 object->state = FSCACHE_OBJECT_DEAD;
49000 spin_unlock(&object->lock);
49001 - fscache_stat(&fscache_n_object_dead);
49002 + fscache_stat_unchecked(&fscache_n_object_dead);
49003 goto terminal_transit;
49004
49005 /* complain about the object being woken up once it is
49006 @@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49007 parent->cookie->def->name, cookie->def->name,
49008 object->cache->tag->name);
49009
49010 - fscache_stat(&fscache_n_object_lookups);
49011 + fscache_stat_unchecked(&fscache_n_object_lookups);
49012 fscache_stat(&fscache_n_cop_lookup_object);
49013 ret = object->cache->ops->lookup_object(object);
49014 fscache_stat_d(&fscache_n_cop_lookup_object);
49015 @@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
49016 if (ret == -ETIMEDOUT) {
49017 /* probably stuck behind another object, so move this one to
49018 * the back of the queue */
49019 - fscache_stat(&fscache_n_object_lookups_timed_out);
49020 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
49021 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49022 }
49023
49024 @@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
49025
49026 spin_lock(&object->lock);
49027 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49028 - fscache_stat(&fscache_n_object_lookups_negative);
49029 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
49030
49031 /* transit here to allow write requests to begin stacking up
49032 * and read requests to begin returning ENODATA */
49033 @@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
49034 * result, in which case there may be data available */
49035 spin_lock(&object->lock);
49036 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
49037 - fscache_stat(&fscache_n_object_lookups_positive);
49038 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
49039
49040 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
49041
49042 @@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
49043 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
49044 } else {
49045 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
49046 - fscache_stat(&fscache_n_object_created);
49047 + fscache_stat_unchecked(&fscache_n_object_created);
49048
49049 object->state = FSCACHE_OBJECT_AVAILABLE;
49050 spin_unlock(&object->lock);
49051 @@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
49052 fscache_enqueue_dependents(object);
49053
49054 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
49055 - fscache_stat(&fscache_n_object_avail);
49056 + fscache_stat_unchecked(&fscache_n_object_avail);
49057
49058 _leave("");
49059 }
49060 @@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49061 enum fscache_checkaux result;
49062
49063 if (!object->cookie->def->check_aux) {
49064 - fscache_stat(&fscache_n_checkaux_none);
49065 + fscache_stat_unchecked(&fscache_n_checkaux_none);
49066 return FSCACHE_CHECKAUX_OKAY;
49067 }
49068
49069 @@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
49070 switch (result) {
49071 /* entry okay as is */
49072 case FSCACHE_CHECKAUX_OKAY:
49073 - fscache_stat(&fscache_n_checkaux_okay);
49074 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
49075 break;
49076
49077 /* entry requires update */
49078 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
49079 - fscache_stat(&fscache_n_checkaux_update);
49080 + fscache_stat_unchecked(&fscache_n_checkaux_update);
49081 break;
49082
49083 /* entry requires deletion */
49084 case FSCACHE_CHECKAUX_OBSOLETE:
49085 - fscache_stat(&fscache_n_checkaux_obsolete);
49086 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
49087 break;
49088
49089 default:
49090 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
49091 index 762a9ec..2023284 100644
49092 --- a/fs/fscache/operation.c
49093 +++ b/fs/fscache/operation.c
49094 @@ -17,7 +17,7 @@
49095 #include <linux/slab.h>
49096 #include "internal.h"
49097
49098 -atomic_t fscache_op_debug_id;
49099 +atomic_unchecked_t fscache_op_debug_id;
49100 EXPORT_SYMBOL(fscache_op_debug_id);
49101
49102 /**
49103 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
49104 ASSERTCMP(atomic_read(&op->usage), >, 0);
49105 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
49106
49107 - fscache_stat(&fscache_n_op_enqueue);
49108 + fscache_stat_unchecked(&fscache_n_op_enqueue);
49109 switch (op->flags & FSCACHE_OP_TYPE) {
49110 case FSCACHE_OP_ASYNC:
49111 _debug("queue async");
49112 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
49113 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
49114 if (op->processor)
49115 fscache_enqueue_operation(op);
49116 - fscache_stat(&fscache_n_op_run);
49117 + fscache_stat_unchecked(&fscache_n_op_run);
49118 }
49119
49120 /*
49121 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49122 if (object->n_in_progress > 0) {
49123 atomic_inc(&op->usage);
49124 list_add_tail(&op->pend_link, &object->pending_ops);
49125 - fscache_stat(&fscache_n_op_pend);
49126 + fscache_stat_unchecked(&fscache_n_op_pend);
49127 } else if (!list_empty(&object->pending_ops)) {
49128 atomic_inc(&op->usage);
49129 list_add_tail(&op->pend_link, &object->pending_ops);
49130 - fscache_stat(&fscache_n_op_pend);
49131 + fscache_stat_unchecked(&fscache_n_op_pend);
49132 fscache_start_operations(object);
49133 } else {
49134 ASSERTCMP(object->n_in_progress, ==, 0);
49135 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
49136 object->n_exclusive++; /* reads and writes must wait */
49137 atomic_inc(&op->usage);
49138 list_add_tail(&op->pend_link, &object->pending_ops);
49139 - fscache_stat(&fscache_n_op_pend);
49140 + fscache_stat_unchecked(&fscache_n_op_pend);
49141 ret = 0;
49142 } else {
49143 /* If we're in any other state, there must have been an I/O
49144 @@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
49145 if (object->n_exclusive > 0) {
49146 atomic_inc(&op->usage);
49147 list_add_tail(&op->pend_link, &object->pending_ops);
49148 - fscache_stat(&fscache_n_op_pend);
49149 + fscache_stat_unchecked(&fscache_n_op_pend);
49150 } else if (!list_empty(&object->pending_ops)) {
49151 atomic_inc(&op->usage);
49152 list_add_tail(&op->pend_link, &object->pending_ops);
49153 - fscache_stat(&fscache_n_op_pend);
49154 + fscache_stat_unchecked(&fscache_n_op_pend);
49155 fscache_start_operations(object);
49156 } else {
49157 ASSERTCMP(object->n_exclusive, ==, 0);
49158 @@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
49159 object->n_ops++;
49160 atomic_inc(&op->usage);
49161 list_add_tail(&op->pend_link, &object->pending_ops);
49162 - fscache_stat(&fscache_n_op_pend);
49163 + fscache_stat_unchecked(&fscache_n_op_pend);
49164 ret = 0;
49165 } else if (object->state == FSCACHE_OBJECT_DYING ||
49166 object->state == FSCACHE_OBJECT_LC_DYING ||
49167 object->state == FSCACHE_OBJECT_WITHDRAWING) {
49168 - fscache_stat(&fscache_n_op_rejected);
49169 + fscache_stat_unchecked(&fscache_n_op_rejected);
49170 op->state = FSCACHE_OP_ST_CANCELLED;
49171 ret = -ENOBUFS;
49172 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
49173 @@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
49174 ret = -EBUSY;
49175 if (op->state == FSCACHE_OP_ST_PENDING) {
49176 ASSERT(!list_empty(&op->pend_link));
49177 - fscache_stat(&fscache_n_op_cancelled);
49178 + fscache_stat_unchecked(&fscache_n_op_cancelled);
49179 list_del_init(&op->pend_link);
49180 if (do_cancel)
49181 do_cancel(op);
49182 @@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
49183 while (!list_empty(&object->pending_ops)) {
49184 op = list_entry(object->pending_ops.next,
49185 struct fscache_operation, pend_link);
49186 - fscache_stat(&fscache_n_op_cancelled);
49187 + fscache_stat_unchecked(&fscache_n_op_cancelled);
49188 list_del_init(&op->pend_link);
49189
49190 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
49191 @@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
49192 op->state, ==, FSCACHE_OP_ST_CANCELLED);
49193 op->state = FSCACHE_OP_ST_DEAD;
49194
49195 - fscache_stat(&fscache_n_op_release);
49196 + fscache_stat_unchecked(&fscache_n_op_release);
49197
49198 if (op->release) {
49199 op->release(op);
49200 @@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
49201 * lock, and defer it otherwise */
49202 if (!spin_trylock(&object->lock)) {
49203 _debug("defer put");
49204 - fscache_stat(&fscache_n_op_deferred_release);
49205 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
49206
49207 cache = object->cache;
49208 spin_lock(&cache->op_gc_list_lock);
49209 @@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
49210
49211 _debug("GC DEFERRED REL OBJ%x OP%x",
49212 object->debug_id, op->debug_id);
49213 - fscache_stat(&fscache_n_op_gc);
49214 + fscache_stat_unchecked(&fscache_n_op_gc);
49215
49216 ASSERTCMP(atomic_read(&op->usage), ==, 0);
49217 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
49218 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
49219 index ff000e5..c44ec6d 100644
49220 --- a/fs/fscache/page.c
49221 +++ b/fs/fscache/page.c
49222 @@ -61,7 +61,7 @@ try_again:
49223 val = radix_tree_lookup(&cookie->stores, page->index);
49224 if (!val) {
49225 rcu_read_unlock();
49226 - fscache_stat(&fscache_n_store_vmscan_not_storing);
49227 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
49228 __fscache_uncache_page(cookie, page);
49229 return true;
49230 }
49231 @@ -91,11 +91,11 @@ try_again:
49232 spin_unlock(&cookie->stores_lock);
49233
49234 if (xpage) {
49235 - fscache_stat(&fscache_n_store_vmscan_cancelled);
49236 - fscache_stat(&fscache_n_store_radix_deletes);
49237 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
49238 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49239 ASSERTCMP(xpage, ==, page);
49240 } else {
49241 - fscache_stat(&fscache_n_store_vmscan_gone);
49242 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
49243 }
49244
49245 wake_up_bit(&cookie->flags, 0);
49246 @@ -110,11 +110,11 @@ page_busy:
49247 * sleeping on memory allocation, so we may need to impose a timeout
49248 * too. */
49249 if (!(gfp & __GFP_WAIT)) {
49250 - fscache_stat(&fscache_n_store_vmscan_busy);
49251 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
49252 return false;
49253 }
49254
49255 - fscache_stat(&fscache_n_store_vmscan_wait);
49256 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
49257 __fscache_wait_on_page_write(cookie, page);
49258 gfp &= ~__GFP_WAIT;
49259 goto try_again;
49260 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
49261 FSCACHE_COOKIE_STORING_TAG);
49262 if (!radix_tree_tag_get(&cookie->stores, page->index,
49263 FSCACHE_COOKIE_PENDING_TAG)) {
49264 - fscache_stat(&fscache_n_store_radix_deletes);
49265 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
49266 xpage = radix_tree_delete(&cookie->stores, page->index);
49267 }
49268 spin_unlock(&cookie->stores_lock);
49269 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
49270
49271 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
49272
49273 - fscache_stat(&fscache_n_attr_changed_calls);
49274 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
49275
49276 if (fscache_object_is_active(object)) {
49277 fscache_stat(&fscache_n_cop_attr_changed);
49278 @@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49279
49280 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49281
49282 - fscache_stat(&fscache_n_attr_changed);
49283 + fscache_stat_unchecked(&fscache_n_attr_changed);
49284
49285 op = kzalloc(sizeof(*op), GFP_KERNEL);
49286 if (!op) {
49287 - fscache_stat(&fscache_n_attr_changed_nomem);
49288 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
49289 _leave(" = -ENOMEM");
49290 return -ENOMEM;
49291 }
49292 @@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49293 if (fscache_submit_exclusive_op(object, op) < 0)
49294 goto nobufs;
49295 spin_unlock(&cookie->lock);
49296 - fscache_stat(&fscache_n_attr_changed_ok);
49297 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
49298 fscache_put_operation(op);
49299 _leave(" = 0");
49300 return 0;
49301 @@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
49302 nobufs:
49303 spin_unlock(&cookie->lock);
49304 kfree(op);
49305 - fscache_stat(&fscache_n_attr_changed_nobufs);
49306 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
49307 _leave(" = %d", -ENOBUFS);
49308 return -ENOBUFS;
49309 }
49310 @@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
49311 /* allocate a retrieval operation and attempt to submit it */
49312 op = kzalloc(sizeof(*op), GFP_NOIO);
49313 if (!op) {
49314 - fscache_stat(&fscache_n_retrievals_nomem);
49315 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49316 return NULL;
49317 }
49318
49319 @@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
49320 return 0;
49321 }
49322
49323 - fscache_stat(&fscache_n_retrievals_wait);
49324 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
49325
49326 jif = jiffies;
49327 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
49328 fscache_wait_bit_interruptible,
49329 TASK_INTERRUPTIBLE) != 0) {
49330 - fscache_stat(&fscache_n_retrievals_intr);
49331 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49332 _leave(" = -ERESTARTSYS");
49333 return -ERESTARTSYS;
49334 }
49335 @@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
49336 */
49337 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49338 struct fscache_retrieval *op,
49339 - atomic_t *stat_op_waits,
49340 - atomic_t *stat_object_dead)
49341 + atomic_unchecked_t *stat_op_waits,
49342 + atomic_unchecked_t *stat_object_dead)
49343 {
49344 int ret;
49345
49346 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49347 goto check_if_dead;
49348
49349 _debug(">>> WT");
49350 - fscache_stat(stat_op_waits);
49351 + fscache_stat_unchecked(stat_op_waits);
49352 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
49353 fscache_wait_bit_interruptible,
49354 TASK_INTERRUPTIBLE) != 0) {
49355 @@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
49356
49357 check_if_dead:
49358 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
49359 - fscache_stat(stat_object_dead);
49360 + fscache_stat_unchecked(stat_object_dead);
49361 _leave(" = -ENOBUFS [cancelled]");
49362 return -ENOBUFS;
49363 }
49364 if (unlikely(fscache_object_is_dead(object))) {
49365 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
49366 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
49367 - fscache_stat(stat_object_dead);
49368 + fscache_stat_unchecked(stat_object_dead);
49369 return -ENOBUFS;
49370 }
49371 return 0;
49372 @@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49373
49374 _enter("%p,%p,,,", cookie, page);
49375
49376 - fscache_stat(&fscache_n_retrievals);
49377 + fscache_stat_unchecked(&fscache_n_retrievals);
49378
49379 if (hlist_empty(&cookie->backing_objects))
49380 goto nobufs;
49381 @@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49382 goto nobufs_unlock_dec;
49383 spin_unlock(&cookie->lock);
49384
49385 - fscache_stat(&fscache_n_retrieval_ops);
49386 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
49387
49388 /* pin the netfs read context in case we need to do the actual netfs
49389 * read because we've encountered a cache read failure */
49390 @@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
49391
49392 error:
49393 if (ret == -ENOMEM)
49394 - fscache_stat(&fscache_n_retrievals_nomem);
49395 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49396 else if (ret == -ERESTARTSYS)
49397 - fscache_stat(&fscache_n_retrievals_intr);
49398 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49399 else if (ret == -ENODATA)
49400 - fscache_stat(&fscache_n_retrievals_nodata);
49401 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49402 else if (ret < 0)
49403 - fscache_stat(&fscache_n_retrievals_nobufs);
49404 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49405 else
49406 - fscache_stat(&fscache_n_retrievals_ok);
49407 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
49408
49409 fscache_put_retrieval(op);
49410 _leave(" = %d", ret);
49411 @@ -467,7 +467,7 @@ nobufs_unlock:
49412 spin_unlock(&cookie->lock);
49413 kfree(op);
49414 nobufs:
49415 - fscache_stat(&fscache_n_retrievals_nobufs);
49416 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49417 _leave(" = -ENOBUFS");
49418 return -ENOBUFS;
49419 }
49420 @@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49421
49422 _enter("%p,,%d,,,", cookie, *nr_pages);
49423
49424 - fscache_stat(&fscache_n_retrievals);
49425 + fscache_stat_unchecked(&fscache_n_retrievals);
49426
49427 if (hlist_empty(&cookie->backing_objects))
49428 goto nobufs;
49429 @@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49430 goto nobufs_unlock_dec;
49431 spin_unlock(&cookie->lock);
49432
49433 - fscache_stat(&fscache_n_retrieval_ops);
49434 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
49435
49436 /* pin the netfs read context in case we need to do the actual netfs
49437 * read because we've encountered a cache read failure */
49438 @@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
49439
49440 error:
49441 if (ret == -ENOMEM)
49442 - fscache_stat(&fscache_n_retrievals_nomem);
49443 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
49444 else if (ret == -ERESTARTSYS)
49445 - fscache_stat(&fscache_n_retrievals_intr);
49446 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
49447 else if (ret == -ENODATA)
49448 - fscache_stat(&fscache_n_retrievals_nodata);
49449 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
49450 else if (ret < 0)
49451 - fscache_stat(&fscache_n_retrievals_nobufs);
49452 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49453 else
49454 - fscache_stat(&fscache_n_retrievals_ok);
49455 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
49456
49457 fscache_put_retrieval(op);
49458 _leave(" = %d", ret);
49459 @@ -591,7 +591,7 @@ nobufs_unlock:
49460 spin_unlock(&cookie->lock);
49461 kfree(op);
49462 nobufs:
49463 - fscache_stat(&fscache_n_retrievals_nobufs);
49464 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
49465 _leave(" = -ENOBUFS");
49466 return -ENOBUFS;
49467 }
49468 @@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49469
49470 _enter("%p,%p,,,", cookie, page);
49471
49472 - fscache_stat(&fscache_n_allocs);
49473 + fscache_stat_unchecked(&fscache_n_allocs);
49474
49475 if (hlist_empty(&cookie->backing_objects))
49476 goto nobufs;
49477 @@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49478 goto nobufs_unlock;
49479 spin_unlock(&cookie->lock);
49480
49481 - fscache_stat(&fscache_n_alloc_ops);
49482 + fscache_stat_unchecked(&fscache_n_alloc_ops);
49483
49484 ret = fscache_wait_for_retrieval_activation(
49485 object, op,
49486 @@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
49487
49488 error:
49489 if (ret == -ERESTARTSYS)
49490 - fscache_stat(&fscache_n_allocs_intr);
49491 + fscache_stat_unchecked(&fscache_n_allocs_intr);
49492 else if (ret < 0)
49493 - fscache_stat(&fscache_n_allocs_nobufs);
49494 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49495 else
49496 - fscache_stat(&fscache_n_allocs_ok);
49497 + fscache_stat_unchecked(&fscache_n_allocs_ok);
49498
49499 fscache_put_retrieval(op);
49500 _leave(" = %d", ret);
49501 @@ -677,7 +677,7 @@ nobufs_unlock:
49502 spin_unlock(&cookie->lock);
49503 kfree(op);
49504 nobufs:
49505 - fscache_stat(&fscache_n_allocs_nobufs);
49506 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
49507 _leave(" = -ENOBUFS");
49508 return -ENOBUFS;
49509 }
49510 @@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49511
49512 spin_lock(&cookie->stores_lock);
49513
49514 - fscache_stat(&fscache_n_store_calls);
49515 + fscache_stat_unchecked(&fscache_n_store_calls);
49516
49517 /* find a page to store */
49518 page = NULL;
49519 @@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49520 page = results[0];
49521 _debug("gang %d [%lx]", n, page->index);
49522 if (page->index > op->store_limit) {
49523 - fscache_stat(&fscache_n_store_pages_over_limit);
49524 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
49525 goto superseded;
49526 }
49527
49528 @@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
49529 spin_unlock(&cookie->stores_lock);
49530 spin_unlock(&object->lock);
49531
49532 - fscache_stat(&fscache_n_store_pages);
49533 + fscache_stat_unchecked(&fscache_n_store_pages);
49534 fscache_stat(&fscache_n_cop_write_page);
49535 ret = object->cache->ops->write_page(op, page);
49536 fscache_stat_d(&fscache_n_cop_write_page);
49537 @@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49538 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49539 ASSERT(PageFsCache(page));
49540
49541 - fscache_stat(&fscache_n_stores);
49542 + fscache_stat_unchecked(&fscache_n_stores);
49543
49544 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
49545 _leave(" = -ENOBUFS [invalidating]");
49546 @@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49547 spin_unlock(&cookie->stores_lock);
49548 spin_unlock(&object->lock);
49549
49550 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
49551 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
49552 op->store_limit = object->store_limit;
49553
49554 if (fscache_submit_op(object, &op->op) < 0)
49555 @@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49556
49557 spin_unlock(&cookie->lock);
49558 radix_tree_preload_end();
49559 - fscache_stat(&fscache_n_store_ops);
49560 - fscache_stat(&fscache_n_stores_ok);
49561 + fscache_stat_unchecked(&fscache_n_store_ops);
49562 + fscache_stat_unchecked(&fscache_n_stores_ok);
49563
49564 /* the work queue now carries its own ref on the object */
49565 fscache_put_operation(&op->op);
49566 @@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
49567 return 0;
49568
49569 already_queued:
49570 - fscache_stat(&fscache_n_stores_again);
49571 + fscache_stat_unchecked(&fscache_n_stores_again);
49572 already_pending:
49573 spin_unlock(&cookie->stores_lock);
49574 spin_unlock(&object->lock);
49575 spin_unlock(&cookie->lock);
49576 radix_tree_preload_end();
49577 kfree(op);
49578 - fscache_stat(&fscache_n_stores_ok);
49579 + fscache_stat_unchecked(&fscache_n_stores_ok);
49580 _leave(" = 0");
49581 return 0;
49582
49583 @@ -959,14 +959,14 @@ nobufs:
49584 spin_unlock(&cookie->lock);
49585 radix_tree_preload_end();
49586 kfree(op);
49587 - fscache_stat(&fscache_n_stores_nobufs);
49588 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
49589 _leave(" = -ENOBUFS");
49590 return -ENOBUFS;
49591
49592 nomem_free:
49593 kfree(op);
49594 nomem:
49595 - fscache_stat(&fscache_n_stores_oom);
49596 + fscache_stat_unchecked(&fscache_n_stores_oom);
49597 _leave(" = -ENOMEM");
49598 return -ENOMEM;
49599 }
49600 @@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
49601 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
49602 ASSERTCMP(page, !=, NULL);
49603
49604 - fscache_stat(&fscache_n_uncaches);
49605 + fscache_stat_unchecked(&fscache_n_uncaches);
49606
49607 /* cache withdrawal may beat us to it */
49608 if (!PageFsCache(page))
49609 @@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
49610 struct fscache_cookie *cookie = op->op.object->cookie;
49611
49612 #ifdef CONFIG_FSCACHE_STATS
49613 - atomic_inc(&fscache_n_marks);
49614 + atomic_inc_unchecked(&fscache_n_marks);
49615 #endif
49616
49617 _debug("- mark %p{%lx}", page, page->index);
49618 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
49619 index 8179e8b..5072cc7 100644
49620 --- a/fs/fscache/stats.c
49621 +++ b/fs/fscache/stats.c
49622 @@ -18,99 +18,99 @@
49623 /*
49624 * operation counters
49625 */
49626 -atomic_t fscache_n_op_pend;
49627 -atomic_t fscache_n_op_run;
49628 -atomic_t fscache_n_op_enqueue;
49629 -atomic_t fscache_n_op_requeue;
49630 -atomic_t fscache_n_op_deferred_release;
49631 -atomic_t fscache_n_op_release;
49632 -atomic_t fscache_n_op_gc;
49633 -atomic_t fscache_n_op_cancelled;
49634 -atomic_t fscache_n_op_rejected;
49635 +atomic_unchecked_t fscache_n_op_pend;
49636 +atomic_unchecked_t fscache_n_op_run;
49637 +atomic_unchecked_t fscache_n_op_enqueue;
49638 +atomic_unchecked_t fscache_n_op_requeue;
49639 +atomic_unchecked_t fscache_n_op_deferred_release;
49640 +atomic_unchecked_t fscache_n_op_release;
49641 +atomic_unchecked_t fscache_n_op_gc;
49642 +atomic_unchecked_t fscache_n_op_cancelled;
49643 +atomic_unchecked_t fscache_n_op_rejected;
49644
49645 -atomic_t fscache_n_attr_changed;
49646 -atomic_t fscache_n_attr_changed_ok;
49647 -atomic_t fscache_n_attr_changed_nobufs;
49648 -atomic_t fscache_n_attr_changed_nomem;
49649 -atomic_t fscache_n_attr_changed_calls;
49650 +atomic_unchecked_t fscache_n_attr_changed;
49651 +atomic_unchecked_t fscache_n_attr_changed_ok;
49652 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
49653 +atomic_unchecked_t fscache_n_attr_changed_nomem;
49654 +atomic_unchecked_t fscache_n_attr_changed_calls;
49655
49656 -atomic_t fscache_n_allocs;
49657 -atomic_t fscache_n_allocs_ok;
49658 -atomic_t fscache_n_allocs_wait;
49659 -atomic_t fscache_n_allocs_nobufs;
49660 -atomic_t fscache_n_allocs_intr;
49661 -atomic_t fscache_n_allocs_object_dead;
49662 -atomic_t fscache_n_alloc_ops;
49663 -atomic_t fscache_n_alloc_op_waits;
49664 +atomic_unchecked_t fscache_n_allocs;
49665 +atomic_unchecked_t fscache_n_allocs_ok;
49666 +atomic_unchecked_t fscache_n_allocs_wait;
49667 +atomic_unchecked_t fscache_n_allocs_nobufs;
49668 +atomic_unchecked_t fscache_n_allocs_intr;
49669 +atomic_unchecked_t fscache_n_allocs_object_dead;
49670 +atomic_unchecked_t fscache_n_alloc_ops;
49671 +atomic_unchecked_t fscache_n_alloc_op_waits;
49672
49673 -atomic_t fscache_n_retrievals;
49674 -atomic_t fscache_n_retrievals_ok;
49675 -atomic_t fscache_n_retrievals_wait;
49676 -atomic_t fscache_n_retrievals_nodata;
49677 -atomic_t fscache_n_retrievals_nobufs;
49678 -atomic_t fscache_n_retrievals_intr;
49679 -atomic_t fscache_n_retrievals_nomem;
49680 -atomic_t fscache_n_retrievals_object_dead;
49681 -atomic_t fscache_n_retrieval_ops;
49682 -atomic_t fscache_n_retrieval_op_waits;
49683 +atomic_unchecked_t fscache_n_retrievals;
49684 +atomic_unchecked_t fscache_n_retrievals_ok;
49685 +atomic_unchecked_t fscache_n_retrievals_wait;
49686 +atomic_unchecked_t fscache_n_retrievals_nodata;
49687 +atomic_unchecked_t fscache_n_retrievals_nobufs;
49688 +atomic_unchecked_t fscache_n_retrievals_intr;
49689 +atomic_unchecked_t fscache_n_retrievals_nomem;
49690 +atomic_unchecked_t fscache_n_retrievals_object_dead;
49691 +atomic_unchecked_t fscache_n_retrieval_ops;
49692 +atomic_unchecked_t fscache_n_retrieval_op_waits;
49693
49694 -atomic_t fscache_n_stores;
49695 -atomic_t fscache_n_stores_ok;
49696 -atomic_t fscache_n_stores_again;
49697 -atomic_t fscache_n_stores_nobufs;
49698 -atomic_t fscache_n_stores_oom;
49699 -atomic_t fscache_n_store_ops;
49700 -atomic_t fscache_n_store_calls;
49701 -atomic_t fscache_n_store_pages;
49702 -atomic_t fscache_n_store_radix_deletes;
49703 -atomic_t fscache_n_store_pages_over_limit;
49704 +atomic_unchecked_t fscache_n_stores;
49705 +atomic_unchecked_t fscache_n_stores_ok;
49706 +atomic_unchecked_t fscache_n_stores_again;
49707 +atomic_unchecked_t fscache_n_stores_nobufs;
49708 +atomic_unchecked_t fscache_n_stores_oom;
49709 +atomic_unchecked_t fscache_n_store_ops;
49710 +atomic_unchecked_t fscache_n_store_calls;
49711 +atomic_unchecked_t fscache_n_store_pages;
49712 +atomic_unchecked_t fscache_n_store_radix_deletes;
49713 +atomic_unchecked_t fscache_n_store_pages_over_limit;
49714
49715 -atomic_t fscache_n_store_vmscan_not_storing;
49716 -atomic_t fscache_n_store_vmscan_gone;
49717 -atomic_t fscache_n_store_vmscan_busy;
49718 -atomic_t fscache_n_store_vmscan_cancelled;
49719 -atomic_t fscache_n_store_vmscan_wait;
49720 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
49721 +atomic_unchecked_t fscache_n_store_vmscan_gone;
49722 +atomic_unchecked_t fscache_n_store_vmscan_busy;
49723 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
49724 +atomic_unchecked_t fscache_n_store_vmscan_wait;
49725
49726 -atomic_t fscache_n_marks;
49727 -atomic_t fscache_n_uncaches;
49728 +atomic_unchecked_t fscache_n_marks;
49729 +atomic_unchecked_t fscache_n_uncaches;
49730
49731 -atomic_t fscache_n_acquires;
49732 -atomic_t fscache_n_acquires_null;
49733 -atomic_t fscache_n_acquires_no_cache;
49734 -atomic_t fscache_n_acquires_ok;
49735 -atomic_t fscache_n_acquires_nobufs;
49736 -atomic_t fscache_n_acquires_oom;
49737 +atomic_unchecked_t fscache_n_acquires;
49738 +atomic_unchecked_t fscache_n_acquires_null;
49739 +atomic_unchecked_t fscache_n_acquires_no_cache;
49740 +atomic_unchecked_t fscache_n_acquires_ok;
49741 +atomic_unchecked_t fscache_n_acquires_nobufs;
49742 +atomic_unchecked_t fscache_n_acquires_oom;
49743
49744 -atomic_t fscache_n_invalidates;
49745 -atomic_t fscache_n_invalidates_run;
49746 +atomic_unchecked_t fscache_n_invalidates;
49747 +atomic_unchecked_t fscache_n_invalidates_run;
49748
49749 -atomic_t fscache_n_updates;
49750 -atomic_t fscache_n_updates_null;
49751 -atomic_t fscache_n_updates_run;
49752 +atomic_unchecked_t fscache_n_updates;
49753 +atomic_unchecked_t fscache_n_updates_null;
49754 +atomic_unchecked_t fscache_n_updates_run;
49755
49756 -atomic_t fscache_n_relinquishes;
49757 -atomic_t fscache_n_relinquishes_null;
49758 -atomic_t fscache_n_relinquishes_waitcrt;
49759 -atomic_t fscache_n_relinquishes_retire;
49760 +atomic_unchecked_t fscache_n_relinquishes;
49761 +atomic_unchecked_t fscache_n_relinquishes_null;
49762 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
49763 +atomic_unchecked_t fscache_n_relinquishes_retire;
49764
49765 -atomic_t fscache_n_cookie_index;
49766 -atomic_t fscache_n_cookie_data;
49767 -atomic_t fscache_n_cookie_special;
49768 +atomic_unchecked_t fscache_n_cookie_index;
49769 +atomic_unchecked_t fscache_n_cookie_data;
49770 +atomic_unchecked_t fscache_n_cookie_special;
49771
49772 -atomic_t fscache_n_object_alloc;
49773 -atomic_t fscache_n_object_no_alloc;
49774 -atomic_t fscache_n_object_lookups;
49775 -atomic_t fscache_n_object_lookups_negative;
49776 -atomic_t fscache_n_object_lookups_positive;
49777 -atomic_t fscache_n_object_lookups_timed_out;
49778 -atomic_t fscache_n_object_created;
49779 -atomic_t fscache_n_object_avail;
49780 -atomic_t fscache_n_object_dead;
49781 +atomic_unchecked_t fscache_n_object_alloc;
49782 +atomic_unchecked_t fscache_n_object_no_alloc;
49783 +atomic_unchecked_t fscache_n_object_lookups;
49784 +atomic_unchecked_t fscache_n_object_lookups_negative;
49785 +atomic_unchecked_t fscache_n_object_lookups_positive;
49786 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
49787 +atomic_unchecked_t fscache_n_object_created;
49788 +atomic_unchecked_t fscache_n_object_avail;
49789 +atomic_unchecked_t fscache_n_object_dead;
49790
49791 -atomic_t fscache_n_checkaux_none;
49792 -atomic_t fscache_n_checkaux_okay;
49793 -atomic_t fscache_n_checkaux_update;
49794 -atomic_t fscache_n_checkaux_obsolete;
49795 +atomic_unchecked_t fscache_n_checkaux_none;
49796 +atomic_unchecked_t fscache_n_checkaux_okay;
49797 +atomic_unchecked_t fscache_n_checkaux_update;
49798 +atomic_unchecked_t fscache_n_checkaux_obsolete;
49799
49800 atomic_t fscache_n_cop_alloc_object;
49801 atomic_t fscache_n_cop_lookup_object;
49802 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
49803 seq_puts(m, "FS-Cache statistics\n");
49804
49805 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
49806 - atomic_read(&fscache_n_cookie_index),
49807 - atomic_read(&fscache_n_cookie_data),
49808 - atomic_read(&fscache_n_cookie_special));
49809 + atomic_read_unchecked(&fscache_n_cookie_index),
49810 + atomic_read_unchecked(&fscache_n_cookie_data),
49811 + atomic_read_unchecked(&fscache_n_cookie_special));
49812
49813 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
49814 - atomic_read(&fscache_n_object_alloc),
49815 - atomic_read(&fscache_n_object_no_alloc),
49816 - atomic_read(&fscache_n_object_avail),
49817 - atomic_read(&fscache_n_object_dead));
49818 + atomic_read_unchecked(&fscache_n_object_alloc),
49819 + atomic_read_unchecked(&fscache_n_object_no_alloc),
49820 + atomic_read_unchecked(&fscache_n_object_avail),
49821 + atomic_read_unchecked(&fscache_n_object_dead));
49822 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
49823 - atomic_read(&fscache_n_checkaux_none),
49824 - atomic_read(&fscache_n_checkaux_okay),
49825 - atomic_read(&fscache_n_checkaux_update),
49826 - atomic_read(&fscache_n_checkaux_obsolete));
49827 + atomic_read_unchecked(&fscache_n_checkaux_none),
49828 + atomic_read_unchecked(&fscache_n_checkaux_okay),
49829 + atomic_read_unchecked(&fscache_n_checkaux_update),
49830 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
49831
49832 seq_printf(m, "Pages : mrk=%u unc=%u\n",
49833 - atomic_read(&fscache_n_marks),
49834 - atomic_read(&fscache_n_uncaches));
49835 + atomic_read_unchecked(&fscache_n_marks),
49836 + atomic_read_unchecked(&fscache_n_uncaches));
49837
49838 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
49839 " oom=%u\n",
49840 - atomic_read(&fscache_n_acquires),
49841 - atomic_read(&fscache_n_acquires_null),
49842 - atomic_read(&fscache_n_acquires_no_cache),
49843 - atomic_read(&fscache_n_acquires_ok),
49844 - atomic_read(&fscache_n_acquires_nobufs),
49845 - atomic_read(&fscache_n_acquires_oom));
49846 + atomic_read_unchecked(&fscache_n_acquires),
49847 + atomic_read_unchecked(&fscache_n_acquires_null),
49848 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
49849 + atomic_read_unchecked(&fscache_n_acquires_ok),
49850 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
49851 + atomic_read_unchecked(&fscache_n_acquires_oom));
49852
49853 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
49854 - atomic_read(&fscache_n_object_lookups),
49855 - atomic_read(&fscache_n_object_lookups_negative),
49856 - atomic_read(&fscache_n_object_lookups_positive),
49857 - atomic_read(&fscache_n_object_created),
49858 - atomic_read(&fscache_n_object_lookups_timed_out));
49859 + atomic_read_unchecked(&fscache_n_object_lookups),
49860 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
49861 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
49862 + atomic_read_unchecked(&fscache_n_object_created),
49863 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
49864
49865 seq_printf(m, "Invals : n=%u run=%u\n",
49866 - atomic_read(&fscache_n_invalidates),
49867 - atomic_read(&fscache_n_invalidates_run));
49868 + atomic_read_unchecked(&fscache_n_invalidates),
49869 + atomic_read_unchecked(&fscache_n_invalidates_run));
49870
49871 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
49872 - atomic_read(&fscache_n_updates),
49873 - atomic_read(&fscache_n_updates_null),
49874 - atomic_read(&fscache_n_updates_run));
49875 + atomic_read_unchecked(&fscache_n_updates),
49876 + atomic_read_unchecked(&fscache_n_updates_null),
49877 + atomic_read_unchecked(&fscache_n_updates_run));
49878
49879 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
49880 - atomic_read(&fscache_n_relinquishes),
49881 - atomic_read(&fscache_n_relinquishes_null),
49882 - atomic_read(&fscache_n_relinquishes_waitcrt),
49883 - atomic_read(&fscache_n_relinquishes_retire));
49884 + atomic_read_unchecked(&fscache_n_relinquishes),
49885 + atomic_read_unchecked(&fscache_n_relinquishes_null),
49886 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
49887 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
49888
49889 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
49890 - atomic_read(&fscache_n_attr_changed),
49891 - atomic_read(&fscache_n_attr_changed_ok),
49892 - atomic_read(&fscache_n_attr_changed_nobufs),
49893 - atomic_read(&fscache_n_attr_changed_nomem),
49894 - atomic_read(&fscache_n_attr_changed_calls));
49895 + atomic_read_unchecked(&fscache_n_attr_changed),
49896 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
49897 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
49898 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
49899 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
49900
49901 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
49902 - atomic_read(&fscache_n_allocs),
49903 - atomic_read(&fscache_n_allocs_ok),
49904 - atomic_read(&fscache_n_allocs_wait),
49905 - atomic_read(&fscache_n_allocs_nobufs),
49906 - atomic_read(&fscache_n_allocs_intr));
49907 + atomic_read_unchecked(&fscache_n_allocs),
49908 + atomic_read_unchecked(&fscache_n_allocs_ok),
49909 + atomic_read_unchecked(&fscache_n_allocs_wait),
49910 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
49911 + atomic_read_unchecked(&fscache_n_allocs_intr));
49912 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
49913 - atomic_read(&fscache_n_alloc_ops),
49914 - atomic_read(&fscache_n_alloc_op_waits),
49915 - atomic_read(&fscache_n_allocs_object_dead));
49916 + atomic_read_unchecked(&fscache_n_alloc_ops),
49917 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
49918 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
49919
49920 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
49921 " int=%u oom=%u\n",
49922 - atomic_read(&fscache_n_retrievals),
49923 - atomic_read(&fscache_n_retrievals_ok),
49924 - atomic_read(&fscache_n_retrievals_wait),
49925 - atomic_read(&fscache_n_retrievals_nodata),
49926 - atomic_read(&fscache_n_retrievals_nobufs),
49927 - atomic_read(&fscache_n_retrievals_intr),
49928 - atomic_read(&fscache_n_retrievals_nomem));
49929 + atomic_read_unchecked(&fscache_n_retrievals),
49930 + atomic_read_unchecked(&fscache_n_retrievals_ok),
49931 + atomic_read_unchecked(&fscache_n_retrievals_wait),
49932 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
49933 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
49934 + atomic_read_unchecked(&fscache_n_retrievals_intr),
49935 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
49936 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
49937 - atomic_read(&fscache_n_retrieval_ops),
49938 - atomic_read(&fscache_n_retrieval_op_waits),
49939 - atomic_read(&fscache_n_retrievals_object_dead));
49940 + atomic_read_unchecked(&fscache_n_retrieval_ops),
49941 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
49942 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
49943
49944 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
49945 - atomic_read(&fscache_n_stores),
49946 - atomic_read(&fscache_n_stores_ok),
49947 - atomic_read(&fscache_n_stores_again),
49948 - atomic_read(&fscache_n_stores_nobufs),
49949 - atomic_read(&fscache_n_stores_oom));
49950 + atomic_read_unchecked(&fscache_n_stores),
49951 + atomic_read_unchecked(&fscache_n_stores_ok),
49952 + atomic_read_unchecked(&fscache_n_stores_again),
49953 + atomic_read_unchecked(&fscache_n_stores_nobufs),
49954 + atomic_read_unchecked(&fscache_n_stores_oom));
49955 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
49956 - atomic_read(&fscache_n_store_ops),
49957 - atomic_read(&fscache_n_store_calls),
49958 - atomic_read(&fscache_n_store_pages),
49959 - atomic_read(&fscache_n_store_radix_deletes),
49960 - atomic_read(&fscache_n_store_pages_over_limit));
49961 + atomic_read_unchecked(&fscache_n_store_ops),
49962 + atomic_read_unchecked(&fscache_n_store_calls),
49963 + atomic_read_unchecked(&fscache_n_store_pages),
49964 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
49965 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
49966
49967 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
49968 - atomic_read(&fscache_n_store_vmscan_not_storing),
49969 - atomic_read(&fscache_n_store_vmscan_gone),
49970 - atomic_read(&fscache_n_store_vmscan_busy),
49971 - atomic_read(&fscache_n_store_vmscan_cancelled),
49972 - atomic_read(&fscache_n_store_vmscan_wait));
49973 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
49974 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
49975 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
49976 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
49977 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
49978
49979 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
49980 - atomic_read(&fscache_n_op_pend),
49981 - atomic_read(&fscache_n_op_run),
49982 - atomic_read(&fscache_n_op_enqueue),
49983 - atomic_read(&fscache_n_op_cancelled),
49984 - atomic_read(&fscache_n_op_rejected));
49985 + atomic_read_unchecked(&fscache_n_op_pend),
49986 + atomic_read_unchecked(&fscache_n_op_run),
49987 + atomic_read_unchecked(&fscache_n_op_enqueue),
49988 + atomic_read_unchecked(&fscache_n_op_cancelled),
49989 + atomic_read_unchecked(&fscache_n_op_rejected));
49990 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
49991 - atomic_read(&fscache_n_op_deferred_release),
49992 - atomic_read(&fscache_n_op_release),
49993 - atomic_read(&fscache_n_op_gc));
49994 + atomic_read_unchecked(&fscache_n_op_deferred_release),
49995 + atomic_read_unchecked(&fscache_n_op_release),
49996 + atomic_read_unchecked(&fscache_n_op_gc));
49997
49998 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
49999 atomic_read(&fscache_n_cop_alloc_object),
50000 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
50001 index e397b67..b0d8709 100644
50002 --- a/fs/fuse/cuse.c
50003 +++ b/fs/fuse/cuse.c
50004 @@ -593,10 +593,12 @@ static int __init cuse_init(void)
50005 INIT_LIST_HEAD(&cuse_conntbl[i]);
50006
50007 /* inherit and extend fuse_dev_operations */
50008 - cuse_channel_fops = fuse_dev_operations;
50009 - cuse_channel_fops.owner = THIS_MODULE;
50010 - cuse_channel_fops.open = cuse_channel_open;
50011 - cuse_channel_fops.release = cuse_channel_release;
50012 + pax_open_kernel();
50013 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
50014 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
50015 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
50016 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
50017 + pax_close_kernel();
50018
50019 cuse_class = class_create(THIS_MODULE, "cuse");
50020 if (IS_ERR(cuse_class))
50021 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
50022 index e83351a..41e3c9c 100644
50023 --- a/fs/fuse/dev.c
50024 +++ b/fs/fuse/dev.c
50025 @@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
50026 ret = 0;
50027 pipe_lock(pipe);
50028
50029 - if (!pipe->readers) {
50030 + if (!atomic_read(&pipe->readers)) {
50031 send_sig(SIGPIPE, current, 0);
50032 if (!ret)
50033 ret = -EPIPE;
50034 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
50035 index b7c09f9..3eff736 100644
50036 --- a/fs/fuse/dir.c
50037 +++ b/fs/fuse/dir.c
50038 @@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
50039 return link;
50040 }
50041
50042 -static void free_link(char *link)
50043 +static void free_link(const char *link)
50044 {
50045 if (!IS_ERR(link))
50046 free_page((unsigned long) link);
50047 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
50048 index 2b6f569..fcb4d1f 100644
50049 --- a/fs/gfs2/inode.c
50050 +++ b/fs/gfs2/inode.c
50051 @@ -1499,7 +1499,7 @@ out:
50052
50053 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
50054 {
50055 - char *s = nd_get_link(nd);
50056 + const char *s = nd_get_link(nd);
50057 if (!IS_ERR(s))
50058 kfree(s);
50059 }
50060 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
50061 index 78bde32..767e906 100644
50062 --- a/fs/hugetlbfs/inode.c
50063 +++ b/fs/hugetlbfs/inode.c
50064 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50065 struct mm_struct *mm = current->mm;
50066 struct vm_area_struct *vma;
50067 struct hstate *h = hstate_file(file);
50068 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
50069 struct vm_unmapped_area_info info;
50070
50071 if (len & ~huge_page_mask(h))
50072 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
50073 return addr;
50074 }
50075
50076 +#ifdef CONFIG_PAX_RANDMMAP
50077 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
50078 +#endif
50079 +
50080 if (addr) {
50081 addr = ALIGN(addr, huge_page_size(h));
50082 vma = find_vma(mm, addr);
50083 - if (TASK_SIZE - len >= addr &&
50084 - (!vma || addr + len <= vma->vm_start))
50085 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
50086 return addr;
50087 }
50088
50089 info.flags = 0;
50090 info.length = len;
50091 info.low_limit = TASK_UNMAPPED_BASE;
50092 +
50093 +#ifdef CONFIG_PAX_RANDMMAP
50094 + if (mm->pax_flags & MF_PAX_RANDMMAP)
50095 + info.low_limit += mm->delta_mmap;
50096 +#endif
50097 +
50098 info.high_limit = TASK_SIZE;
50099 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
50100 info.align_offset = 0;
50101 @@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
50102 .kill_sb = kill_litter_super,
50103 };
50104
50105 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50106 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
50107
50108 static int can_do_hugetlb_shm(void)
50109 {
50110 diff --git a/fs/inode.c b/fs/inode.c
50111 index 14084b7..29af1d9 100644
50112 --- a/fs/inode.c
50113 +++ b/fs/inode.c
50114 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
50115
50116 #ifdef CONFIG_SMP
50117 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
50118 - static atomic_t shared_last_ino;
50119 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
50120 + static atomic_unchecked_t shared_last_ino;
50121 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
50122
50123 res = next - LAST_INO_BATCH;
50124 }
50125 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
50126 index 4a6cf28..d3a29d3 100644
50127 --- a/fs/jffs2/erase.c
50128 +++ b/fs/jffs2/erase.c
50129 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
50130 struct jffs2_unknown_node marker = {
50131 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
50132 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50133 - .totlen = cpu_to_je32(c->cleanmarker_size)
50134 + .totlen = cpu_to_je32(c->cleanmarker_size),
50135 + .hdr_crc = cpu_to_je32(0)
50136 };
50137
50138 jffs2_prealloc_raw_node_refs(c, jeb, 1);
50139 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
50140 index a6597d6..41b30ec 100644
50141 --- a/fs/jffs2/wbuf.c
50142 +++ b/fs/jffs2/wbuf.c
50143 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
50144 {
50145 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
50146 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
50147 - .totlen = constant_cpu_to_je32(8)
50148 + .totlen = constant_cpu_to_je32(8),
50149 + .hdr_crc = constant_cpu_to_je32(0)
50150 };
50151
50152 /*
50153 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
50154 index 1a543be..d803c40 100644
50155 --- a/fs/jfs/super.c
50156 +++ b/fs/jfs/super.c
50157 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
50158
50159 jfs_inode_cachep =
50160 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
50161 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
50162 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
50163 init_once);
50164 if (jfs_inode_cachep == NULL)
50165 return -ENOMEM;
50166 diff --git a/fs/libfs.c b/fs/libfs.c
50167 index 916da8c..1588998 100644
50168 --- a/fs/libfs.c
50169 +++ b/fs/libfs.c
50170 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50171
50172 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
50173 struct dentry *next;
50174 + char d_name[sizeof(next->d_iname)];
50175 + const unsigned char *name;
50176 +
50177 next = list_entry(p, struct dentry, d_u.d_child);
50178 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
50179 if (!simple_positive(next)) {
50180 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
50181
50182 spin_unlock(&next->d_lock);
50183 spin_unlock(&dentry->d_lock);
50184 - if (filldir(dirent, next->d_name.name,
50185 + name = next->d_name.name;
50186 + if (name == next->d_iname) {
50187 + memcpy(d_name, name, next->d_name.len);
50188 + name = d_name;
50189 + }
50190 + if (filldir(dirent, name,
50191 next->d_name.len, filp->f_pos,
50192 next->d_inode->i_ino,
50193 dt_type(next->d_inode)) < 0)
50194 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
50195 index 54f9e6c..9ed908c 100644
50196 --- a/fs/lockd/clntproc.c
50197 +++ b/fs/lockd/clntproc.c
50198 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
50199 /*
50200 * Cookie counter for NLM requests
50201 */
50202 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
50203 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
50204
50205 void nlmclnt_next_cookie(struct nlm_cookie *c)
50206 {
50207 - u32 cookie = atomic_inc_return(&nlm_cookie);
50208 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
50209
50210 memcpy(c->data, &cookie, 4);
50211 c->len=4;
50212 diff --git a/fs/locks.c b/fs/locks.c
50213 index a94e331..060bce3 100644
50214 --- a/fs/locks.c
50215 +++ b/fs/locks.c
50216 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
50217 return;
50218
50219 if (filp->f_op && filp->f_op->flock) {
50220 - struct file_lock fl = {
50221 + struct file_lock flock = {
50222 .fl_pid = current->tgid,
50223 .fl_file = filp,
50224 .fl_flags = FL_FLOCK,
50225 .fl_type = F_UNLCK,
50226 .fl_end = OFFSET_MAX,
50227 };
50228 - filp->f_op->flock(filp, F_SETLKW, &fl);
50229 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
50230 - fl.fl_ops->fl_release_private(&fl);
50231 + filp->f_op->flock(filp, F_SETLKW, &flock);
50232 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
50233 + flock.fl_ops->fl_release_private(&flock);
50234 }
50235
50236 lock_flocks();
50237 diff --git a/fs/namei.c b/fs/namei.c
50238 index 43a97ee..117e7e4 100644
50239 --- a/fs/namei.c
50240 +++ b/fs/namei.c
50241 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
50242 if (ret != -EACCES)
50243 return ret;
50244
50245 +#ifdef CONFIG_GRKERNSEC
50246 + /* we'll block if we have to log due to a denied capability use */
50247 + if (mask & MAY_NOT_BLOCK)
50248 + return -ECHILD;
50249 +#endif
50250 +
50251 if (S_ISDIR(inode->i_mode)) {
50252 /* DACs are overridable for directories */
50253 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
50254 - return 0;
50255 if (!(mask & MAY_WRITE))
50256 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50257 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50258 + inode_capable(inode, CAP_DAC_READ_SEARCH))
50259 return 0;
50260 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
50261 + return 0;
50262 return -EACCES;
50263 }
50264 /*
50265 + * Searching includes executable on directories, else just read.
50266 + */
50267 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50268 + if (mask == MAY_READ)
50269 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
50270 + inode_capable(inode, CAP_DAC_READ_SEARCH))
50271 + return 0;
50272 +
50273 + /*
50274 * Read/write DACs are always overridable.
50275 * Executable DACs are overridable when there is
50276 * at least one exec bit set.
50277 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
50278 if (inode_capable(inode, CAP_DAC_OVERRIDE))
50279 return 0;
50280
50281 - /*
50282 - * Searching includes executable on directories, else just read.
50283 - */
50284 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
50285 - if (mask == MAY_READ)
50286 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
50287 - return 0;
50288 -
50289 return -EACCES;
50290 }
50291
50292 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50293 {
50294 struct dentry *dentry = link->dentry;
50295 int error;
50296 - char *s;
50297 + const char *s;
50298
50299 BUG_ON(nd->flags & LOOKUP_RCU);
50300
50301 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
50302 if (error)
50303 goto out_put_nd_path;
50304
50305 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
50306 + dentry->d_inode, dentry, nd->path.mnt)) {
50307 + error = -EACCES;
50308 + goto out_put_nd_path;
50309 + }
50310 +
50311 nd->last_type = LAST_BIND;
50312 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
50313 error = PTR_ERR(*p);
50314 @@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
50315 break;
50316 res = walk_component(nd, path, &nd->last,
50317 nd->last_type, LOOKUP_FOLLOW);
50318 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
50319 + res = -EACCES;
50320 put_link(nd, &link, cookie);
50321 } while (res > 0);
50322
50323 @@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
50324 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
50325 {
50326 unsigned long a, b, adata, bdata, mask, hash, len;
50327 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50328 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
50329
50330 hash = a = 0;
50331 len = -sizeof(unsigned long);
50332 @@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
50333 if (err)
50334 break;
50335 err = lookup_last(nd, &path);
50336 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
50337 + err = -EACCES;
50338 put_link(nd, &link, cookie);
50339 }
50340 }
50341 @@ -1986,6 +2004,21 @@ static int path_lookupat(int dfd, const char *name,
50342 if (!err)
50343 err = complete_walk(nd);
50344
50345 + if (!(nd->flags & LOOKUP_PARENT)) {
50346 +#ifdef CONFIG_GRKERNSEC
50347 + if (flags & LOOKUP_RCU) {
50348 + if (!err)
50349 + path_put(&nd->path);
50350 + err = -ECHILD;
50351 + } else
50352 +#endif
50353 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50354 + if (!err)
50355 + path_put(&nd->path);
50356 + err = -ENOENT;
50357 + }
50358 + }
50359 +
50360 if (!err && nd->flags & LOOKUP_DIRECTORY) {
50361 if (!nd->inode->i_op->lookup) {
50362 path_put(&nd->path);
50363 @@ -2013,8 +2046,17 @@ static int filename_lookup(int dfd, struct filename *name,
50364 retval = path_lookupat(dfd, name->name,
50365 flags | LOOKUP_REVAL, nd);
50366
50367 - if (likely(!retval))
50368 + if (likely(!retval)) {
50369 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
50370 +#ifdef CONFIG_GRKERNSEC
50371 + if (flags & LOOKUP_RCU)
50372 + return -ECHILD;
50373 +#endif
50374 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
50375 + return -ENOENT;
50376 + }
50377 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
50378 + }
50379 return retval;
50380 }
50381
50382 @@ -2392,6 +2434,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
50383 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
50384 return -EPERM;
50385
50386 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
50387 + return -EPERM;
50388 + if (gr_handle_rawio(inode))
50389 + return -EPERM;
50390 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
50391 + return -EACCES;
50392 +
50393 return 0;
50394 }
50395
50396 @@ -2613,7 +2662,7 @@ looked_up:
50397 * cleared otherwise prior to returning.
50398 */
50399 static int lookup_open(struct nameidata *nd, struct path *path,
50400 - struct file *file,
50401 + struct path *link, struct file *file,
50402 const struct open_flags *op,
50403 bool got_write, int *opened)
50404 {
50405 @@ -2648,6 +2697,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50406 /* Negative dentry, just create the file */
50407 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
50408 umode_t mode = op->mode;
50409 +
50410 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
50411 + error = -EACCES;
50412 + goto out_dput;
50413 + }
50414 +
50415 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
50416 + error = -EACCES;
50417 + goto out_dput;
50418 + }
50419 +
50420 if (!IS_POSIXACL(dir->d_inode))
50421 mode &= ~current_umask();
50422 /*
50423 @@ -2669,6 +2729,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
50424 nd->flags & LOOKUP_EXCL);
50425 if (error)
50426 goto out_dput;
50427 + else
50428 + gr_handle_create(dentry, nd->path.mnt);
50429 }
50430 out_no_open:
50431 path->dentry = dentry;
50432 @@ -2683,7 +2745,7 @@ out_dput:
50433 /*
50434 * Handle the last step of open()
50435 */
50436 -static int do_last(struct nameidata *nd, struct path *path,
50437 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
50438 struct file *file, const struct open_flags *op,
50439 int *opened, struct filename *name)
50440 {
50441 @@ -2712,16 +2774,44 @@ static int do_last(struct nameidata *nd, struct path *path,
50442 error = complete_walk(nd);
50443 if (error)
50444 return error;
50445 +#ifdef CONFIG_GRKERNSEC
50446 + if (nd->flags & LOOKUP_RCU) {
50447 + error = -ECHILD;
50448 + goto out;
50449 + }
50450 +#endif
50451 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50452 + error = -ENOENT;
50453 + goto out;
50454 + }
50455 audit_inode(name, nd->path.dentry, 0);
50456 if (open_flag & O_CREAT) {
50457 error = -EISDIR;
50458 goto out;
50459 }
50460 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
50461 + error = -EACCES;
50462 + goto out;
50463 + }
50464 goto finish_open;
50465 case LAST_BIND:
50466 error = complete_walk(nd);
50467 if (error)
50468 return error;
50469 +#ifdef CONFIG_GRKERNSEC
50470 + if (nd->flags & LOOKUP_RCU) {
50471 + error = -ECHILD;
50472 + goto out;
50473 + }
50474 +#endif
50475 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
50476 + error = -ENOENT;
50477 + goto out;
50478 + }
50479 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
50480 + error = -EACCES;
50481 + goto out;
50482 + }
50483 audit_inode(name, dir, 0);
50484 goto finish_open;
50485 }
50486 @@ -2770,7 +2860,7 @@ retry_lookup:
50487 */
50488 }
50489 mutex_lock(&dir->d_inode->i_mutex);
50490 - error = lookup_open(nd, path, file, op, got_write, opened);
50491 + error = lookup_open(nd, path, link, file, op, got_write, opened);
50492 mutex_unlock(&dir->d_inode->i_mutex);
50493
50494 if (error <= 0) {
50495 @@ -2794,11 +2884,28 @@ retry_lookup:
50496 goto finish_open_created;
50497 }
50498
50499 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
50500 + error = -ENOENT;
50501 + goto exit_dput;
50502 + }
50503 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
50504 + error = -EACCES;
50505 + goto exit_dput;
50506 + }
50507 +
50508 /*
50509 * create/update audit record if it already exists.
50510 */
50511 - if (path->dentry->d_inode)
50512 + if (path->dentry->d_inode) {
50513 + /* only check if O_CREAT is specified, all other checks need to go
50514 + into may_open */
50515 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
50516 + error = -EACCES;
50517 + goto exit_dput;
50518 + }
50519 +
50520 audit_inode(name, path->dentry, 0);
50521 + }
50522
50523 /*
50524 * If atomic_open() acquired write access it is dropped now due to
50525 @@ -2839,6 +2946,11 @@ finish_lookup:
50526 }
50527 }
50528 BUG_ON(inode != path->dentry->d_inode);
50529 + /* if we're resolving a symlink to another symlink */
50530 + if (link && gr_handle_symlink_owner(link, inode)) {
50531 + error = -EACCES;
50532 + goto out;
50533 + }
50534 return 1;
50535 }
50536
50537 @@ -2848,7 +2960,6 @@ finish_lookup:
50538 save_parent.dentry = nd->path.dentry;
50539 save_parent.mnt = mntget(path->mnt);
50540 nd->path.dentry = path->dentry;
50541 -
50542 }
50543 nd->inode = inode;
50544 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
50545 @@ -2857,6 +2968,22 @@ finish_lookup:
50546 path_put(&save_parent);
50547 return error;
50548 }
50549 +
50550 +#ifdef CONFIG_GRKERNSEC
50551 + if (nd->flags & LOOKUP_RCU) {
50552 + error = -ECHILD;
50553 + goto out;
50554 + }
50555 +#endif
50556 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
50557 + error = -ENOENT;
50558 + goto out;
50559 + }
50560 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
50561 + error = -EACCES;
50562 + goto out;
50563 + }
50564 +
50565 error = -EISDIR;
50566 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
50567 goto out;
50568 @@ -2955,7 +3082,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50569 if (unlikely(error))
50570 goto out;
50571
50572 - error = do_last(nd, &path, file, op, &opened, pathname);
50573 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
50574 while (unlikely(error > 0)) { /* trailing symlink */
50575 struct path link = path;
50576 void *cookie;
50577 @@ -2973,7 +3100,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
50578 error = follow_link(&link, nd, &cookie);
50579 if (unlikely(error))
50580 break;
50581 - error = do_last(nd, &path, file, op, &opened, pathname);
50582 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
50583 put_link(nd, &link, cookie);
50584 }
50585 out:
50586 @@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
50587 goto unlock;
50588
50589 error = -EEXIST;
50590 - if (dentry->d_inode)
50591 + if (dentry->d_inode) {
50592 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
50593 + error = -ENOENT;
50594 + }
50595 goto fail;
50596 + }
50597 /*
50598 * Special case - lookup gave negative, but... we had foo/bar/
50599 * From the vfs_mknod() POV we just have a negative dentry -
50600 @@ -3126,6 +3257,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
50601 }
50602 EXPORT_SYMBOL(user_path_create);
50603
50604 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
50605 +{
50606 + struct filename *tmp = getname(pathname);
50607 + struct dentry *res;
50608 + if (IS_ERR(tmp))
50609 + return ERR_CAST(tmp);
50610 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
50611 + if (IS_ERR(res))
50612 + putname(tmp);
50613 + else
50614 + *to = tmp;
50615 + return res;
50616 +}
50617 +
50618 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
50619 {
50620 int error = may_create(dir, dentry);
50621 @@ -3188,6 +3333,17 @@ retry:
50622
50623 if (!IS_POSIXACL(path.dentry->d_inode))
50624 mode &= ~current_umask();
50625 +
50626 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
50627 + error = -EPERM;
50628 + goto out;
50629 + }
50630 +
50631 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
50632 + error = -EACCES;
50633 + goto out;
50634 + }
50635 +
50636 error = security_path_mknod(&path, dentry, mode, dev);
50637 if (error)
50638 goto out;
50639 @@ -3204,6 +3360,8 @@ retry:
50640 break;
50641 }
50642 out:
50643 + if (!error)
50644 + gr_handle_create(dentry, path.mnt);
50645 done_path_create(&path, dentry);
50646 if (retry_estale(error, lookup_flags)) {
50647 lookup_flags |= LOOKUP_REVAL;
50648 @@ -3256,9 +3414,16 @@ retry:
50649
50650 if (!IS_POSIXACL(path.dentry->d_inode))
50651 mode &= ~current_umask();
50652 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
50653 + error = -EACCES;
50654 + goto out;
50655 + }
50656 error = security_path_mkdir(&path, dentry, mode);
50657 if (!error)
50658 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
50659 + if (!error)
50660 + gr_handle_create(dentry, path.mnt);
50661 +out:
50662 done_path_create(&path, dentry);
50663 if (retry_estale(error, lookup_flags)) {
50664 lookup_flags |= LOOKUP_REVAL;
50665 @@ -3339,6 +3504,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
50666 struct filename *name;
50667 struct dentry *dentry;
50668 struct nameidata nd;
50669 + ino_t saved_ino = 0;
50670 + dev_t saved_dev = 0;
50671 unsigned int lookup_flags = 0;
50672 retry:
50673 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50674 @@ -3371,10 +3538,21 @@ retry:
50675 error = -ENOENT;
50676 goto exit3;
50677 }
50678 +
50679 + saved_ino = dentry->d_inode->i_ino;
50680 + saved_dev = gr_get_dev_from_dentry(dentry);
50681 +
50682 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
50683 + error = -EACCES;
50684 + goto exit3;
50685 + }
50686 +
50687 error = security_path_rmdir(&nd.path, dentry);
50688 if (error)
50689 goto exit3;
50690 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
50691 + if (!error && (saved_dev || saved_ino))
50692 + gr_handle_delete(saved_ino, saved_dev);
50693 exit3:
50694 dput(dentry);
50695 exit2:
50696 @@ -3440,6 +3618,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
50697 struct dentry *dentry;
50698 struct nameidata nd;
50699 struct inode *inode = NULL;
50700 + ino_t saved_ino = 0;
50701 + dev_t saved_dev = 0;
50702 unsigned int lookup_flags = 0;
50703 retry:
50704 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
50705 @@ -3466,10 +3646,22 @@ retry:
50706 if (!inode)
50707 goto slashes;
50708 ihold(inode);
50709 +
50710 + if (inode->i_nlink <= 1) {
50711 + saved_ino = inode->i_ino;
50712 + saved_dev = gr_get_dev_from_dentry(dentry);
50713 + }
50714 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
50715 + error = -EACCES;
50716 + goto exit2;
50717 + }
50718 +
50719 error = security_path_unlink(&nd.path, dentry);
50720 if (error)
50721 goto exit2;
50722 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
50723 + if (!error && (saved_ino || saved_dev))
50724 + gr_handle_delete(saved_ino, saved_dev);
50725 exit2:
50726 dput(dentry);
50727 }
50728 @@ -3547,9 +3739,17 @@ retry:
50729 if (IS_ERR(dentry))
50730 goto out_putname;
50731
50732 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
50733 + error = -EACCES;
50734 + goto out;
50735 + }
50736 +
50737 error = security_path_symlink(&path, dentry, from->name);
50738 if (!error)
50739 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
50740 + if (!error)
50741 + gr_handle_create(dentry, path.mnt);
50742 +out:
50743 done_path_create(&path, dentry);
50744 if (retry_estale(error, lookup_flags)) {
50745 lookup_flags |= LOOKUP_REVAL;
50746 @@ -3623,6 +3823,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
50747 {
50748 struct dentry *new_dentry;
50749 struct path old_path, new_path;
50750 + struct filename *to = NULL;
50751 int how = 0;
50752 int error;
50753
50754 @@ -3646,7 +3847,7 @@ retry:
50755 if (error)
50756 return error;
50757
50758 - new_dentry = user_path_create(newdfd, newname, &new_path,
50759 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
50760 (how & LOOKUP_REVAL));
50761 error = PTR_ERR(new_dentry);
50762 if (IS_ERR(new_dentry))
50763 @@ -3658,11 +3859,28 @@ retry:
50764 error = may_linkat(&old_path);
50765 if (unlikely(error))
50766 goto out_dput;
50767 +
50768 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
50769 + old_path.dentry->d_inode,
50770 + old_path.dentry->d_inode->i_mode, to)) {
50771 + error = -EACCES;
50772 + goto out_dput;
50773 + }
50774 +
50775 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
50776 + old_path.dentry, old_path.mnt, to)) {
50777 + error = -EACCES;
50778 + goto out_dput;
50779 + }
50780 +
50781 error = security_path_link(old_path.dentry, &new_path, new_dentry);
50782 if (error)
50783 goto out_dput;
50784 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
50785 + if (!error)
50786 + gr_handle_create(new_dentry, new_path.mnt);
50787 out_dput:
50788 + putname(to);
50789 done_path_create(&new_path, new_dentry);
50790 if (retry_estale(error, how)) {
50791 how |= LOOKUP_REVAL;
50792 @@ -3908,12 +4126,21 @@ retry:
50793 if (new_dentry == trap)
50794 goto exit5;
50795
50796 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
50797 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
50798 + to);
50799 + if (error)
50800 + goto exit5;
50801 +
50802 error = security_path_rename(&oldnd.path, old_dentry,
50803 &newnd.path, new_dentry);
50804 if (error)
50805 goto exit5;
50806 error = vfs_rename(old_dir->d_inode, old_dentry,
50807 new_dir->d_inode, new_dentry);
50808 + if (!error)
50809 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
50810 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
50811 exit5:
50812 dput(new_dentry);
50813 exit4:
50814 @@ -3945,6 +4172,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
50815
50816 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
50817 {
50818 + char tmpbuf[64];
50819 + const char *newlink;
50820 int len;
50821
50822 len = PTR_ERR(link);
50823 @@ -3954,7 +4183,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
50824 len = strlen(link);
50825 if (len > (unsigned) buflen)
50826 len = buflen;
50827 - if (copy_to_user(buffer, link, len))
50828 +
50829 + if (len < sizeof(tmpbuf)) {
50830 + memcpy(tmpbuf, link, len);
50831 + newlink = tmpbuf;
50832 + } else
50833 + newlink = link;
50834 +
50835 + if (copy_to_user(buffer, newlink, len))
50836 len = -EFAULT;
50837 out:
50838 return len;
50839 diff --git a/fs/namespace.c b/fs/namespace.c
50840 index 55605c5..f2908c8 100644
50841 --- a/fs/namespace.c
50842 +++ b/fs/namespace.c
50843 @@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
50844 if (!(sb->s_flags & MS_RDONLY))
50845 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
50846 up_write(&sb->s_umount);
50847 +
50848 + gr_log_remount(mnt->mnt_devname, retval);
50849 +
50850 return retval;
50851 }
50852
50853 @@ -1234,9 +1237,20 @@ static int do_umount(struct mount *mnt, int flags)
50854 br_write_unlock(&vfsmount_lock);
50855 up_write(&namespace_sem);
50856 release_mounts(&umount_list);
50857 +
50858 + gr_log_unmount(mnt->mnt_devname, retval);
50859 +
50860 return retval;
50861 }
50862
50863 +/*
50864 + * Is the caller allowed to modify his namespace?
50865 + */
50866 +static inline bool may_mount(void)
50867 +{
50868 + return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
50869 +}
50870 +
50871 /*
50872 * Now umount can handle mount points as well as block devices.
50873 * This is important for filesystems which use unnamed block devices.
50874 @@ -1255,6 +1269,9 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
50875 if (flags & ~(MNT_FORCE | MNT_DETACH | MNT_EXPIRE | UMOUNT_NOFOLLOW))
50876 return -EINVAL;
50877
50878 + if (!may_mount())
50879 + return -EPERM;
50880 +
50881 if (!(flags & UMOUNT_NOFOLLOW))
50882 lookup_flags |= LOOKUP_FOLLOW;
50883
50884 @@ -1268,10 +1285,6 @@ SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
50885 if (!check_mnt(mnt))
50886 goto dput_and_out;
50887
50888 - retval = -EPERM;
50889 - if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
50890 - goto dput_and_out;
50891 -
50892 retval = do_umount(mnt, flags);
50893 dput_and_out:
50894 /* we mustn't call path_put() as that would clear mnt_expiry_mark */
50895 @@ -1295,7 +1308,7 @@ SYSCALL_DEFINE1(oldumount, char __user *, name)
50896
50897 static int mount_is_safe(struct path *path)
50898 {
50899 - if (ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
50900 + if (may_mount())
50901 return 0;
50902 return -EPERM;
50903 #ifdef notyet
50904 @@ -1633,7 +1646,7 @@ static int do_change_type(struct path *path, int flag)
50905 int type;
50906 int err = 0;
50907
50908 - if (!ns_capable(mnt->mnt_ns->user_ns, CAP_SYS_ADMIN))
50909 + if (!may_mount())
50910 return -EPERM;
50911
50912 if (path->dentry != path->mnt->mnt_root)
50913 @@ -1797,7 +1810,7 @@ static int do_move_mount(struct path *path, const char *old_name)
50914 struct mount *p;
50915 struct mount *old;
50916 int err = 0;
50917 - if (!ns_capable(real_mount(path->mnt)->mnt_ns->user_ns, CAP_SYS_ADMIN))
50918 + if (!may_mount())
50919 return -EPERM;
50920 if (!old_name || !*old_name)
50921 return -EINVAL;
50922 @@ -1933,16 +1946,14 @@ static int do_new_mount(struct path *path, const char *fstype, int flags,
50923 int mnt_flags, const char *name, void *data)
50924 {
50925 struct file_system_type *type;
50926 - struct user_namespace *user_ns;
50927 + struct user_namespace *user_ns = current->nsproxy->mnt_ns->user_ns;
50928 struct vfsmount *mnt;
50929 int err;
50930
50931 if (!fstype)
50932 return -EINVAL;
50933
50934 - /* we need capabilities... */
50935 - user_ns = real_mount(path->mnt)->mnt_ns->user_ns;
50936 - if (!ns_capable(user_ns, CAP_SYS_ADMIN))
50937 + if (!may_mount())
50938 return -EPERM;
50939
50940 type = get_fs_type(fstype);
50941 @@ -2282,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
50942 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
50943 MS_STRICTATIME);
50944
50945 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
50946 + retval = -EPERM;
50947 + goto dput_out;
50948 + }
50949 +
50950 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
50951 + retval = -EPERM;
50952 + goto dput_out;
50953 + }
50954 +
50955 if (flags & MS_REMOUNT)
50956 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
50957 data_page);
50958 @@ -2296,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
50959 dev_name, data_page);
50960 dput_out:
50961 path_put(&path);
50962 +
50963 + gr_log_mount(dev_name, dir_name, retval);
50964 +
50965 return retval;
50966 }
50967
50968 @@ -2567,7 +2591,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50969 struct mount *new_mnt, *root_mnt;
50970 int error;
50971
50972 - if (!ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN))
50973 + if (!may_mount())
50974 return -EPERM;
50975
50976 error = user_path_dir(new_root, &new);
50977 @@ -2582,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
50978 if (error)
50979 goto out2;
50980
50981 + if (gr_handle_chroot_pivot()) {
50982 + error = -EPERM;
50983 + goto out2;
50984 + }
50985 +
50986 get_fs_root(current->fs, &root);
50987 error = lock_mount(&old);
50988 if (error)
50989 @@ -2785,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
50990 !nsown_capable(CAP_SYS_ADMIN))
50991 return -EPERM;
50992
50993 - if (fs->users != 1)
50994 + if (atomic_read(&fs->users) != 1)
50995 return -EINVAL;
50996
50997 get_mnt_ns(mnt_ns);
50998 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
50999 index ebeb94c..ff35337 100644
51000 --- a/fs/nfs/inode.c
51001 +++ b/fs/nfs/inode.c
51002 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
51003 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
51004 }
51005
51006 -static atomic_long_t nfs_attr_generation_counter;
51007 +static atomic_long_unchecked_t nfs_attr_generation_counter;
51008
51009 static unsigned long nfs_read_attr_generation_counter(void)
51010 {
51011 - return atomic_long_read(&nfs_attr_generation_counter);
51012 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
51013 }
51014
51015 unsigned long nfs_inc_attr_generation_counter(void)
51016 {
51017 - return atomic_long_inc_return(&nfs_attr_generation_counter);
51018 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
51019 }
51020
51021 void nfs_fattr_init(struct nfs_fattr *fattr)
51022 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
51023 index d586117..143d568 100644
51024 --- a/fs/nfsd/vfs.c
51025 +++ b/fs/nfsd/vfs.c
51026 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51027 } else {
51028 oldfs = get_fs();
51029 set_fs(KERNEL_DS);
51030 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
51031 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
51032 set_fs(oldfs);
51033 }
51034
51035 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
51036
51037 /* Write the data. */
51038 oldfs = get_fs(); set_fs(KERNEL_DS);
51039 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
51040 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
51041 set_fs(oldfs);
51042 if (host_err < 0)
51043 goto out_nfserr;
51044 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
51045 */
51046
51047 oldfs = get_fs(); set_fs(KERNEL_DS);
51048 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
51049 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
51050 set_fs(oldfs);
51051
51052 if (host_err < 0)
51053 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
51054 index 9ff4a5e..deb1f0f 100644
51055 --- a/fs/notify/fanotify/fanotify_user.c
51056 +++ b/fs/notify/fanotify/fanotify_user.c
51057 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
51058
51059 fd = fanotify_event_metadata.fd;
51060 ret = -EFAULT;
51061 - if (copy_to_user(buf, &fanotify_event_metadata,
51062 - fanotify_event_metadata.event_len))
51063 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
51064 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
51065 goto out_close_fd;
51066
51067 ret = prepare_for_access_response(group, event, fd);
51068 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
51069 index 7b51b05..5ea5ef6 100644
51070 --- a/fs/notify/notification.c
51071 +++ b/fs/notify/notification.c
51072 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
51073 * get set to 0 so it will never get 'freed'
51074 */
51075 static struct fsnotify_event *q_overflow_event;
51076 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51077 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51078
51079 /**
51080 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
51081 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
51082 */
51083 u32 fsnotify_get_cookie(void)
51084 {
51085 - return atomic_inc_return(&fsnotify_sync_cookie);
51086 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
51087 }
51088 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
51089
51090 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
51091 index 99e3610..02c1068 100644
51092 --- a/fs/ntfs/dir.c
51093 +++ b/fs/ntfs/dir.c
51094 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
51095 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
51096 ~(s64)(ndir->itype.index.block_size - 1)));
51097 /* Bounds checks. */
51098 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51099 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
51100 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
51101 "inode 0x%lx or driver bug.", vdir->i_ino);
51102 goto err_out;
51103 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
51104 index 5b2d4f0..c6de396 100644
51105 --- a/fs/ntfs/file.c
51106 +++ b/fs/ntfs/file.c
51107 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
51108 #endif /* NTFS_RW */
51109 };
51110
51111 -const struct file_operations ntfs_empty_file_ops = {};
51112 +const struct file_operations ntfs_empty_file_ops __read_only;
51113
51114 -const struct inode_operations ntfs_empty_inode_ops = {};
51115 +const struct inode_operations ntfs_empty_inode_ops __read_only;
51116 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
51117 index a9f78c7..ed8a381 100644
51118 --- a/fs/ocfs2/localalloc.c
51119 +++ b/fs/ocfs2/localalloc.c
51120 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
51121 goto bail;
51122 }
51123
51124 - atomic_inc(&osb->alloc_stats.moves);
51125 + atomic_inc_unchecked(&osb->alloc_stats.moves);
51126
51127 bail:
51128 if (handle)
51129 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
51130 index d355e6e..578d905 100644
51131 --- a/fs/ocfs2/ocfs2.h
51132 +++ b/fs/ocfs2/ocfs2.h
51133 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
51134
51135 struct ocfs2_alloc_stats
51136 {
51137 - atomic_t moves;
51138 - atomic_t local_data;
51139 - atomic_t bitmap_data;
51140 - atomic_t bg_allocs;
51141 - atomic_t bg_extends;
51142 + atomic_unchecked_t moves;
51143 + atomic_unchecked_t local_data;
51144 + atomic_unchecked_t bitmap_data;
51145 + atomic_unchecked_t bg_allocs;
51146 + atomic_unchecked_t bg_extends;
51147 };
51148
51149 enum ocfs2_local_alloc_state
51150 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
51151 index f169da4..9112253 100644
51152 --- a/fs/ocfs2/suballoc.c
51153 +++ b/fs/ocfs2/suballoc.c
51154 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
51155 mlog_errno(status);
51156 goto bail;
51157 }
51158 - atomic_inc(&osb->alloc_stats.bg_extends);
51159 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
51160
51161 /* You should never ask for this much metadata */
51162 BUG_ON(bits_wanted >
51163 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
51164 mlog_errno(status);
51165 goto bail;
51166 }
51167 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51168 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51169
51170 *suballoc_loc = res.sr_bg_blkno;
51171 *suballoc_bit_start = res.sr_bit_offset;
51172 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
51173 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
51174 res->sr_bits);
51175
51176 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51177 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51178
51179 BUG_ON(res->sr_bits != 1);
51180
51181 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
51182 mlog_errno(status);
51183 goto bail;
51184 }
51185 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51186 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
51187
51188 BUG_ON(res.sr_bits != 1);
51189
51190 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51191 cluster_start,
51192 num_clusters);
51193 if (!status)
51194 - atomic_inc(&osb->alloc_stats.local_data);
51195 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
51196 } else {
51197 if (min_clusters > (osb->bitmap_cpg - 1)) {
51198 /* The only paths asking for contiguousness
51199 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
51200 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
51201 res.sr_bg_blkno,
51202 res.sr_bit_offset);
51203 - atomic_inc(&osb->alloc_stats.bitmap_data);
51204 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
51205 *num_clusters = res.sr_bits;
51206 }
51207 }
51208 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
51209 index 0e91ec2..f4b3fc6 100644
51210 --- a/fs/ocfs2/super.c
51211 +++ b/fs/ocfs2/super.c
51212 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
51213 "%10s => GlobalAllocs: %d LocalAllocs: %d "
51214 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
51215 "Stats",
51216 - atomic_read(&osb->alloc_stats.bitmap_data),
51217 - atomic_read(&osb->alloc_stats.local_data),
51218 - atomic_read(&osb->alloc_stats.bg_allocs),
51219 - atomic_read(&osb->alloc_stats.moves),
51220 - atomic_read(&osb->alloc_stats.bg_extends));
51221 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
51222 + atomic_read_unchecked(&osb->alloc_stats.local_data),
51223 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
51224 + atomic_read_unchecked(&osb->alloc_stats.moves),
51225 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
51226
51227 out += snprintf(buf + out, len - out,
51228 "%10s => State: %u Descriptor: %llu Size: %u bits "
51229 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
51230 spin_lock_init(&osb->osb_xattr_lock);
51231 ocfs2_init_steal_slots(osb);
51232
51233 - atomic_set(&osb->alloc_stats.moves, 0);
51234 - atomic_set(&osb->alloc_stats.local_data, 0);
51235 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
51236 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
51237 - atomic_set(&osb->alloc_stats.bg_extends, 0);
51238 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
51239 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
51240 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
51241 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
51242 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
51243
51244 /* Copy the blockcheck stats from the superblock probe */
51245 osb->osb_ecc_stats = *stats;
51246 diff --git a/fs/open.c b/fs/open.c
51247 index 9b33c0c..2ffcca2 100644
51248 --- a/fs/open.c
51249 +++ b/fs/open.c
51250 @@ -31,6 +31,8 @@
51251 #include <linux/ima.h>
51252 #include <linux/dnotify.h>
51253
51254 +#define CREATE_TRACE_POINTS
51255 +#include <trace/events/fs.h>
51256 #include "internal.h"
51257
51258 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
51259 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
51260 error = locks_verify_truncate(inode, NULL, length);
51261 if (!error)
51262 error = security_path_truncate(path);
51263 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
51264 + error = -EACCES;
51265 if (!error)
51266 error = do_truncate(path->dentry, length, 0, NULL);
51267
51268 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
51269 error = locks_verify_truncate(inode, f.file, length);
51270 if (!error)
51271 error = security_path_truncate(&f.file->f_path);
51272 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
51273 + error = -EACCES;
51274 if (!error)
51275 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
51276 sb_end_write(inode->i_sb);
51277 @@ -373,6 +379,9 @@ retry:
51278 if (__mnt_is_readonly(path.mnt))
51279 res = -EROFS;
51280
51281 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
51282 + res = -EACCES;
51283 +
51284 out_path_release:
51285 path_put(&path);
51286 if (retry_estale(res, lookup_flags)) {
51287 @@ -404,6 +413,8 @@ retry:
51288 if (error)
51289 goto dput_and_out;
51290
51291 + gr_log_chdir(path.dentry, path.mnt);
51292 +
51293 set_fs_pwd(current->fs, &path);
51294
51295 dput_and_out:
51296 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
51297 goto out_putf;
51298
51299 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
51300 +
51301 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
51302 + error = -EPERM;
51303 +
51304 + if (!error)
51305 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
51306 +
51307 if (!error)
51308 set_fs_pwd(current->fs, &f.file->f_path);
51309 out_putf:
51310 @@ -462,7 +480,13 @@ retry:
51311 if (error)
51312 goto dput_and_out;
51313
51314 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
51315 + goto dput_and_out;
51316 +
51317 set_fs_root(current->fs, &path);
51318 +
51319 + gr_handle_chroot_chdir(&path);
51320 +
51321 error = 0;
51322 dput_and_out:
51323 path_put(&path);
51324 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
51325 if (error)
51326 return error;
51327 mutex_lock(&inode->i_mutex);
51328 +
51329 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
51330 + error = -EACCES;
51331 + goto out_unlock;
51332 + }
51333 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
51334 + error = -EACCES;
51335 + goto out_unlock;
51336 + }
51337 +
51338 error = security_path_chmod(path, mode);
51339 if (error)
51340 goto out_unlock;
51341 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
51342 uid = make_kuid(current_user_ns(), user);
51343 gid = make_kgid(current_user_ns(), group);
51344
51345 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
51346 + return -EACCES;
51347 +
51348 newattrs.ia_valid = ATTR_CTIME;
51349 if (user != (uid_t) -1) {
51350 if (!uid_valid(uid))
51351 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
51352 } else {
51353 fsnotify_open(f);
51354 fd_install(fd, f);
51355 + trace_do_sys_open(tmp->name, flags, mode);
51356 }
51357 }
51358 putname(tmp);
51359 diff --git a/fs/pipe.c b/fs/pipe.c
51360 index bd3479d..fb92c4d 100644
51361 --- a/fs/pipe.c
51362 +++ b/fs/pipe.c
51363 @@ -438,9 +438,9 @@ redo:
51364 }
51365 if (bufs) /* More to do? */
51366 continue;
51367 - if (!pipe->writers)
51368 + if (!atomic_read(&pipe->writers))
51369 break;
51370 - if (!pipe->waiting_writers) {
51371 + if (!atomic_read(&pipe->waiting_writers)) {
51372 /* syscall merging: Usually we must not sleep
51373 * if O_NONBLOCK is set, or if we got some data.
51374 * But if a writer sleeps in kernel space, then
51375 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
51376 mutex_lock(&inode->i_mutex);
51377 pipe = inode->i_pipe;
51378
51379 - if (!pipe->readers) {
51380 + if (!atomic_read(&pipe->readers)) {
51381 send_sig(SIGPIPE, current, 0);
51382 ret = -EPIPE;
51383 goto out;
51384 @@ -553,7 +553,7 @@ redo1:
51385 for (;;) {
51386 int bufs;
51387
51388 - if (!pipe->readers) {
51389 + if (!atomic_read(&pipe->readers)) {
51390 send_sig(SIGPIPE, current, 0);
51391 if (!ret)
51392 ret = -EPIPE;
51393 @@ -644,9 +644,9 @@ redo2:
51394 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
51395 do_wakeup = 0;
51396 }
51397 - pipe->waiting_writers++;
51398 + atomic_inc(&pipe->waiting_writers);
51399 pipe_wait(pipe);
51400 - pipe->waiting_writers--;
51401 + atomic_dec(&pipe->waiting_writers);
51402 }
51403 out:
51404 mutex_unlock(&inode->i_mutex);
51405 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51406 mask = 0;
51407 if (filp->f_mode & FMODE_READ) {
51408 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
51409 - if (!pipe->writers && filp->f_version != pipe->w_counter)
51410 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
51411 mask |= POLLHUP;
51412 }
51413
51414 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
51415 * Most Unices do not set POLLERR for FIFOs but on Linux they
51416 * behave exactly like pipes for poll().
51417 */
51418 - if (!pipe->readers)
51419 + if (!atomic_read(&pipe->readers))
51420 mask |= POLLERR;
51421 }
51422
51423 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
51424
51425 mutex_lock(&inode->i_mutex);
51426 pipe = inode->i_pipe;
51427 - pipe->readers -= decr;
51428 - pipe->writers -= decw;
51429 + atomic_sub(decr, &pipe->readers);
51430 + atomic_sub(decw, &pipe->writers);
51431
51432 - if (!pipe->readers && !pipe->writers) {
51433 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
51434 free_pipe_info(inode);
51435 } else {
51436 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
51437 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
51438
51439 if (inode->i_pipe) {
51440 ret = 0;
51441 - inode->i_pipe->readers++;
51442 + atomic_inc(&inode->i_pipe->readers);
51443 }
51444
51445 mutex_unlock(&inode->i_mutex);
51446 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
51447
51448 if (inode->i_pipe) {
51449 ret = 0;
51450 - inode->i_pipe->writers++;
51451 + atomic_inc(&inode->i_pipe->writers);
51452 }
51453
51454 mutex_unlock(&inode->i_mutex);
51455 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
51456 if (inode->i_pipe) {
51457 ret = 0;
51458 if (filp->f_mode & FMODE_READ)
51459 - inode->i_pipe->readers++;
51460 + atomic_inc(&inode->i_pipe->readers);
51461 if (filp->f_mode & FMODE_WRITE)
51462 - inode->i_pipe->writers++;
51463 + atomic_inc(&inode->i_pipe->writers);
51464 }
51465
51466 mutex_unlock(&inode->i_mutex);
51467 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
51468 inode->i_pipe = NULL;
51469 }
51470
51471 -static struct vfsmount *pipe_mnt __read_mostly;
51472 +struct vfsmount *pipe_mnt __read_mostly;
51473
51474 /*
51475 * pipefs_dname() is called from d_path().
51476 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
51477 goto fail_iput;
51478 inode->i_pipe = pipe;
51479
51480 - pipe->readers = pipe->writers = 1;
51481 + atomic_set(&pipe->readers, 1);
51482 + atomic_set(&pipe->writers, 1);
51483 inode->i_fop = &rdwr_pipefifo_fops;
51484
51485 /*
51486 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
51487 index 15af622..0e9f4467 100644
51488 --- a/fs/proc/Kconfig
51489 +++ b/fs/proc/Kconfig
51490 @@ -30,12 +30,12 @@ config PROC_FS
51491
51492 config PROC_KCORE
51493 bool "/proc/kcore support" if !ARM
51494 - depends on PROC_FS && MMU
51495 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
51496
51497 config PROC_VMCORE
51498 bool "/proc/vmcore support"
51499 - depends on PROC_FS && CRASH_DUMP
51500 - default y
51501 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
51502 + default n
51503 help
51504 Exports the dump image of crashed kernel in ELF format.
51505
51506 @@ -59,8 +59,8 @@ config PROC_SYSCTL
51507 limited in memory.
51508
51509 config PROC_PAGE_MONITOR
51510 - default y
51511 - depends on PROC_FS && MMU
51512 + default n
51513 + depends on PROC_FS && MMU && !GRKERNSEC
51514 bool "Enable /proc page monitoring" if EXPERT
51515 help
51516 Various /proc files exist to monitor process memory utilization:
51517 diff --git a/fs/proc/array.c b/fs/proc/array.c
51518 index 6a91e6f..e54dbc14 100644
51519 --- a/fs/proc/array.c
51520 +++ b/fs/proc/array.c
51521 @@ -60,6 +60,7 @@
51522 #include <linux/tty.h>
51523 #include <linux/string.h>
51524 #include <linux/mman.h>
51525 +#include <linux/grsecurity.h>
51526 #include <linux/proc_fs.h>
51527 #include <linux/ioport.h>
51528 #include <linux/uaccess.h>
51529 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
51530 seq_putc(m, '\n');
51531 }
51532
51533 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51534 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
51535 +{
51536 + if (p->mm)
51537 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
51538 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
51539 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
51540 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
51541 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
51542 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
51543 + else
51544 + seq_printf(m, "PaX:\t-----\n");
51545 +}
51546 +#endif
51547 +
51548 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51549 struct pid *pid, struct task_struct *task)
51550 {
51551 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51552 task_cpus_allowed(m, task);
51553 cpuset_task_status_allowed(m, task);
51554 task_context_switch_counts(m, task);
51555 +
51556 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
51557 + task_pax(m, task);
51558 +#endif
51559 +
51560 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
51561 + task_grsec_rbac(m, task);
51562 +#endif
51563 +
51564 return 0;
51565 }
51566
51567 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51568 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51569 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51570 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51571 +#endif
51572 +
51573 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51574 struct pid *pid, struct task_struct *task, int whole)
51575 {
51576 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51577 char tcomm[sizeof(task->comm)];
51578 unsigned long flags;
51579
51580 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51581 + if (current->exec_id != m->exec_id) {
51582 + gr_log_badprocpid("stat");
51583 + return 0;
51584 + }
51585 +#endif
51586 +
51587 state = *get_task_state(task);
51588 vsize = eip = esp = 0;
51589 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51590 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51591 gtime = task->gtime;
51592 }
51593
51594 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51595 + if (PAX_RAND_FLAGS(mm)) {
51596 + eip = 0;
51597 + esp = 0;
51598 + wchan = 0;
51599 + }
51600 +#endif
51601 +#ifdef CONFIG_GRKERNSEC_HIDESYM
51602 + wchan = 0;
51603 + eip =0;
51604 + esp =0;
51605 +#endif
51606 +
51607 /* scale priority and nice values from timeslices to -20..20 */
51608 /* to make it look like a "normal" Unix priority/nice value */
51609 priority = task_prio(task);
51610 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51611 seq_put_decimal_ull(m, ' ', vsize);
51612 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
51613 seq_put_decimal_ull(m, ' ', rsslim);
51614 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51615 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
51616 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
51617 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
51618 +#else
51619 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
51620 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
51621 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
51622 +#endif
51623 seq_put_decimal_ull(m, ' ', esp);
51624 seq_put_decimal_ull(m, ' ', eip);
51625 /* The signal information here is obsolete.
51626 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
51627 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
51628 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
51629
51630 - if (mm && permitted) {
51631 + if (mm && permitted
51632 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51633 + && !PAX_RAND_FLAGS(mm)
51634 +#endif
51635 + ) {
51636 seq_put_decimal_ull(m, ' ', mm->start_data);
51637 seq_put_decimal_ull(m, ' ', mm->end_data);
51638 seq_put_decimal_ull(m, ' ', mm->start_brk);
51639 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51640 struct pid *pid, struct task_struct *task)
51641 {
51642 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
51643 - struct mm_struct *mm = get_task_mm(task);
51644 + struct mm_struct *mm;
51645
51646 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51647 + if (current->exec_id != m->exec_id) {
51648 + gr_log_badprocpid("statm");
51649 + return 0;
51650 + }
51651 +#endif
51652 + mm = get_task_mm(task);
51653 if (mm) {
51654 size = task_statm(mm, &shared, &text, &data, &resident);
51655 mmput(mm);
51656 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51657 return 0;
51658 }
51659
51660 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51661 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
51662 +{
51663 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
51664 +}
51665 +#endif
51666 +
51667 #ifdef CONFIG_CHECKPOINT_RESTORE
51668 static struct pid *
51669 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
51670 diff --git a/fs/proc/base.c b/fs/proc/base.c
51671 index 9b43ff77..3d6a99f 100644
51672 --- a/fs/proc/base.c
51673 +++ b/fs/proc/base.c
51674 @@ -111,6 +111,14 @@ struct pid_entry {
51675 union proc_op op;
51676 };
51677
51678 +struct getdents_callback {
51679 + struct linux_dirent __user * current_dir;
51680 + struct linux_dirent __user * previous;
51681 + struct file * file;
51682 + int count;
51683 + int error;
51684 +};
51685 +
51686 #define NOD(NAME, MODE, IOP, FOP, OP) { \
51687 .name = (NAME), \
51688 .len = sizeof(NAME) - 1, \
51689 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
51690 if (!mm->arg_end)
51691 goto out_mm; /* Shh! No looking before we're done */
51692
51693 + if (gr_acl_handle_procpidmem(task))
51694 + goto out_mm;
51695 +
51696 len = mm->arg_end - mm->arg_start;
51697
51698 if (len > PAGE_SIZE)
51699 @@ -235,12 +246,28 @@ out:
51700 return res;
51701 }
51702
51703 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51704 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51705 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
51706 + _mm->pax_flags & MF_PAX_SEGMEXEC))
51707 +#endif
51708 +
51709 static int proc_pid_auxv(struct task_struct *task, char *buffer)
51710 {
51711 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
51712 int res = PTR_ERR(mm);
51713 if (mm && !IS_ERR(mm)) {
51714 unsigned int nwords = 0;
51715 +
51716 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51717 + /* allow if we're currently ptracing this task */
51718 + if (PAX_RAND_FLAGS(mm) &&
51719 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
51720 + mmput(mm);
51721 + return 0;
51722 + }
51723 +#endif
51724 +
51725 do {
51726 nwords += 2;
51727 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
51728 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
51729 }
51730
51731
51732 -#ifdef CONFIG_KALLSYMS
51733 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51734 /*
51735 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
51736 * Returns the resolved symbol. If that fails, simply return the address.
51737 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
51738 mutex_unlock(&task->signal->cred_guard_mutex);
51739 }
51740
51741 -#ifdef CONFIG_STACKTRACE
51742 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51743
51744 #define MAX_STACK_TRACE_DEPTH 64
51745
51746 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
51747 return count;
51748 }
51749
51750 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51751 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51752 static int proc_pid_syscall(struct task_struct *task, char *buffer)
51753 {
51754 long nr;
51755 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
51756 /************************************************************************/
51757
51758 /* permission checks */
51759 -static int proc_fd_access_allowed(struct inode *inode)
51760 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
51761 {
51762 struct task_struct *task;
51763 int allowed = 0;
51764 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
51765 */
51766 task = get_proc_task(inode);
51767 if (task) {
51768 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51769 + if (log)
51770 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
51771 + else
51772 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
51773 put_task_struct(task);
51774 }
51775 return allowed;
51776 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
51777 struct task_struct *task,
51778 int hide_pid_min)
51779 {
51780 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51781 + return false;
51782 +
51783 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51784 + rcu_read_lock();
51785 + {
51786 + const struct cred *tmpcred = current_cred();
51787 + const struct cred *cred = __task_cred(task);
51788 +
51789 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
51790 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51791 + || in_group_p(grsec_proc_gid)
51792 +#endif
51793 + ) {
51794 + rcu_read_unlock();
51795 + return true;
51796 + }
51797 + }
51798 + rcu_read_unlock();
51799 +
51800 + if (!pid->hide_pid)
51801 + return false;
51802 +#endif
51803 +
51804 if (pid->hide_pid < hide_pid_min)
51805 return true;
51806 if (in_group_p(pid->pid_gid))
51807 return true;
51808 +
51809 return ptrace_may_access(task, PTRACE_MODE_READ);
51810 }
51811
51812 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
51813 put_task_struct(task);
51814
51815 if (!has_perms) {
51816 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51817 + {
51818 +#else
51819 if (pid->hide_pid == 2) {
51820 +#endif
51821 /*
51822 * Let's make getdents(), stat(), and open()
51823 * consistent with each other. If a process
51824 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51825 if (!task)
51826 return -ESRCH;
51827
51828 + if (gr_acl_handle_procpidmem(task)) {
51829 + put_task_struct(task);
51830 + return -EPERM;
51831 + }
51832 +
51833 mm = mm_access(task, mode);
51834 put_task_struct(task);
51835
51836 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
51837
51838 file->private_data = mm;
51839
51840 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51841 + file->f_version = current->exec_id;
51842 +#endif
51843 +
51844 return 0;
51845 }
51846
51847 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
51848 ssize_t copied;
51849 char *page;
51850
51851 +#ifdef CONFIG_GRKERNSEC
51852 + if (write)
51853 + return -EPERM;
51854 +#endif
51855 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51856 + if (file->f_version != current->exec_id) {
51857 + gr_log_badprocpid("mem");
51858 + return 0;
51859 + }
51860 +#endif
51861 +
51862 if (!mm)
51863 return 0;
51864
51865 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
51866 if (!mm)
51867 return 0;
51868
51869 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51870 + if (file->f_version != current->exec_id) {
51871 + gr_log_badprocpid("environ");
51872 + return 0;
51873 + }
51874 +#endif
51875 +
51876 page = (char *)__get_free_page(GFP_TEMPORARY);
51877 if (!page)
51878 return -ENOMEM;
51879 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
51880 int error = -EACCES;
51881
51882 /* Are we allowed to snoop on the tasks file descriptors? */
51883 - if (!proc_fd_access_allowed(inode))
51884 + if (!proc_fd_access_allowed(inode, 0))
51885 goto out;
51886
51887 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51888 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
51889 struct path path;
51890
51891 /* Are we allowed to snoop on the tasks file descriptors? */
51892 - if (!proc_fd_access_allowed(inode))
51893 - goto out;
51894 + /* logging this is needed for learning on chromium to work properly,
51895 + but we don't want to flood the logs from 'ps' which does a readlink
51896 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
51897 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
51898 + */
51899 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
51900 + if (!proc_fd_access_allowed(inode,0))
51901 + goto out;
51902 + } else {
51903 + if (!proc_fd_access_allowed(inode,1))
51904 + goto out;
51905 + }
51906
51907 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
51908 if (error)
51909 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
51910 rcu_read_lock();
51911 cred = __task_cred(task);
51912 inode->i_uid = cred->euid;
51913 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51914 + inode->i_gid = grsec_proc_gid;
51915 +#else
51916 inode->i_gid = cred->egid;
51917 +#endif
51918 rcu_read_unlock();
51919 }
51920 security_task_to_inode(task, inode);
51921 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51922 return -ENOENT;
51923 }
51924 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51925 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51926 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51927 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51928 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51929 +#endif
51930 task_dumpable(task)) {
51931 cred = __task_cred(task);
51932 stat->uid = cred->euid;
51933 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51934 + stat->gid = grsec_proc_gid;
51935 +#else
51936 stat->gid = cred->egid;
51937 +#endif
51938 }
51939 }
51940 rcu_read_unlock();
51941 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
51942
51943 if (task) {
51944 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
51945 +#ifdef CONFIG_GRKERNSEC_PROC_USER
51946 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
51947 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51948 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
51949 +#endif
51950 task_dumpable(task)) {
51951 rcu_read_lock();
51952 cred = __task_cred(task);
51953 inode->i_uid = cred->euid;
51954 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
51955 + inode->i_gid = grsec_proc_gid;
51956 +#else
51957 inode->i_gid = cred->egid;
51958 +#endif
51959 rcu_read_unlock();
51960 } else {
51961 inode->i_uid = GLOBAL_ROOT_UID;
51962 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
51963 if (!task)
51964 goto out_no_task;
51965
51966 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51967 + goto out;
51968 +
51969 /*
51970 * Yes, it does not scale. And it should not. Don't add
51971 * new entries into /proc/<tgid>/ without very good reasons.
51972 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
51973 if (!task)
51974 goto out_no_task;
51975
51976 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
51977 + goto out;
51978 +
51979 ret = 0;
51980 i = filp->f_pos;
51981 switch (i) {
51982 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
51983 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
51984 #endif
51985 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
51986 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
51987 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51988 INF("syscall", S_IRUGO, proc_pid_syscall),
51989 #endif
51990 INF("cmdline", S_IRUGO, proc_pid_cmdline),
51991 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
51992 #ifdef CONFIG_SECURITY
51993 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
51994 #endif
51995 -#ifdef CONFIG_KALLSYMS
51996 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
51997 INF("wchan", S_IRUGO, proc_pid_wchan),
51998 #endif
51999 -#ifdef CONFIG_STACKTRACE
52000 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52001 ONE("stack", S_IRUGO, proc_pid_stack),
52002 #endif
52003 #ifdef CONFIG_SCHEDSTATS
52004 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
52005 #ifdef CONFIG_HARDWALL
52006 INF("hardwall", S_IRUGO, proc_pid_hardwall),
52007 #endif
52008 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52009 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
52010 +#endif
52011 #ifdef CONFIG_USER_NS
52012 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
52013 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
52014 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
52015 if (!inode)
52016 goto out;
52017
52018 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52019 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
52020 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52021 + inode->i_gid = grsec_proc_gid;
52022 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
52023 +#else
52024 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
52025 +#endif
52026 inode->i_op = &proc_tgid_base_inode_operations;
52027 inode->i_fop = &proc_tgid_base_operations;
52028 inode->i_flags|=S_IMMUTABLE;
52029 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
52030 if (!task)
52031 goto out;
52032
52033 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
52034 + goto out_put_task;
52035 +
52036 result = proc_pid_instantiate(dir, dentry, task, NULL);
52037 +out_put_task:
52038 put_task_struct(task);
52039 out:
52040 return result;
52041 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
52042 static int fake_filldir(void *buf, const char *name, int namelen,
52043 loff_t offset, u64 ino, unsigned d_type)
52044 {
52045 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
52046 + __buf->error = -EINVAL;
52047 return 0;
52048 }
52049
52050 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
52051 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
52052 #endif
52053 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
52054 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
52055 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
52056 INF("syscall", S_IRUGO, proc_pid_syscall),
52057 #endif
52058 INF("cmdline", S_IRUGO, proc_pid_cmdline),
52059 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
52060 #ifdef CONFIG_SECURITY
52061 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
52062 #endif
52063 -#ifdef CONFIG_KALLSYMS
52064 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52065 INF("wchan", S_IRUGO, proc_pid_wchan),
52066 #endif
52067 -#ifdef CONFIG_STACKTRACE
52068 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
52069 ONE("stack", S_IRUGO, proc_pid_stack),
52070 #endif
52071 #ifdef CONFIG_SCHEDSTATS
52072 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
52073 index 82676e3..5f8518a 100644
52074 --- a/fs/proc/cmdline.c
52075 +++ b/fs/proc/cmdline.c
52076 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
52077
52078 static int __init proc_cmdline_init(void)
52079 {
52080 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52081 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
52082 +#else
52083 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
52084 +#endif
52085 return 0;
52086 }
52087 module_init(proc_cmdline_init);
52088 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
52089 index b143471..bb105e5 100644
52090 --- a/fs/proc/devices.c
52091 +++ b/fs/proc/devices.c
52092 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
52093
52094 static int __init proc_devices_init(void)
52095 {
52096 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52097 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
52098 +#else
52099 proc_create("devices", 0, NULL, &proc_devinfo_operations);
52100 +#endif
52101 return 0;
52102 }
52103 module_init(proc_devices_init);
52104 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
52105 index d7a4a28..0201742 100644
52106 --- a/fs/proc/fd.c
52107 +++ b/fs/proc/fd.c
52108 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
52109 if (!task)
52110 return -ENOENT;
52111
52112 - files = get_files_struct(task);
52113 + if (!gr_acl_handle_procpidmem(task))
52114 + files = get_files_struct(task);
52115 put_task_struct(task);
52116
52117 if (files) {
52118 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
52119 */
52120 int proc_fd_permission(struct inode *inode, int mask)
52121 {
52122 + struct task_struct *task;
52123 int rv = generic_permission(inode, mask);
52124 - if (rv == 0)
52125 - return 0;
52126 +
52127 if (task_pid(current) == proc_pid(inode))
52128 rv = 0;
52129 +
52130 + task = get_proc_task(inode);
52131 + if (task == NULL)
52132 + return rv;
52133 +
52134 + if (gr_acl_handle_procpidmem(task))
52135 + rv = -EACCES;
52136 +
52137 + put_task_struct(task);
52138 +
52139 return rv;
52140 }
52141
52142 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
52143 index 439ae688..c21ac36 100644
52144 --- a/fs/proc/inode.c
52145 +++ b/fs/proc/inode.c
52146 @@ -21,11 +21,17 @@
52147 #include <linux/seq_file.h>
52148 #include <linux/slab.h>
52149 #include <linux/mount.h>
52150 +#include <linux/grsecurity.h>
52151
52152 #include <asm/uaccess.h>
52153
52154 #include "internal.h"
52155
52156 +#ifdef CONFIG_PROC_SYSCTL
52157 +extern const struct inode_operations proc_sys_inode_operations;
52158 +extern const struct inode_operations proc_sys_dir_operations;
52159 +#endif
52160 +
52161 static void proc_evict_inode(struct inode *inode)
52162 {
52163 struct proc_dir_entry *de;
52164 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
52165 ns = PROC_I(inode)->ns;
52166 if (ns_ops && ns)
52167 ns_ops->put(ns);
52168 +
52169 +#ifdef CONFIG_PROC_SYSCTL
52170 + if (inode->i_op == &proc_sys_inode_operations ||
52171 + inode->i_op == &proc_sys_dir_operations)
52172 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
52173 +#endif
52174 +
52175 }
52176
52177 static struct kmem_cache * proc_inode_cachep;
52178 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
52179 if (de->mode) {
52180 inode->i_mode = de->mode;
52181 inode->i_uid = de->uid;
52182 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
52183 + inode->i_gid = grsec_proc_gid;
52184 +#else
52185 inode->i_gid = de->gid;
52186 +#endif
52187 }
52188 if (de->size)
52189 inode->i_size = de->size;
52190 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
52191 index 252544c..04395b9 100644
52192 --- a/fs/proc/internal.h
52193 +++ b/fs/proc/internal.h
52194 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
52195 struct pid *pid, struct task_struct *task);
52196 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
52197 struct pid *pid, struct task_struct *task);
52198 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
52199 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
52200 +#endif
52201 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
52202
52203 extern const struct file_operations proc_tid_children_operations;
52204 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
52205 index e96d4f1..8b116ed 100644
52206 --- a/fs/proc/kcore.c
52207 +++ b/fs/proc/kcore.c
52208 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52209 * the addresses in the elf_phdr on our list.
52210 */
52211 start = kc_offset_to_vaddr(*fpos - elf_buflen);
52212 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
52213 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
52214 + if (tsz > buflen)
52215 tsz = buflen;
52216 -
52217 +
52218 while (buflen) {
52219 struct kcore_list *m;
52220
52221 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52222 kfree(elf_buf);
52223 } else {
52224 if (kern_addr_valid(start)) {
52225 - unsigned long n;
52226 + char *elf_buf;
52227 + mm_segment_t oldfs;
52228
52229 - n = copy_to_user(buffer, (char *)start, tsz);
52230 - /*
52231 - * We cannot distinguish between fault on source
52232 - * and fault on destination. When this happens
52233 - * we clear too and hope it will trigger the
52234 - * EFAULT again.
52235 - */
52236 - if (n) {
52237 - if (clear_user(buffer + tsz - n,
52238 - n))
52239 + elf_buf = kmalloc(tsz, GFP_KERNEL);
52240 + if (!elf_buf)
52241 + return -ENOMEM;
52242 + oldfs = get_fs();
52243 + set_fs(KERNEL_DS);
52244 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
52245 + set_fs(oldfs);
52246 + if (copy_to_user(buffer, elf_buf, tsz)) {
52247 + kfree(elf_buf);
52248 return -EFAULT;
52249 + }
52250 }
52251 + set_fs(oldfs);
52252 + kfree(elf_buf);
52253 } else {
52254 if (clear_user(buffer, tsz))
52255 return -EFAULT;
52256 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
52257
52258 static int open_kcore(struct inode *inode, struct file *filp)
52259 {
52260 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
52261 + return -EPERM;
52262 +#endif
52263 if (!capable(CAP_SYS_RAWIO))
52264 return -EPERM;
52265 if (kcore_need_update)
52266 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
52267 index 80e4645..53e5fcf 100644
52268 --- a/fs/proc/meminfo.c
52269 +++ b/fs/proc/meminfo.c
52270 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
52271 vmi.used >> 10,
52272 vmi.largest_chunk >> 10
52273 #ifdef CONFIG_MEMORY_FAILURE
52274 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
52275 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
52276 #endif
52277 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
52278 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
52279 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
52280 index b1822dd..df622cb 100644
52281 --- a/fs/proc/nommu.c
52282 +++ b/fs/proc/nommu.c
52283 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
52284 if (len < 1)
52285 len = 1;
52286 seq_printf(m, "%*c", len, ' ');
52287 - seq_path(m, &file->f_path, "");
52288 + seq_path(m, &file->f_path, "\n\\");
52289 }
52290
52291 seq_putc(m, '\n');
52292 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
52293 index fe72cd0..cb9b67d 100644
52294 --- a/fs/proc/proc_net.c
52295 +++ b/fs/proc/proc_net.c
52296 @@ -23,6 +23,7 @@
52297 #include <linux/nsproxy.h>
52298 #include <net/net_namespace.h>
52299 #include <linux/seq_file.h>
52300 +#include <linux/grsecurity.h>
52301
52302 #include "internal.h"
52303
52304 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
52305 struct task_struct *task;
52306 struct nsproxy *ns;
52307 struct net *net = NULL;
52308 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52309 + const struct cred *cred = current_cred();
52310 +#endif
52311 +
52312 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52313 + if (cred->fsuid)
52314 + return net;
52315 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52316 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
52317 + return net;
52318 +#endif
52319
52320 rcu_read_lock();
52321 task = pid_task(proc_pid(dir), PIDTYPE_PID);
52322 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
52323 index 1827d88..9a60b01 100644
52324 --- a/fs/proc/proc_sysctl.c
52325 +++ b/fs/proc/proc_sysctl.c
52326 @@ -12,11 +12,15 @@
52327 #include <linux/module.h>
52328 #include "internal.h"
52329
52330 +extern int gr_handle_chroot_sysctl(const int op);
52331 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
52332 + const int op);
52333 +
52334 static const struct dentry_operations proc_sys_dentry_operations;
52335 static const struct file_operations proc_sys_file_operations;
52336 -static const struct inode_operations proc_sys_inode_operations;
52337 +const struct inode_operations proc_sys_inode_operations;
52338 static const struct file_operations proc_sys_dir_file_operations;
52339 -static const struct inode_operations proc_sys_dir_operations;
52340 +const struct inode_operations proc_sys_dir_operations;
52341
52342 void proc_sys_poll_notify(struct ctl_table_poll *poll)
52343 {
52344 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
52345
52346 err = NULL;
52347 d_set_d_op(dentry, &proc_sys_dentry_operations);
52348 +
52349 + gr_handle_proc_create(dentry, inode);
52350 +
52351 d_add(dentry, inode);
52352
52353 out:
52354 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52355 struct inode *inode = filp->f_path.dentry->d_inode;
52356 struct ctl_table_header *head = grab_header(inode);
52357 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
52358 + int op = write ? MAY_WRITE : MAY_READ;
52359 ssize_t error;
52360 size_t res;
52361
52362 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52363 * and won't be until we finish.
52364 */
52365 error = -EPERM;
52366 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
52367 + if (sysctl_perm(head, table, op))
52368 goto out;
52369
52370 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
52371 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
52372 if (!table->proc_handler)
52373 goto out;
52374
52375 +#ifdef CONFIG_GRKERNSEC
52376 + error = -EPERM;
52377 + if (gr_handle_chroot_sysctl(op))
52378 + goto out;
52379 + dget(filp->f_path.dentry);
52380 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
52381 + dput(filp->f_path.dentry);
52382 + goto out;
52383 + }
52384 + dput(filp->f_path.dentry);
52385 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
52386 + goto out;
52387 + if (write && !capable(CAP_SYS_ADMIN))
52388 + goto out;
52389 +#endif
52390 +
52391 /* careful: calling conventions are nasty here */
52392 res = count;
52393 error = table->proc_handler(table, write, buf, &res, ppos);
52394 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
52395 return -ENOMEM;
52396 } else {
52397 d_set_d_op(child, &proc_sys_dentry_operations);
52398 +
52399 + gr_handle_proc_create(child, inode);
52400 +
52401 d_add(child, inode);
52402 }
52403 } else {
52404 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
52405 if ((*pos)++ < file->f_pos)
52406 return 0;
52407
52408 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
52409 + return 0;
52410 +
52411 if (unlikely(S_ISLNK(table->mode)))
52412 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
52413 else
52414 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
52415 if (IS_ERR(head))
52416 return PTR_ERR(head);
52417
52418 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
52419 + return -ENOENT;
52420 +
52421 generic_fillattr(inode, stat);
52422 if (table)
52423 stat->mode = (stat->mode & S_IFMT) | table->mode;
52424 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
52425 .llseek = generic_file_llseek,
52426 };
52427
52428 -static const struct inode_operations proc_sys_inode_operations = {
52429 +const struct inode_operations proc_sys_inode_operations = {
52430 .permission = proc_sys_permission,
52431 .setattr = proc_sys_setattr,
52432 .getattr = proc_sys_getattr,
52433 };
52434
52435 -static const struct inode_operations proc_sys_dir_operations = {
52436 +const struct inode_operations proc_sys_dir_operations = {
52437 .lookup = proc_sys_lookup,
52438 .permission = proc_sys_permission,
52439 .setattr = proc_sys_setattr,
52440 diff --git a/fs/proc/root.c b/fs/proc/root.c
52441 index c6e9fac..a740964 100644
52442 --- a/fs/proc/root.c
52443 +++ b/fs/proc/root.c
52444 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
52445 #ifdef CONFIG_PROC_DEVICETREE
52446 proc_device_tree_init();
52447 #endif
52448 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
52449 +#ifdef CONFIG_GRKERNSEC_PROC_USER
52450 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
52451 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
52452 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
52453 +#endif
52454 +#else
52455 proc_mkdir("bus", NULL);
52456 +#endif
52457 proc_sys_init();
52458 }
52459
52460 diff --git a/fs/proc/self.c b/fs/proc/self.c
52461 index aa5cc3b..c91a5d0 100644
52462 --- a/fs/proc/self.c
52463 +++ b/fs/proc/self.c
52464 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
52465 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
52466 void *cookie)
52467 {
52468 - char *s = nd_get_link(nd);
52469 + const char *s = nd_get_link(nd);
52470 if (!IS_ERR(s))
52471 kfree(s);
52472 }
52473 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
52474 index ca5ce7f..02c1cf0 100644
52475 --- a/fs/proc/task_mmu.c
52476 +++ b/fs/proc/task_mmu.c
52477 @@ -11,12 +11,19 @@
52478 #include <linux/rmap.h>
52479 #include <linux/swap.h>
52480 #include <linux/swapops.h>
52481 +#include <linux/grsecurity.h>
52482
52483 #include <asm/elf.h>
52484 #include <asm/uaccess.h>
52485 #include <asm/tlbflush.h>
52486 #include "internal.h"
52487
52488 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52489 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
52490 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
52491 + _mm->pax_flags & MF_PAX_SEGMEXEC))
52492 +#endif
52493 +
52494 void task_mem(struct seq_file *m, struct mm_struct *mm)
52495 {
52496 unsigned long data, text, lib, swap;
52497 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52498 "VmExe:\t%8lu kB\n"
52499 "VmLib:\t%8lu kB\n"
52500 "VmPTE:\t%8lu kB\n"
52501 - "VmSwap:\t%8lu kB\n",
52502 - hiwater_vm << (PAGE_SHIFT-10),
52503 + "VmSwap:\t%8lu kB\n"
52504 +
52505 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52506 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
52507 +#endif
52508 +
52509 + ,hiwater_vm << (PAGE_SHIFT-10),
52510 total_vm << (PAGE_SHIFT-10),
52511 mm->locked_vm << (PAGE_SHIFT-10),
52512 mm->pinned_vm << (PAGE_SHIFT-10),
52513 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52514 data << (PAGE_SHIFT-10),
52515 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
52516 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
52517 - swap << (PAGE_SHIFT-10));
52518 + swap << (PAGE_SHIFT-10)
52519 +
52520 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
52521 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52522 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
52523 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
52524 +#else
52525 + , mm->context.user_cs_base
52526 + , mm->context.user_cs_limit
52527 +#endif
52528 +#endif
52529 +
52530 + );
52531 }
52532
52533 unsigned long task_vsize(struct mm_struct *mm)
52534 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52535 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
52536 }
52537
52538 - /* We don't show the stack guard page in /proc/maps */
52539 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52540 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
52541 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
52542 +#else
52543 start = vma->vm_start;
52544 - if (stack_guard_page_start(vma, start))
52545 - start += PAGE_SIZE;
52546 end = vma->vm_end;
52547 - if (stack_guard_page_end(vma, end))
52548 - end -= PAGE_SIZE;
52549 +#endif
52550
52551 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
52552 start,
52553 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52554 flags & VM_WRITE ? 'w' : '-',
52555 flags & VM_EXEC ? 'x' : '-',
52556 flags & VM_MAYSHARE ? 's' : 'p',
52557 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52558 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
52559 +#else
52560 pgoff,
52561 +#endif
52562 MAJOR(dev), MINOR(dev), ino, &len);
52563
52564 /*
52565 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52566 */
52567 if (file) {
52568 pad_len_spaces(m, len);
52569 - seq_path(m, &file->f_path, "\n");
52570 + seq_path(m, &file->f_path, "\n\\");
52571 goto done;
52572 }
52573
52574 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
52575 * Thread stack in /proc/PID/task/TID/maps or
52576 * the main process stack.
52577 */
52578 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
52579 - vma->vm_end >= mm->start_stack)) {
52580 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
52581 + (vma->vm_start <= mm->start_stack &&
52582 + vma->vm_end >= mm->start_stack)) {
52583 name = "[stack]";
52584 } else {
52585 /* Thread stack in /proc/PID/maps */
52586 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
52587 struct proc_maps_private *priv = m->private;
52588 struct task_struct *task = priv->task;
52589
52590 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52591 + if (current->exec_id != m->exec_id) {
52592 + gr_log_badprocpid("maps");
52593 + return 0;
52594 + }
52595 +#endif
52596 +
52597 show_map_vma(m, vma, is_pid);
52598
52599 if (m->count < m->size) /* vma is copied successfully */
52600 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52601 .private = &mss,
52602 };
52603
52604 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52605 + if (current->exec_id != m->exec_id) {
52606 + gr_log_badprocpid("smaps");
52607 + return 0;
52608 + }
52609 +#endif
52610 memset(&mss, 0, sizeof mss);
52611 - mss.vma = vma;
52612 - /* mmap_sem is held in m_start */
52613 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52614 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52615 -
52616 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52617 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
52618 +#endif
52619 + mss.vma = vma;
52620 + /* mmap_sem is held in m_start */
52621 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
52622 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
52623 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52624 + }
52625 +#endif
52626 show_map_vma(m, vma, is_pid);
52627
52628 seq_printf(m,
52629 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
52630 "KernelPageSize: %8lu kB\n"
52631 "MMUPageSize: %8lu kB\n"
52632 "Locked: %8lu kB\n",
52633 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52634 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
52635 +#else
52636 (vma->vm_end - vma->vm_start) >> 10,
52637 +#endif
52638 mss.resident >> 10,
52639 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
52640 mss.shared_clean >> 10,
52641 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52642 int n;
52643 char buffer[50];
52644
52645 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52646 + if (current->exec_id != m->exec_id) {
52647 + gr_log_badprocpid("numa_maps");
52648 + return 0;
52649 + }
52650 +#endif
52651 +
52652 if (!mm)
52653 return 0;
52654
52655 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
52656 mpol_to_str(buffer, sizeof(buffer), pol);
52657 mpol_cond_put(pol);
52658
52659 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52660 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
52661 +#else
52662 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
52663 +#endif
52664
52665 if (file) {
52666 seq_printf(m, " file=");
52667 - seq_path(m, &file->f_path, "\n\t= ");
52668 + seq_path(m, &file->f_path, "\n\t\\= ");
52669 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
52670 seq_printf(m, " heap");
52671 } else {
52672 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
52673 index 1ccfa53..0848f95 100644
52674 --- a/fs/proc/task_nommu.c
52675 +++ b/fs/proc/task_nommu.c
52676 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
52677 else
52678 bytes += kobjsize(mm);
52679
52680 - if (current->fs && current->fs->users > 1)
52681 + if (current->fs && atomic_read(&current->fs->users) > 1)
52682 sbytes += kobjsize(current->fs);
52683 else
52684 bytes += kobjsize(current->fs);
52685 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
52686
52687 if (file) {
52688 pad_len_spaces(m, len);
52689 - seq_path(m, &file->f_path, "");
52690 + seq_path(m, &file->f_path, "\n\\");
52691 } else if (mm) {
52692 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
52693
52694 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
52695 index 16e8abb..2dcf914 100644
52696 --- a/fs/quota/netlink.c
52697 +++ b/fs/quota/netlink.c
52698 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
52699 void quota_send_warning(struct kqid qid, dev_t dev,
52700 const char warntype)
52701 {
52702 - static atomic_t seq;
52703 + static atomic_unchecked_t seq;
52704 struct sk_buff *skb;
52705 void *msg_head;
52706 int ret;
52707 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
52708 "VFS: Not enough memory to send quota warning.\n");
52709 return;
52710 }
52711 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
52712 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
52713 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
52714 if (!msg_head) {
52715 printk(KERN_ERR
52716 diff --git a/fs/readdir.c b/fs/readdir.c
52717 index 5e69ef5..e5d9099 100644
52718 --- a/fs/readdir.c
52719 +++ b/fs/readdir.c
52720 @@ -17,6 +17,7 @@
52721 #include <linux/security.h>
52722 #include <linux/syscalls.h>
52723 #include <linux/unistd.h>
52724 +#include <linux/namei.h>
52725
52726 #include <asm/uaccess.h>
52727
52728 @@ -67,6 +68,7 @@ struct old_linux_dirent {
52729
52730 struct readdir_callback {
52731 struct old_linux_dirent __user * dirent;
52732 + struct file * file;
52733 int result;
52734 };
52735
52736 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
52737 buf->result = -EOVERFLOW;
52738 return -EOVERFLOW;
52739 }
52740 +
52741 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52742 + return 0;
52743 +
52744 buf->result++;
52745 dirent = buf->dirent;
52746 if (!access_ok(VERIFY_WRITE, dirent,
52747 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
52748
52749 buf.result = 0;
52750 buf.dirent = dirent;
52751 + buf.file = f.file;
52752
52753 error = vfs_readdir(f.file, fillonedir, &buf);
52754 if (buf.result)
52755 @@ -139,6 +146,7 @@ struct linux_dirent {
52756 struct getdents_callback {
52757 struct linux_dirent __user * current_dir;
52758 struct linux_dirent __user * previous;
52759 + struct file * file;
52760 int count;
52761 int error;
52762 };
52763 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
52764 buf->error = -EOVERFLOW;
52765 return -EOVERFLOW;
52766 }
52767 +
52768 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52769 + return 0;
52770 +
52771 dirent = buf->previous;
52772 if (dirent) {
52773 if (__put_user(offset, &dirent->d_off))
52774 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52775 buf.previous = NULL;
52776 buf.count = count;
52777 buf.error = 0;
52778 + buf.file = f.file;
52779
52780 error = vfs_readdir(f.file, filldir, &buf);
52781 if (error >= 0)
52782 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
52783 struct getdents_callback64 {
52784 struct linux_dirent64 __user * current_dir;
52785 struct linux_dirent64 __user * previous;
52786 + struct file *file;
52787 int count;
52788 int error;
52789 };
52790 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
52791 buf->error = -EINVAL; /* only used if we fail.. */
52792 if (reclen > buf->count)
52793 return -EINVAL;
52794 +
52795 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
52796 + return 0;
52797 +
52798 dirent = buf->previous;
52799 if (dirent) {
52800 if (__put_user(offset, &dirent->d_off))
52801 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52802
52803 buf.current_dir = dirent;
52804 buf.previous = NULL;
52805 + buf.file = f.file;
52806 buf.count = count;
52807 buf.error = 0;
52808
52809 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
52810 error = buf.error;
52811 lastdirent = buf.previous;
52812 if (lastdirent) {
52813 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
52814 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
52815 if (__put_user(d_off, &lastdirent->d_off))
52816 error = -EFAULT;
52817 else
52818 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
52819 index 2b7882b..1c5ef48 100644
52820 --- a/fs/reiserfs/do_balan.c
52821 +++ b/fs/reiserfs/do_balan.c
52822 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
52823 return;
52824 }
52825
52826 - atomic_inc(&(fs_generation(tb->tb_sb)));
52827 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
52828 do_balance_starts(tb);
52829
52830 /* balance leaf returns 0 except if combining L R and S into
52831 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
52832 index e60e870..f40ac16 100644
52833 --- a/fs/reiserfs/procfs.c
52834 +++ b/fs/reiserfs/procfs.c
52835 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
52836 "SMALL_TAILS " : "NO_TAILS ",
52837 replay_only(sb) ? "REPLAY_ONLY " : "",
52838 convert_reiserfs(sb) ? "CONV " : "",
52839 - atomic_read(&r->s_generation_counter),
52840 + atomic_read_unchecked(&r->s_generation_counter),
52841 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
52842 SF(s_do_balance), SF(s_unneeded_left_neighbor),
52843 SF(s_good_search_by_key_reada), SF(s_bmaps),
52844 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
52845 index 157e474..65a6114 100644
52846 --- a/fs/reiserfs/reiserfs.h
52847 +++ b/fs/reiserfs/reiserfs.h
52848 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
52849 /* Comment? -Hans */
52850 wait_queue_head_t s_wait;
52851 /* To be obsoleted soon by per buffer seals.. -Hans */
52852 - atomic_t s_generation_counter; // increased by one every time the
52853 + atomic_unchecked_t s_generation_counter; // increased by one every time the
52854 // tree gets re-balanced
52855 unsigned long s_properties; /* File system properties. Currently holds
52856 on-disk FS format */
52857 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
52858 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
52859
52860 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
52861 -#define get_generation(s) atomic_read (&fs_generation(s))
52862 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
52863 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
52864 #define __fs_changed(gen,s) (gen != get_generation (s))
52865 #define fs_changed(gen,s) \
52866 diff --git a/fs/select.c b/fs/select.c
52867 index 2ef72d9..f213b17 100644
52868 --- a/fs/select.c
52869 +++ b/fs/select.c
52870 @@ -20,6 +20,7 @@
52871 #include <linux/export.h>
52872 #include <linux/slab.h>
52873 #include <linux/poll.h>
52874 +#include <linux/security.h>
52875 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
52876 #include <linux/file.h>
52877 #include <linux/fdtable.h>
52878 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
52879 struct poll_list *walk = head;
52880 unsigned long todo = nfds;
52881
52882 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
52883 if (nfds > rlimit(RLIMIT_NOFILE))
52884 return -EINVAL;
52885
52886 diff --git a/fs/seq_file.c b/fs/seq_file.c
52887 index f2bc3df..239d4f6 100644
52888 --- a/fs/seq_file.c
52889 +++ b/fs/seq_file.c
52890 @@ -10,6 +10,7 @@
52891 #include <linux/seq_file.h>
52892 #include <linux/slab.h>
52893 #include <linux/cred.h>
52894 +#include <linux/sched.h>
52895
52896 #include <asm/uaccess.h>
52897 #include <asm/page.h>
52898 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
52899 #ifdef CONFIG_USER_NS
52900 p->user_ns = file->f_cred->user_ns;
52901 #endif
52902 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
52903 + p->exec_id = current->exec_id;
52904 +#endif
52905
52906 /*
52907 * Wrappers around seq_open(e.g. swaps_open) need to be
52908 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52909 return 0;
52910 }
52911 if (!m->buf) {
52912 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52913 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52914 if (!m->buf)
52915 return -ENOMEM;
52916 }
52917 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
52918 Eoverflow:
52919 m->op->stop(m, p);
52920 kfree(m->buf);
52921 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52922 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52923 return !m->buf ? -ENOMEM : -EAGAIN;
52924 }
52925
52926 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52927
52928 /* grab buffer if we didn't have one */
52929 if (!m->buf) {
52930 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
52931 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
52932 if (!m->buf)
52933 goto Enomem;
52934 }
52935 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
52936 goto Fill;
52937 m->op->stop(m, p);
52938 kfree(m->buf);
52939 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
52940 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
52941 if (!m->buf)
52942 goto Enomem;
52943 m->count = 0;
52944 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
52945 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
52946 void *data)
52947 {
52948 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
52949 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
52950 int res = -ENOMEM;
52951
52952 if (op) {
52953 diff --git a/fs/splice.c b/fs/splice.c
52954 index 6909d89..5b2e8f9 100644
52955 --- a/fs/splice.c
52956 +++ b/fs/splice.c
52957 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52958 pipe_lock(pipe);
52959
52960 for (;;) {
52961 - if (!pipe->readers) {
52962 + if (!atomic_read(&pipe->readers)) {
52963 send_sig(SIGPIPE, current, 0);
52964 if (!ret)
52965 ret = -EPIPE;
52966 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
52967 do_wakeup = 0;
52968 }
52969
52970 - pipe->waiting_writers++;
52971 + atomic_inc(&pipe->waiting_writers);
52972 pipe_wait(pipe);
52973 - pipe->waiting_writers--;
52974 + atomic_dec(&pipe->waiting_writers);
52975 }
52976
52977 pipe_unlock(pipe);
52978 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
52979 old_fs = get_fs();
52980 set_fs(get_ds());
52981 /* The cast to a user pointer is valid due to the set_fs() */
52982 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
52983 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
52984 set_fs(old_fs);
52985
52986 return res;
52987 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
52988 old_fs = get_fs();
52989 set_fs(get_ds());
52990 /* The cast to a user pointer is valid due to the set_fs() */
52991 - res = vfs_write(file, (const char __user *)buf, count, &pos);
52992 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
52993 set_fs(old_fs);
52994
52995 return res;
52996 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
52997 goto err;
52998
52999 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
53000 - vec[i].iov_base = (void __user *) page_address(page);
53001 + vec[i].iov_base = (void __force_user *) page_address(page);
53002 vec[i].iov_len = this_len;
53003 spd.pages[i] = page;
53004 spd.nr_pages++;
53005 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
53006 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
53007 {
53008 while (!pipe->nrbufs) {
53009 - if (!pipe->writers)
53010 + if (!atomic_read(&pipe->writers))
53011 return 0;
53012
53013 - if (!pipe->waiting_writers && sd->num_spliced)
53014 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
53015 return 0;
53016
53017 if (sd->flags & SPLICE_F_NONBLOCK)
53018 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
53019 * out of the pipe right after the splice_to_pipe(). So set
53020 * PIPE_READERS appropriately.
53021 */
53022 - pipe->readers = 1;
53023 + atomic_set(&pipe->readers, 1);
53024
53025 current->splice_pipe = pipe;
53026 }
53027 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53028 ret = -ERESTARTSYS;
53029 break;
53030 }
53031 - if (!pipe->writers)
53032 + if (!atomic_read(&pipe->writers))
53033 break;
53034 - if (!pipe->waiting_writers) {
53035 + if (!atomic_read(&pipe->waiting_writers)) {
53036 if (flags & SPLICE_F_NONBLOCK) {
53037 ret = -EAGAIN;
53038 break;
53039 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53040 pipe_lock(pipe);
53041
53042 while (pipe->nrbufs >= pipe->buffers) {
53043 - if (!pipe->readers) {
53044 + if (!atomic_read(&pipe->readers)) {
53045 send_sig(SIGPIPE, current, 0);
53046 ret = -EPIPE;
53047 break;
53048 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
53049 ret = -ERESTARTSYS;
53050 break;
53051 }
53052 - pipe->waiting_writers++;
53053 + atomic_inc(&pipe->waiting_writers);
53054 pipe_wait(pipe);
53055 - pipe->waiting_writers--;
53056 + atomic_dec(&pipe->waiting_writers);
53057 }
53058
53059 pipe_unlock(pipe);
53060 @@ -1823,14 +1823,14 @@ retry:
53061 pipe_double_lock(ipipe, opipe);
53062
53063 do {
53064 - if (!opipe->readers) {
53065 + if (!atomic_read(&opipe->readers)) {
53066 send_sig(SIGPIPE, current, 0);
53067 if (!ret)
53068 ret = -EPIPE;
53069 break;
53070 }
53071
53072 - if (!ipipe->nrbufs && !ipipe->writers)
53073 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
53074 break;
53075
53076 /*
53077 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53078 pipe_double_lock(ipipe, opipe);
53079
53080 do {
53081 - if (!opipe->readers) {
53082 + if (!atomic_read(&opipe->readers)) {
53083 send_sig(SIGPIPE, current, 0);
53084 if (!ret)
53085 ret = -EPIPE;
53086 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
53087 * return EAGAIN if we have the potential of some data in the
53088 * future, otherwise just return 0
53089 */
53090 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
53091 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
53092 ret = -EAGAIN;
53093
53094 pipe_unlock(ipipe);
53095 diff --git a/fs/stat.c b/fs/stat.c
53096 index 14f4545..9b7f55b 100644
53097 --- a/fs/stat.c
53098 +++ b/fs/stat.c
53099 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
53100 stat->gid = inode->i_gid;
53101 stat->rdev = inode->i_rdev;
53102 stat->size = i_size_read(inode);
53103 - stat->atime = inode->i_atime;
53104 - stat->mtime = inode->i_mtime;
53105 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53106 + stat->atime = inode->i_ctime;
53107 + stat->mtime = inode->i_ctime;
53108 + } else {
53109 + stat->atime = inode->i_atime;
53110 + stat->mtime = inode->i_mtime;
53111 + }
53112 stat->ctime = inode->i_ctime;
53113 stat->blksize = (1 << inode->i_blkbits);
53114 stat->blocks = inode->i_blocks;
53115 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
53116 if (retval)
53117 return retval;
53118
53119 - if (inode->i_op->getattr)
53120 - return inode->i_op->getattr(mnt, dentry, stat);
53121 + if (inode->i_op->getattr) {
53122 + retval = inode->i_op->getattr(mnt, dentry, stat);
53123 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
53124 + stat->atime = stat->ctime;
53125 + stat->mtime = stat->ctime;
53126 + }
53127 + return retval;
53128 + }
53129
53130 generic_fillattr(inode, stat);
53131 return 0;
53132 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
53133 index 2fbdff6..5530a61 100644
53134 --- a/fs/sysfs/dir.c
53135 +++ b/fs/sysfs/dir.c
53136 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
53137 struct sysfs_dirent *sd;
53138 int rc;
53139
53140 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
53141 + const char *parent_name = parent_sd->s_name;
53142 +
53143 + mode = S_IFDIR | S_IRWXU;
53144 +
53145 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
53146 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
53147 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
53148 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
53149 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
53150 +#endif
53151 +
53152 /* allocate */
53153 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
53154 if (!sd)
53155 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
53156 index 602f56d..6853db8 100644
53157 --- a/fs/sysfs/file.c
53158 +++ b/fs/sysfs/file.c
53159 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
53160
53161 struct sysfs_open_dirent {
53162 atomic_t refcnt;
53163 - atomic_t event;
53164 + atomic_unchecked_t event;
53165 wait_queue_head_t poll;
53166 struct list_head buffers; /* goes through sysfs_buffer.list */
53167 };
53168 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
53169 if (!sysfs_get_active(attr_sd))
53170 return -ENODEV;
53171
53172 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
53173 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
53174 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
53175
53176 sysfs_put_active(attr_sd);
53177 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
53178 return -ENOMEM;
53179
53180 atomic_set(&new_od->refcnt, 0);
53181 - atomic_set(&new_od->event, 1);
53182 + atomic_set_unchecked(&new_od->event, 1);
53183 init_waitqueue_head(&new_od->poll);
53184 INIT_LIST_HEAD(&new_od->buffers);
53185 goto retry;
53186 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
53187
53188 sysfs_put_active(attr_sd);
53189
53190 - if (buffer->event != atomic_read(&od->event))
53191 + if (buffer->event != atomic_read_unchecked(&od->event))
53192 goto trigger;
53193
53194 return DEFAULT_POLLMASK;
53195 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
53196
53197 od = sd->s_attr.open;
53198 if (od) {
53199 - atomic_inc(&od->event);
53200 + atomic_inc_unchecked(&od->event);
53201 wake_up_interruptible(&od->poll);
53202 }
53203
53204 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
53205 index 3c9eb56..9dea5be 100644
53206 --- a/fs/sysfs/symlink.c
53207 +++ b/fs/sysfs/symlink.c
53208 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
53209
53210 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
53211 {
53212 - char *page = nd_get_link(nd);
53213 + const char *page = nd_get_link(nd);
53214 if (!IS_ERR(page))
53215 free_page((unsigned long)page);
53216 }
53217 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
53218 index c175b4d..8f36a16 100644
53219 --- a/fs/udf/misc.c
53220 +++ b/fs/udf/misc.c
53221 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
53222
53223 u8 udf_tag_checksum(const struct tag *t)
53224 {
53225 - u8 *data = (u8 *)t;
53226 + const u8 *data = (const u8 *)t;
53227 u8 checksum = 0;
53228 int i;
53229 for (i = 0; i < sizeof(struct tag); ++i)
53230 diff --git a/fs/utimes.c b/fs/utimes.c
53231 index f4fb7ec..3fe03c0 100644
53232 --- a/fs/utimes.c
53233 +++ b/fs/utimes.c
53234 @@ -1,6 +1,7 @@
53235 #include <linux/compiler.h>
53236 #include <linux/file.h>
53237 #include <linux/fs.h>
53238 +#include <linux/security.h>
53239 #include <linux/linkage.h>
53240 #include <linux/mount.h>
53241 #include <linux/namei.h>
53242 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
53243 goto mnt_drop_write_and_out;
53244 }
53245 }
53246 +
53247 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
53248 + error = -EACCES;
53249 + goto mnt_drop_write_and_out;
53250 + }
53251 +
53252 mutex_lock(&inode->i_mutex);
53253 error = notify_change(path->dentry, &newattrs);
53254 mutex_unlock(&inode->i_mutex);
53255 diff --git a/fs/xattr.c b/fs/xattr.c
53256 index 3377dff..4feded6 100644
53257 --- a/fs/xattr.c
53258 +++ b/fs/xattr.c
53259 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
53260 * Extended attribute SET operations
53261 */
53262 static long
53263 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
53264 +setxattr(struct path *path, const char __user *name, const void __user *value,
53265 size_t size, int flags)
53266 {
53267 int error;
53268 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
53269 posix_acl_fix_xattr_from_user(kvalue, size);
53270 }
53271
53272 - error = vfs_setxattr(d, kname, kvalue, size, flags);
53273 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
53274 + error = -EACCES;
53275 + goto out;
53276 + }
53277 +
53278 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
53279 out:
53280 if (vvalue)
53281 vfree(vvalue);
53282 @@ -377,7 +382,7 @@ retry:
53283 return error;
53284 error = mnt_want_write(path.mnt);
53285 if (!error) {
53286 - error = setxattr(path.dentry, name, value, size, flags);
53287 + error = setxattr(&path, name, value, size, flags);
53288 mnt_drop_write(path.mnt);
53289 }
53290 path_put(&path);
53291 @@ -401,7 +406,7 @@ retry:
53292 return error;
53293 error = mnt_want_write(path.mnt);
53294 if (!error) {
53295 - error = setxattr(path.dentry, name, value, size, flags);
53296 + error = setxattr(&path, name, value, size, flags);
53297 mnt_drop_write(path.mnt);
53298 }
53299 path_put(&path);
53300 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
53301 const void __user *,value, size_t, size, int, flags)
53302 {
53303 struct fd f = fdget(fd);
53304 - struct dentry *dentry;
53305 int error = -EBADF;
53306
53307 if (!f.file)
53308 return error;
53309 - dentry = f.file->f_path.dentry;
53310 - audit_inode(NULL, dentry, 0);
53311 + audit_inode(NULL, f.file->f_path.dentry, 0);
53312 error = mnt_want_write_file(f.file);
53313 if (!error) {
53314 - error = setxattr(dentry, name, value, size, flags);
53315 + error = setxattr(&f.file->f_path, name, value, size, flags);
53316 mnt_drop_write_file(f.file);
53317 }
53318 fdput(f);
53319 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
53320 index 9fbea87..6b19972 100644
53321 --- a/fs/xattr_acl.c
53322 +++ b/fs/xattr_acl.c
53323 @@ -76,8 +76,8 @@ struct posix_acl *
53324 posix_acl_from_xattr(struct user_namespace *user_ns,
53325 const void *value, size_t size)
53326 {
53327 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
53328 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
53329 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
53330 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
53331 int count;
53332 struct posix_acl *acl;
53333 struct posix_acl_entry *acl_e;
53334 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
53335 index cdb2d33..704ce7f 100644
53336 --- a/fs/xfs/xfs_bmap.c
53337 +++ b/fs/xfs/xfs_bmap.c
53338 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
53339 int nmap,
53340 int ret_nmap);
53341 #else
53342 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
53343 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
53344 #endif /* DEBUG */
53345
53346 STATIC int
53347 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
53348 index 1b9fc3e..e1bdde0 100644
53349 --- a/fs/xfs/xfs_dir2_sf.c
53350 +++ b/fs/xfs/xfs_dir2_sf.c
53351 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
53352 }
53353
53354 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
53355 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53356 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
53357 + char name[sfep->namelen];
53358 + memcpy(name, sfep->name, sfep->namelen);
53359 + if (filldir(dirent, name, sfep->namelen,
53360 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
53361 + *offset = off & 0x7fffffff;
53362 + return 0;
53363 + }
53364 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
53365 off & 0x7fffffff, ino, DT_UNKNOWN)) {
53366 *offset = off & 0x7fffffff;
53367 return 0;
53368 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
53369 index c1c3ef8..0952438 100644
53370 --- a/fs/xfs/xfs_ioctl.c
53371 +++ b/fs/xfs/xfs_ioctl.c
53372 @@ -127,7 +127,7 @@ xfs_find_handle(
53373 }
53374
53375 error = -EFAULT;
53376 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
53377 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
53378 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
53379 goto out_put;
53380
53381 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
53382 index d82efaa..0904a8e 100644
53383 --- a/fs/xfs/xfs_iops.c
53384 +++ b/fs/xfs/xfs_iops.c
53385 @@ -395,7 +395,7 @@ xfs_vn_put_link(
53386 struct nameidata *nd,
53387 void *p)
53388 {
53389 - char *s = nd_get_link(nd);
53390 + const char *s = nd_get_link(nd);
53391
53392 if (!IS_ERR(s))
53393 kfree(s);
53394 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
53395 new file mode 100644
53396 index 0000000..92247e4
53397 --- /dev/null
53398 +++ b/grsecurity/Kconfig
53399 @@ -0,0 +1,1021 @@
53400 +#
53401 +# grecurity configuration
53402 +#
53403 +menu "Memory Protections"
53404 +depends on GRKERNSEC
53405 +
53406 +config GRKERNSEC_KMEM
53407 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
53408 + default y if GRKERNSEC_CONFIG_AUTO
53409 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
53410 + help
53411 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
53412 + be written to or read from to modify or leak the contents of the running
53413 + kernel. /dev/port will also not be allowed to be opened and support
53414 + for /dev/cpu/*/msr will be removed. If you have module
53415 + support disabled, enabling this will close up five ways that are
53416 + currently used to insert malicious code into the running kernel.
53417 +
53418 + Even with all these features enabled, we still highly recommend that
53419 + you use the RBAC system, as it is still possible for an attacker to
53420 + modify the running kernel through privileged I/O granted by ioperm/iopl.
53421 +
53422 + If you are not using XFree86, you may be able to stop this additional
53423 + case by enabling the 'Disable privileged I/O' option. Though nothing
53424 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
53425 + but only to video memory, which is the only writing we allow in this
53426 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
53427 + not be allowed to mprotect it with PROT_WRITE later.
53428 + Enabling this feature will prevent the "cpupower" and "powertop" tools
53429 + from working.
53430 +
53431 + It is highly recommended that you say Y here if you meet all the
53432 + conditions above.
53433 +
53434 +config GRKERNSEC_VM86
53435 + bool "Restrict VM86 mode"
53436 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53437 + depends on X86_32
53438 +
53439 + help
53440 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
53441 + make use of a special execution mode on 32bit x86 processors called
53442 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
53443 + video cards and will still work with this option enabled. The purpose
53444 + of the option is to prevent exploitation of emulation errors in
53445 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
53446 + Nearly all users should be able to enable this option.
53447 +
53448 +config GRKERNSEC_IO
53449 + bool "Disable privileged I/O"
53450 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53451 + depends on X86
53452 + select RTC_CLASS
53453 + select RTC_INTF_DEV
53454 + select RTC_DRV_CMOS
53455 +
53456 + help
53457 + If you say Y here, all ioperm and iopl calls will return an error.
53458 + Ioperm and iopl can be used to modify the running kernel.
53459 + Unfortunately, some programs need this access to operate properly,
53460 + the most notable of which are XFree86 and hwclock. hwclock can be
53461 + remedied by having RTC support in the kernel, so real-time
53462 + clock support is enabled if this option is enabled, to ensure
53463 + that hwclock operates correctly. XFree86 still will not
53464 + operate correctly with this option enabled, so DO NOT CHOOSE Y
53465 + IF YOU USE XFree86. If you use XFree86 and you still want to
53466 + protect your kernel against modification, use the RBAC system.
53467 +
53468 +config GRKERNSEC_JIT_HARDEN
53469 + bool "Harden BPF JIT against spray attacks"
53470 + default y if GRKERNSEC_CONFIG_AUTO
53471 + depends on BPF_JIT
53472 + help
53473 + If you say Y here, the native code generated by the kernel's Berkeley
53474 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
53475 + attacks that attempt to fit attacker-beneficial instructions in
53476 + 32bit immediate fields of JIT-generated native instructions. The
53477 + attacker will generally aim to cause an unintended instruction sequence
53478 + of JIT-generated native code to execute by jumping into the middle of
53479 + a generated instruction. This feature effectively randomizes the 32bit
53480 + immediate constants present in the generated code to thwart such attacks.
53481 +
53482 + If you're using KERNEXEC, it's recommended that you enable this option
53483 + to supplement the hardening of the kernel.
53484 +
53485 +config GRKERNSEC_RAND_THREADSTACK
53486 + bool "Insert random gaps between thread stacks"
53487 + default y if GRKERNSEC_CONFIG_AUTO
53488 + depends on PAX_RANDMMAP && !PPC
53489 + help
53490 + If you say Y here, a random-sized gap will be enforced between allocated
53491 + thread stacks. Glibc's NPTL and other threading libraries that
53492 + pass MAP_STACK to the kernel for thread stack allocation are supported.
53493 + The implementation currently provides 8 bits of entropy for the gap.
53494 +
53495 + Many distributions do not compile threaded remote services with the
53496 + -fstack-check argument to GCC, causing the variable-sized stack-based
53497 + allocator, alloca(), to not probe the stack on allocation. This
53498 + permits an unbounded alloca() to skip over any guard page and potentially
53499 + modify another thread's stack reliably. An enforced random gap
53500 + reduces the reliability of such an attack and increases the chance
53501 + that such a read/write to another thread's stack instead lands in
53502 + an unmapped area, causing a crash and triggering grsecurity's
53503 + anti-bruteforcing logic.
53504 +
53505 +config GRKERNSEC_PROC_MEMMAP
53506 + bool "Harden ASLR against information leaks and entropy reduction"
53507 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
53508 + depends on PAX_NOEXEC || PAX_ASLR
53509 + help
53510 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
53511 + give no information about the addresses of its mappings if
53512 + PaX features that rely on random addresses are enabled on the task.
53513 + In addition to sanitizing this information and disabling other
53514 + dangerous sources of information, this option causes reads of sensitive
53515 + /proc/<pid> entries where the file descriptor was opened in a different
53516 + task than the one performing the read. Such attempts are logged.
53517 + This option also limits argv/env strings for suid/sgid binaries
53518 + to 512KB to prevent a complete exhaustion of the stack entropy provided
53519 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
53520 + binaries to prevent alternative mmap layouts from being abused.
53521 +
53522 + If you use PaX it is essential that you say Y here as it closes up
53523 + several holes that make full ASLR useless locally.
53524 +
53525 +config GRKERNSEC_BRUTE
53526 + bool "Deter exploit bruteforcing"
53527 + default y if GRKERNSEC_CONFIG_AUTO
53528 + help
53529 + If you say Y here, attempts to bruteforce exploits against forking
53530 + daemons such as apache or sshd, as well as against suid/sgid binaries
53531 + will be deterred. When a child of a forking daemon is killed by PaX
53532 + or crashes due to an illegal instruction or other suspicious signal,
53533 + the parent process will be delayed 30 seconds upon every subsequent
53534 + fork until the administrator is able to assess the situation and
53535 + restart the daemon.
53536 + In the suid/sgid case, the attempt is logged, the user has all their
53537 + processes terminated, and they are prevented from executing any further
53538 + processes for 15 minutes.
53539 + It is recommended that you also enable signal logging in the auditing
53540 + section so that logs are generated when a process triggers a suspicious
53541 + signal.
53542 + If the sysctl option is enabled, a sysctl option with name
53543 + "deter_bruteforce" is created.
53544 +
53545 +
53546 +config GRKERNSEC_MODHARDEN
53547 + bool "Harden module auto-loading"
53548 + default y if GRKERNSEC_CONFIG_AUTO
53549 + depends on MODULES
53550 + help
53551 + If you say Y here, module auto-loading in response to use of some
53552 + feature implemented by an unloaded module will be restricted to
53553 + root users. Enabling this option helps defend against attacks
53554 + by unprivileged users who abuse the auto-loading behavior to
53555 + cause a vulnerable module to load that is then exploited.
53556 +
53557 + If this option prevents a legitimate use of auto-loading for a
53558 + non-root user, the administrator can execute modprobe manually
53559 + with the exact name of the module mentioned in the alert log.
53560 + Alternatively, the administrator can add the module to the list
53561 + of modules loaded at boot by modifying init scripts.
53562 +
53563 + Modification of init scripts will most likely be needed on
53564 + Ubuntu servers with encrypted home directory support enabled,
53565 + as the first non-root user logging in will cause the ecb(aes),
53566 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
53567 +
53568 +config GRKERNSEC_HIDESYM
53569 + bool "Hide kernel symbols"
53570 + default y if GRKERNSEC_CONFIG_AUTO
53571 + select PAX_USERCOPY_SLABS
53572 + help
53573 + If you say Y here, getting information on loaded modules, and
53574 + displaying all kernel symbols through a syscall will be restricted
53575 + to users with CAP_SYS_MODULE. For software compatibility reasons,
53576 + /proc/kallsyms will be restricted to the root user. The RBAC
53577 + system can hide that entry even from root.
53578 +
53579 + This option also prevents leaking of kernel addresses through
53580 + several /proc entries.
53581 +
53582 + Note that this option is only effective provided the following
53583 + conditions are met:
53584 + 1) The kernel using grsecurity is not precompiled by some distribution
53585 + 2) You have also enabled GRKERNSEC_DMESG
53586 + 3) You are using the RBAC system and hiding other files such as your
53587 + kernel image and System.map. Alternatively, enabling this option
53588 + causes the permissions on /boot, /lib/modules, and the kernel
53589 + source directory to change at compile time to prevent
53590 + reading by non-root users.
53591 + If the above conditions are met, this option will aid in providing a
53592 + useful protection against local kernel exploitation of overflows
53593 + and arbitrary read/write vulnerabilities.
53594 +
53595 +config GRKERNSEC_KERN_LOCKOUT
53596 + bool "Active kernel exploit response"
53597 + default y if GRKERNSEC_CONFIG_AUTO
53598 + depends on X86 || ARM || PPC || SPARC
53599 + help
53600 + If you say Y here, when a PaX alert is triggered due to suspicious
53601 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
53602 + or an OOPS occurs due to bad memory accesses, instead of just
53603 + terminating the offending process (and potentially allowing
53604 + a subsequent exploit from the same user), we will take one of two
53605 + actions:
53606 + If the user was root, we will panic the system
53607 + If the user was non-root, we will log the attempt, terminate
53608 + all processes owned by the user, then prevent them from creating
53609 + any new processes until the system is restarted
53610 + This deters repeated kernel exploitation/bruteforcing attempts
53611 + and is useful for later forensics.
53612 +
53613 +endmenu
53614 +menu "Role Based Access Control Options"
53615 +depends on GRKERNSEC
53616 +
53617 +config GRKERNSEC_RBAC_DEBUG
53618 + bool
53619 +
53620 +config GRKERNSEC_NO_RBAC
53621 + bool "Disable RBAC system"
53622 + help
53623 + If you say Y here, the /dev/grsec device will be removed from the kernel,
53624 + preventing the RBAC system from being enabled. You should only say Y
53625 + here if you have no intention of using the RBAC system, so as to prevent
53626 + an attacker with root access from misusing the RBAC system to hide files
53627 + and processes when loadable module support and /dev/[k]mem have been
53628 + locked down.
53629 +
53630 +config GRKERNSEC_ACL_HIDEKERN
53631 + bool "Hide kernel processes"
53632 + help
53633 + If you say Y here, all kernel threads will be hidden to all
53634 + processes but those whose subject has the "view hidden processes"
53635 + flag.
53636 +
53637 +config GRKERNSEC_ACL_MAXTRIES
53638 + int "Maximum tries before password lockout"
53639 + default 3
53640 + help
53641 + This option enforces the maximum number of times a user can attempt
53642 + to authorize themselves with the grsecurity RBAC system before being
53643 + denied the ability to attempt authorization again for a specified time.
53644 + The lower the number, the harder it will be to brute-force a password.
53645 +
53646 +config GRKERNSEC_ACL_TIMEOUT
53647 + int "Time to wait after max password tries, in seconds"
53648 + default 30
53649 + help
53650 + This option specifies the time the user must wait after attempting to
53651 + authorize to the RBAC system with the maximum number of invalid
53652 + passwords. The higher the number, the harder it will be to brute-force
53653 + a password.
53654 +
53655 +endmenu
53656 +menu "Filesystem Protections"
53657 +depends on GRKERNSEC
53658 +
53659 +config GRKERNSEC_PROC
53660 + bool "Proc restrictions"
53661 + default y if GRKERNSEC_CONFIG_AUTO
53662 + help
53663 + If you say Y here, the permissions of the /proc filesystem
53664 + will be altered to enhance system security and privacy. You MUST
53665 + choose either a user only restriction or a user and group restriction.
53666 + Depending upon the option you choose, you can either restrict users to
53667 + see only the processes they themselves run, or choose a group that can
53668 + view all processes and files normally restricted to root if you choose
53669 + the "restrict to user only" option. NOTE: If you're running identd or
53670 + ntpd as a non-root user, you will have to run it as the group you
53671 + specify here.
53672 +
53673 +config GRKERNSEC_PROC_USER
53674 + bool "Restrict /proc to user only"
53675 + depends on GRKERNSEC_PROC
53676 + help
53677 + If you say Y here, non-root users will only be able to view their own
53678 + processes, and restricts them from viewing network-related information,
53679 + and viewing kernel symbol and module information.
53680 +
53681 +config GRKERNSEC_PROC_USERGROUP
53682 + bool "Allow special group"
53683 + default y if GRKERNSEC_CONFIG_AUTO
53684 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
53685 + help
53686 + If you say Y here, you will be able to select a group that will be
53687 + able to view all processes and network-related information. If you've
53688 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
53689 + remain hidden. This option is useful if you want to run identd as
53690 + a non-root user. The group you select may also be chosen at boot time
53691 + via "grsec_proc_gid=" on the kernel commandline.
53692 +
53693 +config GRKERNSEC_PROC_GID
53694 + int "GID for special group"
53695 + depends on GRKERNSEC_PROC_USERGROUP
53696 + default 1001
53697 +
53698 +config GRKERNSEC_PROC_ADD
53699 + bool "Additional restrictions"
53700 + default y if GRKERNSEC_CONFIG_AUTO
53701 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
53702 + help
53703 + If you say Y here, additional restrictions will be placed on
53704 + /proc that keep normal users from viewing device information and
53705 + slabinfo information that could be useful for exploits.
53706 +
53707 +config GRKERNSEC_LINK
53708 + bool "Linking restrictions"
53709 + default y if GRKERNSEC_CONFIG_AUTO
53710 + help
53711 + If you say Y here, /tmp race exploits will be prevented, since users
53712 + will no longer be able to follow symlinks owned by other users in
53713 + world-writable +t directories (e.g. /tmp), unless the owner of the
53714 + symlink is the owner of the directory. users will also not be
53715 + able to hardlink to files they do not own. If the sysctl option is
53716 + enabled, a sysctl option with name "linking_restrictions" is created.
53717 +
53718 +config GRKERNSEC_SYMLINKOWN
53719 + bool "Kernel-enforced SymlinksIfOwnerMatch"
53720 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
53721 + help
53722 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
53723 + that prevents it from being used as a security feature. As Apache
53724 + verifies the symlink by performing a stat() against the target of
53725 + the symlink before it is followed, an attacker can setup a symlink
53726 + to point to a same-owned file, then replace the symlink with one
53727 + that targets another user's file just after Apache "validates" the
53728 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
53729 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
53730 + will be in place for the group you specify. If the sysctl option
53731 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
53732 + created.
53733 +
53734 +config GRKERNSEC_SYMLINKOWN_GID
53735 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
53736 + depends on GRKERNSEC_SYMLINKOWN
53737 + default 1006
53738 + help
53739 + Setting this GID determines what group kernel-enforced
53740 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
53741 + is enabled, a sysctl option with name "symlinkown_gid" is created.
53742 +
53743 +config GRKERNSEC_FIFO
53744 + bool "FIFO restrictions"
53745 + default y if GRKERNSEC_CONFIG_AUTO
53746 + help
53747 + If you say Y here, users will not be able to write to FIFOs they don't
53748 + own in world-writable +t directories (e.g. /tmp), unless the owner of
53749 + the FIFO is the same owner of the directory it's held in. If the sysctl
53750 + option is enabled, a sysctl option with name "fifo_restrictions" is
53751 + created.
53752 +
53753 +config GRKERNSEC_SYSFS_RESTRICT
53754 + bool "Sysfs/debugfs restriction"
53755 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
53756 + depends on SYSFS
53757 + help
53758 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
53759 + any filesystem normally mounted under it (e.g. debugfs) will be
53760 + mostly accessible only by root. These filesystems generally provide access
53761 + to hardware and debug information that isn't appropriate for unprivileged
53762 + users of the system. Sysfs and debugfs have also become a large source
53763 + of new vulnerabilities, ranging from infoleaks to local compromise.
53764 + There has been very little oversight with an eye toward security involved
53765 + in adding new exporters of information to these filesystems, so their
53766 + use is discouraged.
53767 + For reasons of compatibility, a few directories have been whitelisted
53768 + for access by non-root users:
53769 + /sys/fs/selinux
53770 + /sys/fs/fuse
53771 + /sys/devices/system/cpu
53772 +
53773 +config GRKERNSEC_ROFS
53774 + bool "Runtime read-only mount protection"
53775 + help
53776 + If you say Y here, a sysctl option with name "romount_protect" will
53777 + be created. By setting this option to 1 at runtime, filesystems
53778 + will be protected in the following ways:
53779 + * No new writable mounts will be allowed
53780 + * Existing read-only mounts won't be able to be remounted read/write
53781 + * Write operations will be denied on all block devices
53782 + This option acts independently of grsec_lock: once it is set to 1,
53783 + it cannot be turned off. Therefore, please be mindful of the resulting
53784 + behavior if this option is enabled in an init script on a read-only
53785 + filesystem. This feature is mainly intended for secure embedded systems.
53786 +
53787 +config GRKERNSEC_DEVICE_SIDECHANNEL
53788 + bool "Eliminate stat/notify-based device sidechannels"
53789 + default y if GRKERNSEC_CONFIG_AUTO
53790 + help
53791 + If you say Y here, timing analyses on block or character
53792 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
53793 + will be thwarted for unprivileged users. If a process without
53794 + CAP_MKNOD stats such a device, the last access and last modify times
53795 + will match the device's create time. No access or modify events
53796 + will be triggered through inotify/dnotify/fanotify for such devices.
53797 + This feature will prevent attacks that may at a minimum
53798 + allow an attacker to determine the administrator's password length.
53799 +
53800 +config GRKERNSEC_CHROOT
53801 + bool "Chroot jail restrictions"
53802 + default y if GRKERNSEC_CONFIG_AUTO
53803 + help
53804 + If you say Y here, you will be able to choose several options that will
53805 + make breaking out of a chrooted jail much more difficult. If you
53806 + encounter no software incompatibilities with the following options, it
53807 + is recommended that you enable each one.
53808 +
53809 +config GRKERNSEC_CHROOT_MOUNT
53810 + bool "Deny mounts"
53811 + default y if GRKERNSEC_CONFIG_AUTO
53812 + depends on GRKERNSEC_CHROOT
53813 + help
53814 + If you say Y here, processes inside a chroot will not be able to
53815 + mount or remount filesystems. If the sysctl option is enabled, a
53816 + sysctl option with name "chroot_deny_mount" is created.
53817 +
53818 +config GRKERNSEC_CHROOT_DOUBLE
53819 + bool "Deny double-chroots"
53820 + default y if GRKERNSEC_CONFIG_AUTO
53821 + depends on GRKERNSEC_CHROOT
53822 + help
53823 + If you say Y here, processes inside a chroot will not be able to chroot
53824 + again outside the chroot. This is a widely used method of breaking
53825 + out of a chroot jail and should not be allowed. If the sysctl
53826 + option is enabled, a sysctl option with name
53827 + "chroot_deny_chroot" is created.
53828 +
53829 +config GRKERNSEC_CHROOT_PIVOT
53830 + bool "Deny pivot_root in chroot"
53831 + default y if GRKERNSEC_CONFIG_AUTO
53832 + depends on GRKERNSEC_CHROOT
53833 + help
53834 + If you say Y here, processes inside a chroot will not be able to use
53835 + a function called pivot_root() that was introduced in Linux 2.3.41. It
53836 + works similar to chroot in that it changes the root filesystem. This
53837 + function could be misused in a chrooted process to attempt to break out
53838 + of the chroot, and therefore should not be allowed. If the sysctl
53839 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
53840 + created.
53841 +
53842 +config GRKERNSEC_CHROOT_CHDIR
53843 + bool "Enforce chdir(\"/\") on all chroots"
53844 + default y if GRKERNSEC_CONFIG_AUTO
53845 + depends on GRKERNSEC_CHROOT
53846 + help
53847 + If you say Y here, the current working directory of all newly-chrooted
53848 + applications will be set to the the root directory of the chroot.
53849 + The man page on chroot(2) states:
53850 + Note that this call does not change the current working
53851 + directory, so that `.' can be outside the tree rooted at
53852 + `/'. In particular, the super-user can escape from a
53853 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
53854 +
53855 + It is recommended that you say Y here, since it's not known to break
53856 + any software. If the sysctl option is enabled, a sysctl option with
53857 + name "chroot_enforce_chdir" is created.
53858 +
53859 +config GRKERNSEC_CHROOT_CHMOD
53860 + bool "Deny (f)chmod +s"
53861 + default y if GRKERNSEC_CONFIG_AUTO
53862 + depends on GRKERNSEC_CHROOT
53863 + help
53864 + If you say Y here, processes inside a chroot will not be able to chmod
53865 + or fchmod files to make them have suid or sgid bits. This protects
53866 + against another published method of breaking a chroot. If the sysctl
53867 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
53868 + created.
53869 +
53870 +config GRKERNSEC_CHROOT_FCHDIR
53871 + bool "Deny fchdir out of chroot"
53872 + default y if GRKERNSEC_CONFIG_AUTO
53873 + depends on GRKERNSEC_CHROOT
53874 + help
53875 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
53876 + to a file descriptor of the chrooting process that points to a directory
53877 + outside the filesystem will be stopped. If the sysctl option
53878 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
53879 +
53880 +config GRKERNSEC_CHROOT_MKNOD
53881 + bool "Deny mknod"
53882 + default y if GRKERNSEC_CONFIG_AUTO
53883 + depends on GRKERNSEC_CHROOT
53884 + help
53885 + If you say Y here, processes inside a chroot will not be allowed to
53886 + mknod. The problem with using mknod inside a chroot is that it
53887 + would allow an attacker to create a device entry that is the same
53888 + as one on the physical root of your system, which could range from
53889 + anything from the console device to a device for your harddrive (which
53890 + they could then use to wipe the drive or steal data). It is recommended
53891 + that you say Y here, unless you run into software incompatibilities.
53892 + If the sysctl option is enabled, a sysctl option with name
53893 + "chroot_deny_mknod" is created.
53894 +
53895 +config GRKERNSEC_CHROOT_SHMAT
53896 + bool "Deny shmat() out of chroot"
53897 + default y if GRKERNSEC_CONFIG_AUTO
53898 + depends on GRKERNSEC_CHROOT
53899 + help
53900 + If you say Y here, processes inside a chroot will not be able to attach
53901 + to shared memory segments that were created outside of the chroot jail.
53902 + It is recommended that you say Y here. If the sysctl option is enabled,
53903 + a sysctl option with name "chroot_deny_shmat" is created.
53904 +
53905 +config GRKERNSEC_CHROOT_UNIX
53906 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
53907 + default y if GRKERNSEC_CONFIG_AUTO
53908 + depends on GRKERNSEC_CHROOT
53909 + help
53910 + If you say Y here, processes inside a chroot will not be able to
53911 + connect to abstract (meaning not belonging to a filesystem) Unix
53912 + domain sockets that were bound outside of a chroot. It is recommended
53913 + that you say Y here. If the sysctl option is enabled, a sysctl option
53914 + with name "chroot_deny_unix" is created.
53915 +
53916 +config GRKERNSEC_CHROOT_FINDTASK
53917 + bool "Protect outside processes"
53918 + default y if GRKERNSEC_CONFIG_AUTO
53919 + depends on GRKERNSEC_CHROOT
53920 + help
53921 + If you say Y here, processes inside a chroot will not be able to
53922 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
53923 + getsid, or view any process outside of the chroot. If the sysctl
53924 + option is enabled, a sysctl option with name "chroot_findtask" is
53925 + created.
53926 +
53927 +config GRKERNSEC_CHROOT_NICE
53928 + bool "Restrict priority changes"
53929 + default y if GRKERNSEC_CONFIG_AUTO
53930 + depends on GRKERNSEC_CHROOT
53931 + help
53932 + If you say Y here, processes inside a chroot will not be able to raise
53933 + the priority of processes in the chroot, or alter the priority of
53934 + processes outside the chroot. This provides more security than simply
53935 + removing CAP_SYS_NICE from the process' capability set. If the
53936 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
53937 + is created.
53938 +
53939 +config GRKERNSEC_CHROOT_SYSCTL
53940 + bool "Deny sysctl writes"
53941 + default y if GRKERNSEC_CONFIG_AUTO
53942 + depends on GRKERNSEC_CHROOT
53943 + help
53944 + If you say Y here, an attacker in a chroot will not be able to
53945 + write to sysctl entries, either by sysctl(2) or through a /proc
53946 + interface. It is strongly recommended that you say Y here. If the
53947 + sysctl option is enabled, a sysctl option with name
53948 + "chroot_deny_sysctl" is created.
53949 +
53950 +config GRKERNSEC_CHROOT_CAPS
53951 + bool "Capability restrictions"
53952 + default y if GRKERNSEC_CONFIG_AUTO
53953 + depends on GRKERNSEC_CHROOT
53954 + help
53955 + If you say Y here, the capabilities on all processes within a
53956 + chroot jail will be lowered to stop module insertion, raw i/o,
53957 + system and net admin tasks, rebooting the system, modifying immutable
53958 + files, modifying IPC owned by another, and changing the system time.
53959 + This is left an option because it can break some apps. Disable this
53960 + if your chrooted apps are having problems performing those kinds of
53961 + tasks. If the sysctl option is enabled, a sysctl option with
53962 + name "chroot_caps" is created.
53963 +
53964 +endmenu
53965 +menu "Kernel Auditing"
53966 +depends on GRKERNSEC
53967 +
53968 +config GRKERNSEC_AUDIT_GROUP
53969 + bool "Single group for auditing"
53970 + help
53971 + If you say Y here, the exec and chdir logging features will only operate
53972 + on a group you specify. This option is recommended if you only want to
53973 + watch certain users instead of having a large amount of logs from the
53974 + entire system. If the sysctl option is enabled, a sysctl option with
53975 + name "audit_group" is created.
53976 +
53977 +config GRKERNSEC_AUDIT_GID
53978 + int "GID for auditing"
53979 + depends on GRKERNSEC_AUDIT_GROUP
53980 + default 1007
53981 +
53982 +config GRKERNSEC_EXECLOG
53983 + bool "Exec logging"
53984 + help
53985 + If you say Y here, all execve() calls will be logged (since the
53986 + other exec*() calls are frontends to execve(), all execution
53987 + will be logged). Useful for shell-servers that like to keep track
53988 + of their users. If the sysctl option is enabled, a sysctl option with
53989 + name "exec_logging" is created.
53990 + WARNING: This option when enabled will produce a LOT of logs, especially
53991 + on an active system.
53992 +
53993 +config GRKERNSEC_RESLOG
53994 + bool "Resource logging"
53995 + default y if GRKERNSEC_CONFIG_AUTO
53996 + help
53997 + If you say Y here, all attempts to overstep resource limits will
53998 + be logged with the resource name, the requested size, and the current
53999 + limit. It is highly recommended that you say Y here. If the sysctl
54000 + option is enabled, a sysctl option with name "resource_logging" is
54001 + created. If the RBAC system is enabled, the sysctl value is ignored.
54002 +
54003 +config GRKERNSEC_CHROOT_EXECLOG
54004 + bool "Log execs within chroot"
54005 + help
54006 + If you say Y here, all executions inside a chroot jail will be logged
54007 + to syslog. This can cause a large amount of logs if certain
54008 + applications (eg. djb's daemontools) are installed on the system, and
54009 + is therefore left as an option. If the sysctl option is enabled, a
54010 + sysctl option with name "chroot_execlog" is created.
54011 +
54012 +config GRKERNSEC_AUDIT_PTRACE
54013 + bool "Ptrace logging"
54014 + help
54015 + If you say Y here, all attempts to attach to a process via ptrace
54016 + will be logged. If the sysctl option is enabled, a sysctl option
54017 + with name "audit_ptrace" is created.
54018 +
54019 +config GRKERNSEC_AUDIT_CHDIR
54020 + bool "Chdir logging"
54021 + help
54022 + If you say Y here, all chdir() calls will be logged. If the sysctl
54023 + option is enabled, a sysctl option with name "audit_chdir" is created.
54024 +
54025 +config GRKERNSEC_AUDIT_MOUNT
54026 + bool "(Un)Mount logging"
54027 + help
54028 + If you say Y here, all mounts and unmounts will be logged. If the
54029 + sysctl option is enabled, a sysctl option with name "audit_mount" is
54030 + created.
54031 +
54032 +config GRKERNSEC_SIGNAL
54033 + bool "Signal logging"
54034 + default y if GRKERNSEC_CONFIG_AUTO
54035 + help
54036 + If you say Y here, certain important signals will be logged, such as
54037 + SIGSEGV, which will as a result inform you of when a error in a program
54038 + occurred, which in some cases could mean a possible exploit attempt.
54039 + If the sysctl option is enabled, a sysctl option with name
54040 + "signal_logging" is created.
54041 +
54042 +config GRKERNSEC_FORKFAIL
54043 + bool "Fork failure logging"
54044 + help
54045 + If you say Y here, all failed fork() attempts will be logged.
54046 + This could suggest a fork bomb, or someone attempting to overstep
54047 + their process limit. If the sysctl option is enabled, a sysctl option
54048 + with name "forkfail_logging" is created.
54049 +
54050 +config GRKERNSEC_TIME
54051 + bool "Time change logging"
54052 + default y if GRKERNSEC_CONFIG_AUTO
54053 + help
54054 + If you say Y here, any changes of the system clock will be logged.
54055 + If the sysctl option is enabled, a sysctl option with name
54056 + "timechange_logging" is created.
54057 +
54058 +config GRKERNSEC_PROC_IPADDR
54059 + bool "/proc/<pid>/ipaddr support"
54060 + default y if GRKERNSEC_CONFIG_AUTO
54061 + help
54062 + If you say Y here, a new entry will be added to each /proc/<pid>
54063 + directory that contains the IP address of the person using the task.
54064 + The IP is carried across local TCP and AF_UNIX stream sockets.
54065 + This information can be useful for IDS/IPSes to perform remote response
54066 + to a local attack. The entry is readable by only the owner of the
54067 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
54068 + the RBAC system), and thus does not create privacy concerns.
54069 +
54070 +config GRKERNSEC_RWXMAP_LOG
54071 + bool 'Denied RWX mmap/mprotect logging'
54072 + default y if GRKERNSEC_CONFIG_AUTO
54073 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
54074 + help
54075 + If you say Y here, calls to mmap() and mprotect() with explicit
54076 + usage of PROT_WRITE and PROT_EXEC together will be logged when
54077 + denied by the PAX_MPROTECT feature. If the sysctl option is
54078 + enabled, a sysctl option with name "rwxmap_logging" is created.
54079 +
54080 +config GRKERNSEC_AUDIT_TEXTREL
54081 + bool 'ELF text relocations logging (READ HELP)'
54082 + depends on PAX_MPROTECT
54083 + help
54084 + If you say Y here, text relocations will be logged with the filename
54085 + of the offending library or binary. The purpose of the feature is
54086 + to help Linux distribution developers get rid of libraries and
54087 + binaries that need text relocations which hinder the future progress
54088 + of PaX. Only Linux distribution developers should say Y here, and
54089 + never on a production machine, as this option creates an information
54090 + leak that could aid an attacker in defeating the randomization of
54091 + a single memory region. If the sysctl option is enabled, a sysctl
54092 + option with name "audit_textrel" is created.
54093 +
54094 +endmenu
54095 +
54096 +menu "Executable Protections"
54097 +depends on GRKERNSEC
54098 +
54099 +config GRKERNSEC_DMESG
54100 + bool "Dmesg(8) restriction"
54101 + default y if GRKERNSEC_CONFIG_AUTO
54102 + help
54103 + If you say Y here, non-root users will not be able to use dmesg(8)
54104 + to view the contents of the kernel's circular log buffer.
54105 + The kernel's log buffer often contains kernel addresses and other
54106 + identifying information useful to an attacker in fingerprinting a
54107 + system for a targeted exploit.
54108 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
54109 + created.
54110 +
54111 +config GRKERNSEC_HARDEN_PTRACE
54112 + bool "Deter ptrace-based process snooping"
54113 + default y if GRKERNSEC_CONFIG_AUTO
54114 + help
54115 + If you say Y here, TTY sniffers and other malicious monitoring
54116 + programs implemented through ptrace will be defeated. If you
54117 + have been using the RBAC system, this option has already been
54118 + enabled for several years for all users, with the ability to make
54119 + fine-grained exceptions.
54120 +
54121 + This option only affects the ability of non-root users to ptrace
54122 + processes that are not a descendent of the ptracing process.
54123 + This means that strace ./binary and gdb ./binary will still work,
54124 + but attaching to arbitrary processes will not. If the sysctl
54125 + option is enabled, a sysctl option with name "harden_ptrace" is
54126 + created.
54127 +
54128 +config GRKERNSEC_PTRACE_READEXEC
54129 + bool "Require read access to ptrace sensitive binaries"
54130 + default y if GRKERNSEC_CONFIG_AUTO
54131 + help
54132 + If you say Y here, unprivileged users will not be able to ptrace unreadable
54133 + binaries. This option is useful in environments that
54134 + remove the read bits (e.g. file mode 4711) from suid binaries to
54135 + prevent infoleaking of their contents. This option adds
54136 + consistency to the use of that file mode, as the binary could normally
54137 + be read out when run without privileges while ptracing.
54138 +
54139 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
54140 + is created.
54141 +
54142 +config GRKERNSEC_SETXID
54143 + bool "Enforce consistent multithreaded privileges"
54144 + default y if GRKERNSEC_CONFIG_AUTO
54145 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
54146 + help
54147 + If you say Y here, a change from a root uid to a non-root uid
54148 + in a multithreaded application will cause the resulting uids,
54149 + gids, supplementary groups, and capabilities in that thread
54150 + to be propagated to the other threads of the process. In most
54151 + cases this is unnecessary, as glibc will emulate this behavior
54152 + on behalf of the application. Other libcs do not act in the
54153 + same way, allowing the other threads of the process to continue
54154 + running with root privileges. If the sysctl option is enabled,
54155 + a sysctl option with name "consistent_setxid" is created.
54156 +
54157 +config GRKERNSEC_TPE
54158 + bool "Trusted Path Execution (TPE)"
54159 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
54160 + help
54161 + If you say Y here, you will be able to choose a gid to add to the
54162 + supplementary groups of users you want to mark as "untrusted."
54163 + These users will not be able to execute any files that are not in
54164 + root-owned directories writable only by root. If the sysctl option
54165 + is enabled, a sysctl option with name "tpe" is created.
54166 +
54167 +config GRKERNSEC_TPE_ALL
54168 + bool "Partially restrict all non-root users"
54169 + depends on GRKERNSEC_TPE
54170 + help
54171 + If you say Y here, all non-root users will be covered under
54172 + a weaker TPE restriction. This is separate from, and in addition to,
54173 + the main TPE options that you have selected elsewhere. Thus, if a
54174 + "trusted" GID is chosen, this restriction applies to even that GID.
54175 + Under this restriction, all non-root users will only be allowed to
54176 + execute files in directories they own that are not group or
54177 + world-writable, or in directories owned by root and writable only by
54178 + root. If the sysctl option is enabled, a sysctl option with name
54179 + "tpe_restrict_all" is created.
54180 +
54181 +config GRKERNSEC_TPE_INVERT
54182 + bool "Invert GID option"
54183 + depends on GRKERNSEC_TPE
54184 + help
54185 + If you say Y here, the group you specify in the TPE configuration will
54186 + decide what group TPE restrictions will be *disabled* for. This
54187 + option is useful if you want TPE restrictions to be applied to most
54188 + users on the system. If the sysctl option is enabled, a sysctl option
54189 + with name "tpe_invert" is created. Unlike other sysctl options, this
54190 + entry will default to on for backward-compatibility.
54191 +
54192 +config GRKERNSEC_TPE_GID
54193 + int
54194 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
54195 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
54196 +
54197 +config GRKERNSEC_TPE_UNTRUSTED_GID
54198 + int "GID for TPE-untrusted users"
54199 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
54200 + default 1005
54201 + help
54202 + Setting this GID determines what group TPE restrictions will be
54203 + *enabled* for. If the sysctl option is enabled, a sysctl option
54204 + with name "tpe_gid" is created.
54205 +
54206 +config GRKERNSEC_TPE_TRUSTED_GID
54207 + int "GID for TPE-trusted users"
54208 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
54209 + default 1005
54210 + help
54211 + Setting this GID determines what group TPE restrictions will be
54212 + *disabled* for. If the sysctl option is enabled, a sysctl option
54213 + with name "tpe_gid" is created.
54214 +
54215 +endmenu
54216 +menu "Network Protections"
54217 +depends on GRKERNSEC
54218 +
54219 +config GRKERNSEC_RANDNET
54220 + bool "Larger entropy pools"
54221 + default y if GRKERNSEC_CONFIG_AUTO
54222 + help
54223 + If you say Y here, the entropy pools used for many features of Linux
54224 + and grsecurity will be doubled in size. Since several grsecurity
54225 + features use additional randomness, it is recommended that you say Y
54226 + here. Saying Y here has a similar effect as modifying
54227 + /proc/sys/kernel/random/poolsize.
54228 +
54229 +config GRKERNSEC_BLACKHOLE
54230 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
54231 + default y if GRKERNSEC_CONFIG_AUTO
54232 + depends on NET
54233 + help
54234 + If you say Y here, neither TCP resets nor ICMP
54235 + destination-unreachable packets will be sent in response to packets
54236 + sent to ports for which no associated listening process exists.
54237 + This feature supports both IPV4 and IPV6 and exempts the
54238 + loopback interface from blackholing. Enabling this feature
54239 + makes a host more resilient to DoS attacks and reduces network
54240 + visibility against scanners.
54241 +
54242 + The blackhole feature as-implemented is equivalent to the FreeBSD
54243 + blackhole feature, as it prevents RST responses to all packets, not
54244 + just SYNs. Under most application behavior this causes no
54245 + problems, but applications (like haproxy) may not close certain
54246 + connections in a way that cleanly terminates them on the remote
54247 + end, leaving the remote host in LAST_ACK state. Because of this
54248 + side-effect and to prevent intentional LAST_ACK DoSes, this
54249 + feature also adds automatic mitigation against such attacks.
54250 + The mitigation drastically reduces the amount of time a socket
54251 + can spend in LAST_ACK state. If you're using haproxy and not
54252 + all servers it connects to have this option enabled, consider
54253 + disabling this feature on the haproxy host.
54254 +
54255 + If the sysctl option is enabled, two sysctl options with names
54256 + "ip_blackhole" and "lastack_retries" will be created.
54257 + While "ip_blackhole" takes the standard zero/non-zero on/off
54258 + toggle, "lastack_retries" uses the same kinds of values as
54259 + "tcp_retries1" and "tcp_retries2". The default value of 4
54260 + prevents a socket from lasting more than 45 seconds in LAST_ACK
54261 + state.
54262 +
54263 +config GRKERNSEC_NO_SIMULT_CONNECT
54264 + bool "Disable TCP Simultaneous Connect"
54265 + default y if GRKERNSEC_CONFIG_AUTO
54266 + depends on NET
54267 + help
54268 + If you say Y here, a feature by Willy Tarreau will be enabled that
54269 + removes a weakness in Linux's strict implementation of TCP that
54270 + allows two clients to connect to each other without either entering
54271 + a listening state. The weakness allows an attacker to easily prevent
54272 + a client from connecting to a known server provided the source port
54273 + for the connection is guessed correctly.
54274 +
54275 + As the weakness could be used to prevent an antivirus or IPS from
54276 + fetching updates, or prevent an SSL gateway from fetching a CRL,
54277 + it should be eliminated by enabling this option. Though Linux is
54278 + one of few operating systems supporting simultaneous connect, it
54279 + has no legitimate use in practice and is rarely supported by firewalls.
54280 +
54281 +config GRKERNSEC_SOCKET
54282 + bool "Socket restrictions"
54283 + depends on NET
54284 + help
54285 + If you say Y here, you will be able to choose from several options.
54286 + If you assign a GID on your system and add it to the supplementary
54287 + groups of users you want to restrict socket access to, this patch
54288 + will perform up to three things, based on the option(s) you choose.
54289 +
54290 +config GRKERNSEC_SOCKET_ALL
54291 + bool "Deny any sockets to group"
54292 + depends on GRKERNSEC_SOCKET
54293 + help
54294 + If you say Y here, you will be able to choose a GID of whose users will
54295 + be unable to connect to other hosts from your machine or run server
54296 + applications from your machine. If the sysctl option is enabled, a
54297 + sysctl option with name "socket_all" is created.
54298 +
54299 +config GRKERNSEC_SOCKET_ALL_GID
54300 + int "GID to deny all sockets for"
54301 + depends on GRKERNSEC_SOCKET_ALL
54302 + default 1004
54303 + help
54304 + Here you can choose the GID to disable socket access for. Remember to
54305 + add the users you want socket access disabled for to the GID
54306 + specified here. If the sysctl option is enabled, a sysctl option
54307 + with name "socket_all_gid" is created.
54308 +
54309 +config GRKERNSEC_SOCKET_CLIENT
54310 + bool "Deny client sockets to group"
54311 + depends on GRKERNSEC_SOCKET
54312 + help
54313 + If you say Y here, you will be able to choose a GID of whose users will
54314 + be unable to connect to other hosts from your machine, but will be
54315 + able to run servers. If this option is enabled, all users in the group
54316 + you specify will have to use passive mode when initiating ftp transfers
54317 + from the shell on your machine. If the sysctl option is enabled, a
54318 + sysctl option with name "socket_client" is created.
54319 +
54320 +config GRKERNSEC_SOCKET_CLIENT_GID
54321 + int "GID to deny client sockets for"
54322 + depends on GRKERNSEC_SOCKET_CLIENT
54323 + default 1003
54324 + help
54325 + Here you can choose the GID to disable client socket access for.
54326 + Remember to add the users you want client socket access disabled for to
54327 + the GID specified here. If the sysctl option is enabled, a sysctl
54328 + option with name "socket_client_gid" is created.
54329 +
54330 +config GRKERNSEC_SOCKET_SERVER
54331 + bool "Deny server sockets to group"
54332 + depends on GRKERNSEC_SOCKET
54333 + help
54334 + If you say Y here, you will be able to choose a GID of whose users will
54335 + be unable to run server applications from your machine. If the sysctl
54336 + option is enabled, a sysctl option with name "socket_server" is created.
54337 +
54338 +config GRKERNSEC_SOCKET_SERVER_GID
54339 + int "GID to deny server sockets for"
54340 + depends on GRKERNSEC_SOCKET_SERVER
54341 + default 1002
54342 + help
54343 + Here you can choose the GID to disable server socket access for.
54344 + Remember to add the users you want server socket access disabled for to
54345 + the GID specified here. If the sysctl option is enabled, a sysctl
54346 + option with name "socket_server_gid" is created.
54347 +
54348 +endmenu
54349 +menu "Sysctl Support"
54350 +depends on GRKERNSEC && SYSCTL
54351 +
54352 +config GRKERNSEC_SYSCTL
54353 + bool "Sysctl support"
54354 + default y if GRKERNSEC_CONFIG_AUTO
54355 + help
54356 + If you say Y here, you will be able to change the options that
54357 + grsecurity runs with at bootup, without having to recompile your
54358 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
54359 + to enable (1) or disable (0) various features. All the sysctl entries
54360 + are mutable until the "grsec_lock" entry is set to a non-zero value.
54361 + All features enabled in the kernel configuration are disabled at boot
54362 + if you do not say Y to the "Turn on features by default" option.
54363 + All options should be set at startup, and the grsec_lock entry should
54364 + be set to a non-zero value after all the options are set.
54365 + *THIS IS EXTREMELY IMPORTANT*
54366 +
54367 +config GRKERNSEC_SYSCTL_DISTRO
54368 + bool "Extra sysctl support for distro makers (READ HELP)"
54369 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
54370 + help
54371 + If you say Y here, additional sysctl options will be created
54372 + for features that affect processes running as root. Therefore,
54373 + it is critical when using this option that the grsec_lock entry be
54374 + enabled after boot. Only distros with prebuilt kernel packages
54375 + with this option enabled that can ensure grsec_lock is enabled
54376 + after boot should use this option.
54377 + *Failure to set grsec_lock after boot makes all grsec features
54378 + this option covers useless*
54379 +
54380 + Currently this option creates the following sysctl entries:
54381 + "Disable Privileged I/O": "disable_priv_io"
54382 +
54383 +config GRKERNSEC_SYSCTL_ON
54384 + bool "Turn on features by default"
54385 + default y if GRKERNSEC_CONFIG_AUTO
54386 + depends on GRKERNSEC_SYSCTL
54387 + help
54388 + If you say Y here, instead of having all features enabled in the
54389 + kernel configuration disabled at boot time, the features will be
54390 + enabled at boot time. It is recommended you say Y here unless
54391 + there is some reason you would want all sysctl-tunable features to
54392 + be disabled by default. As mentioned elsewhere, it is important
54393 + to enable the grsec_lock entry once you have finished modifying
54394 + the sysctl entries.
54395 +
54396 +endmenu
54397 +menu "Logging Options"
54398 +depends on GRKERNSEC
54399 +
54400 +config GRKERNSEC_FLOODTIME
54401 + int "Seconds in between log messages (minimum)"
54402 + default 10
54403 + help
54404 + This option allows you to enforce the number of seconds between
54405 + grsecurity log messages. The default should be suitable for most
54406 + people, however, if you choose to change it, choose a value small enough
54407 + to allow informative logs to be produced, but large enough to
54408 + prevent flooding.
54409 +
54410 +config GRKERNSEC_FLOODBURST
54411 + int "Number of messages in a burst (maximum)"
54412 + default 6
54413 + help
54414 + This option allows you to choose the maximum number of messages allowed
54415 + within the flood time interval you chose in a separate option. The
54416 + default should be suitable for most people, however if you find that
54417 + many of your logs are being interpreted as flooding, you may want to
54418 + raise this value.
54419 +
54420 +endmenu
54421 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
54422 new file mode 100644
54423 index 0000000..1b9afa9
54424 --- /dev/null
54425 +++ b/grsecurity/Makefile
54426 @@ -0,0 +1,38 @@
54427 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
54428 +# during 2001-2009 it has been completely redesigned by Brad Spengler
54429 +# into an RBAC system
54430 +#
54431 +# All code in this directory and various hooks inserted throughout the kernel
54432 +# are copyright Brad Spengler - Open Source Security, Inc., and released
54433 +# under the GPL v2 or higher
54434 +
54435 +KBUILD_CFLAGS += -Werror
54436 +
54437 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
54438 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
54439 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
54440 +
54441 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
54442 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
54443 + gracl_learn.o grsec_log.o
54444 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
54445 +
54446 +ifdef CONFIG_NET
54447 +obj-y += grsec_sock.o
54448 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
54449 +endif
54450 +
54451 +ifndef CONFIG_GRKERNSEC
54452 +obj-y += grsec_disabled.o
54453 +endif
54454 +
54455 +ifdef CONFIG_GRKERNSEC_HIDESYM
54456 +extra-y := grsec_hidesym.o
54457 +$(obj)/grsec_hidesym.o:
54458 + @-chmod -f 500 /boot
54459 + @-chmod -f 500 /lib/modules
54460 + @-chmod -f 500 /lib64/modules
54461 + @-chmod -f 500 /lib32/modules
54462 + @-chmod -f 700 .
54463 + @echo ' grsec: protected kernel image paths'
54464 +endif
54465 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
54466 new file mode 100644
54467 index 0000000..69e1320
54468 --- /dev/null
54469 +++ b/grsecurity/gracl.c
54470 @@ -0,0 +1,4019 @@
54471 +#include <linux/kernel.h>
54472 +#include <linux/module.h>
54473 +#include <linux/sched.h>
54474 +#include <linux/mm.h>
54475 +#include <linux/file.h>
54476 +#include <linux/fs.h>
54477 +#include <linux/namei.h>
54478 +#include <linux/mount.h>
54479 +#include <linux/tty.h>
54480 +#include <linux/proc_fs.h>
54481 +#include <linux/lglock.h>
54482 +#include <linux/slab.h>
54483 +#include <linux/vmalloc.h>
54484 +#include <linux/types.h>
54485 +#include <linux/sysctl.h>
54486 +#include <linux/netdevice.h>
54487 +#include <linux/ptrace.h>
54488 +#include <linux/gracl.h>
54489 +#include <linux/gralloc.h>
54490 +#include <linux/security.h>
54491 +#include <linux/grinternal.h>
54492 +#include <linux/pid_namespace.h>
54493 +#include <linux/stop_machine.h>
54494 +#include <linux/fdtable.h>
54495 +#include <linux/percpu.h>
54496 +#include <linux/lglock.h>
54497 +#include <linux/hugetlb.h>
54498 +#include "../fs/mount.h"
54499 +
54500 +#include <asm/uaccess.h>
54501 +#include <asm/errno.h>
54502 +#include <asm/mman.h>
54503 +
54504 +extern struct lglock vfsmount_lock;
54505 +
54506 +static struct acl_role_db acl_role_set;
54507 +static struct name_db name_set;
54508 +static struct inodev_db inodev_set;
54509 +
54510 +/* for keeping track of userspace pointers used for subjects, so we
54511 + can share references in the kernel as well
54512 +*/
54513 +
54514 +static struct path real_root;
54515 +
54516 +static struct acl_subj_map_db subj_map_set;
54517 +
54518 +static struct acl_role_label *default_role;
54519 +
54520 +static struct acl_role_label *role_list;
54521 +
54522 +static u16 acl_sp_role_value;
54523 +
54524 +extern char *gr_shared_page[4];
54525 +static DEFINE_MUTEX(gr_dev_mutex);
54526 +DEFINE_RWLOCK(gr_inode_lock);
54527 +
54528 +struct gr_arg *gr_usermode;
54529 +
54530 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
54531 +
54532 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
54533 +extern void gr_clear_learn_entries(void);
54534 +
54535 +unsigned char *gr_system_salt;
54536 +unsigned char *gr_system_sum;
54537 +
54538 +static struct sprole_pw **acl_special_roles = NULL;
54539 +static __u16 num_sprole_pws = 0;
54540 +
54541 +static struct acl_role_label *kernel_role = NULL;
54542 +
54543 +static unsigned int gr_auth_attempts = 0;
54544 +static unsigned long gr_auth_expires = 0UL;
54545 +
54546 +#ifdef CONFIG_NET
54547 +extern struct vfsmount *sock_mnt;
54548 +#endif
54549 +
54550 +extern struct vfsmount *pipe_mnt;
54551 +extern struct vfsmount *shm_mnt;
54552 +
54553 +#ifdef CONFIG_HUGETLBFS
54554 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
54555 +#endif
54556 +
54557 +static struct acl_object_label *fakefs_obj_rw;
54558 +static struct acl_object_label *fakefs_obj_rwx;
54559 +
54560 +extern int gr_init_uidset(void);
54561 +extern void gr_free_uidset(void);
54562 +extern void gr_remove_uid(uid_t uid);
54563 +extern int gr_find_uid(uid_t uid);
54564 +
54565 +__inline__ int
54566 +gr_acl_is_enabled(void)
54567 +{
54568 + return (gr_status & GR_READY);
54569 +}
54570 +
54571 +#ifdef CONFIG_BTRFS_FS
54572 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
54573 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
54574 +#endif
54575 +
54576 +static inline dev_t __get_dev(const struct dentry *dentry)
54577 +{
54578 +#ifdef CONFIG_BTRFS_FS
54579 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
54580 + return get_btrfs_dev_from_inode(dentry->d_inode);
54581 + else
54582 +#endif
54583 + return dentry->d_inode->i_sb->s_dev;
54584 +}
54585 +
54586 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
54587 +{
54588 + return __get_dev(dentry);
54589 +}
54590 +
54591 +static char gr_task_roletype_to_char(struct task_struct *task)
54592 +{
54593 + switch (task->role->roletype &
54594 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
54595 + GR_ROLE_SPECIAL)) {
54596 + case GR_ROLE_DEFAULT:
54597 + return 'D';
54598 + case GR_ROLE_USER:
54599 + return 'U';
54600 + case GR_ROLE_GROUP:
54601 + return 'G';
54602 + case GR_ROLE_SPECIAL:
54603 + return 'S';
54604 + }
54605 +
54606 + return 'X';
54607 +}
54608 +
54609 +char gr_roletype_to_char(void)
54610 +{
54611 + return gr_task_roletype_to_char(current);
54612 +}
54613 +
54614 +__inline__ int
54615 +gr_acl_tpe_check(void)
54616 +{
54617 + if (unlikely(!(gr_status & GR_READY)))
54618 + return 0;
54619 + if (current->role->roletype & GR_ROLE_TPE)
54620 + return 1;
54621 + else
54622 + return 0;
54623 +}
54624 +
54625 +int
54626 +gr_handle_rawio(const struct inode *inode)
54627 +{
54628 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
54629 + if (inode && S_ISBLK(inode->i_mode) &&
54630 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
54631 + !capable(CAP_SYS_RAWIO))
54632 + return 1;
54633 +#endif
54634 + return 0;
54635 +}
54636 +
54637 +static int
54638 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
54639 +{
54640 + if (likely(lena != lenb))
54641 + return 0;
54642 +
54643 + return !memcmp(a, b, lena);
54644 +}
54645 +
54646 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
54647 +{
54648 + *buflen -= namelen;
54649 + if (*buflen < 0)
54650 + return -ENAMETOOLONG;
54651 + *buffer -= namelen;
54652 + memcpy(*buffer, str, namelen);
54653 + return 0;
54654 +}
54655 +
54656 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
54657 +{
54658 + return prepend(buffer, buflen, name->name, name->len);
54659 +}
54660 +
54661 +static int prepend_path(const struct path *path, struct path *root,
54662 + char **buffer, int *buflen)
54663 +{
54664 + struct dentry *dentry = path->dentry;
54665 + struct vfsmount *vfsmnt = path->mnt;
54666 + struct mount *mnt = real_mount(vfsmnt);
54667 + bool slash = false;
54668 + int error = 0;
54669 +
54670 + while (dentry != root->dentry || vfsmnt != root->mnt) {
54671 + struct dentry * parent;
54672 +
54673 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
54674 + /* Global root? */
54675 + if (!mnt_has_parent(mnt)) {
54676 + goto out;
54677 + }
54678 + dentry = mnt->mnt_mountpoint;
54679 + mnt = mnt->mnt_parent;
54680 + vfsmnt = &mnt->mnt;
54681 + continue;
54682 + }
54683 + parent = dentry->d_parent;
54684 + prefetch(parent);
54685 + spin_lock(&dentry->d_lock);
54686 + error = prepend_name(buffer, buflen, &dentry->d_name);
54687 + spin_unlock(&dentry->d_lock);
54688 + if (!error)
54689 + error = prepend(buffer, buflen, "/", 1);
54690 + if (error)
54691 + break;
54692 +
54693 + slash = true;
54694 + dentry = parent;
54695 + }
54696 +
54697 +out:
54698 + if (!error && !slash)
54699 + error = prepend(buffer, buflen, "/", 1);
54700 +
54701 + return error;
54702 +}
54703 +
54704 +/* this must be called with vfsmount_lock and rename_lock held */
54705 +
54706 +static char *__our_d_path(const struct path *path, struct path *root,
54707 + char *buf, int buflen)
54708 +{
54709 + char *res = buf + buflen;
54710 + int error;
54711 +
54712 + prepend(&res, &buflen, "\0", 1);
54713 + error = prepend_path(path, root, &res, &buflen);
54714 + if (error)
54715 + return ERR_PTR(error);
54716 +
54717 + return res;
54718 +}
54719 +
54720 +static char *
54721 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
54722 +{
54723 + char *retval;
54724 +
54725 + retval = __our_d_path(path, root, buf, buflen);
54726 + if (unlikely(IS_ERR(retval)))
54727 + retval = strcpy(buf, "<path too long>");
54728 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
54729 + retval[1] = '\0';
54730 +
54731 + return retval;
54732 +}
54733 +
54734 +static char *
54735 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54736 + char *buf, int buflen)
54737 +{
54738 + struct path path;
54739 + char *res;
54740 +
54741 + path.dentry = (struct dentry *)dentry;
54742 + path.mnt = (struct vfsmount *)vfsmnt;
54743 +
54744 + /* we can use real_root.dentry, real_root.mnt, because this is only called
54745 + by the RBAC system */
54746 + res = gen_full_path(&path, &real_root, buf, buflen);
54747 +
54748 + return res;
54749 +}
54750 +
54751 +static char *
54752 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
54753 + char *buf, int buflen)
54754 +{
54755 + char *res;
54756 + struct path path;
54757 + struct path root;
54758 + struct task_struct *reaper = init_pid_ns.child_reaper;
54759 +
54760 + path.dentry = (struct dentry *)dentry;
54761 + path.mnt = (struct vfsmount *)vfsmnt;
54762 +
54763 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
54764 + get_fs_root(reaper->fs, &root);
54765 +
54766 + write_seqlock(&rename_lock);
54767 + br_read_lock(&vfsmount_lock);
54768 + res = gen_full_path(&path, &root, buf, buflen);
54769 + br_read_unlock(&vfsmount_lock);
54770 + write_sequnlock(&rename_lock);
54771 +
54772 + path_put(&root);
54773 + return res;
54774 +}
54775 +
54776 +static char *
54777 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54778 +{
54779 + char *ret;
54780 + write_seqlock(&rename_lock);
54781 + br_read_lock(&vfsmount_lock);
54782 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54783 + PAGE_SIZE);
54784 + br_read_unlock(&vfsmount_lock);
54785 + write_sequnlock(&rename_lock);
54786 + return ret;
54787 +}
54788 +
54789 +static char *
54790 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
54791 +{
54792 + char *ret;
54793 + char *buf;
54794 + int buflen;
54795 +
54796 + write_seqlock(&rename_lock);
54797 + br_read_lock(&vfsmount_lock);
54798 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
54799 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
54800 + buflen = (int)(ret - buf);
54801 + if (buflen >= 5)
54802 + prepend(&ret, &buflen, "/proc", 5);
54803 + else
54804 + ret = strcpy(buf, "<path too long>");
54805 + br_read_unlock(&vfsmount_lock);
54806 + write_sequnlock(&rename_lock);
54807 + return ret;
54808 +}
54809 +
54810 +char *
54811 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
54812 +{
54813 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
54814 + PAGE_SIZE);
54815 +}
54816 +
54817 +char *
54818 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
54819 +{
54820 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
54821 + PAGE_SIZE);
54822 +}
54823 +
54824 +char *
54825 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
54826 +{
54827 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
54828 + PAGE_SIZE);
54829 +}
54830 +
54831 +char *
54832 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
54833 +{
54834 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
54835 + PAGE_SIZE);
54836 +}
54837 +
54838 +char *
54839 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
54840 +{
54841 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
54842 + PAGE_SIZE);
54843 +}
54844 +
54845 +__inline__ __u32
54846 +to_gr_audit(const __u32 reqmode)
54847 +{
54848 + /* masks off auditable permission flags, then shifts them to create
54849 + auditing flags, and adds the special case of append auditing if
54850 + we're requesting write */
54851 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
54852 +}
54853 +
54854 +struct acl_subject_label *
54855 +lookup_subject_map(const struct acl_subject_label *userp)
54856 +{
54857 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
54858 + struct subject_map *match;
54859 +
54860 + match = subj_map_set.s_hash[index];
54861 +
54862 + while (match && match->user != userp)
54863 + match = match->next;
54864 +
54865 + if (match != NULL)
54866 + return match->kernel;
54867 + else
54868 + return NULL;
54869 +}
54870 +
54871 +static void
54872 +insert_subj_map_entry(struct subject_map *subjmap)
54873 +{
54874 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
54875 + struct subject_map **curr;
54876 +
54877 + subjmap->prev = NULL;
54878 +
54879 + curr = &subj_map_set.s_hash[index];
54880 + if (*curr != NULL)
54881 + (*curr)->prev = subjmap;
54882 +
54883 + subjmap->next = *curr;
54884 + *curr = subjmap;
54885 +
54886 + return;
54887 +}
54888 +
54889 +static struct acl_role_label *
54890 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
54891 + const gid_t gid)
54892 +{
54893 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
54894 + struct acl_role_label *match;
54895 + struct role_allowed_ip *ipp;
54896 + unsigned int x;
54897 + u32 curr_ip = task->signal->curr_ip;
54898 +
54899 + task->signal->saved_ip = curr_ip;
54900 +
54901 + match = acl_role_set.r_hash[index];
54902 +
54903 + while (match) {
54904 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
54905 + for (x = 0; x < match->domain_child_num; x++) {
54906 + if (match->domain_children[x] == uid)
54907 + goto found;
54908 + }
54909 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
54910 + break;
54911 + match = match->next;
54912 + }
54913 +found:
54914 + if (match == NULL) {
54915 + try_group:
54916 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
54917 + match = acl_role_set.r_hash[index];
54918 +
54919 + while (match) {
54920 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
54921 + for (x = 0; x < match->domain_child_num; x++) {
54922 + if (match->domain_children[x] == gid)
54923 + goto found2;
54924 + }
54925 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
54926 + break;
54927 + match = match->next;
54928 + }
54929 +found2:
54930 + if (match == NULL)
54931 + match = default_role;
54932 + if (match->allowed_ips == NULL)
54933 + return match;
54934 + else {
54935 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54936 + if (likely
54937 + ((ntohl(curr_ip) & ipp->netmask) ==
54938 + (ntohl(ipp->addr) & ipp->netmask)))
54939 + return match;
54940 + }
54941 + match = default_role;
54942 + }
54943 + } else if (match->allowed_ips == NULL) {
54944 + return match;
54945 + } else {
54946 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
54947 + if (likely
54948 + ((ntohl(curr_ip) & ipp->netmask) ==
54949 + (ntohl(ipp->addr) & ipp->netmask)))
54950 + return match;
54951 + }
54952 + goto try_group;
54953 + }
54954 +
54955 + return match;
54956 +}
54957 +
54958 +struct acl_subject_label *
54959 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
54960 + const struct acl_role_label *role)
54961 +{
54962 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54963 + struct acl_subject_label *match;
54964 +
54965 + match = role->subj_hash[index];
54966 +
54967 + while (match && (match->inode != ino || match->device != dev ||
54968 + (match->mode & GR_DELETED))) {
54969 + match = match->next;
54970 + }
54971 +
54972 + if (match && !(match->mode & GR_DELETED))
54973 + return match;
54974 + else
54975 + return NULL;
54976 +}
54977 +
54978 +struct acl_subject_label *
54979 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
54980 + const struct acl_role_label *role)
54981 +{
54982 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
54983 + struct acl_subject_label *match;
54984 +
54985 + match = role->subj_hash[index];
54986 +
54987 + while (match && (match->inode != ino || match->device != dev ||
54988 + !(match->mode & GR_DELETED))) {
54989 + match = match->next;
54990 + }
54991 +
54992 + if (match && (match->mode & GR_DELETED))
54993 + return match;
54994 + else
54995 + return NULL;
54996 +}
54997 +
54998 +static struct acl_object_label *
54999 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
55000 + const struct acl_subject_label *subj)
55001 +{
55002 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
55003 + struct acl_object_label *match;
55004 +
55005 + match = subj->obj_hash[index];
55006 +
55007 + while (match && (match->inode != ino || match->device != dev ||
55008 + (match->mode & GR_DELETED))) {
55009 + match = match->next;
55010 + }
55011 +
55012 + if (match && !(match->mode & GR_DELETED))
55013 + return match;
55014 + else
55015 + return NULL;
55016 +}
55017 +
55018 +static struct acl_object_label *
55019 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
55020 + const struct acl_subject_label *subj)
55021 +{
55022 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
55023 + struct acl_object_label *match;
55024 +
55025 + match = subj->obj_hash[index];
55026 +
55027 + while (match && (match->inode != ino || match->device != dev ||
55028 + !(match->mode & GR_DELETED))) {
55029 + match = match->next;
55030 + }
55031 +
55032 + if (match && (match->mode & GR_DELETED))
55033 + return match;
55034 +
55035 + match = subj->obj_hash[index];
55036 +
55037 + while (match && (match->inode != ino || match->device != dev ||
55038 + (match->mode & GR_DELETED))) {
55039 + match = match->next;
55040 + }
55041 +
55042 + if (match && !(match->mode & GR_DELETED))
55043 + return match;
55044 + else
55045 + return NULL;
55046 +}
55047 +
55048 +static struct name_entry *
55049 +lookup_name_entry(const char *name)
55050 +{
55051 + unsigned int len = strlen(name);
55052 + unsigned int key = full_name_hash(name, len);
55053 + unsigned int index = key % name_set.n_size;
55054 + struct name_entry *match;
55055 +
55056 + match = name_set.n_hash[index];
55057 +
55058 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
55059 + match = match->next;
55060 +
55061 + return match;
55062 +}
55063 +
55064 +static struct name_entry *
55065 +lookup_name_entry_create(const char *name)
55066 +{
55067 + unsigned int len = strlen(name);
55068 + unsigned int key = full_name_hash(name, len);
55069 + unsigned int index = key % name_set.n_size;
55070 + struct name_entry *match;
55071 +
55072 + match = name_set.n_hash[index];
55073 +
55074 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55075 + !match->deleted))
55076 + match = match->next;
55077 +
55078 + if (match && match->deleted)
55079 + return match;
55080 +
55081 + match = name_set.n_hash[index];
55082 +
55083 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
55084 + match->deleted))
55085 + match = match->next;
55086 +
55087 + if (match && !match->deleted)
55088 + return match;
55089 + else
55090 + return NULL;
55091 +}
55092 +
55093 +static struct inodev_entry *
55094 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
55095 +{
55096 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
55097 + struct inodev_entry *match;
55098 +
55099 + match = inodev_set.i_hash[index];
55100 +
55101 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
55102 + match = match->next;
55103 +
55104 + return match;
55105 +}
55106 +
55107 +static void
55108 +insert_inodev_entry(struct inodev_entry *entry)
55109 +{
55110 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
55111 + inodev_set.i_size);
55112 + struct inodev_entry **curr;
55113 +
55114 + entry->prev = NULL;
55115 +
55116 + curr = &inodev_set.i_hash[index];
55117 + if (*curr != NULL)
55118 + (*curr)->prev = entry;
55119 +
55120 + entry->next = *curr;
55121 + *curr = entry;
55122 +
55123 + return;
55124 +}
55125 +
55126 +static void
55127 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
55128 +{
55129 + unsigned int index =
55130 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
55131 + struct acl_role_label **curr;
55132 + struct acl_role_label *tmp, *tmp2;
55133 +
55134 + curr = &acl_role_set.r_hash[index];
55135 +
55136 + /* simple case, slot is empty, just set it to our role */
55137 + if (*curr == NULL) {
55138 + *curr = role;
55139 + } else {
55140 + /* example:
55141 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
55142 + 2 -> 3
55143 + */
55144 + /* first check to see if we can already be reached via this slot */
55145 + tmp = *curr;
55146 + while (tmp && tmp != role)
55147 + tmp = tmp->next;
55148 + if (tmp == role) {
55149 + /* we don't need to add ourselves to this slot's chain */
55150 + return;
55151 + }
55152 + /* we need to add ourselves to this chain, two cases */
55153 + if (role->next == NULL) {
55154 + /* simple case, append the current chain to our role */
55155 + role->next = *curr;
55156 + *curr = role;
55157 + } else {
55158 + /* 1 -> 2 -> 3 -> 4
55159 + 2 -> 3 -> 4
55160 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
55161 + */
55162 + /* trickier case: walk our role's chain until we find
55163 + the role for the start of the current slot's chain */
55164 + tmp = role;
55165 + tmp2 = *curr;
55166 + while (tmp->next && tmp->next != tmp2)
55167 + tmp = tmp->next;
55168 + if (tmp->next == tmp2) {
55169 + /* from example above, we found 3, so just
55170 + replace this slot's chain with ours */
55171 + *curr = role;
55172 + } else {
55173 + /* we didn't find a subset of our role's chain
55174 + in the current slot's chain, so append their
55175 + chain to ours, and set us as the first role in
55176 + the slot's chain
55177 +
55178 + we could fold this case with the case above,
55179 + but making it explicit for clarity
55180 + */
55181 + tmp->next = tmp2;
55182 + *curr = role;
55183 + }
55184 + }
55185 + }
55186 +
55187 + return;
55188 +}
55189 +
55190 +static void
55191 +insert_acl_role_label(struct acl_role_label *role)
55192 +{
55193 + int i;
55194 +
55195 + if (role_list == NULL) {
55196 + role_list = role;
55197 + role->prev = NULL;
55198 + } else {
55199 + role->prev = role_list;
55200 + role_list = role;
55201 + }
55202 +
55203 + /* used for hash chains */
55204 + role->next = NULL;
55205 +
55206 + if (role->roletype & GR_ROLE_DOMAIN) {
55207 + for (i = 0; i < role->domain_child_num; i++)
55208 + __insert_acl_role_label(role, role->domain_children[i]);
55209 + } else
55210 + __insert_acl_role_label(role, role->uidgid);
55211 +}
55212 +
55213 +static int
55214 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
55215 +{
55216 + struct name_entry **curr, *nentry;
55217 + struct inodev_entry *ientry;
55218 + unsigned int len = strlen(name);
55219 + unsigned int key = full_name_hash(name, len);
55220 + unsigned int index = key % name_set.n_size;
55221 +
55222 + curr = &name_set.n_hash[index];
55223 +
55224 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
55225 + curr = &((*curr)->next);
55226 +
55227 + if (*curr != NULL)
55228 + return 1;
55229 +
55230 + nentry = acl_alloc(sizeof (struct name_entry));
55231 + if (nentry == NULL)
55232 + return 0;
55233 + ientry = acl_alloc(sizeof (struct inodev_entry));
55234 + if (ientry == NULL)
55235 + return 0;
55236 + ientry->nentry = nentry;
55237 +
55238 + nentry->key = key;
55239 + nentry->name = name;
55240 + nentry->inode = inode;
55241 + nentry->device = device;
55242 + nentry->len = len;
55243 + nentry->deleted = deleted;
55244 +
55245 + nentry->prev = NULL;
55246 + curr = &name_set.n_hash[index];
55247 + if (*curr != NULL)
55248 + (*curr)->prev = nentry;
55249 + nentry->next = *curr;
55250 + *curr = nentry;
55251 +
55252 + /* insert us into the table searchable by inode/dev */
55253 + insert_inodev_entry(ientry);
55254 +
55255 + return 1;
55256 +}
55257 +
55258 +static void
55259 +insert_acl_obj_label(struct acl_object_label *obj,
55260 + struct acl_subject_label *subj)
55261 +{
55262 + unsigned int index =
55263 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
55264 + struct acl_object_label **curr;
55265 +
55266 +
55267 + obj->prev = NULL;
55268 +
55269 + curr = &subj->obj_hash[index];
55270 + if (*curr != NULL)
55271 + (*curr)->prev = obj;
55272 +
55273 + obj->next = *curr;
55274 + *curr = obj;
55275 +
55276 + return;
55277 +}
55278 +
55279 +static void
55280 +insert_acl_subj_label(struct acl_subject_label *obj,
55281 + struct acl_role_label *role)
55282 +{
55283 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
55284 + struct acl_subject_label **curr;
55285 +
55286 + obj->prev = NULL;
55287 +
55288 + curr = &role->subj_hash[index];
55289 + if (*curr != NULL)
55290 + (*curr)->prev = obj;
55291 +
55292 + obj->next = *curr;
55293 + *curr = obj;
55294 +
55295 + return;
55296 +}
55297 +
55298 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
55299 +
55300 +static void *
55301 +create_table(__u32 * len, int elementsize)
55302 +{
55303 + unsigned int table_sizes[] = {
55304 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
55305 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
55306 + 4194301, 8388593, 16777213, 33554393, 67108859
55307 + };
55308 + void *newtable = NULL;
55309 + unsigned int pwr = 0;
55310 +
55311 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
55312 + table_sizes[pwr] <= *len)
55313 + pwr++;
55314 +
55315 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
55316 + return newtable;
55317 +
55318 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
55319 + newtable =
55320 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
55321 + else
55322 + newtable = vmalloc(table_sizes[pwr] * elementsize);
55323 +
55324 + *len = table_sizes[pwr];
55325 +
55326 + return newtable;
55327 +}
55328 +
55329 +static int
55330 +init_variables(const struct gr_arg *arg)
55331 +{
55332 + struct task_struct *reaper = init_pid_ns.child_reaper;
55333 + unsigned int stacksize;
55334 +
55335 + subj_map_set.s_size = arg->role_db.num_subjects;
55336 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
55337 + name_set.n_size = arg->role_db.num_objects;
55338 + inodev_set.i_size = arg->role_db.num_objects;
55339 +
55340 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
55341 + !name_set.n_size || !inodev_set.i_size)
55342 + return 1;
55343 +
55344 + if (!gr_init_uidset())
55345 + return 1;
55346 +
55347 + /* set up the stack that holds allocation info */
55348 +
55349 + stacksize = arg->role_db.num_pointers + 5;
55350 +
55351 + if (!acl_alloc_stack_init(stacksize))
55352 + return 1;
55353 +
55354 + /* grab reference for the real root dentry and vfsmount */
55355 + get_fs_root(reaper->fs, &real_root);
55356 +
55357 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55358 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
55359 +#endif
55360 +
55361 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
55362 + if (fakefs_obj_rw == NULL)
55363 + return 1;
55364 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
55365 +
55366 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
55367 + if (fakefs_obj_rwx == NULL)
55368 + return 1;
55369 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
55370 +
55371 + subj_map_set.s_hash =
55372 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
55373 + acl_role_set.r_hash =
55374 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
55375 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
55376 + inodev_set.i_hash =
55377 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
55378 +
55379 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
55380 + !name_set.n_hash || !inodev_set.i_hash)
55381 + return 1;
55382 +
55383 + memset(subj_map_set.s_hash, 0,
55384 + sizeof(struct subject_map *) * subj_map_set.s_size);
55385 + memset(acl_role_set.r_hash, 0,
55386 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
55387 + memset(name_set.n_hash, 0,
55388 + sizeof (struct name_entry *) * name_set.n_size);
55389 + memset(inodev_set.i_hash, 0,
55390 + sizeof (struct inodev_entry *) * inodev_set.i_size);
55391 +
55392 + return 0;
55393 +}
55394 +
55395 +/* free information not needed after startup
55396 + currently contains user->kernel pointer mappings for subjects
55397 +*/
55398 +
55399 +static void
55400 +free_init_variables(void)
55401 +{
55402 + __u32 i;
55403 +
55404 + if (subj_map_set.s_hash) {
55405 + for (i = 0; i < subj_map_set.s_size; i++) {
55406 + if (subj_map_set.s_hash[i]) {
55407 + kfree(subj_map_set.s_hash[i]);
55408 + subj_map_set.s_hash[i] = NULL;
55409 + }
55410 + }
55411 +
55412 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
55413 + PAGE_SIZE)
55414 + kfree(subj_map_set.s_hash);
55415 + else
55416 + vfree(subj_map_set.s_hash);
55417 + }
55418 +
55419 + return;
55420 +}
55421 +
55422 +static void
55423 +free_variables(void)
55424 +{
55425 + struct acl_subject_label *s;
55426 + struct acl_role_label *r;
55427 + struct task_struct *task, *task2;
55428 + unsigned int x;
55429 +
55430 + gr_clear_learn_entries();
55431 +
55432 + read_lock(&tasklist_lock);
55433 + do_each_thread(task2, task) {
55434 + task->acl_sp_role = 0;
55435 + task->acl_role_id = 0;
55436 + task->acl = NULL;
55437 + task->role = NULL;
55438 + } while_each_thread(task2, task);
55439 + read_unlock(&tasklist_lock);
55440 +
55441 + /* release the reference to the real root dentry and vfsmount */
55442 + path_put(&real_root);
55443 + memset(&real_root, 0, sizeof(real_root));
55444 +
55445 + /* free all object hash tables */
55446 +
55447 + FOR_EACH_ROLE_START(r)
55448 + if (r->subj_hash == NULL)
55449 + goto next_role;
55450 + FOR_EACH_SUBJECT_START(r, s, x)
55451 + if (s->obj_hash == NULL)
55452 + break;
55453 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55454 + kfree(s->obj_hash);
55455 + else
55456 + vfree(s->obj_hash);
55457 + FOR_EACH_SUBJECT_END(s, x)
55458 + FOR_EACH_NESTED_SUBJECT_START(r, s)
55459 + if (s->obj_hash == NULL)
55460 + break;
55461 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
55462 + kfree(s->obj_hash);
55463 + else
55464 + vfree(s->obj_hash);
55465 + FOR_EACH_NESTED_SUBJECT_END(s)
55466 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
55467 + kfree(r->subj_hash);
55468 + else
55469 + vfree(r->subj_hash);
55470 + r->subj_hash = NULL;
55471 +next_role:
55472 + FOR_EACH_ROLE_END(r)
55473 +
55474 + acl_free_all();
55475 +
55476 + if (acl_role_set.r_hash) {
55477 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
55478 + PAGE_SIZE)
55479 + kfree(acl_role_set.r_hash);
55480 + else
55481 + vfree(acl_role_set.r_hash);
55482 + }
55483 + if (name_set.n_hash) {
55484 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
55485 + PAGE_SIZE)
55486 + kfree(name_set.n_hash);
55487 + else
55488 + vfree(name_set.n_hash);
55489 + }
55490 +
55491 + if (inodev_set.i_hash) {
55492 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
55493 + PAGE_SIZE)
55494 + kfree(inodev_set.i_hash);
55495 + else
55496 + vfree(inodev_set.i_hash);
55497 + }
55498 +
55499 + gr_free_uidset();
55500 +
55501 + memset(&name_set, 0, sizeof (struct name_db));
55502 + memset(&inodev_set, 0, sizeof (struct inodev_db));
55503 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
55504 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
55505 +
55506 + default_role = NULL;
55507 + kernel_role = NULL;
55508 + role_list = NULL;
55509 +
55510 + return;
55511 +}
55512 +
55513 +static __u32
55514 +count_user_objs(struct acl_object_label *userp)
55515 +{
55516 + struct acl_object_label o_tmp;
55517 + __u32 num = 0;
55518 +
55519 + while (userp) {
55520 + if (copy_from_user(&o_tmp, userp,
55521 + sizeof (struct acl_object_label)))
55522 + break;
55523 +
55524 + userp = o_tmp.prev;
55525 + num++;
55526 + }
55527 +
55528 + return num;
55529 +}
55530 +
55531 +static struct acl_subject_label *
55532 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
55533 +
55534 +static int
55535 +copy_user_glob(struct acl_object_label *obj)
55536 +{
55537 + struct acl_object_label *g_tmp, **guser;
55538 + unsigned int len;
55539 + char *tmp;
55540 +
55541 + if (obj->globbed == NULL)
55542 + return 0;
55543 +
55544 + guser = &obj->globbed;
55545 + while (*guser) {
55546 + g_tmp = (struct acl_object_label *)
55547 + acl_alloc(sizeof (struct acl_object_label));
55548 + if (g_tmp == NULL)
55549 + return -ENOMEM;
55550 +
55551 + if (copy_from_user(g_tmp, *guser,
55552 + sizeof (struct acl_object_label)))
55553 + return -EFAULT;
55554 +
55555 + len = strnlen_user(g_tmp->filename, PATH_MAX);
55556 +
55557 + if (!len || len >= PATH_MAX)
55558 + return -EINVAL;
55559 +
55560 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55561 + return -ENOMEM;
55562 +
55563 + if (copy_from_user(tmp, g_tmp->filename, len))
55564 + return -EFAULT;
55565 + tmp[len-1] = '\0';
55566 + g_tmp->filename = tmp;
55567 +
55568 + *guser = g_tmp;
55569 + guser = &(g_tmp->next);
55570 + }
55571 +
55572 + return 0;
55573 +}
55574 +
55575 +static int
55576 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
55577 + struct acl_role_label *role)
55578 +{
55579 + struct acl_object_label *o_tmp;
55580 + unsigned int len;
55581 + int ret;
55582 + char *tmp;
55583 +
55584 + while (userp) {
55585 + if ((o_tmp = (struct acl_object_label *)
55586 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
55587 + return -ENOMEM;
55588 +
55589 + if (copy_from_user(o_tmp, userp,
55590 + sizeof (struct acl_object_label)))
55591 + return -EFAULT;
55592 +
55593 + userp = o_tmp->prev;
55594 +
55595 + len = strnlen_user(o_tmp->filename, PATH_MAX);
55596 +
55597 + if (!len || len >= PATH_MAX)
55598 + return -EINVAL;
55599 +
55600 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55601 + return -ENOMEM;
55602 +
55603 + if (copy_from_user(tmp, o_tmp->filename, len))
55604 + return -EFAULT;
55605 + tmp[len-1] = '\0';
55606 + o_tmp->filename = tmp;
55607 +
55608 + insert_acl_obj_label(o_tmp, subj);
55609 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
55610 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
55611 + return -ENOMEM;
55612 +
55613 + ret = copy_user_glob(o_tmp);
55614 + if (ret)
55615 + return ret;
55616 +
55617 + if (o_tmp->nested) {
55618 + int already_copied;
55619 +
55620 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
55621 + if (IS_ERR(o_tmp->nested))
55622 + return PTR_ERR(o_tmp->nested);
55623 +
55624 + /* insert into nested subject list if we haven't copied this one yet
55625 + to prevent duplicate entries */
55626 + if (!already_copied) {
55627 + o_tmp->nested->next = role->hash->first;
55628 + role->hash->first = o_tmp->nested;
55629 + }
55630 + }
55631 + }
55632 +
55633 + return 0;
55634 +}
55635 +
55636 +static __u32
55637 +count_user_subjs(struct acl_subject_label *userp)
55638 +{
55639 + struct acl_subject_label s_tmp;
55640 + __u32 num = 0;
55641 +
55642 + while (userp) {
55643 + if (copy_from_user(&s_tmp, userp,
55644 + sizeof (struct acl_subject_label)))
55645 + break;
55646 +
55647 + userp = s_tmp.prev;
55648 + }
55649 +
55650 + return num;
55651 +}
55652 +
55653 +static int
55654 +copy_user_allowedips(struct acl_role_label *rolep)
55655 +{
55656 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
55657 +
55658 + ruserip = rolep->allowed_ips;
55659 +
55660 + while (ruserip) {
55661 + rlast = rtmp;
55662 +
55663 + if ((rtmp = (struct role_allowed_ip *)
55664 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
55665 + return -ENOMEM;
55666 +
55667 + if (copy_from_user(rtmp, ruserip,
55668 + sizeof (struct role_allowed_ip)))
55669 + return -EFAULT;
55670 +
55671 + ruserip = rtmp->prev;
55672 +
55673 + if (!rlast) {
55674 + rtmp->prev = NULL;
55675 + rolep->allowed_ips = rtmp;
55676 + } else {
55677 + rlast->next = rtmp;
55678 + rtmp->prev = rlast;
55679 + }
55680 +
55681 + if (!ruserip)
55682 + rtmp->next = NULL;
55683 + }
55684 +
55685 + return 0;
55686 +}
55687 +
55688 +static int
55689 +copy_user_transitions(struct acl_role_label *rolep)
55690 +{
55691 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
55692 +
55693 + unsigned int len;
55694 + char *tmp;
55695 +
55696 + rusertp = rolep->transitions;
55697 +
55698 + while (rusertp) {
55699 + rlast = rtmp;
55700 +
55701 + if ((rtmp = (struct role_transition *)
55702 + acl_alloc(sizeof (struct role_transition))) == NULL)
55703 + return -ENOMEM;
55704 +
55705 + if (copy_from_user(rtmp, rusertp,
55706 + sizeof (struct role_transition)))
55707 + return -EFAULT;
55708 +
55709 + rusertp = rtmp->prev;
55710 +
55711 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
55712 +
55713 + if (!len || len >= GR_SPROLE_LEN)
55714 + return -EINVAL;
55715 +
55716 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55717 + return -ENOMEM;
55718 +
55719 + if (copy_from_user(tmp, rtmp->rolename, len))
55720 + return -EFAULT;
55721 + tmp[len-1] = '\0';
55722 + rtmp->rolename = tmp;
55723 +
55724 + if (!rlast) {
55725 + rtmp->prev = NULL;
55726 + rolep->transitions = rtmp;
55727 + } else {
55728 + rlast->next = rtmp;
55729 + rtmp->prev = rlast;
55730 + }
55731 +
55732 + if (!rusertp)
55733 + rtmp->next = NULL;
55734 + }
55735 +
55736 + return 0;
55737 +}
55738 +
55739 +static struct acl_subject_label *
55740 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
55741 +{
55742 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
55743 + unsigned int len;
55744 + char *tmp;
55745 + __u32 num_objs;
55746 + struct acl_ip_label **i_tmp, *i_utmp2;
55747 + struct gr_hash_struct ghash;
55748 + struct subject_map *subjmap;
55749 + unsigned int i_num;
55750 + int err;
55751 +
55752 + if (already_copied != NULL)
55753 + *already_copied = 0;
55754 +
55755 + s_tmp = lookup_subject_map(userp);
55756 +
55757 + /* we've already copied this subject into the kernel, just return
55758 + the reference to it, and don't copy it over again
55759 + */
55760 + if (s_tmp) {
55761 + if (already_copied != NULL)
55762 + *already_copied = 1;
55763 + return(s_tmp);
55764 + }
55765 +
55766 + if ((s_tmp = (struct acl_subject_label *)
55767 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
55768 + return ERR_PTR(-ENOMEM);
55769 +
55770 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
55771 + if (subjmap == NULL)
55772 + return ERR_PTR(-ENOMEM);
55773 +
55774 + subjmap->user = userp;
55775 + subjmap->kernel = s_tmp;
55776 + insert_subj_map_entry(subjmap);
55777 +
55778 + if (copy_from_user(s_tmp, userp,
55779 + sizeof (struct acl_subject_label)))
55780 + return ERR_PTR(-EFAULT);
55781 +
55782 + len = strnlen_user(s_tmp->filename, PATH_MAX);
55783 +
55784 + if (!len || len >= PATH_MAX)
55785 + return ERR_PTR(-EINVAL);
55786 +
55787 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55788 + return ERR_PTR(-ENOMEM);
55789 +
55790 + if (copy_from_user(tmp, s_tmp->filename, len))
55791 + return ERR_PTR(-EFAULT);
55792 + tmp[len-1] = '\0';
55793 + s_tmp->filename = tmp;
55794 +
55795 + if (!strcmp(s_tmp->filename, "/"))
55796 + role->root_label = s_tmp;
55797 +
55798 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
55799 + return ERR_PTR(-EFAULT);
55800 +
55801 + /* copy user and group transition tables */
55802 +
55803 + if (s_tmp->user_trans_num) {
55804 + uid_t *uidlist;
55805 +
55806 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
55807 + if (uidlist == NULL)
55808 + return ERR_PTR(-ENOMEM);
55809 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
55810 + return ERR_PTR(-EFAULT);
55811 +
55812 + s_tmp->user_transitions = uidlist;
55813 + }
55814 +
55815 + if (s_tmp->group_trans_num) {
55816 + gid_t *gidlist;
55817 +
55818 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
55819 + if (gidlist == NULL)
55820 + return ERR_PTR(-ENOMEM);
55821 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
55822 + return ERR_PTR(-EFAULT);
55823 +
55824 + s_tmp->group_transitions = gidlist;
55825 + }
55826 +
55827 + /* set up object hash table */
55828 + num_objs = count_user_objs(ghash.first);
55829 +
55830 + s_tmp->obj_hash_size = num_objs;
55831 + s_tmp->obj_hash =
55832 + (struct acl_object_label **)
55833 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
55834 +
55835 + if (!s_tmp->obj_hash)
55836 + return ERR_PTR(-ENOMEM);
55837 +
55838 + memset(s_tmp->obj_hash, 0,
55839 + s_tmp->obj_hash_size *
55840 + sizeof (struct acl_object_label *));
55841 +
55842 + /* add in objects */
55843 + err = copy_user_objs(ghash.first, s_tmp, role);
55844 +
55845 + if (err)
55846 + return ERR_PTR(err);
55847 +
55848 + /* set pointer for parent subject */
55849 + if (s_tmp->parent_subject) {
55850 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
55851 +
55852 + if (IS_ERR(s_tmp2))
55853 + return s_tmp2;
55854 +
55855 + s_tmp->parent_subject = s_tmp2;
55856 + }
55857 +
55858 + /* add in ip acls */
55859 +
55860 + if (!s_tmp->ip_num) {
55861 + s_tmp->ips = NULL;
55862 + goto insert;
55863 + }
55864 +
55865 + i_tmp =
55866 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
55867 + sizeof (struct acl_ip_label *));
55868 +
55869 + if (!i_tmp)
55870 + return ERR_PTR(-ENOMEM);
55871 +
55872 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
55873 + *(i_tmp + i_num) =
55874 + (struct acl_ip_label *)
55875 + acl_alloc(sizeof (struct acl_ip_label));
55876 + if (!*(i_tmp + i_num))
55877 + return ERR_PTR(-ENOMEM);
55878 +
55879 + if (copy_from_user
55880 + (&i_utmp2, s_tmp->ips + i_num,
55881 + sizeof (struct acl_ip_label *)))
55882 + return ERR_PTR(-EFAULT);
55883 +
55884 + if (copy_from_user
55885 + (*(i_tmp + i_num), i_utmp2,
55886 + sizeof (struct acl_ip_label)))
55887 + return ERR_PTR(-EFAULT);
55888 +
55889 + if ((*(i_tmp + i_num))->iface == NULL)
55890 + continue;
55891 +
55892 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
55893 + if (!len || len >= IFNAMSIZ)
55894 + return ERR_PTR(-EINVAL);
55895 + tmp = acl_alloc(len);
55896 + if (tmp == NULL)
55897 + return ERR_PTR(-ENOMEM);
55898 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
55899 + return ERR_PTR(-EFAULT);
55900 + (*(i_tmp + i_num))->iface = tmp;
55901 + }
55902 +
55903 + s_tmp->ips = i_tmp;
55904 +
55905 +insert:
55906 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
55907 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
55908 + return ERR_PTR(-ENOMEM);
55909 +
55910 + return s_tmp;
55911 +}
55912 +
55913 +static int
55914 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
55915 +{
55916 + struct acl_subject_label s_pre;
55917 + struct acl_subject_label * ret;
55918 + int err;
55919 +
55920 + while (userp) {
55921 + if (copy_from_user(&s_pre, userp,
55922 + sizeof (struct acl_subject_label)))
55923 + return -EFAULT;
55924 +
55925 + ret = do_copy_user_subj(userp, role, NULL);
55926 +
55927 + err = PTR_ERR(ret);
55928 + if (IS_ERR(ret))
55929 + return err;
55930 +
55931 + insert_acl_subj_label(ret, role);
55932 +
55933 + userp = s_pre.prev;
55934 + }
55935 +
55936 + return 0;
55937 +}
55938 +
55939 +static int
55940 +copy_user_acl(struct gr_arg *arg)
55941 +{
55942 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
55943 + struct acl_subject_label *subj_list;
55944 + struct sprole_pw *sptmp;
55945 + struct gr_hash_struct *ghash;
55946 + uid_t *domainlist;
55947 + unsigned int r_num;
55948 + unsigned int len;
55949 + char *tmp;
55950 + int err = 0;
55951 + __u16 i;
55952 + __u32 num_subjs;
55953 +
55954 + /* we need a default and kernel role */
55955 + if (arg->role_db.num_roles < 2)
55956 + return -EINVAL;
55957 +
55958 + /* copy special role authentication info from userspace */
55959 +
55960 + num_sprole_pws = arg->num_sprole_pws;
55961 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
55962 +
55963 + if (!acl_special_roles && num_sprole_pws)
55964 + return -ENOMEM;
55965 +
55966 + for (i = 0; i < num_sprole_pws; i++) {
55967 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
55968 + if (!sptmp)
55969 + return -ENOMEM;
55970 + if (copy_from_user(sptmp, arg->sprole_pws + i,
55971 + sizeof (struct sprole_pw)))
55972 + return -EFAULT;
55973 +
55974 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
55975 +
55976 + if (!len || len >= GR_SPROLE_LEN)
55977 + return -EINVAL;
55978 +
55979 + if ((tmp = (char *) acl_alloc(len)) == NULL)
55980 + return -ENOMEM;
55981 +
55982 + if (copy_from_user(tmp, sptmp->rolename, len))
55983 + return -EFAULT;
55984 +
55985 + tmp[len-1] = '\0';
55986 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55987 + printk(KERN_ALERT "Copying special role %s\n", tmp);
55988 +#endif
55989 + sptmp->rolename = tmp;
55990 + acl_special_roles[i] = sptmp;
55991 + }
55992 +
55993 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
55994 +
55995 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
55996 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
55997 +
55998 + if (!r_tmp)
55999 + return -ENOMEM;
56000 +
56001 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
56002 + sizeof (struct acl_role_label *)))
56003 + return -EFAULT;
56004 +
56005 + if (copy_from_user(r_tmp, r_utmp2,
56006 + sizeof (struct acl_role_label)))
56007 + return -EFAULT;
56008 +
56009 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
56010 +
56011 + if (!len || len >= PATH_MAX)
56012 + return -EINVAL;
56013 +
56014 + if ((tmp = (char *) acl_alloc(len)) == NULL)
56015 + return -ENOMEM;
56016 +
56017 + if (copy_from_user(tmp, r_tmp->rolename, len))
56018 + return -EFAULT;
56019 +
56020 + tmp[len-1] = '\0';
56021 + r_tmp->rolename = tmp;
56022 +
56023 + if (!strcmp(r_tmp->rolename, "default")
56024 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
56025 + default_role = r_tmp;
56026 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
56027 + kernel_role = r_tmp;
56028 + }
56029 +
56030 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
56031 + return -ENOMEM;
56032 +
56033 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
56034 + return -EFAULT;
56035 +
56036 + r_tmp->hash = ghash;
56037 +
56038 + num_subjs = count_user_subjs(r_tmp->hash->first);
56039 +
56040 + r_tmp->subj_hash_size = num_subjs;
56041 + r_tmp->subj_hash =
56042 + (struct acl_subject_label **)
56043 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
56044 +
56045 + if (!r_tmp->subj_hash)
56046 + return -ENOMEM;
56047 +
56048 + err = copy_user_allowedips(r_tmp);
56049 + if (err)
56050 + return err;
56051 +
56052 + /* copy domain info */
56053 + if (r_tmp->domain_children != NULL) {
56054 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
56055 + if (domainlist == NULL)
56056 + return -ENOMEM;
56057 +
56058 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
56059 + return -EFAULT;
56060 +
56061 + r_tmp->domain_children = domainlist;
56062 + }
56063 +
56064 + err = copy_user_transitions(r_tmp);
56065 + if (err)
56066 + return err;
56067 +
56068 + memset(r_tmp->subj_hash, 0,
56069 + r_tmp->subj_hash_size *
56070 + sizeof (struct acl_subject_label *));
56071 +
56072 + /* acquire the list of subjects, then NULL out
56073 + the list prior to parsing the subjects for this role,
56074 + as during this parsing the list is replaced with a list
56075 + of *nested* subjects for the role
56076 + */
56077 + subj_list = r_tmp->hash->first;
56078 +
56079 + /* set nested subject list to null */
56080 + r_tmp->hash->first = NULL;
56081 +
56082 + err = copy_user_subjs(subj_list, r_tmp);
56083 +
56084 + if (err)
56085 + return err;
56086 +
56087 + insert_acl_role_label(r_tmp);
56088 + }
56089 +
56090 + if (default_role == NULL || kernel_role == NULL)
56091 + return -EINVAL;
56092 +
56093 + return err;
56094 +}
56095 +
56096 +static int
56097 +gracl_init(struct gr_arg *args)
56098 +{
56099 + int error = 0;
56100 +
56101 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
56102 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
56103 +
56104 + if (init_variables(args)) {
56105 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
56106 + error = -ENOMEM;
56107 + free_variables();
56108 + goto out;
56109 + }
56110 +
56111 + error = copy_user_acl(args);
56112 + free_init_variables();
56113 + if (error) {
56114 + free_variables();
56115 + goto out;
56116 + }
56117 +
56118 + if ((error = gr_set_acls(0))) {
56119 + free_variables();
56120 + goto out;
56121 + }
56122 +
56123 + pax_open_kernel();
56124 + gr_status |= GR_READY;
56125 + pax_close_kernel();
56126 +
56127 + out:
56128 + return error;
56129 +}
56130 +
56131 +/* derived from glibc fnmatch() 0: match, 1: no match*/
56132 +
56133 +static int
56134 +glob_match(const char *p, const char *n)
56135 +{
56136 + char c;
56137 +
56138 + while ((c = *p++) != '\0') {
56139 + switch (c) {
56140 + case '?':
56141 + if (*n == '\0')
56142 + return 1;
56143 + else if (*n == '/')
56144 + return 1;
56145 + break;
56146 + case '\\':
56147 + if (*n != c)
56148 + return 1;
56149 + break;
56150 + case '*':
56151 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
56152 + if (*n == '/')
56153 + return 1;
56154 + else if (c == '?') {
56155 + if (*n == '\0')
56156 + return 1;
56157 + else
56158 + ++n;
56159 + }
56160 + }
56161 + if (c == '\0') {
56162 + return 0;
56163 + } else {
56164 + const char *endp;
56165 +
56166 + if ((endp = strchr(n, '/')) == NULL)
56167 + endp = n + strlen(n);
56168 +
56169 + if (c == '[') {
56170 + for (--p; n < endp; ++n)
56171 + if (!glob_match(p, n))
56172 + return 0;
56173 + } else if (c == '/') {
56174 + while (*n != '\0' && *n != '/')
56175 + ++n;
56176 + if (*n == '/' && !glob_match(p, n + 1))
56177 + return 0;
56178 + } else {
56179 + for (--p; n < endp; ++n)
56180 + if (*n == c && !glob_match(p, n))
56181 + return 0;
56182 + }
56183 +
56184 + return 1;
56185 + }
56186 + case '[':
56187 + {
56188 + int not;
56189 + char cold;
56190 +
56191 + if (*n == '\0' || *n == '/')
56192 + return 1;
56193 +
56194 + not = (*p == '!' || *p == '^');
56195 + if (not)
56196 + ++p;
56197 +
56198 + c = *p++;
56199 + for (;;) {
56200 + unsigned char fn = (unsigned char)*n;
56201 +
56202 + if (c == '\0')
56203 + return 1;
56204 + else {
56205 + if (c == fn)
56206 + goto matched;
56207 + cold = c;
56208 + c = *p++;
56209 +
56210 + if (c == '-' && *p != ']') {
56211 + unsigned char cend = *p++;
56212 +
56213 + if (cend == '\0')
56214 + return 1;
56215 +
56216 + if (cold <= fn && fn <= cend)
56217 + goto matched;
56218 +
56219 + c = *p++;
56220 + }
56221 + }
56222 +
56223 + if (c == ']')
56224 + break;
56225 + }
56226 + if (!not)
56227 + return 1;
56228 + break;
56229 + matched:
56230 + while (c != ']') {
56231 + if (c == '\0')
56232 + return 1;
56233 +
56234 + c = *p++;
56235 + }
56236 + if (not)
56237 + return 1;
56238 + }
56239 + break;
56240 + default:
56241 + if (c != *n)
56242 + return 1;
56243 + }
56244 +
56245 + ++n;
56246 + }
56247 +
56248 + if (*n == '\0')
56249 + return 0;
56250 +
56251 + if (*n == '/')
56252 + return 0;
56253 +
56254 + return 1;
56255 +}
56256 +
56257 +static struct acl_object_label *
56258 +chk_glob_label(struct acl_object_label *globbed,
56259 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
56260 +{
56261 + struct acl_object_label *tmp;
56262 +
56263 + if (*path == NULL)
56264 + *path = gr_to_filename_nolock(dentry, mnt);
56265 +
56266 + tmp = globbed;
56267 +
56268 + while (tmp) {
56269 + if (!glob_match(tmp->filename, *path))
56270 + return tmp;
56271 + tmp = tmp->next;
56272 + }
56273 +
56274 + return NULL;
56275 +}
56276 +
56277 +static struct acl_object_label *
56278 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56279 + const ino_t curr_ino, const dev_t curr_dev,
56280 + const struct acl_subject_label *subj, char **path, const int checkglob)
56281 +{
56282 + struct acl_subject_label *tmpsubj;
56283 + struct acl_object_label *retval;
56284 + struct acl_object_label *retval2;
56285 +
56286 + tmpsubj = (struct acl_subject_label *) subj;
56287 + read_lock(&gr_inode_lock);
56288 + do {
56289 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
56290 + if (retval) {
56291 + if (checkglob && retval->globbed) {
56292 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
56293 + if (retval2)
56294 + retval = retval2;
56295 + }
56296 + break;
56297 + }
56298 + } while ((tmpsubj = tmpsubj->parent_subject));
56299 + read_unlock(&gr_inode_lock);
56300 +
56301 + return retval;
56302 +}
56303 +
56304 +static __inline__ struct acl_object_label *
56305 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
56306 + struct dentry *curr_dentry,
56307 + const struct acl_subject_label *subj, char **path, const int checkglob)
56308 +{
56309 + int newglob = checkglob;
56310 + ino_t inode;
56311 + dev_t device;
56312 +
56313 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
56314 + as we don't want a / * rule to match instead of the / object
56315 + don't do this for create lookups that call this function though, since they're looking up
56316 + on the parent and thus need globbing checks on all paths
56317 + */
56318 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
56319 + newglob = GR_NO_GLOB;
56320 +
56321 + spin_lock(&curr_dentry->d_lock);
56322 + inode = curr_dentry->d_inode->i_ino;
56323 + device = __get_dev(curr_dentry);
56324 + spin_unlock(&curr_dentry->d_lock);
56325 +
56326 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
56327 +}
56328 +
56329 +#ifdef CONFIG_HUGETLBFS
56330 +static inline bool
56331 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
56332 +{
56333 + int i;
56334 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
56335 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
56336 + return true;
56337 + }
56338 +
56339 + return false;
56340 +}
56341 +#endif
56342 +
56343 +static struct acl_object_label *
56344 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56345 + const struct acl_subject_label *subj, char *path, const int checkglob)
56346 +{
56347 + struct dentry *dentry = (struct dentry *) l_dentry;
56348 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56349 + struct mount *real_mnt = real_mount(mnt);
56350 + struct acl_object_label *retval;
56351 + struct dentry *parent;
56352 +
56353 + write_seqlock(&rename_lock);
56354 + br_read_lock(&vfsmount_lock);
56355 +
56356 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
56357 +#ifdef CONFIG_NET
56358 + mnt == sock_mnt ||
56359 +#endif
56360 +#ifdef CONFIG_HUGETLBFS
56361 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
56362 +#endif
56363 + /* ignore Eric Biederman */
56364 + IS_PRIVATE(l_dentry->d_inode))) {
56365 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
56366 + goto out;
56367 + }
56368 +
56369 + for (;;) {
56370 + if (dentry == real_root.dentry && mnt == real_root.mnt)
56371 + break;
56372 +
56373 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56374 + if (!mnt_has_parent(real_mnt))
56375 + break;
56376 +
56377 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56378 + if (retval != NULL)
56379 + goto out;
56380 +
56381 + dentry = real_mnt->mnt_mountpoint;
56382 + real_mnt = real_mnt->mnt_parent;
56383 + mnt = &real_mnt->mnt;
56384 + continue;
56385 + }
56386 +
56387 + parent = dentry->d_parent;
56388 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56389 + if (retval != NULL)
56390 + goto out;
56391 +
56392 + dentry = parent;
56393 + }
56394 +
56395 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
56396 +
56397 + /* real_root is pinned so we don't have to hold a reference */
56398 + if (retval == NULL)
56399 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
56400 +out:
56401 + br_read_unlock(&vfsmount_lock);
56402 + write_sequnlock(&rename_lock);
56403 +
56404 + BUG_ON(retval == NULL);
56405 +
56406 + return retval;
56407 +}
56408 +
56409 +static __inline__ struct acl_object_label *
56410 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56411 + const struct acl_subject_label *subj)
56412 +{
56413 + char *path = NULL;
56414 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
56415 +}
56416 +
56417 +static __inline__ struct acl_object_label *
56418 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56419 + const struct acl_subject_label *subj)
56420 +{
56421 + char *path = NULL;
56422 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
56423 +}
56424 +
56425 +static __inline__ struct acl_object_label *
56426 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56427 + const struct acl_subject_label *subj, char *path)
56428 +{
56429 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
56430 +}
56431 +
56432 +static struct acl_subject_label *
56433 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
56434 + const struct acl_role_label *role)
56435 +{
56436 + struct dentry *dentry = (struct dentry *) l_dentry;
56437 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
56438 + struct mount *real_mnt = real_mount(mnt);
56439 + struct acl_subject_label *retval;
56440 + struct dentry *parent;
56441 +
56442 + write_seqlock(&rename_lock);
56443 + br_read_lock(&vfsmount_lock);
56444 +
56445 + for (;;) {
56446 + if (dentry == real_root.dentry && mnt == real_root.mnt)
56447 + break;
56448 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
56449 + if (!mnt_has_parent(real_mnt))
56450 + break;
56451 +
56452 + spin_lock(&dentry->d_lock);
56453 + read_lock(&gr_inode_lock);
56454 + retval =
56455 + lookup_acl_subj_label(dentry->d_inode->i_ino,
56456 + __get_dev(dentry), role);
56457 + read_unlock(&gr_inode_lock);
56458 + spin_unlock(&dentry->d_lock);
56459 + if (retval != NULL)
56460 + goto out;
56461 +
56462 + dentry = real_mnt->mnt_mountpoint;
56463 + real_mnt = real_mnt->mnt_parent;
56464 + mnt = &real_mnt->mnt;
56465 + continue;
56466 + }
56467 +
56468 + spin_lock(&dentry->d_lock);
56469 + read_lock(&gr_inode_lock);
56470 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56471 + __get_dev(dentry), role);
56472 + read_unlock(&gr_inode_lock);
56473 + parent = dentry->d_parent;
56474 + spin_unlock(&dentry->d_lock);
56475 +
56476 + if (retval != NULL)
56477 + goto out;
56478 +
56479 + dentry = parent;
56480 + }
56481 +
56482 + spin_lock(&dentry->d_lock);
56483 + read_lock(&gr_inode_lock);
56484 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
56485 + __get_dev(dentry), role);
56486 + read_unlock(&gr_inode_lock);
56487 + spin_unlock(&dentry->d_lock);
56488 +
56489 + if (unlikely(retval == NULL)) {
56490 + /* real_root is pinned, we don't need to hold a reference */
56491 + read_lock(&gr_inode_lock);
56492 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
56493 + __get_dev(real_root.dentry), role);
56494 + read_unlock(&gr_inode_lock);
56495 + }
56496 +out:
56497 + br_read_unlock(&vfsmount_lock);
56498 + write_sequnlock(&rename_lock);
56499 +
56500 + BUG_ON(retval == NULL);
56501 +
56502 + return retval;
56503 +}
56504 +
56505 +static void
56506 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
56507 +{
56508 + struct task_struct *task = current;
56509 + const struct cred *cred = current_cred();
56510 +
56511 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
56512 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56513 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56514 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
56515 +
56516 + return;
56517 +}
56518 +
56519 +static void
56520 +gr_log_learn_id_change(const char type, const unsigned int real,
56521 + const unsigned int effective, const unsigned int fs)
56522 +{
56523 + struct task_struct *task = current;
56524 + const struct cred *cred = current_cred();
56525 +
56526 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
56527 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
56528 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
56529 + type, real, effective, fs, &task->signal->saved_ip);
56530 +
56531 + return;
56532 +}
56533 +
56534 +__u32
56535 +gr_search_file(const struct dentry * dentry, const __u32 mode,
56536 + const struct vfsmount * mnt)
56537 +{
56538 + __u32 retval = mode;
56539 + struct acl_subject_label *curracl;
56540 + struct acl_object_label *currobj;
56541 +
56542 + if (unlikely(!(gr_status & GR_READY)))
56543 + return (mode & ~GR_AUDITS);
56544 +
56545 + curracl = current->acl;
56546 +
56547 + currobj = chk_obj_label(dentry, mnt, curracl);
56548 + retval = currobj->mode & mode;
56549 +
56550 + /* if we're opening a specified transfer file for writing
56551 + (e.g. /dev/initctl), then transfer our role to init
56552 + */
56553 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
56554 + current->role->roletype & GR_ROLE_PERSIST)) {
56555 + struct task_struct *task = init_pid_ns.child_reaper;
56556 +
56557 + if (task->role != current->role) {
56558 + task->acl_sp_role = 0;
56559 + task->acl_role_id = current->acl_role_id;
56560 + task->role = current->role;
56561 + rcu_read_lock();
56562 + read_lock(&grsec_exec_file_lock);
56563 + gr_apply_subject_to_task(task);
56564 + read_unlock(&grsec_exec_file_lock);
56565 + rcu_read_unlock();
56566 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
56567 + }
56568 + }
56569 +
56570 + if (unlikely
56571 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
56572 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
56573 + __u32 new_mode = mode;
56574 +
56575 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56576 +
56577 + retval = new_mode;
56578 +
56579 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
56580 + new_mode |= GR_INHERIT;
56581 +
56582 + if (!(mode & GR_NOLEARN))
56583 + gr_log_learn(dentry, mnt, new_mode);
56584 + }
56585 +
56586 + return retval;
56587 +}
56588 +
56589 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
56590 + const struct dentry *parent,
56591 + const struct vfsmount *mnt)
56592 +{
56593 + struct name_entry *match;
56594 + struct acl_object_label *matchpo;
56595 + struct acl_subject_label *curracl;
56596 + char *path;
56597 +
56598 + if (unlikely(!(gr_status & GR_READY)))
56599 + return NULL;
56600 +
56601 + preempt_disable();
56602 + path = gr_to_filename_rbac(new_dentry, mnt);
56603 + match = lookup_name_entry_create(path);
56604 +
56605 + curracl = current->acl;
56606 +
56607 + if (match) {
56608 + read_lock(&gr_inode_lock);
56609 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
56610 + read_unlock(&gr_inode_lock);
56611 +
56612 + if (matchpo) {
56613 + preempt_enable();
56614 + return matchpo;
56615 + }
56616 + }
56617 +
56618 + // lookup parent
56619 +
56620 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
56621 +
56622 + preempt_enable();
56623 + return matchpo;
56624 +}
56625 +
56626 +__u32
56627 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
56628 + const struct vfsmount * mnt, const __u32 mode)
56629 +{
56630 + struct acl_object_label *matchpo;
56631 + __u32 retval;
56632 +
56633 + if (unlikely(!(gr_status & GR_READY)))
56634 + return (mode & ~GR_AUDITS);
56635 +
56636 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
56637 +
56638 + retval = matchpo->mode & mode;
56639 +
56640 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
56641 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
56642 + __u32 new_mode = mode;
56643 +
56644 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
56645 +
56646 + gr_log_learn(new_dentry, mnt, new_mode);
56647 + return new_mode;
56648 + }
56649 +
56650 + return retval;
56651 +}
56652 +
56653 +__u32
56654 +gr_check_link(const struct dentry * new_dentry,
56655 + const struct dentry * parent_dentry,
56656 + const struct vfsmount * parent_mnt,
56657 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
56658 +{
56659 + struct acl_object_label *obj;
56660 + __u32 oldmode, newmode;
56661 + __u32 needmode;
56662 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
56663 + GR_DELETE | GR_INHERIT;
56664 +
56665 + if (unlikely(!(gr_status & GR_READY)))
56666 + return (GR_CREATE | GR_LINK);
56667 +
56668 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
56669 + oldmode = obj->mode;
56670 +
56671 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
56672 + newmode = obj->mode;
56673 +
56674 + needmode = newmode & checkmodes;
56675 +
56676 + // old name for hardlink must have at least the permissions of the new name
56677 + if ((oldmode & needmode) != needmode)
56678 + goto bad;
56679 +
56680 + // if old name had restrictions/auditing, make sure the new name does as well
56681 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
56682 +
56683 + // don't allow hardlinking of suid/sgid/fcapped files without permission
56684 + if (is_privileged_binary(old_dentry))
56685 + needmode |= GR_SETID;
56686 +
56687 + if ((newmode & needmode) != needmode)
56688 + goto bad;
56689 +
56690 + // enforce minimum permissions
56691 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
56692 + return newmode;
56693 +bad:
56694 + needmode = oldmode;
56695 + if (is_privileged_binary(old_dentry))
56696 + needmode |= GR_SETID;
56697 +
56698 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
56699 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
56700 + return (GR_CREATE | GR_LINK);
56701 + } else if (newmode & GR_SUPPRESS)
56702 + return GR_SUPPRESS;
56703 + else
56704 + return 0;
56705 +}
56706 +
56707 +int
56708 +gr_check_hidden_task(const struct task_struct *task)
56709 +{
56710 + if (unlikely(!(gr_status & GR_READY)))
56711 + return 0;
56712 +
56713 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
56714 + return 1;
56715 +
56716 + return 0;
56717 +}
56718 +
56719 +int
56720 +gr_check_protected_task(const struct task_struct *task)
56721 +{
56722 + if (unlikely(!(gr_status & GR_READY) || !task))
56723 + return 0;
56724 +
56725 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56726 + task->acl != current->acl)
56727 + return 1;
56728 +
56729 + return 0;
56730 +}
56731 +
56732 +int
56733 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
56734 +{
56735 + struct task_struct *p;
56736 + int ret = 0;
56737 +
56738 + if (unlikely(!(gr_status & GR_READY) || !pid))
56739 + return ret;
56740 +
56741 + read_lock(&tasklist_lock);
56742 + do_each_pid_task(pid, type, p) {
56743 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
56744 + p->acl != current->acl) {
56745 + ret = 1;
56746 + goto out;
56747 + }
56748 + } while_each_pid_task(pid, type, p);
56749 +out:
56750 + read_unlock(&tasklist_lock);
56751 +
56752 + return ret;
56753 +}
56754 +
56755 +void
56756 +gr_copy_label(struct task_struct *tsk)
56757 +{
56758 + tsk->signal->used_accept = 0;
56759 + tsk->acl_sp_role = 0;
56760 + tsk->acl_role_id = current->acl_role_id;
56761 + tsk->acl = current->acl;
56762 + tsk->role = current->role;
56763 + tsk->signal->curr_ip = current->signal->curr_ip;
56764 + tsk->signal->saved_ip = current->signal->saved_ip;
56765 + if (current->exec_file)
56766 + get_file(current->exec_file);
56767 + tsk->exec_file = current->exec_file;
56768 + tsk->is_writable = current->is_writable;
56769 + if (unlikely(current->signal->used_accept)) {
56770 + current->signal->curr_ip = 0;
56771 + current->signal->saved_ip = 0;
56772 + }
56773 +
56774 + return;
56775 +}
56776 +
56777 +static void
56778 +gr_set_proc_res(struct task_struct *task)
56779 +{
56780 + struct acl_subject_label *proc;
56781 + unsigned short i;
56782 +
56783 + proc = task->acl;
56784 +
56785 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
56786 + return;
56787 +
56788 + for (i = 0; i < RLIM_NLIMITS; i++) {
56789 + if (!(proc->resmask & (1 << i)))
56790 + continue;
56791 +
56792 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
56793 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
56794 + }
56795 +
56796 + return;
56797 +}
56798 +
56799 +extern int __gr_process_user_ban(struct user_struct *user);
56800 +
56801 +int
56802 +gr_check_user_change(int real, int effective, int fs)
56803 +{
56804 + unsigned int i;
56805 + __u16 num;
56806 + uid_t *uidlist;
56807 + int curuid;
56808 + int realok = 0;
56809 + int effectiveok = 0;
56810 + int fsok = 0;
56811 +
56812 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
56813 + struct user_struct *user;
56814 +
56815 + if (real == -1)
56816 + goto skipit;
56817 +
56818 + user = find_user(real);
56819 + if (user == NULL)
56820 + goto skipit;
56821 +
56822 + if (__gr_process_user_ban(user)) {
56823 + /* for find_user */
56824 + free_uid(user);
56825 + return 1;
56826 + }
56827 +
56828 + /* for find_user */
56829 + free_uid(user);
56830 +
56831 +skipit:
56832 +#endif
56833 +
56834 + if (unlikely(!(gr_status & GR_READY)))
56835 + return 0;
56836 +
56837 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56838 + gr_log_learn_id_change('u', real, effective, fs);
56839 +
56840 + num = current->acl->user_trans_num;
56841 + uidlist = current->acl->user_transitions;
56842 +
56843 + if (uidlist == NULL)
56844 + return 0;
56845 +
56846 + if (real == -1)
56847 + realok = 1;
56848 + if (effective == -1)
56849 + effectiveok = 1;
56850 + if (fs == -1)
56851 + fsok = 1;
56852 +
56853 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
56854 + for (i = 0; i < num; i++) {
56855 + curuid = (int)uidlist[i];
56856 + if (real == curuid)
56857 + realok = 1;
56858 + if (effective == curuid)
56859 + effectiveok = 1;
56860 + if (fs == curuid)
56861 + fsok = 1;
56862 + }
56863 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
56864 + for (i = 0; i < num; i++) {
56865 + curuid = (int)uidlist[i];
56866 + if (real == curuid)
56867 + break;
56868 + if (effective == curuid)
56869 + break;
56870 + if (fs == curuid)
56871 + break;
56872 + }
56873 + /* not in deny list */
56874 + if (i == num) {
56875 + realok = 1;
56876 + effectiveok = 1;
56877 + fsok = 1;
56878 + }
56879 + }
56880 +
56881 + if (realok && effectiveok && fsok)
56882 + return 0;
56883 + else {
56884 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56885 + return 1;
56886 + }
56887 +}
56888 +
56889 +int
56890 +gr_check_group_change(int real, int effective, int fs)
56891 +{
56892 + unsigned int i;
56893 + __u16 num;
56894 + gid_t *gidlist;
56895 + int curgid;
56896 + int realok = 0;
56897 + int effectiveok = 0;
56898 + int fsok = 0;
56899 +
56900 + if (unlikely(!(gr_status & GR_READY)))
56901 + return 0;
56902 +
56903 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
56904 + gr_log_learn_id_change('g', real, effective, fs);
56905 +
56906 + num = current->acl->group_trans_num;
56907 + gidlist = current->acl->group_transitions;
56908 +
56909 + if (gidlist == NULL)
56910 + return 0;
56911 +
56912 + if (real == -1)
56913 + realok = 1;
56914 + if (effective == -1)
56915 + effectiveok = 1;
56916 + if (fs == -1)
56917 + fsok = 1;
56918 +
56919 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
56920 + for (i = 0; i < num; i++) {
56921 + curgid = (int)gidlist[i];
56922 + if (real == curgid)
56923 + realok = 1;
56924 + if (effective == curgid)
56925 + effectiveok = 1;
56926 + if (fs == curgid)
56927 + fsok = 1;
56928 + }
56929 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
56930 + for (i = 0; i < num; i++) {
56931 + curgid = (int)gidlist[i];
56932 + if (real == curgid)
56933 + break;
56934 + if (effective == curgid)
56935 + break;
56936 + if (fs == curgid)
56937 + break;
56938 + }
56939 + /* not in deny list */
56940 + if (i == num) {
56941 + realok = 1;
56942 + effectiveok = 1;
56943 + fsok = 1;
56944 + }
56945 + }
56946 +
56947 + if (realok && effectiveok && fsok)
56948 + return 0;
56949 + else {
56950 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
56951 + return 1;
56952 + }
56953 +}
56954 +
56955 +extern int gr_acl_is_capable(const int cap);
56956 +
56957 +void
56958 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
56959 +{
56960 + struct acl_role_label *role = task->role;
56961 + struct acl_subject_label *subj = NULL;
56962 + struct acl_object_label *obj;
56963 + struct file *filp;
56964 +
56965 + if (unlikely(!(gr_status & GR_READY)))
56966 + return;
56967 +
56968 + filp = task->exec_file;
56969 +
56970 + /* kernel process, we'll give them the kernel role */
56971 + if (unlikely(!filp)) {
56972 + task->role = kernel_role;
56973 + task->acl = kernel_role->root_label;
56974 + return;
56975 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
56976 + role = lookup_acl_role_label(task, uid, gid);
56977 +
56978 + /* don't change the role if we're not a privileged process */
56979 + if (role && task->role != role &&
56980 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
56981 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
56982 + return;
56983 +
56984 + /* perform subject lookup in possibly new role
56985 + we can use this result below in the case where role == task->role
56986 + */
56987 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
56988 +
56989 + /* if we changed uid/gid, but result in the same role
56990 + and are using inheritance, don't lose the inherited subject
56991 + if current subject is other than what normal lookup
56992 + would result in, we arrived via inheritance, don't
56993 + lose subject
56994 + */
56995 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
56996 + (subj == task->acl)))
56997 + task->acl = subj;
56998 +
56999 + task->role = role;
57000 +
57001 + task->is_writable = 0;
57002 +
57003 + /* ignore additional mmap checks for processes that are writable
57004 + by the default ACL */
57005 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57006 + if (unlikely(obj->mode & GR_WRITE))
57007 + task->is_writable = 1;
57008 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57009 + if (unlikely(obj->mode & GR_WRITE))
57010 + task->is_writable = 1;
57011 +
57012 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57013 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57014 +#endif
57015 +
57016 + gr_set_proc_res(task);
57017 +
57018 + return;
57019 +}
57020 +
57021 +int
57022 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57023 + const int unsafe_flags)
57024 +{
57025 + struct task_struct *task = current;
57026 + struct acl_subject_label *newacl;
57027 + struct acl_object_label *obj;
57028 + __u32 retmode;
57029 +
57030 + if (unlikely(!(gr_status & GR_READY)))
57031 + return 0;
57032 +
57033 + newacl = chk_subj_label(dentry, mnt, task->role);
57034 +
57035 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
57036 + did an exec
57037 + */
57038 + rcu_read_lock();
57039 + read_lock(&tasklist_lock);
57040 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
57041 + (task->parent->acl->mode & GR_POVERRIDE))) {
57042 + read_unlock(&tasklist_lock);
57043 + rcu_read_unlock();
57044 + goto skip_check;
57045 + }
57046 + read_unlock(&tasklist_lock);
57047 + rcu_read_unlock();
57048 +
57049 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
57050 + !(task->role->roletype & GR_ROLE_GOD) &&
57051 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
57052 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
57053 + if (unsafe_flags & LSM_UNSAFE_SHARE)
57054 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
57055 + else
57056 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
57057 + return -EACCES;
57058 + }
57059 +
57060 +skip_check:
57061 +
57062 + obj = chk_obj_label(dentry, mnt, task->acl);
57063 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
57064 +
57065 + if (!(task->acl->mode & GR_INHERITLEARN) &&
57066 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
57067 + if (obj->nested)
57068 + task->acl = obj->nested;
57069 + else
57070 + task->acl = newacl;
57071 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
57072 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
57073 +
57074 + task->is_writable = 0;
57075 +
57076 + /* ignore additional mmap checks for processes that are writable
57077 + by the default ACL */
57078 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
57079 + if (unlikely(obj->mode & GR_WRITE))
57080 + task->is_writable = 1;
57081 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
57082 + if (unlikely(obj->mode & GR_WRITE))
57083 + task->is_writable = 1;
57084 +
57085 + gr_set_proc_res(task);
57086 +
57087 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57088 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57089 +#endif
57090 + return 0;
57091 +}
57092 +
57093 +/* always called with valid inodev ptr */
57094 +static void
57095 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
57096 +{
57097 + struct acl_object_label *matchpo;
57098 + struct acl_subject_label *matchps;
57099 + struct acl_subject_label *subj;
57100 + struct acl_role_label *role;
57101 + unsigned int x;
57102 +
57103 + FOR_EACH_ROLE_START(role)
57104 + FOR_EACH_SUBJECT_START(role, subj, x)
57105 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57106 + matchpo->mode |= GR_DELETED;
57107 + FOR_EACH_SUBJECT_END(subj,x)
57108 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
57109 + /* nested subjects aren't in the role's subj_hash table */
57110 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
57111 + matchpo->mode |= GR_DELETED;
57112 + FOR_EACH_NESTED_SUBJECT_END(subj)
57113 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
57114 + matchps->mode |= GR_DELETED;
57115 + FOR_EACH_ROLE_END(role)
57116 +
57117 + inodev->nentry->deleted = 1;
57118 +
57119 + return;
57120 +}
57121 +
57122 +void
57123 +gr_handle_delete(const ino_t ino, const dev_t dev)
57124 +{
57125 + struct inodev_entry *inodev;
57126 +
57127 + if (unlikely(!(gr_status & GR_READY)))
57128 + return;
57129 +
57130 + write_lock(&gr_inode_lock);
57131 + inodev = lookup_inodev_entry(ino, dev);
57132 + if (inodev != NULL)
57133 + do_handle_delete(inodev, ino, dev);
57134 + write_unlock(&gr_inode_lock);
57135 +
57136 + return;
57137 +}
57138 +
57139 +static void
57140 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
57141 + const ino_t newinode, const dev_t newdevice,
57142 + struct acl_subject_label *subj)
57143 +{
57144 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
57145 + struct acl_object_label *match;
57146 +
57147 + match = subj->obj_hash[index];
57148 +
57149 + while (match && (match->inode != oldinode ||
57150 + match->device != olddevice ||
57151 + !(match->mode & GR_DELETED)))
57152 + match = match->next;
57153 +
57154 + if (match && (match->inode == oldinode)
57155 + && (match->device == olddevice)
57156 + && (match->mode & GR_DELETED)) {
57157 + if (match->prev == NULL) {
57158 + subj->obj_hash[index] = match->next;
57159 + if (match->next != NULL)
57160 + match->next->prev = NULL;
57161 + } else {
57162 + match->prev->next = match->next;
57163 + if (match->next != NULL)
57164 + match->next->prev = match->prev;
57165 + }
57166 + match->prev = NULL;
57167 + match->next = NULL;
57168 + match->inode = newinode;
57169 + match->device = newdevice;
57170 + match->mode &= ~GR_DELETED;
57171 +
57172 + insert_acl_obj_label(match, subj);
57173 + }
57174 +
57175 + return;
57176 +}
57177 +
57178 +static void
57179 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
57180 + const ino_t newinode, const dev_t newdevice,
57181 + struct acl_role_label *role)
57182 +{
57183 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
57184 + struct acl_subject_label *match;
57185 +
57186 + match = role->subj_hash[index];
57187 +
57188 + while (match && (match->inode != oldinode ||
57189 + match->device != olddevice ||
57190 + !(match->mode & GR_DELETED)))
57191 + match = match->next;
57192 +
57193 + if (match && (match->inode == oldinode)
57194 + && (match->device == olddevice)
57195 + && (match->mode & GR_DELETED)) {
57196 + if (match->prev == NULL) {
57197 + role->subj_hash[index] = match->next;
57198 + if (match->next != NULL)
57199 + match->next->prev = NULL;
57200 + } else {
57201 + match->prev->next = match->next;
57202 + if (match->next != NULL)
57203 + match->next->prev = match->prev;
57204 + }
57205 + match->prev = NULL;
57206 + match->next = NULL;
57207 + match->inode = newinode;
57208 + match->device = newdevice;
57209 + match->mode &= ~GR_DELETED;
57210 +
57211 + insert_acl_subj_label(match, role);
57212 + }
57213 +
57214 + return;
57215 +}
57216 +
57217 +static void
57218 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
57219 + const ino_t newinode, const dev_t newdevice)
57220 +{
57221 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
57222 + struct inodev_entry *match;
57223 +
57224 + match = inodev_set.i_hash[index];
57225 +
57226 + while (match && (match->nentry->inode != oldinode ||
57227 + match->nentry->device != olddevice || !match->nentry->deleted))
57228 + match = match->next;
57229 +
57230 + if (match && (match->nentry->inode == oldinode)
57231 + && (match->nentry->device == olddevice) &&
57232 + match->nentry->deleted) {
57233 + if (match->prev == NULL) {
57234 + inodev_set.i_hash[index] = match->next;
57235 + if (match->next != NULL)
57236 + match->next->prev = NULL;
57237 + } else {
57238 + match->prev->next = match->next;
57239 + if (match->next != NULL)
57240 + match->next->prev = match->prev;
57241 + }
57242 + match->prev = NULL;
57243 + match->next = NULL;
57244 + match->nentry->inode = newinode;
57245 + match->nentry->device = newdevice;
57246 + match->nentry->deleted = 0;
57247 +
57248 + insert_inodev_entry(match);
57249 + }
57250 +
57251 + return;
57252 +}
57253 +
57254 +static void
57255 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
57256 +{
57257 + struct acl_subject_label *subj;
57258 + struct acl_role_label *role;
57259 + unsigned int x;
57260 +
57261 + FOR_EACH_ROLE_START(role)
57262 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
57263 +
57264 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
57265 + if ((subj->inode == ino) && (subj->device == dev)) {
57266 + subj->inode = ino;
57267 + subj->device = dev;
57268 + }
57269 + /* nested subjects aren't in the role's subj_hash table */
57270 + update_acl_obj_label(matchn->inode, matchn->device,
57271 + ino, dev, subj);
57272 + FOR_EACH_NESTED_SUBJECT_END(subj)
57273 + FOR_EACH_SUBJECT_START(role, subj, x)
57274 + update_acl_obj_label(matchn->inode, matchn->device,
57275 + ino, dev, subj);
57276 + FOR_EACH_SUBJECT_END(subj,x)
57277 + FOR_EACH_ROLE_END(role)
57278 +
57279 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
57280 +
57281 + return;
57282 +}
57283 +
57284 +static void
57285 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
57286 + const struct vfsmount *mnt)
57287 +{
57288 + ino_t ino = dentry->d_inode->i_ino;
57289 + dev_t dev = __get_dev(dentry);
57290 +
57291 + __do_handle_create(matchn, ino, dev);
57292 +
57293 + return;
57294 +}
57295 +
57296 +void
57297 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57298 +{
57299 + struct name_entry *matchn;
57300 +
57301 + if (unlikely(!(gr_status & GR_READY)))
57302 + return;
57303 +
57304 + preempt_disable();
57305 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
57306 +
57307 + if (unlikely((unsigned long)matchn)) {
57308 + write_lock(&gr_inode_lock);
57309 + do_handle_create(matchn, dentry, mnt);
57310 + write_unlock(&gr_inode_lock);
57311 + }
57312 + preempt_enable();
57313 +
57314 + return;
57315 +}
57316 +
57317 +void
57318 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57319 +{
57320 + struct name_entry *matchn;
57321 +
57322 + if (unlikely(!(gr_status & GR_READY)))
57323 + return;
57324 +
57325 + preempt_disable();
57326 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
57327 +
57328 + if (unlikely((unsigned long)matchn)) {
57329 + write_lock(&gr_inode_lock);
57330 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
57331 + write_unlock(&gr_inode_lock);
57332 + }
57333 + preempt_enable();
57334 +
57335 + return;
57336 +}
57337 +
57338 +void
57339 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57340 + struct dentry *old_dentry,
57341 + struct dentry *new_dentry,
57342 + struct vfsmount *mnt, const __u8 replace)
57343 +{
57344 + struct name_entry *matchn;
57345 + struct inodev_entry *inodev;
57346 + struct inode *inode = new_dentry->d_inode;
57347 + ino_t old_ino = old_dentry->d_inode->i_ino;
57348 + dev_t old_dev = __get_dev(old_dentry);
57349 +
57350 + /* vfs_rename swaps the name and parent link for old_dentry and
57351 + new_dentry
57352 + at this point, old_dentry has the new name, parent link, and inode
57353 + for the renamed file
57354 + if a file is being replaced by a rename, new_dentry has the inode
57355 + and name for the replaced file
57356 + */
57357 +
57358 + if (unlikely(!(gr_status & GR_READY)))
57359 + return;
57360 +
57361 + preempt_disable();
57362 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
57363 +
57364 + /* we wouldn't have to check d_inode if it weren't for
57365 + NFS silly-renaming
57366 + */
57367 +
57368 + write_lock(&gr_inode_lock);
57369 + if (unlikely(replace && inode)) {
57370 + ino_t new_ino = inode->i_ino;
57371 + dev_t new_dev = __get_dev(new_dentry);
57372 +
57373 + inodev = lookup_inodev_entry(new_ino, new_dev);
57374 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
57375 + do_handle_delete(inodev, new_ino, new_dev);
57376 + }
57377 +
57378 + inodev = lookup_inodev_entry(old_ino, old_dev);
57379 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
57380 + do_handle_delete(inodev, old_ino, old_dev);
57381 +
57382 + if (unlikely((unsigned long)matchn))
57383 + do_handle_create(matchn, old_dentry, mnt);
57384 +
57385 + write_unlock(&gr_inode_lock);
57386 + preempt_enable();
57387 +
57388 + return;
57389 +}
57390 +
57391 +static int
57392 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
57393 + unsigned char **sum)
57394 +{
57395 + struct acl_role_label *r;
57396 + struct role_allowed_ip *ipp;
57397 + struct role_transition *trans;
57398 + unsigned int i;
57399 + int found = 0;
57400 + u32 curr_ip = current->signal->curr_ip;
57401 +
57402 + current->signal->saved_ip = curr_ip;
57403 +
57404 + /* check transition table */
57405 +
57406 + for (trans = current->role->transitions; trans; trans = trans->next) {
57407 + if (!strcmp(rolename, trans->rolename)) {
57408 + found = 1;
57409 + break;
57410 + }
57411 + }
57412 +
57413 + if (!found)
57414 + return 0;
57415 +
57416 + /* handle special roles that do not require authentication
57417 + and check ip */
57418 +
57419 + FOR_EACH_ROLE_START(r)
57420 + if (!strcmp(rolename, r->rolename) &&
57421 + (r->roletype & GR_ROLE_SPECIAL)) {
57422 + found = 0;
57423 + if (r->allowed_ips != NULL) {
57424 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
57425 + if ((ntohl(curr_ip) & ipp->netmask) ==
57426 + (ntohl(ipp->addr) & ipp->netmask))
57427 + found = 1;
57428 + }
57429 + } else
57430 + found = 2;
57431 + if (!found)
57432 + return 0;
57433 +
57434 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
57435 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
57436 + *salt = NULL;
57437 + *sum = NULL;
57438 + return 1;
57439 + }
57440 + }
57441 + FOR_EACH_ROLE_END(r)
57442 +
57443 + for (i = 0; i < num_sprole_pws; i++) {
57444 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
57445 + *salt = acl_special_roles[i]->salt;
57446 + *sum = acl_special_roles[i]->sum;
57447 + return 1;
57448 + }
57449 + }
57450 +
57451 + return 0;
57452 +}
57453 +
57454 +static void
57455 +assign_special_role(char *rolename)
57456 +{
57457 + struct acl_object_label *obj;
57458 + struct acl_role_label *r;
57459 + struct acl_role_label *assigned = NULL;
57460 + struct task_struct *tsk;
57461 + struct file *filp;
57462 +
57463 + FOR_EACH_ROLE_START(r)
57464 + if (!strcmp(rolename, r->rolename) &&
57465 + (r->roletype & GR_ROLE_SPECIAL)) {
57466 + assigned = r;
57467 + break;
57468 + }
57469 + FOR_EACH_ROLE_END(r)
57470 +
57471 + if (!assigned)
57472 + return;
57473 +
57474 + read_lock(&tasklist_lock);
57475 + read_lock(&grsec_exec_file_lock);
57476 +
57477 + tsk = current->real_parent;
57478 + if (tsk == NULL)
57479 + goto out_unlock;
57480 +
57481 + filp = tsk->exec_file;
57482 + if (filp == NULL)
57483 + goto out_unlock;
57484 +
57485 + tsk->is_writable = 0;
57486 +
57487 + tsk->acl_sp_role = 1;
57488 + tsk->acl_role_id = ++acl_sp_role_value;
57489 + tsk->role = assigned;
57490 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
57491 +
57492 + /* ignore additional mmap checks for processes that are writable
57493 + by the default ACL */
57494 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57495 + if (unlikely(obj->mode & GR_WRITE))
57496 + tsk->is_writable = 1;
57497 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
57498 + if (unlikely(obj->mode & GR_WRITE))
57499 + tsk->is_writable = 1;
57500 +
57501 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57502 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
57503 +#endif
57504 +
57505 +out_unlock:
57506 + read_unlock(&grsec_exec_file_lock);
57507 + read_unlock(&tasklist_lock);
57508 + return;
57509 +}
57510 +
57511 +int gr_check_secure_terminal(struct task_struct *task)
57512 +{
57513 + struct task_struct *p, *p2, *p3;
57514 + struct files_struct *files;
57515 + struct fdtable *fdt;
57516 + struct file *our_file = NULL, *file;
57517 + int i;
57518 +
57519 + if (task->signal->tty == NULL)
57520 + return 1;
57521 +
57522 + files = get_files_struct(task);
57523 + if (files != NULL) {
57524 + rcu_read_lock();
57525 + fdt = files_fdtable(files);
57526 + for (i=0; i < fdt->max_fds; i++) {
57527 + file = fcheck_files(files, i);
57528 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
57529 + get_file(file);
57530 + our_file = file;
57531 + }
57532 + }
57533 + rcu_read_unlock();
57534 + put_files_struct(files);
57535 + }
57536 +
57537 + if (our_file == NULL)
57538 + return 1;
57539 +
57540 + read_lock(&tasklist_lock);
57541 + do_each_thread(p2, p) {
57542 + files = get_files_struct(p);
57543 + if (files == NULL ||
57544 + (p->signal && p->signal->tty == task->signal->tty)) {
57545 + if (files != NULL)
57546 + put_files_struct(files);
57547 + continue;
57548 + }
57549 + rcu_read_lock();
57550 + fdt = files_fdtable(files);
57551 + for (i=0; i < fdt->max_fds; i++) {
57552 + file = fcheck_files(files, i);
57553 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
57554 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
57555 + p3 = task;
57556 + while (p3->pid > 0) {
57557 + if (p3 == p)
57558 + break;
57559 + p3 = p3->real_parent;
57560 + }
57561 + if (p3 == p)
57562 + break;
57563 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
57564 + gr_handle_alertkill(p);
57565 + rcu_read_unlock();
57566 + put_files_struct(files);
57567 + read_unlock(&tasklist_lock);
57568 + fput(our_file);
57569 + return 0;
57570 + }
57571 + }
57572 + rcu_read_unlock();
57573 + put_files_struct(files);
57574 + } while_each_thread(p2, p);
57575 + read_unlock(&tasklist_lock);
57576 +
57577 + fput(our_file);
57578 + return 1;
57579 +}
57580 +
57581 +static int gr_rbac_disable(void *unused)
57582 +{
57583 + pax_open_kernel();
57584 + gr_status &= ~GR_READY;
57585 + pax_close_kernel();
57586 +
57587 + return 0;
57588 +}
57589 +
57590 +ssize_t
57591 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
57592 +{
57593 + struct gr_arg_wrapper uwrap;
57594 + unsigned char *sprole_salt = NULL;
57595 + unsigned char *sprole_sum = NULL;
57596 + int error = sizeof (struct gr_arg_wrapper);
57597 + int error2 = 0;
57598 +
57599 + mutex_lock(&gr_dev_mutex);
57600 +
57601 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
57602 + error = -EPERM;
57603 + goto out;
57604 + }
57605 +
57606 + if (count != sizeof (struct gr_arg_wrapper)) {
57607 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
57608 + error = -EINVAL;
57609 + goto out;
57610 + }
57611 +
57612 +
57613 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
57614 + gr_auth_expires = 0;
57615 + gr_auth_attempts = 0;
57616 + }
57617 +
57618 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
57619 + error = -EFAULT;
57620 + goto out;
57621 + }
57622 +
57623 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
57624 + error = -EINVAL;
57625 + goto out;
57626 + }
57627 +
57628 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
57629 + error = -EFAULT;
57630 + goto out;
57631 + }
57632 +
57633 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57634 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57635 + time_after(gr_auth_expires, get_seconds())) {
57636 + error = -EBUSY;
57637 + goto out;
57638 + }
57639 +
57640 + /* if non-root trying to do anything other than use a special role,
57641 + do not attempt authentication, do not count towards authentication
57642 + locking
57643 + */
57644 +
57645 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
57646 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
57647 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
57648 + error = -EPERM;
57649 + goto out;
57650 + }
57651 +
57652 + /* ensure pw and special role name are null terminated */
57653 +
57654 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
57655 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
57656 +
57657 + /* Okay.
57658 + * We have our enough of the argument structure..(we have yet
57659 + * to copy_from_user the tables themselves) . Copy the tables
57660 + * only if we need them, i.e. for loading operations. */
57661 +
57662 + switch (gr_usermode->mode) {
57663 + case GR_STATUS:
57664 + if (gr_status & GR_READY) {
57665 + error = 1;
57666 + if (!gr_check_secure_terminal(current))
57667 + error = 3;
57668 + } else
57669 + error = 2;
57670 + goto out;
57671 + case GR_SHUTDOWN:
57672 + if ((gr_status & GR_READY)
57673 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57674 + stop_machine(gr_rbac_disable, NULL, NULL);
57675 + free_variables();
57676 + memset(gr_usermode, 0, sizeof (struct gr_arg));
57677 + memset(gr_system_salt, 0, GR_SALT_LEN);
57678 + memset(gr_system_sum, 0, GR_SHA_LEN);
57679 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
57680 + } else if (gr_status & GR_READY) {
57681 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
57682 + error = -EPERM;
57683 + } else {
57684 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
57685 + error = -EAGAIN;
57686 + }
57687 + break;
57688 + case GR_ENABLE:
57689 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
57690 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
57691 + else {
57692 + if (gr_status & GR_READY)
57693 + error = -EAGAIN;
57694 + else
57695 + error = error2;
57696 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
57697 + }
57698 + break;
57699 + case GR_RELOAD:
57700 + if (!(gr_status & GR_READY)) {
57701 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
57702 + error = -EAGAIN;
57703 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57704 + stop_machine(gr_rbac_disable, NULL, NULL);
57705 + free_variables();
57706 + error2 = gracl_init(gr_usermode);
57707 + if (!error2)
57708 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
57709 + else {
57710 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57711 + error = error2;
57712 + }
57713 + } else {
57714 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
57715 + error = -EPERM;
57716 + }
57717 + break;
57718 + case GR_SEGVMOD:
57719 + if (unlikely(!(gr_status & GR_READY))) {
57720 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
57721 + error = -EAGAIN;
57722 + break;
57723 + }
57724 +
57725 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
57726 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
57727 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
57728 + struct acl_subject_label *segvacl;
57729 + segvacl =
57730 + lookup_acl_subj_label(gr_usermode->segv_inode,
57731 + gr_usermode->segv_device,
57732 + current->role);
57733 + if (segvacl) {
57734 + segvacl->crashes = 0;
57735 + segvacl->expires = 0;
57736 + }
57737 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
57738 + gr_remove_uid(gr_usermode->segv_uid);
57739 + }
57740 + } else {
57741 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
57742 + error = -EPERM;
57743 + }
57744 + break;
57745 + case GR_SPROLE:
57746 + case GR_SPROLEPAM:
57747 + if (unlikely(!(gr_status & GR_READY))) {
57748 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
57749 + error = -EAGAIN;
57750 + break;
57751 + }
57752 +
57753 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
57754 + current->role->expires = 0;
57755 + current->role->auth_attempts = 0;
57756 + }
57757 +
57758 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
57759 + time_after(current->role->expires, get_seconds())) {
57760 + error = -EBUSY;
57761 + goto out;
57762 + }
57763 +
57764 + if (lookup_special_role_auth
57765 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
57766 + && ((!sprole_salt && !sprole_sum)
57767 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
57768 + char *p = "";
57769 + assign_special_role(gr_usermode->sp_role);
57770 + read_lock(&tasklist_lock);
57771 + if (current->real_parent)
57772 + p = current->real_parent->role->rolename;
57773 + read_unlock(&tasklist_lock);
57774 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
57775 + p, acl_sp_role_value);
57776 + } else {
57777 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
57778 + error = -EPERM;
57779 + if(!(current->role->auth_attempts++))
57780 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57781 +
57782 + goto out;
57783 + }
57784 + break;
57785 + case GR_UNSPROLE:
57786 + if (unlikely(!(gr_status & GR_READY))) {
57787 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
57788 + error = -EAGAIN;
57789 + break;
57790 + }
57791 +
57792 + if (current->role->roletype & GR_ROLE_SPECIAL) {
57793 + char *p = "";
57794 + int i = 0;
57795 +
57796 + read_lock(&tasklist_lock);
57797 + if (current->real_parent) {
57798 + p = current->real_parent->role->rolename;
57799 + i = current->real_parent->acl_role_id;
57800 + }
57801 + read_unlock(&tasklist_lock);
57802 +
57803 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
57804 + gr_set_acls(1);
57805 + } else {
57806 + error = -EPERM;
57807 + goto out;
57808 + }
57809 + break;
57810 + default:
57811 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
57812 + error = -EINVAL;
57813 + break;
57814 + }
57815 +
57816 + if (error != -EPERM)
57817 + goto out;
57818 +
57819 + if(!(gr_auth_attempts++))
57820 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
57821 +
57822 + out:
57823 + mutex_unlock(&gr_dev_mutex);
57824 + return error;
57825 +}
57826 +
57827 +/* must be called with
57828 + rcu_read_lock();
57829 + read_lock(&tasklist_lock);
57830 + read_lock(&grsec_exec_file_lock);
57831 +*/
57832 +int gr_apply_subject_to_task(struct task_struct *task)
57833 +{
57834 + struct acl_object_label *obj;
57835 + char *tmpname;
57836 + struct acl_subject_label *tmpsubj;
57837 + struct file *filp;
57838 + struct name_entry *nmatch;
57839 +
57840 + filp = task->exec_file;
57841 + if (filp == NULL)
57842 + return 0;
57843 +
57844 + /* the following is to apply the correct subject
57845 + on binaries running when the RBAC system
57846 + is enabled, when the binaries have been
57847 + replaced or deleted since their execution
57848 + -----
57849 + when the RBAC system starts, the inode/dev
57850 + from exec_file will be one the RBAC system
57851 + is unaware of. It only knows the inode/dev
57852 + of the present file on disk, or the absence
57853 + of it.
57854 + */
57855 + preempt_disable();
57856 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
57857 +
57858 + nmatch = lookup_name_entry(tmpname);
57859 + preempt_enable();
57860 + tmpsubj = NULL;
57861 + if (nmatch) {
57862 + if (nmatch->deleted)
57863 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
57864 + else
57865 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
57866 + if (tmpsubj != NULL)
57867 + task->acl = tmpsubj;
57868 + }
57869 + if (tmpsubj == NULL)
57870 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
57871 + task->role);
57872 + if (task->acl) {
57873 + task->is_writable = 0;
57874 + /* ignore additional mmap checks for processes that are writable
57875 + by the default ACL */
57876 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57877 + if (unlikely(obj->mode & GR_WRITE))
57878 + task->is_writable = 1;
57879 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
57880 + if (unlikely(obj->mode & GR_WRITE))
57881 + task->is_writable = 1;
57882 +
57883 + gr_set_proc_res(task);
57884 +
57885 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57886 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
57887 +#endif
57888 + } else {
57889 + return 1;
57890 + }
57891 +
57892 + return 0;
57893 +}
57894 +
57895 +int
57896 +gr_set_acls(const int type)
57897 +{
57898 + struct task_struct *task, *task2;
57899 + struct acl_role_label *role = current->role;
57900 + __u16 acl_role_id = current->acl_role_id;
57901 + const struct cred *cred;
57902 + int ret;
57903 +
57904 + rcu_read_lock();
57905 + read_lock(&tasklist_lock);
57906 + read_lock(&grsec_exec_file_lock);
57907 + do_each_thread(task2, task) {
57908 + /* check to see if we're called from the exit handler,
57909 + if so, only replace ACLs that have inherited the admin
57910 + ACL */
57911 +
57912 + if (type && (task->role != role ||
57913 + task->acl_role_id != acl_role_id))
57914 + continue;
57915 +
57916 + task->acl_role_id = 0;
57917 + task->acl_sp_role = 0;
57918 +
57919 + if (task->exec_file) {
57920 + cred = __task_cred(task);
57921 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
57922 + ret = gr_apply_subject_to_task(task);
57923 + if (ret) {
57924 + read_unlock(&grsec_exec_file_lock);
57925 + read_unlock(&tasklist_lock);
57926 + rcu_read_unlock();
57927 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
57928 + return ret;
57929 + }
57930 + } else {
57931 + // it's a kernel process
57932 + task->role = kernel_role;
57933 + task->acl = kernel_role->root_label;
57934 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
57935 + task->acl->mode &= ~GR_PROCFIND;
57936 +#endif
57937 + }
57938 + } while_each_thread(task2, task);
57939 + read_unlock(&grsec_exec_file_lock);
57940 + read_unlock(&tasklist_lock);
57941 + rcu_read_unlock();
57942 +
57943 + return 0;
57944 +}
57945 +
57946 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
57947 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
57948 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
57949 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
57950 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
57951 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
57952 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
57953 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
57954 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
57955 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
57956 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
57957 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
57958 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
57959 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
57960 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
57961 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
57962 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
57963 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
57964 +};
57965 +
57966 +void
57967 +gr_learn_resource(const struct task_struct *task,
57968 + const int res, const unsigned long wanted, const int gt)
57969 +{
57970 + struct acl_subject_label *acl;
57971 + const struct cred *cred;
57972 +
57973 + if (unlikely((gr_status & GR_READY) &&
57974 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
57975 + goto skip_reslog;
57976 +
57977 + gr_log_resource(task, res, wanted, gt);
57978 +skip_reslog:
57979 +
57980 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
57981 + return;
57982 +
57983 + acl = task->acl;
57984 +
57985 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
57986 + !(acl->resmask & (1 << (unsigned short) res))))
57987 + return;
57988 +
57989 + if (wanted >= acl->res[res].rlim_cur) {
57990 + unsigned long res_add;
57991 +
57992 + res_add = wanted + res_learn_bumps[res];
57993 +
57994 + acl->res[res].rlim_cur = res_add;
57995 +
57996 + if (wanted > acl->res[res].rlim_max)
57997 + acl->res[res].rlim_max = res_add;
57998 +
57999 + /* only log the subject filename, since resource logging is supported for
58000 + single-subject learning only */
58001 + rcu_read_lock();
58002 + cred = __task_cred(task);
58003 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58004 + task->role->roletype, cred->uid, cred->gid, acl->filename,
58005 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
58006 + "", (unsigned long) res, &task->signal->saved_ip);
58007 + rcu_read_unlock();
58008 + }
58009 +
58010 + return;
58011 +}
58012 +EXPORT_SYMBOL(gr_learn_resource);
58013 +#endif
58014 +
58015 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
58016 +void
58017 +pax_set_initial_flags(struct linux_binprm *bprm)
58018 +{
58019 + struct task_struct *task = current;
58020 + struct acl_subject_label *proc;
58021 + unsigned long flags;
58022 +
58023 + if (unlikely(!(gr_status & GR_READY)))
58024 + return;
58025 +
58026 + flags = pax_get_flags(task);
58027 +
58028 + proc = task->acl;
58029 +
58030 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
58031 + flags &= ~MF_PAX_PAGEEXEC;
58032 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
58033 + flags &= ~MF_PAX_SEGMEXEC;
58034 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
58035 + flags &= ~MF_PAX_RANDMMAP;
58036 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
58037 + flags &= ~MF_PAX_EMUTRAMP;
58038 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
58039 + flags &= ~MF_PAX_MPROTECT;
58040 +
58041 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
58042 + flags |= MF_PAX_PAGEEXEC;
58043 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
58044 + flags |= MF_PAX_SEGMEXEC;
58045 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
58046 + flags |= MF_PAX_RANDMMAP;
58047 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
58048 + flags |= MF_PAX_EMUTRAMP;
58049 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
58050 + flags |= MF_PAX_MPROTECT;
58051 +
58052 + pax_set_flags(task, flags);
58053 +
58054 + return;
58055 +}
58056 +#endif
58057 +
58058 +int
58059 +gr_handle_proc_ptrace(struct task_struct *task)
58060 +{
58061 + struct file *filp;
58062 + struct task_struct *tmp = task;
58063 + struct task_struct *curtemp = current;
58064 + __u32 retmode;
58065 +
58066 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58067 + if (unlikely(!(gr_status & GR_READY)))
58068 + return 0;
58069 +#endif
58070 +
58071 + read_lock(&tasklist_lock);
58072 + read_lock(&grsec_exec_file_lock);
58073 + filp = task->exec_file;
58074 +
58075 + while (tmp->pid > 0) {
58076 + if (tmp == curtemp)
58077 + break;
58078 + tmp = tmp->real_parent;
58079 + }
58080 +
58081 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58082 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
58083 + read_unlock(&grsec_exec_file_lock);
58084 + read_unlock(&tasklist_lock);
58085 + return 1;
58086 + }
58087 +
58088 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58089 + if (!(gr_status & GR_READY)) {
58090 + read_unlock(&grsec_exec_file_lock);
58091 + read_unlock(&tasklist_lock);
58092 + return 0;
58093 + }
58094 +#endif
58095 +
58096 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
58097 + read_unlock(&grsec_exec_file_lock);
58098 + read_unlock(&tasklist_lock);
58099 +
58100 + if (retmode & GR_NOPTRACE)
58101 + return 1;
58102 +
58103 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
58104 + && (current->acl != task->acl || (current->acl != current->role->root_label
58105 + && current->pid != task->pid)))
58106 + return 1;
58107 +
58108 + return 0;
58109 +}
58110 +
58111 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
58112 +{
58113 + if (unlikely(!(gr_status & GR_READY)))
58114 + return;
58115 +
58116 + if (!(current->role->roletype & GR_ROLE_GOD))
58117 + return;
58118 +
58119 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
58120 + p->role->rolename, gr_task_roletype_to_char(p),
58121 + p->acl->filename);
58122 +}
58123 +
58124 +int
58125 +gr_handle_ptrace(struct task_struct *task, const long request)
58126 +{
58127 + struct task_struct *tmp = task;
58128 + struct task_struct *curtemp = current;
58129 + __u32 retmode;
58130 +
58131 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
58132 + if (unlikely(!(gr_status & GR_READY)))
58133 + return 0;
58134 +#endif
58135 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
58136 + read_lock(&tasklist_lock);
58137 + while (tmp->pid > 0) {
58138 + if (tmp == curtemp)
58139 + break;
58140 + tmp = tmp->real_parent;
58141 + }
58142 +
58143 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
58144 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
58145 + read_unlock(&tasklist_lock);
58146 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58147 + return 1;
58148 + }
58149 + read_unlock(&tasklist_lock);
58150 + }
58151 +
58152 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58153 + if (!(gr_status & GR_READY))
58154 + return 0;
58155 +#endif
58156 +
58157 + read_lock(&grsec_exec_file_lock);
58158 + if (unlikely(!task->exec_file)) {
58159 + read_unlock(&grsec_exec_file_lock);
58160 + return 0;
58161 + }
58162 +
58163 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
58164 + read_unlock(&grsec_exec_file_lock);
58165 +
58166 + if (retmode & GR_NOPTRACE) {
58167 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58168 + return 1;
58169 + }
58170 +
58171 + if (retmode & GR_PTRACERD) {
58172 + switch (request) {
58173 + case PTRACE_SEIZE:
58174 + case PTRACE_POKETEXT:
58175 + case PTRACE_POKEDATA:
58176 + case PTRACE_POKEUSR:
58177 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
58178 + case PTRACE_SETREGS:
58179 + case PTRACE_SETFPREGS:
58180 +#endif
58181 +#ifdef CONFIG_X86
58182 + case PTRACE_SETFPXREGS:
58183 +#endif
58184 +#ifdef CONFIG_ALTIVEC
58185 + case PTRACE_SETVRREGS:
58186 +#endif
58187 + return 1;
58188 + default:
58189 + return 0;
58190 + }
58191 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
58192 + !(current->role->roletype & GR_ROLE_GOD) &&
58193 + (current->acl != task->acl)) {
58194 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
58195 + return 1;
58196 + }
58197 +
58198 + return 0;
58199 +}
58200 +
58201 +static int is_writable_mmap(const struct file *filp)
58202 +{
58203 + struct task_struct *task = current;
58204 + struct acl_object_label *obj, *obj2;
58205 +
58206 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
58207 + !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))) {
58208 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
58209 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
58210 + task->role->root_label);
58211 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
58212 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
58213 + return 1;
58214 + }
58215 + }
58216 + return 0;
58217 +}
58218 +
58219 +int
58220 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
58221 +{
58222 + __u32 mode;
58223 +
58224 + if (unlikely(!file || !(prot & PROT_EXEC)))
58225 + return 1;
58226 +
58227 + if (is_writable_mmap(file))
58228 + return 0;
58229 +
58230 + mode =
58231 + gr_search_file(file->f_path.dentry,
58232 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58233 + file->f_path.mnt);
58234 +
58235 + if (!gr_tpe_allow(file))
58236 + return 0;
58237 +
58238 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58239 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58240 + return 0;
58241 + } else if (unlikely(!(mode & GR_EXEC))) {
58242 + return 0;
58243 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58244 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58245 + return 1;
58246 + }
58247 +
58248 + return 1;
58249 +}
58250 +
58251 +int
58252 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58253 +{
58254 + __u32 mode;
58255 +
58256 + if (unlikely(!file || !(prot & PROT_EXEC)))
58257 + return 1;
58258 +
58259 + if (is_writable_mmap(file))
58260 + return 0;
58261 +
58262 + mode =
58263 + gr_search_file(file->f_path.dentry,
58264 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
58265 + file->f_path.mnt);
58266 +
58267 + if (!gr_tpe_allow(file))
58268 + return 0;
58269 +
58270 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
58271 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58272 + return 0;
58273 + } else if (unlikely(!(mode & GR_EXEC))) {
58274 + return 0;
58275 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
58276 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
58277 + return 1;
58278 + }
58279 +
58280 + return 1;
58281 +}
58282 +
58283 +void
58284 +gr_acl_handle_psacct(struct task_struct *task, const long code)
58285 +{
58286 + unsigned long runtime;
58287 + unsigned long cputime;
58288 + unsigned int wday, cday;
58289 + __u8 whr, chr;
58290 + __u8 wmin, cmin;
58291 + __u8 wsec, csec;
58292 + struct timespec timeval;
58293 +
58294 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
58295 + !(task->acl->mode & GR_PROCACCT)))
58296 + return;
58297 +
58298 + do_posix_clock_monotonic_gettime(&timeval);
58299 + runtime = timeval.tv_sec - task->start_time.tv_sec;
58300 + wday = runtime / (3600 * 24);
58301 + runtime -= wday * (3600 * 24);
58302 + whr = runtime / 3600;
58303 + runtime -= whr * 3600;
58304 + wmin = runtime / 60;
58305 + runtime -= wmin * 60;
58306 + wsec = runtime;
58307 +
58308 + cputime = (task->utime + task->stime) / HZ;
58309 + cday = cputime / (3600 * 24);
58310 + cputime -= cday * (3600 * 24);
58311 + chr = cputime / 3600;
58312 + cputime -= chr * 3600;
58313 + cmin = cputime / 60;
58314 + cputime -= cmin * 60;
58315 + csec = cputime;
58316 +
58317 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
58318 +
58319 + return;
58320 +}
58321 +
58322 +void gr_set_kernel_label(struct task_struct *task)
58323 +{
58324 + if (gr_status & GR_READY) {
58325 + task->role = kernel_role;
58326 + task->acl = kernel_role->root_label;
58327 + }
58328 + return;
58329 +}
58330 +
58331 +#ifdef CONFIG_TASKSTATS
58332 +int gr_is_taskstats_denied(int pid)
58333 +{
58334 + struct task_struct *task;
58335 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58336 + const struct cred *cred;
58337 +#endif
58338 + int ret = 0;
58339 +
58340 + /* restrict taskstats viewing to un-chrooted root users
58341 + who have the 'view' subject flag if the RBAC system is enabled
58342 + */
58343 +
58344 + rcu_read_lock();
58345 + read_lock(&tasklist_lock);
58346 + task = find_task_by_vpid(pid);
58347 + if (task) {
58348 +#ifdef CONFIG_GRKERNSEC_CHROOT
58349 + if (proc_is_chrooted(task))
58350 + ret = -EACCES;
58351 +#endif
58352 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58353 + cred = __task_cred(task);
58354 +#ifdef CONFIG_GRKERNSEC_PROC_USER
58355 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
58356 + ret = -EACCES;
58357 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
58358 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
58359 + ret = -EACCES;
58360 +#endif
58361 +#endif
58362 + if (gr_status & GR_READY) {
58363 + if (!(task->acl->mode & GR_VIEW))
58364 + ret = -EACCES;
58365 + }
58366 + } else
58367 + ret = -ENOENT;
58368 +
58369 + read_unlock(&tasklist_lock);
58370 + rcu_read_unlock();
58371 +
58372 + return ret;
58373 +}
58374 +#endif
58375 +
58376 +/* AUXV entries are filled via a descendant of search_binary_handler
58377 + after we've already applied the subject for the target
58378 +*/
58379 +int gr_acl_enable_at_secure(void)
58380 +{
58381 + if (unlikely(!(gr_status & GR_READY)))
58382 + return 0;
58383 +
58384 + if (current->acl->mode & GR_ATSECURE)
58385 + return 1;
58386 +
58387 + return 0;
58388 +}
58389 +
58390 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
58391 +{
58392 + struct task_struct *task = current;
58393 + struct dentry *dentry = file->f_path.dentry;
58394 + struct vfsmount *mnt = file->f_path.mnt;
58395 + struct acl_object_label *obj, *tmp;
58396 + struct acl_subject_label *subj;
58397 + unsigned int bufsize;
58398 + int is_not_root;
58399 + char *path;
58400 + dev_t dev = __get_dev(dentry);
58401 +
58402 + if (unlikely(!(gr_status & GR_READY)))
58403 + return 1;
58404 +
58405 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
58406 + return 1;
58407 +
58408 + /* ignore Eric Biederman */
58409 + if (IS_PRIVATE(dentry->d_inode))
58410 + return 1;
58411 +
58412 + subj = task->acl;
58413 + read_lock(&gr_inode_lock);
58414 + do {
58415 + obj = lookup_acl_obj_label(ino, dev, subj);
58416 + if (obj != NULL) {
58417 + read_unlock(&gr_inode_lock);
58418 + return (obj->mode & GR_FIND) ? 1 : 0;
58419 + }
58420 + } while ((subj = subj->parent_subject));
58421 + read_unlock(&gr_inode_lock);
58422 +
58423 + /* this is purely an optimization since we're looking for an object
58424 + for the directory we're doing a readdir on
58425 + if it's possible for any globbed object to match the entry we're
58426 + filling into the directory, then the object we find here will be
58427 + an anchor point with attached globbed objects
58428 + */
58429 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
58430 + if (obj->globbed == NULL)
58431 + return (obj->mode & GR_FIND) ? 1 : 0;
58432 +
58433 + is_not_root = ((obj->filename[0] == '/') &&
58434 + (obj->filename[1] == '\0')) ? 0 : 1;
58435 + bufsize = PAGE_SIZE - namelen - is_not_root;
58436 +
58437 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
58438 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
58439 + return 1;
58440 +
58441 + preempt_disable();
58442 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58443 + bufsize);
58444 +
58445 + bufsize = strlen(path);
58446 +
58447 + /* if base is "/", don't append an additional slash */
58448 + if (is_not_root)
58449 + *(path + bufsize) = '/';
58450 + memcpy(path + bufsize + is_not_root, name, namelen);
58451 + *(path + bufsize + namelen + is_not_root) = '\0';
58452 +
58453 + tmp = obj->globbed;
58454 + while (tmp) {
58455 + if (!glob_match(tmp->filename, path)) {
58456 + preempt_enable();
58457 + return (tmp->mode & GR_FIND) ? 1 : 0;
58458 + }
58459 + tmp = tmp->next;
58460 + }
58461 + preempt_enable();
58462 + return (obj->mode & GR_FIND) ? 1 : 0;
58463 +}
58464 +
58465 +void gr_put_exec_file(struct task_struct *task)
58466 +{
58467 + struct file *filp;
58468 +
58469 + write_lock(&grsec_exec_file_lock);
58470 + filp = task->exec_file;
58471 + task->exec_file = NULL;
58472 + write_unlock(&grsec_exec_file_lock);
58473 +
58474 + if (filp)
58475 + fput(filp);
58476 +
58477 + return;
58478 +}
58479 +
58480 +
58481 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
58482 +EXPORT_SYMBOL(gr_acl_is_enabled);
58483 +#endif
58484 +EXPORT_SYMBOL(gr_set_kernel_label);
58485 +#ifdef CONFIG_SECURITY
58486 +EXPORT_SYMBOL(gr_check_user_change);
58487 +EXPORT_SYMBOL(gr_check_group_change);
58488 +#endif
58489 +
58490 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
58491 new file mode 100644
58492 index 0000000..34fefda
58493 --- /dev/null
58494 +++ b/grsecurity/gracl_alloc.c
58495 @@ -0,0 +1,105 @@
58496 +#include <linux/kernel.h>
58497 +#include <linux/mm.h>
58498 +#include <linux/slab.h>
58499 +#include <linux/vmalloc.h>
58500 +#include <linux/gracl.h>
58501 +#include <linux/grsecurity.h>
58502 +
58503 +static unsigned long alloc_stack_next = 1;
58504 +static unsigned long alloc_stack_size = 1;
58505 +static void **alloc_stack;
58506 +
58507 +static __inline__ int
58508 +alloc_pop(void)
58509 +{
58510 + if (alloc_stack_next == 1)
58511 + return 0;
58512 +
58513 + kfree(alloc_stack[alloc_stack_next - 2]);
58514 +
58515 + alloc_stack_next--;
58516 +
58517 + return 1;
58518 +}
58519 +
58520 +static __inline__ int
58521 +alloc_push(void *buf)
58522 +{
58523 + if (alloc_stack_next >= alloc_stack_size)
58524 + return 1;
58525 +
58526 + alloc_stack[alloc_stack_next - 1] = buf;
58527 +
58528 + alloc_stack_next++;
58529 +
58530 + return 0;
58531 +}
58532 +
58533 +void *
58534 +acl_alloc(unsigned long len)
58535 +{
58536 + void *ret = NULL;
58537 +
58538 + if (!len || len > PAGE_SIZE)
58539 + goto out;
58540 +
58541 + ret = kmalloc(len, GFP_KERNEL);
58542 +
58543 + if (ret) {
58544 + if (alloc_push(ret)) {
58545 + kfree(ret);
58546 + ret = NULL;
58547 + }
58548 + }
58549 +
58550 +out:
58551 + return ret;
58552 +}
58553 +
58554 +void *
58555 +acl_alloc_num(unsigned long num, unsigned long len)
58556 +{
58557 + if (!len || (num > (PAGE_SIZE / len)))
58558 + return NULL;
58559 +
58560 + return acl_alloc(num * len);
58561 +}
58562 +
58563 +void
58564 +acl_free_all(void)
58565 +{
58566 + if (gr_acl_is_enabled() || !alloc_stack)
58567 + return;
58568 +
58569 + while (alloc_pop()) ;
58570 +
58571 + if (alloc_stack) {
58572 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
58573 + kfree(alloc_stack);
58574 + else
58575 + vfree(alloc_stack);
58576 + }
58577 +
58578 + alloc_stack = NULL;
58579 + alloc_stack_size = 1;
58580 + alloc_stack_next = 1;
58581 +
58582 + return;
58583 +}
58584 +
58585 +int
58586 +acl_alloc_stack_init(unsigned long size)
58587 +{
58588 + if ((size * sizeof (void *)) <= PAGE_SIZE)
58589 + alloc_stack =
58590 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
58591 + else
58592 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
58593 +
58594 + alloc_stack_size = size;
58595 +
58596 + if (!alloc_stack)
58597 + return 0;
58598 + else
58599 + return 1;
58600 +}
58601 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
58602 new file mode 100644
58603 index 0000000..6d21049
58604 --- /dev/null
58605 +++ b/grsecurity/gracl_cap.c
58606 @@ -0,0 +1,110 @@
58607 +#include <linux/kernel.h>
58608 +#include <linux/module.h>
58609 +#include <linux/sched.h>
58610 +#include <linux/gracl.h>
58611 +#include <linux/grsecurity.h>
58612 +#include <linux/grinternal.h>
58613 +
58614 +extern const char *captab_log[];
58615 +extern int captab_log_entries;
58616 +
58617 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58618 +{
58619 + struct acl_subject_label *curracl;
58620 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58621 + kernel_cap_t cap_audit = __cap_empty_set;
58622 +
58623 + if (!gr_acl_is_enabled())
58624 + return 1;
58625 +
58626 + curracl = task->acl;
58627 +
58628 + cap_drop = curracl->cap_lower;
58629 + cap_mask = curracl->cap_mask;
58630 + cap_audit = curracl->cap_invert_audit;
58631 +
58632 + while ((curracl = curracl->parent_subject)) {
58633 + /* if the cap isn't specified in the current computed mask but is specified in the
58634 + current level subject, and is lowered in the current level subject, then add
58635 + it to the set of dropped capabilities
58636 + otherwise, add the current level subject's mask to the current computed mask
58637 + */
58638 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58639 + cap_raise(cap_mask, cap);
58640 + if (cap_raised(curracl->cap_lower, cap))
58641 + cap_raise(cap_drop, cap);
58642 + if (cap_raised(curracl->cap_invert_audit, cap))
58643 + cap_raise(cap_audit, cap);
58644 + }
58645 + }
58646 +
58647 + if (!cap_raised(cap_drop, cap)) {
58648 + if (cap_raised(cap_audit, cap))
58649 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
58650 + return 1;
58651 + }
58652 +
58653 + curracl = task->acl;
58654 +
58655 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
58656 + && cap_raised(cred->cap_effective, cap)) {
58657 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
58658 + task->role->roletype, cred->uid,
58659 + cred->gid, task->exec_file ?
58660 + gr_to_filename(task->exec_file->f_path.dentry,
58661 + task->exec_file->f_path.mnt) : curracl->filename,
58662 + curracl->filename, 0UL,
58663 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
58664 + return 1;
58665 + }
58666 +
58667 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
58668 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
58669 +
58670 + return 0;
58671 +}
58672 +
58673 +int
58674 +gr_acl_is_capable(const int cap)
58675 +{
58676 + return gr_task_acl_is_capable(current, current_cred(), cap);
58677 +}
58678 +
58679 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
58680 +{
58681 + struct acl_subject_label *curracl;
58682 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
58683 +
58684 + if (!gr_acl_is_enabled())
58685 + return 1;
58686 +
58687 + curracl = task->acl;
58688 +
58689 + cap_drop = curracl->cap_lower;
58690 + cap_mask = curracl->cap_mask;
58691 +
58692 + while ((curracl = curracl->parent_subject)) {
58693 + /* if the cap isn't specified in the current computed mask but is specified in the
58694 + current level subject, and is lowered in the current level subject, then add
58695 + it to the set of dropped capabilities
58696 + otherwise, add the current level subject's mask to the current computed mask
58697 + */
58698 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
58699 + cap_raise(cap_mask, cap);
58700 + if (cap_raised(curracl->cap_lower, cap))
58701 + cap_raise(cap_drop, cap);
58702 + }
58703 + }
58704 +
58705 + if (!cap_raised(cap_drop, cap))
58706 + return 1;
58707 +
58708 + return 0;
58709 +}
58710 +
58711 +int
58712 +gr_acl_is_capable_nolog(const int cap)
58713 +{
58714 + return gr_task_acl_is_capable_nolog(current, cap);
58715 +}
58716 +
58717 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
58718 new file mode 100644
58719 index 0000000..a340c17
58720 --- /dev/null
58721 +++ b/grsecurity/gracl_fs.c
58722 @@ -0,0 +1,431 @@
58723 +#include <linux/kernel.h>
58724 +#include <linux/sched.h>
58725 +#include <linux/types.h>
58726 +#include <linux/fs.h>
58727 +#include <linux/file.h>
58728 +#include <linux/stat.h>
58729 +#include <linux/grsecurity.h>
58730 +#include <linux/grinternal.h>
58731 +#include <linux/gracl.h>
58732 +
58733 +umode_t
58734 +gr_acl_umask(void)
58735 +{
58736 + if (unlikely(!gr_acl_is_enabled()))
58737 + return 0;
58738 +
58739 + return current->role->umask;
58740 +}
58741 +
58742 +__u32
58743 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58744 + const struct vfsmount * mnt)
58745 +{
58746 + __u32 mode;
58747 +
58748 + if (unlikely(!dentry->d_inode))
58749 + return GR_FIND;
58750 +
58751 + mode =
58752 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
58753 +
58754 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
58755 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58756 + return mode;
58757 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
58758 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
58759 + return 0;
58760 + } else if (unlikely(!(mode & GR_FIND)))
58761 + return 0;
58762 +
58763 + return GR_FIND;
58764 +}
58765 +
58766 +__u32
58767 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58768 + int acc_mode)
58769 +{
58770 + __u32 reqmode = GR_FIND;
58771 + __u32 mode;
58772 +
58773 + if (unlikely(!dentry->d_inode))
58774 + return reqmode;
58775 +
58776 + if (acc_mode & MAY_APPEND)
58777 + reqmode |= GR_APPEND;
58778 + else if (acc_mode & MAY_WRITE)
58779 + reqmode |= GR_WRITE;
58780 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
58781 + reqmode |= GR_READ;
58782 +
58783 + mode =
58784 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58785 + mnt);
58786 +
58787 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58788 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58789 + reqmode & GR_READ ? " reading" : "",
58790 + reqmode & GR_WRITE ? " writing" : reqmode &
58791 + GR_APPEND ? " appending" : "");
58792 + return reqmode;
58793 + } else
58794 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58795 + {
58796 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
58797 + reqmode & GR_READ ? " reading" : "",
58798 + reqmode & GR_WRITE ? " writing" : reqmode &
58799 + GR_APPEND ? " appending" : "");
58800 + return 0;
58801 + } else if (unlikely((mode & reqmode) != reqmode))
58802 + return 0;
58803 +
58804 + return reqmode;
58805 +}
58806 +
58807 +__u32
58808 +gr_acl_handle_creat(const struct dentry * dentry,
58809 + const struct dentry * p_dentry,
58810 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58811 + const int imode)
58812 +{
58813 + __u32 reqmode = GR_WRITE | GR_CREATE;
58814 + __u32 mode;
58815 +
58816 + if (acc_mode & MAY_APPEND)
58817 + reqmode |= GR_APPEND;
58818 + // if a directory was required or the directory already exists, then
58819 + // don't count this open as a read
58820 + if ((acc_mode & MAY_READ) &&
58821 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
58822 + reqmode |= GR_READ;
58823 + if ((open_flags & O_CREAT) &&
58824 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
58825 + reqmode |= GR_SETID;
58826 +
58827 + mode =
58828 + gr_check_create(dentry, p_dentry, p_mnt,
58829 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
58830 +
58831 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58832 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58833 + reqmode & GR_READ ? " reading" : "",
58834 + reqmode & GR_WRITE ? " writing" : reqmode &
58835 + GR_APPEND ? " appending" : "");
58836 + return reqmode;
58837 + } else
58838 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58839 + {
58840 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
58841 + reqmode & GR_READ ? " reading" : "",
58842 + reqmode & GR_WRITE ? " writing" : reqmode &
58843 + GR_APPEND ? " appending" : "");
58844 + return 0;
58845 + } else if (unlikely((mode & reqmode) != reqmode))
58846 + return 0;
58847 +
58848 + return reqmode;
58849 +}
58850 +
58851 +__u32
58852 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
58853 + const int fmode)
58854 +{
58855 + __u32 mode, reqmode = GR_FIND;
58856 +
58857 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
58858 + reqmode |= GR_EXEC;
58859 + if (fmode & S_IWOTH)
58860 + reqmode |= GR_WRITE;
58861 + if (fmode & S_IROTH)
58862 + reqmode |= GR_READ;
58863 +
58864 + mode =
58865 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
58866 + mnt);
58867 +
58868 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
58869 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58870 + reqmode & GR_READ ? " reading" : "",
58871 + reqmode & GR_WRITE ? " writing" : "",
58872 + reqmode & GR_EXEC ? " executing" : "");
58873 + return reqmode;
58874 + } else
58875 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
58876 + {
58877 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
58878 + reqmode & GR_READ ? " reading" : "",
58879 + reqmode & GR_WRITE ? " writing" : "",
58880 + reqmode & GR_EXEC ? " executing" : "");
58881 + return 0;
58882 + } else if (unlikely((mode & reqmode) != reqmode))
58883 + return 0;
58884 +
58885 + return reqmode;
58886 +}
58887 +
58888 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
58889 +{
58890 + __u32 mode;
58891 +
58892 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
58893 +
58894 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
58895 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
58896 + return mode;
58897 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
58898 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
58899 + return 0;
58900 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
58901 + return 0;
58902 +
58903 + return (reqmode);
58904 +}
58905 +
58906 +__u32
58907 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58908 +{
58909 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
58910 +}
58911 +
58912 +__u32
58913 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
58914 +{
58915 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
58916 +}
58917 +
58918 +__u32
58919 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
58920 +{
58921 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
58922 +}
58923 +
58924 +__u32
58925 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
58926 +{
58927 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
58928 +}
58929 +
58930 +__u32
58931 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
58932 + umode_t *modeptr)
58933 +{
58934 + umode_t mode;
58935 +
58936 + *modeptr &= ~gr_acl_umask();
58937 + mode = *modeptr;
58938 +
58939 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
58940 + return 1;
58941 +
58942 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
58943 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
58944 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
58945 + GR_CHMOD_ACL_MSG);
58946 + } else {
58947 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
58948 + }
58949 +}
58950 +
58951 +__u32
58952 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
58953 +{
58954 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
58955 +}
58956 +
58957 +__u32
58958 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
58959 +{
58960 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
58961 +}
58962 +
58963 +__u32
58964 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
58965 +{
58966 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
58967 +}
58968 +
58969 +__u32
58970 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
58971 +{
58972 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
58973 + GR_UNIXCONNECT_ACL_MSG);
58974 +}
58975 +
58976 +/* hardlinks require at minimum create and link permission,
58977 + any additional privilege required is based on the
58978 + privilege of the file being linked to
58979 +*/
58980 +__u32
58981 +gr_acl_handle_link(const struct dentry * new_dentry,
58982 + const struct dentry * parent_dentry,
58983 + const struct vfsmount * parent_mnt,
58984 + const struct dentry * old_dentry,
58985 + const struct vfsmount * old_mnt, const struct filename *to)
58986 +{
58987 + __u32 mode;
58988 + __u32 needmode = GR_CREATE | GR_LINK;
58989 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
58990 +
58991 + mode =
58992 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
58993 + old_mnt);
58994 +
58995 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
58996 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
58997 + return mode;
58998 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
58999 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
59000 + return 0;
59001 + } else if (unlikely((mode & needmode) != needmode))
59002 + return 0;
59003 +
59004 + return 1;
59005 +}
59006 +
59007 +__u32
59008 +gr_acl_handle_symlink(const struct dentry * new_dentry,
59009 + const struct dentry * parent_dentry,
59010 + const struct vfsmount * parent_mnt, const struct filename *from)
59011 +{
59012 + __u32 needmode = GR_WRITE | GR_CREATE;
59013 + __u32 mode;
59014 +
59015 + mode =
59016 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
59017 + GR_CREATE | GR_AUDIT_CREATE |
59018 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
59019 +
59020 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
59021 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
59022 + return mode;
59023 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
59024 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
59025 + return 0;
59026 + } else if (unlikely((mode & needmode) != needmode))
59027 + return 0;
59028 +
59029 + return (GR_WRITE | GR_CREATE);
59030 +}
59031 +
59032 +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)
59033 +{
59034 + __u32 mode;
59035 +
59036 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
59037 +
59038 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
59039 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
59040 + return mode;
59041 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
59042 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
59043 + return 0;
59044 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
59045 + return 0;
59046 +
59047 + return (reqmode);
59048 +}
59049 +
59050 +__u32
59051 +gr_acl_handle_mknod(const struct dentry * new_dentry,
59052 + const struct dentry * parent_dentry,
59053 + const struct vfsmount * parent_mnt,
59054 + const int mode)
59055 +{
59056 + __u32 reqmode = GR_WRITE | GR_CREATE;
59057 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
59058 + reqmode |= GR_SETID;
59059 +
59060 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59061 + reqmode, GR_MKNOD_ACL_MSG);
59062 +}
59063 +
59064 +__u32
59065 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
59066 + const struct dentry *parent_dentry,
59067 + const struct vfsmount *parent_mnt)
59068 +{
59069 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
59070 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
59071 +}
59072 +
59073 +#define RENAME_CHECK_SUCCESS(old, new) \
59074 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
59075 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
59076 +
59077 +int
59078 +gr_acl_handle_rename(struct dentry *new_dentry,
59079 + struct dentry *parent_dentry,
59080 + const struct vfsmount *parent_mnt,
59081 + struct dentry *old_dentry,
59082 + struct inode *old_parent_inode,
59083 + struct vfsmount *old_mnt, const struct filename *newname)
59084 +{
59085 + __u32 comp1, comp2;
59086 + int error = 0;
59087 +
59088 + if (unlikely(!gr_acl_is_enabled()))
59089 + return 0;
59090 +
59091 + if (!new_dentry->d_inode) {
59092 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
59093 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
59094 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
59095 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
59096 + GR_DELETE | GR_AUDIT_DELETE |
59097 + GR_AUDIT_READ | GR_AUDIT_WRITE |
59098 + GR_SUPPRESS, old_mnt);
59099 + } else {
59100 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
59101 + GR_CREATE | GR_DELETE |
59102 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
59103 + GR_AUDIT_READ | GR_AUDIT_WRITE |
59104 + GR_SUPPRESS, parent_mnt);
59105 + comp2 =
59106 + gr_search_file(old_dentry,
59107 + GR_READ | GR_WRITE | GR_AUDIT_READ |
59108 + GR_DELETE | GR_AUDIT_DELETE |
59109 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
59110 + }
59111 +
59112 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
59113 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
59114 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59115 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
59116 + && !(comp2 & GR_SUPPRESS)) {
59117 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
59118 + error = -EACCES;
59119 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
59120 + error = -EACCES;
59121 +
59122 + return error;
59123 +}
59124 +
59125 +void
59126 +gr_acl_handle_exit(void)
59127 +{
59128 + u16 id;
59129 + char *rolename;
59130 +
59131 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
59132 + !(current->role->roletype & GR_ROLE_PERSIST))) {
59133 + id = current->acl_role_id;
59134 + rolename = current->role->rolename;
59135 + gr_set_acls(1);
59136 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
59137 + }
59138 +
59139 + gr_put_exec_file(current);
59140 + return;
59141 +}
59142 +
59143 +int
59144 +gr_acl_handle_procpidmem(const struct task_struct *task)
59145 +{
59146 + if (unlikely(!gr_acl_is_enabled()))
59147 + return 0;
59148 +
59149 + if (task != current && task->acl->mode & GR_PROTPROCFD)
59150 + return -EACCES;
59151 +
59152 + return 0;
59153 +}
59154 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
59155 new file mode 100644
59156 index 0000000..58800a7
59157 --- /dev/null
59158 +++ b/grsecurity/gracl_ip.c
59159 @@ -0,0 +1,384 @@
59160 +#include <linux/kernel.h>
59161 +#include <asm/uaccess.h>
59162 +#include <asm/errno.h>
59163 +#include <net/sock.h>
59164 +#include <linux/file.h>
59165 +#include <linux/fs.h>
59166 +#include <linux/net.h>
59167 +#include <linux/in.h>
59168 +#include <linux/skbuff.h>
59169 +#include <linux/ip.h>
59170 +#include <linux/udp.h>
59171 +#include <linux/types.h>
59172 +#include <linux/sched.h>
59173 +#include <linux/netdevice.h>
59174 +#include <linux/inetdevice.h>
59175 +#include <linux/gracl.h>
59176 +#include <linux/grsecurity.h>
59177 +#include <linux/grinternal.h>
59178 +
59179 +#define GR_BIND 0x01
59180 +#define GR_CONNECT 0x02
59181 +#define GR_INVERT 0x04
59182 +#define GR_BINDOVERRIDE 0x08
59183 +#define GR_CONNECTOVERRIDE 0x10
59184 +#define GR_SOCK_FAMILY 0x20
59185 +
59186 +static const char * gr_protocols[IPPROTO_MAX] = {
59187 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
59188 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
59189 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
59190 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
59191 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
59192 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
59193 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
59194 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
59195 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
59196 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
59197 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
59198 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
59199 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
59200 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
59201 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
59202 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
59203 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
59204 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
59205 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
59206 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
59207 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
59208 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
59209 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
59210 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
59211 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
59212 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
59213 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
59214 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
59215 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
59216 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
59217 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
59218 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
59219 + };
59220 +
59221 +static const char * gr_socktypes[SOCK_MAX] = {
59222 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
59223 + "unknown:7", "unknown:8", "unknown:9", "packet"
59224 + };
59225 +
59226 +static const char * gr_sockfamilies[AF_MAX+1] = {
59227 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
59228 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
59229 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
59230 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
59231 + };
59232 +
59233 +const char *
59234 +gr_proto_to_name(unsigned char proto)
59235 +{
59236 + return gr_protocols[proto];
59237 +}
59238 +
59239 +const char *
59240 +gr_socktype_to_name(unsigned char type)
59241 +{
59242 + return gr_socktypes[type];
59243 +}
59244 +
59245 +const char *
59246 +gr_sockfamily_to_name(unsigned char family)
59247 +{
59248 + return gr_sockfamilies[family];
59249 +}
59250 +
59251 +int
59252 +gr_search_socket(const int domain, const int type, const int protocol)
59253 +{
59254 + struct acl_subject_label *curr;
59255 + const struct cred *cred = current_cred();
59256 +
59257 + if (unlikely(!gr_acl_is_enabled()))
59258 + goto exit;
59259 +
59260 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
59261 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
59262 + goto exit; // let the kernel handle it
59263 +
59264 + curr = current->acl;
59265 +
59266 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
59267 + /* the family is allowed, if this is PF_INET allow it only if
59268 + the extra sock type/protocol checks pass */
59269 + if (domain == PF_INET)
59270 + goto inet_check;
59271 + goto exit;
59272 + } else {
59273 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59274 + __u32 fakeip = 0;
59275 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59276 + current->role->roletype, cred->uid,
59277 + cred->gid, current->exec_file ?
59278 + gr_to_filename(current->exec_file->f_path.dentry,
59279 + current->exec_file->f_path.mnt) :
59280 + curr->filename, curr->filename,
59281 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
59282 + &current->signal->saved_ip);
59283 + goto exit;
59284 + }
59285 + goto exit_fail;
59286 + }
59287 +
59288 +inet_check:
59289 + /* the rest of this checking is for IPv4 only */
59290 + if (!curr->ips)
59291 + goto exit;
59292 +
59293 + if ((curr->ip_type & (1 << type)) &&
59294 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
59295 + goto exit;
59296 +
59297 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59298 + /* we don't place acls on raw sockets , and sometimes
59299 + dgram/ip sockets are opened for ioctl and not
59300 + bind/connect, so we'll fake a bind learn log */
59301 + if (type == SOCK_RAW || type == SOCK_PACKET) {
59302 + __u32 fakeip = 0;
59303 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59304 + current->role->roletype, cred->uid,
59305 + cred->gid, current->exec_file ?
59306 + gr_to_filename(current->exec_file->f_path.dentry,
59307 + current->exec_file->f_path.mnt) :
59308 + curr->filename, curr->filename,
59309 + &fakeip, 0, type,
59310 + protocol, GR_CONNECT, &current->signal->saved_ip);
59311 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
59312 + __u32 fakeip = 0;
59313 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59314 + current->role->roletype, cred->uid,
59315 + cred->gid, current->exec_file ?
59316 + gr_to_filename(current->exec_file->f_path.dentry,
59317 + current->exec_file->f_path.mnt) :
59318 + curr->filename, curr->filename,
59319 + &fakeip, 0, type,
59320 + protocol, GR_BIND, &current->signal->saved_ip);
59321 + }
59322 + /* we'll log when they use connect or bind */
59323 + goto exit;
59324 + }
59325 +
59326 +exit_fail:
59327 + if (domain == PF_INET)
59328 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
59329 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
59330 + else
59331 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
59332 + gr_socktype_to_name(type), protocol);
59333 +
59334 + return 0;
59335 +exit:
59336 + return 1;
59337 +}
59338 +
59339 +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)
59340 +{
59341 + if ((ip->mode & mode) &&
59342 + (ip_port >= ip->low) &&
59343 + (ip_port <= ip->high) &&
59344 + ((ntohl(ip_addr) & our_netmask) ==
59345 + (ntohl(our_addr) & our_netmask))
59346 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
59347 + && (ip->type & (1 << type))) {
59348 + if (ip->mode & GR_INVERT)
59349 + return 2; // specifically denied
59350 + else
59351 + return 1; // allowed
59352 + }
59353 +
59354 + return 0; // not specifically allowed, may continue parsing
59355 +}
59356 +
59357 +static int
59358 +gr_search_connectbind(const int full_mode, struct sock *sk,
59359 + struct sockaddr_in *addr, const int type)
59360 +{
59361 + char iface[IFNAMSIZ] = {0};
59362 + struct acl_subject_label *curr;
59363 + struct acl_ip_label *ip;
59364 + struct inet_sock *isk;
59365 + struct net_device *dev;
59366 + struct in_device *idev;
59367 + unsigned long i;
59368 + int ret;
59369 + int mode = full_mode & (GR_BIND | GR_CONNECT);
59370 + __u32 ip_addr = 0;
59371 + __u32 our_addr;
59372 + __u32 our_netmask;
59373 + char *p;
59374 + __u16 ip_port = 0;
59375 + const struct cred *cred = current_cred();
59376 +
59377 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
59378 + return 0;
59379 +
59380 + curr = current->acl;
59381 + isk = inet_sk(sk);
59382 +
59383 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
59384 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
59385 + addr->sin_addr.s_addr = curr->inaddr_any_override;
59386 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
59387 + struct sockaddr_in saddr;
59388 + int err;
59389 +
59390 + saddr.sin_family = AF_INET;
59391 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
59392 + saddr.sin_port = isk->inet_sport;
59393 +
59394 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59395 + if (err)
59396 + return err;
59397 +
59398 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
59399 + if (err)
59400 + return err;
59401 + }
59402 +
59403 + if (!curr->ips)
59404 + return 0;
59405 +
59406 + ip_addr = addr->sin_addr.s_addr;
59407 + ip_port = ntohs(addr->sin_port);
59408 +
59409 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
59410 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
59411 + current->role->roletype, cred->uid,
59412 + cred->gid, current->exec_file ?
59413 + gr_to_filename(current->exec_file->f_path.dentry,
59414 + current->exec_file->f_path.mnt) :
59415 + curr->filename, curr->filename,
59416 + &ip_addr, ip_port, type,
59417 + sk->sk_protocol, mode, &current->signal->saved_ip);
59418 + return 0;
59419 + }
59420 +
59421 + for (i = 0; i < curr->ip_num; i++) {
59422 + ip = *(curr->ips + i);
59423 + if (ip->iface != NULL) {
59424 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
59425 + p = strchr(iface, ':');
59426 + if (p != NULL)
59427 + *p = '\0';
59428 + dev = dev_get_by_name(sock_net(sk), iface);
59429 + if (dev == NULL)
59430 + continue;
59431 + idev = in_dev_get(dev);
59432 + if (idev == NULL) {
59433 + dev_put(dev);
59434 + continue;
59435 + }
59436 + rcu_read_lock();
59437 + for_ifa(idev) {
59438 + if (!strcmp(ip->iface, ifa->ifa_label)) {
59439 + our_addr = ifa->ifa_address;
59440 + our_netmask = 0xffffffff;
59441 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59442 + if (ret == 1) {
59443 + rcu_read_unlock();
59444 + in_dev_put(idev);
59445 + dev_put(dev);
59446 + return 0;
59447 + } else if (ret == 2) {
59448 + rcu_read_unlock();
59449 + in_dev_put(idev);
59450 + dev_put(dev);
59451 + goto denied;
59452 + }
59453 + }
59454 + } endfor_ifa(idev);
59455 + rcu_read_unlock();
59456 + in_dev_put(idev);
59457 + dev_put(dev);
59458 + } else {
59459 + our_addr = ip->addr;
59460 + our_netmask = ip->netmask;
59461 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
59462 + if (ret == 1)
59463 + return 0;
59464 + else if (ret == 2)
59465 + goto denied;
59466 + }
59467 + }
59468 +
59469 +denied:
59470 + if (mode == GR_BIND)
59471 + 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));
59472 + else if (mode == GR_CONNECT)
59473 + 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));
59474 +
59475 + return -EACCES;
59476 +}
59477 +
59478 +int
59479 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
59480 +{
59481 + /* always allow disconnection of dgram sockets with connect */
59482 + if (addr->sin_family == AF_UNSPEC)
59483 + return 0;
59484 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
59485 +}
59486 +
59487 +int
59488 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
59489 +{
59490 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
59491 +}
59492 +
59493 +int gr_search_listen(struct socket *sock)
59494 +{
59495 + struct sock *sk = sock->sk;
59496 + struct sockaddr_in addr;
59497 +
59498 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59499 + addr.sin_port = inet_sk(sk)->inet_sport;
59500 +
59501 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59502 +}
59503 +
59504 +int gr_search_accept(struct socket *sock)
59505 +{
59506 + struct sock *sk = sock->sk;
59507 + struct sockaddr_in addr;
59508 +
59509 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
59510 + addr.sin_port = inet_sk(sk)->inet_sport;
59511 +
59512 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
59513 +}
59514 +
59515 +int
59516 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
59517 +{
59518 + if (addr)
59519 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
59520 + else {
59521 + struct sockaddr_in sin;
59522 + const struct inet_sock *inet = inet_sk(sk);
59523 +
59524 + sin.sin_addr.s_addr = inet->inet_daddr;
59525 + sin.sin_port = inet->inet_dport;
59526 +
59527 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59528 + }
59529 +}
59530 +
59531 +int
59532 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
59533 +{
59534 + struct sockaddr_in sin;
59535 +
59536 + if (unlikely(skb->len < sizeof (struct udphdr)))
59537 + return 0; // skip this packet
59538 +
59539 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
59540 + sin.sin_port = udp_hdr(skb)->source;
59541 +
59542 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
59543 +}
59544 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
59545 new file mode 100644
59546 index 0000000..25f54ef
59547 --- /dev/null
59548 +++ b/grsecurity/gracl_learn.c
59549 @@ -0,0 +1,207 @@
59550 +#include <linux/kernel.h>
59551 +#include <linux/mm.h>
59552 +#include <linux/sched.h>
59553 +#include <linux/poll.h>
59554 +#include <linux/string.h>
59555 +#include <linux/file.h>
59556 +#include <linux/types.h>
59557 +#include <linux/vmalloc.h>
59558 +#include <linux/grinternal.h>
59559 +
59560 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
59561 + size_t count, loff_t *ppos);
59562 +extern int gr_acl_is_enabled(void);
59563 +
59564 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
59565 +static int gr_learn_attached;
59566 +
59567 +/* use a 512k buffer */
59568 +#define LEARN_BUFFER_SIZE (512 * 1024)
59569 +
59570 +static DEFINE_SPINLOCK(gr_learn_lock);
59571 +static DEFINE_MUTEX(gr_learn_user_mutex);
59572 +
59573 +/* we need to maintain two buffers, so that the kernel context of grlearn
59574 + uses a semaphore around the userspace copying, and the other kernel contexts
59575 + use a spinlock when copying into the buffer, since they cannot sleep
59576 +*/
59577 +static char *learn_buffer;
59578 +static char *learn_buffer_user;
59579 +static int learn_buffer_len;
59580 +static int learn_buffer_user_len;
59581 +
59582 +static ssize_t
59583 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
59584 +{
59585 + DECLARE_WAITQUEUE(wait, current);
59586 + ssize_t retval = 0;
59587 +
59588 + add_wait_queue(&learn_wait, &wait);
59589 + set_current_state(TASK_INTERRUPTIBLE);
59590 + do {
59591 + mutex_lock(&gr_learn_user_mutex);
59592 + spin_lock(&gr_learn_lock);
59593 + if (learn_buffer_len)
59594 + break;
59595 + spin_unlock(&gr_learn_lock);
59596 + mutex_unlock(&gr_learn_user_mutex);
59597 + if (file->f_flags & O_NONBLOCK) {
59598 + retval = -EAGAIN;
59599 + goto out;
59600 + }
59601 + if (signal_pending(current)) {
59602 + retval = -ERESTARTSYS;
59603 + goto out;
59604 + }
59605 +
59606 + schedule();
59607 + } while (1);
59608 +
59609 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
59610 + learn_buffer_user_len = learn_buffer_len;
59611 + retval = learn_buffer_len;
59612 + learn_buffer_len = 0;
59613 +
59614 + spin_unlock(&gr_learn_lock);
59615 +
59616 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
59617 + retval = -EFAULT;
59618 +
59619 + mutex_unlock(&gr_learn_user_mutex);
59620 +out:
59621 + set_current_state(TASK_RUNNING);
59622 + remove_wait_queue(&learn_wait, &wait);
59623 + return retval;
59624 +}
59625 +
59626 +static unsigned int
59627 +poll_learn(struct file * file, poll_table * wait)
59628 +{
59629 + poll_wait(file, &learn_wait, wait);
59630 +
59631 + if (learn_buffer_len)
59632 + return (POLLIN | POLLRDNORM);
59633 +
59634 + return 0;
59635 +}
59636 +
59637 +void
59638 +gr_clear_learn_entries(void)
59639 +{
59640 + char *tmp;
59641 +
59642 + mutex_lock(&gr_learn_user_mutex);
59643 + spin_lock(&gr_learn_lock);
59644 + tmp = learn_buffer;
59645 + learn_buffer = NULL;
59646 + spin_unlock(&gr_learn_lock);
59647 + if (tmp)
59648 + vfree(tmp);
59649 + if (learn_buffer_user != NULL) {
59650 + vfree(learn_buffer_user);
59651 + learn_buffer_user = NULL;
59652 + }
59653 + learn_buffer_len = 0;
59654 + mutex_unlock(&gr_learn_user_mutex);
59655 +
59656 + return;
59657 +}
59658 +
59659 +void
59660 +gr_add_learn_entry(const char *fmt, ...)
59661 +{
59662 + va_list args;
59663 + unsigned int len;
59664 +
59665 + if (!gr_learn_attached)
59666 + return;
59667 +
59668 + spin_lock(&gr_learn_lock);
59669 +
59670 + /* leave a gap at the end so we know when it's "full" but don't have to
59671 + compute the exact length of the string we're trying to append
59672 + */
59673 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
59674 + spin_unlock(&gr_learn_lock);
59675 + wake_up_interruptible(&learn_wait);
59676 + return;
59677 + }
59678 + if (learn_buffer == NULL) {
59679 + spin_unlock(&gr_learn_lock);
59680 + return;
59681 + }
59682 +
59683 + va_start(args, fmt);
59684 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
59685 + va_end(args);
59686 +
59687 + learn_buffer_len += len + 1;
59688 +
59689 + spin_unlock(&gr_learn_lock);
59690 + wake_up_interruptible(&learn_wait);
59691 +
59692 + return;
59693 +}
59694 +
59695 +static int
59696 +open_learn(struct inode *inode, struct file *file)
59697 +{
59698 + if (file->f_mode & FMODE_READ && gr_learn_attached)
59699 + return -EBUSY;
59700 + if (file->f_mode & FMODE_READ) {
59701 + int retval = 0;
59702 + mutex_lock(&gr_learn_user_mutex);
59703 + if (learn_buffer == NULL)
59704 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
59705 + if (learn_buffer_user == NULL)
59706 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
59707 + if (learn_buffer == NULL) {
59708 + retval = -ENOMEM;
59709 + goto out_error;
59710 + }
59711 + if (learn_buffer_user == NULL) {
59712 + retval = -ENOMEM;
59713 + goto out_error;
59714 + }
59715 + learn_buffer_len = 0;
59716 + learn_buffer_user_len = 0;
59717 + gr_learn_attached = 1;
59718 +out_error:
59719 + mutex_unlock(&gr_learn_user_mutex);
59720 + return retval;
59721 + }
59722 + return 0;
59723 +}
59724 +
59725 +static int
59726 +close_learn(struct inode *inode, struct file *file)
59727 +{
59728 + if (file->f_mode & FMODE_READ) {
59729 + char *tmp = NULL;
59730 + mutex_lock(&gr_learn_user_mutex);
59731 + spin_lock(&gr_learn_lock);
59732 + tmp = learn_buffer;
59733 + learn_buffer = NULL;
59734 + spin_unlock(&gr_learn_lock);
59735 + if (tmp)
59736 + vfree(tmp);
59737 + if (learn_buffer_user != NULL) {
59738 + vfree(learn_buffer_user);
59739 + learn_buffer_user = NULL;
59740 + }
59741 + learn_buffer_len = 0;
59742 + learn_buffer_user_len = 0;
59743 + gr_learn_attached = 0;
59744 + mutex_unlock(&gr_learn_user_mutex);
59745 + }
59746 +
59747 + return 0;
59748 +}
59749 +
59750 +const struct file_operations grsec_fops = {
59751 + .read = read_learn,
59752 + .write = write_grsec_handler,
59753 + .open = open_learn,
59754 + .release = close_learn,
59755 + .poll = poll_learn,
59756 +};
59757 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
59758 new file mode 100644
59759 index 0000000..39645c9
59760 --- /dev/null
59761 +++ b/grsecurity/gracl_res.c
59762 @@ -0,0 +1,68 @@
59763 +#include <linux/kernel.h>
59764 +#include <linux/sched.h>
59765 +#include <linux/gracl.h>
59766 +#include <linux/grinternal.h>
59767 +
59768 +static const char *restab_log[] = {
59769 + [RLIMIT_CPU] = "RLIMIT_CPU",
59770 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
59771 + [RLIMIT_DATA] = "RLIMIT_DATA",
59772 + [RLIMIT_STACK] = "RLIMIT_STACK",
59773 + [RLIMIT_CORE] = "RLIMIT_CORE",
59774 + [RLIMIT_RSS] = "RLIMIT_RSS",
59775 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
59776 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
59777 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
59778 + [RLIMIT_AS] = "RLIMIT_AS",
59779 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
59780 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
59781 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
59782 + [RLIMIT_NICE] = "RLIMIT_NICE",
59783 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
59784 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
59785 + [GR_CRASH_RES] = "RLIMIT_CRASH"
59786 +};
59787 +
59788 +void
59789 +gr_log_resource(const struct task_struct *task,
59790 + const int res, const unsigned long wanted, const int gt)
59791 +{
59792 + const struct cred *cred;
59793 + unsigned long rlim;
59794 +
59795 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
59796 + return;
59797 +
59798 + // not yet supported resource
59799 + if (unlikely(!restab_log[res]))
59800 + return;
59801 +
59802 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
59803 + rlim = task_rlimit_max(task, res);
59804 + else
59805 + rlim = task_rlimit(task, res);
59806 +
59807 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
59808 + return;
59809 +
59810 + rcu_read_lock();
59811 + cred = __task_cred(task);
59812 +
59813 + if (res == RLIMIT_NPROC &&
59814 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
59815 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
59816 + goto out_rcu_unlock;
59817 + else if (res == RLIMIT_MEMLOCK &&
59818 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
59819 + goto out_rcu_unlock;
59820 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
59821 + goto out_rcu_unlock;
59822 + rcu_read_unlock();
59823 +
59824 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
59825 +
59826 + return;
59827 +out_rcu_unlock:
59828 + rcu_read_unlock();
59829 + return;
59830 +}
59831 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
59832 new file mode 100644
59833 index 0000000..25197e9
59834 --- /dev/null
59835 +++ b/grsecurity/gracl_segv.c
59836 @@ -0,0 +1,299 @@
59837 +#include <linux/kernel.h>
59838 +#include <linux/mm.h>
59839 +#include <asm/uaccess.h>
59840 +#include <asm/errno.h>
59841 +#include <asm/mman.h>
59842 +#include <net/sock.h>
59843 +#include <linux/file.h>
59844 +#include <linux/fs.h>
59845 +#include <linux/net.h>
59846 +#include <linux/in.h>
59847 +#include <linux/slab.h>
59848 +#include <linux/types.h>
59849 +#include <linux/sched.h>
59850 +#include <linux/timer.h>
59851 +#include <linux/gracl.h>
59852 +#include <linux/grsecurity.h>
59853 +#include <linux/grinternal.h>
59854 +
59855 +static struct crash_uid *uid_set;
59856 +static unsigned short uid_used;
59857 +static DEFINE_SPINLOCK(gr_uid_lock);
59858 +extern rwlock_t gr_inode_lock;
59859 +extern struct acl_subject_label *
59860 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
59861 + struct acl_role_label *role);
59862 +
59863 +#ifdef CONFIG_BTRFS_FS
59864 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
59865 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
59866 +#endif
59867 +
59868 +static inline dev_t __get_dev(const struct dentry *dentry)
59869 +{
59870 +#ifdef CONFIG_BTRFS_FS
59871 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
59872 + return get_btrfs_dev_from_inode(dentry->d_inode);
59873 + else
59874 +#endif
59875 + return dentry->d_inode->i_sb->s_dev;
59876 +}
59877 +
59878 +int
59879 +gr_init_uidset(void)
59880 +{
59881 + uid_set =
59882 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
59883 + uid_used = 0;
59884 +
59885 + return uid_set ? 1 : 0;
59886 +}
59887 +
59888 +void
59889 +gr_free_uidset(void)
59890 +{
59891 + if (uid_set)
59892 + kfree(uid_set);
59893 +
59894 + return;
59895 +}
59896 +
59897 +int
59898 +gr_find_uid(const uid_t uid)
59899 +{
59900 + struct crash_uid *tmp = uid_set;
59901 + uid_t buid;
59902 + int low = 0, high = uid_used - 1, mid;
59903 +
59904 + while (high >= low) {
59905 + mid = (low + high) >> 1;
59906 + buid = tmp[mid].uid;
59907 + if (buid == uid)
59908 + return mid;
59909 + if (buid > uid)
59910 + high = mid - 1;
59911 + if (buid < uid)
59912 + low = mid + 1;
59913 + }
59914 +
59915 + return -1;
59916 +}
59917 +
59918 +static __inline__ void
59919 +gr_insertsort(void)
59920 +{
59921 + unsigned short i, j;
59922 + struct crash_uid index;
59923 +
59924 + for (i = 1; i < uid_used; i++) {
59925 + index = uid_set[i];
59926 + j = i;
59927 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
59928 + uid_set[j] = uid_set[j - 1];
59929 + j--;
59930 + }
59931 + uid_set[j] = index;
59932 + }
59933 +
59934 + return;
59935 +}
59936 +
59937 +static __inline__ void
59938 +gr_insert_uid(const uid_t uid, const unsigned long expires)
59939 +{
59940 + int loc;
59941 +
59942 + if (uid_used == GR_UIDTABLE_MAX)
59943 + return;
59944 +
59945 + loc = gr_find_uid(uid);
59946 +
59947 + if (loc >= 0) {
59948 + uid_set[loc].expires = expires;
59949 + return;
59950 + }
59951 +
59952 + uid_set[uid_used].uid = uid;
59953 + uid_set[uid_used].expires = expires;
59954 + uid_used++;
59955 +
59956 + gr_insertsort();
59957 +
59958 + return;
59959 +}
59960 +
59961 +void
59962 +gr_remove_uid(const unsigned short loc)
59963 +{
59964 + unsigned short i;
59965 +
59966 + for (i = loc + 1; i < uid_used; i++)
59967 + uid_set[i - 1] = uid_set[i];
59968 +
59969 + uid_used--;
59970 +
59971 + return;
59972 +}
59973 +
59974 +int
59975 +gr_check_crash_uid(const uid_t uid)
59976 +{
59977 + int loc;
59978 + int ret = 0;
59979 +
59980 + if (unlikely(!gr_acl_is_enabled()))
59981 + return 0;
59982 +
59983 + spin_lock(&gr_uid_lock);
59984 + loc = gr_find_uid(uid);
59985 +
59986 + if (loc < 0)
59987 + goto out_unlock;
59988 +
59989 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
59990 + gr_remove_uid(loc);
59991 + else
59992 + ret = 1;
59993 +
59994 +out_unlock:
59995 + spin_unlock(&gr_uid_lock);
59996 + return ret;
59997 +}
59998 +
59999 +static __inline__ int
60000 +proc_is_setxid(const struct cred *cred)
60001 +{
60002 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
60003 + !uid_eq(cred->uid, cred->fsuid))
60004 + return 1;
60005 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
60006 + !uid_eq(cred->gid, cred->fsgid))
60007 + return 1;
60008 +
60009 + return 0;
60010 +}
60011 +
60012 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
60013 +
60014 +void
60015 +gr_handle_crash(struct task_struct *task, const int sig)
60016 +{
60017 + struct acl_subject_label *curr;
60018 + struct task_struct *tsk, *tsk2;
60019 + const struct cred *cred;
60020 + const struct cred *cred2;
60021 +
60022 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
60023 + return;
60024 +
60025 + if (unlikely(!gr_acl_is_enabled()))
60026 + return;
60027 +
60028 + curr = task->acl;
60029 +
60030 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
60031 + return;
60032 +
60033 + if (time_before_eq(curr->expires, get_seconds())) {
60034 + curr->expires = 0;
60035 + curr->crashes = 0;
60036 + }
60037 +
60038 + curr->crashes++;
60039 +
60040 + if (!curr->expires)
60041 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
60042 +
60043 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60044 + time_after(curr->expires, get_seconds())) {
60045 + rcu_read_lock();
60046 + cred = __task_cred(task);
60047 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
60048 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60049 + spin_lock(&gr_uid_lock);
60050 + gr_insert_uid(cred->uid, curr->expires);
60051 + spin_unlock(&gr_uid_lock);
60052 + curr->expires = 0;
60053 + curr->crashes = 0;
60054 + read_lock(&tasklist_lock);
60055 + do_each_thread(tsk2, tsk) {
60056 + cred2 = __task_cred(tsk);
60057 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
60058 + gr_fake_force_sig(SIGKILL, tsk);
60059 + } while_each_thread(tsk2, tsk);
60060 + read_unlock(&tasklist_lock);
60061 + } else {
60062 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
60063 + read_lock(&tasklist_lock);
60064 + read_lock(&grsec_exec_file_lock);
60065 + do_each_thread(tsk2, tsk) {
60066 + if (likely(tsk != task)) {
60067 + // if this thread has the same subject as the one that triggered
60068 + // RES_CRASH and it's the same binary, kill it
60069 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
60070 + gr_fake_force_sig(SIGKILL, tsk);
60071 + }
60072 + } while_each_thread(tsk2, tsk);
60073 + read_unlock(&grsec_exec_file_lock);
60074 + read_unlock(&tasklist_lock);
60075 + }
60076 + rcu_read_unlock();
60077 + }
60078 +
60079 + return;
60080 +}
60081 +
60082 +int
60083 +gr_check_crash_exec(const struct file *filp)
60084 +{
60085 + struct acl_subject_label *curr;
60086 +
60087 + if (unlikely(!gr_acl_is_enabled()))
60088 + return 0;
60089 +
60090 + read_lock(&gr_inode_lock);
60091 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
60092 + __get_dev(filp->f_path.dentry),
60093 + current->role);
60094 + read_unlock(&gr_inode_lock);
60095 +
60096 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
60097 + (!curr->crashes && !curr->expires))
60098 + return 0;
60099 +
60100 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
60101 + time_after(curr->expires, get_seconds()))
60102 + return 1;
60103 + else if (time_before_eq(curr->expires, get_seconds())) {
60104 + curr->crashes = 0;
60105 + curr->expires = 0;
60106 + }
60107 +
60108 + return 0;
60109 +}
60110 +
60111 +void
60112 +gr_handle_alertkill(struct task_struct *task)
60113 +{
60114 + struct acl_subject_label *curracl;
60115 + __u32 curr_ip;
60116 + struct task_struct *p, *p2;
60117 +
60118 + if (unlikely(!gr_acl_is_enabled()))
60119 + return;
60120 +
60121 + curracl = task->acl;
60122 + curr_ip = task->signal->curr_ip;
60123 +
60124 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
60125 + read_lock(&tasklist_lock);
60126 + do_each_thread(p2, p) {
60127 + if (p->signal->curr_ip == curr_ip)
60128 + gr_fake_force_sig(SIGKILL, p);
60129 + } while_each_thread(p2, p);
60130 + read_unlock(&tasklist_lock);
60131 + } else if (curracl->mode & GR_KILLPROC)
60132 + gr_fake_force_sig(SIGKILL, task);
60133 +
60134 + return;
60135 +}
60136 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
60137 new file mode 100644
60138 index 0000000..9d83a69
60139 --- /dev/null
60140 +++ b/grsecurity/gracl_shm.c
60141 @@ -0,0 +1,40 @@
60142 +#include <linux/kernel.h>
60143 +#include <linux/mm.h>
60144 +#include <linux/sched.h>
60145 +#include <linux/file.h>
60146 +#include <linux/ipc.h>
60147 +#include <linux/gracl.h>
60148 +#include <linux/grsecurity.h>
60149 +#include <linux/grinternal.h>
60150 +
60151 +int
60152 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60153 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60154 +{
60155 + struct task_struct *task;
60156 +
60157 + if (!gr_acl_is_enabled())
60158 + return 1;
60159 +
60160 + rcu_read_lock();
60161 + read_lock(&tasklist_lock);
60162 +
60163 + task = find_task_by_vpid(shm_cprid);
60164 +
60165 + if (unlikely(!task))
60166 + task = find_task_by_vpid(shm_lapid);
60167 +
60168 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
60169 + (task->pid == shm_lapid)) &&
60170 + (task->acl->mode & GR_PROTSHM) &&
60171 + (task->acl != current->acl))) {
60172 + read_unlock(&tasklist_lock);
60173 + rcu_read_unlock();
60174 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
60175 + return 0;
60176 + }
60177 + read_unlock(&tasklist_lock);
60178 + rcu_read_unlock();
60179 +
60180 + return 1;
60181 +}
60182 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
60183 new file mode 100644
60184 index 0000000..bc0be01
60185 --- /dev/null
60186 +++ b/grsecurity/grsec_chdir.c
60187 @@ -0,0 +1,19 @@
60188 +#include <linux/kernel.h>
60189 +#include <linux/sched.h>
60190 +#include <linux/fs.h>
60191 +#include <linux/file.h>
60192 +#include <linux/grsecurity.h>
60193 +#include <linux/grinternal.h>
60194 +
60195 +void
60196 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
60197 +{
60198 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60199 + if ((grsec_enable_chdir && grsec_enable_group &&
60200 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
60201 + !grsec_enable_group)) {
60202 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
60203 + }
60204 +#endif
60205 + return;
60206 +}
60207 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
60208 new file mode 100644
60209 index 0000000..70fe0ae
60210 --- /dev/null
60211 +++ b/grsecurity/grsec_chroot.c
60212 @@ -0,0 +1,357 @@
60213 +#include <linux/kernel.h>
60214 +#include <linux/module.h>
60215 +#include <linux/sched.h>
60216 +#include <linux/file.h>
60217 +#include <linux/fs.h>
60218 +#include <linux/mount.h>
60219 +#include <linux/types.h>
60220 +#include "../fs/mount.h"
60221 +#include <linux/grsecurity.h>
60222 +#include <linux/grinternal.h>
60223 +
60224 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
60225 +{
60226 +#ifdef CONFIG_GRKERNSEC
60227 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
60228 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
60229 + task->gr_is_chrooted = 1;
60230 + else
60231 + task->gr_is_chrooted = 0;
60232 +
60233 + task->gr_chroot_dentry = path->dentry;
60234 +#endif
60235 + return;
60236 +}
60237 +
60238 +void gr_clear_chroot_entries(struct task_struct *task)
60239 +{
60240 +#ifdef CONFIG_GRKERNSEC
60241 + task->gr_is_chrooted = 0;
60242 + task->gr_chroot_dentry = NULL;
60243 +#endif
60244 + return;
60245 +}
60246 +
60247 +int
60248 +gr_handle_chroot_unix(const pid_t pid)
60249 +{
60250 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60251 + struct task_struct *p;
60252 +
60253 + if (unlikely(!grsec_enable_chroot_unix))
60254 + return 1;
60255 +
60256 + if (likely(!proc_is_chrooted(current)))
60257 + return 1;
60258 +
60259 + rcu_read_lock();
60260 + read_lock(&tasklist_lock);
60261 + p = find_task_by_vpid_unrestricted(pid);
60262 + if (unlikely(p && !have_same_root(current, p))) {
60263 + read_unlock(&tasklist_lock);
60264 + rcu_read_unlock();
60265 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
60266 + return 0;
60267 + }
60268 + read_unlock(&tasklist_lock);
60269 + rcu_read_unlock();
60270 +#endif
60271 + return 1;
60272 +}
60273 +
60274 +int
60275 +gr_handle_chroot_nice(void)
60276 +{
60277 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60278 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
60279 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
60280 + return -EPERM;
60281 + }
60282 +#endif
60283 + return 0;
60284 +}
60285 +
60286 +int
60287 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
60288 +{
60289 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60290 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
60291 + && proc_is_chrooted(current)) {
60292 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
60293 + return -EACCES;
60294 + }
60295 +#endif
60296 + return 0;
60297 +}
60298 +
60299 +int
60300 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
60301 +{
60302 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60303 + struct task_struct *p;
60304 + int ret = 0;
60305 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
60306 + return ret;
60307 +
60308 + read_lock(&tasklist_lock);
60309 + do_each_pid_task(pid, type, p) {
60310 + if (!have_same_root(current, p)) {
60311 + ret = 1;
60312 + goto out;
60313 + }
60314 + } while_each_pid_task(pid, type, p);
60315 +out:
60316 + read_unlock(&tasklist_lock);
60317 + return ret;
60318 +#endif
60319 + return 0;
60320 +}
60321 +
60322 +int
60323 +gr_pid_is_chrooted(struct task_struct *p)
60324 +{
60325 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60326 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
60327 + return 0;
60328 +
60329 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
60330 + !have_same_root(current, p)) {
60331 + return 1;
60332 + }
60333 +#endif
60334 + return 0;
60335 +}
60336 +
60337 +EXPORT_SYMBOL(gr_pid_is_chrooted);
60338 +
60339 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
60340 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
60341 +{
60342 + struct path path, currentroot;
60343 + int ret = 0;
60344 +
60345 + path.dentry = (struct dentry *)u_dentry;
60346 + path.mnt = (struct vfsmount *)u_mnt;
60347 + get_fs_root(current->fs, &currentroot);
60348 + if (path_is_under(&path, &currentroot))
60349 + ret = 1;
60350 + path_put(&currentroot);
60351 +
60352 + return ret;
60353 +}
60354 +#endif
60355 +
60356 +int
60357 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
60358 +{
60359 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60360 + if (!grsec_enable_chroot_fchdir)
60361 + return 1;
60362 +
60363 + if (!proc_is_chrooted(current))
60364 + return 1;
60365 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
60366 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
60367 + return 0;
60368 + }
60369 +#endif
60370 + return 1;
60371 +}
60372 +
60373 +int
60374 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60375 + const time_t shm_createtime)
60376 +{
60377 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60378 + struct task_struct *p;
60379 + time_t starttime;
60380 +
60381 + if (unlikely(!grsec_enable_chroot_shmat))
60382 + return 1;
60383 +
60384 + if (likely(!proc_is_chrooted(current)))
60385 + return 1;
60386 +
60387 + rcu_read_lock();
60388 + read_lock(&tasklist_lock);
60389 +
60390 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
60391 + starttime = p->start_time.tv_sec;
60392 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
60393 + if (have_same_root(current, p)) {
60394 + goto allow;
60395 + } else {
60396 + read_unlock(&tasklist_lock);
60397 + rcu_read_unlock();
60398 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60399 + return 0;
60400 + }
60401 + }
60402 + /* creator exited, pid reuse, fall through to next check */
60403 + }
60404 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
60405 + if (unlikely(!have_same_root(current, p))) {
60406 + read_unlock(&tasklist_lock);
60407 + rcu_read_unlock();
60408 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
60409 + return 0;
60410 + }
60411 + }
60412 +
60413 +allow:
60414 + read_unlock(&tasklist_lock);
60415 + rcu_read_unlock();
60416 +#endif
60417 + return 1;
60418 +}
60419 +
60420 +void
60421 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
60422 +{
60423 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60424 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
60425 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
60426 +#endif
60427 + return;
60428 +}
60429 +
60430 +int
60431 +gr_handle_chroot_mknod(const struct dentry *dentry,
60432 + const struct vfsmount *mnt, const int mode)
60433 +{
60434 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60435 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
60436 + proc_is_chrooted(current)) {
60437 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
60438 + return -EPERM;
60439 + }
60440 +#endif
60441 + return 0;
60442 +}
60443 +
60444 +int
60445 +gr_handle_chroot_mount(const struct dentry *dentry,
60446 + const struct vfsmount *mnt, const char *dev_name)
60447 +{
60448 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60449 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
60450 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
60451 + return -EPERM;
60452 + }
60453 +#endif
60454 + return 0;
60455 +}
60456 +
60457 +int
60458 +gr_handle_chroot_pivot(void)
60459 +{
60460 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60461 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
60462 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
60463 + return -EPERM;
60464 + }
60465 +#endif
60466 + return 0;
60467 +}
60468 +
60469 +int
60470 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
60471 +{
60472 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60473 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
60474 + !gr_is_outside_chroot(dentry, mnt)) {
60475 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
60476 + return -EPERM;
60477 + }
60478 +#endif
60479 + return 0;
60480 +}
60481 +
60482 +extern const char *captab_log[];
60483 +extern int captab_log_entries;
60484 +
60485 +int
60486 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60487 +{
60488 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60489 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60490 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60491 + if (cap_raised(chroot_caps, cap)) {
60492 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
60493 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
60494 + }
60495 + return 0;
60496 + }
60497 + }
60498 +#endif
60499 + return 1;
60500 +}
60501 +
60502 +int
60503 +gr_chroot_is_capable(const int cap)
60504 +{
60505 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60506 + return gr_task_chroot_is_capable(current, current_cred(), cap);
60507 +#endif
60508 + return 1;
60509 +}
60510 +
60511 +int
60512 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
60513 +{
60514 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60515 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
60516 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
60517 + if (cap_raised(chroot_caps, cap)) {
60518 + return 0;
60519 + }
60520 + }
60521 +#endif
60522 + return 1;
60523 +}
60524 +
60525 +int
60526 +gr_chroot_is_capable_nolog(const int cap)
60527 +{
60528 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60529 + return gr_task_chroot_is_capable_nolog(current, cap);
60530 +#endif
60531 + return 1;
60532 +}
60533 +
60534 +int
60535 +gr_handle_chroot_sysctl(const int op)
60536 +{
60537 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60538 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
60539 + proc_is_chrooted(current))
60540 + return -EACCES;
60541 +#endif
60542 + return 0;
60543 +}
60544 +
60545 +void
60546 +gr_handle_chroot_chdir(struct path *path)
60547 +{
60548 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60549 + if (grsec_enable_chroot_chdir)
60550 + set_fs_pwd(current->fs, path);
60551 +#endif
60552 + return;
60553 +}
60554 +
60555 +int
60556 +gr_handle_chroot_chmod(const struct dentry *dentry,
60557 + const struct vfsmount *mnt, const int mode)
60558 +{
60559 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60560 + /* allow chmod +s on directories, but not files */
60561 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
60562 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
60563 + proc_is_chrooted(current)) {
60564 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
60565 + return -EPERM;
60566 + }
60567 +#endif
60568 + return 0;
60569 +}
60570 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
60571 new file mode 100644
60572 index 0000000..e6796b3
60573 --- /dev/null
60574 +++ b/grsecurity/grsec_disabled.c
60575 @@ -0,0 +1,434 @@
60576 +#include <linux/kernel.h>
60577 +#include <linux/module.h>
60578 +#include <linux/sched.h>
60579 +#include <linux/file.h>
60580 +#include <linux/fs.h>
60581 +#include <linux/kdev_t.h>
60582 +#include <linux/net.h>
60583 +#include <linux/in.h>
60584 +#include <linux/ip.h>
60585 +#include <linux/skbuff.h>
60586 +#include <linux/sysctl.h>
60587 +
60588 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
60589 +void
60590 +pax_set_initial_flags(struct linux_binprm *bprm)
60591 +{
60592 + return;
60593 +}
60594 +#endif
60595 +
60596 +#ifdef CONFIG_SYSCTL
60597 +__u32
60598 +gr_handle_sysctl(const struct ctl_table * table, const int op)
60599 +{
60600 + return 0;
60601 +}
60602 +#endif
60603 +
60604 +#ifdef CONFIG_TASKSTATS
60605 +int gr_is_taskstats_denied(int pid)
60606 +{
60607 + return 0;
60608 +}
60609 +#endif
60610 +
60611 +int
60612 +gr_acl_is_enabled(void)
60613 +{
60614 + return 0;
60615 +}
60616 +
60617 +void
60618 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
60619 +{
60620 + return;
60621 +}
60622 +
60623 +int
60624 +gr_handle_rawio(const struct inode *inode)
60625 +{
60626 + return 0;
60627 +}
60628 +
60629 +void
60630 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60631 +{
60632 + return;
60633 +}
60634 +
60635 +int
60636 +gr_handle_ptrace(struct task_struct *task, const long request)
60637 +{
60638 + return 0;
60639 +}
60640 +
60641 +int
60642 +gr_handle_proc_ptrace(struct task_struct *task)
60643 +{
60644 + return 0;
60645 +}
60646 +
60647 +int
60648 +gr_set_acls(const int type)
60649 +{
60650 + return 0;
60651 +}
60652 +
60653 +int
60654 +gr_check_hidden_task(const struct task_struct *tsk)
60655 +{
60656 + return 0;
60657 +}
60658 +
60659 +int
60660 +gr_check_protected_task(const struct task_struct *task)
60661 +{
60662 + return 0;
60663 +}
60664 +
60665 +int
60666 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60667 +{
60668 + return 0;
60669 +}
60670 +
60671 +void
60672 +gr_copy_label(struct task_struct *tsk)
60673 +{
60674 + return;
60675 +}
60676 +
60677 +void
60678 +gr_set_pax_flags(struct task_struct *task)
60679 +{
60680 + return;
60681 +}
60682 +
60683 +int
60684 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60685 + const int unsafe_share)
60686 +{
60687 + return 0;
60688 +}
60689 +
60690 +void
60691 +gr_handle_delete(const ino_t ino, const dev_t dev)
60692 +{
60693 + return;
60694 +}
60695 +
60696 +void
60697 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
60698 +{
60699 + return;
60700 +}
60701 +
60702 +void
60703 +gr_handle_crash(struct task_struct *task, const int sig)
60704 +{
60705 + return;
60706 +}
60707 +
60708 +int
60709 +gr_check_crash_exec(const struct file *filp)
60710 +{
60711 + return 0;
60712 +}
60713 +
60714 +int
60715 +gr_check_crash_uid(const uid_t uid)
60716 +{
60717 + return 0;
60718 +}
60719 +
60720 +void
60721 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
60722 + struct dentry *old_dentry,
60723 + struct dentry *new_dentry,
60724 + struct vfsmount *mnt, const __u8 replace)
60725 +{
60726 + return;
60727 +}
60728 +
60729 +int
60730 +gr_search_socket(const int family, const int type, const int protocol)
60731 +{
60732 + return 1;
60733 +}
60734 +
60735 +int
60736 +gr_search_connectbind(const int mode, const struct socket *sock,
60737 + const struct sockaddr_in *addr)
60738 +{
60739 + return 0;
60740 +}
60741 +
60742 +void
60743 +gr_handle_alertkill(struct task_struct *task)
60744 +{
60745 + return;
60746 +}
60747 +
60748 +__u32
60749 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
60750 +{
60751 + return 1;
60752 +}
60753 +
60754 +__u32
60755 +gr_acl_handle_hidden_file(const struct dentry * dentry,
60756 + const struct vfsmount * mnt)
60757 +{
60758 + return 1;
60759 +}
60760 +
60761 +__u32
60762 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
60763 + int acc_mode)
60764 +{
60765 + return 1;
60766 +}
60767 +
60768 +__u32
60769 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
60770 +{
60771 + return 1;
60772 +}
60773 +
60774 +__u32
60775 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
60776 +{
60777 + return 1;
60778 +}
60779 +
60780 +int
60781 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
60782 + unsigned int *vm_flags)
60783 +{
60784 + return 1;
60785 +}
60786 +
60787 +__u32
60788 +gr_acl_handle_truncate(const struct dentry * dentry,
60789 + const struct vfsmount * mnt)
60790 +{
60791 + return 1;
60792 +}
60793 +
60794 +__u32
60795 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
60796 +{
60797 + return 1;
60798 +}
60799 +
60800 +__u32
60801 +gr_acl_handle_access(const struct dentry * dentry,
60802 + const struct vfsmount * mnt, const int fmode)
60803 +{
60804 + return 1;
60805 +}
60806 +
60807 +__u32
60808 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
60809 + umode_t *mode)
60810 +{
60811 + return 1;
60812 +}
60813 +
60814 +__u32
60815 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
60816 +{
60817 + return 1;
60818 +}
60819 +
60820 +__u32
60821 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
60822 +{
60823 + return 1;
60824 +}
60825 +
60826 +void
60827 +grsecurity_init(void)
60828 +{
60829 + return;
60830 +}
60831 +
60832 +umode_t gr_acl_umask(void)
60833 +{
60834 + return 0;
60835 +}
60836 +
60837 +__u32
60838 +gr_acl_handle_mknod(const struct dentry * new_dentry,
60839 + const struct dentry * parent_dentry,
60840 + const struct vfsmount * parent_mnt,
60841 + const int mode)
60842 +{
60843 + return 1;
60844 +}
60845 +
60846 +__u32
60847 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
60848 + const struct dentry * parent_dentry,
60849 + const struct vfsmount * parent_mnt)
60850 +{
60851 + return 1;
60852 +}
60853 +
60854 +__u32
60855 +gr_acl_handle_symlink(const struct dentry * new_dentry,
60856 + const struct dentry * parent_dentry,
60857 + const struct vfsmount * parent_mnt, const struct filename *from)
60858 +{
60859 + return 1;
60860 +}
60861 +
60862 +__u32
60863 +gr_acl_handle_link(const struct dentry * new_dentry,
60864 + const struct dentry * parent_dentry,
60865 + const struct vfsmount * parent_mnt,
60866 + const struct dentry * old_dentry,
60867 + const struct vfsmount * old_mnt, const struct filename *to)
60868 +{
60869 + return 1;
60870 +}
60871 +
60872 +int
60873 +gr_acl_handle_rename(const struct dentry *new_dentry,
60874 + const struct dentry *parent_dentry,
60875 + const struct vfsmount *parent_mnt,
60876 + const struct dentry *old_dentry,
60877 + const struct inode *old_parent_inode,
60878 + const struct vfsmount *old_mnt, const struct filename *newname)
60879 +{
60880 + return 0;
60881 +}
60882 +
60883 +int
60884 +gr_acl_handle_filldir(const struct file *file, const char *name,
60885 + const int namelen, const ino_t ino)
60886 +{
60887 + return 1;
60888 +}
60889 +
60890 +int
60891 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
60892 + const time_t shm_createtime, const uid_t cuid, const int shmid)
60893 +{
60894 + return 1;
60895 +}
60896 +
60897 +int
60898 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
60899 +{
60900 + return 0;
60901 +}
60902 +
60903 +int
60904 +gr_search_accept(const struct socket *sock)
60905 +{
60906 + return 0;
60907 +}
60908 +
60909 +int
60910 +gr_search_listen(const struct socket *sock)
60911 +{
60912 + return 0;
60913 +}
60914 +
60915 +int
60916 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
60917 +{
60918 + return 0;
60919 +}
60920 +
60921 +__u32
60922 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
60923 +{
60924 + return 1;
60925 +}
60926 +
60927 +__u32
60928 +gr_acl_handle_creat(const struct dentry * dentry,
60929 + const struct dentry * p_dentry,
60930 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
60931 + const int imode)
60932 +{
60933 + return 1;
60934 +}
60935 +
60936 +void
60937 +gr_acl_handle_exit(void)
60938 +{
60939 + return;
60940 +}
60941 +
60942 +int
60943 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60944 +{
60945 + return 1;
60946 +}
60947 +
60948 +void
60949 +gr_set_role_label(const uid_t uid, const gid_t gid)
60950 +{
60951 + return;
60952 +}
60953 +
60954 +int
60955 +gr_acl_handle_procpidmem(const struct task_struct *task)
60956 +{
60957 + return 0;
60958 +}
60959 +
60960 +int
60961 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
60962 +{
60963 + return 0;
60964 +}
60965 +
60966 +int
60967 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
60968 +{
60969 + return 0;
60970 +}
60971 +
60972 +void
60973 +gr_set_kernel_label(struct task_struct *task)
60974 +{
60975 + return;
60976 +}
60977 +
60978 +int
60979 +gr_check_user_change(int real, int effective, int fs)
60980 +{
60981 + return 0;
60982 +}
60983 +
60984 +int
60985 +gr_check_group_change(int real, int effective, int fs)
60986 +{
60987 + return 0;
60988 +}
60989 +
60990 +int gr_acl_enable_at_secure(void)
60991 +{
60992 + return 0;
60993 +}
60994 +
60995 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
60996 +{
60997 + return dentry->d_inode->i_sb->s_dev;
60998 +}
60999 +
61000 +void gr_put_exec_file(struct task_struct *task)
61001 +{
61002 + return;
61003 +}
61004 +
61005 +EXPORT_SYMBOL(gr_set_kernel_label);
61006 +#ifdef CONFIG_SECURITY
61007 +EXPORT_SYMBOL(gr_check_user_change);
61008 +EXPORT_SYMBOL(gr_check_group_change);
61009 +#endif
61010 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
61011 new file mode 100644
61012 index 0000000..abfa971
61013 --- /dev/null
61014 +++ b/grsecurity/grsec_exec.c
61015 @@ -0,0 +1,174 @@
61016 +#include <linux/kernel.h>
61017 +#include <linux/sched.h>
61018 +#include <linux/file.h>
61019 +#include <linux/binfmts.h>
61020 +#include <linux/fs.h>
61021 +#include <linux/types.h>
61022 +#include <linux/grdefs.h>
61023 +#include <linux/grsecurity.h>
61024 +#include <linux/grinternal.h>
61025 +#include <linux/capability.h>
61026 +#include <linux/module.h>
61027 +
61028 +#include <asm/uaccess.h>
61029 +
61030 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61031 +static char gr_exec_arg_buf[132];
61032 +static DEFINE_MUTEX(gr_exec_arg_mutex);
61033 +#endif
61034 +
61035 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
61036 +
61037 +void
61038 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
61039 +{
61040 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61041 + char *grarg = gr_exec_arg_buf;
61042 + unsigned int i, x, execlen = 0;
61043 + char c;
61044 +
61045 + if (!((grsec_enable_execlog && grsec_enable_group &&
61046 + in_group_p(grsec_audit_gid))
61047 + || (grsec_enable_execlog && !grsec_enable_group)))
61048 + return;
61049 +
61050 + mutex_lock(&gr_exec_arg_mutex);
61051 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
61052 +
61053 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
61054 + const char __user *p;
61055 + unsigned int len;
61056 +
61057 + p = get_user_arg_ptr(argv, i);
61058 + if (IS_ERR(p))
61059 + goto log;
61060 +
61061 + len = strnlen_user(p, 128 - execlen);
61062 + if (len > 128 - execlen)
61063 + len = 128 - execlen;
61064 + else if (len > 0)
61065 + len--;
61066 + if (copy_from_user(grarg + execlen, p, len))
61067 + goto log;
61068 +
61069 + /* rewrite unprintable characters */
61070 + for (x = 0; x < len; x++) {
61071 + c = *(grarg + execlen + x);
61072 + if (c < 32 || c > 126)
61073 + *(grarg + execlen + x) = ' ';
61074 + }
61075 +
61076 + execlen += len;
61077 + *(grarg + execlen) = ' ';
61078 + *(grarg + execlen + 1) = '\0';
61079 + execlen++;
61080 + }
61081 +
61082 + log:
61083 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
61084 + bprm->file->f_path.mnt, grarg);
61085 + mutex_unlock(&gr_exec_arg_mutex);
61086 +#endif
61087 + return;
61088 +}
61089 +
61090 +#ifdef CONFIG_GRKERNSEC
61091 +extern int gr_acl_is_capable(const int cap);
61092 +extern int gr_acl_is_capable_nolog(const int cap);
61093 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61094 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
61095 +extern int gr_chroot_is_capable(const int cap);
61096 +extern int gr_chroot_is_capable_nolog(const int cap);
61097 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
61098 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
61099 +#endif
61100 +
61101 +const char *captab_log[] = {
61102 + "CAP_CHOWN",
61103 + "CAP_DAC_OVERRIDE",
61104 + "CAP_DAC_READ_SEARCH",
61105 + "CAP_FOWNER",
61106 + "CAP_FSETID",
61107 + "CAP_KILL",
61108 + "CAP_SETGID",
61109 + "CAP_SETUID",
61110 + "CAP_SETPCAP",
61111 + "CAP_LINUX_IMMUTABLE",
61112 + "CAP_NET_BIND_SERVICE",
61113 + "CAP_NET_BROADCAST",
61114 + "CAP_NET_ADMIN",
61115 + "CAP_NET_RAW",
61116 + "CAP_IPC_LOCK",
61117 + "CAP_IPC_OWNER",
61118 + "CAP_SYS_MODULE",
61119 + "CAP_SYS_RAWIO",
61120 + "CAP_SYS_CHROOT",
61121 + "CAP_SYS_PTRACE",
61122 + "CAP_SYS_PACCT",
61123 + "CAP_SYS_ADMIN",
61124 + "CAP_SYS_BOOT",
61125 + "CAP_SYS_NICE",
61126 + "CAP_SYS_RESOURCE",
61127 + "CAP_SYS_TIME",
61128 + "CAP_SYS_TTY_CONFIG",
61129 + "CAP_MKNOD",
61130 + "CAP_LEASE",
61131 + "CAP_AUDIT_WRITE",
61132 + "CAP_AUDIT_CONTROL",
61133 + "CAP_SETFCAP",
61134 + "CAP_MAC_OVERRIDE",
61135 + "CAP_MAC_ADMIN",
61136 + "CAP_SYSLOG",
61137 + "CAP_WAKE_ALARM"
61138 +};
61139 +
61140 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
61141 +
61142 +int gr_is_capable(const int cap)
61143 +{
61144 +#ifdef CONFIG_GRKERNSEC
61145 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
61146 + return 1;
61147 + return 0;
61148 +#else
61149 + return 1;
61150 +#endif
61151 +}
61152 +
61153 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
61154 +{
61155 +#ifdef CONFIG_GRKERNSEC
61156 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
61157 + return 1;
61158 + return 0;
61159 +#else
61160 + return 1;
61161 +#endif
61162 +}
61163 +
61164 +int gr_is_capable_nolog(const int cap)
61165 +{
61166 +#ifdef CONFIG_GRKERNSEC
61167 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
61168 + return 1;
61169 + return 0;
61170 +#else
61171 + return 1;
61172 +#endif
61173 +}
61174 +
61175 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
61176 +{
61177 +#ifdef CONFIG_GRKERNSEC
61178 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
61179 + return 1;
61180 + return 0;
61181 +#else
61182 + return 1;
61183 +#endif
61184 +}
61185 +
61186 +EXPORT_SYMBOL(gr_is_capable);
61187 +EXPORT_SYMBOL(gr_is_capable_nolog);
61188 +EXPORT_SYMBOL(gr_task_is_capable);
61189 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
61190 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
61191 new file mode 100644
61192 index 0000000..d3ee748
61193 --- /dev/null
61194 +++ b/grsecurity/grsec_fifo.c
61195 @@ -0,0 +1,24 @@
61196 +#include <linux/kernel.h>
61197 +#include <linux/sched.h>
61198 +#include <linux/fs.h>
61199 +#include <linux/file.h>
61200 +#include <linux/grinternal.h>
61201 +
61202 +int
61203 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
61204 + const struct dentry *dir, const int flag, const int acc_mode)
61205 +{
61206 +#ifdef CONFIG_GRKERNSEC_FIFO
61207 + const struct cred *cred = current_cred();
61208 +
61209 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
61210 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
61211 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
61212 + (cred->fsuid != dentry->d_inode->i_uid)) {
61213 + if (!inode_permission(dentry->d_inode, acc_mode))
61214 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
61215 + return -EACCES;
61216 + }
61217 +#endif
61218 + return 0;
61219 +}
61220 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
61221 new file mode 100644
61222 index 0000000..8ca18bf
61223 --- /dev/null
61224 +++ b/grsecurity/grsec_fork.c
61225 @@ -0,0 +1,23 @@
61226 +#include <linux/kernel.h>
61227 +#include <linux/sched.h>
61228 +#include <linux/grsecurity.h>
61229 +#include <linux/grinternal.h>
61230 +#include <linux/errno.h>
61231 +
61232 +void
61233 +gr_log_forkfail(const int retval)
61234 +{
61235 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61236 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
61237 + switch (retval) {
61238 + case -EAGAIN:
61239 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
61240 + break;
61241 + case -ENOMEM:
61242 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
61243 + break;
61244 + }
61245 + }
61246 +#endif
61247 + return;
61248 +}
61249 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
61250 new file mode 100644
61251 index 0000000..05a6015
61252 --- /dev/null
61253 +++ b/grsecurity/grsec_init.c
61254 @@ -0,0 +1,283 @@
61255 +#include <linux/kernel.h>
61256 +#include <linux/sched.h>
61257 +#include <linux/mm.h>
61258 +#include <linux/gracl.h>
61259 +#include <linux/slab.h>
61260 +#include <linux/vmalloc.h>
61261 +#include <linux/percpu.h>
61262 +#include <linux/module.h>
61263 +
61264 +int grsec_enable_ptrace_readexec;
61265 +int grsec_enable_setxid;
61266 +int grsec_enable_symlinkown;
61267 +int grsec_symlinkown_gid;
61268 +int grsec_enable_brute;
61269 +int grsec_enable_link;
61270 +int grsec_enable_dmesg;
61271 +int grsec_enable_harden_ptrace;
61272 +int grsec_enable_fifo;
61273 +int grsec_enable_execlog;
61274 +int grsec_enable_signal;
61275 +int grsec_enable_forkfail;
61276 +int grsec_enable_audit_ptrace;
61277 +int grsec_enable_time;
61278 +int grsec_enable_audit_textrel;
61279 +int grsec_enable_group;
61280 +int grsec_audit_gid;
61281 +int grsec_enable_chdir;
61282 +int grsec_enable_mount;
61283 +int grsec_enable_rofs;
61284 +int grsec_enable_chroot_findtask;
61285 +int grsec_enable_chroot_mount;
61286 +int grsec_enable_chroot_shmat;
61287 +int grsec_enable_chroot_fchdir;
61288 +int grsec_enable_chroot_double;
61289 +int grsec_enable_chroot_pivot;
61290 +int grsec_enable_chroot_chdir;
61291 +int grsec_enable_chroot_chmod;
61292 +int grsec_enable_chroot_mknod;
61293 +int grsec_enable_chroot_nice;
61294 +int grsec_enable_chroot_execlog;
61295 +int grsec_enable_chroot_caps;
61296 +int grsec_enable_chroot_sysctl;
61297 +int grsec_enable_chroot_unix;
61298 +int grsec_enable_tpe;
61299 +int grsec_tpe_gid;
61300 +int grsec_enable_blackhole;
61301 +#ifdef CONFIG_IPV6_MODULE
61302 +EXPORT_SYMBOL(grsec_enable_blackhole);
61303 +#endif
61304 +int grsec_lastack_retries;
61305 +int grsec_enable_tpe_all;
61306 +int grsec_enable_tpe_invert;
61307 +int grsec_enable_socket_all;
61308 +int grsec_socket_all_gid;
61309 +int grsec_enable_socket_client;
61310 +int grsec_socket_client_gid;
61311 +int grsec_enable_socket_server;
61312 +int grsec_socket_server_gid;
61313 +int grsec_resource_logging;
61314 +int grsec_disable_privio;
61315 +int grsec_enable_log_rwxmaps;
61316 +int grsec_lock;
61317 +
61318 +DEFINE_SPINLOCK(grsec_alert_lock);
61319 +unsigned long grsec_alert_wtime = 0;
61320 +unsigned long grsec_alert_fyet = 0;
61321 +
61322 +DEFINE_SPINLOCK(grsec_audit_lock);
61323 +
61324 +DEFINE_RWLOCK(grsec_exec_file_lock);
61325 +
61326 +char *gr_shared_page[4];
61327 +
61328 +char *gr_alert_log_fmt;
61329 +char *gr_audit_log_fmt;
61330 +char *gr_alert_log_buf;
61331 +char *gr_audit_log_buf;
61332 +
61333 +extern struct gr_arg *gr_usermode;
61334 +extern unsigned char *gr_system_salt;
61335 +extern unsigned char *gr_system_sum;
61336 +
61337 +void __init
61338 +grsecurity_init(void)
61339 +{
61340 + int j;
61341 + /* create the per-cpu shared pages */
61342 +
61343 +#ifdef CONFIG_X86
61344 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
61345 +#endif
61346 +
61347 + for (j = 0; j < 4; j++) {
61348 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
61349 + if (gr_shared_page[j] == NULL) {
61350 + panic("Unable to allocate grsecurity shared page");
61351 + return;
61352 + }
61353 + }
61354 +
61355 + /* allocate log buffers */
61356 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
61357 + if (!gr_alert_log_fmt) {
61358 + panic("Unable to allocate grsecurity alert log format buffer");
61359 + return;
61360 + }
61361 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
61362 + if (!gr_audit_log_fmt) {
61363 + panic("Unable to allocate grsecurity audit log format buffer");
61364 + return;
61365 + }
61366 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61367 + if (!gr_alert_log_buf) {
61368 + panic("Unable to allocate grsecurity alert log buffer");
61369 + return;
61370 + }
61371 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
61372 + if (!gr_audit_log_buf) {
61373 + panic("Unable to allocate grsecurity audit log buffer");
61374 + return;
61375 + }
61376 +
61377 + /* allocate memory for authentication structure */
61378 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
61379 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
61380 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
61381 +
61382 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
61383 + panic("Unable to allocate grsecurity authentication structure");
61384 + return;
61385 + }
61386 +
61387 +
61388 +#ifdef CONFIG_GRKERNSEC_IO
61389 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
61390 + grsec_disable_privio = 1;
61391 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61392 + grsec_disable_privio = 1;
61393 +#else
61394 + grsec_disable_privio = 0;
61395 +#endif
61396 +#endif
61397 +
61398 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61399 + /* for backward compatibility, tpe_invert always defaults to on if
61400 + enabled in the kernel
61401 + */
61402 + grsec_enable_tpe_invert = 1;
61403 +#endif
61404 +
61405 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
61406 +#ifndef CONFIG_GRKERNSEC_SYSCTL
61407 + grsec_lock = 1;
61408 +#endif
61409 +
61410 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61411 + grsec_enable_audit_textrel = 1;
61412 +#endif
61413 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61414 + grsec_enable_log_rwxmaps = 1;
61415 +#endif
61416 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61417 + grsec_enable_group = 1;
61418 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
61419 +#endif
61420 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61421 + grsec_enable_ptrace_readexec = 1;
61422 +#endif
61423 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61424 + grsec_enable_chdir = 1;
61425 +#endif
61426 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61427 + grsec_enable_harden_ptrace = 1;
61428 +#endif
61429 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61430 + grsec_enable_mount = 1;
61431 +#endif
61432 +#ifdef CONFIG_GRKERNSEC_LINK
61433 + grsec_enable_link = 1;
61434 +#endif
61435 +#ifdef CONFIG_GRKERNSEC_BRUTE
61436 + grsec_enable_brute = 1;
61437 +#endif
61438 +#ifdef CONFIG_GRKERNSEC_DMESG
61439 + grsec_enable_dmesg = 1;
61440 +#endif
61441 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61442 + grsec_enable_blackhole = 1;
61443 + grsec_lastack_retries = 4;
61444 +#endif
61445 +#ifdef CONFIG_GRKERNSEC_FIFO
61446 + grsec_enable_fifo = 1;
61447 +#endif
61448 +#ifdef CONFIG_GRKERNSEC_EXECLOG
61449 + grsec_enable_execlog = 1;
61450 +#endif
61451 +#ifdef CONFIG_GRKERNSEC_SETXID
61452 + grsec_enable_setxid = 1;
61453 +#endif
61454 +#ifdef CONFIG_GRKERNSEC_SIGNAL
61455 + grsec_enable_signal = 1;
61456 +#endif
61457 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
61458 + grsec_enable_forkfail = 1;
61459 +#endif
61460 +#ifdef CONFIG_GRKERNSEC_TIME
61461 + grsec_enable_time = 1;
61462 +#endif
61463 +#ifdef CONFIG_GRKERNSEC_RESLOG
61464 + grsec_resource_logging = 1;
61465 +#endif
61466 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61467 + grsec_enable_chroot_findtask = 1;
61468 +#endif
61469 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61470 + grsec_enable_chroot_unix = 1;
61471 +#endif
61472 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61473 + grsec_enable_chroot_mount = 1;
61474 +#endif
61475 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61476 + grsec_enable_chroot_fchdir = 1;
61477 +#endif
61478 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61479 + grsec_enable_chroot_shmat = 1;
61480 +#endif
61481 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61482 + grsec_enable_audit_ptrace = 1;
61483 +#endif
61484 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61485 + grsec_enable_chroot_double = 1;
61486 +#endif
61487 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61488 + grsec_enable_chroot_pivot = 1;
61489 +#endif
61490 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61491 + grsec_enable_chroot_chdir = 1;
61492 +#endif
61493 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61494 + grsec_enable_chroot_chmod = 1;
61495 +#endif
61496 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61497 + grsec_enable_chroot_mknod = 1;
61498 +#endif
61499 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61500 + grsec_enable_chroot_nice = 1;
61501 +#endif
61502 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61503 + grsec_enable_chroot_execlog = 1;
61504 +#endif
61505 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61506 + grsec_enable_chroot_caps = 1;
61507 +#endif
61508 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61509 + grsec_enable_chroot_sysctl = 1;
61510 +#endif
61511 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61512 + grsec_enable_symlinkown = 1;
61513 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
61514 +#endif
61515 +#ifdef CONFIG_GRKERNSEC_TPE
61516 + grsec_enable_tpe = 1;
61517 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
61518 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
61519 + grsec_enable_tpe_all = 1;
61520 +#endif
61521 +#endif
61522 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61523 + grsec_enable_socket_all = 1;
61524 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
61525 +#endif
61526 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61527 + grsec_enable_socket_client = 1;
61528 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
61529 +#endif
61530 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61531 + grsec_enable_socket_server = 1;
61532 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
61533 +#endif
61534 +#endif
61535 +
61536 + return;
61537 +}
61538 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
61539 new file mode 100644
61540 index 0000000..6095407
61541 --- /dev/null
61542 +++ b/grsecurity/grsec_link.c
61543 @@ -0,0 +1,58 @@
61544 +#include <linux/kernel.h>
61545 +#include <linux/sched.h>
61546 +#include <linux/fs.h>
61547 +#include <linux/file.h>
61548 +#include <linux/grinternal.h>
61549 +
61550 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
61551 +{
61552 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61553 + const struct inode *link_inode = link->dentry->d_inode;
61554 +
61555 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
61556 + /* ignore root-owned links, e.g. /proc/self */
61557 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
61558 + !uid_eq(link_inode->i_uid, target->i_uid)) {
61559 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
61560 + return 1;
61561 + }
61562 +#endif
61563 + return 0;
61564 +}
61565 +
61566 +int
61567 +gr_handle_follow_link(const struct inode *parent,
61568 + const struct inode *inode,
61569 + const struct dentry *dentry, const struct vfsmount *mnt)
61570 +{
61571 +#ifdef CONFIG_GRKERNSEC_LINK
61572 + const struct cred *cred = current_cred();
61573 +
61574 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
61575 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
61576 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
61577 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
61578 + return -EACCES;
61579 + }
61580 +#endif
61581 + return 0;
61582 +}
61583 +
61584 +int
61585 +gr_handle_hardlink(const struct dentry *dentry,
61586 + const struct vfsmount *mnt,
61587 + struct inode *inode, const int mode, const struct filename *to)
61588 +{
61589 +#ifdef CONFIG_GRKERNSEC_LINK
61590 + const struct cred *cred = current_cred();
61591 +
61592 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
61593 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
61594 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
61595 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61596 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
61597 + return -EPERM;
61598 + }
61599 +#endif
61600 + return 0;
61601 +}
61602 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
61603 new file mode 100644
61604 index 0000000..7bd6c2b
61605 --- /dev/null
61606 +++ b/grsecurity/grsec_log.c
61607 @@ -0,0 +1,329 @@
61608 +#include <linux/kernel.h>
61609 +#include <linux/sched.h>
61610 +#include <linux/file.h>
61611 +#include <linux/tty.h>
61612 +#include <linux/fs.h>
61613 +#include <linux/grinternal.h>
61614 +
61615 +#ifdef CONFIG_TREE_PREEMPT_RCU
61616 +#define DISABLE_PREEMPT() preempt_disable()
61617 +#define ENABLE_PREEMPT() preempt_enable()
61618 +#else
61619 +#define DISABLE_PREEMPT()
61620 +#define ENABLE_PREEMPT()
61621 +#endif
61622 +
61623 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
61624 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
61625 +
61626 +#define BEGIN_LOCKS(x) \
61627 + DISABLE_PREEMPT(); \
61628 + rcu_read_lock(); \
61629 + read_lock(&tasklist_lock); \
61630 + read_lock(&grsec_exec_file_lock); \
61631 + if (x != GR_DO_AUDIT) \
61632 + spin_lock(&grsec_alert_lock); \
61633 + else \
61634 + spin_lock(&grsec_audit_lock)
61635 +
61636 +#define END_LOCKS(x) \
61637 + if (x != GR_DO_AUDIT) \
61638 + spin_unlock(&grsec_alert_lock); \
61639 + else \
61640 + spin_unlock(&grsec_audit_lock); \
61641 + read_unlock(&grsec_exec_file_lock); \
61642 + read_unlock(&tasklist_lock); \
61643 + rcu_read_unlock(); \
61644 + ENABLE_PREEMPT(); \
61645 + if (x == GR_DONT_AUDIT) \
61646 + gr_handle_alertkill(current)
61647 +
61648 +enum {
61649 + FLOODING,
61650 + NO_FLOODING
61651 +};
61652 +
61653 +extern char *gr_alert_log_fmt;
61654 +extern char *gr_audit_log_fmt;
61655 +extern char *gr_alert_log_buf;
61656 +extern char *gr_audit_log_buf;
61657 +
61658 +static int gr_log_start(int audit)
61659 +{
61660 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
61661 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
61662 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61663 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
61664 + unsigned long curr_secs = get_seconds();
61665 +
61666 + if (audit == GR_DO_AUDIT)
61667 + goto set_fmt;
61668 +
61669 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
61670 + grsec_alert_wtime = curr_secs;
61671 + grsec_alert_fyet = 0;
61672 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
61673 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
61674 + grsec_alert_fyet++;
61675 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
61676 + grsec_alert_wtime = curr_secs;
61677 + grsec_alert_fyet++;
61678 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
61679 + return FLOODING;
61680 + }
61681 + else return FLOODING;
61682 +
61683 +set_fmt:
61684 +#endif
61685 + memset(buf, 0, PAGE_SIZE);
61686 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
61687 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
61688 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61689 + } else if (current->signal->curr_ip) {
61690 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
61691 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
61692 + } else if (gr_acl_is_enabled()) {
61693 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
61694 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
61695 + } else {
61696 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
61697 + strcpy(buf, fmt);
61698 + }
61699 +
61700 + return NO_FLOODING;
61701 +}
61702 +
61703 +static void gr_log_middle(int audit, const char *msg, va_list ap)
61704 + __attribute__ ((format (printf, 2, 0)));
61705 +
61706 +static void gr_log_middle(int audit, const char *msg, va_list ap)
61707 +{
61708 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61709 + unsigned int len = strlen(buf);
61710 +
61711 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61712 +
61713 + return;
61714 +}
61715 +
61716 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
61717 + __attribute__ ((format (printf, 2, 3)));
61718 +
61719 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
61720 +{
61721 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61722 + unsigned int len = strlen(buf);
61723 + va_list ap;
61724 +
61725 + va_start(ap, msg);
61726 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
61727 + va_end(ap);
61728 +
61729 + return;
61730 +}
61731 +
61732 +static void gr_log_end(int audit, int append_default)
61733 +{
61734 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
61735 + if (append_default) {
61736 + struct task_struct *task = current;
61737 + struct task_struct *parent = task->real_parent;
61738 + const struct cred *cred = __task_cred(task);
61739 + const struct cred *pcred = __task_cred(parent);
61740 + unsigned int len = strlen(buf);
61741 +
61742 + 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));
61743 + }
61744 +
61745 + printk("%s\n", buf);
61746 +
61747 + return;
61748 +}
61749 +
61750 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
61751 +{
61752 + int logtype;
61753 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
61754 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
61755 + void *voidptr = NULL;
61756 + int num1 = 0, num2 = 0;
61757 + unsigned long ulong1 = 0, ulong2 = 0;
61758 + struct dentry *dentry = NULL;
61759 + struct vfsmount *mnt = NULL;
61760 + struct file *file = NULL;
61761 + struct task_struct *task = NULL;
61762 + const struct cred *cred, *pcred;
61763 + va_list ap;
61764 +
61765 + BEGIN_LOCKS(audit);
61766 + logtype = gr_log_start(audit);
61767 + if (logtype == FLOODING) {
61768 + END_LOCKS(audit);
61769 + return;
61770 + }
61771 + va_start(ap, argtypes);
61772 + switch (argtypes) {
61773 + case GR_TTYSNIFF:
61774 + task = va_arg(ap, struct task_struct *);
61775 + 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));
61776 + break;
61777 + case GR_SYSCTL_HIDDEN:
61778 + str1 = va_arg(ap, char *);
61779 + gr_log_middle_varargs(audit, msg, result, str1);
61780 + break;
61781 + case GR_RBAC:
61782 + dentry = va_arg(ap, struct dentry *);
61783 + mnt = va_arg(ap, struct vfsmount *);
61784 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
61785 + break;
61786 + case GR_RBAC_STR:
61787 + dentry = va_arg(ap, struct dentry *);
61788 + mnt = va_arg(ap, struct vfsmount *);
61789 + str1 = va_arg(ap, char *);
61790 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
61791 + break;
61792 + case GR_STR_RBAC:
61793 + str1 = va_arg(ap, char *);
61794 + dentry = va_arg(ap, struct dentry *);
61795 + mnt = va_arg(ap, struct vfsmount *);
61796 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
61797 + break;
61798 + case GR_RBAC_MODE2:
61799 + dentry = va_arg(ap, struct dentry *);
61800 + mnt = va_arg(ap, struct vfsmount *);
61801 + str1 = va_arg(ap, char *);
61802 + str2 = va_arg(ap, char *);
61803 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
61804 + break;
61805 + case GR_RBAC_MODE3:
61806 + dentry = va_arg(ap, struct dentry *);
61807 + mnt = va_arg(ap, struct vfsmount *);
61808 + str1 = va_arg(ap, char *);
61809 + str2 = va_arg(ap, char *);
61810 + str3 = va_arg(ap, char *);
61811 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
61812 + break;
61813 + case GR_FILENAME:
61814 + dentry = va_arg(ap, struct dentry *);
61815 + mnt = va_arg(ap, struct vfsmount *);
61816 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
61817 + break;
61818 + case GR_STR_FILENAME:
61819 + str1 = va_arg(ap, char *);
61820 + dentry = va_arg(ap, struct dentry *);
61821 + mnt = va_arg(ap, struct vfsmount *);
61822 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
61823 + break;
61824 + case GR_FILENAME_STR:
61825 + dentry = va_arg(ap, struct dentry *);
61826 + mnt = va_arg(ap, struct vfsmount *);
61827 + str1 = va_arg(ap, char *);
61828 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
61829 + break;
61830 + case GR_FILENAME_TWO_INT:
61831 + dentry = va_arg(ap, struct dentry *);
61832 + mnt = va_arg(ap, struct vfsmount *);
61833 + num1 = va_arg(ap, int);
61834 + num2 = va_arg(ap, int);
61835 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
61836 + break;
61837 + case GR_FILENAME_TWO_INT_STR:
61838 + dentry = va_arg(ap, struct dentry *);
61839 + mnt = va_arg(ap, struct vfsmount *);
61840 + num1 = va_arg(ap, int);
61841 + num2 = va_arg(ap, int);
61842 + str1 = va_arg(ap, char *);
61843 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
61844 + break;
61845 + case GR_TEXTREL:
61846 + file = va_arg(ap, struct file *);
61847 + ulong1 = va_arg(ap, unsigned long);
61848 + ulong2 = va_arg(ap, unsigned long);
61849 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
61850 + break;
61851 + case GR_PTRACE:
61852 + task = va_arg(ap, struct task_struct *);
61853 + 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));
61854 + break;
61855 + case GR_RESOURCE:
61856 + task = va_arg(ap, struct task_struct *);
61857 + cred = __task_cred(task);
61858 + pcred = __task_cred(task->real_parent);
61859 + ulong1 = va_arg(ap, unsigned long);
61860 + str1 = va_arg(ap, char *);
61861 + ulong2 = va_arg(ap, unsigned long);
61862 + 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));
61863 + break;
61864 + case GR_CAP:
61865 + task = va_arg(ap, struct task_struct *);
61866 + cred = __task_cred(task);
61867 + pcred = __task_cred(task->real_parent);
61868 + str1 = va_arg(ap, char *);
61869 + 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));
61870 + break;
61871 + case GR_SIG:
61872 + str1 = va_arg(ap, char *);
61873 + voidptr = va_arg(ap, void *);
61874 + gr_log_middle_varargs(audit, msg, str1, voidptr);
61875 + break;
61876 + case GR_SIG2:
61877 + task = va_arg(ap, struct task_struct *);
61878 + cred = __task_cred(task);
61879 + pcred = __task_cred(task->real_parent);
61880 + num1 = va_arg(ap, int);
61881 + 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));
61882 + break;
61883 + case GR_CRASH1:
61884 + task = va_arg(ap, struct task_struct *);
61885 + cred = __task_cred(task);
61886 + pcred = __task_cred(task->real_parent);
61887 + ulong1 = va_arg(ap, unsigned long);
61888 + 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);
61889 + break;
61890 + case GR_CRASH2:
61891 + task = va_arg(ap, struct task_struct *);
61892 + cred = __task_cred(task);
61893 + pcred = __task_cred(task->real_parent);
61894 + ulong1 = va_arg(ap, unsigned long);
61895 + 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);
61896 + break;
61897 + case GR_RWXMAP:
61898 + file = va_arg(ap, struct file *);
61899 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
61900 + break;
61901 + case GR_PSACCT:
61902 + {
61903 + unsigned int wday, cday;
61904 + __u8 whr, chr;
61905 + __u8 wmin, cmin;
61906 + __u8 wsec, csec;
61907 + char cur_tty[64] = { 0 };
61908 + char parent_tty[64] = { 0 };
61909 +
61910 + task = va_arg(ap, struct task_struct *);
61911 + wday = va_arg(ap, unsigned int);
61912 + cday = va_arg(ap, unsigned int);
61913 + whr = va_arg(ap, int);
61914 + chr = va_arg(ap, int);
61915 + wmin = va_arg(ap, int);
61916 + cmin = va_arg(ap, int);
61917 + wsec = va_arg(ap, int);
61918 + csec = va_arg(ap, int);
61919 + ulong1 = va_arg(ap, unsigned long);
61920 + cred = __task_cred(task);
61921 + pcred = __task_cred(task->real_parent);
61922 +
61923 + 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));
61924 + }
61925 + break;
61926 + default:
61927 + gr_log_middle(audit, msg, ap);
61928 + }
61929 + va_end(ap);
61930 + // these don't need DEFAULTSECARGS printed on the end
61931 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
61932 + gr_log_end(audit, 0);
61933 + else
61934 + gr_log_end(audit, 1);
61935 + END_LOCKS(audit);
61936 +}
61937 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
61938 new file mode 100644
61939 index 0000000..f536303
61940 --- /dev/null
61941 +++ b/grsecurity/grsec_mem.c
61942 @@ -0,0 +1,40 @@
61943 +#include <linux/kernel.h>
61944 +#include <linux/sched.h>
61945 +#include <linux/mm.h>
61946 +#include <linux/mman.h>
61947 +#include <linux/grinternal.h>
61948 +
61949 +void
61950 +gr_handle_ioperm(void)
61951 +{
61952 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
61953 + return;
61954 +}
61955 +
61956 +void
61957 +gr_handle_iopl(void)
61958 +{
61959 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
61960 + return;
61961 +}
61962 +
61963 +void
61964 +gr_handle_mem_readwrite(u64 from, u64 to)
61965 +{
61966 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
61967 + return;
61968 +}
61969 +
61970 +void
61971 +gr_handle_vm86(void)
61972 +{
61973 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
61974 + return;
61975 +}
61976 +
61977 +void
61978 +gr_log_badprocpid(const char *entry)
61979 +{
61980 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
61981 + return;
61982 +}
61983 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
61984 new file mode 100644
61985 index 0000000..2131422
61986 --- /dev/null
61987 +++ b/grsecurity/grsec_mount.c
61988 @@ -0,0 +1,62 @@
61989 +#include <linux/kernel.h>
61990 +#include <linux/sched.h>
61991 +#include <linux/mount.h>
61992 +#include <linux/grsecurity.h>
61993 +#include <linux/grinternal.h>
61994 +
61995 +void
61996 +gr_log_remount(const char *devname, const int retval)
61997 +{
61998 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61999 + if (grsec_enable_mount && (retval >= 0))
62000 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
62001 +#endif
62002 + return;
62003 +}
62004 +
62005 +void
62006 +gr_log_unmount(const char *devname, const int retval)
62007 +{
62008 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62009 + if (grsec_enable_mount && (retval >= 0))
62010 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
62011 +#endif
62012 + return;
62013 +}
62014 +
62015 +void
62016 +gr_log_mount(const char *from, const char *to, const int retval)
62017 +{
62018 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62019 + if (grsec_enable_mount && (retval >= 0))
62020 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
62021 +#endif
62022 + return;
62023 +}
62024 +
62025 +int
62026 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
62027 +{
62028 +#ifdef CONFIG_GRKERNSEC_ROFS
62029 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
62030 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
62031 + return -EPERM;
62032 + } else
62033 + return 0;
62034 +#endif
62035 + return 0;
62036 +}
62037 +
62038 +int
62039 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
62040 +{
62041 +#ifdef CONFIG_GRKERNSEC_ROFS
62042 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
62043 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
62044 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
62045 + return -EPERM;
62046 + } else
62047 + return 0;
62048 +#endif
62049 + return 0;
62050 +}
62051 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
62052 new file mode 100644
62053 index 0000000..a3b12a0
62054 --- /dev/null
62055 +++ b/grsecurity/grsec_pax.c
62056 @@ -0,0 +1,36 @@
62057 +#include <linux/kernel.h>
62058 +#include <linux/sched.h>
62059 +#include <linux/mm.h>
62060 +#include <linux/file.h>
62061 +#include <linux/grinternal.h>
62062 +#include <linux/grsecurity.h>
62063 +
62064 +void
62065 +gr_log_textrel(struct vm_area_struct * vma)
62066 +{
62067 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
62068 + if (grsec_enable_audit_textrel)
62069 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
62070 +#endif
62071 + return;
62072 +}
62073 +
62074 +void
62075 +gr_log_rwxmmap(struct file *file)
62076 +{
62077 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62078 + if (grsec_enable_log_rwxmaps)
62079 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
62080 +#endif
62081 + return;
62082 +}
62083 +
62084 +void
62085 +gr_log_rwxmprotect(struct file *file)
62086 +{
62087 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62088 + if (grsec_enable_log_rwxmaps)
62089 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
62090 +#endif
62091 + return;
62092 +}
62093 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
62094 new file mode 100644
62095 index 0000000..f7f29aa
62096 --- /dev/null
62097 +++ b/grsecurity/grsec_ptrace.c
62098 @@ -0,0 +1,30 @@
62099 +#include <linux/kernel.h>
62100 +#include <linux/sched.h>
62101 +#include <linux/grinternal.h>
62102 +#include <linux/security.h>
62103 +
62104 +void
62105 +gr_audit_ptrace(struct task_struct *task)
62106 +{
62107 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
62108 + if (grsec_enable_audit_ptrace)
62109 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
62110 +#endif
62111 + return;
62112 +}
62113 +
62114 +int
62115 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
62116 +{
62117 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62118 + const struct dentry *dentry = file->f_path.dentry;
62119 + const struct vfsmount *mnt = file->f_path.mnt;
62120 +
62121 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
62122 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
62123 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
62124 + return -EACCES;
62125 + }
62126 +#endif
62127 + return 0;
62128 +}
62129 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
62130 new file mode 100644
62131 index 0000000..5c00416
62132 --- /dev/null
62133 +++ b/grsecurity/grsec_sig.c
62134 @@ -0,0 +1,222 @@
62135 +#include <linux/kernel.h>
62136 +#include <linux/sched.h>
62137 +#include <linux/delay.h>
62138 +#include <linux/grsecurity.h>
62139 +#include <linux/grinternal.h>
62140 +#include <linux/hardirq.h>
62141 +
62142 +char *signames[] = {
62143 + [SIGSEGV] = "Segmentation fault",
62144 + [SIGILL] = "Illegal instruction",
62145 + [SIGABRT] = "Abort",
62146 + [SIGBUS] = "Invalid alignment/Bus error"
62147 +};
62148 +
62149 +void
62150 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
62151 +{
62152 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62153 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
62154 + (sig == SIGABRT) || (sig == SIGBUS))) {
62155 + if (t->pid == current->pid) {
62156 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
62157 + } else {
62158 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
62159 + }
62160 + }
62161 +#endif
62162 + return;
62163 +}
62164 +
62165 +int
62166 +gr_handle_signal(const struct task_struct *p, const int sig)
62167 +{
62168 +#ifdef CONFIG_GRKERNSEC
62169 + /* ignore the 0 signal for protected task checks */
62170 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
62171 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
62172 + return -EPERM;
62173 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
62174 + return -EPERM;
62175 + }
62176 +#endif
62177 + return 0;
62178 +}
62179 +
62180 +#ifdef CONFIG_GRKERNSEC
62181 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
62182 +
62183 +int gr_fake_force_sig(int sig, struct task_struct *t)
62184 +{
62185 + unsigned long int flags;
62186 + int ret, blocked, ignored;
62187 + struct k_sigaction *action;
62188 +
62189 + spin_lock_irqsave(&t->sighand->siglock, flags);
62190 + action = &t->sighand->action[sig-1];
62191 + ignored = action->sa.sa_handler == SIG_IGN;
62192 + blocked = sigismember(&t->blocked, sig);
62193 + if (blocked || ignored) {
62194 + action->sa.sa_handler = SIG_DFL;
62195 + if (blocked) {
62196 + sigdelset(&t->blocked, sig);
62197 + recalc_sigpending_and_wake(t);
62198 + }
62199 + }
62200 + if (action->sa.sa_handler == SIG_DFL)
62201 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
62202 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
62203 +
62204 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
62205 +
62206 + return ret;
62207 +}
62208 +#endif
62209 +
62210 +#ifdef CONFIG_GRKERNSEC_BRUTE
62211 +#define GR_USER_BAN_TIME (15 * 60)
62212 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
62213 +
62214 +static int __get_dumpable(unsigned long mm_flags)
62215 +{
62216 + int ret;
62217 +
62218 + ret = mm_flags & MMF_DUMPABLE_MASK;
62219 + return (ret >= 2) ? 2 : ret;
62220 +}
62221 +#endif
62222 +
62223 +void gr_handle_brute_attach(unsigned long mm_flags)
62224 +{
62225 +#ifdef CONFIG_GRKERNSEC_BRUTE
62226 + struct task_struct *p = current;
62227 + kuid_t uid = GLOBAL_ROOT_UID;
62228 + int daemon = 0;
62229 +
62230 + if (!grsec_enable_brute)
62231 + return;
62232 +
62233 + rcu_read_lock();
62234 + read_lock(&tasklist_lock);
62235 + read_lock(&grsec_exec_file_lock);
62236 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
62237 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
62238 + p->real_parent->brute = 1;
62239 + daemon = 1;
62240 + } else {
62241 + const struct cred *cred = __task_cred(p), *cred2;
62242 + struct task_struct *tsk, *tsk2;
62243 +
62244 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
62245 + struct user_struct *user;
62246 +
62247 + uid = cred->uid;
62248 +
62249 + /* this is put upon execution past expiration */
62250 + user = find_user(uid);
62251 + if (user == NULL)
62252 + goto unlock;
62253 + user->banned = 1;
62254 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
62255 + if (user->ban_expires == ~0UL)
62256 + user->ban_expires--;
62257 +
62258 + do_each_thread(tsk2, tsk) {
62259 + cred2 = __task_cred(tsk);
62260 + if (tsk != p && uid_eq(cred2->uid, uid))
62261 + gr_fake_force_sig(SIGKILL, tsk);
62262 + } while_each_thread(tsk2, tsk);
62263 + }
62264 + }
62265 +unlock:
62266 + read_unlock(&grsec_exec_file_lock);
62267 + read_unlock(&tasklist_lock);
62268 + rcu_read_unlock();
62269 +
62270 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
62271 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
62272 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
62273 + else if (daemon)
62274 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
62275 +
62276 +#endif
62277 + return;
62278 +}
62279 +
62280 +void gr_handle_brute_check(void)
62281 +{
62282 +#ifdef CONFIG_GRKERNSEC_BRUTE
62283 + struct task_struct *p = current;
62284 +
62285 + if (unlikely(p->brute)) {
62286 + if (!grsec_enable_brute)
62287 + p->brute = 0;
62288 + else if (time_before(get_seconds(), p->brute_expires))
62289 + msleep(30 * 1000);
62290 + }
62291 +#endif
62292 + return;
62293 +}
62294 +
62295 +void gr_handle_kernel_exploit(void)
62296 +{
62297 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
62298 + const struct cred *cred;
62299 + struct task_struct *tsk, *tsk2;
62300 + struct user_struct *user;
62301 + kuid_t uid;
62302 +
62303 + if (in_irq() || in_serving_softirq() || in_nmi())
62304 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
62305 +
62306 + uid = current_uid();
62307 +
62308 + if (uid_eq(uid, GLOBAL_ROOT_UID))
62309 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
62310 + else {
62311 + /* kill all the processes of this user, hold a reference
62312 + to their creds struct, and prevent them from creating
62313 + another process until system reset
62314 + */
62315 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
62316 + from_kuid_munged(&init_user_ns, uid));
62317 + /* we intentionally leak this ref */
62318 + user = get_uid(current->cred->user);
62319 + if (user) {
62320 + user->banned = 1;
62321 + user->ban_expires = ~0UL;
62322 + }
62323 +
62324 + read_lock(&tasklist_lock);
62325 + do_each_thread(tsk2, tsk) {
62326 + cred = __task_cred(tsk);
62327 + if (uid_eq(cred->uid, uid))
62328 + gr_fake_force_sig(SIGKILL, tsk);
62329 + } while_each_thread(tsk2, tsk);
62330 + read_unlock(&tasklist_lock);
62331 + }
62332 +#endif
62333 +}
62334 +
62335 +int __gr_process_user_ban(struct user_struct *user)
62336 +{
62337 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62338 + if (unlikely(user->banned)) {
62339 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
62340 + user->banned = 0;
62341 + user->ban_expires = 0;
62342 + free_uid(user);
62343 + } else
62344 + return -EPERM;
62345 + }
62346 +#endif
62347 + return 0;
62348 +}
62349 +
62350 +int gr_process_user_ban(void)
62351 +{
62352 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
62353 + return __gr_process_user_ban(current->cred->user);
62354 +#endif
62355 + return 0;
62356 +}
62357 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
62358 new file mode 100644
62359 index 0000000..4030d57
62360 --- /dev/null
62361 +++ b/grsecurity/grsec_sock.c
62362 @@ -0,0 +1,244 @@
62363 +#include <linux/kernel.h>
62364 +#include <linux/module.h>
62365 +#include <linux/sched.h>
62366 +#include <linux/file.h>
62367 +#include <linux/net.h>
62368 +#include <linux/in.h>
62369 +#include <linux/ip.h>
62370 +#include <net/sock.h>
62371 +#include <net/inet_sock.h>
62372 +#include <linux/grsecurity.h>
62373 +#include <linux/grinternal.h>
62374 +#include <linux/gracl.h>
62375 +
62376 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
62377 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
62378 +
62379 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
62380 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
62381 +
62382 +#ifdef CONFIG_UNIX_MODULE
62383 +EXPORT_SYMBOL(gr_acl_handle_unix);
62384 +EXPORT_SYMBOL(gr_acl_handle_mknod);
62385 +EXPORT_SYMBOL(gr_handle_chroot_unix);
62386 +EXPORT_SYMBOL(gr_handle_create);
62387 +#endif
62388 +
62389 +#ifdef CONFIG_GRKERNSEC
62390 +#define gr_conn_table_size 32749
62391 +struct conn_table_entry {
62392 + struct conn_table_entry *next;
62393 + struct signal_struct *sig;
62394 +};
62395 +
62396 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
62397 +DEFINE_SPINLOCK(gr_conn_table_lock);
62398 +
62399 +extern const char * gr_socktype_to_name(unsigned char type);
62400 +extern const char * gr_proto_to_name(unsigned char proto);
62401 +extern const char * gr_sockfamily_to_name(unsigned char family);
62402 +
62403 +static __inline__ int
62404 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
62405 +{
62406 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
62407 +}
62408 +
62409 +static __inline__ int
62410 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
62411 + __u16 sport, __u16 dport)
62412 +{
62413 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
62414 + sig->gr_sport == sport && sig->gr_dport == dport))
62415 + return 1;
62416 + else
62417 + return 0;
62418 +}
62419 +
62420 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
62421 +{
62422 + struct conn_table_entry **match;
62423 + unsigned int index;
62424 +
62425 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62426 + sig->gr_sport, sig->gr_dport,
62427 + gr_conn_table_size);
62428 +
62429 + newent->sig = sig;
62430 +
62431 + match = &gr_conn_table[index];
62432 + newent->next = *match;
62433 + *match = newent;
62434 +
62435 + return;
62436 +}
62437 +
62438 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
62439 +{
62440 + struct conn_table_entry *match, *last = NULL;
62441 + unsigned int index;
62442 +
62443 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
62444 + sig->gr_sport, sig->gr_dport,
62445 + gr_conn_table_size);
62446 +
62447 + match = gr_conn_table[index];
62448 + while (match && !conn_match(match->sig,
62449 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
62450 + sig->gr_dport)) {
62451 + last = match;
62452 + match = match->next;
62453 + }
62454 +
62455 + if (match) {
62456 + if (last)
62457 + last->next = match->next;
62458 + else
62459 + gr_conn_table[index] = NULL;
62460 + kfree(match);
62461 + }
62462 +
62463 + return;
62464 +}
62465 +
62466 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
62467 + __u16 sport, __u16 dport)
62468 +{
62469 + struct conn_table_entry *match;
62470 + unsigned int index;
62471 +
62472 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
62473 +
62474 + match = gr_conn_table[index];
62475 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
62476 + match = match->next;
62477 +
62478 + if (match)
62479 + return match->sig;
62480 + else
62481 + return NULL;
62482 +}
62483 +
62484 +#endif
62485 +
62486 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
62487 +{
62488 +#ifdef CONFIG_GRKERNSEC
62489 + struct signal_struct *sig = task->signal;
62490 + struct conn_table_entry *newent;
62491 +
62492 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
62493 + if (newent == NULL)
62494 + return;
62495 + /* no bh lock needed since we are called with bh disabled */
62496 + spin_lock(&gr_conn_table_lock);
62497 + gr_del_task_from_ip_table_nolock(sig);
62498 + sig->gr_saddr = inet->inet_rcv_saddr;
62499 + sig->gr_daddr = inet->inet_daddr;
62500 + sig->gr_sport = inet->inet_sport;
62501 + sig->gr_dport = inet->inet_dport;
62502 + gr_add_to_task_ip_table_nolock(sig, newent);
62503 + spin_unlock(&gr_conn_table_lock);
62504 +#endif
62505 + return;
62506 +}
62507 +
62508 +void gr_del_task_from_ip_table(struct task_struct *task)
62509 +{
62510 +#ifdef CONFIG_GRKERNSEC
62511 + spin_lock_bh(&gr_conn_table_lock);
62512 + gr_del_task_from_ip_table_nolock(task->signal);
62513 + spin_unlock_bh(&gr_conn_table_lock);
62514 +#endif
62515 + return;
62516 +}
62517 +
62518 +void
62519 +gr_attach_curr_ip(const struct sock *sk)
62520 +{
62521 +#ifdef CONFIG_GRKERNSEC
62522 + struct signal_struct *p, *set;
62523 + const struct inet_sock *inet = inet_sk(sk);
62524 +
62525 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
62526 + return;
62527 +
62528 + set = current->signal;
62529 +
62530 + spin_lock_bh(&gr_conn_table_lock);
62531 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
62532 + inet->inet_dport, inet->inet_sport);
62533 + if (unlikely(p != NULL)) {
62534 + set->curr_ip = p->curr_ip;
62535 + set->used_accept = 1;
62536 + gr_del_task_from_ip_table_nolock(p);
62537 + spin_unlock_bh(&gr_conn_table_lock);
62538 + return;
62539 + }
62540 + spin_unlock_bh(&gr_conn_table_lock);
62541 +
62542 + set->curr_ip = inet->inet_daddr;
62543 + set->used_accept = 1;
62544 +#endif
62545 + return;
62546 +}
62547 +
62548 +int
62549 +gr_handle_sock_all(const int family, const int type, const int protocol)
62550 +{
62551 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62552 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
62553 + (family != AF_UNIX)) {
62554 + if (family == AF_INET)
62555 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
62556 + else
62557 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
62558 + return -EACCES;
62559 + }
62560 +#endif
62561 + return 0;
62562 +}
62563 +
62564 +int
62565 +gr_handle_sock_server(const struct sockaddr *sck)
62566 +{
62567 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62568 + if (grsec_enable_socket_server &&
62569 + in_group_p(grsec_socket_server_gid) &&
62570 + sck && (sck->sa_family != AF_UNIX) &&
62571 + (sck->sa_family != AF_LOCAL)) {
62572 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62573 + return -EACCES;
62574 + }
62575 +#endif
62576 + return 0;
62577 +}
62578 +
62579 +int
62580 +gr_handle_sock_server_other(const struct sock *sck)
62581 +{
62582 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62583 + if (grsec_enable_socket_server &&
62584 + in_group_p(grsec_socket_server_gid) &&
62585 + sck && (sck->sk_family != AF_UNIX) &&
62586 + (sck->sk_family != AF_LOCAL)) {
62587 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
62588 + return -EACCES;
62589 + }
62590 +#endif
62591 + return 0;
62592 +}
62593 +
62594 +int
62595 +gr_handle_sock_client(const struct sockaddr *sck)
62596 +{
62597 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62598 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
62599 + sck && (sck->sa_family != AF_UNIX) &&
62600 + (sck->sa_family != AF_LOCAL)) {
62601 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
62602 + return -EACCES;
62603 + }
62604 +#endif
62605 + return 0;
62606 +}
62607 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
62608 new file mode 100644
62609 index 0000000..f55ef0f
62610 --- /dev/null
62611 +++ b/grsecurity/grsec_sysctl.c
62612 @@ -0,0 +1,469 @@
62613 +#include <linux/kernel.h>
62614 +#include <linux/sched.h>
62615 +#include <linux/sysctl.h>
62616 +#include <linux/grsecurity.h>
62617 +#include <linux/grinternal.h>
62618 +
62619 +int
62620 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
62621 +{
62622 +#ifdef CONFIG_GRKERNSEC_SYSCTL
62623 + if (dirname == NULL || name == NULL)
62624 + return 0;
62625 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
62626 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
62627 + return -EACCES;
62628 + }
62629 +#endif
62630 + return 0;
62631 +}
62632 +
62633 +#ifdef CONFIG_GRKERNSEC_ROFS
62634 +static int __maybe_unused one = 1;
62635 +#endif
62636 +
62637 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
62638 +struct ctl_table grsecurity_table[] = {
62639 +#ifdef CONFIG_GRKERNSEC_SYSCTL
62640 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
62641 +#ifdef CONFIG_GRKERNSEC_IO
62642 + {
62643 + .procname = "disable_priv_io",
62644 + .data = &grsec_disable_privio,
62645 + .maxlen = sizeof(int),
62646 + .mode = 0600,
62647 + .proc_handler = &proc_dointvec,
62648 + },
62649 +#endif
62650 +#endif
62651 +#ifdef CONFIG_GRKERNSEC_LINK
62652 + {
62653 + .procname = "linking_restrictions",
62654 + .data = &grsec_enable_link,
62655 + .maxlen = sizeof(int),
62656 + .mode = 0600,
62657 + .proc_handler = &proc_dointvec,
62658 + },
62659 +#endif
62660 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
62661 + {
62662 + .procname = "enforce_symlinksifowner",
62663 + .data = &grsec_enable_symlinkown,
62664 + .maxlen = sizeof(int),
62665 + .mode = 0600,
62666 + .proc_handler = &proc_dointvec,
62667 + },
62668 + {
62669 + .procname = "symlinkown_gid",
62670 + .data = &grsec_symlinkown_gid,
62671 + .maxlen = sizeof(int),
62672 + .mode = 0600,
62673 + .proc_handler = &proc_dointvec,
62674 + },
62675 +#endif
62676 +#ifdef CONFIG_GRKERNSEC_BRUTE
62677 + {
62678 + .procname = "deter_bruteforce",
62679 + .data = &grsec_enable_brute,
62680 + .maxlen = sizeof(int),
62681 + .mode = 0600,
62682 + .proc_handler = &proc_dointvec,
62683 + },
62684 +#endif
62685 +#ifdef CONFIG_GRKERNSEC_FIFO
62686 + {
62687 + .procname = "fifo_restrictions",
62688 + .data = &grsec_enable_fifo,
62689 + .maxlen = sizeof(int),
62690 + .mode = 0600,
62691 + .proc_handler = &proc_dointvec,
62692 + },
62693 +#endif
62694 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
62695 + {
62696 + .procname = "ptrace_readexec",
62697 + .data = &grsec_enable_ptrace_readexec,
62698 + .maxlen = sizeof(int),
62699 + .mode = 0600,
62700 + .proc_handler = &proc_dointvec,
62701 + },
62702 +#endif
62703 +#ifdef CONFIG_GRKERNSEC_SETXID
62704 + {
62705 + .procname = "consistent_setxid",
62706 + .data = &grsec_enable_setxid,
62707 + .maxlen = sizeof(int),
62708 + .mode = 0600,
62709 + .proc_handler = &proc_dointvec,
62710 + },
62711 +#endif
62712 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
62713 + {
62714 + .procname = "ip_blackhole",
62715 + .data = &grsec_enable_blackhole,
62716 + .maxlen = sizeof(int),
62717 + .mode = 0600,
62718 + .proc_handler = &proc_dointvec,
62719 + },
62720 + {
62721 + .procname = "lastack_retries",
62722 + .data = &grsec_lastack_retries,
62723 + .maxlen = sizeof(int),
62724 + .mode = 0600,
62725 + .proc_handler = &proc_dointvec,
62726 + },
62727 +#endif
62728 +#ifdef CONFIG_GRKERNSEC_EXECLOG
62729 + {
62730 + .procname = "exec_logging",
62731 + .data = &grsec_enable_execlog,
62732 + .maxlen = sizeof(int),
62733 + .mode = 0600,
62734 + .proc_handler = &proc_dointvec,
62735 + },
62736 +#endif
62737 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
62738 + {
62739 + .procname = "rwxmap_logging",
62740 + .data = &grsec_enable_log_rwxmaps,
62741 + .maxlen = sizeof(int),
62742 + .mode = 0600,
62743 + .proc_handler = &proc_dointvec,
62744 + },
62745 +#endif
62746 +#ifdef CONFIG_GRKERNSEC_SIGNAL
62747 + {
62748 + .procname = "signal_logging",
62749 + .data = &grsec_enable_signal,
62750 + .maxlen = sizeof(int),
62751 + .mode = 0600,
62752 + .proc_handler = &proc_dointvec,
62753 + },
62754 +#endif
62755 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
62756 + {
62757 + .procname = "forkfail_logging",
62758 + .data = &grsec_enable_forkfail,
62759 + .maxlen = sizeof(int),
62760 + .mode = 0600,
62761 + .proc_handler = &proc_dointvec,
62762 + },
62763 +#endif
62764 +#ifdef CONFIG_GRKERNSEC_TIME
62765 + {
62766 + .procname = "timechange_logging",
62767 + .data = &grsec_enable_time,
62768 + .maxlen = sizeof(int),
62769 + .mode = 0600,
62770 + .proc_handler = &proc_dointvec,
62771 + },
62772 +#endif
62773 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62774 + {
62775 + .procname = "chroot_deny_shmat",
62776 + .data = &grsec_enable_chroot_shmat,
62777 + .maxlen = sizeof(int),
62778 + .mode = 0600,
62779 + .proc_handler = &proc_dointvec,
62780 + },
62781 +#endif
62782 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62783 + {
62784 + .procname = "chroot_deny_unix",
62785 + .data = &grsec_enable_chroot_unix,
62786 + .maxlen = sizeof(int),
62787 + .mode = 0600,
62788 + .proc_handler = &proc_dointvec,
62789 + },
62790 +#endif
62791 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62792 + {
62793 + .procname = "chroot_deny_mount",
62794 + .data = &grsec_enable_chroot_mount,
62795 + .maxlen = sizeof(int),
62796 + .mode = 0600,
62797 + .proc_handler = &proc_dointvec,
62798 + },
62799 +#endif
62800 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62801 + {
62802 + .procname = "chroot_deny_fchdir",
62803 + .data = &grsec_enable_chroot_fchdir,
62804 + .maxlen = sizeof(int),
62805 + .mode = 0600,
62806 + .proc_handler = &proc_dointvec,
62807 + },
62808 +#endif
62809 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62810 + {
62811 + .procname = "chroot_deny_chroot",
62812 + .data = &grsec_enable_chroot_double,
62813 + .maxlen = sizeof(int),
62814 + .mode = 0600,
62815 + .proc_handler = &proc_dointvec,
62816 + },
62817 +#endif
62818 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62819 + {
62820 + .procname = "chroot_deny_pivot",
62821 + .data = &grsec_enable_chroot_pivot,
62822 + .maxlen = sizeof(int),
62823 + .mode = 0600,
62824 + .proc_handler = &proc_dointvec,
62825 + },
62826 +#endif
62827 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62828 + {
62829 + .procname = "chroot_enforce_chdir",
62830 + .data = &grsec_enable_chroot_chdir,
62831 + .maxlen = sizeof(int),
62832 + .mode = 0600,
62833 + .proc_handler = &proc_dointvec,
62834 + },
62835 +#endif
62836 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62837 + {
62838 + .procname = "chroot_deny_chmod",
62839 + .data = &grsec_enable_chroot_chmod,
62840 + .maxlen = sizeof(int),
62841 + .mode = 0600,
62842 + .proc_handler = &proc_dointvec,
62843 + },
62844 +#endif
62845 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62846 + {
62847 + .procname = "chroot_deny_mknod",
62848 + .data = &grsec_enable_chroot_mknod,
62849 + .maxlen = sizeof(int),
62850 + .mode = 0600,
62851 + .proc_handler = &proc_dointvec,
62852 + },
62853 +#endif
62854 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62855 + {
62856 + .procname = "chroot_restrict_nice",
62857 + .data = &grsec_enable_chroot_nice,
62858 + .maxlen = sizeof(int),
62859 + .mode = 0600,
62860 + .proc_handler = &proc_dointvec,
62861 + },
62862 +#endif
62863 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62864 + {
62865 + .procname = "chroot_execlog",
62866 + .data = &grsec_enable_chroot_execlog,
62867 + .maxlen = sizeof(int),
62868 + .mode = 0600,
62869 + .proc_handler = &proc_dointvec,
62870 + },
62871 +#endif
62872 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62873 + {
62874 + .procname = "chroot_caps",
62875 + .data = &grsec_enable_chroot_caps,
62876 + .maxlen = sizeof(int),
62877 + .mode = 0600,
62878 + .proc_handler = &proc_dointvec,
62879 + },
62880 +#endif
62881 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62882 + {
62883 + .procname = "chroot_deny_sysctl",
62884 + .data = &grsec_enable_chroot_sysctl,
62885 + .maxlen = sizeof(int),
62886 + .mode = 0600,
62887 + .proc_handler = &proc_dointvec,
62888 + },
62889 +#endif
62890 +#ifdef CONFIG_GRKERNSEC_TPE
62891 + {
62892 + .procname = "tpe",
62893 + .data = &grsec_enable_tpe,
62894 + .maxlen = sizeof(int),
62895 + .mode = 0600,
62896 + .proc_handler = &proc_dointvec,
62897 + },
62898 + {
62899 + .procname = "tpe_gid",
62900 + .data = &grsec_tpe_gid,
62901 + .maxlen = sizeof(int),
62902 + .mode = 0600,
62903 + .proc_handler = &proc_dointvec,
62904 + },
62905 +#endif
62906 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
62907 + {
62908 + .procname = "tpe_invert",
62909 + .data = &grsec_enable_tpe_invert,
62910 + .maxlen = sizeof(int),
62911 + .mode = 0600,
62912 + .proc_handler = &proc_dointvec,
62913 + },
62914 +#endif
62915 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
62916 + {
62917 + .procname = "tpe_restrict_all",
62918 + .data = &grsec_enable_tpe_all,
62919 + .maxlen = sizeof(int),
62920 + .mode = 0600,
62921 + .proc_handler = &proc_dointvec,
62922 + },
62923 +#endif
62924 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
62925 + {
62926 + .procname = "socket_all",
62927 + .data = &grsec_enable_socket_all,
62928 + .maxlen = sizeof(int),
62929 + .mode = 0600,
62930 + .proc_handler = &proc_dointvec,
62931 + },
62932 + {
62933 + .procname = "socket_all_gid",
62934 + .data = &grsec_socket_all_gid,
62935 + .maxlen = sizeof(int),
62936 + .mode = 0600,
62937 + .proc_handler = &proc_dointvec,
62938 + },
62939 +#endif
62940 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
62941 + {
62942 + .procname = "socket_client",
62943 + .data = &grsec_enable_socket_client,
62944 + .maxlen = sizeof(int),
62945 + .mode = 0600,
62946 + .proc_handler = &proc_dointvec,
62947 + },
62948 + {
62949 + .procname = "socket_client_gid",
62950 + .data = &grsec_socket_client_gid,
62951 + .maxlen = sizeof(int),
62952 + .mode = 0600,
62953 + .proc_handler = &proc_dointvec,
62954 + },
62955 +#endif
62956 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
62957 + {
62958 + .procname = "socket_server",
62959 + .data = &grsec_enable_socket_server,
62960 + .maxlen = sizeof(int),
62961 + .mode = 0600,
62962 + .proc_handler = &proc_dointvec,
62963 + },
62964 + {
62965 + .procname = "socket_server_gid",
62966 + .data = &grsec_socket_server_gid,
62967 + .maxlen = sizeof(int),
62968 + .mode = 0600,
62969 + .proc_handler = &proc_dointvec,
62970 + },
62971 +#endif
62972 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
62973 + {
62974 + .procname = "audit_group",
62975 + .data = &grsec_enable_group,
62976 + .maxlen = sizeof(int),
62977 + .mode = 0600,
62978 + .proc_handler = &proc_dointvec,
62979 + },
62980 + {
62981 + .procname = "audit_gid",
62982 + .data = &grsec_audit_gid,
62983 + .maxlen = sizeof(int),
62984 + .mode = 0600,
62985 + .proc_handler = &proc_dointvec,
62986 + },
62987 +#endif
62988 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62989 + {
62990 + .procname = "audit_chdir",
62991 + .data = &grsec_enable_chdir,
62992 + .maxlen = sizeof(int),
62993 + .mode = 0600,
62994 + .proc_handler = &proc_dointvec,
62995 + },
62996 +#endif
62997 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
62998 + {
62999 + .procname = "audit_mount",
63000 + .data = &grsec_enable_mount,
63001 + .maxlen = sizeof(int),
63002 + .mode = 0600,
63003 + .proc_handler = &proc_dointvec,
63004 + },
63005 +#endif
63006 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63007 + {
63008 + .procname = "audit_textrel",
63009 + .data = &grsec_enable_audit_textrel,
63010 + .maxlen = sizeof(int),
63011 + .mode = 0600,
63012 + .proc_handler = &proc_dointvec,
63013 + },
63014 +#endif
63015 +#ifdef CONFIG_GRKERNSEC_DMESG
63016 + {
63017 + .procname = "dmesg",
63018 + .data = &grsec_enable_dmesg,
63019 + .maxlen = sizeof(int),
63020 + .mode = 0600,
63021 + .proc_handler = &proc_dointvec,
63022 + },
63023 +#endif
63024 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63025 + {
63026 + .procname = "chroot_findtask",
63027 + .data = &grsec_enable_chroot_findtask,
63028 + .maxlen = sizeof(int),
63029 + .mode = 0600,
63030 + .proc_handler = &proc_dointvec,
63031 + },
63032 +#endif
63033 +#ifdef CONFIG_GRKERNSEC_RESLOG
63034 + {
63035 + .procname = "resource_logging",
63036 + .data = &grsec_resource_logging,
63037 + .maxlen = sizeof(int),
63038 + .mode = 0600,
63039 + .proc_handler = &proc_dointvec,
63040 + },
63041 +#endif
63042 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63043 + {
63044 + .procname = "audit_ptrace",
63045 + .data = &grsec_enable_audit_ptrace,
63046 + .maxlen = sizeof(int),
63047 + .mode = 0600,
63048 + .proc_handler = &proc_dointvec,
63049 + },
63050 +#endif
63051 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63052 + {
63053 + .procname = "harden_ptrace",
63054 + .data = &grsec_enable_harden_ptrace,
63055 + .maxlen = sizeof(int),
63056 + .mode = 0600,
63057 + .proc_handler = &proc_dointvec,
63058 + },
63059 +#endif
63060 + {
63061 + .procname = "grsec_lock",
63062 + .data = &grsec_lock,
63063 + .maxlen = sizeof(int),
63064 + .mode = 0600,
63065 + .proc_handler = &proc_dointvec,
63066 + },
63067 +#endif
63068 +#ifdef CONFIG_GRKERNSEC_ROFS
63069 + {
63070 + .procname = "romount_protect",
63071 + .data = &grsec_enable_rofs,
63072 + .maxlen = sizeof(int),
63073 + .mode = 0600,
63074 + .proc_handler = &proc_dointvec_minmax,
63075 + .extra1 = &one,
63076 + .extra2 = &one,
63077 + },
63078 +#endif
63079 + { }
63080 +};
63081 +#endif
63082 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
63083 new file mode 100644
63084 index 0000000..0dc13c3
63085 --- /dev/null
63086 +++ b/grsecurity/grsec_time.c
63087 @@ -0,0 +1,16 @@
63088 +#include <linux/kernel.h>
63089 +#include <linux/sched.h>
63090 +#include <linux/grinternal.h>
63091 +#include <linux/module.h>
63092 +
63093 +void
63094 +gr_log_timechange(void)
63095 +{
63096 +#ifdef CONFIG_GRKERNSEC_TIME
63097 + if (grsec_enable_time)
63098 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
63099 +#endif
63100 + return;
63101 +}
63102 +
63103 +EXPORT_SYMBOL(gr_log_timechange);
63104 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
63105 new file mode 100644
63106 index 0000000..07e0dc0
63107 --- /dev/null
63108 +++ b/grsecurity/grsec_tpe.c
63109 @@ -0,0 +1,73 @@
63110 +#include <linux/kernel.h>
63111 +#include <linux/sched.h>
63112 +#include <linux/file.h>
63113 +#include <linux/fs.h>
63114 +#include <linux/grinternal.h>
63115 +
63116 +extern int gr_acl_tpe_check(void);
63117 +
63118 +int
63119 +gr_tpe_allow(const struct file *file)
63120 +{
63121 +#ifdef CONFIG_GRKERNSEC
63122 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
63123 + const struct cred *cred = current_cred();
63124 + char *msg = NULL;
63125 + char *msg2 = NULL;
63126 +
63127 + // never restrict root
63128 + if (!cred->uid)
63129 + return 1;
63130 +
63131 + if (grsec_enable_tpe) {
63132 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63133 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
63134 + msg = "not being in trusted group";
63135 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
63136 + msg = "being in untrusted group";
63137 +#else
63138 + if (in_group_p(grsec_tpe_gid))
63139 + msg = "being in untrusted group";
63140 +#endif
63141 + }
63142 + if (!msg && gr_acl_tpe_check())
63143 + msg = "being in untrusted role";
63144 +
63145 + // not in any affected group/role
63146 + if (!msg)
63147 + goto next_check;
63148 +
63149 + if (inode->i_uid)
63150 + msg2 = "file in non-root-owned directory";
63151 + else if (inode->i_mode & S_IWOTH)
63152 + msg2 = "file in world-writable directory";
63153 + else if (inode->i_mode & S_IWGRP)
63154 + msg2 = "file in group-writable directory";
63155 +
63156 + if (msg && msg2) {
63157 + char fullmsg[70] = {0};
63158 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
63159 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
63160 + return 0;
63161 + }
63162 + msg = NULL;
63163 +next_check:
63164 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63165 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
63166 + return 1;
63167 +
63168 + if (inode->i_uid && (inode->i_uid != cred->uid))
63169 + msg = "directory not owned by user";
63170 + else if (inode->i_mode & S_IWOTH)
63171 + msg = "file in world-writable directory";
63172 + else if (inode->i_mode & S_IWGRP)
63173 + msg = "file in group-writable directory";
63174 +
63175 + if (msg) {
63176 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
63177 + return 0;
63178 + }
63179 +#endif
63180 +#endif
63181 + return 1;
63182 +}
63183 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
63184 new file mode 100644
63185 index 0000000..9f7b1ac
63186 --- /dev/null
63187 +++ b/grsecurity/grsum.c
63188 @@ -0,0 +1,61 @@
63189 +#include <linux/err.h>
63190 +#include <linux/kernel.h>
63191 +#include <linux/sched.h>
63192 +#include <linux/mm.h>
63193 +#include <linux/scatterlist.h>
63194 +#include <linux/crypto.h>
63195 +#include <linux/gracl.h>
63196 +
63197 +
63198 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
63199 +#error "crypto and sha256 must be built into the kernel"
63200 +#endif
63201 +
63202 +int
63203 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
63204 +{
63205 + char *p;
63206 + struct crypto_hash *tfm;
63207 + struct hash_desc desc;
63208 + struct scatterlist sg;
63209 + unsigned char temp_sum[GR_SHA_LEN];
63210 + volatile int retval = 0;
63211 + volatile int dummy = 0;
63212 + unsigned int i;
63213 +
63214 + sg_init_table(&sg, 1);
63215 +
63216 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
63217 + if (IS_ERR(tfm)) {
63218 + /* should never happen, since sha256 should be built in */
63219 + return 1;
63220 + }
63221 +
63222 + desc.tfm = tfm;
63223 + desc.flags = 0;
63224 +
63225 + crypto_hash_init(&desc);
63226 +
63227 + p = salt;
63228 + sg_set_buf(&sg, p, GR_SALT_LEN);
63229 + crypto_hash_update(&desc, &sg, sg.length);
63230 +
63231 + p = entry->pw;
63232 + sg_set_buf(&sg, p, strlen(p));
63233 +
63234 + crypto_hash_update(&desc, &sg, sg.length);
63235 +
63236 + crypto_hash_final(&desc, temp_sum);
63237 +
63238 + memset(entry->pw, 0, GR_PW_LEN);
63239 +
63240 + for (i = 0; i < GR_SHA_LEN; i++)
63241 + if (sum[i] != temp_sum[i])
63242 + retval = 1;
63243 + else
63244 + dummy = 1; // waste a cycle
63245 +
63246 + crypto_free_hash(tfm);
63247 +
63248 + return retval;
63249 +}
63250 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
63251 index 77ff547..181834f 100644
63252 --- a/include/asm-generic/4level-fixup.h
63253 +++ b/include/asm-generic/4level-fixup.h
63254 @@ -13,8 +13,10 @@
63255 #define pmd_alloc(mm, pud, address) \
63256 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
63257 NULL: pmd_offset(pud, address))
63258 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
63259
63260 #define pud_alloc(mm, pgd, address) (pgd)
63261 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
63262 #define pud_offset(pgd, start) (pgd)
63263 #define pud_none(pud) 0
63264 #define pud_bad(pud) 0
63265 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
63266 index b7babf0..04ad282 100644
63267 --- a/include/asm-generic/atomic-long.h
63268 +++ b/include/asm-generic/atomic-long.h
63269 @@ -22,6 +22,12 @@
63270
63271 typedef atomic64_t atomic_long_t;
63272
63273 +#ifdef CONFIG_PAX_REFCOUNT
63274 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
63275 +#else
63276 +typedef atomic64_t atomic_long_unchecked_t;
63277 +#endif
63278 +
63279 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
63280
63281 static inline long atomic_long_read(atomic_long_t *l)
63282 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63283 return (long)atomic64_read(v);
63284 }
63285
63286 +#ifdef CONFIG_PAX_REFCOUNT
63287 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63288 +{
63289 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63290 +
63291 + return (long)atomic64_read_unchecked(v);
63292 +}
63293 +#endif
63294 +
63295 static inline void atomic_long_set(atomic_long_t *l, long i)
63296 {
63297 atomic64_t *v = (atomic64_t *)l;
63298 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63299 atomic64_set(v, i);
63300 }
63301
63302 +#ifdef CONFIG_PAX_REFCOUNT
63303 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63304 +{
63305 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63306 +
63307 + atomic64_set_unchecked(v, i);
63308 +}
63309 +#endif
63310 +
63311 static inline void atomic_long_inc(atomic_long_t *l)
63312 {
63313 atomic64_t *v = (atomic64_t *)l;
63314 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63315 atomic64_inc(v);
63316 }
63317
63318 +#ifdef CONFIG_PAX_REFCOUNT
63319 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63320 +{
63321 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63322 +
63323 + atomic64_inc_unchecked(v);
63324 +}
63325 +#endif
63326 +
63327 static inline void atomic_long_dec(atomic_long_t *l)
63328 {
63329 atomic64_t *v = (atomic64_t *)l;
63330 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63331 atomic64_dec(v);
63332 }
63333
63334 +#ifdef CONFIG_PAX_REFCOUNT
63335 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63336 +{
63337 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63338 +
63339 + atomic64_dec_unchecked(v);
63340 +}
63341 +#endif
63342 +
63343 static inline void atomic_long_add(long i, atomic_long_t *l)
63344 {
63345 atomic64_t *v = (atomic64_t *)l;
63346 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63347 atomic64_add(i, v);
63348 }
63349
63350 +#ifdef CONFIG_PAX_REFCOUNT
63351 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63352 +{
63353 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63354 +
63355 + atomic64_add_unchecked(i, v);
63356 +}
63357 +#endif
63358 +
63359 static inline void atomic_long_sub(long i, atomic_long_t *l)
63360 {
63361 atomic64_t *v = (atomic64_t *)l;
63362 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63363 atomic64_sub(i, v);
63364 }
63365
63366 +#ifdef CONFIG_PAX_REFCOUNT
63367 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63368 +{
63369 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63370 +
63371 + atomic64_sub_unchecked(i, v);
63372 +}
63373 +#endif
63374 +
63375 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63376 {
63377 atomic64_t *v = (atomic64_t *)l;
63378 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63379 return (long)atomic64_add_return(i, v);
63380 }
63381
63382 +#ifdef CONFIG_PAX_REFCOUNT
63383 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63384 +{
63385 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63386 +
63387 + return (long)atomic64_add_return_unchecked(i, v);
63388 +}
63389 +#endif
63390 +
63391 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63392 {
63393 atomic64_t *v = (atomic64_t *)l;
63394 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63395 return (long)atomic64_inc_return(v);
63396 }
63397
63398 +#ifdef CONFIG_PAX_REFCOUNT
63399 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63400 +{
63401 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
63402 +
63403 + return (long)atomic64_inc_return_unchecked(v);
63404 +}
63405 +#endif
63406 +
63407 static inline long atomic_long_dec_return(atomic_long_t *l)
63408 {
63409 atomic64_t *v = (atomic64_t *)l;
63410 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63411
63412 typedef atomic_t atomic_long_t;
63413
63414 +#ifdef CONFIG_PAX_REFCOUNT
63415 +typedef atomic_unchecked_t atomic_long_unchecked_t;
63416 +#else
63417 +typedef atomic_t atomic_long_unchecked_t;
63418 +#endif
63419 +
63420 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
63421 static inline long atomic_long_read(atomic_long_t *l)
63422 {
63423 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
63424 return (long)atomic_read(v);
63425 }
63426
63427 +#ifdef CONFIG_PAX_REFCOUNT
63428 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
63429 +{
63430 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63431 +
63432 + return (long)atomic_read_unchecked(v);
63433 +}
63434 +#endif
63435 +
63436 static inline void atomic_long_set(atomic_long_t *l, long i)
63437 {
63438 atomic_t *v = (atomic_t *)l;
63439 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
63440 atomic_set(v, i);
63441 }
63442
63443 +#ifdef CONFIG_PAX_REFCOUNT
63444 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
63445 +{
63446 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63447 +
63448 + atomic_set_unchecked(v, i);
63449 +}
63450 +#endif
63451 +
63452 static inline void atomic_long_inc(atomic_long_t *l)
63453 {
63454 atomic_t *v = (atomic_t *)l;
63455 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
63456 atomic_inc(v);
63457 }
63458
63459 +#ifdef CONFIG_PAX_REFCOUNT
63460 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
63461 +{
63462 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63463 +
63464 + atomic_inc_unchecked(v);
63465 +}
63466 +#endif
63467 +
63468 static inline void atomic_long_dec(atomic_long_t *l)
63469 {
63470 atomic_t *v = (atomic_t *)l;
63471 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
63472 atomic_dec(v);
63473 }
63474
63475 +#ifdef CONFIG_PAX_REFCOUNT
63476 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
63477 +{
63478 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63479 +
63480 + atomic_dec_unchecked(v);
63481 +}
63482 +#endif
63483 +
63484 static inline void atomic_long_add(long i, atomic_long_t *l)
63485 {
63486 atomic_t *v = (atomic_t *)l;
63487 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
63488 atomic_add(i, v);
63489 }
63490
63491 +#ifdef CONFIG_PAX_REFCOUNT
63492 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
63493 +{
63494 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63495 +
63496 + atomic_add_unchecked(i, v);
63497 +}
63498 +#endif
63499 +
63500 static inline void atomic_long_sub(long i, atomic_long_t *l)
63501 {
63502 atomic_t *v = (atomic_t *)l;
63503 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
63504 atomic_sub(i, v);
63505 }
63506
63507 +#ifdef CONFIG_PAX_REFCOUNT
63508 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
63509 +{
63510 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63511 +
63512 + atomic_sub_unchecked(i, v);
63513 +}
63514 +#endif
63515 +
63516 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
63517 {
63518 atomic_t *v = (atomic_t *)l;
63519 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
63520 return (long)atomic_add_return(i, v);
63521 }
63522
63523 +#ifdef CONFIG_PAX_REFCOUNT
63524 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
63525 +{
63526 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63527 +
63528 + return (long)atomic_add_return_unchecked(i, v);
63529 +}
63530 +
63531 +#endif
63532 +
63533 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
63534 {
63535 atomic_t *v = (atomic_t *)l;
63536 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
63537 return (long)atomic_inc_return(v);
63538 }
63539
63540 +#ifdef CONFIG_PAX_REFCOUNT
63541 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
63542 +{
63543 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
63544 +
63545 + return (long)atomic_inc_return_unchecked(v);
63546 +}
63547 +#endif
63548 +
63549 static inline long atomic_long_dec_return(atomic_long_t *l)
63550 {
63551 atomic_t *v = (atomic_t *)l;
63552 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
63553
63554 #endif /* BITS_PER_LONG == 64 */
63555
63556 +#ifdef CONFIG_PAX_REFCOUNT
63557 +static inline void pax_refcount_needs_these_functions(void)
63558 +{
63559 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
63560 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
63561 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
63562 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
63563 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
63564 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
63565 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
63566 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
63567 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
63568 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
63569 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
63570 +#ifdef CONFIG_X86
63571 + atomic_clear_mask_unchecked(0, NULL);
63572 + atomic_set_mask_unchecked(0, NULL);
63573 +#endif
63574 +
63575 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
63576 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
63577 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
63578 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
63579 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
63580 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
63581 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
63582 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
63583 +}
63584 +#else
63585 +#define atomic_read_unchecked(v) atomic_read(v)
63586 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
63587 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
63588 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
63589 +#define atomic_inc_unchecked(v) atomic_inc(v)
63590 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
63591 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
63592 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
63593 +#define atomic_dec_unchecked(v) atomic_dec(v)
63594 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
63595 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
63596 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
63597 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
63598 +
63599 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
63600 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
63601 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
63602 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
63603 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
63604 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
63605 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
63606 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
63607 +#endif
63608 +
63609 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
63610 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
63611 index 1ced641..c896ee8 100644
63612 --- a/include/asm-generic/atomic.h
63613 +++ b/include/asm-generic/atomic.h
63614 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
63615 * Atomically clears the bits set in @mask from @v
63616 */
63617 #ifndef atomic_clear_mask
63618 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
63619 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
63620 {
63621 unsigned long flags;
63622
63623 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
63624 index b18ce4f..2ee2843 100644
63625 --- a/include/asm-generic/atomic64.h
63626 +++ b/include/asm-generic/atomic64.h
63627 @@ -16,6 +16,8 @@ typedef struct {
63628 long long counter;
63629 } atomic64_t;
63630
63631 +typedef atomic64_t atomic64_unchecked_t;
63632 +
63633 #define ATOMIC64_INIT(i) { (i) }
63634
63635 extern long long atomic64_read(const atomic64_t *v);
63636 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
63637 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
63638 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
63639
63640 +#define atomic64_read_unchecked(v) atomic64_read(v)
63641 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
63642 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
63643 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
63644 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
63645 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
63646 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
63647 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
63648 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
63649 +
63650 #endif /* _ASM_GENERIC_ATOMIC64_H */
63651 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
63652 index 1bfcfe5..e04c5c9 100644
63653 --- a/include/asm-generic/cache.h
63654 +++ b/include/asm-generic/cache.h
63655 @@ -6,7 +6,7 @@
63656 * cache lines need to provide their own cache.h.
63657 */
63658
63659 -#define L1_CACHE_SHIFT 5
63660 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
63661 +#define L1_CACHE_SHIFT 5UL
63662 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
63663
63664 #endif /* __ASM_GENERIC_CACHE_H */
63665 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
63666 index 0d68a1e..b74a761 100644
63667 --- a/include/asm-generic/emergency-restart.h
63668 +++ b/include/asm-generic/emergency-restart.h
63669 @@ -1,7 +1,7 @@
63670 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
63671 #define _ASM_GENERIC_EMERGENCY_RESTART_H
63672
63673 -static inline void machine_emergency_restart(void)
63674 +static inline __noreturn void machine_emergency_restart(void)
63675 {
63676 machine_restart(NULL);
63677 }
63678 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
63679 index 90f99c7..00ce236 100644
63680 --- a/include/asm-generic/kmap_types.h
63681 +++ b/include/asm-generic/kmap_types.h
63682 @@ -2,9 +2,9 @@
63683 #define _ASM_GENERIC_KMAP_TYPES_H
63684
63685 #ifdef __WITH_KM_FENCE
63686 -# define KM_TYPE_NR 41
63687 +# define KM_TYPE_NR 42
63688 #else
63689 -# define KM_TYPE_NR 20
63690 +# define KM_TYPE_NR 21
63691 #endif
63692
63693 #endif
63694 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
63695 index 9ceb03b..62b0b8f 100644
63696 --- a/include/asm-generic/local.h
63697 +++ b/include/asm-generic/local.h
63698 @@ -23,24 +23,37 @@ typedef struct
63699 atomic_long_t a;
63700 } local_t;
63701
63702 +typedef struct {
63703 + atomic_long_unchecked_t a;
63704 +} local_unchecked_t;
63705 +
63706 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
63707
63708 #define local_read(l) atomic_long_read(&(l)->a)
63709 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
63710 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
63711 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
63712 #define local_inc(l) atomic_long_inc(&(l)->a)
63713 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
63714 #define local_dec(l) atomic_long_dec(&(l)->a)
63715 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
63716 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
63717 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
63718 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
63719 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
63720
63721 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
63722 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
63723 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
63724 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
63725 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
63726 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
63727 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
63728 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
63729 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
63730
63731 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63732 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
63733 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
63734 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
63735 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
63736 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
63737 index 725612b..9cc513a 100644
63738 --- a/include/asm-generic/pgtable-nopmd.h
63739 +++ b/include/asm-generic/pgtable-nopmd.h
63740 @@ -1,14 +1,19 @@
63741 #ifndef _PGTABLE_NOPMD_H
63742 #define _PGTABLE_NOPMD_H
63743
63744 -#ifndef __ASSEMBLY__
63745 -
63746 #include <asm-generic/pgtable-nopud.h>
63747
63748 -struct mm_struct;
63749 -
63750 #define __PAGETABLE_PMD_FOLDED
63751
63752 +#define PMD_SHIFT PUD_SHIFT
63753 +#define PTRS_PER_PMD 1
63754 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
63755 +#define PMD_MASK (~(PMD_SIZE-1))
63756 +
63757 +#ifndef __ASSEMBLY__
63758 +
63759 +struct mm_struct;
63760 +
63761 /*
63762 * Having the pmd type consist of a pud gets the size right, and allows
63763 * us to conceptually access the pud entry that this pmd is folded into
63764 @@ -16,11 +21,6 @@ struct mm_struct;
63765 */
63766 typedef struct { pud_t pud; } pmd_t;
63767
63768 -#define PMD_SHIFT PUD_SHIFT
63769 -#define PTRS_PER_PMD 1
63770 -#define PMD_SIZE (1UL << PMD_SHIFT)
63771 -#define PMD_MASK (~(PMD_SIZE-1))
63772 -
63773 /*
63774 * The "pud_xxx()" functions here are trivial for a folded two-level
63775 * setup: the pmd is never bad, and a pmd always exists (as it's folded
63776 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
63777 index 810431d..0ec4804f 100644
63778 --- a/include/asm-generic/pgtable-nopud.h
63779 +++ b/include/asm-generic/pgtable-nopud.h
63780 @@ -1,10 +1,15 @@
63781 #ifndef _PGTABLE_NOPUD_H
63782 #define _PGTABLE_NOPUD_H
63783
63784 -#ifndef __ASSEMBLY__
63785 -
63786 #define __PAGETABLE_PUD_FOLDED
63787
63788 +#define PUD_SHIFT PGDIR_SHIFT
63789 +#define PTRS_PER_PUD 1
63790 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
63791 +#define PUD_MASK (~(PUD_SIZE-1))
63792 +
63793 +#ifndef __ASSEMBLY__
63794 +
63795 /*
63796 * Having the pud type consist of a pgd gets the size right, and allows
63797 * us to conceptually access the pgd entry that this pud is folded into
63798 @@ -12,11 +17,6 @@
63799 */
63800 typedef struct { pgd_t pgd; } pud_t;
63801
63802 -#define PUD_SHIFT PGDIR_SHIFT
63803 -#define PTRS_PER_PUD 1
63804 -#define PUD_SIZE (1UL << PUD_SHIFT)
63805 -#define PUD_MASK (~(PUD_SIZE-1))
63806 -
63807 /*
63808 * The "pgd_xxx()" functions here are trivial for a folded two-level
63809 * setup: the pud is never bad, and a pud always exists (as it's folded
63810 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
63811 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
63812
63813 #define pgd_populate(mm, pgd, pud) do { } while (0)
63814 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
63815 /*
63816 * (puds are folded into pgds so this doesn't get actually called,
63817 * but the define is needed for a generic inline function.)
63818 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
63819 index 5cf680a..4b74d62 100644
63820 --- a/include/asm-generic/pgtable.h
63821 +++ b/include/asm-generic/pgtable.h
63822 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
63823 }
63824 #endif /* CONFIG_NUMA_BALANCING */
63825
63826 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
63827 +static inline unsigned long pax_open_kernel(void) { return 0; }
63828 +#endif
63829 +
63830 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
63831 +static inline unsigned long pax_close_kernel(void) { return 0; }
63832 +#endif
63833 +
63834 #endif /* CONFIG_MMU */
63835
63836 #endif /* !__ASSEMBLY__ */
63837 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
63838 index d1ea7ce..b1ebf2a 100644
63839 --- a/include/asm-generic/vmlinux.lds.h
63840 +++ b/include/asm-generic/vmlinux.lds.h
63841 @@ -218,6 +218,7 @@
63842 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
63843 VMLINUX_SYMBOL(__start_rodata) = .; \
63844 *(.rodata) *(.rodata.*) \
63845 + *(.data..read_only) \
63846 *(__vermagic) /* Kernel version magic */ \
63847 . = ALIGN(8); \
63848 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
63849 @@ -725,17 +726,18 @@
63850 * section in the linker script will go there too. @phdr should have
63851 * a leading colon.
63852 *
63853 - * Note that this macros defines __per_cpu_load as an absolute symbol.
63854 + * Note that this macros defines per_cpu_load as an absolute symbol.
63855 * If there is no need to put the percpu section at a predetermined
63856 * address, use PERCPU_SECTION.
63857 */
63858 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
63859 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
63860 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
63861 + per_cpu_load = .; \
63862 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
63863 - LOAD_OFFSET) { \
63864 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
63865 PERCPU_INPUT(cacheline) \
63866 } phdr \
63867 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
63868 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
63869
63870 /**
63871 * PERCPU_SECTION - define output section for percpu area, simple version
63872 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
63873 index 418d270..bfd2794 100644
63874 --- a/include/crypto/algapi.h
63875 +++ b/include/crypto/algapi.h
63876 @@ -34,7 +34,7 @@ struct crypto_type {
63877 unsigned int maskclear;
63878 unsigned int maskset;
63879 unsigned int tfmsize;
63880 -};
63881 +} __do_const;
63882
63883 struct crypto_instance {
63884 struct crypto_alg alg;
63885 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
63886 index fad21c9..3fff955 100644
63887 --- a/include/drm/drmP.h
63888 +++ b/include/drm/drmP.h
63889 @@ -72,6 +72,7 @@
63890 #include <linux/workqueue.h>
63891 #include <linux/poll.h>
63892 #include <asm/pgalloc.h>
63893 +#include <asm/local.h>
63894 #include <drm/drm.h>
63895 #include <drm/drm_sarea.h>
63896
63897 @@ -1068,7 +1069,7 @@ struct drm_device {
63898
63899 /** \name Usage Counters */
63900 /*@{ */
63901 - int open_count; /**< Outstanding files open */
63902 + local_t open_count; /**< Outstanding files open */
63903 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
63904 atomic_t vma_count; /**< Outstanding vma areas open */
63905 int buf_use; /**< Buffers in use -- cannot alloc */
63906 @@ -1079,7 +1080,7 @@ struct drm_device {
63907 /*@{ */
63908 unsigned long counters;
63909 enum drm_stat_type types[15];
63910 - atomic_t counts[15];
63911 + atomic_unchecked_t counts[15];
63912 /*@} */
63913
63914 struct list_head filelist;
63915 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
63916 index f43d556..94d9343 100644
63917 --- a/include/drm/drm_crtc_helper.h
63918 +++ b/include/drm/drm_crtc_helper.h
63919 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
63920 struct drm_connector *connector);
63921 /* disable encoder when not in use - more explicit than dpms off */
63922 void (*disable)(struct drm_encoder *encoder);
63923 -};
63924 +} __no_const;
63925
63926 /**
63927 * drm_connector_helper_funcs - helper operations for connectors
63928 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
63929 index 72dcbe8..8db58d7 100644
63930 --- a/include/drm/ttm/ttm_memory.h
63931 +++ b/include/drm/ttm/ttm_memory.h
63932 @@ -48,7 +48,7 @@
63933
63934 struct ttm_mem_shrink {
63935 int (*do_shrink) (struct ttm_mem_shrink *);
63936 -};
63937 +} __no_const;
63938
63939 /**
63940 * struct ttm_mem_global - Global memory accounting structure.
63941 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
63942 index c1da539..4db35ec 100644
63943 --- a/include/linux/atmdev.h
63944 +++ b/include/linux/atmdev.h
63945 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
63946 #endif
63947
63948 struct k_atm_aal_stats {
63949 -#define __HANDLE_ITEM(i) atomic_t i
63950 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
63951 __AAL_STAT_ITEMS
63952 #undef __HANDLE_ITEM
63953 };
63954 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
63955 index 0530b98..b127a9e 100644
63956 --- a/include/linux/binfmts.h
63957 +++ b/include/linux/binfmts.h
63958 @@ -73,6 +73,7 @@ struct linux_binfmt {
63959 int (*load_binary)(struct linux_binprm *);
63960 int (*load_shlib)(struct file *);
63961 int (*core_dump)(struct coredump_params *cprm);
63962 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
63963 unsigned long min_coredump; /* minimal dump size */
63964 };
63965
63966 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
63967 index f94bc83..62b9cfe 100644
63968 --- a/include/linux/blkdev.h
63969 +++ b/include/linux/blkdev.h
63970 @@ -1498,7 +1498,7 @@ struct block_device_operations {
63971 /* this callback is with swap_lock and sometimes page table lock held */
63972 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
63973 struct module *owner;
63974 -};
63975 +} __do_const;
63976
63977 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
63978 unsigned long);
63979 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
63980 index 7c2e030..b72475d 100644
63981 --- a/include/linux/blktrace_api.h
63982 +++ b/include/linux/blktrace_api.h
63983 @@ -23,7 +23,7 @@ struct blk_trace {
63984 struct dentry *dir;
63985 struct dentry *dropped_file;
63986 struct dentry *msg_file;
63987 - atomic_t dropped;
63988 + atomic_unchecked_t dropped;
63989 };
63990
63991 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
63992 diff --git a/include/linux/cache.h b/include/linux/cache.h
63993 index 4c57065..4307975 100644
63994 --- a/include/linux/cache.h
63995 +++ b/include/linux/cache.h
63996 @@ -16,6 +16,10 @@
63997 #define __read_mostly
63998 #endif
63999
64000 +#ifndef __read_only
64001 +#define __read_only __read_mostly
64002 +#endif
64003 +
64004 #ifndef ____cacheline_aligned
64005 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
64006 #endif
64007 diff --git a/include/linux/capability.h b/include/linux/capability.h
64008 index 98503b7..cc36d18 100644
64009 --- a/include/linux/capability.h
64010 +++ b/include/linux/capability.h
64011 @@ -211,8 +211,13 @@ extern bool capable(int cap);
64012 extern bool ns_capable(struct user_namespace *ns, int cap);
64013 extern bool nsown_capable(int cap);
64014 extern bool inode_capable(const struct inode *inode, int cap);
64015 +extern bool capable_nolog(int cap);
64016 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
64017 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
64018
64019 /* audit system wants to get cap info from files as well */
64020 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
64021
64022 +extern int is_privileged_binary(const struct dentry *dentry);
64023 +
64024 #endif /* !_LINUX_CAPABILITY_H */
64025 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
64026 index 8609d57..86e4d79 100644
64027 --- a/include/linux/cdrom.h
64028 +++ b/include/linux/cdrom.h
64029 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
64030
64031 /* driver specifications */
64032 const int capability; /* capability flags */
64033 - int n_minors; /* number of active minor devices */
64034 /* handle uniform packets for scsi type devices (scsi,atapi) */
64035 int (*generic_packet) (struct cdrom_device_info *,
64036 struct packet_command *);
64037 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
64038 index 42e55de..1cd0e66 100644
64039 --- a/include/linux/cleancache.h
64040 +++ b/include/linux/cleancache.h
64041 @@ -31,7 +31,7 @@ struct cleancache_ops {
64042 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
64043 void (*invalidate_inode)(int, struct cleancache_filekey);
64044 void (*invalidate_fs)(int);
64045 -};
64046 +} __no_const;
64047
64048 extern struct cleancache_ops
64049 cleancache_register_ops(struct cleancache_ops *ops);
64050 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
64051 index 662fd1b..e801992 100644
64052 --- a/include/linux/compiler-gcc4.h
64053 +++ b/include/linux/compiler-gcc4.h
64054 @@ -34,6 +34,21 @@
64055 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
64056
64057 #if __GNUC_MINOR__ >= 5
64058 +
64059 +#ifdef CONSTIFY_PLUGIN
64060 +#define __no_const __attribute__((no_const))
64061 +#define __do_const __attribute__((do_const))
64062 +#endif
64063 +
64064 +#ifdef SIZE_OVERFLOW_PLUGIN
64065 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
64066 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
64067 +#endif
64068 +
64069 +#ifdef LATENT_ENTROPY_PLUGIN
64070 +#define __latent_entropy __attribute__((latent_entropy))
64071 +#endif
64072 +
64073 /*
64074 * Mark a position in code as unreachable. This can be used to
64075 * suppress control flow warnings after asm blocks that transfer
64076 @@ -49,6 +64,11 @@
64077 #define __noclone __attribute__((__noclone__))
64078
64079 #endif
64080 +
64081 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
64082 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
64083 +#define __bos0(ptr) __bos((ptr), 0)
64084 +#define __bos1(ptr) __bos((ptr), 1)
64085 #endif
64086
64087 #if __GNUC_MINOR__ >= 6
64088 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
64089 index dd852b7..72924c0 100644
64090 --- a/include/linux/compiler.h
64091 +++ b/include/linux/compiler.h
64092 @@ -5,11 +5,14 @@
64093
64094 #ifdef __CHECKER__
64095 # define __user __attribute__((noderef, address_space(1)))
64096 +# define __force_user __force __user
64097 # define __kernel __attribute__((address_space(0)))
64098 +# define __force_kernel __force __kernel
64099 # define __safe __attribute__((safe))
64100 # define __force __attribute__((force))
64101 # define __nocast __attribute__((nocast))
64102 # define __iomem __attribute__((noderef, address_space(2)))
64103 +# define __force_iomem __force __iomem
64104 # define __must_hold(x) __attribute__((context(x,1,1)))
64105 # define __acquires(x) __attribute__((context(x,0,1)))
64106 # define __releases(x) __attribute__((context(x,1,0)))
64107 @@ -17,20 +20,48 @@
64108 # define __release(x) __context__(x,-1)
64109 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
64110 # define __percpu __attribute__((noderef, address_space(3)))
64111 +# define __force_percpu __force __percpu
64112 #ifdef CONFIG_SPARSE_RCU_POINTER
64113 # define __rcu __attribute__((noderef, address_space(4)))
64114 +# define __force_rcu __force __rcu
64115 #else
64116 # define __rcu
64117 +# define __force_rcu
64118 #endif
64119 extern void __chk_user_ptr(const volatile void __user *);
64120 extern void __chk_io_ptr(const volatile void __iomem *);
64121 +#elif defined(CHECKER_PLUGIN)
64122 +//# define __user
64123 +//# define __force_user
64124 +//# define __kernel
64125 +//# define __force_kernel
64126 +# define __safe
64127 +# define __force
64128 +# define __nocast
64129 +# define __iomem
64130 +# define __force_iomem
64131 +# define __chk_user_ptr(x) (void)0
64132 +# define __chk_io_ptr(x) (void)0
64133 +# define __builtin_warning(x, y...) (1)
64134 +# define __acquires(x)
64135 +# define __releases(x)
64136 +# define __acquire(x) (void)0
64137 +# define __release(x) (void)0
64138 +# define __cond_lock(x,c) (c)
64139 +# define __percpu
64140 +# define __force_percpu
64141 +# define __rcu
64142 +# define __force_rcu
64143 #else
64144 # define __user
64145 +# define __force_user
64146 # define __kernel
64147 +# define __force_kernel
64148 # define __safe
64149 # define __force
64150 # define __nocast
64151 # define __iomem
64152 +# define __force_iomem
64153 # define __chk_user_ptr(x) (void)0
64154 # define __chk_io_ptr(x) (void)0
64155 # define __builtin_warning(x, y...) (1)
64156 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
64157 # define __release(x) (void)0
64158 # define __cond_lock(x,c) (c)
64159 # define __percpu
64160 +# define __force_percpu
64161 # define __rcu
64162 +# define __force_rcu
64163 #endif
64164
64165 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
64166 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64167 # define __attribute_const__ /* unimplemented */
64168 #endif
64169
64170 +#ifndef __no_const
64171 +# define __no_const
64172 +#endif
64173 +
64174 +#ifndef __do_const
64175 +# define __do_const
64176 +#endif
64177 +
64178 +#ifndef __size_overflow
64179 +# define __size_overflow(...)
64180 +#endif
64181 +
64182 +#ifndef __intentional_overflow
64183 +# define __intentional_overflow(...)
64184 +#endif
64185 +
64186 +#ifndef __latent_entropy
64187 +# define __latent_entropy
64188 +#endif
64189 +
64190 /*
64191 * Tell gcc if a function is cold. The compiler will assume any path
64192 * directly leading to the call is unlikely.
64193 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64194 #define __cold
64195 #endif
64196
64197 +#ifndef __alloc_size
64198 +#define __alloc_size(...)
64199 +#endif
64200 +
64201 +#ifndef __bos
64202 +#define __bos(ptr, arg)
64203 +#endif
64204 +
64205 +#ifndef __bos0
64206 +#define __bos0(ptr)
64207 +#endif
64208 +
64209 +#ifndef __bos1
64210 +#define __bos1(ptr)
64211 +#endif
64212 +
64213 /* Simple shorthand for a section definition */
64214 #ifndef __section
64215 # define __section(S) __attribute__ ((__section__(#S)))
64216 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
64217 * use is to mediate communication between process-level code and irq/NMI
64218 * handlers, all running on the same CPU.
64219 */
64220 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
64221 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
64222 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
64223
64224 #endif /* __LINUX_COMPILER_H */
64225 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
64226 index ce7a074..01ab8ac 100644
64227 --- a/include/linux/cpu.h
64228 +++ b/include/linux/cpu.h
64229 @@ -115,7 +115,7 @@ enum {
64230 /* Need to know about CPUs going up/down? */
64231 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
64232 #define cpu_notifier(fn, pri) { \
64233 - static struct notifier_block fn##_nb __cpuinitdata = \
64234 + static struct notifier_block fn##_nb = \
64235 { .notifier_call = fn, .priority = pri }; \
64236 register_cpu_notifier(&fn##_nb); \
64237 }
64238 diff --git a/include/linux/cred.h b/include/linux/cred.h
64239 index 04421e8..6bce4ef 100644
64240 --- a/include/linux/cred.h
64241 +++ b/include/linux/cred.h
64242 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
64243 static inline void validate_process_creds(void)
64244 {
64245 }
64246 +static inline void validate_task_creds(struct task_struct *task)
64247 +{
64248 +}
64249 #endif
64250
64251 /**
64252 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
64253 index b92eadf..b4ecdc1 100644
64254 --- a/include/linux/crypto.h
64255 +++ b/include/linux/crypto.h
64256 @@ -373,7 +373,7 @@ struct cipher_tfm {
64257 const u8 *key, unsigned int keylen);
64258 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64259 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
64260 -};
64261 +} __no_const;
64262
64263 struct hash_tfm {
64264 int (*init)(struct hash_desc *desc);
64265 @@ -394,13 +394,13 @@ struct compress_tfm {
64266 int (*cot_decompress)(struct crypto_tfm *tfm,
64267 const u8 *src, unsigned int slen,
64268 u8 *dst, unsigned int *dlen);
64269 -};
64270 +} __no_const;
64271
64272 struct rng_tfm {
64273 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
64274 unsigned int dlen);
64275 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
64276 -};
64277 +} __no_const;
64278
64279 #define crt_ablkcipher crt_u.ablkcipher
64280 #define crt_aead crt_u.aead
64281 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
64282 index 7925bf0..d5143d2 100644
64283 --- a/include/linux/decompress/mm.h
64284 +++ b/include/linux/decompress/mm.h
64285 @@ -77,7 +77,7 @@ static void free(void *where)
64286 * warnings when not needed (indeed large_malloc / large_free are not
64287 * needed by inflate */
64288
64289 -#define malloc(a) kmalloc(a, GFP_KERNEL)
64290 +#define malloc(a) kmalloc((a), GFP_KERNEL)
64291 #define free(a) kfree(a)
64292
64293 #define large_malloc(a) vmalloc(a)
64294 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
64295 index 94af418..b1ca7a2 100644
64296 --- a/include/linux/dma-mapping.h
64297 +++ b/include/linux/dma-mapping.h
64298 @@ -54,7 +54,7 @@ struct dma_map_ops {
64299 u64 (*get_required_mask)(struct device *dev);
64300 #endif
64301 int is_phys;
64302 -};
64303 +} __do_const;
64304
64305 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
64306
64307 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
64308 index d3201e4..8281e63 100644
64309 --- a/include/linux/dmaengine.h
64310 +++ b/include/linux/dmaengine.h
64311 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
64312 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
64313 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
64314
64315 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64316 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
64317 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
64318 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64319 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
64320 struct dma_pinned_list *pinned_list, struct page *page,
64321 unsigned int offset, size_t len);
64322
64323 diff --git a/include/linux/efi.h b/include/linux/efi.h
64324 index 7a9498a..155713d 100644
64325 --- a/include/linux/efi.h
64326 +++ b/include/linux/efi.h
64327 @@ -733,6 +733,7 @@ struct efivar_operations {
64328 efi_set_variable_t *set_variable;
64329 efi_query_variable_info_t *query_variable_info;
64330 };
64331 +typedef struct efivar_operations __no_const efivar_operations_no_const;
64332
64333 struct efivars {
64334 /*
64335 diff --git a/include/linux/elf.h b/include/linux/elf.h
64336 index 8c9048e..16a4665 100644
64337 --- a/include/linux/elf.h
64338 +++ b/include/linux/elf.h
64339 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
64340 #define elf_note elf32_note
64341 #define elf_addr_t Elf32_Off
64342 #define Elf_Half Elf32_Half
64343 +#define elf_dyn Elf32_Dyn
64344
64345 #else
64346
64347 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
64348 #define elf_note elf64_note
64349 #define elf_addr_t Elf64_Off
64350 #define Elf_Half Elf64_Half
64351 +#define elf_dyn Elf64_Dyn
64352
64353 #endif
64354
64355 diff --git a/include/linux/filter.h b/include/linux/filter.h
64356 index c45eabc..baa0be5 100644
64357 --- a/include/linux/filter.h
64358 +++ b/include/linux/filter.h
64359 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
64360
64361 struct sk_buff;
64362 struct sock;
64363 +struct bpf_jit_work;
64364
64365 struct sk_filter
64366 {
64367 @@ -27,6 +28,9 @@ struct sk_filter
64368 unsigned int len; /* Number of filter blocks */
64369 unsigned int (*bpf_func)(const struct sk_buff *skb,
64370 const struct sock_filter *filter);
64371 +#ifdef CONFIG_BPF_JIT
64372 + struct bpf_jit_work *work;
64373 +#endif
64374 struct rcu_head rcu;
64375 struct sock_filter insns[0];
64376 };
64377 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
64378 index 3044254..9767f41 100644
64379 --- a/include/linux/frontswap.h
64380 +++ b/include/linux/frontswap.h
64381 @@ -11,7 +11,7 @@ struct frontswap_ops {
64382 int (*load)(unsigned, pgoff_t, struct page *);
64383 void (*invalidate_page)(unsigned, pgoff_t);
64384 void (*invalidate_area)(unsigned);
64385 -};
64386 +} __no_const;
64387
64388 extern bool frontswap_enabled;
64389 extern struct frontswap_ops
64390 diff --git a/include/linux/fs.h b/include/linux/fs.h
64391 index 7617ee0..b575199 100644
64392 --- a/include/linux/fs.h
64393 +++ b/include/linux/fs.h
64394 @@ -1541,7 +1541,8 @@ struct file_operations {
64395 long (*fallocate)(struct file *file, int mode, loff_t offset,
64396 loff_t len);
64397 int (*show_fdinfo)(struct seq_file *m, struct file *f);
64398 -};
64399 +} __do_const;
64400 +typedef struct file_operations __no_const file_operations_no_const;
64401
64402 struct inode_operations {
64403 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
64404 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
64405 inode->i_flags |= S_NOSEC;
64406 }
64407
64408 +static inline bool is_sidechannel_device(const struct inode *inode)
64409 +{
64410 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
64411 + umode_t mode = inode->i_mode;
64412 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
64413 +#else
64414 + return false;
64415 +#endif
64416 +}
64417 +
64418 #endif /* _LINUX_FS_H */
64419 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
64420 index d0ae3a8..0244b34 100644
64421 --- a/include/linux/fs_struct.h
64422 +++ b/include/linux/fs_struct.h
64423 @@ -6,7 +6,7 @@
64424 #include <linux/seqlock.h>
64425
64426 struct fs_struct {
64427 - int users;
64428 + atomic_t users;
64429 spinlock_t lock;
64430 seqcount_t seq;
64431 int umask;
64432 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
64433 index 5dfa0aa..6acf322 100644
64434 --- a/include/linux/fscache-cache.h
64435 +++ b/include/linux/fscache-cache.h
64436 @@ -112,7 +112,7 @@ struct fscache_operation {
64437 fscache_operation_release_t release;
64438 };
64439
64440 -extern atomic_t fscache_op_debug_id;
64441 +extern atomic_unchecked_t fscache_op_debug_id;
64442 extern void fscache_op_work_func(struct work_struct *work);
64443
64444 extern void fscache_enqueue_operation(struct fscache_operation *);
64445 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
64446 INIT_WORK(&op->work, fscache_op_work_func);
64447 atomic_set(&op->usage, 1);
64448 op->state = FSCACHE_OP_ST_INITIALISED;
64449 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
64450 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
64451 op->processor = processor;
64452 op->release = release;
64453 INIT_LIST_HEAD(&op->pend_link);
64454 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
64455 index 0fbfb46..508eb0d 100644
64456 --- a/include/linux/fsnotify.h
64457 +++ b/include/linux/fsnotify.h
64458 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
64459 struct inode *inode = path->dentry->d_inode;
64460 __u32 mask = FS_ACCESS;
64461
64462 + if (is_sidechannel_device(inode))
64463 + return;
64464 +
64465 if (S_ISDIR(inode->i_mode))
64466 mask |= FS_ISDIR;
64467
64468 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
64469 struct inode *inode = path->dentry->d_inode;
64470 __u32 mask = FS_MODIFY;
64471
64472 + if (is_sidechannel_device(inode))
64473 + return;
64474 +
64475 if (S_ISDIR(inode->i_mode))
64476 mask |= FS_ISDIR;
64477
64478 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
64479 */
64480 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
64481 {
64482 - return kstrdup(name, GFP_KERNEL);
64483 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
64484 }
64485
64486 /*
64487 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
64488 index a3d4895..ddd2a50 100644
64489 --- a/include/linux/ftrace_event.h
64490 +++ b/include/linux/ftrace_event.h
64491 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
64492 extern int trace_add_event_call(struct ftrace_event_call *call);
64493 extern void trace_remove_event_call(struct ftrace_event_call *call);
64494
64495 -#define is_signed_type(type) (((type)(-1)) < 0)
64496 +#define is_signed_type(type) (((type)(-1)) < (type)1)
64497
64498 int trace_set_clr_event(const char *system, const char *event, int set);
64499
64500 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
64501 index 79b8bba..86b539e 100644
64502 --- a/include/linux/genhd.h
64503 +++ b/include/linux/genhd.h
64504 @@ -194,7 +194,7 @@ struct gendisk {
64505 struct kobject *slave_dir;
64506
64507 struct timer_rand_state *random;
64508 - atomic_t sync_io; /* RAID */
64509 + atomic_unchecked_t sync_io; /* RAID */
64510 struct disk_events *ev;
64511 #ifdef CONFIG_BLK_DEV_INTEGRITY
64512 struct blk_integrity *integrity;
64513 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
64514 index 0f615eb..5c3832f 100644
64515 --- a/include/linux/gfp.h
64516 +++ b/include/linux/gfp.h
64517 @@ -35,6 +35,13 @@ struct vm_area_struct;
64518 #define ___GFP_NO_KSWAPD 0x400000u
64519 #define ___GFP_OTHER_NODE 0x800000u
64520 #define ___GFP_WRITE 0x1000000u
64521 +
64522 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64523 +#define ___GFP_USERCOPY 0x2000000u
64524 +#else
64525 +#define ___GFP_USERCOPY 0
64526 +#endif
64527 +
64528 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
64529
64530 /*
64531 @@ -92,6 +99,7 @@ struct vm_area_struct;
64532 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
64533 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
64534 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
64535 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
64536
64537 /*
64538 * This may seem redundant, but it's a way of annotating false positives vs.
64539 @@ -99,7 +107,7 @@ struct vm_area_struct;
64540 */
64541 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
64542
64543 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
64544 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
64545 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
64546
64547 /* This equals 0, but use constants in case they ever change */
64548 @@ -153,6 +161,8 @@ struct vm_area_struct;
64549 /* 4GB DMA on some platforms */
64550 #define GFP_DMA32 __GFP_DMA32
64551
64552 +#define GFP_USERCOPY __GFP_USERCOPY
64553 +
64554 /* Convert GFP flags to their corresponding migrate type */
64555 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
64556 {
64557 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
64558 new file mode 100644
64559 index 0000000..ebe6d72
64560 --- /dev/null
64561 +++ b/include/linux/gracl.h
64562 @@ -0,0 +1,319 @@
64563 +#ifndef GR_ACL_H
64564 +#define GR_ACL_H
64565 +
64566 +#include <linux/grdefs.h>
64567 +#include <linux/resource.h>
64568 +#include <linux/capability.h>
64569 +#include <linux/dcache.h>
64570 +#include <asm/resource.h>
64571 +
64572 +/* Major status information */
64573 +
64574 +#define GR_VERSION "grsecurity 2.9.1"
64575 +#define GRSECURITY_VERSION 0x2901
64576 +
64577 +enum {
64578 + GR_SHUTDOWN = 0,
64579 + GR_ENABLE = 1,
64580 + GR_SPROLE = 2,
64581 + GR_RELOAD = 3,
64582 + GR_SEGVMOD = 4,
64583 + GR_STATUS = 5,
64584 + GR_UNSPROLE = 6,
64585 + GR_PASSSET = 7,
64586 + GR_SPROLEPAM = 8,
64587 +};
64588 +
64589 +/* Password setup definitions
64590 + * kernel/grhash.c */
64591 +enum {
64592 + GR_PW_LEN = 128,
64593 + GR_SALT_LEN = 16,
64594 + GR_SHA_LEN = 32,
64595 +};
64596 +
64597 +enum {
64598 + GR_SPROLE_LEN = 64,
64599 +};
64600 +
64601 +enum {
64602 + GR_NO_GLOB = 0,
64603 + GR_REG_GLOB,
64604 + GR_CREATE_GLOB
64605 +};
64606 +
64607 +#define GR_NLIMITS 32
64608 +
64609 +/* Begin Data Structures */
64610 +
64611 +struct sprole_pw {
64612 + unsigned char *rolename;
64613 + unsigned char salt[GR_SALT_LEN];
64614 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
64615 +};
64616 +
64617 +struct name_entry {
64618 + __u32 key;
64619 + ino_t inode;
64620 + dev_t device;
64621 + char *name;
64622 + __u16 len;
64623 + __u8 deleted;
64624 + struct name_entry *prev;
64625 + struct name_entry *next;
64626 +};
64627 +
64628 +struct inodev_entry {
64629 + struct name_entry *nentry;
64630 + struct inodev_entry *prev;
64631 + struct inodev_entry *next;
64632 +};
64633 +
64634 +struct acl_role_db {
64635 + struct acl_role_label **r_hash;
64636 + __u32 r_size;
64637 +};
64638 +
64639 +struct inodev_db {
64640 + struct inodev_entry **i_hash;
64641 + __u32 i_size;
64642 +};
64643 +
64644 +struct name_db {
64645 + struct name_entry **n_hash;
64646 + __u32 n_size;
64647 +};
64648 +
64649 +struct crash_uid {
64650 + uid_t uid;
64651 + unsigned long expires;
64652 +};
64653 +
64654 +struct gr_hash_struct {
64655 + void **table;
64656 + void **nametable;
64657 + void *first;
64658 + __u32 table_size;
64659 + __u32 used_size;
64660 + int type;
64661 +};
64662 +
64663 +/* Userspace Grsecurity ACL data structures */
64664 +
64665 +struct acl_subject_label {
64666 + char *filename;
64667 + ino_t inode;
64668 + dev_t device;
64669 + __u32 mode;
64670 + kernel_cap_t cap_mask;
64671 + kernel_cap_t cap_lower;
64672 + kernel_cap_t cap_invert_audit;
64673 +
64674 + struct rlimit res[GR_NLIMITS];
64675 + __u32 resmask;
64676 +
64677 + __u8 user_trans_type;
64678 + __u8 group_trans_type;
64679 + uid_t *user_transitions;
64680 + gid_t *group_transitions;
64681 + __u16 user_trans_num;
64682 + __u16 group_trans_num;
64683 +
64684 + __u32 sock_families[2];
64685 + __u32 ip_proto[8];
64686 + __u32 ip_type;
64687 + struct acl_ip_label **ips;
64688 + __u32 ip_num;
64689 + __u32 inaddr_any_override;
64690 +
64691 + __u32 crashes;
64692 + unsigned long expires;
64693 +
64694 + struct acl_subject_label *parent_subject;
64695 + struct gr_hash_struct *hash;
64696 + struct acl_subject_label *prev;
64697 + struct acl_subject_label *next;
64698 +
64699 + struct acl_object_label **obj_hash;
64700 + __u32 obj_hash_size;
64701 + __u16 pax_flags;
64702 +};
64703 +
64704 +struct role_allowed_ip {
64705 + __u32 addr;
64706 + __u32 netmask;
64707 +
64708 + struct role_allowed_ip *prev;
64709 + struct role_allowed_ip *next;
64710 +};
64711 +
64712 +struct role_transition {
64713 + char *rolename;
64714 +
64715 + struct role_transition *prev;
64716 + struct role_transition *next;
64717 +};
64718 +
64719 +struct acl_role_label {
64720 + char *rolename;
64721 + uid_t uidgid;
64722 + __u16 roletype;
64723 +
64724 + __u16 auth_attempts;
64725 + unsigned long expires;
64726 +
64727 + struct acl_subject_label *root_label;
64728 + struct gr_hash_struct *hash;
64729 +
64730 + struct acl_role_label *prev;
64731 + struct acl_role_label *next;
64732 +
64733 + struct role_transition *transitions;
64734 + struct role_allowed_ip *allowed_ips;
64735 + uid_t *domain_children;
64736 + __u16 domain_child_num;
64737 +
64738 + umode_t umask;
64739 +
64740 + struct acl_subject_label **subj_hash;
64741 + __u32 subj_hash_size;
64742 +};
64743 +
64744 +struct user_acl_role_db {
64745 + struct acl_role_label **r_table;
64746 + __u32 num_pointers; /* Number of allocations to track */
64747 + __u32 num_roles; /* Number of roles */
64748 + __u32 num_domain_children; /* Number of domain children */
64749 + __u32 num_subjects; /* Number of subjects */
64750 + __u32 num_objects; /* Number of objects */
64751 +};
64752 +
64753 +struct acl_object_label {
64754 + char *filename;
64755 + ino_t inode;
64756 + dev_t device;
64757 + __u32 mode;
64758 +
64759 + struct acl_subject_label *nested;
64760 + struct acl_object_label *globbed;
64761 +
64762 + /* next two structures not used */
64763 +
64764 + struct acl_object_label *prev;
64765 + struct acl_object_label *next;
64766 +};
64767 +
64768 +struct acl_ip_label {
64769 + char *iface;
64770 + __u32 addr;
64771 + __u32 netmask;
64772 + __u16 low, high;
64773 + __u8 mode;
64774 + __u32 type;
64775 + __u32 proto[8];
64776 +
64777 + /* next two structures not used */
64778 +
64779 + struct acl_ip_label *prev;
64780 + struct acl_ip_label *next;
64781 +};
64782 +
64783 +struct gr_arg {
64784 + struct user_acl_role_db role_db;
64785 + unsigned char pw[GR_PW_LEN];
64786 + unsigned char salt[GR_SALT_LEN];
64787 + unsigned char sum[GR_SHA_LEN];
64788 + unsigned char sp_role[GR_SPROLE_LEN];
64789 + struct sprole_pw *sprole_pws;
64790 + dev_t segv_device;
64791 + ino_t segv_inode;
64792 + uid_t segv_uid;
64793 + __u16 num_sprole_pws;
64794 + __u16 mode;
64795 +};
64796 +
64797 +struct gr_arg_wrapper {
64798 + struct gr_arg *arg;
64799 + __u32 version;
64800 + __u32 size;
64801 +};
64802 +
64803 +struct subject_map {
64804 + struct acl_subject_label *user;
64805 + struct acl_subject_label *kernel;
64806 + struct subject_map *prev;
64807 + struct subject_map *next;
64808 +};
64809 +
64810 +struct acl_subj_map_db {
64811 + struct subject_map **s_hash;
64812 + __u32 s_size;
64813 +};
64814 +
64815 +/* End Data Structures Section */
64816 +
64817 +/* Hash functions generated by empirical testing by Brad Spengler
64818 + Makes good use of the low bits of the inode. Generally 0-1 times
64819 + in loop for successful match. 0-3 for unsuccessful match.
64820 + Shift/add algorithm with modulus of table size and an XOR*/
64821 +
64822 +static __inline__ unsigned int
64823 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
64824 +{
64825 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
64826 +}
64827 +
64828 + static __inline__ unsigned int
64829 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
64830 +{
64831 + return ((const unsigned long)userp % sz);
64832 +}
64833 +
64834 +static __inline__ unsigned int
64835 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
64836 +{
64837 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
64838 +}
64839 +
64840 +static __inline__ unsigned int
64841 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
64842 +{
64843 + return full_name_hash((const unsigned char *)name, len) % sz;
64844 +}
64845 +
64846 +#define FOR_EACH_ROLE_START(role) \
64847 + role = role_list; \
64848 + while (role) {
64849 +
64850 +#define FOR_EACH_ROLE_END(role) \
64851 + role = role->prev; \
64852 + }
64853 +
64854 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
64855 + subj = NULL; \
64856 + iter = 0; \
64857 + while (iter < role->subj_hash_size) { \
64858 + if (subj == NULL) \
64859 + subj = role->subj_hash[iter]; \
64860 + if (subj == NULL) { \
64861 + iter++; \
64862 + continue; \
64863 + }
64864 +
64865 +#define FOR_EACH_SUBJECT_END(subj,iter) \
64866 + subj = subj->next; \
64867 + if (subj == NULL) \
64868 + iter++; \
64869 + }
64870 +
64871 +
64872 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
64873 + subj = role->hash->first; \
64874 + while (subj != NULL) {
64875 +
64876 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
64877 + subj = subj->next; \
64878 + }
64879 +
64880 +#endif
64881 +
64882 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
64883 new file mode 100644
64884 index 0000000..323ecf2
64885 --- /dev/null
64886 +++ b/include/linux/gralloc.h
64887 @@ -0,0 +1,9 @@
64888 +#ifndef __GRALLOC_H
64889 +#define __GRALLOC_H
64890 +
64891 +void acl_free_all(void);
64892 +int acl_alloc_stack_init(unsigned long size);
64893 +void *acl_alloc(unsigned long len);
64894 +void *acl_alloc_num(unsigned long num, unsigned long len);
64895 +
64896 +#endif
64897 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
64898 new file mode 100644
64899 index 0000000..be66033
64900 --- /dev/null
64901 +++ b/include/linux/grdefs.h
64902 @@ -0,0 +1,140 @@
64903 +#ifndef GRDEFS_H
64904 +#define GRDEFS_H
64905 +
64906 +/* Begin grsecurity status declarations */
64907 +
64908 +enum {
64909 + GR_READY = 0x01,
64910 + GR_STATUS_INIT = 0x00 // disabled state
64911 +};
64912 +
64913 +/* Begin ACL declarations */
64914 +
64915 +/* Role flags */
64916 +
64917 +enum {
64918 + GR_ROLE_USER = 0x0001,
64919 + GR_ROLE_GROUP = 0x0002,
64920 + GR_ROLE_DEFAULT = 0x0004,
64921 + GR_ROLE_SPECIAL = 0x0008,
64922 + GR_ROLE_AUTH = 0x0010,
64923 + GR_ROLE_NOPW = 0x0020,
64924 + GR_ROLE_GOD = 0x0040,
64925 + GR_ROLE_LEARN = 0x0080,
64926 + GR_ROLE_TPE = 0x0100,
64927 + GR_ROLE_DOMAIN = 0x0200,
64928 + GR_ROLE_PAM = 0x0400,
64929 + GR_ROLE_PERSIST = 0x0800
64930 +};
64931 +
64932 +/* ACL Subject and Object mode flags */
64933 +enum {
64934 + GR_DELETED = 0x80000000
64935 +};
64936 +
64937 +/* ACL Object-only mode flags */
64938 +enum {
64939 + GR_READ = 0x00000001,
64940 + GR_APPEND = 0x00000002,
64941 + GR_WRITE = 0x00000004,
64942 + GR_EXEC = 0x00000008,
64943 + GR_FIND = 0x00000010,
64944 + GR_INHERIT = 0x00000020,
64945 + GR_SETID = 0x00000040,
64946 + GR_CREATE = 0x00000080,
64947 + GR_DELETE = 0x00000100,
64948 + GR_LINK = 0x00000200,
64949 + GR_AUDIT_READ = 0x00000400,
64950 + GR_AUDIT_APPEND = 0x00000800,
64951 + GR_AUDIT_WRITE = 0x00001000,
64952 + GR_AUDIT_EXEC = 0x00002000,
64953 + GR_AUDIT_FIND = 0x00004000,
64954 + GR_AUDIT_INHERIT= 0x00008000,
64955 + GR_AUDIT_SETID = 0x00010000,
64956 + GR_AUDIT_CREATE = 0x00020000,
64957 + GR_AUDIT_DELETE = 0x00040000,
64958 + GR_AUDIT_LINK = 0x00080000,
64959 + GR_PTRACERD = 0x00100000,
64960 + GR_NOPTRACE = 0x00200000,
64961 + GR_SUPPRESS = 0x00400000,
64962 + GR_NOLEARN = 0x00800000,
64963 + GR_INIT_TRANSFER= 0x01000000
64964 +};
64965 +
64966 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
64967 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
64968 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
64969 +
64970 +/* ACL subject-only mode flags */
64971 +enum {
64972 + GR_KILL = 0x00000001,
64973 + GR_VIEW = 0x00000002,
64974 + GR_PROTECTED = 0x00000004,
64975 + GR_LEARN = 0x00000008,
64976 + GR_OVERRIDE = 0x00000010,
64977 + /* just a placeholder, this mode is only used in userspace */
64978 + GR_DUMMY = 0x00000020,
64979 + GR_PROTSHM = 0x00000040,
64980 + GR_KILLPROC = 0x00000080,
64981 + GR_KILLIPPROC = 0x00000100,
64982 + /* just a placeholder, this mode is only used in userspace */
64983 + GR_NOTROJAN = 0x00000200,
64984 + GR_PROTPROCFD = 0x00000400,
64985 + GR_PROCACCT = 0x00000800,
64986 + GR_RELAXPTRACE = 0x00001000,
64987 + //GR_NESTED = 0x00002000,
64988 + GR_INHERITLEARN = 0x00004000,
64989 + GR_PROCFIND = 0x00008000,
64990 + GR_POVERRIDE = 0x00010000,
64991 + GR_KERNELAUTH = 0x00020000,
64992 + GR_ATSECURE = 0x00040000,
64993 + GR_SHMEXEC = 0x00080000
64994 +};
64995 +
64996 +enum {
64997 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
64998 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
64999 + GR_PAX_ENABLE_MPROTECT = 0x0004,
65000 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
65001 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
65002 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
65003 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
65004 + GR_PAX_DISABLE_MPROTECT = 0x0400,
65005 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
65006 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
65007 +};
65008 +
65009 +enum {
65010 + GR_ID_USER = 0x01,
65011 + GR_ID_GROUP = 0x02,
65012 +};
65013 +
65014 +enum {
65015 + GR_ID_ALLOW = 0x01,
65016 + GR_ID_DENY = 0x02,
65017 +};
65018 +
65019 +#define GR_CRASH_RES 31
65020 +#define GR_UIDTABLE_MAX 500
65021 +
65022 +/* begin resource learning section */
65023 +enum {
65024 + GR_RLIM_CPU_BUMP = 60,
65025 + GR_RLIM_FSIZE_BUMP = 50000,
65026 + GR_RLIM_DATA_BUMP = 10000,
65027 + GR_RLIM_STACK_BUMP = 1000,
65028 + GR_RLIM_CORE_BUMP = 10000,
65029 + GR_RLIM_RSS_BUMP = 500000,
65030 + GR_RLIM_NPROC_BUMP = 1,
65031 + GR_RLIM_NOFILE_BUMP = 5,
65032 + GR_RLIM_MEMLOCK_BUMP = 50000,
65033 + GR_RLIM_AS_BUMP = 500000,
65034 + GR_RLIM_LOCKS_BUMP = 2,
65035 + GR_RLIM_SIGPENDING_BUMP = 5,
65036 + GR_RLIM_MSGQUEUE_BUMP = 10000,
65037 + GR_RLIM_NICE_BUMP = 1,
65038 + GR_RLIM_RTPRIO_BUMP = 1,
65039 + GR_RLIM_RTTIME_BUMP = 1000000
65040 +};
65041 +
65042 +#endif
65043 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
65044 new file mode 100644
65045 index 0000000..baa6e96
65046 --- /dev/null
65047 +++ b/include/linux/grinternal.h
65048 @@ -0,0 +1,215 @@
65049 +#ifndef __GRINTERNAL_H
65050 +#define __GRINTERNAL_H
65051 +
65052 +#ifdef CONFIG_GRKERNSEC
65053 +
65054 +#include <linux/fs.h>
65055 +#include <linux/mnt_namespace.h>
65056 +#include <linux/nsproxy.h>
65057 +#include <linux/gracl.h>
65058 +#include <linux/grdefs.h>
65059 +#include <linux/grmsg.h>
65060 +
65061 +void gr_add_learn_entry(const char *fmt, ...)
65062 + __attribute__ ((format (printf, 1, 2)));
65063 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
65064 + const struct vfsmount *mnt);
65065 +__u32 gr_check_create(const struct dentry *new_dentry,
65066 + const struct dentry *parent,
65067 + const struct vfsmount *mnt, const __u32 mode);
65068 +int gr_check_protected_task(const struct task_struct *task);
65069 +__u32 to_gr_audit(const __u32 reqmode);
65070 +int gr_set_acls(const int type);
65071 +int gr_apply_subject_to_task(struct task_struct *task);
65072 +int gr_acl_is_enabled(void);
65073 +char gr_roletype_to_char(void);
65074 +
65075 +void gr_handle_alertkill(struct task_struct *task);
65076 +char *gr_to_filename(const struct dentry *dentry,
65077 + const struct vfsmount *mnt);
65078 +char *gr_to_filename1(const struct dentry *dentry,
65079 + const struct vfsmount *mnt);
65080 +char *gr_to_filename2(const struct dentry *dentry,
65081 + const struct vfsmount *mnt);
65082 +char *gr_to_filename3(const struct dentry *dentry,
65083 + const struct vfsmount *mnt);
65084 +
65085 +extern int grsec_enable_ptrace_readexec;
65086 +extern int grsec_enable_harden_ptrace;
65087 +extern int grsec_enable_link;
65088 +extern int grsec_enable_fifo;
65089 +extern int grsec_enable_execve;
65090 +extern int grsec_enable_shm;
65091 +extern int grsec_enable_execlog;
65092 +extern int grsec_enable_signal;
65093 +extern int grsec_enable_audit_ptrace;
65094 +extern int grsec_enable_forkfail;
65095 +extern int grsec_enable_time;
65096 +extern int grsec_enable_rofs;
65097 +extern int grsec_enable_chroot_shmat;
65098 +extern int grsec_enable_chroot_mount;
65099 +extern int grsec_enable_chroot_double;
65100 +extern int grsec_enable_chroot_pivot;
65101 +extern int grsec_enable_chroot_chdir;
65102 +extern int grsec_enable_chroot_chmod;
65103 +extern int grsec_enable_chroot_mknod;
65104 +extern int grsec_enable_chroot_fchdir;
65105 +extern int grsec_enable_chroot_nice;
65106 +extern int grsec_enable_chroot_execlog;
65107 +extern int grsec_enable_chroot_caps;
65108 +extern int grsec_enable_chroot_sysctl;
65109 +extern int grsec_enable_chroot_unix;
65110 +extern int grsec_enable_symlinkown;
65111 +extern int grsec_symlinkown_gid;
65112 +extern int grsec_enable_tpe;
65113 +extern int grsec_tpe_gid;
65114 +extern int grsec_enable_tpe_all;
65115 +extern int grsec_enable_tpe_invert;
65116 +extern int grsec_enable_socket_all;
65117 +extern int grsec_socket_all_gid;
65118 +extern int grsec_enable_socket_client;
65119 +extern int grsec_socket_client_gid;
65120 +extern int grsec_enable_socket_server;
65121 +extern int grsec_socket_server_gid;
65122 +extern int grsec_audit_gid;
65123 +extern int grsec_enable_group;
65124 +extern int grsec_enable_audit_textrel;
65125 +extern int grsec_enable_log_rwxmaps;
65126 +extern int grsec_enable_mount;
65127 +extern int grsec_enable_chdir;
65128 +extern int grsec_resource_logging;
65129 +extern int grsec_enable_blackhole;
65130 +extern int grsec_lastack_retries;
65131 +extern int grsec_enable_brute;
65132 +extern int grsec_lock;
65133 +
65134 +extern spinlock_t grsec_alert_lock;
65135 +extern unsigned long grsec_alert_wtime;
65136 +extern unsigned long grsec_alert_fyet;
65137 +
65138 +extern spinlock_t grsec_audit_lock;
65139 +
65140 +extern rwlock_t grsec_exec_file_lock;
65141 +
65142 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
65143 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
65144 + (tsk)->exec_file->f_vfsmnt) : "/")
65145 +
65146 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
65147 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
65148 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65149 +
65150 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
65151 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
65152 + (tsk)->exec_file->f_vfsmnt) : "/")
65153 +
65154 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
65155 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
65156 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
65157 +
65158 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
65159 +
65160 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
65161 +
65162 +#define GR_CHROOT_CAPS {{ \
65163 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
65164 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
65165 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
65166 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
65167 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
65168 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
65169 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
65170 +
65171 +#define security_learn(normal_msg,args...) \
65172 +({ \
65173 + read_lock(&grsec_exec_file_lock); \
65174 + gr_add_learn_entry(normal_msg "\n", ## args); \
65175 + read_unlock(&grsec_exec_file_lock); \
65176 +})
65177 +
65178 +enum {
65179 + GR_DO_AUDIT,
65180 + GR_DONT_AUDIT,
65181 + /* used for non-audit messages that we shouldn't kill the task on */
65182 + GR_DONT_AUDIT_GOOD
65183 +};
65184 +
65185 +enum {
65186 + GR_TTYSNIFF,
65187 + GR_RBAC,
65188 + GR_RBAC_STR,
65189 + GR_STR_RBAC,
65190 + GR_RBAC_MODE2,
65191 + GR_RBAC_MODE3,
65192 + GR_FILENAME,
65193 + GR_SYSCTL_HIDDEN,
65194 + GR_NOARGS,
65195 + GR_ONE_INT,
65196 + GR_ONE_INT_TWO_STR,
65197 + GR_ONE_STR,
65198 + GR_STR_INT,
65199 + GR_TWO_STR_INT,
65200 + GR_TWO_INT,
65201 + GR_TWO_U64,
65202 + GR_THREE_INT,
65203 + GR_FIVE_INT_TWO_STR,
65204 + GR_TWO_STR,
65205 + GR_THREE_STR,
65206 + GR_FOUR_STR,
65207 + GR_STR_FILENAME,
65208 + GR_FILENAME_STR,
65209 + GR_FILENAME_TWO_INT,
65210 + GR_FILENAME_TWO_INT_STR,
65211 + GR_TEXTREL,
65212 + GR_PTRACE,
65213 + GR_RESOURCE,
65214 + GR_CAP,
65215 + GR_SIG,
65216 + GR_SIG2,
65217 + GR_CRASH1,
65218 + GR_CRASH2,
65219 + GR_PSACCT,
65220 + GR_RWXMAP
65221 +};
65222 +
65223 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
65224 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
65225 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
65226 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
65227 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
65228 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
65229 +#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)
65230 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
65231 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
65232 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
65233 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
65234 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
65235 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
65236 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
65237 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
65238 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
65239 +#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)
65240 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
65241 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
65242 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
65243 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
65244 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
65245 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
65246 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
65247 +#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)
65248 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
65249 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
65250 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
65251 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
65252 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
65253 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
65254 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
65255 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
65256 +#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)
65257 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
65258 +
65259 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
65260 +
65261 +#endif
65262 +
65263 +#endif
65264 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
65265 new file mode 100644
65266 index 0000000..2bd4c8d
65267 --- /dev/null
65268 +++ b/include/linux/grmsg.h
65269 @@ -0,0 +1,111 @@
65270 +#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"
65271 +#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"
65272 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
65273 +#define GR_STOPMOD_MSG "denied modification of module state by "
65274 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
65275 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
65276 +#define GR_IOPERM_MSG "denied use of ioperm() by "
65277 +#define GR_IOPL_MSG "denied use of iopl() by "
65278 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
65279 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
65280 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
65281 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
65282 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
65283 +#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"
65284 +#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"
65285 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
65286 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
65287 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
65288 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
65289 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
65290 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
65291 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
65292 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
65293 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
65294 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
65295 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
65296 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
65297 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
65298 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
65299 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
65300 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
65301 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
65302 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
65303 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
65304 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
65305 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
65306 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
65307 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
65308 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
65309 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
65310 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
65311 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
65312 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
65313 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
65314 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
65315 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
65316 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
65317 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
65318 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
65319 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
65320 +#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"
65321 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
65322 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
65323 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
65324 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
65325 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
65326 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
65327 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
65328 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
65329 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
65330 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
65331 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
65332 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
65333 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
65334 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
65335 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
65336 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
65337 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
65338 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
65339 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
65340 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
65341 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
65342 +#define GR_NICE_CHROOT_MSG "denied priority change by "
65343 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
65344 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
65345 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
65346 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
65347 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
65348 +#define GR_TIME_MSG "time set by "
65349 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
65350 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
65351 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
65352 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
65353 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
65354 +#define GR_BIND_MSG "denied bind() by "
65355 +#define GR_CONNECT_MSG "denied connect() by "
65356 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
65357 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
65358 +#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"
65359 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
65360 +#define GR_CAP_ACL_MSG "use of %s denied for "
65361 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
65362 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
65363 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
65364 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
65365 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
65366 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
65367 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
65368 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
65369 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
65370 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
65371 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
65372 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
65373 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
65374 +#define GR_VM86_MSG "denied use of vm86 by "
65375 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
65376 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
65377 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
65378 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
65379 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
65380 +#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 "
65381 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
65382 new file mode 100644
65383 index 0000000..c5e5913
65384 --- /dev/null
65385 +++ b/include/linux/grsecurity.h
65386 @@ -0,0 +1,257 @@
65387 +#ifndef GR_SECURITY_H
65388 +#define GR_SECURITY_H
65389 +#include <linux/fs.h>
65390 +#include <linux/fs_struct.h>
65391 +#include <linux/binfmts.h>
65392 +#include <linux/gracl.h>
65393 +
65394 +/* notify of brain-dead configs */
65395 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65396 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
65397 +#endif
65398 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
65399 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
65400 +#endif
65401 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
65402 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
65403 +#endif
65404 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
65405 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
65406 +#endif
65407 +
65408 +#include <linux/compat.h>
65409 +
65410 +struct user_arg_ptr {
65411 +#ifdef CONFIG_COMPAT
65412 + bool is_compat;
65413 +#endif
65414 + union {
65415 + const char __user *const __user *native;
65416 +#ifdef CONFIG_COMPAT
65417 + const compat_uptr_t __user *compat;
65418 +#endif
65419 + } ptr;
65420 +};
65421 +
65422 +void gr_handle_brute_attach(unsigned long mm_flags);
65423 +void gr_handle_brute_check(void);
65424 +void gr_handle_kernel_exploit(void);
65425 +int gr_process_user_ban(void);
65426 +
65427 +char gr_roletype_to_char(void);
65428 +
65429 +int gr_acl_enable_at_secure(void);
65430 +
65431 +int gr_check_user_change(int real, int effective, int fs);
65432 +int gr_check_group_change(int real, int effective, int fs);
65433 +
65434 +void gr_del_task_from_ip_table(struct task_struct *p);
65435 +
65436 +int gr_pid_is_chrooted(struct task_struct *p);
65437 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
65438 +int gr_handle_chroot_nice(void);
65439 +int gr_handle_chroot_sysctl(const int op);
65440 +int gr_handle_chroot_setpriority(struct task_struct *p,
65441 + const int niceval);
65442 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
65443 +int gr_handle_chroot_chroot(const struct dentry *dentry,
65444 + const struct vfsmount *mnt);
65445 +void gr_handle_chroot_chdir(struct path *path);
65446 +int gr_handle_chroot_chmod(const struct dentry *dentry,
65447 + const struct vfsmount *mnt, const int mode);
65448 +int gr_handle_chroot_mknod(const struct dentry *dentry,
65449 + const struct vfsmount *mnt, const int mode);
65450 +int gr_handle_chroot_mount(const struct dentry *dentry,
65451 + const struct vfsmount *mnt,
65452 + const char *dev_name);
65453 +int gr_handle_chroot_pivot(void);
65454 +int gr_handle_chroot_unix(const pid_t pid);
65455 +
65456 +int gr_handle_rawio(const struct inode *inode);
65457 +
65458 +void gr_handle_ioperm(void);
65459 +void gr_handle_iopl(void);
65460 +
65461 +umode_t gr_acl_umask(void);
65462 +
65463 +int gr_tpe_allow(const struct file *file);
65464 +
65465 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
65466 +void gr_clear_chroot_entries(struct task_struct *task);
65467 +
65468 +void gr_log_forkfail(const int retval);
65469 +void gr_log_timechange(void);
65470 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
65471 +void gr_log_chdir(const struct dentry *dentry,
65472 + const struct vfsmount *mnt);
65473 +void gr_log_chroot_exec(const struct dentry *dentry,
65474 + const struct vfsmount *mnt);
65475 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
65476 +void gr_log_remount(const char *devname, const int retval);
65477 +void gr_log_unmount(const char *devname, const int retval);
65478 +void gr_log_mount(const char *from, const char *to, const int retval);
65479 +void gr_log_textrel(struct vm_area_struct *vma);
65480 +void gr_log_rwxmmap(struct file *file);
65481 +void gr_log_rwxmprotect(struct file *file);
65482 +
65483 +int gr_handle_follow_link(const struct inode *parent,
65484 + const struct inode *inode,
65485 + const struct dentry *dentry,
65486 + const struct vfsmount *mnt);
65487 +int gr_handle_fifo(const struct dentry *dentry,
65488 + const struct vfsmount *mnt,
65489 + const struct dentry *dir, const int flag,
65490 + const int acc_mode);
65491 +int gr_handle_hardlink(const struct dentry *dentry,
65492 + const struct vfsmount *mnt,
65493 + struct inode *inode,
65494 + const int mode, const struct filename *to);
65495 +
65496 +int gr_is_capable(const int cap);
65497 +int gr_is_capable_nolog(const int cap);
65498 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
65499 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
65500 +
65501 +void gr_copy_label(struct task_struct *tsk);
65502 +void gr_handle_crash(struct task_struct *task, const int sig);
65503 +int gr_handle_signal(const struct task_struct *p, const int sig);
65504 +int gr_check_crash_uid(const uid_t uid);
65505 +int gr_check_protected_task(const struct task_struct *task);
65506 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
65507 +int gr_acl_handle_mmap(const struct file *file,
65508 + const unsigned long prot);
65509 +int gr_acl_handle_mprotect(const struct file *file,
65510 + const unsigned long prot);
65511 +int gr_check_hidden_task(const struct task_struct *tsk);
65512 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
65513 + const struct vfsmount *mnt);
65514 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
65515 + const struct vfsmount *mnt);
65516 +__u32 gr_acl_handle_access(const struct dentry *dentry,
65517 + const struct vfsmount *mnt, const int fmode);
65518 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
65519 + const struct vfsmount *mnt, umode_t *mode);
65520 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
65521 + const struct vfsmount *mnt);
65522 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
65523 + const struct vfsmount *mnt);
65524 +int gr_handle_ptrace(struct task_struct *task, const long request);
65525 +int gr_handle_proc_ptrace(struct task_struct *task);
65526 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
65527 + const struct vfsmount *mnt);
65528 +int gr_check_crash_exec(const struct file *filp);
65529 +int gr_acl_is_enabled(void);
65530 +void gr_set_kernel_label(struct task_struct *task);
65531 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
65532 + const gid_t gid);
65533 +int gr_set_proc_label(const struct dentry *dentry,
65534 + const struct vfsmount *mnt,
65535 + const int unsafe_flags);
65536 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
65537 + const struct vfsmount *mnt);
65538 +__u32 gr_acl_handle_open(const struct dentry *dentry,
65539 + const struct vfsmount *mnt, int acc_mode);
65540 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
65541 + const struct dentry *p_dentry,
65542 + const struct vfsmount *p_mnt,
65543 + int open_flags, int acc_mode, const int imode);
65544 +void gr_handle_create(const struct dentry *dentry,
65545 + const struct vfsmount *mnt);
65546 +void gr_handle_proc_create(const struct dentry *dentry,
65547 + const struct inode *inode);
65548 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
65549 + const struct dentry *parent_dentry,
65550 + const struct vfsmount *parent_mnt,
65551 + const int mode);
65552 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
65553 + const struct dentry *parent_dentry,
65554 + const struct vfsmount *parent_mnt);
65555 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
65556 + const struct vfsmount *mnt);
65557 +void gr_handle_delete(const ino_t ino, const dev_t dev);
65558 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
65559 + const struct vfsmount *mnt);
65560 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
65561 + const struct dentry *parent_dentry,
65562 + const struct vfsmount *parent_mnt,
65563 + const struct filename *from);
65564 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
65565 + const struct dentry *parent_dentry,
65566 + const struct vfsmount *parent_mnt,
65567 + const struct dentry *old_dentry,
65568 + const struct vfsmount *old_mnt, const struct filename *to);
65569 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
65570 +int gr_acl_handle_rename(struct dentry *new_dentry,
65571 + struct dentry *parent_dentry,
65572 + const struct vfsmount *parent_mnt,
65573 + struct dentry *old_dentry,
65574 + struct inode *old_parent_inode,
65575 + struct vfsmount *old_mnt, const struct filename *newname);
65576 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65577 + struct dentry *old_dentry,
65578 + struct dentry *new_dentry,
65579 + struct vfsmount *mnt, const __u8 replace);
65580 +__u32 gr_check_link(const struct dentry *new_dentry,
65581 + const struct dentry *parent_dentry,
65582 + const struct vfsmount *parent_mnt,
65583 + const struct dentry *old_dentry,
65584 + const struct vfsmount *old_mnt);
65585 +int gr_acl_handle_filldir(const struct file *file, const char *name,
65586 + const unsigned int namelen, const ino_t ino);
65587 +
65588 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
65589 + const struct vfsmount *mnt);
65590 +void gr_acl_handle_exit(void);
65591 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
65592 +int gr_acl_handle_procpidmem(const struct task_struct *task);
65593 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
65594 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
65595 +void gr_audit_ptrace(struct task_struct *task);
65596 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
65597 +void gr_put_exec_file(struct task_struct *task);
65598 +
65599 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
65600 +
65601 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
65602 +extern void gr_learn_resource(const struct task_struct *task, const int res,
65603 + const unsigned long wanted, const int gt);
65604 +#else
65605 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
65606 + const unsigned long wanted, const int gt)
65607 +{
65608 +}
65609 +#endif
65610 +
65611 +#ifdef CONFIG_GRKERNSEC_RESLOG
65612 +extern void gr_log_resource(const struct task_struct *task, const int res,
65613 + const unsigned long wanted, const int gt);
65614 +#else
65615 +static inline void gr_log_resource(const struct task_struct *task, const int res,
65616 + const unsigned long wanted, const int gt)
65617 +{
65618 +}
65619 +#endif
65620 +
65621 +#ifdef CONFIG_GRKERNSEC
65622 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
65623 +void gr_handle_vm86(void);
65624 +void gr_handle_mem_readwrite(u64 from, u64 to);
65625 +
65626 +void gr_log_badprocpid(const char *entry);
65627 +
65628 +extern int grsec_enable_dmesg;
65629 +extern int grsec_disable_privio;
65630 +
65631 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
65632 +extern int grsec_proc_gid;
65633 +#endif
65634 +
65635 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65636 +extern int grsec_enable_chroot_findtask;
65637 +#endif
65638 +#ifdef CONFIG_GRKERNSEC_SETXID
65639 +extern int grsec_enable_setxid;
65640 +#endif
65641 +#endif
65642 +
65643 +#endif
65644 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
65645 new file mode 100644
65646 index 0000000..e7ffaaf
65647 --- /dev/null
65648 +++ b/include/linux/grsock.h
65649 @@ -0,0 +1,19 @@
65650 +#ifndef __GRSOCK_H
65651 +#define __GRSOCK_H
65652 +
65653 +extern void gr_attach_curr_ip(const struct sock *sk);
65654 +extern int gr_handle_sock_all(const int family, const int type,
65655 + const int protocol);
65656 +extern int gr_handle_sock_server(const struct sockaddr *sck);
65657 +extern int gr_handle_sock_server_other(const struct sock *sck);
65658 +extern int gr_handle_sock_client(const struct sockaddr *sck);
65659 +extern int gr_search_connect(struct socket * sock,
65660 + struct sockaddr_in * addr);
65661 +extern int gr_search_bind(struct socket * sock,
65662 + struct sockaddr_in * addr);
65663 +extern int gr_search_listen(struct socket * sock);
65664 +extern int gr_search_accept(struct socket * sock);
65665 +extern int gr_search_socket(const int domain, const int type,
65666 + const int protocol);
65667 +
65668 +#endif
65669 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
65670 index ef788b5..ac41b7b 100644
65671 --- a/include/linux/highmem.h
65672 +++ b/include/linux/highmem.h
65673 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
65674 kunmap_atomic(kaddr);
65675 }
65676
65677 +static inline void sanitize_highpage(struct page *page)
65678 +{
65679 + void *kaddr;
65680 + unsigned long flags;
65681 +
65682 + local_irq_save(flags);
65683 + kaddr = kmap_atomic(page);
65684 + clear_page(kaddr);
65685 + kunmap_atomic(kaddr);
65686 + local_irq_restore(flags);
65687 +}
65688 +
65689 static inline void zero_user_segments(struct page *page,
65690 unsigned start1, unsigned end1,
65691 unsigned start2, unsigned end2)
65692 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
65693 index d0c4db7..61b3577 100644
65694 --- a/include/linux/i2c.h
65695 +++ b/include/linux/i2c.h
65696 @@ -369,6 +369,7 @@ struct i2c_algorithm {
65697 /* To determine what the adapter supports */
65698 u32 (*functionality) (struct i2c_adapter *);
65699 };
65700 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
65701
65702 /*
65703 * i2c_adapter is the structure used to identify a physical i2c bus along
65704 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
65705 index d23c3c2..eb63c81 100644
65706 --- a/include/linux/i2o.h
65707 +++ b/include/linux/i2o.h
65708 @@ -565,7 +565,7 @@ struct i2o_controller {
65709 struct i2o_device *exec; /* Executive */
65710 #if BITS_PER_LONG == 64
65711 spinlock_t context_list_lock; /* lock for context_list */
65712 - atomic_t context_list_counter; /* needed for unique contexts */
65713 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
65714 struct list_head context_list; /* list of context id's
65715 and pointers */
65716 #endif
65717 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
65718 index aff7ad8..3942bbd 100644
65719 --- a/include/linux/if_pppox.h
65720 +++ b/include/linux/if_pppox.h
65721 @@ -76,7 +76,7 @@ struct pppox_proto {
65722 int (*ioctl)(struct socket *sock, unsigned int cmd,
65723 unsigned long arg);
65724 struct module *owner;
65725 -};
65726 +} __do_const;
65727
65728 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
65729 extern void unregister_pppox_proto(int proto_num);
65730 diff --git a/include/linux/init.h b/include/linux/init.h
65731 index 10ed4f4..8e8490d 100644
65732 --- a/include/linux/init.h
65733 +++ b/include/linux/init.h
65734 @@ -39,9 +39,36 @@
65735 * Also note, that this data cannot be "const".
65736 */
65737
65738 +#ifdef MODULE
65739 +#define add_init_latent_entropy
65740 +#define add_devinit_latent_entropy
65741 +#define add_cpuinit_latent_entropy
65742 +#define add_meminit_latent_entropy
65743 +#else
65744 +#define add_init_latent_entropy __latent_entropy
65745 +
65746 +#ifdef CONFIG_HOTPLUG
65747 +#define add_devinit_latent_entropy
65748 +#else
65749 +#define add_devinit_latent_entropy __latent_entropy
65750 +#endif
65751 +
65752 +#ifdef CONFIG_HOTPLUG_CPU
65753 +#define add_cpuinit_latent_entropy
65754 +#else
65755 +#define add_cpuinit_latent_entropy __latent_entropy
65756 +#endif
65757 +
65758 +#ifdef CONFIG_MEMORY_HOTPLUG
65759 +#define add_meminit_latent_entropy
65760 +#else
65761 +#define add_meminit_latent_entropy __latent_entropy
65762 +#endif
65763 +#endif
65764 +
65765 /* These are for everybody (although not all archs will actually
65766 discard it in modules) */
65767 -#define __init __section(.init.text) __cold notrace
65768 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
65769 #define __initdata __section(.init.data)
65770 #define __initconst __constsection(.init.rodata)
65771 #define __exitdata __section(.exit.data)
65772 @@ -94,7 +121,7 @@
65773 #define __exit __section(.exit.text) __exitused __cold notrace
65774
65775 /* Used for HOTPLUG_CPU */
65776 -#define __cpuinit __section(.cpuinit.text) __cold notrace
65777 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
65778 #define __cpuinitdata __section(.cpuinit.data)
65779 #define __cpuinitconst __constsection(.cpuinit.rodata)
65780 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
65781 @@ -102,7 +129,7 @@
65782 #define __cpuexitconst __constsection(.cpuexit.rodata)
65783
65784 /* Used for MEMORY_HOTPLUG */
65785 -#define __meminit __section(.meminit.text) __cold notrace
65786 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
65787 #define __meminitdata __section(.meminit.data)
65788 #define __meminitconst __constsection(.meminit.rodata)
65789 #define __memexit __section(.memexit.text) __exitused __cold notrace
65790 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
65791 index 6d087c5..401cab8 100644
65792 --- a/include/linux/init_task.h
65793 +++ b/include/linux/init_task.h
65794 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
65795
65796 #define INIT_TASK_COMM "swapper"
65797
65798 +#ifdef CONFIG_X86
65799 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
65800 +#else
65801 +#define INIT_TASK_THREAD_INFO
65802 +#endif
65803 +
65804 /*
65805 * INIT_TASK is used to set up the first task table, touch at
65806 * your own risk!. Base=0, limit=0x1fffff (=2MB)
65807 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
65808 RCU_POINTER_INITIALIZER(cred, &init_cred), \
65809 .comm = INIT_TASK_COMM, \
65810 .thread = INIT_THREAD, \
65811 + INIT_TASK_THREAD_INFO \
65812 .fs = &init_fs, \
65813 .files = &init_files, \
65814 .signal = &init_signals, \
65815 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
65816 index 5fa5afe..ac55b25 100644
65817 --- a/include/linux/interrupt.h
65818 +++ b/include/linux/interrupt.h
65819 @@ -430,7 +430,7 @@ enum
65820 /* map softirq index to softirq name. update 'softirq_to_name' in
65821 * kernel/softirq.c when adding a new softirq.
65822 */
65823 -extern char *softirq_to_name[NR_SOFTIRQS];
65824 +extern const char * const softirq_to_name[NR_SOFTIRQS];
65825
65826 /* softirq mask and active fields moved to irq_cpustat_t in
65827 * asm/hardirq.h to get better cache usage. KAO
65828 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
65829
65830 struct softirq_action
65831 {
65832 - void (*action)(struct softirq_action *);
65833 -};
65834 + void (*action)(void);
65835 +} __no_const;
65836
65837 asmlinkage void do_softirq(void);
65838 asmlinkage void __do_softirq(void);
65839 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
65840 +extern void open_softirq(int nr, void (*action)(void));
65841 extern void softirq_init(void);
65842 extern void __raise_softirq_irqoff(unsigned int nr);
65843
65844 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
65845 index 6883e19..06992b1 100644
65846 --- a/include/linux/kallsyms.h
65847 +++ b/include/linux/kallsyms.h
65848 @@ -15,7 +15,8 @@
65849
65850 struct module;
65851
65852 -#ifdef CONFIG_KALLSYMS
65853 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
65854 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65855 /* Lookup the address for a symbol. Returns 0 if not found. */
65856 unsigned long kallsyms_lookup_name(const char *name);
65857
65858 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
65859 /* Stupid that this does nothing, but I didn't create this mess. */
65860 #define __print_symbol(fmt, addr)
65861 #endif /*CONFIG_KALLSYMS*/
65862 +#else /* when included by kallsyms.c, vsnprintf.c, or
65863 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
65864 +extern void __print_symbol(const char *fmt, unsigned long address);
65865 +extern int sprint_backtrace(char *buffer, unsigned long address);
65866 +extern int sprint_symbol(char *buffer, unsigned long address);
65867 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
65868 +const char *kallsyms_lookup(unsigned long addr,
65869 + unsigned long *symbolsize,
65870 + unsigned long *offset,
65871 + char **modname, char *namebuf);
65872 +#endif
65873
65874 /* This macro allows us to keep printk typechecking */
65875 static __printf(1, 2)
65876 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
65877 index 4dff0c6..1ca9b72 100644
65878 --- a/include/linux/kgdb.h
65879 +++ b/include/linux/kgdb.h
65880 @@ -53,7 +53,7 @@ extern int kgdb_connected;
65881 extern int kgdb_io_module_registered;
65882
65883 extern atomic_t kgdb_setting_breakpoint;
65884 -extern atomic_t kgdb_cpu_doing_single_step;
65885 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
65886
65887 extern struct task_struct *kgdb_usethread;
65888 extern struct task_struct *kgdb_contthread;
65889 @@ -255,7 +255,7 @@ struct kgdb_arch {
65890 void (*correct_hw_break)(void);
65891
65892 void (*enable_nmi)(bool on);
65893 -};
65894 +} __do_const;
65895
65896 /**
65897 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
65898 @@ -280,7 +280,7 @@ struct kgdb_io {
65899 void (*pre_exception) (void);
65900 void (*post_exception) (void);
65901 int is_console;
65902 -};
65903 +} __do_const;
65904
65905 extern struct kgdb_arch arch_kgdb_ops;
65906
65907 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
65908 index 5398d58..5883a34 100644
65909 --- a/include/linux/kmod.h
65910 +++ b/include/linux/kmod.h
65911 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
65912 * usually useless though. */
65913 extern __printf(2, 3)
65914 int __request_module(bool wait, const char *name, ...);
65915 +extern __printf(3, 4)
65916 +int ___request_module(bool wait, char *param_name, const char *name, ...);
65917 #define request_module(mod...) __request_module(true, mod)
65918 #define request_module_nowait(mod...) __request_module(false, mod)
65919 #define try_then_request_module(x, mod...) \
65920 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
65921 index 939b112..90b7f44 100644
65922 --- a/include/linux/kobject.h
65923 +++ b/include/linux/kobject.h
65924 @@ -111,7 +111,7 @@ struct kobj_type {
65925 struct attribute **default_attrs;
65926 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
65927 const void *(*namespace)(struct kobject *kobj);
65928 -};
65929 +} __do_const;
65930
65931 struct kobj_uevent_env {
65932 char *envp[UEVENT_NUM_ENVP];
65933 diff --git a/include/linux/kref.h b/include/linux/kref.h
65934 index 4972e6e..de4d19b 100644
65935 --- a/include/linux/kref.h
65936 +++ b/include/linux/kref.h
65937 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
65938 static inline int kref_sub(struct kref *kref, unsigned int count,
65939 void (*release)(struct kref *kref))
65940 {
65941 - WARN_ON(release == NULL);
65942 + BUG_ON(release == NULL);
65943
65944 if (atomic_sub_and_test((int) count, &kref->refcount)) {
65945 release(kref);
65946 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
65947 index 2c497ab..afe32f5 100644
65948 --- a/include/linux/kvm_host.h
65949 +++ b/include/linux/kvm_host.h
65950 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
65951 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
65952 void vcpu_put(struct kvm_vcpu *vcpu);
65953
65954 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65955 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
65956 struct module *module);
65957 void kvm_exit(void);
65958
65959 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
65960 struct kvm_guest_debug *dbg);
65961 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
65962
65963 -int kvm_arch_init(void *opaque);
65964 +int kvm_arch_init(const void *opaque);
65965 void kvm_arch_exit(void);
65966
65967 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
65968 diff --git a/include/linux/libata.h b/include/linux/libata.h
65969 index 649e5f8..ead5194 100644
65970 --- a/include/linux/libata.h
65971 +++ b/include/linux/libata.h
65972 @@ -915,7 +915,7 @@ struct ata_port_operations {
65973 * fields must be pointers.
65974 */
65975 const struct ata_port_operations *inherits;
65976 -};
65977 +} __do_const;
65978
65979 struct ata_port_info {
65980 unsigned long flags;
65981 diff --git a/include/linux/list.h b/include/linux/list.h
65982 index cc6d2aa..71febca 100644
65983 --- a/include/linux/list.h
65984 +++ b/include/linux/list.h
65985 @@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
65986 extern void list_del(struct list_head *entry);
65987 #endif
65988
65989 +extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
65990 +extern void pax_list_del(struct list_head *entry);
65991 +
65992 /**
65993 * list_replace - replace old entry by new one
65994 * @old : the element to be replaced
65995 diff --git a/include/linux/mm.h b/include/linux/mm.h
65996 index 66e2f7c..ea88001 100644
65997 --- a/include/linux/mm.h
65998 +++ b/include/linux/mm.h
65999 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
66000 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
66001 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
66002 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
66003 +
66004 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
66005 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
66006 +#endif
66007 +
66008 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
66009
66010 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
66011 @@ -231,6 +236,7 @@ struct vm_operations_struct {
66012 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
66013 unsigned long size, pgoff_t pgoff);
66014 };
66015 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
66016
66017 struct mmu_gather;
66018 struct inode;
66019 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
66020 int set_page_dirty_lock(struct page *page);
66021 int clear_page_dirty_for_io(struct page *page);
66022
66023 -/* Is the vma a continuation of the stack vma above it? */
66024 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
66025 -{
66026 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
66027 -}
66028 -
66029 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
66030 - unsigned long addr)
66031 -{
66032 - return (vma->vm_flags & VM_GROWSDOWN) &&
66033 - (vma->vm_start == addr) &&
66034 - !vma_growsdown(vma->vm_prev, addr);
66035 -}
66036 -
66037 -/* Is the vma a continuation of the stack vma below it? */
66038 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
66039 -{
66040 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
66041 -}
66042 -
66043 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
66044 - unsigned long addr)
66045 -{
66046 - return (vma->vm_flags & VM_GROWSUP) &&
66047 - (vma->vm_end == addr) &&
66048 - !vma_growsup(vma->vm_next, addr);
66049 -}
66050 -
66051 extern pid_t
66052 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
66053
66054 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
66055 }
66056 #endif
66057
66058 +#ifdef CONFIG_MMU
66059 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
66060 +#else
66061 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
66062 +{
66063 + return __pgprot(0);
66064 +}
66065 +#endif
66066 +
66067 int vma_wants_writenotify(struct vm_area_struct *vma);
66068
66069 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
66070 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
66071 {
66072 return 0;
66073 }
66074 +
66075 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
66076 + unsigned long address)
66077 +{
66078 + return 0;
66079 +}
66080 #else
66081 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66082 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
66083 #endif
66084
66085 #ifdef __PAGETABLE_PMD_FOLDED
66086 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
66087 {
66088 return 0;
66089 }
66090 +
66091 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
66092 + unsigned long address)
66093 +{
66094 + return 0;
66095 +}
66096 #else
66097 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
66098 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
66099 #endif
66100
66101 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
66102 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
66103 NULL: pud_offset(pgd, address);
66104 }
66105
66106 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
66107 +{
66108 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
66109 + NULL: pud_offset(pgd, address);
66110 +}
66111 +
66112 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
66113 {
66114 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
66115 NULL: pmd_offset(pud, address);
66116 }
66117 +
66118 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
66119 +{
66120 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
66121 + NULL: pmd_offset(pud, address);
66122 +}
66123 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
66124
66125 #if USE_SPLIT_PTLOCKS
66126 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
66127 unsigned long, unsigned long,
66128 unsigned long, unsigned long);
66129 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
66130 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
66131
66132 /* These take the mm semaphore themselves */
66133 extern unsigned long vm_brk(unsigned long, unsigned long);
66134 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
66135 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
66136 struct vm_area_struct **pprev);
66137
66138 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
66139 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
66140 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
66141 +
66142 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
66143 NULL if none. Assume start_addr < end_addr. */
66144 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
66145 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
66146 return vma;
66147 }
66148
66149 -#ifdef CONFIG_MMU
66150 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
66151 -#else
66152 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
66153 -{
66154 - return __pgprot(0);
66155 -}
66156 -#endif
66157 -
66158 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
66159 unsigned long change_prot_numa(struct vm_area_struct *vma,
66160 unsigned long start, unsigned long end);
66161 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
66162 extern int sysctl_memory_failure_early_kill;
66163 extern int sysctl_memory_failure_recovery;
66164 extern void shake_page(struct page *p, int access);
66165 -extern atomic_long_t mce_bad_pages;
66166 +extern atomic_long_unchecked_t mce_bad_pages;
66167 extern int soft_offline_page(struct page *page, int flags);
66168
66169 extern void dump_page(struct page *page);
66170 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
66171 static inline bool page_is_guard(struct page *page) { return false; }
66172 #endif /* CONFIG_DEBUG_PAGEALLOC */
66173
66174 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
66175 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
66176 +#else
66177 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
66178 +#endif
66179 +
66180 #endif /* __KERNEL__ */
66181 #endif /* _LINUX_MM_H */
66182 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
66183 index f8f5162..6276a36 100644
66184 --- a/include/linux/mm_types.h
66185 +++ b/include/linux/mm_types.h
66186 @@ -288,6 +288,8 @@ struct vm_area_struct {
66187 #ifdef CONFIG_NUMA
66188 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
66189 #endif
66190 +
66191 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
66192 };
66193
66194 struct core_thread {
66195 @@ -362,7 +364,7 @@ struct mm_struct {
66196 unsigned long def_flags;
66197 unsigned long nr_ptes; /* Page table pages */
66198 unsigned long start_code, end_code, start_data, end_data;
66199 - unsigned long start_brk, brk, start_stack;
66200 + unsigned long brk_gap, start_brk, brk, start_stack;
66201 unsigned long arg_start, arg_end, env_start, env_end;
66202
66203 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
66204 @@ -436,6 +438,24 @@ struct mm_struct {
66205 int first_nid;
66206 #endif
66207 struct uprobes_state uprobes_state;
66208 +
66209 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
66210 + unsigned long pax_flags;
66211 +#endif
66212 +
66213 +#ifdef CONFIG_PAX_DLRESOLVE
66214 + unsigned long call_dl_resolve;
66215 +#endif
66216 +
66217 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
66218 + unsigned long call_syscall;
66219 +#endif
66220 +
66221 +#ifdef CONFIG_PAX_ASLR
66222 + unsigned long delta_mmap; /* randomized offset */
66223 + unsigned long delta_stack; /* randomized offset */
66224 +#endif
66225 +
66226 };
66227
66228 /* first nid will either be a valid NID or one of these values */
66229 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
66230 index c5d5278..f0b68c8 100644
66231 --- a/include/linux/mmiotrace.h
66232 +++ b/include/linux/mmiotrace.h
66233 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
66234 /* Called from ioremap.c */
66235 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
66236 void __iomem *addr);
66237 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
66238 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
66239
66240 /* For anyone to insert markers. Remember trailing newline. */
66241 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
66242 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
66243 {
66244 }
66245
66246 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
66247 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
66248 {
66249 }
66250
66251 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
66252 index 73b64a3..6562925 100644
66253 --- a/include/linux/mmzone.h
66254 +++ b/include/linux/mmzone.h
66255 @@ -412,7 +412,7 @@ struct zone {
66256 unsigned long flags; /* zone flags, see below */
66257
66258 /* Zone statistics */
66259 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66260 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66261
66262 /*
66263 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
66264 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
66265 index fed3def..7cc3f93 100644
66266 --- a/include/linux/mod_devicetable.h
66267 +++ b/include/linux/mod_devicetable.h
66268 @@ -12,7 +12,7 @@
66269 typedef unsigned long kernel_ulong_t;
66270 #endif
66271
66272 -#define PCI_ANY_ID (~0)
66273 +#define PCI_ANY_ID ((__u16)~0)
66274
66275 struct pci_device_id {
66276 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
66277 @@ -139,7 +139,7 @@ struct usb_device_id {
66278 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
66279 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
66280
66281 -#define HID_ANY_ID (~0)
66282 +#define HID_ANY_ID (~0U)
66283 #define HID_BUS_ANY 0xffff
66284 #define HID_GROUP_ANY 0x0000
66285
66286 diff --git a/include/linux/module.h b/include/linux/module.h
66287 index 1375ee3..d631af0 100644
66288 --- a/include/linux/module.h
66289 +++ b/include/linux/module.h
66290 @@ -17,9 +17,11 @@
66291 #include <linux/moduleparam.h>
66292 #include <linux/tracepoint.h>
66293 #include <linux/export.h>
66294 +#include <linux/fs.h>
66295
66296 #include <linux/percpu.h>
66297 #include <asm/module.h>
66298 +#include <asm/pgtable.h>
66299
66300 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
66301 #define MODULE_SIG_STRING "~Module signature appended~\n"
66302 @@ -281,19 +283,16 @@ struct module
66303 int (*init)(void);
66304
66305 /* If this is non-NULL, vfree after init() returns */
66306 - void *module_init;
66307 + void *module_init_rx, *module_init_rw;
66308
66309 /* Here is the actual code + data, vfree'd on unload. */
66310 - void *module_core;
66311 + void *module_core_rx, *module_core_rw;
66312
66313 /* Here are the sizes of the init and core sections */
66314 - unsigned int init_size, core_size;
66315 + unsigned int init_size_rw, core_size_rw;
66316
66317 /* The size of the executable code in each section. */
66318 - unsigned int init_text_size, core_text_size;
66319 -
66320 - /* Size of RO sections of the module (text+rodata) */
66321 - unsigned int init_ro_size, core_ro_size;
66322 + unsigned int init_size_rx, core_size_rx;
66323
66324 /* Arch-specific module values */
66325 struct mod_arch_specific arch;
66326 @@ -349,6 +348,10 @@ struct module
66327 #ifdef CONFIG_EVENT_TRACING
66328 struct ftrace_event_call **trace_events;
66329 unsigned int num_trace_events;
66330 + struct file_operations trace_id;
66331 + struct file_operations trace_enable;
66332 + struct file_operations trace_format;
66333 + struct file_operations trace_filter;
66334 #endif
66335 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
66336 unsigned int num_ftrace_callsites;
66337 @@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
66338 bool is_module_percpu_address(unsigned long addr);
66339 bool is_module_text_address(unsigned long addr);
66340
66341 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
66342 +{
66343 +
66344 +#ifdef CONFIG_PAX_KERNEXEC
66345 + if (ktla_ktva(addr) >= (unsigned long)start &&
66346 + ktla_ktva(addr) < (unsigned long)start + size)
66347 + return 1;
66348 +#endif
66349 +
66350 + return ((void *)addr >= start && (void *)addr < start + size);
66351 +}
66352 +
66353 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
66354 +{
66355 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
66356 +}
66357 +
66358 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
66359 +{
66360 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
66361 +}
66362 +
66363 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
66364 +{
66365 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
66366 +}
66367 +
66368 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
66369 +{
66370 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
66371 +}
66372 +
66373 static inline int within_module_core(unsigned long addr, struct module *mod)
66374 {
66375 - return (unsigned long)mod->module_core <= addr &&
66376 - addr < (unsigned long)mod->module_core + mod->core_size;
66377 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
66378 }
66379
66380 static inline int within_module_init(unsigned long addr, struct module *mod)
66381 {
66382 - return (unsigned long)mod->module_init <= addr &&
66383 - addr < (unsigned long)mod->module_init + mod->init_size;
66384 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
66385 }
66386
66387 /* Search for module by name: must hold module_mutex. */
66388 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
66389 index 560ca53..5ee8d73 100644
66390 --- a/include/linux/moduleloader.h
66391 +++ b/include/linux/moduleloader.h
66392 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
66393
66394 /* Allocator used for allocating struct module, core sections and init
66395 sections. Returns NULL on failure. */
66396 -void *module_alloc(unsigned long size);
66397 +void *module_alloc(unsigned long size) __size_overflow(1);
66398 +
66399 +#ifdef CONFIG_PAX_KERNEXEC
66400 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
66401 +#else
66402 +#define module_alloc_exec(x) module_alloc(x)
66403 +#endif
66404
66405 /* Free memory returned from module_alloc. */
66406 void module_free(struct module *mod, void *module_region);
66407
66408 +#ifdef CONFIG_PAX_KERNEXEC
66409 +void module_free_exec(struct module *mod, void *module_region);
66410 +#else
66411 +#define module_free_exec(x, y) module_free((x), (y))
66412 +#endif
66413 +
66414 /*
66415 * Apply the given relocation to the (simplified) ELF. Return -error
66416 * or 0.
66417 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
66418 unsigned int relsec,
66419 struct module *me)
66420 {
66421 +#ifdef CONFIG_MODULES
66422 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66423 +#endif
66424 return -ENOEXEC;
66425 }
66426 #endif
66427 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
66428 unsigned int relsec,
66429 struct module *me)
66430 {
66431 +#ifdef CONFIG_MODULES
66432 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
66433 +#endif
66434 return -ENOEXEC;
66435 }
66436 #endif
66437 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
66438 index 137b419..fe663ec 100644
66439 --- a/include/linux/moduleparam.h
66440 +++ b/include/linux/moduleparam.h
66441 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
66442 * @len is usually just sizeof(string).
66443 */
66444 #define module_param_string(name, string, len, perm) \
66445 - static const struct kparam_string __param_string_##name \
66446 + static const struct kparam_string __param_string_##name __used \
66447 = { len, string }; \
66448 __module_param_call(MODULE_PARAM_PREFIX, name, \
66449 &param_ops_string, \
66450 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
66451 */
66452 #define module_param_array_named(name, array, type, nump, perm) \
66453 param_check_##type(name, &(array)[0]); \
66454 - static const struct kparam_array __param_arr_##name \
66455 + static const struct kparam_array __param_arr_##name __used \
66456 = { .max = ARRAY_SIZE(array), .num = nump, \
66457 .ops = &param_ops_##type, \
66458 .elemsize = sizeof(array[0]), .elem = array }; \
66459 diff --git a/include/linux/namei.h b/include/linux/namei.h
66460 index 5a5ff57..5ae5070 100644
66461 --- a/include/linux/namei.h
66462 +++ b/include/linux/namei.h
66463 @@ -19,7 +19,7 @@ struct nameidata {
66464 unsigned seq;
66465 int last_type;
66466 unsigned depth;
66467 - char *saved_names[MAX_NESTED_LINKS + 1];
66468 + const char *saved_names[MAX_NESTED_LINKS + 1];
66469 };
66470
66471 /*
66472 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
66473
66474 extern void nd_jump_link(struct nameidata *nd, struct path *path);
66475
66476 -static inline void nd_set_link(struct nameidata *nd, char *path)
66477 +static inline void nd_set_link(struct nameidata *nd, const char *path)
66478 {
66479 nd->saved_names[nd->depth] = path;
66480 }
66481
66482 -static inline char *nd_get_link(struct nameidata *nd)
66483 +static inline const char *nd_get_link(const struct nameidata *nd)
66484 {
66485 return nd->saved_names[nd->depth];
66486 }
66487 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
66488 index 9ef07d0..130a5d9 100644
66489 --- a/include/linux/netdevice.h
66490 +++ b/include/linux/netdevice.h
66491 @@ -1012,6 +1012,7 @@ struct net_device_ops {
66492 u32 pid, u32 seq,
66493 struct net_device *dev);
66494 };
66495 +typedef struct net_device_ops __no_const net_device_ops_no_const;
66496
66497 /*
66498 * The DEVICE structure.
66499 @@ -1078,7 +1079,7 @@ struct net_device {
66500 int iflink;
66501
66502 struct net_device_stats stats;
66503 - atomic_long_t rx_dropped; /* dropped packets by core network
66504 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
66505 * Do not use this in drivers.
66506 */
66507
66508 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
66509 index 7958e84..ed74d7a 100644
66510 --- a/include/linux/netfilter/ipset/ip_set.h
66511 +++ b/include/linux/netfilter/ipset/ip_set.h
66512 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
66513 /* Return true if "b" set is the same as "a"
66514 * according to the create set parameters */
66515 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
66516 -};
66517 +} __do_const;
66518
66519 /* The core set type structure */
66520 struct ip_set_type {
66521 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
66522 index 4966dde..7d8ce06 100644
66523 --- a/include/linux/netfilter/nfnetlink.h
66524 +++ b/include/linux/netfilter/nfnetlink.h
66525 @@ -16,7 +16,7 @@ struct nfnl_callback {
66526 const struct nlattr * const cda[]);
66527 const struct nla_policy *policy; /* netlink attribute policy */
66528 const u_int16_t attr_count; /* number of nlattr's */
66529 -};
66530 +} __do_const;
66531
66532 struct nfnetlink_subsystem {
66533 const char *name;
66534 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
66535 new file mode 100644
66536 index 0000000..33f4af8
66537 --- /dev/null
66538 +++ b/include/linux/netfilter/xt_gradm.h
66539 @@ -0,0 +1,9 @@
66540 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
66541 +#define _LINUX_NETFILTER_XT_GRADM_H 1
66542 +
66543 +struct xt_gradm_mtinfo {
66544 + __u16 flags;
66545 + __u16 invflags;
66546 +};
66547 +
66548 +#endif
66549 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
66550 index d65746e..62e72c2 100644
66551 --- a/include/linux/notifier.h
66552 +++ b/include/linux/notifier.h
66553 @@ -51,7 +51,8 @@ struct notifier_block {
66554 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
66555 struct notifier_block __rcu *next;
66556 int priority;
66557 -};
66558 +} __do_const;
66559 +typedef struct notifier_block __no_const notifier_block_no_const;
66560
66561 struct atomic_notifier_head {
66562 spinlock_t lock;
66563 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
66564 index a4c5624..79d6d88 100644
66565 --- a/include/linux/oprofile.h
66566 +++ b/include/linux/oprofile.h
66567 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
66568 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
66569 char const * name, ulong * val);
66570
66571 -/** Create a file for read-only access to an atomic_t. */
66572 +/** Create a file for read-only access to an atomic_unchecked_t. */
66573 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
66574 - char const * name, atomic_t * val);
66575 + char const * name, atomic_unchecked_t * val);
66576
66577 /** create a directory */
66578 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
66579 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
66580 index 6bfb2faa..e5bc5e5 100644
66581 --- a/include/linux/perf_event.h
66582 +++ b/include/linux/perf_event.h
66583 @@ -328,8 +328,8 @@ struct perf_event {
66584
66585 enum perf_event_active_state state;
66586 unsigned int attach_state;
66587 - local64_t count;
66588 - atomic64_t child_count;
66589 + local64_t count; /* PaX: fix it one day */
66590 + atomic64_unchecked_t child_count;
66591
66592 /*
66593 * These are the total time in nanoseconds that the event
66594 @@ -380,8 +380,8 @@ struct perf_event {
66595 * These accumulate total time (in nanoseconds) that children
66596 * events have been enabled and running, respectively.
66597 */
66598 - atomic64_t child_total_time_enabled;
66599 - atomic64_t child_total_time_running;
66600 + atomic64_unchecked_t child_total_time_enabled;
66601 + atomic64_unchecked_t child_total_time_running;
66602
66603 /*
66604 * Protect attach/detach and child_list:
66605 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
66606 */
66607 #define perf_cpu_notifier(fn) \
66608 do { \
66609 - static struct notifier_block fn##_nb __cpuinitdata = \
66610 + static struct notifier_block fn##_nb = \
66611 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
66612 unsigned long cpu = smp_processor_id(); \
66613 unsigned long flags; \
66614 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
66615 index ad1a427..6419649 100644
66616 --- a/include/linux/pipe_fs_i.h
66617 +++ b/include/linux/pipe_fs_i.h
66618 @@ -45,9 +45,9 @@ struct pipe_buffer {
66619 struct pipe_inode_info {
66620 wait_queue_head_t wait;
66621 unsigned int nrbufs, curbuf, buffers;
66622 - unsigned int readers;
66623 - unsigned int writers;
66624 - unsigned int waiting_writers;
66625 + atomic_t readers;
66626 + atomic_t writers;
66627 + atomic_t waiting_writers;
66628 unsigned int r_counter;
66629 unsigned int w_counter;
66630 struct page *tmp_page;
66631 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
66632 index 5f28cae..3d23723 100644
66633 --- a/include/linux/platform_data/usb-ehci-s5p.h
66634 +++ b/include/linux/platform_data/usb-ehci-s5p.h
66635 @@ -14,7 +14,7 @@
66636 struct s5p_ehci_platdata {
66637 int (*phy_init)(struct platform_device *pdev, int type);
66638 int (*phy_exit)(struct platform_device *pdev, int type);
66639 -};
66640 +} __no_const;
66641
66642 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
66643
66644 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
66645 index f271860..6b3bec5 100644
66646 --- a/include/linux/pm_runtime.h
66647 +++ b/include/linux/pm_runtime.h
66648 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
66649
66650 static inline void pm_runtime_mark_last_busy(struct device *dev)
66651 {
66652 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
66653 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
66654 }
66655
66656 #else /* !CONFIG_PM_RUNTIME */
66657 diff --git a/include/linux/poison.h b/include/linux/poison.h
66658 index 2110a81..13a11bb 100644
66659 --- a/include/linux/poison.h
66660 +++ b/include/linux/poison.h
66661 @@ -19,8 +19,8 @@
66662 * under normal circumstances, used to verify that nobody uses
66663 * non-initialized list entries.
66664 */
66665 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
66666 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
66667 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
66668 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
66669
66670 /********** include/linux/timer.h **********/
66671 /*
66672 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
66673 index c0f44c2..1572583 100644
66674 --- a/include/linux/power/smartreflex.h
66675 +++ b/include/linux/power/smartreflex.h
66676 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
66677 int (*notify)(struct omap_sr *sr, u32 status);
66678 u8 notify_flags;
66679 u8 class_type;
66680 -};
66681 +} __do_const;
66682
66683 /**
66684 * struct omap_sr_nvalue_table - Smartreflex n-target value info
66685 diff --git a/include/linux/printk.h b/include/linux/printk.h
66686 index 9afc01e..92c32e8 100644
66687 --- a/include/linux/printk.h
66688 +++ b/include/linux/printk.h
66689 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
66690 extern int printk_needs_cpu(int cpu);
66691 extern void printk_tick(void);
66692
66693 +extern int kptr_restrict;
66694 +
66695 #ifdef CONFIG_PRINTK
66696 asmlinkage __printf(5, 0)
66697 int vprintk_emit(int facility, int level,
66698 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
66699
66700 extern int printk_delay_msec;
66701 extern int dmesg_restrict;
66702 -extern int kptr_restrict;
66703
66704 void log_buf_kexec_setup(void);
66705 void __init setup_log_buf(int early);
66706 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
66707 index 32676b3..8f7a182 100644
66708 --- a/include/linux/proc_fs.h
66709 +++ b/include/linux/proc_fs.h
66710 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
66711 return proc_create_data(name, mode, parent, proc_fops, NULL);
66712 }
66713
66714 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
66715 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
66716 +{
66717 +#ifdef CONFIG_GRKERNSEC_PROC_USER
66718 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
66719 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66720 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
66721 +#else
66722 + return proc_create_data(name, mode, parent, proc_fops, NULL);
66723 +#endif
66724 +}
66725 +
66726 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
66727 umode_t mode, struct proc_dir_entry *base,
66728 read_proc_t *read_proc, void * data)
66729 diff --git a/include/linux/random.h b/include/linux/random.h
66730 index d984608..d6f0042 100644
66731 --- a/include/linux/random.h
66732 +++ b/include/linux/random.h
66733 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
66734 u32 prandom_u32_state(struct rnd_state *);
66735 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
66736
66737 +static inline unsigned long pax_get_random_long(void)
66738 +{
66739 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
66740 +}
66741 +
66742 /*
66743 * Handle minimum values for seeds
66744 */
66745 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
66746 index 23b3630..e1bc12b 100644
66747 --- a/include/linux/reboot.h
66748 +++ b/include/linux/reboot.h
66749 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
66750 * Architecture-specific implementations of sys_reboot commands.
66751 */
66752
66753 -extern void machine_restart(char *cmd);
66754 -extern void machine_halt(void);
66755 -extern void machine_power_off(void);
66756 +extern void machine_restart(char *cmd) __noreturn;
66757 +extern void machine_halt(void) __noreturn;
66758 +extern void machine_power_off(void) __noreturn;
66759
66760 extern void machine_shutdown(void);
66761 struct pt_regs;
66762 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
66763 */
66764
66765 extern void kernel_restart_prepare(char *cmd);
66766 -extern void kernel_restart(char *cmd);
66767 -extern void kernel_halt(void);
66768 -extern void kernel_power_off(void);
66769 +extern void kernel_restart(char *cmd) __noreturn;
66770 +extern void kernel_halt(void) __noreturn;
66771 +extern void kernel_power_off(void) __noreturn;
66772
66773 extern int C_A_D; /* for sysctl */
66774 void ctrl_alt_del(void);
66775 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
66776 * Emergency restart, callable from an interrupt handler.
66777 */
66778
66779 -extern void emergency_restart(void);
66780 +extern void emergency_restart(void) __noreturn;
66781 #include <asm/emergency-restart.h>
66782
66783 #endif /* _LINUX_REBOOT_H */
66784 diff --git a/include/linux/regset.h b/include/linux/regset.h
66785 index 8e0c9fe..ac4d221 100644
66786 --- a/include/linux/regset.h
66787 +++ b/include/linux/regset.h
66788 @@ -161,7 +161,8 @@ struct user_regset {
66789 unsigned int align;
66790 unsigned int bias;
66791 unsigned int core_note_type;
66792 -};
66793 +} __do_const;
66794 +typedef struct user_regset __no_const user_regset_no_const;
66795
66796 /**
66797 * struct user_regset_view - available regsets
66798 diff --git a/include/linux/relay.h b/include/linux/relay.h
66799 index 91cacc3..b55ff74 100644
66800 --- a/include/linux/relay.h
66801 +++ b/include/linux/relay.h
66802 @@ -160,7 +160,7 @@ struct rchan_callbacks
66803 * The callback should return 0 if successful, negative if not.
66804 */
66805 int (*remove_buf_file)(struct dentry *dentry);
66806 -};
66807 +} __no_const;
66808
66809 /*
66810 * CONFIG_RELAY kernel API, kernel/relay.c
66811 diff --git a/include/linux/rio.h b/include/linux/rio.h
66812 index a3e7842..d973ca6 100644
66813 --- a/include/linux/rio.h
66814 +++ b/include/linux/rio.h
66815 @@ -339,7 +339,7 @@ struct rio_ops {
66816 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
66817 u64 rstart, u32 size, u32 flags);
66818 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
66819 -};
66820 +} __no_const;
66821
66822 #define RIO_RESOURCE_MEM 0x00000100
66823 #define RIO_RESOURCE_DOORBELL 0x00000200
66824 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
66825 index c20635c..2f5def4 100644
66826 --- a/include/linux/rmap.h
66827 +++ b/include/linux/rmap.h
66828 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
66829 void anon_vma_init(void); /* create anon_vma_cachep */
66830 int anon_vma_prepare(struct vm_area_struct *);
66831 void unlink_anon_vmas(struct vm_area_struct *);
66832 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
66833 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
66834 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
66835 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
66836
66837 static inline void anon_vma_merge(struct vm_area_struct *vma,
66838 struct vm_area_struct *next)
66839 diff --git a/include/linux/sched.h b/include/linux/sched.h
66840 index d211247..d64a165 100644
66841 --- a/include/linux/sched.h
66842 +++ b/include/linux/sched.h
66843 @@ -61,6 +61,7 @@ struct bio_list;
66844 struct fs_struct;
66845 struct perf_event_context;
66846 struct blk_plug;
66847 +struct linux_binprm;
66848
66849 /*
66850 * List of flags we want to share for kernel threads,
66851 @@ -354,10 +355,23 @@ struct user_namespace;
66852 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
66853
66854 extern int sysctl_max_map_count;
66855 +extern unsigned long sysctl_heap_stack_gap;
66856
66857 #include <linux/aio.h>
66858
66859 #ifdef CONFIG_MMU
66860 +
66861 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
66862 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
66863 +#else
66864 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
66865 +{
66866 + return 0;
66867 +}
66868 +#endif
66869 +
66870 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
66871 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
66872 extern void arch_pick_mmap_layout(struct mm_struct *mm);
66873 extern unsigned long
66874 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
66875 @@ -639,6 +653,17 @@ struct signal_struct {
66876 #ifdef CONFIG_TASKSTATS
66877 struct taskstats *stats;
66878 #endif
66879 +
66880 +#ifdef CONFIG_GRKERNSEC
66881 + u32 curr_ip;
66882 + u32 saved_ip;
66883 + u32 gr_saddr;
66884 + u32 gr_daddr;
66885 + u16 gr_sport;
66886 + u16 gr_dport;
66887 + u8 used_accept:1;
66888 +#endif
66889 +
66890 #ifdef CONFIG_AUDIT
66891 unsigned audit_tty;
66892 struct tty_audit_buf *tty_audit_buf;
66893 @@ -717,6 +742,11 @@ struct user_struct {
66894 struct key *session_keyring; /* UID's default session keyring */
66895 #endif
66896
66897 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66898 + unsigned int banned;
66899 + unsigned long ban_expires;
66900 +#endif
66901 +
66902 /* Hash table maintenance information */
66903 struct hlist_node uidhash_node;
66904 kuid_t uid;
66905 @@ -1360,8 +1390,8 @@ struct task_struct {
66906 struct list_head thread_group;
66907
66908 struct completion *vfork_done; /* for vfork() */
66909 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
66910 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66911 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
66912 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
66913
66914 cputime_t utime, stime, utimescaled, stimescaled;
66915 cputime_t gtime;
66916 @@ -1377,11 +1407,6 @@ struct task_struct {
66917 struct task_cputime cputime_expires;
66918 struct list_head cpu_timers[3];
66919
66920 -/* process credentials */
66921 - const struct cred __rcu *real_cred; /* objective and real subjective task
66922 - * credentials (COW) */
66923 - const struct cred __rcu *cred; /* effective (overridable) subjective task
66924 - * credentials (COW) */
66925 char comm[TASK_COMM_LEN]; /* executable name excluding path
66926 - access with [gs]et_task_comm (which lock
66927 it with task_lock())
66928 @@ -1398,6 +1423,10 @@ struct task_struct {
66929 #endif
66930 /* CPU-specific state of this task */
66931 struct thread_struct thread;
66932 +/* thread_info moved to task_struct */
66933 +#ifdef CONFIG_X86
66934 + struct thread_info tinfo;
66935 +#endif
66936 /* filesystem information */
66937 struct fs_struct *fs;
66938 /* open file information */
66939 @@ -1471,6 +1500,10 @@ struct task_struct {
66940 gfp_t lockdep_reclaim_gfp;
66941 #endif
66942
66943 +/* process credentials */
66944 + const struct cred __rcu *real_cred; /* objective and real subjective task
66945 + * credentials (COW) */
66946 +
66947 /* journalling filesystem info */
66948 void *journal_info;
66949
66950 @@ -1509,6 +1542,10 @@ struct task_struct {
66951 /* cg_list protected by css_set_lock and tsk->alloc_lock */
66952 struct list_head cg_list;
66953 #endif
66954 +
66955 + const struct cred __rcu *cred; /* effective (overridable) subjective task
66956 + * credentials (COW) */
66957 +
66958 #ifdef CONFIG_FUTEX
66959 struct robust_list_head __user *robust_list;
66960 #ifdef CONFIG_COMPAT
66961 @@ -1605,8 +1642,74 @@ struct task_struct {
66962 #ifdef CONFIG_UPROBES
66963 struct uprobe_task *utask;
66964 #endif
66965 +
66966 +#ifdef CONFIG_GRKERNSEC
66967 + /* grsecurity */
66968 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66969 + u64 exec_id;
66970 +#endif
66971 +#ifdef CONFIG_GRKERNSEC_SETXID
66972 + const struct cred *delayed_cred;
66973 +#endif
66974 + struct dentry *gr_chroot_dentry;
66975 + struct acl_subject_label *acl;
66976 + struct acl_role_label *role;
66977 + struct file *exec_file;
66978 + unsigned long brute_expires;
66979 + u16 acl_role_id;
66980 + /* is this the task that authenticated to the special role */
66981 + u8 acl_sp_role;
66982 + u8 is_writable;
66983 + u8 brute;
66984 + u8 gr_is_chrooted;
66985 +#endif
66986 +
66987 };
66988
66989 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
66990 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
66991 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
66992 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
66993 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
66994 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
66995 +
66996 +#ifdef CONFIG_PAX_SOFTMODE
66997 +extern int pax_softmode;
66998 +#endif
66999 +
67000 +extern int pax_check_flags(unsigned long *);
67001 +
67002 +/* if tsk != current then task_lock must be held on it */
67003 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
67004 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
67005 +{
67006 + if (likely(tsk->mm))
67007 + return tsk->mm->pax_flags;
67008 + else
67009 + return 0UL;
67010 +}
67011 +
67012 +/* if tsk != current then task_lock must be held on it */
67013 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
67014 +{
67015 + if (likely(tsk->mm)) {
67016 + tsk->mm->pax_flags = flags;
67017 + return 0;
67018 + }
67019 + return -EINVAL;
67020 +}
67021 +#endif
67022 +
67023 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
67024 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
67025 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
67026 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
67027 +#endif
67028 +
67029 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
67030 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
67031 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
67032 +
67033 /* Future-safe accessor for struct task_struct's cpus_allowed. */
67034 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
67035
67036 @@ -2155,7 +2258,9 @@ void yield(void);
67037 extern struct exec_domain default_exec_domain;
67038
67039 union thread_union {
67040 +#ifndef CONFIG_X86
67041 struct thread_info thread_info;
67042 +#endif
67043 unsigned long stack[THREAD_SIZE/sizeof(long)];
67044 };
67045
67046 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
67047 */
67048
67049 extern struct task_struct *find_task_by_vpid(pid_t nr);
67050 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
67051 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
67052 struct pid_namespace *ns);
67053
67054 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
67055 extern void exit_itimers(struct signal_struct *);
67056 extern void flush_itimer_signals(void);
67057
67058 -extern void do_group_exit(int);
67059 +extern __noreturn void do_group_exit(int);
67060
67061 extern int allow_signal(int);
67062 extern int disallow_signal(int);
67063 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
67064
67065 #endif
67066
67067 -static inline int object_is_on_stack(void *obj)
67068 +static inline int object_starts_on_stack(void *obj)
67069 {
67070 - void *stack = task_stack_page(current);
67071 + const void *stack = task_stack_page(current);
67072
67073 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
67074 }
67075 diff --git a/include/linux/security.h b/include/linux/security.h
67076 index eee7478..290f7ba 100644
67077 --- a/include/linux/security.h
67078 +++ b/include/linux/security.h
67079 @@ -26,6 +26,7 @@
67080 #include <linux/capability.h>
67081 #include <linux/slab.h>
67082 #include <linux/err.h>
67083 +#include <linux/grsecurity.h>
67084
67085 struct linux_binprm;
67086 struct cred;
67087 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
67088 index 68a04a3..866e6a1 100644
67089 --- a/include/linux/seq_file.h
67090 +++ b/include/linux/seq_file.h
67091 @@ -26,6 +26,9 @@ struct seq_file {
67092 struct mutex lock;
67093 const struct seq_operations *op;
67094 int poll_event;
67095 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67096 + u64 exec_id;
67097 +#endif
67098 #ifdef CONFIG_USER_NS
67099 struct user_namespace *user_ns;
67100 #endif
67101 @@ -38,6 +41,7 @@ struct seq_operations {
67102 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
67103 int (*show) (struct seq_file *m, void *v);
67104 };
67105 +typedef struct seq_operations __no_const seq_operations_no_const;
67106
67107 #define SEQ_SKIP 1
67108
67109 diff --git a/include/linux/shm.h b/include/linux/shm.h
67110 index 429c199..4d42e38 100644
67111 --- a/include/linux/shm.h
67112 +++ b/include/linux/shm.h
67113 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
67114
67115 /* The task created the shm object. NULL if the task is dead. */
67116 struct task_struct *shm_creator;
67117 +#ifdef CONFIG_GRKERNSEC
67118 + time_t shm_createtime;
67119 + pid_t shm_lapid;
67120 +#endif
67121 };
67122
67123 /* shm_mode upper byte flags */
67124 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
67125 index 320e976..fd52553 100644
67126 --- a/include/linux/skbuff.h
67127 +++ b/include/linux/skbuff.h
67128 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
67129 extern struct sk_buff *__alloc_skb(unsigned int size,
67130 gfp_t priority, int flags, int node);
67131 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
67132 -static inline struct sk_buff *alloc_skb(unsigned int size,
67133 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
67134 gfp_t priority)
67135 {
67136 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
67137 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
67138 */
67139 static inline int skb_queue_empty(const struct sk_buff_head *list)
67140 {
67141 - return list->next == (struct sk_buff *)list;
67142 + return list->next == (const struct sk_buff *)list;
67143 }
67144
67145 /**
67146 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
67147 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67148 const struct sk_buff *skb)
67149 {
67150 - return skb->next == (struct sk_buff *)list;
67151 + return skb->next == (const struct sk_buff *)list;
67152 }
67153
67154 /**
67155 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
67156 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
67157 const struct sk_buff *skb)
67158 {
67159 - return skb->prev == (struct sk_buff *)list;
67160 + return skb->prev == (const struct sk_buff *)list;
67161 }
67162
67163 /**
67164 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
67165 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
67166 */
67167 #ifndef NET_SKB_PAD
67168 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
67169 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
67170 #endif
67171
67172 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
67173 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
67174 int noblock, int *err);
67175 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
67176 struct poll_table_struct *wait);
67177 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
67178 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
67179 int offset, struct iovec *to,
67180 int size);
67181 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
67182 diff --git a/include/linux/slab.h b/include/linux/slab.h
67183 index 5d168d7..720bff3 100644
67184 --- a/include/linux/slab.h
67185 +++ b/include/linux/slab.h
67186 @@ -12,13 +12,20 @@
67187 #include <linux/gfp.h>
67188 #include <linux/types.h>
67189 #include <linux/workqueue.h>
67190 -
67191 +#include <linux/err.h>
67192
67193 /*
67194 * Flags to pass to kmem_cache_create().
67195 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
67196 */
67197 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
67198 +
67199 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67200 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
67201 +#else
67202 +#define SLAB_USERCOPY 0x00000000UL
67203 +#endif
67204 +
67205 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
67206 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
67207 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
67208 @@ -89,10 +96,13 @@
67209 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
67210 * Both make kfree a no-op.
67211 */
67212 -#define ZERO_SIZE_PTR ((void *)16)
67213 +#define ZERO_SIZE_PTR \
67214 +({ \
67215 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
67216 + (void *)(-MAX_ERRNO-1L); \
67217 +})
67218
67219 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
67220 - (unsigned long)ZERO_SIZE_PTR)
67221 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
67222
67223 /*
67224 * Common fields provided in kmem_cache by all slab allocators
67225 @@ -112,7 +122,7 @@ struct kmem_cache {
67226 unsigned int align; /* Alignment as calculated */
67227 unsigned long flags; /* Active flags on the slab */
67228 const char *name; /* Slab name for sysfs */
67229 - int refcount; /* Use counter */
67230 + atomic_t refcount; /* Use counter */
67231 void (*ctor)(void *); /* Called on object slot creation */
67232 struct list_head list; /* List of all slab caches on the system */
67233 };
67234 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
67235 void kfree(const void *);
67236 void kzfree(const void *);
67237 size_t ksize(const void *);
67238 +const char *check_heap_object(const void *ptr, unsigned long n);
67239 +bool is_usercopy_object(const void *ptr);
67240
67241 /*
67242 * Allocator specific definitions. These are mainly used to establish optimized
67243 @@ -311,6 +323,7 @@ size_t ksize(const void *);
67244 * for general use, and so are not documented here. For a full list of
67245 * potential flags, always refer to linux/gfp.h.
67246 */
67247 +
67248 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
67249 {
67250 if (size != 0 && n > SIZE_MAX / size)
67251 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
67252 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67253 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67254 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67255 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67256 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
67257 #define kmalloc_track_caller(size, flags) \
67258 __kmalloc_track_caller(size, flags, _RET_IP_)
67259 #else
67260 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
67261 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
67262 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
67263 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
67264 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
67265 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
67266 #define kmalloc_node_track_caller(size, flags, node) \
67267 __kmalloc_node_track_caller(size, flags, node, \
67268 _RET_IP_)
67269 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
67270 index 8bb6e0e..8eb0dbe 100644
67271 --- a/include/linux/slab_def.h
67272 +++ b/include/linux/slab_def.h
67273 @@ -52,7 +52,7 @@ struct kmem_cache {
67274 /* 4) cache creation/removal */
67275 const char *name;
67276 struct list_head list;
67277 - int refcount;
67278 + atomic_t refcount;
67279 int object_size;
67280 int align;
67281
67282 @@ -68,10 +68,10 @@ struct kmem_cache {
67283 unsigned long node_allocs;
67284 unsigned long node_frees;
67285 unsigned long node_overflow;
67286 - atomic_t allochit;
67287 - atomic_t allocmiss;
67288 - atomic_t freehit;
67289 - atomic_t freemiss;
67290 + atomic_unchecked_t allochit;
67291 + atomic_unchecked_t allocmiss;
67292 + atomic_unchecked_t freehit;
67293 + atomic_unchecked_t freemiss;
67294
67295 /*
67296 * If debugging is enabled, then the allocator can add additional
67297 @@ -111,11 +111,16 @@ struct cache_sizes {
67298 #ifdef CONFIG_ZONE_DMA
67299 struct kmem_cache *cs_dmacachep;
67300 #endif
67301 +
67302 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67303 + struct kmem_cache *cs_usercopycachep;
67304 +#endif
67305 +
67306 };
67307 extern struct cache_sizes malloc_sizes[];
67308
67309 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67310 -void *__kmalloc(size_t size, gfp_t flags);
67311 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
67312
67313 #ifdef CONFIG_TRACING
67314 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
67315 @@ -152,6 +157,13 @@ found:
67316 cachep = malloc_sizes[i].cs_dmacachep;
67317 else
67318 #endif
67319 +
67320 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67321 + if (flags & GFP_USERCOPY)
67322 + cachep = malloc_sizes[i].cs_usercopycachep;
67323 + else
67324 +#endif
67325 +
67326 cachep = malloc_sizes[i].cs_cachep;
67327
67328 ret = kmem_cache_alloc_trace(cachep, flags, size);
67329 @@ -162,7 +174,7 @@ found:
67330 }
67331
67332 #ifdef CONFIG_NUMA
67333 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
67334 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67335 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67336
67337 #ifdef CONFIG_TRACING
67338 @@ -205,6 +217,13 @@ found:
67339 cachep = malloc_sizes[i].cs_dmacachep;
67340 else
67341 #endif
67342 +
67343 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67344 + if (flags & GFP_USERCOPY)
67345 + cachep = malloc_sizes[i].cs_usercopycachep;
67346 + else
67347 +#endif
67348 +
67349 cachep = malloc_sizes[i].cs_cachep;
67350
67351 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
67352 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
67353 index f28e14a..7831211 100644
67354 --- a/include/linux/slob_def.h
67355 +++ b/include/linux/slob_def.h
67356 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
67357 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
67358 }
67359
67360 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
67361 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67362
67363 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
67364 {
67365 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67366 return __kmalloc_node(size, flags, NUMA_NO_NODE);
67367 }
67368
67369 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
67370 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
67371 {
67372 return kmalloc(size, flags);
67373 }
67374 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
67375 index 9db4825..ed42fb5 100644
67376 --- a/include/linux/slub_def.h
67377 +++ b/include/linux/slub_def.h
67378 @@ -91,7 +91,7 @@ struct kmem_cache {
67379 struct kmem_cache_order_objects max;
67380 struct kmem_cache_order_objects min;
67381 gfp_t allocflags; /* gfp flags to use on each alloc */
67382 - int refcount; /* Refcount for slab cache destroy */
67383 + atomic_t refcount; /* Refcount for slab cache destroy */
67384 void (*ctor)(void *);
67385 int inuse; /* Offset to metadata */
67386 int align; /* Alignment */
67387 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
67388 * Sorry that the following has to be that ugly but some versions of GCC
67389 * have trouble with constant propagation and loops.
67390 */
67391 -static __always_inline int kmalloc_index(size_t size)
67392 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
67393 {
67394 if (!size)
67395 return 0;
67396 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
67397 }
67398
67399 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
67400 -void *__kmalloc(size_t size, gfp_t flags);
67401 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
67402
67403 static __always_inline void *
67404 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
67405 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
67406 }
67407 #endif
67408
67409 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
67410 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
67411 {
67412 unsigned int order = get_order(size);
67413 return kmalloc_order_trace(size, flags, order);
67414 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
67415 }
67416
67417 #ifdef CONFIG_NUMA
67418 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
67419 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
67420 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
67421
67422 #ifdef CONFIG_TRACING
67423 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
67424 index 680f9a3..f13aeb0 100644
67425 --- a/include/linux/sonet.h
67426 +++ b/include/linux/sonet.h
67427 @@ -7,7 +7,7 @@
67428 #include <uapi/linux/sonet.h>
67429
67430 struct k_sonet_stats {
67431 -#define __HANDLE_ITEM(i) atomic_t i
67432 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
67433 __SONET_ITEMS
67434 #undef __HANDLE_ITEM
67435 };
67436 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
67437 index 34206b8..f019e06 100644
67438 --- a/include/linux/sunrpc/clnt.h
67439 +++ b/include/linux/sunrpc/clnt.h
67440 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
67441 {
67442 switch (sap->sa_family) {
67443 case AF_INET:
67444 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
67445 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
67446 case AF_INET6:
67447 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
67448 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
67449 }
67450 return 0;
67451 }
67452 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
67453 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
67454 const struct sockaddr *src)
67455 {
67456 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
67457 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
67458 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
67459
67460 dsin->sin_family = ssin->sin_family;
67461 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
67462 if (sa->sa_family != AF_INET6)
67463 return 0;
67464
67465 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
67466 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
67467 }
67468
67469 #endif /* __KERNEL__ */
67470 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
67471 index 0b8e3e6..33e0a01 100644
67472 --- a/include/linux/sunrpc/svc_rdma.h
67473 +++ b/include/linux/sunrpc/svc_rdma.h
67474 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
67475 extern unsigned int svcrdma_max_requests;
67476 extern unsigned int svcrdma_max_req_size;
67477
67478 -extern atomic_t rdma_stat_recv;
67479 -extern atomic_t rdma_stat_read;
67480 -extern atomic_t rdma_stat_write;
67481 -extern atomic_t rdma_stat_sq_starve;
67482 -extern atomic_t rdma_stat_rq_starve;
67483 -extern atomic_t rdma_stat_rq_poll;
67484 -extern atomic_t rdma_stat_rq_prod;
67485 -extern atomic_t rdma_stat_sq_poll;
67486 -extern atomic_t rdma_stat_sq_prod;
67487 +extern atomic_unchecked_t rdma_stat_recv;
67488 +extern atomic_unchecked_t rdma_stat_read;
67489 +extern atomic_unchecked_t rdma_stat_write;
67490 +extern atomic_unchecked_t rdma_stat_sq_starve;
67491 +extern atomic_unchecked_t rdma_stat_rq_starve;
67492 +extern atomic_unchecked_t rdma_stat_rq_poll;
67493 +extern atomic_unchecked_t rdma_stat_rq_prod;
67494 +extern atomic_unchecked_t rdma_stat_sq_poll;
67495 +extern atomic_unchecked_t rdma_stat_sq_prod;
67496
67497 #define RPCRDMA_VERSION 1
67498
67499 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
67500 index 14a8ff2..21fe4c7 100644
67501 --- a/include/linux/sysctl.h
67502 +++ b/include/linux/sysctl.h
67503 @@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
67504
67505 extern int proc_dostring(struct ctl_table *, int,
67506 void __user *, size_t *, loff_t *);
67507 +extern int proc_dostring_modpriv(struct ctl_table *, int,
67508 + void __user *, size_t *, loff_t *);
67509 extern int proc_dointvec(struct ctl_table *, int,
67510 void __user *, size_t *, loff_t *);
67511 extern int proc_dointvec_minmax(struct ctl_table *, int,
67512 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
67513 index 7faf933..eb6f5e3 100644
67514 --- a/include/linux/sysrq.h
67515 +++ b/include/linux/sysrq.h
67516 @@ -36,7 +36,7 @@ struct sysrq_key_op {
67517 char *help_msg;
67518 char *action_msg;
67519 int enable_mask;
67520 -};
67521 +} __do_const;
67522
67523 #ifdef CONFIG_MAGIC_SYSRQ
67524
67525 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
67526 index e7e0473..39b7b52 100644
67527 --- a/include/linux/thread_info.h
67528 +++ b/include/linux/thread_info.h
67529 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
67530 #error "no set_restore_sigmask() provided and default one won't work"
67531 #endif
67532
67533 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
67534 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
67535 +{
67536 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
67537 + if (!__builtin_constant_p(n))
67538 +#endif
67539 + __check_object_size(ptr, n, to);
67540 +}
67541 +
67542 #endif /* __KERNEL__ */
67543
67544 #endif /* _LINUX_THREAD_INFO_H */
67545 diff --git a/include/linux/tty.h b/include/linux/tty.h
67546 index 8db1b56..c16a040 100644
67547 --- a/include/linux/tty.h
67548 +++ b/include/linux/tty.h
67549 @@ -194,7 +194,7 @@ struct tty_port {
67550 const struct tty_port_operations *ops; /* Port operations */
67551 spinlock_t lock; /* Lock protecting tty field */
67552 int blocked_open; /* Waiting to open */
67553 - int count; /* Usage count */
67554 + atomic_t count; /* Usage count */
67555 wait_queue_head_t open_wait; /* Open waiters */
67556 wait_queue_head_t close_wait; /* Close waiters */
67557 wait_queue_head_t delta_msr_wait; /* Modem status change */
67558 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
67559 struct tty_struct *tty, struct file *filp);
67560 static inline int tty_port_users(struct tty_port *port)
67561 {
67562 - return port->count + port->blocked_open;
67563 + return atomic_read(&port->count) + port->blocked_open;
67564 }
67565
67566 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
67567 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
67568 index dd976cf..e272742 100644
67569 --- a/include/linux/tty_driver.h
67570 +++ b/include/linux/tty_driver.h
67571 @@ -284,7 +284,7 @@ struct tty_operations {
67572 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
67573 #endif
67574 const struct file_operations *proc_fops;
67575 -};
67576 +} __do_const;
67577
67578 struct tty_driver {
67579 int magic; /* magic number for this structure */
67580 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
67581 index fb79dd8d..07d4773 100644
67582 --- a/include/linux/tty_ldisc.h
67583 +++ b/include/linux/tty_ldisc.h
67584 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
67585
67586 struct module *owner;
67587
67588 - int refcount;
67589 + atomic_t refcount;
67590 };
67591
67592 struct tty_ldisc {
67593 diff --git a/include/linux/types.h b/include/linux/types.h
67594 index 4d118ba..c3ee9bf 100644
67595 --- a/include/linux/types.h
67596 +++ b/include/linux/types.h
67597 @@ -176,10 +176,26 @@ typedef struct {
67598 int counter;
67599 } atomic_t;
67600
67601 +#ifdef CONFIG_PAX_REFCOUNT
67602 +typedef struct {
67603 + int counter;
67604 +} atomic_unchecked_t;
67605 +#else
67606 +typedef atomic_t atomic_unchecked_t;
67607 +#endif
67608 +
67609 #ifdef CONFIG_64BIT
67610 typedef struct {
67611 long counter;
67612 } atomic64_t;
67613 +
67614 +#ifdef CONFIG_PAX_REFCOUNT
67615 +typedef struct {
67616 + long counter;
67617 +} atomic64_unchecked_t;
67618 +#else
67619 +typedef atomic64_t atomic64_unchecked_t;
67620 +#endif
67621 #endif
67622
67623 struct list_head {
67624 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
67625 index 5ca0951..ab496a5 100644
67626 --- a/include/linux/uaccess.h
67627 +++ b/include/linux/uaccess.h
67628 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
67629 long ret; \
67630 mm_segment_t old_fs = get_fs(); \
67631 \
67632 - set_fs(KERNEL_DS); \
67633 pagefault_disable(); \
67634 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
67635 - pagefault_enable(); \
67636 + set_fs(KERNEL_DS); \
67637 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
67638 set_fs(old_fs); \
67639 + pagefault_enable(); \
67640 ret; \
67641 })
67642
67643 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
67644 index 99c1b4d..bb94261 100644
67645 --- a/include/linux/unaligned/access_ok.h
67646 +++ b/include/linux/unaligned/access_ok.h
67647 @@ -6,32 +6,32 @@
67648
67649 static inline u16 get_unaligned_le16(const void *p)
67650 {
67651 - return le16_to_cpup((__le16 *)p);
67652 + return le16_to_cpup((const __le16 *)p);
67653 }
67654
67655 static inline u32 get_unaligned_le32(const void *p)
67656 {
67657 - return le32_to_cpup((__le32 *)p);
67658 + return le32_to_cpup((const __le32 *)p);
67659 }
67660
67661 static inline u64 get_unaligned_le64(const void *p)
67662 {
67663 - return le64_to_cpup((__le64 *)p);
67664 + return le64_to_cpup((const __le64 *)p);
67665 }
67666
67667 static inline u16 get_unaligned_be16(const void *p)
67668 {
67669 - return be16_to_cpup((__be16 *)p);
67670 + return be16_to_cpup((const __be16 *)p);
67671 }
67672
67673 static inline u32 get_unaligned_be32(const void *p)
67674 {
67675 - return be32_to_cpup((__be32 *)p);
67676 + return be32_to_cpup((const __be32 *)p);
67677 }
67678
67679 static inline u64 get_unaligned_be64(const void *p)
67680 {
67681 - return be64_to_cpup((__be64 *)p);
67682 + return be64_to_cpup((const __be64 *)p);
67683 }
67684
67685 static inline void put_unaligned_le16(u16 val, void *p)
67686 diff --git a/include/linux/usb.h b/include/linux/usb.h
67687 index 4d22d0f..ac43c2f 100644
67688 --- a/include/linux/usb.h
67689 +++ b/include/linux/usb.h
67690 @@ -554,7 +554,7 @@ struct usb_device {
67691 int maxchild;
67692
67693 u32 quirks;
67694 - atomic_t urbnum;
67695 + atomic_unchecked_t urbnum;
67696
67697 unsigned long active_duration;
67698
67699 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
67700 index c5d36c6..108f4f9 100644
67701 --- a/include/linux/usb/renesas_usbhs.h
67702 +++ b/include/linux/usb/renesas_usbhs.h
67703 @@ -39,7 +39,7 @@ enum {
67704 */
67705 struct renesas_usbhs_driver_callback {
67706 int (*notify_hotplug)(struct platform_device *pdev);
67707 -};
67708 +} __no_const;
67709
67710 /*
67711 * callback functions for platform
67712 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
67713 index b9bd2e6..4ce0093 100644
67714 --- a/include/linux/user_namespace.h
67715 +++ b/include/linux/user_namespace.h
67716 @@ -21,7 +21,7 @@ struct user_namespace {
67717 struct uid_gid_map uid_map;
67718 struct uid_gid_map gid_map;
67719 struct uid_gid_map projid_map;
67720 - struct kref kref;
67721 + atomic_t count;
67722 struct user_namespace *parent;
67723 kuid_t owner;
67724 kgid_t group;
67725 @@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
67726 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
67727 {
67728 if (ns)
67729 - kref_get(&ns->kref);
67730 + atomic_inc(&ns->count);
67731 return ns;
67732 }
67733
67734 extern int create_user_ns(struct cred *new);
67735 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
67736 -extern void free_user_ns(struct kref *kref);
67737 +extern void free_user_ns(struct user_namespace *ns);
67738
67739 static inline void put_user_ns(struct user_namespace *ns)
67740 {
67741 - if (ns)
67742 - kref_put(&ns->kref, free_user_ns);
67743 + if (ns && atomic_dec_and_test(&ns->count))
67744 + free_user_ns(ns);
67745 }
67746
67747 struct seq_operations;
67748 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
67749 index 6f8fbcf..8259001 100644
67750 --- a/include/linux/vermagic.h
67751 +++ b/include/linux/vermagic.h
67752 @@ -25,9 +25,35 @@
67753 #define MODULE_ARCH_VERMAGIC ""
67754 #endif
67755
67756 +#ifdef CONFIG_PAX_REFCOUNT
67757 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
67758 +#else
67759 +#define MODULE_PAX_REFCOUNT ""
67760 +#endif
67761 +
67762 +#ifdef CONSTIFY_PLUGIN
67763 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
67764 +#else
67765 +#define MODULE_CONSTIFY_PLUGIN ""
67766 +#endif
67767 +
67768 +#ifdef STACKLEAK_PLUGIN
67769 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
67770 +#else
67771 +#define MODULE_STACKLEAK_PLUGIN ""
67772 +#endif
67773 +
67774 +#ifdef CONFIG_GRKERNSEC
67775 +#define MODULE_GRSEC "GRSEC "
67776 +#else
67777 +#define MODULE_GRSEC ""
67778 +#endif
67779 +
67780 #define VERMAGIC_STRING \
67781 UTS_RELEASE " " \
67782 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
67783 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
67784 - MODULE_ARCH_VERMAGIC
67785 + MODULE_ARCH_VERMAGIC \
67786 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
67787 + MODULE_GRSEC
67788
67789 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
67790 index 6071e91..ca6a489 100644
67791 --- a/include/linux/vmalloc.h
67792 +++ b/include/linux/vmalloc.h
67793 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
67794 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
67795 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
67796 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
67797 +
67798 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
67799 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
67800 +#endif
67801 +
67802 /* bits [20..32] reserved for arch specific ioremap internals */
67803
67804 /*
67805 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
67806 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
67807 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
67808 unsigned long start, unsigned long end, gfp_t gfp_mask,
67809 - pgprot_t prot, int node, const void *caller);
67810 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
67811 extern void vfree(const void *addr);
67812
67813 extern void *vmap(struct page **pages, unsigned int count,
67814 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
67815 extern void free_vm_area(struct vm_struct *area);
67816
67817 /* for /dev/kmem */
67818 -extern long vread(char *buf, char *addr, unsigned long count);
67819 -extern long vwrite(char *buf, char *addr, unsigned long count);
67820 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
67821 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
67822
67823 /*
67824 * Internals. Dont't use..
67825 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
67826 index a13291f..af51fa3 100644
67827 --- a/include/linux/vmstat.h
67828 +++ b/include/linux/vmstat.h
67829 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
67830 /*
67831 * Zone based page accounting with per cpu differentials.
67832 */
67833 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67834 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
67835
67836 static inline void zone_page_state_add(long x, struct zone *zone,
67837 enum zone_stat_item item)
67838 {
67839 - atomic_long_add(x, &zone->vm_stat[item]);
67840 - atomic_long_add(x, &vm_stat[item]);
67841 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
67842 + atomic_long_add_unchecked(x, &vm_stat[item]);
67843 }
67844
67845 static inline unsigned long global_page_state(enum zone_stat_item item)
67846 {
67847 - long x = atomic_long_read(&vm_stat[item]);
67848 + long x = atomic_long_read_unchecked(&vm_stat[item]);
67849 #ifdef CONFIG_SMP
67850 if (x < 0)
67851 x = 0;
67852 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
67853 static inline unsigned long zone_page_state(struct zone *zone,
67854 enum zone_stat_item item)
67855 {
67856 - long x = atomic_long_read(&zone->vm_stat[item]);
67857 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67858 #ifdef CONFIG_SMP
67859 if (x < 0)
67860 x = 0;
67861 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
67862 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
67863 enum zone_stat_item item)
67864 {
67865 - long x = atomic_long_read(&zone->vm_stat[item]);
67866 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
67867
67868 #ifdef CONFIG_SMP
67869 int cpu;
67870 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
67871
67872 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
67873 {
67874 - atomic_long_inc(&zone->vm_stat[item]);
67875 - atomic_long_inc(&vm_stat[item]);
67876 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
67877 + atomic_long_inc_unchecked(&vm_stat[item]);
67878 }
67879
67880 static inline void __inc_zone_page_state(struct page *page,
67881 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
67882
67883 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
67884 {
67885 - atomic_long_dec(&zone->vm_stat[item]);
67886 - atomic_long_dec(&vm_stat[item]);
67887 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
67888 + atomic_long_dec_unchecked(&vm_stat[item]);
67889 }
67890
67891 static inline void __dec_zone_page_state(struct page *page,
67892 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
67893 index 95d1c91..6798cca 100644
67894 --- a/include/media/v4l2-dev.h
67895 +++ b/include/media/v4l2-dev.h
67896 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
67897 int (*mmap) (struct file *, struct vm_area_struct *);
67898 int (*open) (struct file *);
67899 int (*release) (struct file *);
67900 -};
67901 +} __do_const;
67902
67903 /*
67904 * Newer version of video_device, handled by videodev2.c
67905 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
67906 index 4118ad1..cb7e25f 100644
67907 --- a/include/media/v4l2-ioctl.h
67908 +++ b/include/media/v4l2-ioctl.h
67909 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
67910 bool valid_prio, int cmd, void *arg);
67911 };
67912
67913 -
67914 /* v4l debugging and diagnostics */
67915
67916 /* Debug bitmask flags to be used on V4L2 */
67917 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
67918 index 9e5425b..8136ffc 100644
67919 --- a/include/net/caif/cfctrl.h
67920 +++ b/include/net/caif/cfctrl.h
67921 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
67922 void (*radioset_rsp)(void);
67923 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
67924 struct cflayer *client_layer);
67925 -};
67926 +} __no_const;
67927
67928 /* Link Setup Parameters for CAIF-Links. */
67929 struct cfctrl_link_param {
67930 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
67931 struct cfctrl {
67932 struct cfsrvl serv;
67933 struct cfctrl_rsp res;
67934 - atomic_t req_seq_no;
67935 - atomic_t rsp_seq_no;
67936 + atomic_unchecked_t req_seq_no;
67937 + atomic_unchecked_t rsp_seq_no;
67938 struct list_head list;
67939 /* Protects from simultaneous access to first_req list */
67940 spinlock_t info_list_lock;
67941 diff --git a/include/net/flow.h b/include/net/flow.h
67942 index 628e11b..4c475df 100644
67943 --- a/include/net/flow.h
67944 +++ b/include/net/flow.h
67945 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
67946
67947 extern void flow_cache_flush(void);
67948 extern void flow_cache_flush_deferred(void);
67949 -extern atomic_t flow_cache_genid;
67950 +extern atomic_unchecked_t flow_cache_genid;
67951
67952 #endif
67953 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
67954 index e5062c9..48a9a4b 100644
67955 --- a/include/net/gro_cells.h
67956 +++ b/include/net/gro_cells.h
67957 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
67958 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
67959
67960 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
67961 - atomic_long_inc(&dev->rx_dropped);
67962 + atomic_long_inc_unchecked(&dev->rx_dropped);
67963 kfree_skb(skb);
67964 return;
67965 }
67966 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
67967 int i;
67968
67969 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
67970 - gcells->cells = kcalloc(sizeof(struct gro_cell),
67971 - gcells->gro_cells_mask + 1,
67972 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
67973 + sizeof(struct gro_cell),
67974 GFP_KERNEL);
67975 if (!gcells->cells)
67976 return -ENOMEM;
67977 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
67978 index 1832927..ce39aea 100644
67979 --- a/include/net/inet_connection_sock.h
67980 +++ b/include/net/inet_connection_sock.h
67981 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
67982 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
67983 int (*bind_conflict)(const struct sock *sk,
67984 const struct inet_bind_bucket *tb, bool relax);
67985 -};
67986 +} __do_const;
67987
67988 /** inet_connection_sock - INET connection oriented sock
67989 *
67990 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
67991 index 53f464d..ba76aaa 100644
67992 --- a/include/net/inetpeer.h
67993 +++ b/include/net/inetpeer.h
67994 @@ -47,8 +47,8 @@ struct inet_peer {
67995 */
67996 union {
67997 struct {
67998 - atomic_t rid; /* Frag reception counter */
67999 - atomic_t ip_id_count; /* IP ID for the next packet */
68000 + atomic_unchecked_t rid; /* Frag reception counter */
68001 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
68002 };
68003 struct rcu_head rcu;
68004 struct inet_peer *gc_next;
68005 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
68006 more++;
68007 inet_peer_refcheck(p);
68008 do {
68009 - old = atomic_read(&p->ip_id_count);
68010 + old = atomic_read_unchecked(&p->ip_id_count);
68011 new = old + more;
68012 if (!new)
68013 new = 1;
68014 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
68015 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
68016 return new;
68017 }
68018
68019 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
68020 index 9497be1..5a4fafe 100644
68021 --- a/include/net/ip_fib.h
68022 +++ b/include/net/ip_fib.h
68023 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
68024
68025 #define FIB_RES_SADDR(net, res) \
68026 ((FIB_RES_NH(res).nh_saddr_genid == \
68027 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
68028 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
68029 FIB_RES_NH(res).nh_saddr : \
68030 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
68031 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
68032 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
68033 index 68c69d5..2ee192b 100644
68034 --- a/include/net/ip_vs.h
68035 +++ b/include/net/ip_vs.h
68036 @@ -599,7 +599,7 @@ struct ip_vs_conn {
68037 struct ip_vs_conn *control; /* Master control connection */
68038 atomic_t n_control; /* Number of controlled ones */
68039 struct ip_vs_dest *dest; /* real server */
68040 - atomic_t in_pkts; /* incoming packet counter */
68041 + atomic_unchecked_t in_pkts; /* incoming packet counter */
68042
68043 /* packet transmitter for different forwarding methods. If it
68044 mangles the packet, it must return NF_DROP or better NF_STOLEN,
68045 @@ -737,7 +737,7 @@ struct ip_vs_dest {
68046 __be16 port; /* port number of the server */
68047 union nf_inet_addr addr; /* IP address of the server */
68048 volatile unsigned int flags; /* dest status flags */
68049 - atomic_t conn_flags; /* flags to copy to conn */
68050 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
68051 atomic_t weight; /* server weight */
68052
68053 atomic_t refcnt; /* reference counter */
68054 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
68055 index 80ffde3..968b0f4 100644
68056 --- a/include/net/irda/ircomm_tty.h
68057 +++ b/include/net/irda/ircomm_tty.h
68058 @@ -35,6 +35,7 @@
68059 #include <linux/termios.h>
68060 #include <linux/timer.h>
68061 #include <linux/tty.h> /* struct tty_struct */
68062 +#include <asm/local.h>
68063
68064 #include <net/irda/irias_object.h>
68065 #include <net/irda/ircomm_core.h>
68066 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
68067 index cc7c197..9f2da2a 100644
68068 --- a/include/net/iucv/af_iucv.h
68069 +++ b/include/net/iucv/af_iucv.h
68070 @@ -141,7 +141,7 @@ struct iucv_sock {
68071 struct iucv_sock_list {
68072 struct hlist_head head;
68073 rwlock_t lock;
68074 - atomic_t autobind_name;
68075 + atomic_unchecked_t autobind_name;
68076 };
68077
68078 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
68079 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
68080 index 0dab173..1b76af0 100644
68081 --- a/include/net/neighbour.h
68082 +++ b/include/net/neighbour.h
68083 @@ -123,7 +123,7 @@ struct neigh_ops {
68084 void (*error_report)(struct neighbour *, struct sk_buff *);
68085 int (*output)(struct neighbour *, struct sk_buff *);
68086 int (*connected_output)(struct neighbour *, struct sk_buff *);
68087 -};
68088 +} __do_const;
68089
68090 struct pneigh_entry {
68091 struct pneigh_entry *next;
68092 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
68093 index de644bc..666aed3 100644
68094 --- a/include/net/net_namespace.h
68095 +++ b/include/net/net_namespace.h
68096 @@ -115,7 +115,7 @@ struct net {
68097 #endif
68098 struct netns_ipvs *ipvs;
68099 struct sock *diag_nlsk;
68100 - atomic_t rt_genid;
68101 + atomic_unchecked_t rt_genid;
68102 };
68103
68104 /*
68105 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
68106
68107 static inline int rt_genid(struct net *net)
68108 {
68109 - return atomic_read(&net->rt_genid);
68110 + return atomic_read_unchecked(&net->rt_genid);
68111 }
68112
68113 static inline void rt_genid_bump(struct net *net)
68114 {
68115 - atomic_inc(&net->rt_genid);
68116 + atomic_inc_unchecked(&net->rt_genid);
68117 }
68118
68119 #endif /* __NET_NET_NAMESPACE_H */
68120 diff --git a/include/net/netdma.h b/include/net/netdma.h
68121 index 8ba8ce2..99b7fff 100644
68122 --- a/include/net/netdma.h
68123 +++ b/include/net/netdma.h
68124 @@ -24,7 +24,7 @@
68125 #include <linux/dmaengine.h>
68126 #include <linux/skbuff.h>
68127
68128 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68129 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
68130 struct sk_buff *skb, int offset, struct iovec *to,
68131 size_t len, struct dma_pinned_list *pinned_list);
68132
68133 diff --git a/include/net/netlink.h b/include/net/netlink.h
68134 index 9690b0f..87aded7 100644
68135 --- a/include/net/netlink.h
68136 +++ b/include/net/netlink.h
68137 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
68138 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
68139 {
68140 if (mark)
68141 - skb_trim(skb, (unsigned char *) mark - skb->data);
68142 + skb_trim(skb, (const unsigned char *) mark - skb->data);
68143 }
68144
68145 /**
68146 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
68147 index 2ae2b83..dbdc85e 100644
68148 --- a/include/net/netns/ipv4.h
68149 +++ b/include/net/netns/ipv4.h
68150 @@ -64,7 +64,7 @@ struct netns_ipv4 {
68151 kgid_t sysctl_ping_group_range[2];
68152 long sysctl_tcp_mem[3];
68153
68154 - atomic_t dev_addr_genid;
68155 + atomic_unchecked_t dev_addr_genid;
68156
68157 #ifdef CONFIG_IP_MROUTE
68158 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
68159 diff --git a/include/net/protocol.h b/include/net/protocol.h
68160 index 047c047..b9dad15 100644
68161 --- a/include/net/protocol.h
68162 +++ b/include/net/protocol.h
68163 @@ -44,7 +44,7 @@ struct net_protocol {
68164 void (*err_handler)(struct sk_buff *skb, u32 info);
68165 unsigned int no_policy:1,
68166 netns_ok:1;
68167 -};
68168 +} __do_const;
68169
68170 #if IS_ENABLED(CONFIG_IPV6)
68171 struct inet6_protocol {
68172 @@ -57,7 +57,7 @@ struct inet6_protocol {
68173 u8 type, u8 code, int offset,
68174 __be32 info);
68175 unsigned int flags; /* INET6_PROTO_xxx */
68176 -};
68177 +} __do_const;
68178
68179 #define INET6_PROTO_NOPOLICY 0x1
68180 #define INET6_PROTO_FINAL 0x2
68181 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
68182 index 7fdf298..197e9f7 100644
68183 --- a/include/net/sctp/sctp.h
68184 +++ b/include/net/sctp/sctp.h
68185 @@ -330,9 +330,9 @@ do { \
68186
68187 #else /* SCTP_DEBUG */
68188
68189 -#define SCTP_DEBUG_PRINTK(whatever...)
68190 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
68191 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
68192 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
68193 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
68194 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
68195 #define SCTP_ENABLE_DEBUG
68196 #define SCTP_DISABLE_DEBUG
68197 #define SCTP_ASSERT(expr, str, func)
68198 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
68199 index fdeb85a..0c554d5 100644
68200 --- a/include/net/sctp/structs.h
68201 +++ b/include/net/sctp/structs.h
68202 @@ -497,7 +497,7 @@ struct sctp_af {
68203 int sockaddr_len;
68204 sa_family_t sa_family;
68205 struct list_head list;
68206 -};
68207 +} __do_const;
68208
68209 struct sctp_af *sctp_get_af_specific(sa_family_t);
68210 int sctp_register_af(struct sctp_af *);
68211 @@ -517,7 +517,7 @@ struct sctp_pf {
68212 struct sctp_association *asoc);
68213 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
68214 struct sctp_af *af;
68215 -};
68216 +} __do_const;
68217
68218
68219 /* Structure to track chunk fragments that have been acked, but peer
68220 diff --git a/include/net/sock.h b/include/net/sock.h
68221 index 182ca99..b7dc290 100644
68222 --- a/include/net/sock.h
68223 +++ b/include/net/sock.h
68224 @@ -322,7 +322,7 @@ struct sock {
68225 #ifdef CONFIG_RPS
68226 __u32 sk_rxhash;
68227 #endif
68228 - atomic_t sk_drops;
68229 + atomic_unchecked_t sk_drops;
68230 int sk_rcvbuf;
68231
68232 struct sk_filter __rcu *sk_filter;
68233 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
68234 }
68235
68236 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
68237 - char __user *from, char *to,
68238 + char __user *from, unsigned char *to,
68239 int copy, int offset)
68240 {
68241 if (skb->ip_summed == CHECKSUM_NONE) {
68242 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
68243 }
68244 }
68245
68246 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68247 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
68248
68249 /**
68250 * sk_page_frag - return an appropriate page_frag
68251 diff --git a/include/net/tcp.h b/include/net/tcp.h
68252 index aed42c7..43890c6 100644
68253 --- a/include/net/tcp.h
68254 +++ b/include/net/tcp.h
68255 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
68256 extern void tcp_xmit_retransmit_queue(struct sock *);
68257 extern void tcp_simple_retransmit(struct sock *);
68258 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
68259 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68260 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
68261
68262 extern void tcp_send_probe0(struct sock *);
68263 extern void tcp_send_partial(struct sock *);
68264 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
68265 struct inet6_skb_parm h6;
68266 #endif
68267 } header; /* For incoming frames */
68268 - __u32 seq; /* Starting sequence number */
68269 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
68270 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
68271 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
68272 __u32 when; /* used to compute rtt's */
68273 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
68274
68275 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
68276
68277 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
68278 /* 1 byte hole */
68279 - __u32 ack_seq; /* Sequence number ACK'd */
68280 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
68281 };
68282
68283 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
68284 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
68285 index 63445ed..74ef61d 100644
68286 --- a/include/net/xfrm.h
68287 +++ b/include/net/xfrm.h
68288 @@ -423,7 +423,7 @@ struct xfrm_mode {
68289 struct module *owner;
68290 unsigned int encap;
68291 int flags;
68292 -};
68293 +} __do_const;
68294
68295 /* Flags for xfrm_mode. */
68296 enum {
68297 @@ -514,7 +514,7 @@ struct xfrm_policy {
68298 struct timer_list timer;
68299
68300 struct flow_cache_object flo;
68301 - atomic_t genid;
68302 + atomic_unchecked_t genid;
68303 u32 priority;
68304 u32 index;
68305 struct xfrm_mark mark;
68306 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
68307 index 1a046b1..ee0bef0 100644
68308 --- a/include/rdma/iw_cm.h
68309 +++ b/include/rdma/iw_cm.h
68310 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
68311 int backlog);
68312
68313 int (*destroy_listen)(struct iw_cm_id *cm_id);
68314 -};
68315 +} __no_const;
68316
68317 /**
68318 * iw_create_cm_id - Create an IW CM identifier.
68319 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
68320 index 399162b..b337f1a 100644
68321 --- a/include/scsi/libfc.h
68322 +++ b/include/scsi/libfc.h
68323 @@ -762,6 +762,7 @@ struct libfc_function_template {
68324 */
68325 void (*disc_stop_final) (struct fc_lport *);
68326 };
68327 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
68328
68329 /**
68330 * struct fc_disc - Discovery context
68331 @@ -866,7 +867,7 @@ struct fc_lport {
68332 struct fc_vport *vport;
68333
68334 /* Operational Information */
68335 - struct libfc_function_template tt;
68336 + libfc_function_template_no_const tt;
68337 u8 link_up;
68338 u8 qfull;
68339 enum fc_lport_state state;
68340 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
68341 index e65c62e..aa2e5a2 100644
68342 --- a/include/scsi/scsi_device.h
68343 +++ b/include/scsi/scsi_device.h
68344 @@ -170,9 +170,9 @@ struct scsi_device {
68345 unsigned int max_device_blocked; /* what device_blocked counts down from */
68346 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
68347
68348 - atomic_t iorequest_cnt;
68349 - atomic_t iodone_cnt;
68350 - atomic_t ioerr_cnt;
68351 + atomic_unchecked_t iorequest_cnt;
68352 + atomic_unchecked_t iodone_cnt;
68353 + atomic_unchecked_t ioerr_cnt;
68354
68355 struct device sdev_gendev,
68356 sdev_dev;
68357 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
68358 index b797e8f..8e2c3aa 100644
68359 --- a/include/scsi/scsi_transport_fc.h
68360 +++ b/include/scsi/scsi_transport_fc.h
68361 @@ -751,7 +751,8 @@ struct fc_function_template {
68362 unsigned long show_host_system_hostname:1;
68363
68364 unsigned long disable_target_scan:1;
68365 -};
68366 +} __do_const;
68367 +typedef struct fc_function_template __no_const fc_function_template_no_const;
68368
68369
68370 /**
68371 diff --git a/include/sound/soc.h b/include/sound/soc.h
68372 index bc56738..a4be132 100644
68373 --- a/include/sound/soc.h
68374 +++ b/include/sound/soc.h
68375 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
68376 /* probe ordering - for components with runtime dependencies */
68377 int probe_order;
68378 int remove_order;
68379 -};
68380 +} __do_const;
68381
68382 /* SoC platform interface */
68383 struct snd_soc_platform_driver {
68384 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
68385 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
68386 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
68387 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
68388 -};
68389 +} __do_const;
68390
68391 struct snd_soc_platform {
68392 const char *name;
68393 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
68394 index 663e34a..91b306a 100644
68395 --- a/include/target/target_core_base.h
68396 +++ b/include/target/target_core_base.h
68397 @@ -654,7 +654,7 @@ struct se_device {
68398 spinlock_t stats_lock;
68399 /* Active commands on this virtual SE device */
68400 atomic_t simple_cmds;
68401 - atomic_t dev_ordered_id;
68402 + atomic_unchecked_t dev_ordered_id;
68403 atomic_t dev_ordered_sync;
68404 atomic_t dev_qf_count;
68405 int export_count;
68406 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
68407 new file mode 100644
68408 index 0000000..fb634b7
68409 --- /dev/null
68410 +++ b/include/trace/events/fs.h
68411 @@ -0,0 +1,53 @@
68412 +#undef TRACE_SYSTEM
68413 +#define TRACE_SYSTEM fs
68414 +
68415 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
68416 +#define _TRACE_FS_H
68417 +
68418 +#include <linux/fs.h>
68419 +#include <linux/tracepoint.h>
68420 +
68421 +TRACE_EVENT(do_sys_open,
68422 +
68423 + TP_PROTO(const char *filename, int flags, int mode),
68424 +
68425 + TP_ARGS(filename, flags, mode),
68426 +
68427 + TP_STRUCT__entry(
68428 + __string( filename, filename )
68429 + __field( int, flags )
68430 + __field( int, mode )
68431 + ),
68432 +
68433 + TP_fast_assign(
68434 + __assign_str(filename, filename);
68435 + __entry->flags = flags;
68436 + __entry->mode = mode;
68437 + ),
68438 +
68439 + TP_printk("\"%s\" %x %o",
68440 + __get_str(filename), __entry->flags, __entry->mode)
68441 +);
68442 +
68443 +TRACE_EVENT(open_exec,
68444 +
68445 + TP_PROTO(const char *filename),
68446 +
68447 + TP_ARGS(filename),
68448 +
68449 + TP_STRUCT__entry(
68450 + __string( filename, filename )
68451 + ),
68452 +
68453 + TP_fast_assign(
68454 + __assign_str(filename, filename);
68455 + ),
68456 +
68457 + TP_printk("\"%s\"",
68458 + __get_str(filename))
68459 +);
68460 +
68461 +#endif /* _TRACE_FS_H */
68462 +
68463 +/* This part must be outside protection */
68464 +#include <trace/define_trace.h>
68465 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
68466 index 1c09820..7f5ec79 100644
68467 --- a/include/trace/events/irq.h
68468 +++ b/include/trace/events/irq.h
68469 @@ -36,7 +36,7 @@ struct softirq_action;
68470 */
68471 TRACE_EVENT(irq_handler_entry,
68472
68473 - TP_PROTO(int irq, struct irqaction *action),
68474 + TP_PROTO(int irq, const struct irqaction *action),
68475
68476 TP_ARGS(irq, action),
68477
68478 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
68479 */
68480 TRACE_EVENT(irq_handler_exit,
68481
68482 - TP_PROTO(int irq, struct irqaction *action, int ret),
68483 + TP_PROTO(int irq, const struct irqaction *action, int ret),
68484
68485 TP_ARGS(irq, action, ret),
68486
68487 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
68488 index 7caf44c..23c6f27 100644
68489 --- a/include/uapi/linux/a.out.h
68490 +++ b/include/uapi/linux/a.out.h
68491 @@ -39,6 +39,14 @@ enum machine_type {
68492 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
68493 };
68494
68495 +/* Constants for the N_FLAGS field */
68496 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68497 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
68498 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
68499 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
68500 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68501 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68502 +
68503 #if !defined (N_MAGIC)
68504 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
68505 #endif
68506 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
68507 index d876736..b36014e 100644
68508 --- a/include/uapi/linux/byteorder/little_endian.h
68509 +++ b/include/uapi/linux/byteorder/little_endian.h
68510 @@ -42,51 +42,51 @@
68511
68512 static inline __le64 __cpu_to_le64p(const __u64 *p)
68513 {
68514 - return (__force __le64)*p;
68515 + return (__force const __le64)*p;
68516 }
68517 static inline __u64 __le64_to_cpup(const __le64 *p)
68518 {
68519 - return (__force __u64)*p;
68520 + return (__force const __u64)*p;
68521 }
68522 static inline __le32 __cpu_to_le32p(const __u32 *p)
68523 {
68524 - return (__force __le32)*p;
68525 + return (__force const __le32)*p;
68526 }
68527 static inline __u32 __le32_to_cpup(const __le32 *p)
68528 {
68529 - return (__force __u32)*p;
68530 + return (__force const __u32)*p;
68531 }
68532 static inline __le16 __cpu_to_le16p(const __u16 *p)
68533 {
68534 - return (__force __le16)*p;
68535 + return (__force const __le16)*p;
68536 }
68537 static inline __u16 __le16_to_cpup(const __le16 *p)
68538 {
68539 - return (__force __u16)*p;
68540 + return (__force const __u16)*p;
68541 }
68542 static inline __be64 __cpu_to_be64p(const __u64 *p)
68543 {
68544 - return (__force __be64)__swab64p(p);
68545 + return (__force const __be64)__swab64p(p);
68546 }
68547 static inline __u64 __be64_to_cpup(const __be64 *p)
68548 {
68549 - return __swab64p((__u64 *)p);
68550 + return __swab64p((const __u64 *)p);
68551 }
68552 static inline __be32 __cpu_to_be32p(const __u32 *p)
68553 {
68554 - return (__force __be32)__swab32p(p);
68555 + return (__force const __be32)__swab32p(p);
68556 }
68557 static inline __u32 __be32_to_cpup(const __be32 *p)
68558 {
68559 - return __swab32p((__u32 *)p);
68560 + return __swab32p((const __u32 *)p);
68561 }
68562 static inline __be16 __cpu_to_be16p(const __u16 *p)
68563 {
68564 - return (__force __be16)__swab16p(p);
68565 + return (__force const __be16)__swab16p(p);
68566 }
68567 static inline __u16 __be16_to_cpup(const __be16 *p)
68568 {
68569 - return __swab16p((__u16 *)p);
68570 + return __swab16p((const __u16 *)p);
68571 }
68572 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
68573 #define __le64_to_cpus(x) do { (void)(x); } while (0)
68574 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
68575 index 126a817..d522bd1 100644
68576 --- a/include/uapi/linux/elf.h
68577 +++ b/include/uapi/linux/elf.h
68578 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
68579 #define PT_GNU_EH_FRAME 0x6474e550
68580
68581 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
68582 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
68583 +
68584 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
68585 +
68586 +/* Constants for the e_flags field */
68587 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
68588 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
68589 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
68590 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
68591 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
68592 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
68593
68594 /*
68595 * Extended Numbering
68596 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
68597 #define DT_DEBUG 21
68598 #define DT_TEXTREL 22
68599 #define DT_JMPREL 23
68600 +#define DT_FLAGS 30
68601 + #define DF_TEXTREL 0x00000004
68602 #define DT_ENCODING 32
68603 #define OLD_DT_LOOS 0x60000000
68604 #define DT_LOOS 0x6000000d
68605 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
68606 #define PF_W 0x2
68607 #define PF_X 0x1
68608
68609 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
68610 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
68611 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
68612 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
68613 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
68614 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
68615 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
68616 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
68617 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
68618 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
68619 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
68620 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
68621 +
68622 typedef struct elf32_phdr{
68623 Elf32_Word p_type;
68624 Elf32_Off p_offset;
68625 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
68626 #define EI_OSABI 7
68627 #define EI_PAD 8
68628
68629 +#define EI_PAX 14
68630 +
68631 #define ELFMAG0 0x7f /* EI_MAG */
68632 #define ELFMAG1 'E'
68633 #define ELFMAG2 'L'
68634 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
68635 index aa169c4..6a2771d 100644
68636 --- a/include/uapi/linux/personality.h
68637 +++ b/include/uapi/linux/personality.h
68638 @@ -30,6 +30,7 @@ enum {
68639 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
68640 ADDR_NO_RANDOMIZE | \
68641 ADDR_COMPAT_LAYOUT | \
68642 + ADDR_LIMIT_3GB | \
68643 MMAP_PAGE_ZERO)
68644
68645 /*
68646 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
68647 index 7530e74..e714828 100644
68648 --- a/include/uapi/linux/screen_info.h
68649 +++ b/include/uapi/linux/screen_info.h
68650 @@ -43,7 +43,8 @@ struct screen_info {
68651 __u16 pages; /* 0x32 */
68652 __u16 vesa_attributes; /* 0x34 */
68653 __u32 capabilities; /* 0x36 */
68654 - __u8 _reserved[6]; /* 0x3a */
68655 + __u16 vesapm_size; /* 0x3a */
68656 + __u8 _reserved[4]; /* 0x3c */
68657 } __attribute__((packed));
68658
68659 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
68660 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
68661 index 6d67213..8dab561 100644
68662 --- a/include/uapi/linux/sysctl.h
68663 +++ b/include/uapi/linux/sysctl.h
68664 @@ -155,7 +155,11 @@ enum
68665 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
68666 };
68667
68668 -
68669 +#ifdef CONFIG_PAX_SOFTMODE
68670 +enum {
68671 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
68672 +};
68673 +#endif
68674
68675 /* CTL_VM names: */
68676 enum
68677 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
68678 index 26607bd..588b65f 100644
68679 --- a/include/uapi/linux/xattr.h
68680 +++ b/include/uapi/linux/xattr.h
68681 @@ -60,5 +60,9 @@
68682 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
68683 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
68684
68685 +/* User namespace */
68686 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
68687 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
68688 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
68689
68690 #endif /* _UAPI_LINUX_XATTR_H */
68691 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
68692 index f9466fa..f4e2b81 100644
68693 --- a/include/video/udlfb.h
68694 +++ b/include/video/udlfb.h
68695 @@ -53,10 +53,10 @@ struct dlfb_data {
68696 u32 pseudo_palette[256];
68697 int blank_mode; /*one of FB_BLANK_ */
68698 /* blit-only rendering path metrics, exposed through sysfs */
68699 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68700 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
68701 - atomic_t bytes_sent; /* to usb, after compression including overhead */
68702 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
68703 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
68704 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
68705 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
68706 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
68707 };
68708
68709 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
68710 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
68711 index 0993a22..32ba2fe 100644
68712 --- a/include/video/uvesafb.h
68713 +++ b/include/video/uvesafb.h
68714 @@ -177,6 +177,7 @@ struct uvesafb_par {
68715 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
68716 u8 pmi_setpal; /* PMI for palette changes */
68717 u16 *pmi_base; /* protected mode interface location */
68718 + u8 *pmi_code; /* protected mode code location */
68719 void *pmi_start;
68720 void *pmi_pal;
68721 u8 *vbe_state_orig; /*
68722 diff --git a/init/Kconfig b/init/Kconfig
68723 index be8b7f5..b13cb62 100644
68724 --- a/init/Kconfig
68725 +++ b/init/Kconfig
68726 @@ -990,6 +990,7 @@ endif # CGROUPS
68727
68728 config CHECKPOINT_RESTORE
68729 bool "Checkpoint/restore support" if EXPERT
68730 + depends on !GRKERNSEC
68731 default n
68732 help
68733 Enables additional kernel features in a sake of checkpoint/restore.
68734 @@ -1079,6 +1080,8 @@ config UIDGID_CONVERTED
68735 depends on OCFS2_FS = n
68736 depends on XFS_FS = n
68737
68738 + depends on GRKERNSEC = n
68739 +
68740 config UIDGID_STRICT_TYPE_CHECKS
68741 bool "Require conversions between uid/gids and their internal representation"
68742 depends on UIDGID_CONVERTED
68743 @@ -1468,7 +1471,7 @@ config SLUB_DEBUG
68744
68745 config COMPAT_BRK
68746 bool "Disable heap randomization"
68747 - default y
68748 + default n
68749 help
68750 Randomizing heap placement makes heap exploits harder, but it
68751 also breaks ancient binaries (including anything libc5 based).
68752 @@ -1711,7 +1714,7 @@ config INIT_ALL_POSSIBLE
68753 config STOP_MACHINE
68754 bool
68755 default y
68756 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
68757 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
68758 help
68759 Need stop_machine() primitive.
68760
68761 diff --git a/init/Makefile b/init/Makefile
68762 index 7bc47ee..6da2dc7 100644
68763 --- a/init/Makefile
68764 +++ b/init/Makefile
68765 @@ -2,6 +2,9 @@
68766 # Makefile for the linux kernel.
68767 #
68768
68769 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
68770 +asflags-y := $(GCC_PLUGINS_AFLAGS)
68771 +
68772 obj-y := main.o version.o mounts.o
68773 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
68774 obj-y += noinitramfs.o
68775 diff --git a/init/do_mounts.c b/init/do_mounts.c
68776 index 1d1b634..a1c810f 100644
68777 --- a/init/do_mounts.c
68778 +++ b/init/do_mounts.c
68779 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
68780 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
68781 {
68782 struct super_block *s;
68783 - int err = sys_mount(name, "/root", fs, flags, data);
68784 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
68785 if (err)
68786 return err;
68787
68788 - sys_chdir("/root");
68789 + sys_chdir((const char __force_user *)"/root");
68790 s = current->fs->pwd.dentry->d_sb;
68791 ROOT_DEV = s->s_dev;
68792 printk(KERN_INFO
68793 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
68794 va_start(args, fmt);
68795 vsprintf(buf, fmt, args);
68796 va_end(args);
68797 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
68798 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
68799 if (fd >= 0) {
68800 sys_ioctl(fd, FDEJECT, 0);
68801 sys_close(fd);
68802 }
68803 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
68804 - fd = sys_open("/dev/console", O_RDWR, 0);
68805 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
68806 if (fd >= 0) {
68807 sys_ioctl(fd, TCGETS, (long)&termios);
68808 termios.c_lflag &= ~ICANON;
68809 sys_ioctl(fd, TCSETSF, (long)&termios);
68810 - sys_read(fd, &c, 1);
68811 + sys_read(fd, (char __user *)&c, 1);
68812 termios.c_lflag |= ICANON;
68813 sys_ioctl(fd, TCSETSF, (long)&termios);
68814 sys_close(fd);
68815 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
68816 mount_root();
68817 out:
68818 devtmpfs_mount("dev");
68819 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
68820 - sys_chroot(".");
68821 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
68822 + sys_chroot((const char __force_user *)".");
68823 }
68824 diff --git a/init/do_mounts.h b/init/do_mounts.h
68825 index f5b978a..69dbfe8 100644
68826 --- a/init/do_mounts.h
68827 +++ b/init/do_mounts.h
68828 @@ -15,15 +15,15 @@ extern int root_mountflags;
68829
68830 static inline int create_dev(char *name, dev_t dev)
68831 {
68832 - sys_unlink(name);
68833 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
68834 + sys_unlink((char __force_user *)name);
68835 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
68836 }
68837
68838 #if BITS_PER_LONG == 32
68839 static inline u32 bstat(char *name)
68840 {
68841 struct stat64 stat;
68842 - if (sys_stat64(name, &stat) != 0)
68843 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
68844 return 0;
68845 if (!S_ISBLK(stat.st_mode))
68846 return 0;
68847 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
68848 static inline u32 bstat(char *name)
68849 {
68850 struct stat stat;
68851 - if (sys_newstat(name, &stat) != 0)
68852 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
68853 return 0;
68854 if (!S_ISBLK(stat.st_mode))
68855 return 0;
68856 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
68857 index f9acf71..1e19144 100644
68858 --- a/init/do_mounts_initrd.c
68859 +++ b/init/do_mounts_initrd.c
68860 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
68861 create_dev("/dev/root.old", Root_RAM0);
68862 /* mount initrd on rootfs' /root */
68863 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
68864 - sys_mkdir("/old", 0700);
68865 - sys_chdir("/old");
68866 + sys_mkdir((const char __force_user *)"/old", 0700);
68867 + sys_chdir((const char __force_user *)"/old");
68868
68869 /*
68870 * In case that a resume from disk is carried out by linuxrc or one of
68871 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
68872 current->flags &= ~PF_FREEZER_SKIP;
68873
68874 /* move initrd to rootfs' /old */
68875 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
68876 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
68877 /* switch root and cwd back to / of rootfs */
68878 - sys_chroot("..");
68879 + sys_chroot((const char __force_user *)"..");
68880
68881 if (new_decode_dev(real_root_dev) == Root_RAM0) {
68882 - sys_chdir("/old");
68883 + sys_chdir((const char __force_user *)"/old");
68884 return;
68885 }
68886
68887 - sys_chdir("/");
68888 + sys_chdir((const char __force_user *)"/");
68889 ROOT_DEV = new_decode_dev(real_root_dev);
68890 mount_root();
68891
68892 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
68893 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
68894 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
68895 if (!error)
68896 printk("okay\n");
68897 else {
68898 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
68899 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
68900 if (error == -ENOENT)
68901 printk("/initrd does not exist. Ignored.\n");
68902 else
68903 printk("failed\n");
68904 printk(KERN_NOTICE "Unmounting old root\n");
68905 - sys_umount("/old", MNT_DETACH);
68906 + sys_umount((char __force_user *)"/old", MNT_DETACH);
68907 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
68908 if (fd < 0) {
68909 error = fd;
68910 @@ -120,11 +120,11 @@ int __init initrd_load(void)
68911 * mounted in the normal path.
68912 */
68913 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
68914 - sys_unlink("/initrd.image");
68915 + sys_unlink((const char __force_user *)"/initrd.image");
68916 handle_initrd();
68917 return 1;
68918 }
68919 }
68920 - sys_unlink("/initrd.image");
68921 + sys_unlink((const char __force_user *)"/initrd.image");
68922 return 0;
68923 }
68924 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
68925 index 8cb6db5..d729f50 100644
68926 --- a/init/do_mounts_md.c
68927 +++ b/init/do_mounts_md.c
68928 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
68929 partitioned ? "_d" : "", minor,
68930 md_setup_args[ent].device_names);
68931
68932 - fd = sys_open(name, 0, 0);
68933 + fd = sys_open((char __force_user *)name, 0, 0);
68934 if (fd < 0) {
68935 printk(KERN_ERR "md: open failed - cannot start "
68936 "array %s\n", name);
68937 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
68938 * array without it
68939 */
68940 sys_close(fd);
68941 - fd = sys_open(name, 0, 0);
68942 + fd = sys_open((char __force_user *)name, 0, 0);
68943 sys_ioctl(fd, BLKRRPART, 0);
68944 }
68945 sys_close(fd);
68946 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
68947
68948 wait_for_device_probe();
68949
68950 - fd = sys_open("/dev/md0", 0, 0);
68951 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
68952 if (fd >= 0) {
68953 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
68954 sys_close(fd);
68955 diff --git a/init/init_task.c b/init/init_task.c
68956 index 8b2f399..f0797c9 100644
68957 --- a/init/init_task.c
68958 +++ b/init/init_task.c
68959 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
68960 * Initial thread structure. Alignment of this is handled by a special
68961 * linker map entry.
68962 */
68963 +#ifdef CONFIG_X86
68964 +union thread_union init_thread_union __init_task_data;
68965 +#else
68966 union thread_union init_thread_union __init_task_data =
68967 { INIT_THREAD_INFO(init_task) };
68968 +#endif
68969 diff --git a/init/initramfs.c b/init/initramfs.c
68970 index 84c6bf1..8899338 100644
68971 --- a/init/initramfs.c
68972 +++ b/init/initramfs.c
68973 @@ -84,7 +84,7 @@ static void __init free_hash(void)
68974 }
68975 }
68976
68977 -static long __init do_utime(char *filename, time_t mtime)
68978 +static long __init do_utime(char __force_user *filename, time_t mtime)
68979 {
68980 struct timespec t[2];
68981
68982 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
68983 struct dir_entry *de, *tmp;
68984 list_for_each_entry_safe(de, tmp, &dir_list, list) {
68985 list_del(&de->list);
68986 - do_utime(de->name, de->mtime);
68987 + do_utime((char __force_user *)de->name, de->mtime);
68988 kfree(de->name);
68989 kfree(de);
68990 }
68991 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
68992 if (nlink >= 2) {
68993 char *old = find_link(major, minor, ino, mode, collected);
68994 if (old)
68995 - return (sys_link(old, collected) < 0) ? -1 : 1;
68996 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
68997 }
68998 return 0;
68999 }
69000 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
69001 {
69002 struct stat st;
69003
69004 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
69005 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
69006 if (S_ISDIR(st.st_mode))
69007 - sys_rmdir(path);
69008 + sys_rmdir((char __force_user *)path);
69009 else
69010 - sys_unlink(path);
69011 + sys_unlink((char __force_user *)path);
69012 }
69013 }
69014
69015 @@ -315,7 +315,7 @@ static int __init do_name(void)
69016 int openflags = O_WRONLY|O_CREAT;
69017 if (ml != 1)
69018 openflags |= O_TRUNC;
69019 - wfd = sys_open(collected, openflags, mode);
69020 + wfd = sys_open((char __force_user *)collected, openflags, mode);
69021
69022 if (wfd >= 0) {
69023 sys_fchown(wfd, uid, gid);
69024 @@ -327,17 +327,17 @@ static int __init do_name(void)
69025 }
69026 }
69027 } else if (S_ISDIR(mode)) {
69028 - sys_mkdir(collected, mode);
69029 - sys_chown(collected, uid, gid);
69030 - sys_chmod(collected, mode);
69031 + sys_mkdir((char __force_user *)collected, mode);
69032 + sys_chown((char __force_user *)collected, uid, gid);
69033 + sys_chmod((char __force_user *)collected, mode);
69034 dir_add(collected, mtime);
69035 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
69036 S_ISFIFO(mode) || S_ISSOCK(mode)) {
69037 if (maybe_link() == 0) {
69038 - sys_mknod(collected, mode, rdev);
69039 - sys_chown(collected, uid, gid);
69040 - sys_chmod(collected, mode);
69041 - do_utime(collected, mtime);
69042 + sys_mknod((char __force_user *)collected, mode, rdev);
69043 + sys_chown((char __force_user *)collected, uid, gid);
69044 + sys_chmod((char __force_user *)collected, mode);
69045 + do_utime((char __force_user *)collected, mtime);
69046 }
69047 }
69048 return 0;
69049 @@ -346,15 +346,15 @@ static int __init do_name(void)
69050 static int __init do_copy(void)
69051 {
69052 if (count >= body_len) {
69053 - sys_write(wfd, victim, body_len);
69054 + sys_write(wfd, (char __force_user *)victim, body_len);
69055 sys_close(wfd);
69056 - do_utime(vcollected, mtime);
69057 + do_utime((char __force_user *)vcollected, mtime);
69058 kfree(vcollected);
69059 eat(body_len);
69060 state = SkipIt;
69061 return 0;
69062 } else {
69063 - sys_write(wfd, victim, count);
69064 + sys_write(wfd, (char __force_user *)victim, count);
69065 body_len -= count;
69066 eat(count);
69067 return 1;
69068 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
69069 {
69070 collected[N_ALIGN(name_len) + body_len] = '\0';
69071 clean_path(collected, 0);
69072 - sys_symlink(collected + N_ALIGN(name_len), collected);
69073 - sys_lchown(collected, uid, gid);
69074 - do_utime(collected, mtime);
69075 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
69076 + sys_lchown((char __force_user *)collected, uid, gid);
69077 + do_utime((char __force_user *)collected, mtime);
69078 state = SkipIt;
69079 next_state = Reset;
69080 return 0;
69081 diff --git a/init/main.c b/init/main.c
69082 index cee4b5c..47f445e 100644
69083 --- a/init/main.c
69084 +++ b/init/main.c
69085 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
69086 extern void tc_init(void);
69087 #endif
69088
69089 +extern void grsecurity_init(void);
69090 +
69091 /*
69092 * Debug helper: via this flag we know that we are in 'early bootup code'
69093 * where only the boot processor is running with IRQ disabled. This means
69094 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
69095
69096 __setup("reset_devices", set_reset_devices);
69097
69098 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69099 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
69100 +static int __init setup_grsec_proc_gid(char *str)
69101 +{
69102 + grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
69103 + return 1;
69104 +}
69105 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
69106 +#endif
69107 +
69108 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
69109 +extern char pax_enter_kernel_user[];
69110 +extern char pax_exit_kernel_user[];
69111 +extern pgdval_t clone_pgd_mask;
69112 +#endif
69113 +
69114 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
69115 +static int __init setup_pax_nouderef(char *str)
69116 +{
69117 +#ifdef CONFIG_X86_32
69118 + unsigned int cpu;
69119 + struct desc_struct *gdt;
69120 +
69121 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
69122 + gdt = get_cpu_gdt_table(cpu);
69123 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
69124 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
69125 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
69126 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
69127 + }
69128 + loadsegment(ds, __KERNEL_DS);
69129 + loadsegment(es, __KERNEL_DS);
69130 + loadsegment(ss, __KERNEL_DS);
69131 +#else
69132 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
69133 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
69134 + clone_pgd_mask = ~(pgdval_t)0UL;
69135 +#endif
69136 +
69137 + return 0;
69138 +}
69139 +early_param("pax_nouderef", setup_pax_nouderef);
69140 +#endif
69141 +
69142 +#ifdef CONFIG_PAX_SOFTMODE
69143 +int pax_softmode;
69144 +
69145 +static int __init setup_pax_softmode(char *str)
69146 +{
69147 + get_option(&str, &pax_softmode);
69148 + return 1;
69149 +}
69150 +__setup("pax_softmode=", setup_pax_softmode);
69151 +#endif
69152 +
69153 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
69154 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
69155 static const char *panic_later, *panic_param;
69156 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
69157 {
69158 int count = preempt_count();
69159 int ret;
69160 + const char *msg1 = "", *msg2 = "";
69161
69162 if (initcall_debug)
69163 ret = do_one_initcall_debug(fn);
69164 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
69165 sprintf(msgbuf, "error code %d ", ret);
69166
69167 if (preempt_count() != count) {
69168 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
69169 + msg1 = " preemption imbalance";
69170 preempt_count() = count;
69171 }
69172 if (irqs_disabled()) {
69173 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
69174 + msg2 = " disabled interrupts";
69175 local_irq_enable();
69176 }
69177 - if (msgbuf[0]) {
69178 - printk("initcall %pF returned with %s\n", fn, msgbuf);
69179 + if (msgbuf[0] || *msg1 || *msg2) {
69180 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
69181 }
69182
69183 return ret;
69184 @@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
69185 "late",
69186 };
69187
69188 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69189 +u64 latent_entropy;
69190 +#endif
69191 +
69192 static void __init do_initcall_level(int level)
69193 {
69194 extern const struct kernel_param __start___param[], __stop___param[];
69195 @@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
69196 level, level,
69197 &repair_env_string);
69198
69199 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
69200 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
69201 do_one_initcall(*fn);
69202 +
69203 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69204 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69205 +#endif
69206 +
69207 + }
69208 }
69209
69210 static void __init do_initcalls(void)
69211 @@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
69212 {
69213 initcall_t *fn;
69214
69215 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
69216 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
69217 do_one_initcall(*fn);
69218 +
69219 +#ifdef CONFIG_PAX_LATENT_ENTROPY
69220 + add_device_randomness(&latent_entropy, sizeof(latent_entropy));
69221 +#endif
69222 +
69223 + }
69224 }
69225
69226 static int run_init_process(const char *init_filename)
69227 @@ -877,7 +951,7 @@ static noinline void __init kernel_init_freeable(void)
69228 do_basic_setup();
69229
69230 /* Open the /dev/console on the rootfs, this should never fail */
69231 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
69232 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
69233 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
69234
69235 (void) sys_dup(0);
69236 @@ -890,11 +964,13 @@ static noinline void __init kernel_init_freeable(void)
69237 if (!ramdisk_execute_command)
69238 ramdisk_execute_command = "/init";
69239
69240 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
69241 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
69242 ramdisk_execute_command = NULL;
69243 prepare_namespace();
69244 }
69245
69246 + grsecurity_init();
69247 +
69248 /*
69249 * Ok, we have completed the initial bootup, and
69250 * we're essentially up and running. Get rid of the
69251 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
69252 index 71a3ca1..cc330ee 100644
69253 --- a/ipc/mqueue.c
69254 +++ b/ipc/mqueue.c
69255 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
69256 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
69257 info->attr.mq_msgsize);
69258
69259 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
69260 spin_lock(&mq_lock);
69261 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
69262 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
69263 diff --git a/ipc/msg.c b/ipc/msg.c
69264 index 950572f..266c15f 100644
69265 --- a/ipc/msg.c
69266 +++ b/ipc/msg.c
69267 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
69268 return security_msg_queue_associate(msq, msgflg);
69269 }
69270
69271 +static struct ipc_ops msg_ops = {
69272 + .getnew = newque,
69273 + .associate = msg_security,
69274 + .more_checks = NULL
69275 +};
69276 +
69277 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
69278 {
69279 struct ipc_namespace *ns;
69280 - struct ipc_ops msg_ops;
69281 struct ipc_params msg_params;
69282
69283 ns = current->nsproxy->ipc_ns;
69284
69285 - msg_ops.getnew = newque;
69286 - msg_ops.associate = msg_security;
69287 - msg_ops.more_checks = NULL;
69288 -
69289 msg_params.key = key;
69290 msg_params.flg = msgflg;
69291
69292 diff --git a/ipc/sem.c b/ipc/sem.c
69293 index 58d31f1..cce7a55 100644
69294 --- a/ipc/sem.c
69295 +++ b/ipc/sem.c
69296 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
69297 return 0;
69298 }
69299
69300 +static struct ipc_ops sem_ops = {
69301 + .getnew = newary,
69302 + .associate = sem_security,
69303 + .more_checks = sem_more_checks
69304 +};
69305 +
69306 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69307 {
69308 struct ipc_namespace *ns;
69309 - struct ipc_ops sem_ops;
69310 struct ipc_params sem_params;
69311
69312 ns = current->nsproxy->ipc_ns;
69313 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
69314 if (nsems < 0 || nsems > ns->sc_semmsl)
69315 return -EINVAL;
69316
69317 - sem_ops.getnew = newary;
69318 - sem_ops.associate = sem_security;
69319 - sem_ops.more_checks = sem_more_checks;
69320 -
69321 sem_params.key = key;
69322 sem_params.flg = semflg;
69323 sem_params.u.nsems = nsems;
69324 diff --git a/ipc/shm.c b/ipc/shm.c
69325 index 4fa6d8f..38dfd0c 100644
69326 --- a/ipc/shm.c
69327 +++ b/ipc/shm.c
69328 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
69329 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
69330 #endif
69331
69332 +#ifdef CONFIG_GRKERNSEC
69333 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69334 + const time_t shm_createtime, const uid_t cuid,
69335 + const int shmid);
69336 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69337 + const time_t shm_createtime);
69338 +#endif
69339 +
69340 void shm_init_ns(struct ipc_namespace *ns)
69341 {
69342 ns->shm_ctlmax = SHMMAX;
69343 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
69344 shp->shm_lprid = 0;
69345 shp->shm_atim = shp->shm_dtim = 0;
69346 shp->shm_ctim = get_seconds();
69347 +#ifdef CONFIG_GRKERNSEC
69348 + {
69349 + struct timespec timeval;
69350 + do_posix_clock_monotonic_gettime(&timeval);
69351 +
69352 + shp->shm_createtime = timeval.tv_sec;
69353 + }
69354 +#endif
69355 shp->shm_segsz = size;
69356 shp->shm_nattch = 0;
69357 shp->shm_file = file;
69358 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
69359 return 0;
69360 }
69361
69362 +static struct ipc_ops shm_ops = {
69363 + .getnew = newseg,
69364 + .associate = shm_security,
69365 + .more_checks = shm_more_checks
69366 +};
69367 +
69368 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
69369 {
69370 struct ipc_namespace *ns;
69371 - struct ipc_ops shm_ops;
69372 struct ipc_params shm_params;
69373
69374 ns = current->nsproxy->ipc_ns;
69375
69376 - shm_ops.getnew = newseg;
69377 - shm_ops.associate = shm_security;
69378 - shm_ops.more_checks = shm_more_checks;
69379 -
69380 shm_params.key = key;
69381 shm_params.flg = shmflg;
69382 shm_params.u.size = size;
69383 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69384 f_mode = FMODE_READ | FMODE_WRITE;
69385 }
69386 if (shmflg & SHM_EXEC) {
69387 +
69388 +#ifdef CONFIG_PAX_MPROTECT
69389 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
69390 + goto out;
69391 +#endif
69392 +
69393 prot |= PROT_EXEC;
69394 acc_mode |= S_IXUGO;
69395 }
69396 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
69397 if (err)
69398 goto out_unlock;
69399
69400 +#ifdef CONFIG_GRKERNSEC
69401 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
69402 + shp->shm_perm.cuid, shmid) ||
69403 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
69404 + err = -EACCES;
69405 + goto out_unlock;
69406 + }
69407 +#endif
69408 +
69409 path = shp->shm_file->f_path;
69410 path_get(&path);
69411 shp->shm_nattch++;
69412 +#ifdef CONFIG_GRKERNSEC
69413 + shp->shm_lapid = current->pid;
69414 +#endif
69415 size = i_size_read(path.dentry->d_inode);
69416 shm_unlock(shp);
69417
69418 diff --git a/kernel/acct.c b/kernel/acct.c
69419 index 051e071..15e0920 100644
69420 --- a/kernel/acct.c
69421 +++ b/kernel/acct.c
69422 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
69423 */
69424 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
69425 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
69426 - file->f_op->write(file, (char *)&ac,
69427 + file->f_op->write(file, (char __force_user *)&ac,
69428 sizeof(acct_t), &file->f_pos);
69429 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
69430 set_fs(fs);
69431 diff --git a/kernel/audit.c b/kernel/audit.c
69432 index d596e53..dbef3c3 100644
69433 --- a/kernel/audit.c
69434 +++ b/kernel/audit.c
69435 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
69436 3) suppressed due to audit_rate_limit
69437 4) suppressed due to audit_backlog_limit
69438 */
69439 -static atomic_t audit_lost = ATOMIC_INIT(0);
69440 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
69441
69442 /* The netlink socket. */
69443 static struct sock *audit_sock;
69444 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
69445 unsigned long now;
69446 int print;
69447
69448 - atomic_inc(&audit_lost);
69449 + atomic_inc_unchecked(&audit_lost);
69450
69451 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
69452
69453 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
69454 printk(KERN_WARNING
69455 "audit: audit_lost=%d audit_rate_limit=%d "
69456 "audit_backlog_limit=%d\n",
69457 - atomic_read(&audit_lost),
69458 + atomic_read_unchecked(&audit_lost),
69459 audit_rate_limit,
69460 audit_backlog_limit);
69461 audit_panic(message);
69462 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
69463 status_set.pid = audit_pid;
69464 status_set.rate_limit = audit_rate_limit;
69465 status_set.backlog_limit = audit_backlog_limit;
69466 - status_set.lost = atomic_read(&audit_lost);
69467 + status_set.lost = atomic_read_unchecked(&audit_lost);
69468 status_set.backlog = skb_queue_len(&audit_skb_queue);
69469 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
69470 &status_set, sizeof(status_set));
69471 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
69472 index a371f85..da826c1 100644
69473 --- a/kernel/auditsc.c
69474 +++ b/kernel/auditsc.c
69475 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
69476 }
69477
69478 /* global counter which is incremented every time something logs in */
69479 -static atomic_t session_id = ATOMIC_INIT(0);
69480 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
69481
69482 /**
69483 * audit_set_loginuid - set current task's audit_context loginuid
69484 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
69485 return -EPERM;
69486 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
69487
69488 - sessionid = atomic_inc_return(&session_id);
69489 + sessionid = atomic_inc_return_unchecked(&session_id);
69490 if (context && context->in_syscall) {
69491 struct audit_buffer *ab;
69492
69493 diff --git a/kernel/capability.c b/kernel/capability.c
69494 index 493d972..f87dfbd 100644
69495 --- a/kernel/capability.c
69496 +++ b/kernel/capability.c
69497 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
69498 * before modification is attempted and the application
69499 * fails.
69500 */
69501 + if (tocopy > ARRAY_SIZE(kdata))
69502 + return -EFAULT;
69503 +
69504 if (copy_to_user(dataptr, kdata, tocopy
69505 * sizeof(struct __user_cap_data_struct))) {
69506 return -EFAULT;
69507 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
69508 int ret;
69509
69510 rcu_read_lock();
69511 - ret = security_capable(__task_cred(t), ns, cap);
69512 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
69513 + gr_task_is_capable(t, __task_cred(t), cap);
69514 rcu_read_unlock();
69515
69516 - return (ret == 0);
69517 + return ret;
69518 }
69519
69520 /**
69521 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
69522 int ret;
69523
69524 rcu_read_lock();
69525 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
69526 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
69527 rcu_read_unlock();
69528
69529 - return (ret == 0);
69530 + return ret;
69531 }
69532
69533 /**
69534 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
69535 BUG();
69536 }
69537
69538 - if (security_capable(current_cred(), ns, cap) == 0) {
69539 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
69540 current->flags |= PF_SUPERPRIV;
69541 return true;
69542 }
69543 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
69544 }
69545 EXPORT_SYMBOL(ns_capable);
69546
69547 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
69548 +{
69549 + if (unlikely(!cap_valid(cap))) {
69550 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
69551 + BUG();
69552 + }
69553 +
69554 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
69555 + current->flags |= PF_SUPERPRIV;
69556 + return true;
69557 + }
69558 + return false;
69559 +}
69560 +EXPORT_SYMBOL(ns_capable_nolog);
69561 +
69562 /**
69563 * capable - Determine if the current task has a superior capability in effect
69564 * @cap: The capability to be tested for
69565 @@ -408,6 +427,12 @@ bool capable(int cap)
69566 }
69567 EXPORT_SYMBOL(capable);
69568
69569 +bool capable_nolog(int cap)
69570 +{
69571 + return ns_capable_nolog(&init_user_ns, cap);
69572 +}
69573 +EXPORT_SYMBOL(capable_nolog);
69574 +
69575 /**
69576 * nsown_capable - Check superior capability to one's own user_ns
69577 * @cap: The capability in question
69578 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
69579
69580 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69581 }
69582 +
69583 +bool inode_capable_nolog(const struct inode *inode, int cap)
69584 +{
69585 + struct user_namespace *ns = current_user_ns();
69586 +
69587 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
69588 +}
69589 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
69590 index 4855892..30d23b4 100644
69591 --- a/kernel/cgroup.c
69592 +++ b/kernel/cgroup.c
69593 @@ -5535,7 +5535,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
69594 struct css_set *cg = link->cg;
69595 struct task_struct *task;
69596 int count = 0;
69597 - seq_printf(seq, "css_set %p\n", cg);
69598 + seq_printf(seq, "css_set %pK\n", cg);
69599 list_for_each_entry(task, &cg->tasks, cg_list) {
69600 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
69601 seq_puts(seq, " ...\n");
69602 diff --git a/kernel/compat.c b/kernel/compat.c
69603 index 36700e9..73d770c 100644
69604 --- a/kernel/compat.c
69605 +++ b/kernel/compat.c
69606 @@ -13,6 +13,7 @@
69607
69608 #include <linux/linkage.h>
69609 #include <linux/compat.h>
69610 +#include <linux/module.h>
69611 #include <linux/errno.h>
69612 #include <linux/time.h>
69613 #include <linux/signal.h>
69614 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
69615 mm_segment_t oldfs;
69616 long ret;
69617
69618 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
69619 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
69620 oldfs = get_fs();
69621 set_fs(KERNEL_DS);
69622 ret = hrtimer_nanosleep_restart(restart);
69623 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
69624 oldfs = get_fs();
69625 set_fs(KERNEL_DS);
69626 ret = hrtimer_nanosleep(&tu,
69627 - rmtp ? (struct timespec __user *)&rmt : NULL,
69628 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
69629 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
69630 set_fs(oldfs);
69631
69632 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
69633 mm_segment_t old_fs = get_fs();
69634
69635 set_fs(KERNEL_DS);
69636 - ret = sys_sigpending((old_sigset_t __user *) &s);
69637 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
69638 set_fs(old_fs);
69639 if (ret == 0)
69640 ret = put_user(s, set);
69641 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
69642 mm_segment_t old_fs = get_fs();
69643
69644 set_fs(KERNEL_DS);
69645 - ret = sys_old_getrlimit(resource, &r);
69646 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
69647 set_fs(old_fs);
69648
69649 if (!ret) {
69650 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
69651 mm_segment_t old_fs = get_fs();
69652
69653 set_fs(KERNEL_DS);
69654 - ret = sys_getrusage(who, (struct rusage __user *) &r);
69655 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
69656 set_fs(old_fs);
69657
69658 if (ret)
69659 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
69660 set_fs (KERNEL_DS);
69661 ret = sys_wait4(pid,
69662 (stat_addr ?
69663 - (unsigned int __user *) &status : NULL),
69664 - options, (struct rusage __user *) &r);
69665 + (unsigned int __force_user *) &status : NULL),
69666 + options, (struct rusage __force_user *) &r);
69667 set_fs (old_fs);
69668
69669 if (ret > 0) {
69670 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
69671 memset(&info, 0, sizeof(info));
69672
69673 set_fs(KERNEL_DS);
69674 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
69675 - uru ? (struct rusage __user *)&ru : NULL);
69676 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
69677 + uru ? (struct rusage __force_user *)&ru : NULL);
69678 set_fs(old_fs);
69679
69680 if ((ret < 0) || (info.si_signo == 0))
69681 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
69682 oldfs = get_fs();
69683 set_fs(KERNEL_DS);
69684 err = sys_timer_settime(timer_id, flags,
69685 - (struct itimerspec __user *) &newts,
69686 - (struct itimerspec __user *) &oldts);
69687 + (struct itimerspec __force_user *) &newts,
69688 + (struct itimerspec __force_user *) &oldts);
69689 set_fs(oldfs);
69690 if (!err && old && put_compat_itimerspec(old, &oldts))
69691 return -EFAULT;
69692 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
69693 oldfs = get_fs();
69694 set_fs(KERNEL_DS);
69695 err = sys_timer_gettime(timer_id,
69696 - (struct itimerspec __user *) &ts);
69697 + (struct itimerspec __force_user *) &ts);
69698 set_fs(oldfs);
69699 if (!err && put_compat_itimerspec(setting, &ts))
69700 return -EFAULT;
69701 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
69702 oldfs = get_fs();
69703 set_fs(KERNEL_DS);
69704 err = sys_clock_settime(which_clock,
69705 - (struct timespec __user *) &ts);
69706 + (struct timespec __force_user *) &ts);
69707 set_fs(oldfs);
69708 return err;
69709 }
69710 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
69711 oldfs = get_fs();
69712 set_fs(KERNEL_DS);
69713 err = sys_clock_gettime(which_clock,
69714 - (struct timespec __user *) &ts);
69715 + (struct timespec __force_user *) &ts);
69716 set_fs(oldfs);
69717 if (!err && put_compat_timespec(&ts, tp))
69718 return -EFAULT;
69719 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
69720
69721 oldfs = get_fs();
69722 set_fs(KERNEL_DS);
69723 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
69724 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
69725 set_fs(oldfs);
69726
69727 err = compat_put_timex(utp, &txc);
69728 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
69729 oldfs = get_fs();
69730 set_fs(KERNEL_DS);
69731 err = sys_clock_getres(which_clock,
69732 - (struct timespec __user *) &ts);
69733 + (struct timespec __force_user *) &ts);
69734 set_fs(oldfs);
69735 if (!err && tp && put_compat_timespec(&ts, tp))
69736 return -EFAULT;
69737 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
69738 long err;
69739 mm_segment_t oldfs;
69740 struct timespec tu;
69741 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
69742 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
69743
69744 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
69745 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
69746 oldfs = get_fs();
69747 set_fs(KERNEL_DS);
69748 err = clock_nanosleep_restart(restart);
69749 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
69750 oldfs = get_fs();
69751 set_fs(KERNEL_DS);
69752 err = sys_clock_nanosleep(which_clock, flags,
69753 - (struct timespec __user *) &in,
69754 - (struct timespec __user *) &out);
69755 + (struct timespec __force_user *) &in,
69756 + (struct timespec __force_user *) &out);
69757 set_fs(oldfs);
69758
69759 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
69760 diff --git a/kernel/configs.c b/kernel/configs.c
69761 index 42e8fa0..9e7406b 100644
69762 --- a/kernel/configs.c
69763 +++ b/kernel/configs.c
69764 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
69765 struct proc_dir_entry *entry;
69766
69767 /* create the current config file */
69768 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
69769 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
69770 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
69771 + &ikconfig_file_ops);
69772 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69773 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
69774 + &ikconfig_file_ops);
69775 +#endif
69776 +#else
69777 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
69778 &ikconfig_file_ops);
69779 +#endif
69780 +
69781 if (!entry)
69782 return -ENOMEM;
69783
69784 diff --git a/kernel/cred.c b/kernel/cred.c
69785 index e0573a4..eefe488 100644
69786 --- a/kernel/cred.c
69787 +++ b/kernel/cred.c
69788 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
69789 validate_creds(cred);
69790 alter_cred_subscribers(cred, -1);
69791 put_cred(cred);
69792 +
69793 +#ifdef CONFIG_GRKERNSEC_SETXID
69794 + cred = (struct cred *) tsk->delayed_cred;
69795 + if (cred != NULL) {
69796 + tsk->delayed_cred = NULL;
69797 + validate_creds(cred);
69798 + alter_cred_subscribers(cred, -1);
69799 + put_cred(cred);
69800 + }
69801 +#endif
69802 }
69803
69804 /**
69805 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
69806 * Always returns 0 thus allowing this function to be tail-called at the end
69807 * of, say, sys_setgid().
69808 */
69809 -int commit_creds(struct cred *new)
69810 +static int __commit_creds(struct cred *new)
69811 {
69812 struct task_struct *task = current;
69813 const struct cred *old = task->real_cred;
69814 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
69815
69816 get_cred(new); /* we will require a ref for the subj creds too */
69817
69818 + gr_set_role_label(task, new->uid, new->gid);
69819 +
69820 /* dumpability changes */
69821 if (!uid_eq(old->euid, new->euid) ||
69822 !gid_eq(old->egid, new->egid) ||
69823 @@ -479,6 +491,101 @@ int commit_creds(struct cred *new)
69824 put_cred(old);
69825 return 0;
69826 }
69827 +#ifdef CONFIG_GRKERNSEC_SETXID
69828 +extern int set_user(struct cred *new);
69829 +
69830 +void gr_delayed_cred_worker(void)
69831 +{
69832 + const struct cred *new = current->delayed_cred;
69833 + struct cred *ncred;
69834 +
69835 + current->delayed_cred = NULL;
69836 +
69837 + if (current_uid() && new != NULL) {
69838 + // from doing get_cred on it when queueing this
69839 + put_cred(new);
69840 + return;
69841 + } else if (new == NULL)
69842 + return;
69843 +
69844 + ncred = prepare_creds();
69845 + if (!ncred)
69846 + goto die;
69847 + // uids
69848 + ncred->uid = new->uid;
69849 + ncred->euid = new->euid;
69850 + ncred->suid = new->suid;
69851 + ncred->fsuid = new->fsuid;
69852 + // gids
69853 + ncred->gid = new->gid;
69854 + ncred->egid = new->egid;
69855 + ncred->sgid = new->sgid;
69856 + ncred->fsgid = new->fsgid;
69857 + // groups
69858 + if (set_groups(ncred, new->group_info) < 0) {
69859 + abort_creds(ncred);
69860 + goto die;
69861 + }
69862 + // caps
69863 + ncred->securebits = new->securebits;
69864 + ncred->cap_inheritable = new->cap_inheritable;
69865 + ncred->cap_permitted = new->cap_permitted;
69866 + ncred->cap_effective = new->cap_effective;
69867 + ncred->cap_bset = new->cap_bset;
69868 +
69869 + if (set_user(ncred)) {
69870 + abort_creds(ncred);
69871 + goto die;
69872 + }
69873 +
69874 + // from doing get_cred on it when queueing this
69875 + put_cred(new);
69876 +
69877 + __commit_creds(ncred);
69878 + return;
69879 +die:
69880 + // from doing get_cred on it when queueing this
69881 + put_cred(new);
69882 + do_group_exit(SIGKILL);
69883 +}
69884 +#endif
69885 +
69886 +int commit_creds(struct cred *new)
69887 +{
69888 +#ifdef CONFIG_GRKERNSEC_SETXID
69889 + int ret;
69890 + int schedule_it = 0;
69891 + struct task_struct *t;
69892 +
69893 + /* we won't get called with tasklist_lock held for writing
69894 + and interrupts disabled as the cred struct in that case is
69895 + init_cred
69896 + */
69897 + if (grsec_enable_setxid && !current_is_single_threaded() &&
69898 + !current_uid() && new->uid) {
69899 + schedule_it = 1;
69900 + }
69901 + ret = __commit_creds(new);
69902 + if (schedule_it) {
69903 + rcu_read_lock();
69904 + read_lock(&tasklist_lock);
69905 + for (t = next_thread(current); t != current;
69906 + t = next_thread(t)) {
69907 + if (t->delayed_cred == NULL) {
69908 + t->delayed_cred = get_cred(new);
69909 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
69910 + set_tsk_need_resched(t);
69911 + }
69912 + }
69913 + read_unlock(&tasklist_lock);
69914 + rcu_read_unlock();
69915 + }
69916 + return ret;
69917 +#else
69918 + return __commit_creds(new);
69919 +#endif
69920 +}
69921 +
69922 EXPORT_SYMBOL(commit_creds);
69923
69924 /**
69925 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
69926 index 9a61738..c5c8f3a 100644
69927 --- a/kernel/debug/debug_core.c
69928 +++ b/kernel/debug/debug_core.c
69929 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
69930 */
69931 static atomic_t masters_in_kgdb;
69932 static atomic_t slaves_in_kgdb;
69933 -static atomic_t kgdb_break_tasklet_var;
69934 +static atomic_unchecked_t kgdb_break_tasklet_var;
69935 atomic_t kgdb_setting_breakpoint;
69936
69937 struct task_struct *kgdb_usethread;
69938 @@ -132,7 +132,7 @@ int kgdb_single_step;
69939 static pid_t kgdb_sstep_pid;
69940
69941 /* to keep track of the CPU which is doing the single stepping*/
69942 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69943 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
69944
69945 /*
69946 * If you are debugging a problem where roundup (the collection of
69947 @@ -540,7 +540,7 @@ return_normal:
69948 * kernel will only try for the value of sstep_tries before
69949 * giving up and continuing on.
69950 */
69951 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
69952 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
69953 (kgdb_info[cpu].task &&
69954 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
69955 atomic_set(&kgdb_active, -1);
69956 @@ -634,8 +634,8 @@ cpu_master_loop:
69957 }
69958
69959 kgdb_restore:
69960 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
69961 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
69962 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
69963 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
69964 if (kgdb_info[sstep_cpu].task)
69965 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
69966 else
69967 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
69968 static void kgdb_tasklet_bpt(unsigned long ing)
69969 {
69970 kgdb_breakpoint();
69971 - atomic_set(&kgdb_break_tasklet_var, 0);
69972 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
69973 }
69974
69975 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
69976
69977 void kgdb_schedule_breakpoint(void)
69978 {
69979 - if (atomic_read(&kgdb_break_tasklet_var) ||
69980 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
69981 atomic_read(&kgdb_active) != -1 ||
69982 atomic_read(&kgdb_setting_breakpoint))
69983 return;
69984 - atomic_inc(&kgdb_break_tasklet_var);
69985 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
69986 tasklet_schedule(&kgdb_tasklet_breakpoint);
69987 }
69988 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
69989 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
69990 index 8875254..7cf4928 100644
69991 --- a/kernel/debug/kdb/kdb_main.c
69992 +++ b/kernel/debug/kdb/kdb_main.c
69993 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
69994 continue;
69995
69996 kdb_printf("%-20s%8u 0x%p ", mod->name,
69997 - mod->core_size, (void *)mod);
69998 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
69999 #ifdef CONFIG_MODULE_UNLOAD
70000 kdb_printf("%4ld ", module_refcount(mod));
70001 #endif
70002 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
70003 kdb_printf(" (Loading)");
70004 else
70005 kdb_printf(" (Live)");
70006 - kdb_printf(" 0x%p", mod->module_core);
70007 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
70008
70009 #ifdef CONFIG_MODULE_UNLOAD
70010 {
70011 diff --git a/kernel/events/core.c b/kernel/events/core.c
70012 index 7b6646a..3cb1135 100644
70013 --- a/kernel/events/core.c
70014 +++ b/kernel/events/core.c
70015 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
70016 return 0;
70017 }
70018
70019 -static atomic64_t perf_event_id;
70020 +static atomic64_unchecked_t perf_event_id;
70021
70022 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
70023 enum event_type_t event_type);
70024 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
70025
70026 static inline u64 perf_event_count(struct perf_event *event)
70027 {
70028 - return local64_read(&event->count) + atomic64_read(&event->child_count);
70029 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
70030 }
70031
70032 static u64 perf_event_read(struct perf_event *event)
70033 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
70034 mutex_lock(&event->child_mutex);
70035 total += perf_event_read(event);
70036 *enabled += event->total_time_enabled +
70037 - atomic64_read(&event->child_total_time_enabled);
70038 + atomic64_read_unchecked(&event->child_total_time_enabled);
70039 *running += event->total_time_running +
70040 - atomic64_read(&event->child_total_time_running);
70041 + atomic64_read_unchecked(&event->child_total_time_running);
70042
70043 list_for_each_entry(child, &event->child_list, child_list) {
70044 total += perf_event_read(child);
70045 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
70046 userpg->offset -= local64_read(&event->hw.prev_count);
70047
70048 userpg->time_enabled = enabled +
70049 - atomic64_read(&event->child_total_time_enabled);
70050 + atomic64_read_unchecked(&event->child_total_time_enabled);
70051
70052 userpg->time_running = running +
70053 - atomic64_read(&event->child_total_time_running);
70054 + atomic64_read_unchecked(&event->child_total_time_running);
70055
70056 arch_perf_update_userpage(userpg, now);
70057
70058 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
70059 values[n++] = perf_event_count(event);
70060 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
70061 values[n++] = enabled +
70062 - atomic64_read(&event->child_total_time_enabled);
70063 + atomic64_read_unchecked(&event->child_total_time_enabled);
70064 }
70065 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
70066 values[n++] = running +
70067 - atomic64_read(&event->child_total_time_running);
70068 + atomic64_read_unchecked(&event->child_total_time_running);
70069 }
70070 if (read_format & PERF_FORMAT_ID)
70071 values[n++] = primary_event_id(event);
70072 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
70073 * need to add enough zero bytes after the string to handle
70074 * the 64bit alignment we do later.
70075 */
70076 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
70077 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
70078 if (!buf) {
70079 name = strncpy(tmp, "//enomem", sizeof(tmp));
70080 goto got_name;
70081 }
70082 - name = d_path(&file->f_path, buf, PATH_MAX);
70083 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
70084 if (IS_ERR(name)) {
70085 name = strncpy(tmp, "//toolong", sizeof(tmp));
70086 goto got_name;
70087 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
70088 event->parent = parent_event;
70089
70090 event->ns = get_pid_ns(task_active_pid_ns(current));
70091 - event->id = atomic64_inc_return(&perf_event_id);
70092 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
70093
70094 event->state = PERF_EVENT_STATE_INACTIVE;
70095
70096 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
70097 /*
70098 * Add back the child's count to the parent's count:
70099 */
70100 - atomic64_add(child_val, &parent_event->child_count);
70101 - atomic64_add(child_event->total_time_enabled,
70102 + atomic64_add_unchecked(child_val, &parent_event->child_count);
70103 + atomic64_add_unchecked(child_event->total_time_enabled,
70104 &parent_event->child_total_time_enabled);
70105 - atomic64_add(child_event->total_time_running,
70106 + atomic64_add_unchecked(child_event->total_time_running,
70107 &parent_event->child_total_time_running);
70108
70109 /*
70110 diff --git a/kernel/exit.c b/kernel/exit.c
70111 index b4df219..f13c02d 100644
70112 --- a/kernel/exit.c
70113 +++ b/kernel/exit.c
70114 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
70115 struct task_struct *leader;
70116 int zap_leader;
70117 repeat:
70118 +#ifdef CONFIG_NET
70119 + gr_del_task_from_ip_table(p);
70120 +#endif
70121 +
70122 /* don't need to get the RCU readlock here - the process is dead and
70123 * can't be modifying its own credentials. But shut RCU-lockdep up */
70124 rcu_read_lock();
70125 @@ -338,7 +342,7 @@ int allow_signal(int sig)
70126 * know it'll be handled, so that they don't get converted to
70127 * SIGKILL or just silently dropped.
70128 */
70129 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
70130 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
70131 recalc_sigpending();
70132 spin_unlock_irq(&current->sighand->siglock);
70133 return 0;
70134 @@ -708,6 +712,8 @@ void do_exit(long code)
70135 struct task_struct *tsk = current;
70136 int group_dead;
70137
70138 + set_fs(USER_DS);
70139 +
70140 profile_task_exit(tsk);
70141
70142 WARN_ON(blk_needs_flush_plug(tsk));
70143 @@ -724,7 +730,6 @@ void do_exit(long code)
70144 * mm_release()->clear_child_tid() from writing to a user-controlled
70145 * kernel address.
70146 */
70147 - set_fs(USER_DS);
70148
70149 ptrace_event(PTRACE_EVENT_EXIT, code);
70150
70151 @@ -783,6 +788,9 @@ void do_exit(long code)
70152 tsk->exit_code = code;
70153 taskstats_exit(tsk, group_dead);
70154
70155 + gr_acl_handle_psacct(tsk, code);
70156 + gr_acl_handle_exit();
70157 +
70158 exit_mm(tsk);
70159
70160 if (group_dead)
70161 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
70162 * Take down every thread in the group. This is called by fatal signals
70163 * as well as by sys_exit_group (below).
70164 */
70165 -void
70166 +__noreturn void
70167 do_group_exit(int exit_code)
70168 {
70169 struct signal_struct *sig = current->signal;
70170 diff --git a/kernel/fork.c b/kernel/fork.c
70171 index c535f33..1d768f9 100644
70172 --- a/kernel/fork.c
70173 +++ b/kernel/fork.c
70174 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
70175 *stackend = STACK_END_MAGIC; /* for overflow detection */
70176
70177 #ifdef CONFIG_CC_STACKPROTECTOR
70178 - tsk->stack_canary = get_random_int();
70179 + tsk->stack_canary = pax_get_random_long();
70180 #endif
70181
70182 /*
70183 @@ -344,13 +344,81 @@ free_tsk:
70184 }
70185
70186 #ifdef CONFIG_MMU
70187 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
70188 +{
70189 + struct vm_area_struct *tmp;
70190 + unsigned long charge;
70191 + struct mempolicy *pol;
70192 + struct file *file;
70193 +
70194 + charge = 0;
70195 + if (mpnt->vm_flags & VM_ACCOUNT) {
70196 + unsigned long len = vma_pages(mpnt);
70197 +
70198 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70199 + goto fail_nomem;
70200 + charge = len;
70201 + }
70202 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70203 + if (!tmp)
70204 + goto fail_nomem;
70205 + *tmp = *mpnt;
70206 + tmp->vm_mm = mm;
70207 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
70208 + pol = mpol_dup(vma_policy(mpnt));
70209 + if (IS_ERR(pol))
70210 + goto fail_nomem_policy;
70211 + vma_set_policy(tmp, pol);
70212 + if (anon_vma_fork(tmp, mpnt))
70213 + goto fail_nomem_anon_vma_fork;
70214 + tmp->vm_flags &= ~VM_LOCKED;
70215 + tmp->vm_next = tmp->vm_prev = NULL;
70216 + tmp->vm_mirror = NULL;
70217 + file = tmp->vm_file;
70218 + if (file) {
70219 + struct inode *inode = file->f_path.dentry->d_inode;
70220 + struct address_space *mapping = file->f_mapping;
70221 +
70222 + get_file(file);
70223 + if (tmp->vm_flags & VM_DENYWRITE)
70224 + atomic_dec(&inode->i_writecount);
70225 + mutex_lock(&mapping->i_mmap_mutex);
70226 + if (tmp->vm_flags & VM_SHARED)
70227 + mapping->i_mmap_writable++;
70228 + flush_dcache_mmap_lock(mapping);
70229 + /* insert tmp into the share list, just after mpnt */
70230 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70231 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
70232 + else
70233 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
70234 + flush_dcache_mmap_unlock(mapping);
70235 + mutex_unlock(&mapping->i_mmap_mutex);
70236 + }
70237 +
70238 + /*
70239 + * Clear hugetlb-related page reserves for children. This only
70240 + * affects MAP_PRIVATE mappings. Faults generated by the child
70241 + * are not guaranteed to succeed, even if read-only
70242 + */
70243 + if (is_vm_hugetlb_page(tmp))
70244 + reset_vma_resv_huge_pages(tmp);
70245 +
70246 + return tmp;
70247 +
70248 +fail_nomem_anon_vma_fork:
70249 + mpol_put(pol);
70250 +fail_nomem_policy:
70251 + kmem_cache_free(vm_area_cachep, tmp);
70252 +fail_nomem:
70253 + vm_unacct_memory(charge);
70254 + return NULL;
70255 +}
70256 +
70257 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70258 {
70259 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
70260 struct rb_node **rb_link, *rb_parent;
70261 int retval;
70262 - unsigned long charge;
70263 - struct mempolicy *pol;
70264
70265 uprobe_start_dup_mmap();
70266 down_write(&oldmm->mmap_sem);
70267 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70268 mm->locked_vm = 0;
70269 mm->mmap = NULL;
70270 mm->mmap_cache = NULL;
70271 - mm->free_area_cache = oldmm->mmap_base;
70272 - mm->cached_hole_size = ~0UL;
70273 + mm->free_area_cache = oldmm->free_area_cache;
70274 + mm->cached_hole_size = oldmm->cached_hole_size;
70275 mm->map_count = 0;
70276 cpumask_clear(mm_cpumask(mm));
70277 mm->mm_rb = RB_ROOT;
70278 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70279
70280 prev = NULL;
70281 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
70282 - struct file *file;
70283 -
70284 if (mpnt->vm_flags & VM_DONTCOPY) {
70285 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
70286 -vma_pages(mpnt));
70287 continue;
70288 }
70289 - charge = 0;
70290 - if (mpnt->vm_flags & VM_ACCOUNT) {
70291 - unsigned long len = vma_pages(mpnt);
70292 -
70293 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
70294 - goto fail_nomem;
70295 - charge = len;
70296 - }
70297 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
70298 - if (!tmp)
70299 - goto fail_nomem;
70300 - *tmp = *mpnt;
70301 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
70302 - pol = mpol_dup(vma_policy(mpnt));
70303 - retval = PTR_ERR(pol);
70304 - if (IS_ERR(pol))
70305 - goto fail_nomem_policy;
70306 - vma_set_policy(tmp, pol);
70307 - tmp->vm_mm = mm;
70308 - if (anon_vma_fork(tmp, mpnt))
70309 - goto fail_nomem_anon_vma_fork;
70310 - tmp->vm_flags &= ~VM_LOCKED;
70311 - tmp->vm_next = tmp->vm_prev = NULL;
70312 - file = tmp->vm_file;
70313 - if (file) {
70314 - struct inode *inode = file->f_path.dentry->d_inode;
70315 - struct address_space *mapping = file->f_mapping;
70316 -
70317 - get_file(file);
70318 - if (tmp->vm_flags & VM_DENYWRITE)
70319 - atomic_dec(&inode->i_writecount);
70320 - mutex_lock(&mapping->i_mmap_mutex);
70321 - if (tmp->vm_flags & VM_SHARED)
70322 - mapping->i_mmap_writable++;
70323 - flush_dcache_mmap_lock(mapping);
70324 - /* insert tmp into the share list, just after mpnt */
70325 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
70326 - vma_nonlinear_insert(tmp,
70327 - &mapping->i_mmap_nonlinear);
70328 - else
70329 - vma_interval_tree_insert_after(tmp, mpnt,
70330 - &mapping->i_mmap);
70331 - flush_dcache_mmap_unlock(mapping);
70332 - mutex_unlock(&mapping->i_mmap_mutex);
70333 + tmp = dup_vma(mm, oldmm, mpnt);
70334 + if (!tmp) {
70335 + retval = -ENOMEM;
70336 + goto out;
70337 }
70338
70339 /*
70340 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
70341 if (retval)
70342 goto out;
70343 }
70344 +
70345 +#ifdef CONFIG_PAX_SEGMEXEC
70346 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
70347 + struct vm_area_struct *mpnt_m;
70348 +
70349 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
70350 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
70351 +
70352 + if (!mpnt->vm_mirror)
70353 + continue;
70354 +
70355 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
70356 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
70357 + mpnt->vm_mirror = mpnt_m;
70358 + } else {
70359 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
70360 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
70361 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
70362 + mpnt->vm_mirror->vm_mirror = mpnt;
70363 + }
70364 + }
70365 + BUG_ON(mpnt_m);
70366 + }
70367 +#endif
70368 +
70369 /* a new mm has just been created */
70370 arch_dup_mmap(oldmm, mm);
70371 retval = 0;
70372 @@ -472,14 +523,6 @@ out:
70373 up_write(&oldmm->mmap_sem);
70374 uprobe_end_dup_mmap();
70375 return retval;
70376 -fail_nomem_anon_vma_fork:
70377 - mpol_put(pol);
70378 -fail_nomem_policy:
70379 - kmem_cache_free(vm_area_cachep, tmp);
70380 -fail_nomem:
70381 - retval = -ENOMEM;
70382 - vm_unacct_memory(charge);
70383 - goto out;
70384 }
70385
70386 static inline int mm_alloc_pgd(struct mm_struct *mm)
70387 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
70388 return ERR_PTR(err);
70389
70390 mm = get_task_mm(task);
70391 - if (mm && mm != current->mm &&
70392 - !ptrace_may_access(task, mode)) {
70393 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
70394 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
70395 mmput(mm);
70396 mm = ERR_PTR(-EACCES);
70397 }
70398 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
70399 spin_unlock(&fs->lock);
70400 return -EAGAIN;
70401 }
70402 - fs->users++;
70403 + atomic_inc(&fs->users);
70404 spin_unlock(&fs->lock);
70405 return 0;
70406 }
70407 tsk->fs = copy_fs_struct(fs);
70408 if (!tsk->fs)
70409 return -ENOMEM;
70410 + /* Carry through gr_chroot_dentry and is_chrooted instead
70411 + of recomputing it here. Already copied when the task struct
70412 + is duplicated. This allows pivot_root to not be treated as
70413 + a chroot
70414 + */
70415 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
70416 +
70417 return 0;
70418 }
70419
70420 @@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70421 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
70422 #endif
70423 retval = -EAGAIN;
70424 +
70425 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
70426 +
70427 if (atomic_read(&p->real_cred->user->processes) >=
70428 task_rlimit(p, RLIMIT_NPROC)) {
70429 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
70430 @@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
70431 goto bad_fork_free_pid;
70432 }
70433
70434 + /* synchronizes with gr_set_acls()
70435 + we need to call this past the point of no return for fork()
70436 + */
70437 + gr_copy_label(p);
70438 +
70439 if (clone_flags & CLONE_THREAD) {
70440 current->signal->nr_threads++;
70441 atomic_inc(&current->signal->live);
70442 @@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
70443 bad_fork_free:
70444 free_task(p);
70445 fork_out:
70446 + gr_log_forkfail(retval);
70447 +
70448 return ERR_PTR(retval);
70449 }
70450
70451 @@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
70452 return -EINVAL;
70453 }
70454
70455 +#ifdef CONFIG_GRKERNSEC
70456 + if (clone_flags & CLONE_NEWUSER) {
70457 + /*
70458 + * This doesn't really inspire confidence:
70459 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
70460 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
70461 + * Increases kernel attack surface in areas developers
70462 + * previously cared little about ("low importance due
70463 + * to requiring "root" capability")
70464 + * To be removed when this code receives *proper* review
70465 + */
70466 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
70467 + !capable(CAP_SETGID))
70468 + return -EPERM;
70469 + }
70470 +#endif
70471 +
70472 /*
70473 * Determine whether and which event to report to ptracer. When
70474 * called from kernel_thread or CLONE_UNTRACED is explicitly
70475 @@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
70476 if (clone_flags & CLONE_PARENT_SETTID)
70477 put_user(nr, parent_tidptr);
70478
70479 + gr_handle_brute_check();
70480 +
70481 if (clone_flags & CLONE_VFORK) {
70482 p->vfork_done = &vfork;
70483 init_completion(&vfork);
70484 @@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
70485 return 0;
70486
70487 /* don't need lock here; in the worst case we'll do useless copy */
70488 - if (fs->users == 1)
70489 + if (atomic_read(&fs->users) == 1)
70490 return 0;
70491
70492 *new_fsp = copy_fs_struct(fs);
70493 @@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
70494 fs = current->fs;
70495 spin_lock(&fs->lock);
70496 current->fs = new_fs;
70497 - if (--fs->users)
70498 + gr_set_chroot_entries(current, &current->fs->root);
70499 + if (atomic_dec_return(&fs->users))
70500 new_fs = NULL;
70501 else
70502 new_fs = fs;
70503 diff --git a/kernel/futex.c b/kernel/futex.c
70504 index 19eb089..b8c65ea 100644
70505 --- a/kernel/futex.c
70506 +++ b/kernel/futex.c
70507 @@ -54,6 +54,7 @@
70508 #include <linux/mount.h>
70509 #include <linux/pagemap.h>
70510 #include <linux/syscalls.h>
70511 +#include <linux/ptrace.h>
70512 #include <linux/signal.h>
70513 #include <linux/export.h>
70514 #include <linux/magic.h>
70515 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
70516 struct page *page, *page_head;
70517 int err, ro = 0;
70518
70519 +#ifdef CONFIG_PAX_SEGMEXEC
70520 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
70521 + return -EFAULT;
70522 +#endif
70523 +
70524 /*
70525 * The futex address must be "naturally" aligned.
70526 */
70527 @@ -2733,6 +2739,7 @@ static int __init futex_init(void)
70528 {
70529 u32 curval;
70530 int i;
70531 + mm_segment_t oldfs;
70532
70533 /*
70534 * This will fail and we want it. Some arch implementations do
70535 @@ -2744,8 +2751,11 @@ static int __init futex_init(void)
70536 * implementation, the non-functional ones will return
70537 * -ENOSYS.
70538 */
70539 + oldfs = get_fs();
70540 + set_fs(USER_DS);
70541 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
70542 futex_cmpxchg_enabled = 1;
70543 + set_fs(oldfs);
70544
70545 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
70546 plist_head_init(&futex_queues[i].chain);
70547 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
70548 index 9b22d03..6295b62 100644
70549 --- a/kernel/gcov/base.c
70550 +++ b/kernel/gcov/base.c
70551 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
70552 }
70553
70554 #ifdef CONFIG_MODULES
70555 -static inline int within(void *addr, void *start, unsigned long size)
70556 -{
70557 - return ((addr >= start) && (addr < start + size));
70558 -}
70559 -
70560 /* Update list and generate events when modules are unloaded. */
70561 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70562 void *data)
70563 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
70564 prev = NULL;
70565 /* Remove entries located in module from linked list. */
70566 for (info = gcov_info_head; info; info = info->next) {
70567 - if (within(info, mod->module_core, mod->core_size)) {
70568 + if (within_module_core_rw((unsigned long)info, mod)) {
70569 if (prev)
70570 prev->next = info->next;
70571 else
70572 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
70573 index 6db7a5e..0d600bd 100644
70574 --- a/kernel/hrtimer.c
70575 +++ b/kernel/hrtimer.c
70576 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
70577 local_irq_restore(flags);
70578 }
70579
70580 -static void run_hrtimer_softirq(struct softirq_action *h)
70581 +static void run_hrtimer_softirq(void)
70582 {
70583 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
70584
70585 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
70586 return NOTIFY_OK;
70587 }
70588
70589 -static struct notifier_block __cpuinitdata hrtimers_nb = {
70590 +static struct notifier_block hrtimers_nb = {
70591 .notifier_call = hrtimer_cpu_notify,
70592 };
70593
70594 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
70595 index 60f48fa..7f3a770 100644
70596 --- a/kernel/jump_label.c
70597 +++ b/kernel/jump_label.c
70598 @@ -13,6 +13,7 @@
70599 #include <linux/sort.h>
70600 #include <linux/err.h>
70601 #include <linux/static_key.h>
70602 +#include <linux/mm.h>
70603
70604 #ifdef HAVE_JUMP_LABEL
70605
70606 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
70607
70608 size = (((unsigned long)stop - (unsigned long)start)
70609 / sizeof(struct jump_entry));
70610 + pax_open_kernel();
70611 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
70612 + pax_close_kernel();
70613 }
70614
70615 static void jump_label_update(struct static_key *key, int enable);
70616 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
70617 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
70618 struct jump_entry *iter;
70619
70620 + pax_open_kernel();
70621 for (iter = iter_start; iter < iter_stop; iter++) {
70622 if (within_module_init(iter->code, mod))
70623 iter->code = 0;
70624 }
70625 + pax_close_kernel();
70626 }
70627
70628 static int
70629 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
70630 index 2169fee..45c017a 100644
70631 --- a/kernel/kallsyms.c
70632 +++ b/kernel/kallsyms.c
70633 @@ -11,6 +11,9 @@
70634 * Changed the compression method from stem compression to "table lookup"
70635 * compression (see scripts/kallsyms.c for a more complete description)
70636 */
70637 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70638 +#define __INCLUDED_BY_HIDESYM 1
70639 +#endif
70640 #include <linux/kallsyms.h>
70641 #include <linux/module.h>
70642 #include <linux/init.h>
70643 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
70644
70645 static inline int is_kernel_inittext(unsigned long addr)
70646 {
70647 + if (system_state != SYSTEM_BOOTING)
70648 + return 0;
70649 +
70650 if (addr >= (unsigned long)_sinittext
70651 && addr <= (unsigned long)_einittext)
70652 return 1;
70653 return 0;
70654 }
70655
70656 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70657 +#ifdef CONFIG_MODULES
70658 +static inline int is_module_text(unsigned long addr)
70659 +{
70660 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
70661 + return 1;
70662 +
70663 + addr = ktla_ktva(addr);
70664 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
70665 +}
70666 +#else
70667 +static inline int is_module_text(unsigned long addr)
70668 +{
70669 + return 0;
70670 +}
70671 +#endif
70672 +#endif
70673 +
70674 static inline int is_kernel_text(unsigned long addr)
70675 {
70676 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
70677 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
70678
70679 static inline int is_kernel(unsigned long addr)
70680 {
70681 +
70682 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70683 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
70684 + return 1;
70685 +
70686 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
70687 +#else
70688 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
70689 +#endif
70690 +
70691 return 1;
70692 return in_gate_area_no_mm(addr);
70693 }
70694
70695 static int is_ksym_addr(unsigned long addr)
70696 {
70697 +
70698 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
70699 + if (is_module_text(addr))
70700 + return 0;
70701 +#endif
70702 +
70703 if (all_var)
70704 return is_kernel(addr);
70705
70706 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
70707
70708 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
70709 {
70710 - iter->name[0] = '\0';
70711 iter->nameoff = get_symbol_offset(new_pos);
70712 iter->pos = new_pos;
70713 }
70714 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
70715 {
70716 struct kallsym_iter *iter = m->private;
70717
70718 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70719 + if (current_uid())
70720 + return 0;
70721 +#endif
70722 +
70723 /* Some debugging symbols have no name. Ignore them. */
70724 if (!iter->name[0])
70725 return 0;
70726 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
70727 */
70728 type = iter->exported ? toupper(iter->type) :
70729 tolower(iter->type);
70730 +
70731 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
70732 type, iter->name, iter->module_name);
70733 } else
70734 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
70735 struct kallsym_iter *iter;
70736 int ret;
70737
70738 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
70739 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
70740 if (!iter)
70741 return -ENOMEM;
70742 reset_iter(iter, 0);
70743 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
70744 index e30ac0f..3528cac 100644
70745 --- a/kernel/kcmp.c
70746 +++ b/kernel/kcmp.c
70747 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
70748 struct task_struct *task1, *task2;
70749 int ret;
70750
70751 +#ifdef CONFIG_GRKERNSEC
70752 + return -ENOSYS;
70753 +#endif
70754 +
70755 rcu_read_lock();
70756
70757 /*
70758 diff --git a/kernel/kexec.c b/kernel/kexec.c
70759 index 5e4bd78..00c5b91 100644
70760 --- a/kernel/kexec.c
70761 +++ b/kernel/kexec.c
70762 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
70763 unsigned long flags)
70764 {
70765 struct compat_kexec_segment in;
70766 - struct kexec_segment out, __user *ksegments;
70767 + struct kexec_segment out;
70768 + struct kexec_segment __user *ksegments;
70769 unsigned long i, result;
70770
70771 /* Don't allow clients that don't understand the native
70772 diff --git a/kernel/kmod.c b/kernel/kmod.c
70773 index 0023a87..3fe3781 100644
70774 --- a/kernel/kmod.c
70775 +++ b/kernel/kmod.c
70776 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
70777 kfree(info->argv);
70778 }
70779
70780 -static int call_modprobe(char *module_name, int wait)
70781 +static int call_modprobe(char *module_name, char *module_param, int wait)
70782 {
70783 static char *envp[] = {
70784 "HOME=/",
70785 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
70786 NULL
70787 };
70788
70789 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
70790 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
70791 if (!argv)
70792 goto out;
70793
70794 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
70795 argv[1] = "-q";
70796 argv[2] = "--";
70797 argv[3] = module_name; /* check free_modprobe_argv() */
70798 - argv[4] = NULL;
70799 + argv[4] = module_param;
70800 + argv[5] = NULL;
70801
70802 return call_usermodehelper_fns(modprobe_path, argv, envp,
70803 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
70804 @@ -120,9 +121,8 @@ out:
70805 * If module auto-loading support is disabled then this function
70806 * becomes a no-operation.
70807 */
70808 -int __request_module(bool wait, const char *fmt, ...)
70809 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
70810 {
70811 - va_list args;
70812 char module_name[MODULE_NAME_LEN];
70813 unsigned int max_modprobes;
70814 int ret;
70815 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
70816 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
70817 static int kmod_loop_msg;
70818
70819 - va_start(args, fmt);
70820 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
70821 - va_end(args);
70822 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
70823 if (ret >= MODULE_NAME_LEN)
70824 return -ENAMETOOLONG;
70825
70826 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
70827 if (ret)
70828 return ret;
70829
70830 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70831 + if (!current_uid()) {
70832 + /* hack to workaround consolekit/udisks stupidity */
70833 + read_lock(&tasklist_lock);
70834 + if (!strcmp(current->comm, "mount") &&
70835 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
70836 + read_unlock(&tasklist_lock);
70837 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
70838 + return -EPERM;
70839 + }
70840 + read_unlock(&tasklist_lock);
70841 + }
70842 +#endif
70843 +
70844 /* If modprobe needs a service that is in a module, we get a recursive
70845 * loop. Limit the number of running kmod threads to max_threads/2 or
70846 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
70847 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
70848
70849 trace_module_request(module_name, wait, _RET_IP_);
70850
70851 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70852 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
70853
70854 atomic_dec(&kmod_concurrent);
70855 return ret;
70856 }
70857 +
70858 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
70859 +{
70860 + va_list args;
70861 + int ret;
70862 +
70863 + va_start(args, fmt);
70864 + ret = ____request_module(wait, module_param, fmt, args);
70865 + va_end(args);
70866 +
70867 + return ret;
70868 +}
70869 +
70870 +int __request_module(bool wait, const char *fmt, ...)
70871 +{
70872 + va_list args;
70873 + int ret;
70874 +
70875 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
70876 + if (current_uid()) {
70877 + char module_param[MODULE_NAME_LEN];
70878 +
70879 + memset(module_param, 0, sizeof(module_param));
70880 +
70881 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
70882 +
70883 + va_start(args, fmt);
70884 + ret = ____request_module(wait, module_param, fmt, args);
70885 + va_end(args);
70886 +
70887 + return ret;
70888 + }
70889 +#endif
70890 +
70891 + va_start(args, fmt);
70892 + ret = ____request_module(wait, NULL, fmt, args);
70893 + va_end(args);
70894 +
70895 + return ret;
70896 +}
70897 +
70898 EXPORT_SYMBOL(__request_module);
70899 #endif /* CONFIG_MODULES */
70900
70901 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
70902 *
70903 * Thus the __user pointer cast is valid here.
70904 */
70905 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
70906 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
70907
70908 /*
70909 * If ret is 0, either ____call_usermodehelper failed and the
70910 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
70911 index 098f396..fe85ff1 100644
70912 --- a/kernel/kprobes.c
70913 +++ b/kernel/kprobes.c
70914 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
70915 * kernel image and loaded module images reside. This is required
70916 * so x86_64 can correctly handle the %rip-relative fixups.
70917 */
70918 - kip->insns = module_alloc(PAGE_SIZE);
70919 + kip->insns = module_alloc_exec(PAGE_SIZE);
70920 if (!kip->insns) {
70921 kfree(kip);
70922 return NULL;
70923 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
70924 */
70925 if (!list_is_singular(&kip->list)) {
70926 list_del(&kip->list);
70927 - module_free(NULL, kip->insns);
70928 + module_free_exec(NULL, kip->insns);
70929 kfree(kip);
70930 }
70931 return 1;
70932 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
70933 {
70934 int i, err = 0;
70935 unsigned long offset = 0, size = 0;
70936 - char *modname, namebuf[128];
70937 + char *modname, namebuf[KSYM_NAME_LEN];
70938 const char *symbol_name;
70939 void *addr;
70940 struct kprobe_blackpoint *kb;
70941 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
70942 kprobe_type = "k";
70943
70944 if (sym)
70945 - seq_printf(pi, "%p %s %s+0x%x %s ",
70946 + seq_printf(pi, "%pK %s %s+0x%x %s ",
70947 p->addr, kprobe_type, sym, offset,
70948 (modname ? modname : " "));
70949 else
70950 - seq_printf(pi, "%p %s %p ",
70951 + seq_printf(pi, "%pK %s %pK ",
70952 p->addr, kprobe_type, p->addr);
70953
70954 if (!pp)
70955 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
70956 const char *sym = NULL;
70957 unsigned int i = *(loff_t *) v;
70958 unsigned long offset = 0;
70959 - char *modname, namebuf[128];
70960 + char *modname, namebuf[KSYM_NAME_LEN];
70961
70962 head = &kprobe_table[i];
70963 preempt_disable();
70964 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
70965 index 6ada93c..55baf4d 100644
70966 --- a/kernel/ksysfs.c
70967 +++ b/kernel/ksysfs.c
70968 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
70969 {
70970 if (count+1 > UEVENT_HELPER_PATH_LEN)
70971 return -ENOENT;
70972 + if (!capable(CAP_SYS_ADMIN))
70973 + return -EPERM;
70974 memcpy(uevent_helper, buf, count);
70975 uevent_helper[count] = '\0';
70976 if (count && uevent_helper[count-1] == '\n')
70977 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
70978 index 7981e5b..7f2105c 100644
70979 --- a/kernel/lockdep.c
70980 +++ b/kernel/lockdep.c
70981 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
70982 end = (unsigned long) &_end,
70983 addr = (unsigned long) obj;
70984
70985 +#ifdef CONFIG_PAX_KERNEXEC
70986 + start = ktla_ktva(start);
70987 +#endif
70988 +
70989 /*
70990 * static variable?
70991 */
70992 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
70993 if (!static_obj(lock->key)) {
70994 debug_locks_off();
70995 printk("INFO: trying to register non-static key.\n");
70996 + printk("lock:%pS key:%pS.\n", lock, lock->key);
70997 printk("the code is fine but needs lockdep annotation.\n");
70998 printk("turning off the locking correctness validator.\n");
70999 dump_stack();
71000 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
71001 if (!class)
71002 return 0;
71003 }
71004 - atomic_inc((atomic_t *)&class->ops);
71005 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
71006 if (very_verbose(class)) {
71007 printk("\nacquire class [%p] %s", class->key, class->name);
71008 if (class->name_version > 1)
71009 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
71010 index b2c71c5..7b88d63 100644
71011 --- a/kernel/lockdep_proc.c
71012 +++ b/kernel/lockdep_proc.c
71013 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
71014 return 0;
71015 }
71016
71017 - seq_printf(m, "%p", class->key);
71018 + seq_printf(m, "%pK", class->key);
71019 #ifdef CONFIG_DEBUG_LOCKDEP
71020 seq_printf(m, " OPS:%8ld", class->ops);
71021 #endif
71022 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
71023
71024 list_for_each_entry(entry, &class->locks_after, entry) {
71025 if (entry->distance == 1) {
71026 - seq_printf(m, " -> [%p] ", entry->class->key);
71027 + seq_printf(m, " -> [%pK] ", entry->class->key);
71028 print_name(m, entry->class);
71029 seq_puts(m, "\n");
71030 }
71031 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
71032 if (!class->key)
71033 continue;
71034
71035 - seq_printf(m, "[%p] ", class->key);
71036 + seq_printf(m, "[%pK] ", class->key);
71037 print_name(m, class);
71038 seq_puts(m, "\n");
71039 }
71040 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
71041 if (!i)
71042 seq_line(m, '-', 40-namelen, namelen);
71043
71044 - snprintf(ip, sizeof(ip), "[<%p>]",
71045 + snprintf(ip, sizeof(ip), "[<%pK>]",
71046 (void *)class->contention_point[i]);
71047 seq_printf(m, "%40s %14lu %29s %pS\n",
71048 name, stats->contention_point[i],
71049 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
71050 if (!i)
71051 seq_line(m, '-', 40-namelen, namelen);
71052
71053 - snprintf(ip, sizeof(ip), "[<%p>]",
71054 + snprintf(ip, sizeof(ip), "[<%pK>]",
71055 (void *)class->contending_point[i]);
71056 seq_printf(m, "%40s %14lu %29s %pS\n",
71057 name, stats->contending_point[i],
71058 diff --git a/kernel/module.c b/kernel/module.c
71059 index eab0827..75ede66 100644
71060 --- a/kernel/module.c
71061 +++ b/kernel/module.c
71062 @@ -61,6 +61,7 @@
71063 #include <linux/pfn.h>
71064 #include <linux/bsearch.h>
71065 #include <linux/fips.h>
71066 +#include <linux/grsecurity.h>
71067 #include <uapi/linux/module.h>
71068 #include "module-internal.h"
71069
71070 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
71071
71072 /* Bounds of module allocation, for speeding __module_address.
71073 * Protected by module_mutex. */
71074 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
71075 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
71076 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
71077
71078 int register_module_notifier(struct notifier_block * nb)
71079 {
71080 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71081 return true;
71082
71083 list_for_each_entry_rcu(mod, &modules, list) {
71084 - struct symsearch arr[] = {
71085 + struct symsearch modarr[] = {
71086 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
71087 NOT_GPL_ONLY, false },
71088 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
71089 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
71090 if (mod->state == MODULE_STATE_UNFORMED)
71091 continue;
71092
71093 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
71094 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
71095 return true;
71096 }
71097 return false;
71098 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
71099 static int percpu_modalloc(struct module *mod,
71100 unsigned long size, unsigned long align)
71101 {
71102 - if (align > PAGE_SIZE) {
71103 + if (align-1 >= PAGE_SIZE) {
71104 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
71105 mod->name, align, PAGE_SIZE);
71106 align = PAGE_SIZE;
71107 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
71108 static ssize_t show_coresize(struct module_attribute *mattr,
71109 struct module_kobject *mk, char *buffer)
71110 {
71111 - return sprintf(buffer, "%u\n", mk->mod->core_size);
71112 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
71113 }
71114
71115 static struct module_attribute modinfo_coresize =
71116 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
71117 static ssize_t show_initsize(struct module_attribute *mattr,
71118 struct module_kobject *mk, char *buffer)
71119 {
71120 - return sprintf(buffer, "%u\n", mk->mod->init_size);
71121 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
71122 }
71123
71124 static struct module_attribute modinfo_initsize =
71125 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
71126 */
71127 #ifdef CONFIG_SYSFS
71128
71129 -#ifdef CONFIG_KALLSYMS
71130 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
71131 static inline bool sect_empty(const Elf_Shdr *sect)
71132 {
71133 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
71134 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
71135
71136 static void unset_module_core_ro_nx(struct module *mod)
71137 {
71138 - set_page_attributes(mod->module_core + mod->core_text_size,
71139 - mod->module_core + mod->core_size,
71140 + set_page_attributes(mod->module_core_rw,
71141 + mod->module_core_rw + mod->core_size_rw,
71142 set_memory_x);
71143 - set_page_attributes(mod->module_core,
71144 - mod->module_core + mod->core_ro_size,
71145 + set_page_attributes(mod->module_core_rx,
71146 + mod->module_core_rx + mod->core_size_rx,
71147 set_memory_rw);
71148 }
71149
71150 static void unset_module_init_ro_nx(struct module *mod)
71151 {
71152 - set_page_attributes(mod->module_init + mod->init_text_size,
71153 - mod->module_init + mod->init_size,
71154 + set_page_attributes(mod->module_init_rw,
71155 + mod->module_init_rw + mod->init_size_rw,
71156 set_memory_x);
71157 - set_page_attributes(mod->module_init,
71158 - mod->module_init + mod->init_ro_size,
71159 + set_page_attributes(mod->module_init_rx,
71160 + mod->module_init_rx + mod->init_size_rx,
71161 set_memory_rw);
71162 }
71163
71164 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
71165 list_for_each_entry_rcu(mod, &modules, list) {
71166 if (mod->state == MODULE_STATE_UNFORMED)
71167 continue;
71168 - if ((mod->module_core) && (mod->core_text_size)) {
71169 - set_page_attributes(mod->module_core,
71170 - mod->module_core + mod->core_text_size,
71171 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
71172 + set_page_attributes(mod->module_core_rx,
71173 + mod->module_core_rx + mod->core_size_rx,
71174 set_memory_rw);
71175 }
71176 - if ((mod->module_init) && (mod->init_text_size)) {
71177 - set_page_attributes(mod->module_init,
71178 - mod->module_init + mod->init_text_size,
71179 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
71180 + set_page_attributes(mod->module_init_rx,
71181 + mod->module_init_rx + mod->init_size_rx,
71182 set_memory_rw);
71183 }
71184 }
71185 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
71186 list_for_each_entry_rcu(mod, &modules, list) {
71187 if (mod->state == MODULE_STATE_UNFORMED)
71188 continue;
71189 - if ((mod->module_core) && (mod->core_text_size)) {
71190 - set_page_attributes(mod->module_core,
71191 - mod->module_core + mod->core_text_size,
71192 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
71193 + set_page_attributes(mod->module_core_rx,
71194 + mod->module_core_rx + mod->core_size_rx,
71195 set_memory_ro);
71196 }
71197 - if ((mod->module_init) && (mod->init_text_size)) {
71198 - set_page_attributes(mod->module_init,
71199 - mod->module_init + mod->init_text_size,
71200 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
71201 + set_page_attributes(mod->module_init_rx,
71202 + mod->module_init_rx + mod->init_size_rx,
71203 set_memory_ro);
71204 }
71205 }
71206 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
71207
71208 /* This may be NULL, but that's OK */
71209 unset_module_init_ro_nx(mod);
71210 - module_free(mod, mod->module_init);
71211 + module_free(mod, mod->module_init_rw);
71212 + module_free_exec(mod, mod->module_init_rx);
71213 kfree(mod->args);
71214 percpu_modfree(mod);
71215
71216 /* Free lock-classes: */
71217 - lockdep_free_key_range(mod->module_core, mod->core_size);
71218 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
71219 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
71220
71221 /* Finally, free the core (containing the module structure) */
71222 unset_module_core_ro_nx(mod);
71223 - module_free(mod, mod->module_core);
71224 + module_free_exec(mod, mod->module_core_rx);
71225 + module_free(mod, mod->module_core_rw);
71226
71227 #ifdef CONFIG_MPU
71228 update_protections(current->mm);
71229 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71230 int ret = 0;
71231 const struct kernel_symbol *ksym;
71232
71233 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71234 + int is_fs_load = 0;
71235 + int register_filesystem_found = 0;
71236 + char *p;
71237 +
71238 + p = strstr(mod->args, "grsec_modharden_fs");
71239 + if (p) {
71240 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
71241 + /* copy \0 as well */
71242 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
71243 + is_fs_load = 1;
71244 + }
71245 +#endif
71246 +
71247 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
71248 const char *name = info->strtab + sym[i].st_name;
71249
71250 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71251 + /* it's a real shame this will never get ripped and copied
71252 + upstream! ;(
71253 + */
71254 + if (is_fs_load && !strcmp(name, "register_filesystem"))
71255 + register_filesystem_found = 1;
71256 +#endif
71257 +
71258 switch (sym[i].st_shndx) {
71259 case SHN_COMMON:
71260 /* We compiled with -fno-common. These are not
71261 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71262 ksym = resolve_symbol_wait(mod, info, name);
71263 /* Ok if resolved. */
71264 if (ksym && !IS_ERR(ksym)) {
71265 + pax_open_kernel();
71266 sym[i].st_value = ksym->value;
71267 + pax_close_kernel();
71268 break;
71269 }
71270
71271 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
71272 secbase = (unsigned long)mod_percpu(mod);
71273 else
71274 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
71275 + pax_open_kernel();
71276 sym[i].st_value += secbase;
71277 + pax_close_kernel();
71278 break;
71279 }
71280 }
71281
71282 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71283 + if (is_fs_load && !register_filesystem_found) {
71284 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
71285 + ret = -EPERM;
71286 + }
71287 +#endif
71288 +
71289 return ret;
71290 }
71291
71292 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
71293 || s->sh_entsize != ~0UL
71294 || strstarts(sname, ".init"))
71295 continue;
71296 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
71297 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71298 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
71299 + else
71300 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
71301 pr_debug("\t%s\n", sname);
71302 }
71303 - switch (m) {
71304 - case 0: /* executable */
71305 - mod->core_size = debug_align(mod->core_size);
71306 - mod->core_text_size = mod->core_size;
71307 - break;
71308 - case 1: /* RO: text and ro-data */
71309 - mod->core_size = debug_align(mod->core_size);
71310 - mod->core_ro_size = mod->core_size;
71311 - break;
71312 - case 3: /* whole core */
71313 - mod->core_size = debug_align(mod->core_size);
71314 - break;
71315 - }
71316 }
71317
71318 pr_debug("Init section allocation order:\n");
71319 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
71320 || s->sh_entsize != ~0UL
71321 || !strstarts(sname, ".init"))
71322 continue;
71323 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
71324 - | INIT_OFFSET_MASK);
71325 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
71326 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
71327 + else
71328 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
71329 + s->sh_entsize |= INIT_OFFSET_MASK;
71330 pr_debug("\t%s\n", sname);
71331 }
71332 - switch (m) {
71333 - case 0: /* executable */
71334 - mod->init_size = debug_align(mod->init_size);
71335 - mod->init_text_size = mod->init_size;
71336 - break;
71337 - case 1: /* RO: text and ro-data */
71338 - mod->init_size = debug_align(mod->init_size);
71339 - mod->init_ro_size = mod->init_size;
71340 - break;
71341 - case 3: /* whole init */
71342 - mod->init_size = debug_align(mod->init_size);
71343 - break;
71344 - }
71345 }
71346 }
71347
71348 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71349
71350 /* Put symbol section at end of init part of module. */
71351 symsect->sh_flags |= SHF_ALLOC;
71352 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
71353 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
71354 info->index.sym) | INIT_OFFSET_MASK;
71355 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
71356
71357 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
71358 }
71359
71360 /* Append room for core symbols at end of core part. */
71361 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
71362 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
71363 - mod->core_size += strtab_size;
71364 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
71365 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
71366 + mod->core_size_rx += strtab_size;
71367
71368 /* Put string table section at end of init part of module. */
71369 strsect->sh_flags |= SHF_ALLOC;
71370 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
71371 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
71372 info->index.str) | INIT_OFFSET_MASK;
71373 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
71374 }
71375 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71376 /* Make sure we get permanent strtab: don't use info->strtab. */
71377 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
71378
71379 + pax_open_kernel();
71380 +
71381 /* Set types up while we still have access to sections. */
71382 for (i = 0; i < mod->num_symtab; i++)
71383 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
71384
71385 - mod->core_symtab = dst = mod->module_core + info->symoffs;
71386 - mod->core_strtab = s = mod->module_core + info->stroffs;
71387 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
71388 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
71389 src = mod->symtab;
71390 for (ndst = i = 0; i < mod->num_symtab; i++) {
71391 if (i == 0 ||
71392 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
71393 }
71394 }
71395 mod->core_num_syms = ndst;
71396 +
71397 + pax_close_kernel();
71398 }
71399 #else
71400 static inline void layout_symtab(struct module *mod, struct load_info *info)
71401 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
71402 return vmalloc_exec(size);
71403 }
71404
71405 -static void *module_alloc_update_bounds(unsigned long size)
71406 +static void *module_alloc_update_bounds_rw(unsigned long size)
71407 {
71408 void *ret = module_alloc(size);
71409
71410 if (ret) {
71411 mutex_lock(&module_mutex);
71412 /* Update module bounds. */
71413 - if ((unsigned long)ret < module_addr_min)
71414 - module_addr_min = (unsigned long)ret;
71415 - if ((unsigned long)ret + size > module_addr_max)
71416 - module_addr_max = (unsigned long)ret + size;
71417 + if ((unsigned long)ret < module_addr_min_rw)
71418 + module_addr_min_rw = (unsigned long)ret;
71419 + if ((unsigned long)ret + size > module_addr_max_rw)
71420 + module_addr_max_rw = (unsigned long)ret + size;
71421 + mutex_unlock(&module_mutex);
71422 + }
71423 + return ret;
71424 +}
71425 +
71426 +static void *module_alloc_update_bounds_rx(unsigned long size)
71427 +{
71428 + void *ret = module_alloc_exec(size);
71429 +
71430 + if (ret) {
71431 + mutex_lock(&module_mutex);
71432 + /* Update module bounds. */
71433 + if ((unsigned long)ret < module_addr_min_rx)
71434 + module_addr_min_rx = (unsigned long)ret;
71435 + if ((unsigned long)ret + size > module_addr_max_rx)
71436 + module_addr_max_rx = (unsigned long)ret + size;
71437 mutex_unlock(&module_mutex);
71438 }
71439 return ret;
71440 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
71441 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71442 {
71443 const char *modmagic = get_modinfo(info, "vermagic");
71444 + const char *license = get_modinfo(info, "license");
71445 int err;
71446
71447 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
71448 + if (!license || !license_is_gpl_compatible(license))
71449 + return -ENOEXEC;
71450 +#endif
71451 +
71452 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
71453 modmagic = NULL;
71454
71455 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
71456 }
71457
71458 /* Set up license info based on the info section */
71459 - set_license(mod, get_modinfo(info, "license"));
71460 + set_license(mod, license);
71461
71462 return 0;
71463 }
71464 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
71465 void *ptr;
71466
71467 /* Do the allocs. */
71468 - ptr = module_alloc_update_bounds(mod->core_size);
71469 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
71470 /*
71471 * The pointer to this block is stored in the module structure
71472 * which is inside the block. Just mark it as not being a
71473 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
71474 if (!ptr)
71475 return -ENOMEM;
71476
71477 - memset(ptr, 0, mod->core_size);
71478 - mod->module_core = ptr;
71479 + memset(ptr, 0, mod->core_size_rw);
71480 + mod->module_core_rw = ptr;
71481
71482 - if (mod->init_size) {
71483 - ptr = module_alloc_update_bounds(mod->init_size);
71484 + if (mod->init_size_rw) {
71485 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
71486 /*
71487 * The pointer to this block is stored in the module structure
71488 * which is inside the block. This block doesn't need to be
71489 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
71490 */
71491 kmemleak_ignore(ptr);
71492 if (!ptr) {
71493 - module_free(mod, mod->module_core);
71494 + module_free(mod, mod->module_core_rw);
71495 return -ENOMEM;
71496 }
71497 - memset(ptr, 0, mod->init_size);
71498 - mod->module_init = ptr;
71499 + memset(ptr, 0, mod->init_size_rw);
71500 + mod->module_init_rw = ptr;
71501 } else
71502 - mod->module_init = NULL;
71503 + mod->module_init_rw = NULL;
71504 +
71505 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
71506 + kmemleak_not_leak(ptr);
71507 + if (!ptr) {
71508 + if (mod->module_init_rw)
71509 + module_free(mod, mod->module_init_rw);
71510 + module_free(mod, mod->module_core_rw);
71511 + return -ENOMEM;
71512 + }
71513 +
71514 + pax_open_kernel();
71515 + memset(ptr, 0, mod->core_size_rx);
71516 + pax_close_kernel();
71517 + mod->module_core_rx = ptr;
71518 +
71519 + if (mod->init_size_rx) {
71520 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
71521 + kmemleak_ignore(ptr);
71522 + if (!ptr && mod->init_size_rx) {
71523 + module_free_exec(mod, mod->module_core_rx);
71524 + if (mod->module_init_rw)
71525 + module_free(mod, mod->module_init_rw);
71526 + module_free(mod, mod->module_core_rw);
71527 + return -ENOMEM;
71528 + }
71529 +
71530 + pax_open_kernel();
71531 + memset(ptr, 0, mod->init_size_rx);
71532 + pax_close_kernel();
71533 + mod->module_init_rx = ptr;
71534 + } else
71535 + mod->module_init_rx = NULL;
71536
71537 /* Transfer each section which specifies SHF_ALLOC */
71538 pr_debug("final section addresses:\n");
71539 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
71540 if (!(shdr->sh_flags & SHF_ALLOC))
71541 continue;
71542
71543 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
71544 - dest = mod->module_init
71545 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71546 - else
71547 - dest = mod->module_core + shdr->sh_entsize;
71548 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
71549 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71550 + dest = mod->module_init_rw
71551 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71552 + else
71553 + dest = mod->module_init_rx
71554 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
71555 + } else {
71556 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
71557 + dest = mod->module_core_rw + shdr->sh_entsize;
71558 + else
71559 + dest = mod->module_core_rx + shdr->sh_entsize;
71560 + }
71561 +
71562 + if (shdr->sh_type != SHT_NOBITS) {
71563 +
71564 +#ifdef CONFIG_PAX_KERNEXEC
71565 +#ifdef CONFIG_X86_64
71566 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
71567 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
71568 +#endif
71569 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
71570 + pax_open_kernel();
71571 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71572 + pax_close_kernel();
71573 + } else
71574 +#endif
71575
71576 - if (shdr->sh_type != SHT_NOBITS)
71577 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
71578 + }
71579 /* Update sh_addr to point to copy in image. */
71580 - shdr->sh_addr = (unsigned long)dest;
71581 +
71582 +#ifdef CONFIG_PAX_KERNEXEC
71583 + if (shdr->sh_flags & SHF_EXECINSTR)
71584 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
71585 + else
71586 +#endif
71587 +
71588 + shdr->sh_addr = (unsigned long)dest;
71589 pr_debug("\t0x%lx %s\n",
71590 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
71591 }
71592 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
71593 * Do it before processing of module parameters, so the module
71594 * can provide parameter accessor functions of its own.
71595 */
71596 - if (mod->module_init)
71597 - flush_icache_range((unsigned long)mod->module_init,
71598 - (unsigned long)mod->module_init
71599 - + mod->init_size);
71600 - flush_icache_range((unsigned long)mod->module_core,
71601 - (unsigned long)mod->module_core + mod->core_size);
71602 + if (mod->module_init_rx)
71603 + flush_icache_range((unsigned long)mod->module_init_rx,
71604 + (unsigned long)mod->module_init_rx
71605 + + mod->init_size_rx);
71606 + flush_icache_range((unsigned long)mod->module_core_rx,
71607 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
71608
71609 set_fs(old_fs);
71610 }
71611 @@ -2983,8 +3088,10 @@ out:
71612 static void module_deallocate(struct module *mod, struct load_info *info)
71613 {
71614 percpu_modfree(mod);
71615 - module_free(mod, mod->module_init);
71616 - module_free(mod, mod->module_core);
71617 + module_free_exec(mod, mod->module_init_rx);
71618 + module_free_exec(mod, mod->module_core_rx);
71619 + module_free(mod, mod->module_init_rw);
71620 + module_free(mod, mod->module_core_rw);
71621 }
71622
71623 int __weak module_finalize(const Elf_Ehdr *hdr,
71624 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
71625 static int post_relocation(struct module *mod, const struct load_info *info)
71626 {
71627 /* Sort exception table now relocations are done. */
71628 + pax_open_kernel();
71629 sort_extable(mod->extable, mod->extable + mod->num_exentries);
71630 + pax_close_kernel();
71631
71632 /* Copy relocated percpu area over. */
71633 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
71634 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
71635 MODULE_STATE_COMING, mod);
71636
71637 /* Set RO and NX regions for core */
71638 - set_section_ro_nx(mod->module_core,
71639 - mod->core_text_size,
71640 - mod->core_ro_size,
71641 - mod->core_size);
71642 + set_section_ro_nx(mod->module_core_rx,
71643 + mod->core_size_rx,
71644 + mod->core_size_rx,
71645 + mod->core_size_rx);
71646
71647 /* Set RO and NX regions for init */
71648 - set_section_ro_nx(mod->module_init,
71649 - mod->init_text_size,
71650 - mod->init_ro_size,
71651 - mod->init_size);
71652 + set_section_ro_nx(mod->module_init_rx,
71653 + mod->init_size_rx,
71654 + mod->init_size_rx,
71655 + mod->init_size_rx);
71656
71657 do_mod_ctors(mod);
71658 /* Start the module */
71659 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
71660 mod->strtab = mod->core_strtab;
71661 #endif
71662 unset_module_init_ro_nx(mod);
71663 - module_free(mod, mod->module_init);
71664 - mod->module_init = NULL;
71665 - mod->init_size = 0;
71666 - mod->init_ro_size = 0;
71667 - mod->init_text_size = 0;
71668 + module_free(mod, mod->module_init_rw);
71669 + module_free_exec(mod, mod->module_init_rx);
71670 + mod->module_init_rw = NULL;
71671 + mod->module_init_rx = NULL;
71672 + mod->init_size_rw = 0;
71673 + mod->init_size_rx = 0;
71674 mutex_unlock(&module_mutex);
71675 wake_up_all(&module_wq);
71676
71677 @@ -3209,9 +3319,38 @@ again:
71678 if (err)
71679 goto free_unload;
71680
71681 + /* Now copy in args */
71682 + mod->args = strndup_user(uargs, ~0UL >> 1);
71683 + if (IS_ERR(mod->args)) {
71684 + err = PTR_ERR(mod->args);
71685 + goto free_unload;
71686 + }
71687 +
71688 /* Set up MODINFO_ATTR fields */
71689 setup_modinfo(mod, info);
71690
71691 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
71692 + {
71693 + char *p, *p2;
71694 +
71695 + if (strstr(mod->args, "grsec_modharden_netdev")) {
71696 + 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);
71697 + err = -EPERM;
71698 + goto free_modinfo;
71699 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
71700 + p += sizeof("grsec_modharden_normal") - 1;
71701 + p2 = strstr(p, "_");
71702 + if (p2) {
71703 + *p2 = '\0';
71704 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
71705 + *p2 = '_';
71706 + }
71707 + err = -EPERM;
71708 + goto free_modinfo;
71709 + }
71710 + }
71711 +#endif
71712 +
71713 /* Fix up syms, so that st_value is a pointer to location. */
71714 err = simplify_symbols(mod, info);
71715 if (err < 0)
71716 @@ -3227,13 +3366,6 @@ again:
71717
71718 flush_module_icache(mod);
71719
71720 - /* Now copy in args */
71721 - mod->args = strndup_user(uargs, ~0UL >> 1);
71722 - if (IS_ERR(mod->args)) {
71723 - err = PTR_ERR(mod->args);
71724 - goto free_arch_cleanup;
71725 - }
71726 -
71727 dynamic_debug_setup(info->debug, info->num_debug);
71728
71729 mutex_lock(&module_mutex);
71730 @@ -3278,11 +3410,10 @@ again:
71731 mutex_unlock(&module_mutex);
71732 dynamic_debug_remove(info->debug);
71733 synchronize_sched();
71734 - kfree(mod->args);
71735 - free_arch_cleanup:
71736 module_arch_cleanup(mod);
71737 free_modinfo:
71738 free_modinfo(mod);
71739 + kfree(mod->args);
71740 free_unload:
71741 module_unload_free(mod);
71742 unlink_mod:
71743 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
71744 unsigned long nextval;
71745
71746 /* At worse, next value is at end of module */
71747 - if (within_module_init(addr, mod))
71748 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
71749 + if (within_module_init_rx(addr, mod))
71750 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
71751 + else if (within_module_init_rw(addr, mod))
71752 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
71753 + else if (within_module_core_rx(addr, mod))
71754 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
71755 + else if (within_module_core_rw(addr, mod))
71756 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
71757 else
71758 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
71759 + return NULL;
71760
71761 /* Scan for closest preceding symbol, and next symbol. (ELF
71762 starts real symbols at 1). */
71763 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
71764 return 0;
71765
71766 seq_printf(m, "%s %u",
71767 - mod->name, mod->init_size + mod->core_size);
71768 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
71769 print_unload_info(m, mod);
71770
71771 /* Informative for users. */
71772 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
71773 mod->state == MODULE_STATE_COMING ? "Loading":
71774 "Live");
71775 /* Used by oprofile and other similar tools. */
71776 - seq_printf(m, " 0x%pK", mod->module_core);
71777 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
71778
71779 /* Taints info */
71780 if (mod->taints)
71781 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
71782
71783 static int __init proc_modules_init(void)
71784 {
71785 +#ifndef CONFIG_GRKERNSEC_HIDESYM
71786 +#ifdef CONFIG_GRKERNSEC_PROC_USER
71787 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71788 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71789 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
71790 +#else
71791 proc_create("modules", 0, NULL, &proc_modules_operations);
71792 +#endif
71793 +#else
71794 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
71795 +#endif
71796 return 0;
71797 }
71798 module_init(proc_modules_init);
71799 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
71800 {
71801 struct module *mod;
71802
71803 - if (addr < module_addr_min || addr > module_addr_max)
71804 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
71805 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
71806 return NULL;
71807
71808 list_for_each_entry_rcu(mod, &modules, list) {
71809 if (mod->state == MODULE_STATE_UNFORMED)
71810 continue;
71811 - if (within_module_core(addr, mod)
71812 - || within_module_init(addr, mod))
71813 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
71814 return mod;
71815 }
71816 return NULL;
71817 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
71818 */
71819 struct module *__module_text_address(unsigned long addr)
71820 {
71821 - struct module *mod = __module_address(addr);
71822 + struct module *mod;
71823 +
71824 +#ifdef CONFIG_X86_32
71825 + addr = ktla_ktva(addr);
71826 +#endif
71827 +
71828 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
71829 + return NULL;
71830 +
71831 + mod = __module_address(addr);
71832 +
71833 if (mod) {
71834 /* Make sure it's within the text section. */
71835 - if (!within(addr, mod->module_init, mod->init_text_size)
71836 - && !within(addr, mod->module_core, mod->core_text_size))
71837 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
71838 mod = NULL;
71839 }
71840 return mod;
71841 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
71842 index 7e3443f..b2a1e6b 100644
71843 --- a/kernel/mutex-debug.c
71844 +++ b/kernel/mutex-debug.c
71845 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
71846 }
71847
71848 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71849 - struct thread_info *ti)
71850 + struct task_struct *task)
71851 {
71852 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
71853
71854 /* Mark the current thread as blocked on the lock: */
71855 - ti->task->blocked_on = waiter;
71856 + task->blocked_on = waiter;
71857 }
71858
71859 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71860 - struct thread_info *ti)
71861 + struct task_struct *task)
71862 {
71863 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
71864 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
71865 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
71866 - ti->task->blocked_on = NULL;
71867 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
71868 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
71869 + task->blocked_on = NULL;
71870
71871 list_del_init(&waiter->list);
71872 waiter->task = NULL;
71873 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
71874 index 0799fd3..d06ae3b 100644
71875 --- a/kernel/mutex-debug.h
71876 +++ b/kernel/mutex-debug.h
71877 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
71878 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
71879 extern void debug_mutex_add_waiter(struct mutex *lock,
71880 struct mutex_waiter *waiter,
71881 - struct thread_info *ti);
71882 + struct task_struct *task);
71883 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
71884 - struct thread_info *ti);
71885 + struct task_struct *task);
71886 extern void debug_mutex_unlock(struct mutex *lock);
71887 extern void debug_mutex_init(struct mutex *lock, const char *name,
71888 struct lock_class_key *key);
71889 diff --git a/kernel/mutex.c b/kernel/mutex.c
71890 index a307cc9..27fd2e9 100644
71891 --- a/kernel/mutex.c
71892 +++ b/kernel/mutex.c
71893 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71894 spin_lock_mutex(&lock->wait_lock, flags);
71895
71896 debug_mutex_lock_common(lock, &waiter);
71897 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
71898 + debug_mutex_add_waiter(lock, &waiter, task);
71899
71900 /* add waiting tasks to the end of the waitqueue (FIFO): */
71901 list_add_tail(&waiter.list, &lock->wait_list);
71902 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71903 * TASK_UNINTERRUPTIBLE case.)
71904 */
71905 if (unlikely(signal_pending_state(state, task))) {
71906 - mutex_remove_waiter(lock, &waiter,
71907 - task_thread_info(task));
71908 + mutex_remove_waiter(lock, &waiter, task);
71909 mutex_release(&lock->dep_map, 1, ip);
71910 spin_unlock_mutex(&lock->wait_lock, flags);
71911
71912 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
71913 done:
71914 lock_acquired(&lock->dep_map, ip);
71915 /* got the lock - rejoice! */
71916 - mutex_remove_waiter(lock, &waiter, current_thread_info());
71917 + mutex_remove_waiter(lock, &waiter, task);
71918 mutex_set_owner(lock);
71919
71920 /* set it to 0 if there are no waiters left: */
71921 diff --git a/kernel/notifier.c b/kernel/notifier.c
71922 index 2d5cc4c..d9ea600 100644
71923 --- a/kernel/notifier.c
71924 +++ b/kernel/notifier.c
71925 @@ -5,6 +5,7 @@
71926 #include <linux/rcupdate.h>
71927 #include <linux/vmalloc.h>
71928 #include <linux/reboot.h>
71929 +#include <linux/mm.h>
71930
71931 /*
71932 * Notifier list for kernel code which wants to be called
71933 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
71934 while ((*nl) != NULL) {
71935 if (n->priority > (*nl)->priority)
71936 break;
71937 - nl = &((*nl)->next);
71938 + nl = (struct notifier_block **)&((*nl)->next);
71939 }
71940 - n->next = *nl;
71941 + pax_open_kernel();
71942 + *(const void **)&n->next = *nl;
71943 rcu_assign_pointer(*nl, n);
71944 + pax_close_kernel();
71945 return 0;
71946 }
71947
71948 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
71949 return 0;
71950 if (n->priority > (*nl)->priority)
71951 break;
71952 - nl = &((*nl)->next);
71953 + nl = (struct notifier_block **)&((*nl)->next);
71954 }
71955 - n->next = *nl;
71956 + pax_open_kernel();
71957 + *(const void **)&n->next = *nl;
71958 rcu_assign_pointer(*nl, n);
71959 + pax_close_kernel();
71960 return 0;
71961 }
71962
71963 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
71964 {
71965 while ((*nl) != NULL) {
71966 if ((*nl) == n) {
71967 + pax_open_kernel();
71968 rcu_assign_pointer(*nl, n->next);
71969 + pax_close_kernel();
71970 return 0;
71971 }
71972 - nl = &((*nl)->next);
71973 + nl = (struct notifier_block **)&((*nl)->next);
71974 }
71975 return -ENOENT;
71976 }
71977 diff --git a/kernel/panic.c b/kernel/panic.c
71978 index e1b2822..5edc1d9 100644
71979 --- a/kernel/panic.c
71980 +++ b/kernel/panic.c
71981 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
71982 const char *board;
71983
71984 printk(KERN_WARNING "------------[ cut here ]------------\n");
71985 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
71986 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
71987 board = dmi_get_system_info(DMI_PRODUCT_NAME);
71988 if (board)
71989 printk(KERN_WARNING "Hardware name: %s\n", board);
71990 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
71991 */
71992 void __stack_chk_fail(void)
71993 {
71994 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
71995 + dump_stack();
71996 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
71997 __builtin_return_address(0));
71998 }
71999 EXPORT_SYMBOL(__stack_chk_fail);
72000 diff --git a/kernel/pid.c b/kernel/pid.c
72001 index f2c6a68..4922d97 100644
72002 --- a/kernel/pid.c
72003 +++ b/kernel/pid.c
72004 @@ -33,6 +33,7 @@
72005 #include <linux/rculist.h>
72006 #include <linux/bootmem.h>
72007 #include <linux/hash.h>
72008 +#include <linux/security.h>
72009 #include <linux/pid_namespace.h>
72010 #include <linux/init_task.h>
72011 #include <linux/syscalls.h>
72012 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
72013
72014 int pid_max = PID_MAX_DEFAULT;
72015
72016 -#define RESERVED_PIDS 300
72017 +#define RESERVED_PIDS 500
72018
72019 int pid_max_min = RESERVED_PIDS + 1;
72020 int pid_max_max = PID_MAX_LIMIT;
72021 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
72022 */
72023 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
72024 {
72025 + struct task_struct *task;
72026 +
72027 rcu_lockdep_assert(rcu_read_lock_held(),
72028 "find_task_by_pid_ns() needs rcu_read_lock()"
72029 " protection");
72030 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72031 +
72032 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
72033 +
72034 + if (gr_pid_is_chrooted(task))
72035 + return NULL;
72036 +
72037 + return task;
72038 }
72039
72040 struct task_struct *find_task_by_vpid(pid_t vnr)
72041 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
72042 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
72043 }
72044
72045 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
72046 +{
72047 + rcu_lockdep_assert(rcu_read_lock_held(),
72048 + "find_task_by_pid_ns() needs rcu_read_lock()"
72049 + " protection");
72050 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
72051 +}
72052 +
72053 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
72054 {
72055 struct pid *pid;
72056 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
72057 index a278cad..bff5bd3 100644
72058 --- a/kernel/posix-cpu-timers.c
72059 +++ b/kernel/posix-cpu-timers.c
72060 @@ -1557,14 +1557,14 @@ struct k_clock clock_posix_cpu = {
72061
72062 static __init int init_posix_cpu_timers(void)
72063 {
72064 - struct k_clock process = {
72065 + static struct k_clock process = {
72066 .clock_getres = process_cpu_clock_getres,
72067 .clock_get = process_cpu_clock_get,
72068 .timer_create = process_cpu_timer_create,
72069 .nsleep = process_cpu_nsleep,
72070 .nsleep_restart = process_cpu_nsleep_restart,
72071 };
72072 - struct k_clock thread = {
72073 + static struct k_clock thread = {
72074 .clock_getres = thread_cpu_clock_getres,
72075 .clock_get = thread_cpu_clock_get,
72076 .timer_create = thread_cpu_timer_create,
72077 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
72078 index 69185ae..cc2847a 100644
72079 --- a/kernel/posix-timers.c
72080 +++ b/kernel/posix-timers.c
72081 @@ -43,6 +43,7 @@
72082 #include <linux/idr.h>
72083 #include <linux/posix-clock.h>
72084 #include <linux/posix-timers.h>
72085 +#include <linux/grsecurity.h>
72086 #include <linux/syscalls.h>
72087 #include <linux/wait.h>
72088 #include <linux/workqueue.h>
72089 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
72090 * which we beg off on and pass to do_sys_settimeofday().
72091 */
72092
72093 -static struct k_clock posix_clocks[MAX_CLOCKS];
72094 +static struct k_clock *posix_clocks[MAX_CLOCKS];
72095
72096 /*
72097 * These ones are defined below.
72098 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
72099 */
72100 static __init int init_posix_timers(void)
72101 {
72102 - struct k_clock clock_realtime = {
72103 + static struct k_clock clock_realtime = {
72104 .clock_getres = hrtimer_get_res,
72105 .clock_get = posix_clock_realtime_get,
72106 .clock_set = posix_clock_realtime_set,
72107 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
72108 .timer_get = common_timer_get,
72109 .timer_del = common_timer_del,
72110 };
72111 - struct k_clock clock_monotonic = {
72112 + static struct k_clock clock_monotonic = {
72113 .clock_getres = hrtimer_get_res,
72114 .clock_get = posix_ktime_get_ts,
72115 .nsleep = common_nsleep,
72116 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
72117 .timer_get = common_timer_get,
72118 .timer_del = common_timer_del,
72119 };
72120 - struct k_clock clock_monotonic_raw = {
72121 + static struct k_clock clock_monotonic_raw = {
72122 .clock_getres = hrtimer_get_res,
72123 .clock_get = posix_get_monotonic_raw,
72124 };
72125 - struct k_clock clock_realtime_coarse = {
72126 + static struct k_clock clock_realtime_coarse = {
72127 .clock_getres = posix_get_coarse_res,
72128 .clock_get = posix_get_realtime_coarse,
72129 };
72130 - struct k_clock clock_monotonic_coarse = {
72131 + static struct k_clock clock_monotonic_coarse = {
72132 .clock_getres = posix_get_coarse_res,
72133 .clock_get = posix_get_monotonic_coarse,
72134 };
72135 - struct k_clock clock_boottime = {
72136 + static struct k_clock clock_boottime = {
72137 .clock_getres = hrtimer_get_res,
72138 .clock_get = posix_get_boottime,
72139 .nsleep = common_nsleep,
72140 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
72141 return;
72142 }
72143
72144 - posix_clocks[clock_id] = *new_clock;
72145 + posix_clocks[clock_id] = new_clock;
72146 }
72147 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
72148
72149 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
72150 return (id & CLOCKFD_MASK) == CLOCKFD ?
72151 &clock_posix_dynamic : &clock_posix_cpu;
72152
72153 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
72154 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
72155 return NULL;
72156 - return &posix_clocks[id];
72157 + return posix_clocks[id];
72158 }
72159
72160 static int common_timer_create(struct k_itimer *new_timer)
72161 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
72162 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
72163 return -EFAULT;
72164
72165 + /* only the CLOCK_REALTIME clock can be set, all other clocks
72166 + have their clock_set fptr set to a nosettime dummy function
72167 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
72168 + call common_clock_set, which calls do_sys_settimeofday, which
72169 + we hook
72170 + */
72171 +
72172 return kc->clock_set(which_clock, &new_tp);
72173 }
72174
72175 diff --git a/kernel/power/process.c b/kernel/power/process.c
72176 index d5a258b..4271191 100644
72177 --- a/kernel/power/process.c
72178 +++ b/kernel/power/process.c
72179 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
72180 u64 elapsed_csecs64;
72181 unsigned int elapsed_csecs;
72182 bool wakeup = false;
72183 + bool timedout = false;
72184
72185 do_gettimeofday(&start);
72186
72187 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
72188
72189 while (true) {
72190 todo = 0;
72191 + if (time_after(jiffies, end_time))
72192 + timedout = true;
72193 read_lock(&tasklist_lock);
72194 do_each_thread(g, p) {
72195 if (p == current || !freeze_task(p))
72196 continue;
72197
72198 - if (!freezer_should_skip(p))
72199 + if (!freezer_should_skip(p)) {
72200 todo++;
72201 + if (timedout) {
72202 + printk(KERN_ERR "Task refusing to freeze:\n");
72203 + sched_show_task(p);
72204 + }
72205 + }
72206 } while_each_thread(g, p);
72207 read_unlock(&tasklist_lock);
72208
72209 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
72210 todo += wq_busy;
72211 }
72212
72213 - if (!todo || time_after(jiffies, end_time))
72214 + if (!todo || timedout)
72215 break;
72216
72217 if (pm_wakeup_pending()) {
72218 diff --git a/kernel/printk.c b/kernel/printk.c
72219 index 267ce78..2487112 100644
72220 --- a/kernel/printk.c
72221 +++ b/kernel/printk.c
72222 @@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
72223 return ret;
72224 }
72225
72226 +static int check_syslog_permissions(int type, bool from_file);
72227 +
72228 static int devkmsg_open(struct inode *inode, struct file *file)
72229 {
72230 struct devkmsg_user *user;
72231 int err;
72232
72233 + err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
72234 + if (err)
72235 + return err;
72236 +
72237 /* write-only does not need any file context */
72238 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
72239 return 0;
72240 @@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
72241 if (dmesg_restrict)
72242 return 1;
72243 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
72244 - return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
72245 + return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
72246 }
72247
72248 static int check_syslog_permissions(int type, bool from_file)
72249 @@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
72250 if (from_file && type != SYSLOG_ACTION_OPEN)
72251 return 0;
72252
72253 +#ifdef CONFIG_GRKERNSEC_DMESG
72254 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
72255 + return -EPERM;
72256 +#endif
72257 +
72258 if (syslog_action_restricted(type)) {
72259 if (capable(CAP_SYSLOG))
72260 return 0;
72261 diff --git a/kernel/profile.c b/kernel/profile.c
72262 index 1f39181..86093471 100644
72263 --- a/kernel/profile.c
72264 +++ b/kernel/profile.c
72265 @@ -40,7 +40,7 @@ struct profile_hit {
72266 /* Oprofile timer tick hook */
72267 static int (*timer_hook)(struct pt_regs *) __read_mostly;
72268
72269 -static atomic_t *prof_buffer;
72270 +static atomic_unchecked_t *prof_buffer;
72271 static unsigned long prof_len, prof_shift;
72272
72273 int prof_on __read_mostly;
72274 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
72275 hits[i].pc = 0;
72276 continue;
72277 }
72278 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72279 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72280 hits[i].hits = hits[i].pc = 0;
72281 }
72282 }
72283 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72284 * Add the current hit(s) and flush the write-queue out
72285 * to the global buffer:
72286 */
72287 - atomic_add(nr_hits, &prof_buffer[pc]);
72288 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
72289 for (i = 0; i < NR_PROFILE_HIT; ++i) {
72290 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
72291 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
72292 hits[i].pc = hits[i].hits = 0;
72293 }
72294 out:
72295 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
72296 {
72297 unsigned long pc;
72298 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
72299 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72300 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
72301 }
72302 #endif /* !CONFIG_SMP */
72303
72304 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
72305 return -EFAULT;
72306 buf++; p++; count--; read++;
72307 }
72308 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
72309 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
72310 if (copy_to_user(buf, (void *)pnt, count))
72311 return -EFAULT;
72312 read += count;
72313 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
72314 }
72315 #endif
72316 profile_discard_flip_buffers();
72317 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
72318 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
72319 return count;
72320 }
72321
72322 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
72323 index 6cbeaae..363c48a 100644
72324 --- a/kernel/ptrace.c
72325 +++ b/kernel/ptrace.c
72326 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
72327 if (seize)
72328 flags |= PT_SEIZED;
72329 rcu_read_lock();
72330 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72331 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
72332 flags |= PT_PTRACE_CAP;
72333 rcu_read_unlock();
72334 task->ptrace = flags;
72335 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
72336 break;
72337 return -EIO;
72338 }
72339 - if (copy_to_user(dst, buf, retval))
72340 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
72341 return -EFAULT;
72342 copied += retval;
72343 src += retval;
72344 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
72345 bool seized = child->ptrace & PT_SEIZED;
72346 int ret = -EIO;
72347 siginfo_t siginfo, *si;
72348 - void __user *datavp = (void __user *) data;
72349 + void __user *datavp = (__force void __user *) data;
72350 unsigned long __user *datalp = datavp;
72351 unsigned long flags;
72352
72353 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
72354 goto out;
72355 }
72356
72357 + if (gr_handle_ptrace(child, request)) {
72358 + ret = -EPERM;
72359 + goto out_put_task_struct;
72360 + }
72361 +
72362 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72363 ret = ptrace_attach(child, request, addr, data);
72364 /*
72365 * Some architectures need to do book-keeping after
72366 * a ptrace attach.
72367 */
72368 - if (!ret)
72369 + if (!ret) {
72370 arch_ptrace_attach(child);
72371 + gr_audit_ptrace(child);
72372 + }
72373 goto out_put_task_struct;
72374 }
72375
72376 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
72377 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
72378 if (copied != sizeof(tmp))
72379 return -EIO;
72380 - return put_user(tmp, (unsigned long __user *)data);
72381 + return put_user(tmp, (__force unsigned long __user *)data);
72382 }
72383
72384 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
72385 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72386 goto out;
72387 }
72388
72389 + if (gr_handle_ptrace(child, request)) {
72390 + ret = -EPERM;
72391 + goto out_put_task_struct;
72392 + }
72393 +
72394 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
72395 ret = ptrace_attach(child, request, addr, data);
72396 /*
72397 * Some architectures need to do book-keeping after
72398 * a ptrace attach.
72399 */
72400 - if (!ret)
72401 + if (!ret) {
72402 arch_ptrace_attach(child);
72403 + gr_audit_ptrace(child);
72404 + }
72405 goto out_put_task_struct;
72406 }
72407
72408 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
72409 index e7dce58..ad0d7b7 100644
72410 --- a/kernel/rcutiny.c
72411 +++ b/kernel/rcutiny.c
72412 @@ -46,7 +46,7 @@
72413 struct rcu_ctrlblk;
72414 static void invoke_rcu_callbacks(void);
72415 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
72416 -static void rcu_process_callbacks(struct softirq_action *unused);
72417 +static void rcu_process_callbacks(void);
72418 static void __call_rcu(struct rcu_head *head,
72419 void (*func)(struct rcu_head *rcu),
72420 struct rcu_ctrlblk *rcp);
72421 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
72422 rcu_is_callbacks_kthread()));
72423 }
72424
72425 -static void rcu_process_callbacks(struct softirq_action *unused)
72426 +static void rcu_process_callbacks(void)
72427 {
72428 __rcu_process_callbacks(&rcu_sched_ctrlblk);
72429 __rcu_process_callbacks(&rcu_bh_ctrlblk);
72430 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
72431 index f85016a..91cb03b 100644
72432 --- a/kernel/rcutiny_plugin.h
72433 +++ b/kernel/rcutiny_plugin.h
72434 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
72435 have_rcu_kthread_work = morework;
72436 local_irq_restore(flags);
72437 if (work)
72438 - rcu_process_callbacks(NULL);
72439 + rcu_process_callbacks();
72440 schedule_timeout_interruptible(1); /* Leave CPU for others. */
72441 }
72442
72443 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
72444 index 31dea01..ad91ffb 100644
72445 --- a/kernel/rcutorture.c
72446 +++ b/kernel/rcutorture.c
72447 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
72448 { 0 };
72449 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
72450 { 0 };
72451 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72452 -static atomic_t n_rcu_torture_alloc;
72453 -static atomic_t n_rcu_torture_alloc_fail;
72454 -static atomic_t n_rcu_torture_free;
72455 -static atomic_t n_rcu_torture_mberror;
72456 -static atomic_t n_rcu_torture_error;
72457 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
72458 +static atomic_unchecked_t n_rcu_torture_alloc;
72459 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
72460 +static atomic_unchecked_t n_rcu_torture_free;
72461 +static atomic_unchecked_t n_rcu_torture_mberror;
72462 +static atomic_unchecked_t n_rcu_torture_error;
72463 static long n_rcu_torture_barrier_error;
72464 static long n_rcu_torture_boost_ktrerror;
72465 static long n_rcu_torture_boost_rterror;
72466 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
72467
72468 spin_lock_bh(&rcu_torture_lock);
72469 if (list_empty(&rcu_torture_freelist)) {
72470 - atomic_inc(&n_rcu_torture_alloc_fail);
72471 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
72472 spin_unlock_bh(&rcu_torture_lock);
72473 return NULL;
72474 }
72475 - atomic_inc(&n_rcu_torture_alloc);
72476 + atomic_inc_unchecked(&n_rcu_torture_alloc);
72477 p = rcu_torture_freelist.next;
72478 list_del_init(p);
72479 spin_unlock_bh(&rcu_torture_lock);
72480 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
72481 static void
72482 rcu_torture_free(struct rcu_torture *p)
72483 {
72484 - atomic_inc(&n_rcu_torture_free);
72485 + atomic_inc_unchecked(&n_rcu_torture_free);
72486 spin_lock_bh(&rcu_torture_lock);
72487 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
72488 spin_unlock_bh(&rcu_torture_lock);
72489 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
72490 i = rp->rtort_pipe_count;
72491 if (i > RCU_TORTURE_PIPE_LEN)
72492 i = RCU_TORTURE_PIPE_LEN;
72493 - atomic_inc(&rcu_torture_wcount[i]);
72494 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72495 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72496 rp->rtort_mbtest = 0;
72497 rcu_torture_free(rp);
72498 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
72499 i = rp->rtort_pipe_count;
72500 if (i > RCU_TORTURE_PIPE_LEN)
72501 i = RCU_TORTURE_PIPE_LEN;
72502 - atomic_inc(&rcu_torture_wcount[i]);
72503 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72504 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
72505 rp->rtort_mbtest = 0;
72506 list_del(&rp->rtort_free);
72507 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
72508 i = old_rp->rtort_pipe_count;
72509 if (i > RCU_TORTURE_PIPE_LEN)
72510 i = RCU_TORTURE_PIPE_LEN;
72511 - atomic_inc(&rcu_torture_wcount[i]);
72512 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
72513 old_rp->rtort_pipe_count++;
72514 cur_ops->deferred_free(old_rp);
72515 }
72516 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
72517 }
72518 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72519 if (p->rtort_mbtest == 0)
72520 - atomic_inc(&n_rcu_torture_mberror);
72521 + atomic_inc_unchecked(&n_rcu_torture_mberror);
72522 spin_lock(&rand_lock);
72523 cur_ops->read_delay(&rand);
72524 n_rcu_torture_timers++;
72525 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
72526 }
72527 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
72528 if (p->rtort_mbtest == 0)
72529 - atomic_inc(&n_rcu_torture_mberror);
72530 + atomic_inc_unchecked(&n_rcu_torture_mberror);
72531 cur_ops->read_delay(&rand);
72532 preempt_disable();
72533 pipe_count = p->rtort_pipe_count;
72534 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
72535 rcu_torture_current,
72536 rcu_torture_current_version,
72537 list_empty(&rcu_torture_freelist),
72538 - atomic_read(&n_rcu_torture_alloc),
72539 - atomic_read(&n_rcu_torture_alloc_fail),
72540 - atomic_read(&n_rcu_torture_free));
72541 + atomic_read_unchecked(&n_rcu_torture_alloc),
72542 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
72543 + atomic_read_unchecked(&n_rcu_torture_free));
72544 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
72545 - atomic_read(&n_rcu_torture_mberror),
72546 + atomic_read_unchecked(&n_rcu_torture_mberror),
72547 n_rcu_torture_boost_ktrerror,
72548 n_rcu_torture_boost_rterror);
72549 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
72550 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
72551 n_barrier_attempts,
72552 n_rcu_torture_barrier_error);
72553 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
72554 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
72555 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
72556 n_rcu_torture_barrier_error != 0 ||
72557 n_rcu_torture_boost_ktrerror != 0 ||
72558 n_rcu_torture_boost_rterror != 0 ||
72559 n_rcu_torture_boost_failure != 0 ||
72560 i > 1) {
72561 cnt += sprintf(&page[cnt], "!!! ");
72562 - atomic_inc(&n_rcu_torture_error);
72563 + atomic_inc_unchecked(&n_rcu_torture_error);
72564 WARN_ON_ONCE(1);
72565 }
72566 cnt += sprintf(&page[cnt], "Reader Pipe: ");
72567 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
72568 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
72569 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72570 cnt += sprintf(&page[cnt], " %d",
72571 - atomic_read(&rcu_torture_wcount[i]));
72572 + atomic_read_unchecked(&rcu_torture_wcount[i]));
72573 }
72574 cnt += sprintf(&page[cnt], "\n");
72575 if (cur_ops->stats)
72576 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
72577
72578 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
72579
72580 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72581 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
72582 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
72583 else if (n_online_successes != n_online_attempts ||
72584 n_offline_successes != n_offline_attempts)
72585 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
72586
72587 rcu_torture_current = NULL;
72588 rcu_torture_current_version = 0;
72589 - atomic_set(&n_rcu_torture_alloc, 0);
72590 - atomic_set(&n_rcu_torture_alloc_fail, 0);
72591 - atomic_set(&n_rcu_torture_free, 0);
72592 - atomic_set(&n_rcu_torture_mberror, 0);
72593 - atomic_set(&n_rcu_torture_error, 0);
72594 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
72595 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
72596 + atomic_set_unchecked(&n_rcu_torture_free, 0);
72597 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
72598 + atomic_set_unchecked(&n_rcu_torture_error, 0);
72599 n_rcu_torture_barrier_error = 0;
72600 n_rcu_torture_boost_ktrerror = 0;
72601 n_rcu_torture_boost_rterror = 0;
72602 n_rcu_torture_boost_failure = 0;
72603 n_rcu_torture_boosts = 0;
72604 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
72605 - atomic_set(&rcu_torture_wcount[i], 0);
72606 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
72607 for_each_possible_cpu(cpu) {
72608 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
72609 per_cpu(rcu_torture_count, cpu)[i] = 0;
72610 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
72611 index e441b77..dd54f17 100644
72612 --- a/kernel/rcutree.c
72613 +++ b/kernel/rcutree.c
72614 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
72615 rcu_prepare_for_idle(smp_processor_id());
72616 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72617 smp_mb__before_atomic_inc(); /* See above. */
72618 - atomic_inc(&rdtp->dynticks);
72619 + atomic_inc_unchecked(&rdtp->dynticks);
72620 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
72621 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72622 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72623
72624 /*
72625 * It is illegal to enter an extended quiescent state while
72626 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
72627 int user)
72628 {
72629 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
72630 - atomic_inc(&rdtp->dynticks);
72631 + atomic_inc_unchecked(&rdtp->dynticks);
72632 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72633 smp_mb__after_atomic_inc(); /* See above. */
72634 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72635 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72636 rcu_cleanup_after_idle(smp_processor_id());
72637 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
72638 if (!user && !is_idle_task(current)) {
72639 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
72640 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
72641
72642 if (rdtp->dynticks_nmi_nesting == 0 &&
72643 - (atomic_read(&rdtp->dynticks) & 0x1))
72644 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
72645 return;
72646 rdtp->dynticks_nmi_nesting++;
72647 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
72648 - atomic_inc(&rdtp->dynticks);
72649 + atomic_inc_unchecked(&rdtp->dynticks);
72650 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
72651 smp_mb__after_atomic_inc(); /* See above. */
72652 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
72653 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
72654 }
72655
72656 /**
72657 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
72658 return;
72659 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
72660 smp_mb__before_atomic_inc(); /* See above. */
72661 - atomic_inc(&rdtp->dynticks);
72662 + atomic_inc_unchecked(&rdtp->dynticks);
72663 smp_mb__after_atomic_inc(); /* Force delay to next write. */
72664 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
72665 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
72666 }
72667
72668 /**
72669 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
72670 int ret;
72671
72672 preempt_disable();
72673 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72674 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
72675 preempt_enable();
72676 return ret;
72677 }
72678 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
72679 */
72680 static int dyntick_save_progress_counter(struct rcu_data *rdp)
72681 {
72682 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
72683 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72684 return (rdp->dynticks_snap & 0x1) == 0;
72685 }
72686
72687 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
72688 unsigned int curr;
72689 unsigned int snap;
72690
72691 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
72692 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
72693 snap = (unsigned int)rdp->dynticks_snap;
72694
72695 /*
72696 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
72697 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
72698 */
72699 if (till_stall_check < 3) {
72700 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
72701 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
72702 till_stall_check = 3;
72703 } else if (till_stall_check > 300) {
72704 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
72705 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
72706 till_stall_check = 300;
72707 }
72708 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
72709 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
72710 rsp->qlen += rdp->qlen;
72711 rdp->n_cbs_orphaned += rdp->qlen;
72712 rdp->qlen_lazy = 0;
72713 - ACCESS_ONCE(rdp->qlen) = 0;
72714 + ACCESS_ONCE_RW(rdp->qlen) = 0;
72715 }
72716
72717 /*
72718 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
72719 }
72720 smp_mb(); /* List handling before counting for rcu_barrier(). */
72721 rdp->qlen_lazy -= count_lazy;
72722 - ACCESS_ONCE(rdp->qlen) -= count;
72723 + ACCESS_ONCE_RW(rdp->qlen) -= count;
72724 rdp->n_cbs_invoked += count;
72725
72726 /* Reinstate batch limit if we have worked down the excess. */
72727 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
72728 /*
72729 * Do RCU core processing for the current CPU.
72730 */
72731 -static void rcu_process_callbacks(struct softirq_action *unused)
72732 +static void rcu_process_callbacks(void)
72733 {
72734 struct rcu_state *rsp;
72735
72736 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
72737 local_irq_restore(flags);
72738 return;
72739 }
72740 - ACCESS_ONCE(rdp->qlen)++;
72741 + ACCESS_ONCE_RW(rdp->qlen)++;
72742 if (lazy)
72743 rdp->qlen_lazy++;
72744 else
72745 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
72746 * counter wrap on a 32-bit system. Quite a few more CPUs would of
72747 * course be required on a 64-bit system.
72748 */
72749 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
72750 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
72751 (ulong)atomic_long_read(&rsp->expedited_done) +
72752 ULONG_MAX / 8)) {
72753 synchronize_sched();
72754 - atomic_long_inc(&rsp->expedited_wrap);
72755 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
72756 return;
72757 }
72758
72759 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
72760 * Take a ticket. Note that atomic_inc_return() implies a
72761 * full memory barrier.
72762 */
72763 - snap = atomic_long_inc_return(&rsp->expedited_start);
72764 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
72765 firstsnap = snap;
72766 get_online_cpus();
72767 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
72768 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
72769 synchronize_sched_expedited_cpu_stop,
72770 NULL) == -EAGAIN) {
72771 put_online_cpus();
72772 - atomic_long_inc(&rsp->expedited_tryfail);
72773 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
72774
72775 /* Check to see if someone else did our work for us. */
72776 s = atomic_long_read(&rsp->expedited_done);
72777 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72778 /* ensure test happens before caller kfree */
72779 smp_mb__before_atomic_inc(); /* ^^^ */
72780 - atomic_long_inc(&rsp->expedited_workdone1);
72781 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
72782 return;
72783 }
72784
72785 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
72786 udelay(trycount * num_online_cpus());
72787 } else {
72788 wait_rcu_gp(call_rcu_sched);
72789 - atomic_long_inc(&rsp->expedited_normal);
72790 + atomic_long_inc_unchecked(&rsp->expedited_normal);
72791 return;
72792 }
72793
72794 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
72795 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
72796 /* ensure test happens before caller kfree */
72797 smp_mb__before_atomic_inc(); /* ^^^ */
72798 - atomic_long_inc(&rsp->expedited_workdone2);
72799 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
72800 return;
72801 }
72802
72803 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
72804 * period works for us.
72805 */
72806 get_online_cpus();
72807 - snap = atomic_long_read(&rsp->expedited_start);
72808 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
72809 smp_mb(); /* ensure read is before try_stop_cpus(). */
72810 }
72811 - atomic_long_inc(&rsp->expedited_stoppedcpus);
72812 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
72813
72814 /*
72815 * Everyone up to our most recent fetch is covered by our grace
72816 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
72817 * than we did already did their update.
72818 */
72819 do {
72820 - atomic_long_inc(&rsp->expedited_done_tries);
72821 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
72822 s = atomic_long_read(&rsp->expedited_done);
72823 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
72824 /* ensure test happens before caller kfree */
72825 smp_mb__before_atomic_inc(); /* ^^^ */
72826 - atomic_long_inc(&rsp->expedited_done_lost);
72827 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
72828 break;
72829 }
72830 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
72831 - atomic_long_inc(&rsp->expedited_done_exit);
72832 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
72833
72834 put_online_cpus();
72835 }
72836 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72837 * ACCESS_ONCE() to prevent the compiler from speculating
72838 * the increment to precede the early-exit check.
72839 */
72840 - ACCESS_ONCE(rsp->n_barrier_done)++;
72841 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72842 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
72843 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
72844 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
72845 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
72846
72847 /* Increment ->n_barrier_done to prevent duplicate work. */
72848 smp_mb(); /* Keep increment after above mechanism. */
72849 - ACCESS_ONCE(rsp->n_barrier_done)++;
72850 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
72851 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
72852 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
72853 smp_mb(); /* Keep increment before caller's subsequent code. */
72854 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
72855 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
72856 init_callback_list(rdp);
72857 rdp->qlen_lazy = 0;
72858 - ACCESS_ONCE(rdp->qlen) = 0;
72859 + ACCESS_ONCE_RW(rdp->qlen) = 0;
72860 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
72861 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
72862 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
72863 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
72864 #ifdef CONFIG_RCU_USER_QS
72865 WARN_ON_ONCE(rdp->dynticks->in_user);
72866 #endif
72867 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
72868 rdp->blimit = blimit;
72869 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
72870 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
72871 - atomic_set(&rdp->dynticks->dynticks,
72872 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
72873 + atomic_set_unchecked(&rdp->dynticks->dynticks,
72874 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
72875 rcu_prepare_for_idle_init(cpu);
72876 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
72877
72878 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
72879 index 4b69291..704c92e 100644
72880 --- a/kernel/rcutree.h
72881 +++ b/kernel/rcutree.h
72882 @@ -86,7 +86,7 @@ struct rcu_dynticks {
72883 long long dynticks_nesting; /* Track irq/process nesting level. */
72884 /* Process level is worth LLONG_MAX/2. */
72885 int dynticks_nmi_nesting; /* Track NMI nesting level. */
72886 - atomic_t dynticks; /* Even value for idle, else odd. */
72887 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
72888 #ifdef CONFIG_RCU_FAST_NO_HZ
72889 int dyntick_drain; /* Prepare-for-idle state variable. */
72890 unsigned long dyntick_holdoff;
72891 @@ -423,17 +423,17 @@ struct rcu_state {
72892 /* _rcu_barrier(). */
72893 /* End of fields guarded by barrier_mutex. */
72894
72895 - atomic_long_t expedited_start; /* Starting ticket. */
72896 - atomic_long_t expedited_done; /* Done ticket. */
72897 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
72898 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
72899 - atomic_long_t expedited_workdone1; /* # done by others #1. */
72900 - atomic_long_t expedited_workdone2; /* # done by others #2. */
72901 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
72902 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
72903 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
72904 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
72905 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
72906 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
72907 + atomic_long_t expedited_done; /* Done ticket. */
72908 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
72909 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
72910 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
72911 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
72912 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
72913 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
72914 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
72915 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
72916 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
72917
72918 unsigned long jiffies_force_qs; /* Time at which to invoke */
72919 /* force_quiescent_state(). */
72920 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
72921 index c1cc7e1..5043e0e 100644
72922 --- a/kernel/rcutree_plugin.h
72923 +++ b/kernel/rcutree_plugin.h
72924 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
72925
72926 /* Clean up and exit. */
72927 smp_mb(); /* ensure expedited GP seen before counter increment. */
72928 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
72929 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
72930 unlock_mb_ret:
72931 mutex_unlock(&sync_rcu_preempt_exp_mutex);
72932 mb_ret:
72933 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
72934 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
72935 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
72936 cpu, ticks_value, ticks_title,
72937 - atomic_read(&rdtp->dynticks) & 0xfff,
72938 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
72939 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
72940 fast_no_hz);
72941 }
72942 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
72943
72944 /* Enqueue the callback on the nocb list and update counts. */
72945 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
72946 - ACCESS_ONCE(*old_rhpp) = rhp;
72947 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
72948 atomic_long_add(rhcount, &rdp->nocb_q_count);
72949 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
72950
72951 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
72952 * Extract queued callbacks, update counts, and wait
72953 * for a grace period to elapse.
72954 */
72955 - ACCESS_ONCE(rdp->nocb_head) = NULL;
72956 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
72957 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
72958 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
72959 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
72960 - ACCESS_ONCE(rdp->nocb_p_count) += c;
72961 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
72962 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
72963 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
72964 wait_rcu_gp(rdp->rsp->call_remote);
72965
72966 /* Each pass through the following loop invokes a callback. */
72967 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
72968 list = next;
72969 }
72970 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
72971 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
72972 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
72973 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
72974 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
72975 rdp->n_nocbs_invoked += c;
72976 }
72977 return 0;
72978 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
72979 rdp = per_cpu_ptr(rsp->rda, cpu);
72980 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
72981 BUG_ON(IS_ERR(t));
72982 - ACCESS_ONCE(rdp->nocb_kthread) = t;
72983 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
72984 }
72985 }
72986
72987 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
72988 index 0d095dc..1985b19 100644
72989 --- a/kernel/rcutree_trace.c
72990 +++ b/kernel/rcutree_trace.c
72991 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
72992 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
72993 rdp->passed_quiesce, rdp->qs_pending);
72994 seq_printf(m, " dt=%d/%llx/%d df=%lu",
72995 - atomic_read(&rdp->dynticks->dynticks),
72996 + atomic_read_unchecked(&rdp->dynticks->dynticks),
72997 rdp->dynticks->dynticks_nesting,
72998 rdp->dynticks->dynticks_nmi_nesting,
72999 rdp->dynticks_fqs);
73000 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
73001 struct rcu_state *rsp = (struct rcu_state *)m->private;
73002
73003 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",
73004 - atomic_long_read(&rsp->expedited_start),
73005 + atomic_long_read_unchecked(&rsp->expedited_start),
73006 atomic_long_read(&rsp->expedited_done),
73007 - atomic_long_read(&rsp->expedited_wrap),
73008 - atomic_long_read(&rsp->expedited_tryfail),
73009 - atomic_long_read(&rsp->expedited_workdone1),
73010 - atomic_long_read(&rsp->expedited_workdone2),
73011 - atomic_long_read(&rsp->expedited_normal),
73012 - atomic_long_read(&rsp->expedited_stoppedcpus),
73013 - atomic_long_read(&rsp->expedited_done_tries),
73014 - atomic_long_read(&rsp->expedited_done_lost),
73015 - atomic_long_read(&rsp->expedited_done_exit));
73016 + atomic_long_read_unchecked(&rsp->expedited_wrap),
73017 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
73018 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
73019 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
73020 + atomic_long_read_unchecked(&rsp->expedited_normal),
73021 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
73022 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
73023 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
73024 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
73025 return 0;
73026 }
73027
73028 diff --git a/kernel/resource.c b/kernel/resource.c
73029 index 73f35d4..4684fc4 100644
73030 --- a/kernel/resource.c
73031 +++ b/kernel/resource.c
73032 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
73033
73034 static int __init ioresources_init(void)
73035 {
73036 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
73037 +#ifdef CONFIG_GRKERNSEC_PROC_USER
73038 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
73039 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
73040 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73041 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
73042 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
73043 +#endif
73044 +#else
73045 proc_create("ioports", 0, NULL, &proc_ioports_operations);
73046 proc_create("iomem", 0, NULL, &proc_iomem_operations);
73047 +#endif
73048 return 0;
73049 }
73050 __initcall(ioresources_init);
73051 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
73052 index 98ec494..4241d6d 100644
73053 --- a/kernel/rtmutex-tester.c
73054 +++ b/kernel/rtmutex-tester.c
73055 @@ -20,7 +20,7 @@
73056 #define MAX_RT_TEST_MUTEXES 8
73057
73058 static spinlock_t rttest_lock;
73059 -static atomic_t rttest_event;
73060 +static atomic_unchecked_t rttest_event;
73061
73062 struct test_thread_data {
73063 int opcode;
73064 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73065
73066 case RTTEST_LOCKCONT:
73067 td->mutexes[td->opdata] = 1;
73068 - td->event = atomic_add_return(1, &rttest_event);
73069 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73070 return 0;
73071
73072 case RTTEST_RESET:
73073 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73074 return 0;
73075
73076 case RTTEST_RESETEVENT:
73077 - atomic_set(&rttest_event, 0);
73078 + atomic_set_unchecked(&rttest_event, 0);
73079 return 0;
73080
73081 default:
73082 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73083 return ret;
73084
73085 td->mutexes[id] = 1;
73086 - td->event = atomic_add_return(1, &rttest_event);
73087 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73088 rt_mutex_lock(&mutexes[id]);
73089 - td->event = atomic_add_return(1, &rttest_event);
73090 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73091 td->mutexes[id] = 4;
73092 return 0;
73093
73094 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73095 return ret;
73096
73097 td->mutexes[id] = 1;
73098 - td->event = atomic_add_return(1, &rttest_event);
73099 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73100 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
73101 - td->event = atomic_add_return(1, &rttest_event);
73102 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73103 td->mutexes[id] = ret ? 0 : 4;
73104 return ret ? -EINTR : 0;
73105
73106 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
73107 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
73108 return ret;
73109
73110 - td->event = atomic_add_return(1, &rttest_event);
73111 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73112 rt_mutex_unlock(&mutexes[id]);
73113 - td->event = atomic_add_return(1, &rttest_event);
73114 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73115 td->mutexes[id] = 0;
73116 return 0;
73117
73118 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73119 break;
73120
73121 td->mutexes[dat] = 2;
73122 - td->event = atomic_add_return(1, &rttest_event);
73123 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73124 break;
73125
73126 default:
73127 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73128 return;
73129
73130 td->mutexes[dat] = 3;
73131 - td->event = atomic_add_return(1, &rttest_event);
73132 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73133 break;
73134
73135 case RTTEST_LOCKNOWAIT:
73136 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
73137 return;
73138
73139 td->mutexes[dat] = 1;
73140 - td->event = atomic_add_return(1, &rttest_event);
73141 + td->event = atomic_add_return_unchecked(1, &rttest_event);
73142 return;
73143
73144 default:
73145 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
73146 index 0984a21..939f183 100644
73147 --- a/kernel/sched/auto_group.c
73148 +++ b/kernel/sched/auto_group.c
73149 @@ -11,7 +11,7 @@
73150
73151 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
73152 static struct autogroup autogroup_default;
73153 -static atomic_t autogroup_seq_nr;
73154 +static atomic_unchecked_t autogroup_seq_nr;
73155
73156 void __init autogroup_init(struct task_struct *init_task)
73157 {
73158 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
73159
73160 kref_init(&ag->kref);
73161 init_rwsem(&ag->lock);
73162 - ag->id = atomic_inc_return(&autogroup_seq_nr);
73163 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
73164 ag->tg = tg;
73165 #ifdef CONFIG_RT_GROUP_SCHED
73166 /*
73167 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
73168 index 26058d0..06f15dd 100644
73169 --- a/kernel/sched/core.c
73170 +++ b/kernel/sched/core.c
73171 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
73172 /* convert nice value [19,-20] to rlimit style value [1,40] */
73173 int nice_rlim = 20 - nice;
73174
73175 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
73176 +
73177 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
73178 capable(CAP_SYS_NICE));
73179 }
73180 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
73181 if (nice > 19)
73182 nice = 19;
73183
73184 - if (increment < 0 && !can_nice(current, nice))
73185 + if (increment < 0 && (!can_nice(current, nice) ||
73186 + gr_handle_chroot_nice()))
73187 return -EPERM;
73188
73189 retval = security_task_setnice(current, nice);
73190 @@ -3818,6 +3821,7 @@ recheck:
73191 unsigned long rlim_rtprio =
73192 task_rlimit(p, RLIMIT_RTPRIO);
73193
73194 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
73195 /* can't set/change the rt policy */
73196 if (policy != p->policy && !rlim_rtprio)
73197 return -EPERM;
73198 @@ -5162,7 +5166,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
73199 * happens before everything else. This has to be lower priority than
73200 * the notifier in the perf_event subsystem, though.
73201 */
73202 -static struct notifier_block __cpuinitdata migration_notifier = {
73203 +static struct notifier_block migration_notifier = {
73204 .notifier_call = migration_call,
73205 .priority = CPU_PRI_MIGRATION,
73206 };
73207 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
73208 index 81fa536..6ccf96a 100644
73209 --- a/kernel/sched/fair.c
73210 +++ b/kernel/sched/fair.c
73211 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
73212
73213 static void reset_ptenuma_scan(struct task_struct *p)
73214 {
73215 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
73216 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
73217 p->mm->numa_scan_offset = 0;
73218 }
73219
73220 @@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
73221 */
73222 static int select_idle_sibling(struct task_struct *p, int target)
73223 {
73224 - int cpu = smp_processor_id();
73225 - int prev_cpu = task_cpu(p);
73226 struct sched_domain *sd;
73227 struct sched_group *sg;
73228 - int i;
73229 + int i = task_cpu(p);
73230
73231 - /*
73232 - * If the task is going to be woken-up on this cpu and if it is
73233 - * already idle, then it is the right target.
73234 - */
73235 - if (target == cpu && idle_cpu(cpu))
73236 - return cpu;
73237 + if (idle_cpu(target))
73238 + return target;
73239
73240 /*
73241 - * If the task is going to be woken-up on the cpu where it previously
73242 - * ran and if it is currently idle, then it the right target.
73243 + * If the prevous cpu is cache affine and idle, don't be stupid.
73244 */
73245 - if (target == prev_cpu && idle_cpu(prev_cpu))
73246 - return prev_cpu;
73247 + if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
73248 + return i;
73249
73250 /*
73251 * Otherwise, iterate the domains and find an elegible idle cpu.
73252 @@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
73253 goto next;
73254
73255 for_each_cpu(i, sched_group_cpus(sg)) {
73256 - if (!idle_cpu(i))
73257 + if (i == target || !idle_cpu(i))
73258 goto next;
73259 }
73260
73261 @@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
73262 * run_rebalance_domains is triggered when needed from the scheduler tick.
73263 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
73264 */
73265 -static void run_rebalance_domains(struct softirq_action *h)
73266 +static void run_rebalance_domains(void)
73267 {
73268 int this_cpu = smp_processor_id();
73269 struct rq *this_rq = cpu_rq(this_cpu);
73270 diff --git a/kernel/signal.c b/kernel/signal.c
73271 index 3d09cf6..a67d2c6 100644
73272 --- a/kernel/signal.c
73273 +++ b/kernel/signal.c
73274 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
73275
73276 int print_fatal_signals __read_mostly;
73277
73278 -static void __user *sig_handler(struct task_struct *t, int sig)
73279 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
73280 {
73281 return t->sighand->action[sig - 1].sa.sa_handler;
73282 }
73283
73284 -static int sig_handler_ignored(void __user *handler, int sig)
73285 +static int sig_handler_ignored(__sighandler_t handler, int sig)
73286 {
73287 /* Is it explicitly or implicitly ignored? */
73288 return handler == SIG_IGN ||
73289 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
73290
73291 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
73292 {
73293 - void __user *handler;
73294 + __sighandler_t handler;
73295
73296 handler = sig_handler(t, sig);
73297
73298 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
73299 atomic_inc(&user->sigpending);
73300 rcu_read_unlock();
73301
73302 + if (!override_rlimit)
73303 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
73304 +
73305 if (override_rlimit ||
73306 atomic_read(&user->sigpending) <=
73307 task_rlimit(t, RLIMIT_SIGPENDING)) {
73308 @@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
73309
73310 int unhandled_signal(struct task_struct *tsk, int sig)
73311 {
73312 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
73313 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
73314 if (is_global_init(tsk))
73315 return 1;
73316 if (handler != SIG_IGN && handler != SIG_DFL)
73317 @@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
73318 }
73319 }
73320
73321 + /* allow glibc communication via tgkill to other threads in our
73322 + thread group */
73323 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
73324 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
73325 + && gr_handle_signal(t, sig))
73326 + return -EPERM;
73327 +
73328 return security_task_kill(t, info, sig, 0);
73329 }
73330
73331 @@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73332 return send_signal(sig, info, p, 1);
73333 }
73334
73335 -static int
73336 +int
73337 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73338 {
73339 return send_signal(sig, info, t, 0);
73340 @@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73341 unsigned long int flags;
73342 int ret, blocked, ignored;
73343 struct k_sigaction *action;
73344 + int is_unhandled = 0;
73345
73346 spin_lock_irqsave(&t->sighand->siglock, flags);
73347 action = &t->sighand->action[sig-1];
73348 @@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
73349 }
73350 if (action->sa.sa_handler == SIG_DFL)
73351 t->signal->flags &= ~SIGNAL_UNKILLABLE;
73352 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
73353 + is_unhandled = 1;
73354 ret = specific_send_sig_info(sig, info, t);
73355 spin_unlock_irqrestore(&t->sighand->siglock, flags);
73356
73357 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
73358 + normal operation */
73359 + if (is_unhandled) {
73360 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
73361 + gr_handle_crash(t, sig);
73362 + }
73363 +
73364 return ret;
73365 }
73366
73367 @@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
73368 ret = check_kill_permission(sig, info, p);
73369 rcu_read_unlock();
73370
73371 - if (!ret && sig)
73372 + if (!ret && sig) {
73373 ret = do_send_sig_info(sig, info, p, true);
73374 + if (!ret)
73375 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
73376 + }
73377
73378 return ret;
73379 }
73380 @@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
73381 int error = -ESRCH;
73382
73383 rcu_read_lock();
73384 - p = find_task_by_vpid(pid);
73385 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73386 + /* allow glibc communication via tgkill to other threads in our
73387 + thread group */
73388 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
73389 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
73390 + p = find_task_by_vpid_unrestricted(pid);
73391 + else
73392 +#endif
73393 + p = find_task_by_vpid(pid);
73394 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
73395 error = check_kill_permission(sig, info, p);
73396 /*
73397 @@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
73398 }
73399 seg = get_fs();
73400 set_fs(KERNEL_DS);
73401 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
73402 - (stack_t __force __user *) &uoss,
73403 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
73404 + (stack_t __force_user *) &uoss,
73405 compat_user_stack_pointer());
73406 set_fs(seg);
73407 if (ret >= 0 && uoss_ptr) {
73408 diff --git a/kernel/smp.c b/kernel/smp.c
73409 index 69f38bd..77bbf12 100644
73410 --- a/kernel/smp.c
73411 +++ b/kernel/smp.c
73412 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
73413 return NOTIFY_OK;
73414 }
73415
73416 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
73417 +static struct notifier_block hotplug_cfd_notifier = {
73418 .notifier_call = hotplug_cfd,
73419 };
73420
73421 diff --git a/kernel/softirq.c b/kernel/softirq.c
73422 index ed567ba..dc61b61 100644
73423 --- a/kernel/softirq.c
73424 +++ b/kernel/softirq.c
73425 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
73426 EXPORT_SYMBOL(irq_stat);
73427 #endif
73428
73429 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
73430 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
73431
73432 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
73433
73434 -char *softirq_to_name[NR_SOFTIRQS] = {
73435 +const char * const softirq_to_name[NR_SOFTIRQS] = {
73436 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
73437 "TASKLET", "SCHED", "HRTIMER", "RCU"
73438 };
73439 @@ -244,7 +244,7 @@ restart:
73440 kstat_incr_softirqs_this_cpu(vec_nr);
73441
73442 trace_softirq_entry(vec_nr);
73443 - h->action(h);
73444 + h->action();
73445 trace_softirq_exit(vec_nr);
73446 if (unlikely(prev_count != preempt_count())) {
73447 printk(KERN_ERR "huh, entered softirq %u %s %p"
73448 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
73449 or_softirq_pending(1UL << nr);
73450 }
73451
73452 -void open_softirq(int nr, void (*action)(struct softirq_action *))
73453 +void __init open_softirq(int nr, void (*action)(void))
73454 {
73455 softirq_vec[nr].action = action;
73456 }
73457 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
73458
73459 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
73460
73461 -static void tasklet_action(struct softirq_action *a)
73462 +static void tasklet_action(void)
73463 {
73464 struct tasklet_struct *list;
73465
73466 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
73467 }
73468 }
73469
73470 -static void tasklet_hi_action(struct softirq_action *a)
73471 +static void tasklet_hi_action(void)
73472 {
73473 struct tasklet_struct *list;
73474
73475 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
73476 return NOTIFY_OK;
73477 }
73478
73479 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
73480 +static struct notifier_block remote_softirq_cpu_notifier = {
73481 .notifier_call = remote_softirq_cpu_notify,
73482 };
73483
73484 @@ -835,7 +835,7 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
73485 return NOTIFY_OK;
73486 }
73487
73488 -static struct notifier_block __cpuinitdata cpu_nfb = {
73489 +static struct notifier_block cpu_nfb = {
73490 .notifier_call = cpu_callback
73491 };
73492
73493 diff --git a/kernel/srcu.c b/kernel/srcu.c
73494 index 2b85982..d52ab26 100644
73495 --- a/kernel/srcu.c
73496 +++ b/kernel/srcu.c
73497 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
73498 preempt_disable();
73499 idx = rcu_dereference_index_check(sp->completed,
73500 rcu_read_lock_sched_held()) & 0x1;
73501 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73502 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
73503 smp_mb(); /* B */ /* Avoid leaking the critical section. */
73504 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73505 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
73506 preempt_enable();
73507 return idx;
73508 }
73509 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
73510 {
73511 preempt_disable();
73512 smp_mb(); /* C */ /* Avoid leaking the critical section. */
73513 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73514 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
73515 preempt_enable();
73516 }
73517 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
73518 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
73519 index 2f194e9..2c05ea9 100644
73520 --- a/kernel/stop_machine.c
73521 +++ b/kernel/stop_machine.c
73522 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
73523 * cpu notifiers. It currently shares the same priority as sched
73524 * migration_notifier.
73525 */
73526 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
73527 +static struct notifier_block cpu_stop_cpu_notifier = {
73528 .notifier_call = cpu_stop_cpu_callback,
73529 .priority = 10,
73530 };
73531 diff --git a/kernel/sys.c b/kernel/sys.c
73532 index 265b376..b0cd50d 100644
73533 --- a/kernel/sys.c
73534 +++ b/kernel/sys.c
73535 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
73536 error = -EACCES;
73537 goto out;
73538 }
73539 +
73540 + if (gr_handle_chroot_setpriority(p, niceval)) {
73541 + error = -EACCES;
73542 + goto out;
73543 + }
73544 +
73545 no_nice = security_task_setnice(p, niceval);
73546 if (no_nice) {
73547 error = no_nice;
73548 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
73549 goto error;
73550 }
73551
73552 + if (gr_check_group_change(new->gid, new->egid, -1))
73553 + goto error;
73554 +
73555 if (rgid != (gid_t) -1 ||
73556 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
73557 new->sgid = new->egid;
73558 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
73559 old = current_cred();
73560
73561 retval = -EPERM;
73562 +
73563 + if (gr_check_group_change(kgid, kgid, kgid))
73564 + goto error;
73565 +
73566 if (nsown_capable(CAP_SETGID))
73567 new->gid = new->egid = new->sgid = new->fsgid = kgid;
73568 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
73569 @@ -647,7 +660,7 @@ error:
73570 /*
73571 * change the user struct in a credentials set to match the new UID
73572 */
73573 -static int set_user(struct cred *new)
73574 +int set_user(struct cred *new)
73575 {
73576 struct user_struct *new_user;
73577
73578 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
73579 goto error;
73580 }
73581
73582 + if (gr_check_user_change(new->uid, new->euid, -1))
73583 + goto error;
73584 +
73585 if (!uid_eq(new->uid, old->uid)) {
73586 retval = set_user(new);
73587 if (retval < 0)
73588 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
73589 old = current_cred();
73590
73591 retval = -EPERM;
73592 +
73593 + if (gr_check_crash_uid(kuid))
73594 + goto error;
73595 + if (gr_check_user_change(kuid, kuid, kuid))
73596 + goto error;
73597 +
73598 if (nsown_capable(CAP_SETUID)) {
73599 new->suid = new->uid = kuid;
73600 if (!uid_eq(kuid, old->uid)) {
73601 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
73602 goto error;
73603 }
73604
73605 + if (gr_check_user_change(kruid, keuid, -1))
73606 + goto error;
73607 +
73608 if (ruid != (uid_t) -1) {
73609 new->uid = kruid;
73610 if (!uid_eq(kruid, old->uid)) {
73611 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
73612 goto error;
73613 }
73614
73615 + if (gr_check_group_change(krgid, kegid, -1))
73616 + goto error;
73617 +
73618 if (rgid != (gid_t) -1)
73619 new->gid = krgid;
73620 if (egid != (gid_t) -1)
73621 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73622 if (!uid_valid(kuid))
73623 return old_fsuid;
73624
73625 + if (gr_check_user_change(-1, -1, kuid))
73626 + goto error;
73627 +
73628 new = prepare_creds();
73629 if (!new)
73630 return old_fsuid;
73631 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
73632 }
73633 }
73634
73635 +error:
73636 abort_creds(new);
73637 return old_fsuid;
73638
73639 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
73640 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
73641 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
73642 nsown_capable(CAP_SETGID)) {
73643 + if (gr_check_group_change(-1, -1, kgid))
73644 + goto error;
73645 +
73646 if (!gid_eq(kgid, old->fsgid)) {
73647 new->fsgid = kgid;
73648 goto change_okay;
73649 }
73650 }
73651
73652 +error:
73653 abort_creds(new);
73654 return old_fsgid;
73655
73656 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
73657 return -EFAULT;
73658
73659 down_read(&uts_sem);
73660 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
73661 + error = __copy_to_user(name->sysname, &utsname()->sysname,
73662 __OLD_UTS_LEN);
73663 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
73664 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
73665 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
73666 __OLD_UTS_LEN);
73667 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
73668 - error |= __copy_to_user(&name->release, &utsname()->release,
73669 + error |= __copy_to_user(name->release, &utsname()->release,
73670 __OLD_UTS_LEN);
73671 error |= __put_user(0, name->release + __OLD_UTS_LEN);
73672 - error |= __copy_to_user(&name->version, &utsname()->version,
73673 + error |= __copy_to_user(name->version, &utsname()->version,
73674 __OLD_UTS_LEN);
73675 error |= __put_user(0, name->version + __OLD_UTS_LEN);
73676 - error |= __copy_to_user(&name->machine, &utsname()->machine,
73677 + error |= __copy_to_user(name->machine, &utsname()->machine,
73678 __OLD_UTS_LEN);
73679 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
73680 up_read(&uts_sem);
73681 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
73682 error = get_dumpable(me->mm);
73683 break;
73684 case PR_SET_DUMPABLE:
73685 - if (arg2 < 0 || arg2 > 1) {
73686 + if (arg2 > 1) {
73687 error = -EINVAL;
73688 break;
73689 }
73690 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
73691 index c88878d..99d321b 100644
73692 --- a/kernel/sysctl.c
73693 +++ b/kernel/sysctl.c
73694 @@ -92,7 +92,6 @@
73695
73696
73697 #if defined(CONFIG_SYSCTL)
73698 -
73699 /* External variables not in a header file. */
73700 extern int sysctl_overcommit_memory;
73701 extern int sysctl_overcommit_ratio;
73702 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
73703 void __user *buffer, size_t *lenp, loff_t *ppos);
73704 #endif
73705
73706 -#ifdef CONFIG_PRINTK
73707 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73708 void __user *buffer, size_t *lenp, loff_t *ppos);
73709 -#endif
73710
73711 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
73712 void __user *buffer, size_t *lenp, loff_t *ppos);
73713 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
73714
73715 #endif
73716
73717 +extern struct ctl_table grsecurity_table[];
73718 +
73719 static struct ctl_table kern_table[];
73720 static struct ctl_table vm_table[];
73721 static struct ctl_table fs_table[];
73722 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
73723 int sysctl_legacy_va_layout;
73724 #endif
73725
73726 +#ifdef CONFIG_PAX_SOFTMODE
73727 +static ctl_table pax_table[] = {
73728 + {
73729 + .procname = "softmode",
73730 + .data = &pax_softmode,
73731 + .maxlen = sizeof(unsigned int),
73732 + .mode = 0600,
73733 + .proc_handler = &proc_dointvec,
73734 + },
73735 +
73736 + { }
73737 +};
73738 +#endif
73739 +
73740 /* The default sysctl tables: */
73741
73742 static struct ctl_table sysctl_base_table[] = {
73743 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
73744 #endif
73745
73746 static struct ctl_table kern_table[] = {
73747 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
73748 + {
73749 + .procname = "grsecurity",
73750 + .mode = 0500,
73751 + .child = grsecurity_table,
73752 + },
73753 +#endif
73754 +
73755 +#ifdef CONFIG_PAX_SOFTMODE
73756 + {
73757 + .procname = "pax",
73758 + .mode = 0500,
73759 + .child = pax_table,
73760 + },
73761 +#endif
73762 +
73763 {
73764 .procname = "sched_child_runs_first",
73765 .data = &sysctl_sched_child_runs_first,
73766 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
73767 .data = &modprobe_path,
73768 .maxlen = KMOD_PATH_LEN,
73769 .mode = 0644,
73770 - .proc_handler = proc_dostring,
73771 + .proc_handler = proc_dostring_modpriv,
73772 },
73773 {
73774 .procname = "modules_disabled",
73775 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
73776 .extra1 = &zero,
73777 .extra2 = &one,
73778 },
73779 +#endif
73780 {
73781 .procname = "kptr_restrict",
73782 .data = &kptr_restrict,
73783 .maxlen = sizeof(int),
73784 .mode = 0644,
73785 .proc_handler = proc_dointvec_minmax_sysadmin,
73786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73787 + .extra1 = &two,
73788 +#else
73789 .extra1 = &zero,
73790 +#endif
73791 .extra2 = &two,
73792 },
73793 -#endif
73794 {
73795 .procname = "ngroups_max",
73796 .data = &ngroups_max,
73797 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
73798 .proc_handler = proc_dointvec_minmax,
73799 .extra1 = &zero,
73800 },
73801 + {
73802 + .procname = "heap_stack_gap",
73803 + .data = &sysctl_heap_stack_gap,
73804 + .maxlen = sizeof(sysctl_heap_stack_gap),
73805 + .mode = 0644,
73806 + .proc_handler = proc_doulongvec_minmax,
73807 + },
73808 #else
73809 {
73810 .procname = "nr_trim_pages",
73811 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
73812 buffer, lenp, ppos);
73813 }
73814
73815 +int proc_dostring_modpriv(struct ctl_table *table, int write,
73816 + void __user *buffer, size_t *lenp, loff_t *ppos)
73817 +{
73818 + if (write && !capable(CAP_SYS_MODULE))
73819 + return -EPERM;
73820 +
73821 + return _proc_do_string(table->data, table->maxlen, write,
73822 + buffer, lenp, ppos);
73823 +}
73824 +
73825 static size_t proc_skip_spaces(char **buf)
73826 {
73827 size_t ret;
73828 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
73829 len = strlen(tmp);
73830 if (len > *size)
73831 len = *size;
73832 + if (len > sizeof(tmp))
73833 + len = sizeof(tmp);
73834 if (copy_to_user(*buf, tmp, len))
73835 return -EFAULT;
73836 *size -= len;
73837 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
73838 return err;
73839 }
73840
73841 -#ifdef CONFIG_PRINTK
73842 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73843 void __user *buffer, size_t *lenp, loff_t *ppos)
73844 {
73845 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
73846
73847 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
73848 }
73849 -#endif
73850
73851 struct do_proc_dointvec_minmax_conv_param {
73852 int *min;
73853 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
73854 *i = val;
73855 } else {
73856 val = convdiv * (*i) / convmul;
73857 - if (!first)
73858 + if (!first) {
73859 err = proc_put_char(&buffer, &left, '\t');
73860 + if (err)
73861 + break;
73862 + }
73863 err = proc_put_long(&buffer, &left, val, false);
73864 if (err)
73865 break;
73866 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
73867 return -ENOSYS;
73868 }
73869
73870 +int proc_dostring_modpriv(struct ctl_table *table, int write,
73871 + void __user *buffer, size_t *lenp, loff_t *ppos)
73872 +{
73873 + return -ENOSYS;
73874 +}
73875 +
73876 int proc_dointvec(struct ctl_table *table, int write,
73877 void __user *buffer, size_t *lenp, loff_t *ppos)
73878 {
73879 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
73880 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
73881 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
73882 EXPORT_SYMBOL(proc_dostring);
73883 +EXPORT_SYMBOL(proc_dostring_modpriv);
73884 EXPORT_SYMBOL(proc_doulongvec_minmax);
73885 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
73886 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
73887 index 5a63844..25dfc5c 100644
73888 --- a/kernel/sysctl_binary.c
73889 +++ b/kernel/sysctl_binary.c
73890 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
73891 int i;
73892
73893 set_fs(KERNEL_DS);
73894 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73895 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73896 set_fs(old_fs);
73897 if (result < 0)
73898 goto out_kfree;
73899 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
73900 }
73901
73902 set_fs(KERNEL_DS);
73903 - result = vfs_write(file, buffer, str - buffer, &pos);
73904 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73905 set_fs(old_fs);
73906 if (result < 0)
73907 goto out_kfree;
73908 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
73909 int i;
73910
73911 set_fs(KERNEL_DS);
73912 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
73913 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
73914 set_fs(old_fs);
73915 if (result < 0)
73916 goto out_kfree;
73917 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
73918 }
73919
73920 set_fs(KERNEL_DS);
73921 - result = vfs_write(file, buffer, str - buffer, &pos);
73922 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
73923 set_fs(old_fs);
73924 if (result < 0)
73925 goto out_kfree;
73926 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
73927 int i;
73928
73929 set_fs(KERNEL_DS);
73930 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73931 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73932 set_fs(old_fs);
73933 if (result < 0)
73934 goto out;
73935 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73936 __le16 dnaddr;
73937
73938 set_fs(KERNEL_DS);
73939 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
73940 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
73941 set_fs(old_fs);
73942 if (result < 0)
73943 goto out;
73944 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
73945 le16_to_cpu(dnaddr) & 0x3ff);
73946
73947 set_fs(KERNEL_DS);
73948 - result = vfs_write(file, buf, len, &pos);
73949 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
73950 set_fs(old_fs);
73951 if (result < 0)
73952 goto out;
73953 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
73954 index 145bb4d..b2aa969 100644
73955 --- a/kernel/taskstats.c
73956 +++ b/kernel/taskstats.c
73957 @@ -28,9 +28,12 @@
73958 #include <linux/fs.h>
73959 #include <linux/file.h>
73960 #include <linux/pid_namespace.h>
73961 +#include <linux/grsecurity.h>
73962 #include <net/genetlink.h>
73963 #include <linux/atomic.h>
73964
73965 +extern int gr_is_taskstats_denied(int pid);
73966 +
73967 /*
73968 * Maximum length of a cpumask that can be specified in
73969 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
73970 @@ -570,6 +573,9 @@ err:
73971
73972 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
73973 {
73974 + if (gr_is_taskstats_denied(current->pid))
73975 + return -EACCES;
73976 +
73977 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
73978 return cmd_attr_register_cpumask(info);
73979 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
73980 diff --git a/kernel/time.c b/kernel/time.c
73981 index d226c6a..c7c0960 100644
73982 --- a/kernel/time.c
73983 +++ b/kernel/time.c
73984 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
73985 return error;
73986
73987 if (tz) {
73988 + /* we log in do_settimeofday called below, so don't log twice
73989 + */
73990 + if (!tv)
73991 + gr_log_timechange();
73992 +
73993 sys_tz = *tz;
73994 update_vsyscall_tz();
73995 if (firsttime) {
73996 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
73997 index f11d83b..d016d91 100644
73998 --- a/kernel/time/alarmtimer.c
73999 +++ b/kernel/time/alarmtimer.c
74000 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
74001 struct platform_device *pdev;
74002 int error = 0;
74003 int i;
74004 - struct k_clock alarm_clock = {
74005 + static struct k_clock alarm_clock = {
74006 .clock_getres = alarm_clock_getres,
74007 .clock_get = alarm_clock_get,
74008 .timer_create = alarm_timer_create,
74009 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
74010 index f113755..ec24223 100644
74011 --- a/kernel/time/tick-broadcast.c
74012 +++ b/kernel/time/tick-broadcast.c
74013 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
74014 * then clear the broadcast bit.
74015 */
74016 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
74017 - int cpu = smp_processor_id();
74018 + cpu = smp_processor_id();
74019
74020 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
74021 tick_broadcast_clear_oneshot(cpu);
74022 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
74023 index cbc6acb..3a77191 100644
74024 --- a/kernel/time/timekeeping.c
74025 +++ b/kernel/time/timekeeping.c
74026 @@ -15,6 +15,7 @@
74027 #include <linux/init.h>
74028 #include <linux/mm.h>
74029 #include <linux/sched.h>
74030 +#include <linux/grsecurity.h>
74031 #include <linux/syscore_ops.h>
74032 #include <linux/clocksource.h>
74033 #include <linux/jiffies.h>
74034 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
74035 if (!timespec_valid_strict(tv))
74036 return -EINVAL;
74037
74038 + gr_log_timechange();
74039 +
74040 write_seqlock_irqsave(&tk->lock, flags);
74041
74042 timekeeping_forward_now(tk);
74043 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
74044 index af5a7e9..715611a 100644
74045 --- a/kernel/time/timer_list.c
74046 +++ b/kernel/time/timer_list.c
74047 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
74048
74049 static void print_name_offset(struct seq_file *m, void *sym)
74050 {
74051 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74052 + SEQ_printf(m, "<%p>", NULL);
74053 +#else
74054 char symname[KSYM_NAME_LEN];
74055
74056 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
74057 SEQ_printf(m, "<%pK>", sym);
74058 else
74059 SEQ_printf(m, "%s", symname);
74060 +#endif
74061 }
74062
74063 static void
74064 @@ -112,7 +116,11 @@ next_one:
74065 static void
74066 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
74067 {
74068 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74069 + SEQ_printf(m, " .base: %p\n", NULL);
74070 +#else
74071 SEQ_printf(m, " .base: %pK\n", base);
74072 +#endif
74073 SEQ_printf(m, " .index: %d\n",
74074 base->index);
74075 SEQ_printf(m, " .resolution: %Lu nsecs\n",
74076 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
74077 {
74078 struct proc_dir_entry *pe;
74079
74080 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74081 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
74082 +#else
74083 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
74084 +#endif
74085 if (!pe)
74086 return -ENOMEM;
74087 return 0;
74088 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
74089 index 0b537f2..40d6c20 100644
74090 --- a/kernel/time/timer_stats.c
74091 +++ b/kernel/time/timer_stats.c
74092 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
74093 static unsigned long nr_entries;
74094 static struct entry entries[MAX_ENTRIES];
74095
74096 -static atomic_t overflow_count;
74097 +static atomic_unchecked_t overflow_count;
74098
74099 /*
74100 * The entries are in a hash-table, for fast lookup:
74101 @@ -140,7 +140,7 @@ static void reset_entries(void)
74102 nr_entries = 0;
74103 memset(entries, 0, sizeof(entries));
74104 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
74105 - atomic_set(&overflow_count, 0);
74106 + atomic_set_unchecked(&overflow_count, 0);
74107 }
74108
74109 static struct entry *alloc_entry(void)
74110 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74111 if (likely(entry))
74112 entry->count++;
74113 else
74114 - atomic_inc(&overflow_count);
74115 + atomic_inc_unchecked(&overflow_count);
74116
74117 out_unlock:
74118 raw_spin_unlock_irqrestore(lock, flags);
74119 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
74120
74121 static void print_name_offset(struct seq_file *m, unsigned long addr)
74122 {
74123 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74124 + seq_printf(m, "<%p>", NULL);
74125 +#else
74126 char symname[KSYM_NAME_LEN];
74127
74128 if (lookup_symbol_name(addr, symname) < 0)
74129 - seq_printf(m, "<%p>", (void *)addr);
74130 + seq_printf(m, "<%pK>", (void *)addr);
74131 else
74132 seq_printf(m, "%s", symname);
74133 +#endif
74134 }
74135
74136 static int tstats_show(struct seq_file *m, void *v)
74137 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
74138
74139 seq_puts(m, "Timer Stats Version: v0.2\n");
74140 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
74141 - if (atomic_read(&overflow_count))
74142 + if (atomic_read_unchecked(&overflow_count))
74143 seq_printf(m, "Overflow: %d entries\n",
74144 - atomic_read(&overflow_count));
74145 + atomic_read_unchecked(&overflow_count));
74146
74147 for (i = 0; i < nr_entries; i++) {
74148 entry = entries + i;
74149 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
74150 {
74151 struct proc_dir_entry *pe;
74152
74153 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
74154 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
74155 +#else
74156 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
74157 +#endif
74158 if (!pe)
74159 return -ENOMEM;
74160 return 0;
74161 diff --git a/kernel/timer.c b/kernel/timer.c
74162 index 367d008..1ee9ed9 100644
74163 --- a/kernel/timer.c
74164 +++ b/kernel/timer.c
74165 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
74166 /*
74167 * This function runs timers and the timer-tq in bottom half context.
74168 */
74169 -static void run_timer_softirq(struct softirq_action *h)
74170 +static void run_timer_softirq(void)
74171 {
74172 struct tvec_base *base = __this_cpu_read(tvec_bases);
74173
74174 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
74175 return NOTIFY_OK;
74176 }
74177
74178 -static struct notifier_block __cpuinitdata timers_nb = {
74179 +static struct notifier_block timers_nb = {
74180 .notifier_call = timer_cpu_notify,
74181 };
74182
74183 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
74184 index c0bd030..62a1927 100644
74185 --- a/kernel/trace/blktrace.c
74186 +++ b/kernel/trace/blktrace.c
74187 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
74188 struct blk_trace *bt = filp->private_data;
74189 char buf[16];
74190
74191 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
74192 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
74193
74194 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
74195 }
74196 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
74197 return 1;
74198
74199 bt = buf->chan->private_data;
74200 - atomic_inc(&bt->dropped);
74201 + atomic_inc_unchecked(&bt->dropped);
74202 return 0;
74203 }
74204
74205 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
74206
74207 bt->dir = dir;
74208 bt->dev = dev;
74209 - atomic_set(&bt->dropped, 0);
74210 + atomic_set_unchecked(&bt->dropped, 0);
74211
74212 ret = -EIO;
74213 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
74214 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
74215 index 41473b4..325fcfc 100644
74216 --- a/kernel/trace/ftrace.c
74217 +++ b/kernel/trace/ftrace.c
74218 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
74219 if (unlikely(ftrace_disabled))
74220 return 0;
74221
74222 + ret = ftrace_arch_code_modify_prepare();
74223 + FTRACE_WARN_ON(ret);
74224 + if (ret)
74225 + return 0;
74226 +
74227 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
74228 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
74229 if (ret) {
74230 ftrace_bug(ret, ip);
74231 - return 0;
74232 }
74233 - return 1;
74234 + return ret ? 0 : 1;
74235 }
74236
74237 /*
74238 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
74239
74240 int
74241 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
74242 - void *data)
74243 + void *data)
74244 {
74245 struct ftrace_func_probe *entry;
74246 struct ftrace_page *pg;
74247 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
74248 if (!count)
74249 return 0;
74250
74251 + pax_open_kernel();
74252 sort(start, count, sizeof(*start),
74253 ftrace_cmp_ips, ftrace_swap_ips);
74254 + pax_close_kernel();
74255
74256 start_pg = ftrace_allocate_pages(count);
74257 if (!start_pg)
74258 @@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
74259 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
74260
74261 static int ftrace_graph_active;
74262 -static struct notifier_block ftrace_suspend_notifier;
74263 -
74264 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
74265 {
74266 return 0;
74267 @@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
74268 return NOTIFY_DONE;
74269 }
74270
74271 +static struct notifier_block ftrace_suspend_notifier = {
74272 + .notifier_call = ftrace_suspend_notifier_call
74273 +};
74274 +
74275 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74276 trace_func_graph_ent_t entryfunc)
74277 {
74278 @@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
74279 goto out;
74280 }
74281
74282 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
74283 register_pm_notifier(&ftrace_suspend_notifier);
74284
74285 ftrace_graph_active++;
74286 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
74287 index ce8514f..8233573 100644
74288 --- a/kernel/trace/ring_buffer.c
74289 +++ b/kernel/trace/ring_buffer.c
74290 @@ -346,9 +346,9 @@ struct buffer_data_page {
74291 */
74292 struct buffer_page {
74293 struct list_head list; /* list of buffer pages */
74294 - local_t write; /* index for next write */
74295 + local_unchecked_t write; /* index for next write */
74296 unsigned read; /* index for next read */
74297 - local_t entries; /* entries on this page */
74298 + local_unchecked_t entries; /* entries on this page */
74299 unsigned long real_end; /* real end of data */
74300 struct buffer_data_page *page; /* Actual data page */
74301 };
74302 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
74303 unsigned long last_overrun;
74304 local_t entries_bytes;
74305 local_t entries;
74306 - local_t overrun;
74307 - local_t commit_overrun;
74308 + local_unchecked_t overrun;
74309 + local_unchecked_t commit_overrun;
74310 local_t dropped_events;
74311 local_t committing;
74312 local_t commits;
74313 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74314 *
74315 * We add a counter to the write field to denote this.
74316 */
74317 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
74318 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
74319 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
74320 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
74321
74322 /*
74323 * Just make sure we have seen our old_write and synchronize
74324 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
74325 * cmpxchg to only update if an interrupt did not already
74326 * do it for us. If the cmpxchg fails, we don't care.
74327 */
74328 - (void)local_cmpxchg(&next_page->write, old_write, val);
74329 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
74330 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
74331 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
74332
74333 /*
74334 * No need to worry about races with clearing out the commit.
74335 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
74336
74337 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
74338 {
74339 - return local_read(&bpage->entries) & RB_WRITE_MASK;
74340 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
74341 }
74342
74343 static inline unsigned long rb_page_write(struct buffer_page *bpage)
74344 {
74345 - return local_read(&bpage->write) & RB_WRITE_MASK;
74346 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
74347 }
74348
74349 static int
74350 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
74351 * bytes consumed in ring buffer from here.
74352 * Increment overrun to account for the lost events.
74353 */
74354 - local_add(page_entries, &cpu_buffer->overrun);
74355 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
74356 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74357 }
74358
74359 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
74360 * it is our responsibility to update
74361 * the counters.
74362 */
74363 - local_add(entries, &cpu_buffer->overrun);
74364 + local_add_unchecked(entries, &cpu_buffer->overrun);
74365 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
74366
74367 /*
74368 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74369 if (tail == BUF_PAGE_SIZE)
74370 tail_page->real_end = 0;
74371
74372 - local_sub(length, &tail_page->write);
74373 + local_sub_unchecked(length, &tail_page->write);
74374 return;
74375 }
74376
74377 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74378 rb_event_set_padding(event);
74379
74380 /* Set the write back to the previous setting */
74381 - local_sub(length, &tail_page->write);
74382 + local_sub_unchecked(length, &tail_page->write);
74383 return;
74384 }
74385
74386 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
74387
74388 /* Set write to end of buffer */
74389 length = (tail + length) - BUF_PAGE_SIZE;
74390 - local_sub(length, &tail_page->write);
74391 + local_sub_unchecked(length, &tail_page->write);
74392 }
74393
74394 /*
74395 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74396 * about it.
74397 */
74398 if (unlikely(next_page == commit_page)) {
74399 - local_inc(&cpu_buffer->commit_overrun);
74400 + local_inc_unchecked(&cpu_buffer->commit_overrun);
74401 goto out_reset;
74402 }
74403
74404 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
74405 cpu_buffer->tail_page) &&
74406 (cpu_buffer->commit_page ==
74407 cpu_buffer->reader_page))) {
74408 - local_inc(&cpu_buffer->commit_overrun);
74409 + local_inc_unchecked(&cpu_buffer->commit_overrun);
74410 goto out_reset;
74411 }
74412 }
74413 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74414 length += RB_LEN_TIME_EXTEND;
74415
74416 tail_page = cpu_buffer->tail_page;
74417 - write = local_add_return(length, &tail_page->write);
74418 + write = local_add_return_unchecked(length, &tail_page->write);
74419
74420 /* set write to only the index of the write */
74421 write &= RB_WRITE_MASK;
74422 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
74423 kmemcheck_annotate_bitfield(event, bitfield);
74424 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
74425
74426 - local_inc(&tail_page->entries);
74427 + local_inc_unchecked(&tail_page->entries);
74428
74429 /*
74430 * If this is the first commit on the page, then update
74431 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74432
74433 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
74434 unsigned long write_mask =
74435 - local_read(&bpage->write) & ~RB_WRITE_MASK;
74436 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
74437 unsigned long event_length = rb_event_length(event);
74438 /*
74439 * This is on the tail page. It is possible that
74440 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
74441 */
74442 old_index += write_mask;
74443 new_index += write_mask;
74444 - index = local_cmpxchg(&bpage->write, old_index, new_index);
74445 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
74446 if (index == old_index) {
74447 /* update counters */
74448 local_sub(event_length, &cpu_buffer->entries_bytes);
74449 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74450
74451 /* Do the likely case first */
74452 if (likely(bpage->page == (void *)addr)) {
74453 - local_dec(&bpage->entries);
74454 + local_dec_unchecked(&bpage->entries);
74455 return;
74456 }
74457
74458 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
74459 start = bpage;
74460 do {
74461 if (bpage->page == (void *)addr) {
74462 - local_dec(&bpage->entries);
74463 + local_dec_unchecked(&bpage->entries);
74464 return;
74465 }
74466 rb_inc_page(cpu_buffer, &bpage);
74467 @@ -2926,7 +2926,7 @@ static inline unsigned long
74468 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
74469 {
74470 return local_read(&cpu_buffer->entries) -
74471 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
74472 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
74473 }
74474
74475 /**
74476 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
74477 return 0;
74478
74479 cpu_buffer = buffer->buffers[cpu];
74480 - ret = local_read(&cpu_buffer->overrun);
74481 + ret = local_read_unchecked(&cpu_buffer->overrun);
74482
74483 return ret;
74484 }
74485 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
74486 return 0;
74487
74488 cpu_buffer = buffer->buffers[cpu];
74489 - ret = local_read(&cpu_buffer->commit_overrun);
74490 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
74491
74492 return ret;
74493 }
74494 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
74495 /* if you care about this being correct, lock the buffer */
74496 for_each_buffer_cpu(buffer, cpu) {
74497 cpu_buffer = buffer->buffers[cpu];
74498 - overruns += local_read(&cpu_buffer->overrun);
74499 + overruns += local_read_unchecked(&cpu_buffer->overrun);
74500 }
74501
74502 return overruns;
74503 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74504 /*
74505 * Reset the reader page to size zero.
74506 */
74507 - local_set(&cpu_buffer->reader_page->write, 0);
74508 - local_set(&cpu_buffer->reader_page->entries, 0);
74509 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74510 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74511 local_set(&cpu_buffer->reader_page->page->commit, 0);
74512 cpu_buffer->reader_page->real_end = 0;
74513
74514 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
74515 * want to compare with the last_overrun.
74516 */
74517 smp_mb();
74518 - overwrite = local_read(&(cpu_buffer->overrun));
74519 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
74520
74521 /*
74522 * Here's the tricky part.
74523 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74524
74525 cpu_buffer->head_page
74526 = list_entry(cpu_buffer->pages, struct buffer_page, list);
74527 - local_set(&cpu_buffer->head_page->write, 0);
74528 - local_set(&cpu_buffer->head_page->entries, 0);
74529 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
74530 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
74531 local_set(&cpu_buffer->head_page->page->commit, 0);
74532
74533 cpu_buffer->head_page->read = 0;
74534 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
74535
74536 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
74537 INIT_LIST_HEAD(&cpu_buffer->new_pages);
74538 - local_set(&cpu_buffer->reader_page->write, 0);
74539 - local_set(&cpu_buffer->reader_page->entries, 0);
74540 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
74541 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
74542 local_set(&cpu_buffer->reader_page->page->commit, 0);
74543 cpu_buffer->reader_page->read = 0;
74544
74545 local_set(&cpu_buffer->entries_bytes, 0);
74546 - local_set(&cpu_buffer->overrun, 0);
74547 - local_set(&cpu_buffer->commit_overrun, 0);
74548 + local_set_unchecked(&cpu_buffer->overrun, 0);
74549 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
74550 local_set(&cpu_buffer->dropped_events, 0);
74551 local_set(&cpu_buffer->entries, 0);
74552 local_set(&cpu_buffer->committing, 0);
74553 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
74554 rb_init_page(bpage);
74555 bpage = reader->page;
74556 reader->page = *data_page;
74557 - local_set(&reader->write, 0);
74558 - local_set(&reader->entries, 0);
74559 + local_set_unchecked(&reader->write, 0);
74560 + local_set_unchecked(&reader->entries, 0);
74561 reader->read = 0;
74562 *data_page = bpage;
74563
74564 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
74565 index 3c13e46..883d039 100644
74566 --- a/kernel/trace/trace.c
74567 +++ b/kernel/trace/trace.c
74568 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
74569 };
74570 #endif
74571
74572 -static struct dentry *d_tracer;
74573 -
74574 struct dentry *tracing_init_dentry(void)
74575 {
74576 + static struct dentry *d_tracer;
74577 static int once;
74578
74579 if (d_tracer)
74580 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
74581 return d_tracer;
74582 }
74583
74584 -static struct dentry *d_percpu;
74585 -
74586 struct dentry *tracing_dentry_percpu(void)
74587 {
74588 + static struct dentry *d_percpu;
74589 static int once;
74590 struct dentry *d_tracer;
74591
74592 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
74593 index 880073d..42db7c3 100644
74594 --- a/kernel/trace/trace_events.c
74595 +++ b/kernel/trace/trace_events.c
74596 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
74597 struct ftrace_module_file_ops {
74598 struct list_head list;
74599 struct module *mod;
74600 - struct file_operations id;
74601 - struct file_operations enable;
74602 - struct file_operations format;
74603 - struct file_operations filter;
74604 };
74605
74606 static struct ftrace_module_file_ops *
74607 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
74608
74609 file_ops->mod = mod;
74610
74611 - file_ops->id = ftrace_event_id_fops;
74612 - file_ops->id.owner = mod;
74613 -
74614 - file_ops->enable = ftrace_enable_fops;
74615 - file_ops->enable.owner = mod;
74616 -
74617 - file_ops->filter = ftrace_event_filter_fops;
74618 - file_ops->filter.owner = mod;
74619 -
74620 - file_ops->format = ftrace_event_format_fops;
74621 - file_ops->format.owner = mod;
74622 + pax_open_kernel();
74623 + mod->trace_id.owner = mod;
74624 + mod->trace_enable.owner = mod;
74625 + mod->trace_filter.owner = mod;
74626 + mod->trace_format.owner = mod;
74627 + pax_close_kernel();
74628
74629 list_add(&file_ops->list, &ftrace_module_file_list);
74630
74631 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
74632
74633 for_each_event(call, start, end) {
74634 __trace_add_event_call(*call, mod,
74635 - &file_ops->id, &file_ops->enable,
74636 - &file_ops->filter, &file_ops->format);
74637 + &mod->trace_id, &mod->trace_enable,
74638 + &mod->trace_filter, &mod->trace_format);
74639 }
74640 }
74641
74642 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
74643 index fd3c8aa..5f324a6 100644
74644 --- a/kernel/trace/trace_mmiotrace.c
74645 +++ b/kernel/trace/trace_mmiotrace.c
74646 @@ -24,7 +24,7 @@ struct header_iter {
74647 static struct trace_array *mmio_trace_array;
74648 static bool overrun_detected;
74649 static unsigned long prev_overruns;
74650 -static atomic_t dropped_count;
74651 +static atomic_unchecked_t dropped_count;
74652
74653 static void mmio_reset_data(struct trace_array *tr)
74654 {
74655 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
74656
74657 static unsigned long count_overruns(struct trace_iterator *iter)
74658 {
74659 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
74660 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
74661 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
74662
74663 if (over > prev_overruns)
74664 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
74665 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
74666 sizeof(*entry), 0, pc);
74667 if (!event) {
74668 - atomic_inc(&dropped_count);
74669 + atomic_inc_unchecked(&dropped_count);
74670 return;
74671 }
74672 entry = ring_buffer_event_data(event);
74673 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
74674 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
74675 sizeof(*entry), 0, pc);
74676 if (!event) {
74677 - atomic_inc(&dropped_count);
74678 + atomic_inc_unchecked(&dropped_count);
74679 return;
74680 }
74681 entry = ring_buffer_event_data(event);
74682 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
74683 index 194d796..76edb8f 100644
74684 --- a/kernel/trace/trace_output.c
74685 +++ b/kernel/trace/trace_output.c
74686 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
74687
74688 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
74689 if (!IS_ERR(p)) {
74690 - p = mangle_path(s->buffer + s->len, p, "\n");
74691 + p = mangle_path(s->buffer + s->len, p, "\n\\");
74692 if (p) {
74693 s->len = p - s->buffer;
74694 return 1;
74695 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
74696 goto out;
74697 }
74698
74699 + pax_open_kernel();
74700 if (event->funcs->trace == NULL)
74701 - event->funcs->trace = trace_nop_print;
74702 + *(void **)&event->funcs->trace = trace_nop_print;
74703 if (event->funcs->raw == NULL)
74704 - event->funcs->raw = trace_nop_print;
74705 + *(void **)&event->funcs->raw = trace_nop_print;
74706 if (event->funcs->hex == NULL)
74707 - event->funcs->hex = trace_nop_print;
74708 + *(void **)&event->funcs->hex = trace_nop_print;
74709 if (event->funcs->binary == NULL)
74710 - event->funcs->binary = trace_nop_print;
74711 + *(void **)&event->funcs->binary = trace_nop_print;
74712 + pax_close_kernel();
74713
74714 key = event->type & (EVENT_HASHSIZE - 1);
74715
74716 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
74717 index 42ca822..cdcacc6 100644
74718 --- a/kernel/trace/trace_stack.c
74719 +++ b/kernel/trace/trace_stack.c
74720 @@ -52,7 +52,7 @@ static inline void check_stack(void)
74721 return;
74722
74723 /* we do not handle interrupt stacks yet */
74724 - if (!object_is_on_stack(&this_size))
74725 + if (!object_starts_on_stack(&this_size))
74726 return;
74727
74728 local_irq_save(flags);
74729 diff --git a/kernel/user.c b/kernel/user.c
74730 index 33acb5e..57ebfd4 100644
74731 --- a/kernel/user.c
74732 +++ b/kernel/user.c
74733 @@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
74734 .count = 4294967295U,
74735 },
74736 },
74737 - .kref = {
74738 - .refcount = ATOMIC_INIT(3),
74739 - },
74740 + .count = ATOMIC_INIT(3),
74741 .owner = GLOBAL_ROOT_UID,
74742 .group = GLOBAL_ROOT_GID,
74743 .proc_inum = PROC_USER_INIT_INO,
74744 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
74745 index 2b042c4..24f8ec3 100644
74746 --- a/kernel/user_namespace.c
74747 +++ b/kernel/user_namespace.c
74748 @@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
74749 return ret;
74750 }
74751
74752 - kref_init(&ns->kref);
74753 + atomic_set(&ns->count, 1);
74754 /* Leave the new->user_ns reference with the new user namespace. */
74755 ns->parent = parent_ns;
74756 ns->owner = owner;
74757 @@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
74758 return create_user_ns(cred);
74759 }
74760
74761 -void free_user_ns(struct kref *kref)
74762 +void free_user_ns(struct user_namespace *ns)
74763 {
74764 - struct user_namespace *parent, *ns =
74765 - container_of(kref, struct user_namespace, kref);
74766 + struct user_namespace *parent;
74767
74768 - parent = ns->parent;
74769 - proc_free_inum(ns->proc_inum);
74770 - kmem_cache_free(user_ns_cachep, ns);
74771 - put_user_ns(parent);
74772 + do {
74773 + parent = ns->parent;
74774 + proc_free_inum(ns->proc_inum);
74775 + kmem_cache_free(user_ns_cachep, ns);
74776 + ns = parent;
74777 + } while (atomic_dec_and_test(&parent->count));
74778 }
74779 EXPORT_SYMBOL(free_user_ns);
74780
74781 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
74782 index 67604e5..3ebb003 100644
74783 --- a/lib/Kconfig.debug
74784 +++ b/lib/Kconfig.debug
74785 @@ -1278,6 +1278,7 @@ config LATENCYTOP
74786 depends on DEBUG_KERNEL
74787 depends on STACKTRACE_SUPPORT
74788 depends on PROC_FS
74789 + depends on !GRKERNSEC_HIDESYM
74790 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
74791 select KALLSYMS
74792 select KALLSYMS_ALL
74793 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
74794
74795 config PROVIDE_OHCI1394_DMA_INIT
74796 bool "Remote debugging over FireWire early on boot"
74797 - depends on PCI && X86
74798 + depends on PCI && X86 && !GRKERNSEC
74799 help
74800 If you want to debug problems which hang or crash the kernel early
74801 on boot and the crashing machine has a FireWire port, you can use
74802 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
74803
74804 config FIREWIRE_OHCI_REMOTE_DMA
74805 bool "Remote debugging over FireWire with firewire-ohci"
74806 - depends on FIREWIRE_OHCI
74807 + depends on FIREWIRE_OHCI && !GRKERNSEC
74808 help
74809 This option lets you use the FireWire bus for remote debugging
74810 with help of the firewire-ohci driver. It enables unfiltered
74811 diff --git a/lib/Makefile b/lib/Makefile
74812 index 02ed6c0..bd243da 100644
74813 --- a/lib/Makefile
74814 +++ b/lib/Makefile
74815 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
74816
74817 obj-$(CONFIG_BTREE) += btree.o
74818 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
74819 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
74820 +obj-y += list_debug.o
74821 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
74822
74823 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
74824 diff --git a/lib/bitmap.c b/lib/bitmap.c
74825 index 06f7e4f..f3cf2b0 100644
74826 --- a/lib/bitmap.c
74827 +++ b/lib/bitmap.c
74828 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
74829 {
74830 int c, old_c, totaldigits, ndigits, nchunks, nbits;
74831 u32 chunk;
74832 - const char __user __force *ubuf = (const char __user __force *)buf;
74833 + const char __user *ubuf = (const char __force_user *)buf;
74834
74835 bitmap_zero(maskp, nmaskbits);
74836
74837 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
74838 {
74839 if (!access_ok(VERIFY_READ, ubuf, ulen))
74840 return -EFAULT;
74841 - return __bitmap_parse((const char __force *)ubuf,
74842 + return __bitmap_parse((const char __force_kernel *)ubuf,
74843 ulen, 1, maskp, nmaskbits);
74844
74845 }
74846 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
74847 {
74848 unsigned a, b;
74849 int c, old_c, totaldigits;
74850 - const char __user __force *ubuf = (const char __user __force *)buf;
74851 + const char __user *ubuf = (const char __force_user *)buf;
74852 int exp_digit, in_range;
74853
74854 totaldigits = c = 0;
74855 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
74856 {
74857 if (!access_ok(VERIFY_READ, ubuf, ulen))
74858 return -EFAULT;
74859 - return __bitmap_parselist((const char __force *)ubuf,
74860 + return __bitmap_parselist((const char __force_kernel *)ubuf,
74861 ulen, 1, maskp, nmaskbits);
74862 }
74863 EXPORT_SYMBOL(bitmap_parselist_user);
74864 diff --git a/lib/bug.c b/lib/bug.c
74865 index d0cdf14..4d07bd2 100644
74866 --- a/lib/bug.c
74867 +++ b/lib/bug.c
74868 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
74869 return BUG_TRAP_TYPE_NONE;
74870
74871 bug = find_bug(bugaddr);
74872 + if (!bug)
74873 + return BUG_TRAP_TYPE_NONE;
74874
74875 file = NULL;
74876 line = 0;
74877 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
74878 index d11808c..dc2d6f8 100644
74879 --- a/lib/debugobjects.c
74880 +++ b/lib/debugobjects.c
74881 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
74882 if (limit > 4)
74883 return;
74884
74885 - is_on_stack = object_is_on_stack(addr);
74886 + is_on_stack = object_starts_on_stack(addr);
74887 if (is_on_stack == onstack)
74888 return;
74889
74890 diff --git a/lib/devres.c b/lib/devres.c
74891 index 80b9c76..9e32279 100644
74892 --- a/lib/devres.c
74893 +++ b/lib/devres.c
74894 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
74895 void devm_iounmap(struct device *dev, void __iomem *addr)
74896 {
74897 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
74898 - (void *)addr));
74899 + (void __force *)addr));
74900 iounmap(addr);
74901 }
74902 EXPORT_SYMBOL(devm_iounmap);
74903 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
74904 {
74905 ioport_unmap(addr);
74906 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
74907 - devm_ioport_map_match, (void *)addr));
74908 + devm_ioport_map_match, (void __force *)addr));
74909 }
74910 EXPORT_SYMBOL(devm_ioport_unmap);
74911
74912 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
74913 index 5e396ac..58d5de1 100644
74914 --- a/lib/dma-debug.c
74915 +++ b/lib/dma-debug.c
74916 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
74917
74918 void dma_debug_add_bus(struct bus_type *bus)
74919 {
74920 - struct notifier_block *nb;
74921 + notifier_block_no_const *nb;
74922
74923 if (global_disable)
74924 return;
74925 @@ -942,7 +942,7 @@ out:
74926
74927 static void check_for_stack(struct device *dev, void *addr)
74928 {
74929 - if (object_is_on_stack(addr))
74930 + if (object_starts_on_stack(addr))
74931 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
74932 "stack [addr=%p]\n", addr);
74933 }
74934 diff --git a/lib/inflate.c b/lib/inflate.c
74935 index 013a761..c28f3fc 100644
74936 --- a/lib/inflate.c
74937 +++ b/lib/inflate.c
74938 @@ -269,7 +269,7 @@ static void free(void *where)
74939 malloc_ptr = free_mem_ptr;
74940 }
74941 #else
74942 -#define malloc(a) kmalloc(a, GFP_KERNEL)
74943 +#define malloc(a) kmalloc((a), GFP_KERNEL)
74944 #define free(a) kfree(a)
74945 #endif
74946
74947 diff --git a/lib/ioremap.c b/lib/ioremap.c
74948 index 0c9216c..863bd89 100644
74949 --- a/lib/ioremap.c
74950 +++ b/lib/ioremap.c
74951 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
74952 unsigned long next;
74953
74954 phys_addr -= addr;
74955 - pmd = pmd_alloc(&init_mm, pud, addr);
74956 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
74957 if (!pmd)
74958 return -ENOMEM;
74959 do {
74960 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
74961 unsigned long next;
74962
74963 phys_addr -= addr;
74964 - pud = pud_alloc(&init_mm, pgd, addr);
74965 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
74966 if (!pud)
74967 return -ENOMEM;
74968 do {
74969 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
74970 index bd2bea9..6b3c95e 100644
74971 --- a/lib/is_single_threaded.c
74972 +++ b/lib/is_single_threaded.c
74973 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
74974 struct task_struct *p, *t;
74975 bool ret;
74976
74977 + if (!mm)
74978 + return true;
74979 +
74980 if (atomic_read(&task->signal->live) != 1)
74981 return false;
74982
74983 diff --git a/lib/list_debug.c b/lib/list_debug.c
74984 index c24c2f7..3fc5da0 100644
74985 --- a/lib/list_debug.c
74986 +++ b/lib/list_debug.c
74987 @@ -11,7 +11,9 @@
74988 #include <linux/bug.h>
74989 #include <linux/kernel.h>
74990 #include <linux/rculist.h>
74991 +#include <linux/mm.h>
74992
74993 +#ifdef CONFIG_DEBUG_LIST
74994 /*
74995 * Insert a new entry between two known consecutive entries.
74996 *
74997 @@ -19,21 +21,32 @@
74998 * the prev/next entries already!
74999 */
75000
75001 -void __list_add(struct list_head *new,
75002 - struct list_head *prev,
75003 - struct list_head *next)
75004 +static bool __list_add_debug(struct list_head *new,
75005 + struct list_head *prev,
75006 + struct list_head *next)
75007 {
75008 - WARN(next->prev != prev,
75009 + if (WARN(next->prev != prev,
75010 "list_add corruption. next->prev should be "
75011 "prev (%p), but was %p. (next=%p).\n",
75012 - prev, next->prev, next);
75013 - WARN(prev->next != next,
75014 + prev, next->prev, next) ||
75015 + WARN(prev->next != next,
75016 "list_add corruption. prev->next should be "
75017 "next (%p), but was %p. (prev=%p).\n",
75018 - next, prev->next, prev);
75019 - WARN(new == prev || new == next,
75020 + next, prev->next, prev) ||
75021 + WARN(new == prev || new == next,
75022 "list_add double add: new=%p, prev=%p, next=%p.\n",
75023 - new, prev, next);
75024 + new, prev, next))
75025 + return false;
75026 + return true;
75027 +}
75028 +
75029 +void __list_add(struct list_head *new,
75030 + struct list_head *prev,
75031 + struct list_head *next)
75032 +{
75033 + if (!__list_add_debug(new, prev, next))
75034 + return;
75035 +
75036 next->prev = new;
75037 new->next = next;
75038 new->prev = prev;
75039 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
75040 }
75041 EXPORT_SYMBOL(__list_add);
75042
75043 -void __list_del_entry(struct list_head *entry)
75044 +static bool __list_del_entry_debug(struct list_head *entry)
75045 {
75046 struct list_head *prev, *next;
75047
75048 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
75049 WARN(next->prev != entry,
75050 "list_del corruption. next->prev should be %p, "
75051 "but was %p\n", entry, next->prev))
75052 + return false;
75053 + return true;
75054 +}
75055 +
75056 +void __list_del_entry(struct list_head *entry)
75057 +{
75058 + if (!__list_del_entry_debug(entry))
75059 return;
75060
75061 - __list_del(prev, next);
75062 + __list_del(entry->prev, entry->next);
75063 }
75064 EXPORT_SYMBOL(__list_del_entry);
75065
75066 @@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
75067 void __list_add_rcu(struct list_head *new,
75068 struct list_head *prev, struct list_head *next)
75069 {
75070 - WARN(next->prev != prev,
75071 + if (WARN(next->prev != prev,
75072 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
75073 - prev, next->prev, next);
75074 - WARN(prev->next != next,
75075 + prev, next->prev, next) ||
75076 + WARN(prev->next != next,
75077 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
75078 - next, prev->next, prev);
75079 + next, prev->next, prev))
75080 + return;
75081 +
75082 new->next = next;
75083 new->prev = prev;
75084 rcu_assign_pointer(list_next_rcu(prev), new);
75085 next->prev = new;
75086 }
75087 EXPORT_SYMBOL(__list_add_rcu);
75088 +#endif
75089 +
75090 +void pax_list_add_tail(struct list_head *new, struct list_head *head)
75091 +{
75092 + struct list_head *prev, *next;
75093 +
75094 + prev = head->prev;
75095 + next = head;
75096 +
75097 +#ifdef CONFIG_DEBUG_LIST
75098 + if (!__list_add_debug(new, prev, next))
75099 + return;
75100 +#endif
75101 +
75102 + pax_open_kernel();
75103 + next->prev = new;
75104 + new->next = next;
75105 + new->prev = prev;
75106 + prev->next = new;
75107 + pax_close_kernel();
75108 +}
75109 +EXPORT_SYMBOL(pax_list_add_tail);
75110 +
75111 +void pax_list_del(struct list_head *entry)
75112 +{
75113 +#ifdef CONFIG_DEBUG_LIST
75114 + if (!__list_del_entry_debug(entry))
75115 + return;
75116 +#endif
75117 +
75118 + pax_open_kernel();
75119 + __list_del(entry->prev, entry->next);
75120 + entry->next = LIST_POISON1;
75121 + entry->prev = LIST_POISON2;
75122 + pax_close_kernel();
75123 +}
75124 +EXPORT_SYMBOL(pax_list_del);
75125 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
75126 index e796429..6e38f9f 100644
75127 --- a/lib/radix-tree.c
75128 +++ b/lib/radix-tree.c
75129 @@ -92,7 +92,7 @@ struct radix_tree_preload {
75130 int nr;
75131 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
75132 };
75133 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
75134 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
75135
75136 static inline void *ptr_to_indirect(void *ptr)
75137 {
75138 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
75139 index bb2b201..46abaf9 100644
75140 --- a/lib/strncpy_from_user.c
75141 +++ b/lib/strncpy_from_user.c
75142 @@ -21,7 +21,7 @@
75143 */
75144 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
75145 {
75146 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75147 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75148 long res = 0;
75149
75150 /*
75151 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
75152 index a28df52..3d55877 100644
75153 --- a/lib/strnlen_user.c
75154 +++ b/lib/strnlen_user.c
75155 @@ -26,7 +26,7 @@
75156 */
75157 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
75158 {
75159 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75160 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
75161 long align, res = 0;
75162 unsigned long c;
75163
75164 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
75165 index fab33a9..3b5fe68 100644
75166 --- a/lib/vsprintf.c
75167 +++ b/lib/vsprintf.c
75168 @@ -16,6 +16,9 @@
75169 * - scnprintf and vscnprintf
75170 */
75171
75172 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75173 +#define __INCLUDED_BY_HIDESYM 1
75174 +#endif
75175 #include <stdarg.h>
75176 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
75177 #include <linux/types.h>
75178 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
75179 char sym[KSYM_SYMBOL_LEN];
75180 if (ext == 'B')
75181 sprint_backtrace(sym, value);
75182 - else if (ext != 'f' && ext != 's')
75183 + else if (ext != 'f' && ext != 's' && ext != 'a')
75184 sprint_symbol(sym, value);
75185 else
75186 sprint_symbol_no_offset(sym, value);
75187 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
75188 return number(buf, end, *(const netdev_features_t *)addr, spec);
75189 }
75190
75191 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75192 +int kptr_restrict __read_mostly = 2;
75193 +#else
75194 int kptr_restrict __read_mostly;
75195 +#endif
75196
75197 /*
75198 * Show a '%p' thing. A kernel extension is that the '%p' is followed
75199 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
75200 * - 'S' For symbolic direct pointers with offset
75201 * - 's' For symbolic direct pointers without offset
75202 * - 'B' For backtraced symbolic direct pointers with offset
75203 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
75204 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
75205 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
75206 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
75207 * - 'M' For a 6-byte MAC address, it prints the address in the
75208 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75209
75210 if (!ptr && *fmt != 'K') {
75211 /*
75212 - * Print (null) with the same width as a pointer so it makes
75213 + * Print (nil) with the same width as a pointer so it makes
75214 * tabular output look nice.
75215 */
75216 if (spec.field_width == -1)
75217 spec.field_width = default_width;
75218 - return string(buf, end, "(null)", spec);
75219 + return string(buf, end, "(nil)", spec);
75220 }
75221
75222 switch (*fmt) {
75223 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75224 /* Fallthrough */
75225 case 'S':
75226 case 's':
75227 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75228 + break;
75229 +#else
75230 + return symbol_string(buf, end, ptr, spec, *fmt);
75231 +#endif
75232 + case 'A':
75233 + case 'a':
75234 case 'B':
75235 return symbol_string(buf, end, ptr, spec, *fmt);
75236 case 'R':
75237 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75238 va_end(va);
75239 return buf;
75240 }
75241 + case 'P':
75242 + break;
75243 case 'K':
75244 /*
75245 * %pK cannot be used in IRQ context because its test
75246 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
75247 }
75248 break;
75249 }
75250 +
75251 +#ifdef CONFIG_GRKERNSEC_HIDESYM
75252 + /* 'P' = approved pointers to copy to userland,
75253 + as in the /proc/kallsyms case, as we make it display nothing
75254 + for non-root users, and the real contents for root users
75255 + Also ignore 'K' pointers, since we force their NULLing for non-root users
75256 + above
75257 + */
75258 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
75259 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
75260 + dump_stack();
75261 + ptr = NULL;
75262 + }
75263 +#endif
75264 +
75265 spec.flags |= SMALL;
75266 if (spec.field_width == -1) {
75267 spec.field_width = default_width;
75268 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75269 typeof(type) value; \
75270 if (sizeof(type) == 8) { \
75271 args = PTR_ALIGN(args, sizeof(u32)); \
75272 - *(u32 *)&value = *(u32 *)args; \
75273 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
75274 + *(u32 *)&value = *(const u32 *)args; \
75275 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
75276 } else { \
75277 args = PTR_ALIGN(args, sizeof(type)); \
75278 - value = *(typeof(type) *)args; \
75279 + value = *(const typeof(type) *)args; \
75280 } \
75281 args += sizeof(type); \
75282 value; \
75283 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
75284 case FORMAT_TYPE_STR: {
75285 const char *str_arg = args;
75286 args += strlen(str_arg) + 1;
75287 - str = string(str, end, (char *)str_arg, spec);
75288 + str = string(str, end, str_arg, spec);
75289 break;
75290 }
75291
75292 diff --git a/localversion-grsec b/localversion-grsec
75293 new file mode 100644
75294 index 0000000..7cd6065
75295 --- /dev/null
75296 +++ b/localversion-grsec
75297 @@ -0,0 +1 @@
75298 +-grsec
75299 diff --git a/mm/Kconfig b/mm/Kconfig
75300 index 278e3ab..87c384d 100644
75301 --- a/mm/Kconfig
75302 +++ b/mm/Kconfig
75303 @@ -286,10 +286,10 @@ config KSM
75304 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
75305
75306 config DEFAULT_MMAP_MIN_ADDR
75307 - int "Low address space to protect from user allocation"
75308 + int "Low address space to protect from user allocation"
75309 depends on MMU
75310 - default 4096
75311 - help
75312 + default 65536
75313 + help
75314 This is the portion of low virtual memory which should be protected
75315 from userspace allocation. Keeping a user from writing to low pages
75316 can help reduce the impact of kernel NULL pointer bugs.
75317 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
75318
75319 config HWPOISON_INJECT
75320 tristate "HWPoison pages injector"
75321 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
75322 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
75323 select PROC_PAGE_MONITOR
75324
75325 config NOMMU_INITIAL_TRIM_EXCESS
75326 diff --git a/mm/filemap.c b/mm/filemap.c
75327 index 83efee7..3f99381 100644
75328 --- a/mm/filemap.c
75329 +++ b/mm/filemap.c
75330 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
75331 struct address_space *mapping = file->f_mapping;
75332
75333 if (!mapping->a_ops->readpage)
75334 - return -ENOEXEC;
75335 + return -ENODEV;
75336 file_accessed(file);
75337 vma->vm_ops = &generic_file_vm_ops;
75338 return 0;
75339 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
75340 *pos = i_size_read(inode);
75341
75342 if (limit != RLIM_INFINITY) {
75343 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
75344 if (*pos >= limit) {
75345 send_sig(SIGXFSZ, current, 0);
75346 return -EFBIG;
75347 diff --git a/mm/fremap.c b/mm/fremap.c
75348 index a0aaf0e..20325c3 100644
75349 --- a/mm/fremap.c
75350 +++ b/mm/fremap.c
75351 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
75352 retry:
75353 vma = find_vma(mm, start);
75354
75355 +#ifdef CONFIG_PAX_SEGMEXEC
75356 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
75357 + goto out;
75358 +#endif
75359 +
75360 /*
75361 * Make sure the vma is shared, that it supports prefaulting,
75362 * and that the remapped range is valid and fully within
75363 diff --git a/mm/highmem.c b/mm/highmem.c
75364 index b32b70c..e512eb0 100644
75365 --- a/mm/highmem.c
75366 +++ b/mm/highmem.c
75367 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
75368 * So no dangers, even with speculative execution.
75369 */
75370 page = pte_page(pkmap_page_table[i]);
75371 + pax_open_kernel();
75372 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
75373 -
75374 + pax_close_kernel();
75375 set_page_address(page, NULL);
75376 need_flush = 1;
75377 }
75378 @@ -198,9 +199,11 @@ start:
75379 }
75380 }
75381 vaddr = PKMAP_ADDR(last_pkmap_nr);
75382 +
75383 + pax_open_kernel();
75384 set_pte_at(&init_mm, vaddr,
75385 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
75386 -
75387 + pax_close_kernel();
75388 pkmap_count[last_pkmap_nr] = 1;
75389 set_page_address(page, (void *)vaddr);
75390
75391 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
75392 index 546db81..01d5c53 100644
75393 --- a/mm/hugetlb.c
75394 +++ b/mm/hugetlb.c
75395 @@ -2511,6 +2511,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
75396 return 1;
75397 }
75398
75399 +#ifdef CONFIG_PAX_SEGMEXEC
75400 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
75401 +{
75402 + struct mm_struct *mm = vma->vm_mm;
75403 + struct vm_area_struct *vma_m;
75404 + unsigned long address_m;
75405 + pte_t *ptep_m;
75406 +
75407 + vma_m = pax_find_mirror_vma(vma);
75408 + if (!vma_m)
75409 + return;
75410 +
75411 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75412 + address_m = address + SEGMEXEC_TASK_SIZE;
75413 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
75414 + get_page(page_m);
75415 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
75416 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
75417 +}
75418 +#endif
75419 +
75420 /*
75421 * Hugetlb_cow() should be called with page lock of the original hugepage held.
75422 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
75423 @@ -2629,6 +2650,11 @@ retry_avoidcopy:
75424 make_huge_pte(vma, new_page, 1));
75425 page_remove_rmap(old_page);
75426 hugepage_add_new_anon_rmap(new_page, vma, address);
75427 +
75428 +#ifdef CONFIG_PAX_SEGMEXEC
75429 + pax_mirror_huge_pte(vma, address, new_page);
75430 +#endif
75431 +
75432 /* Make the old page be freed below */
75433 new_page = old_page;
75434 }
75435 @@ -2788,6 +2814,10 @@ retry:
75436 && (vma->vm_flags & VM_SHARED)));
75437 set_huge_pte_at(mm, address, ptep, new_pte);
75438
75439 +#ifdef CONFIG_PAX_SEGMEXEC
75440 + pax_mirror_huge_pte(vma, address, page);
75441 +#endif
75442 +
75443 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
75444 /* Optimization, do the COW without a second fault */
75445 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
75446 @@ -2817,6 +2847,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75447 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
75448 struct hstate *h = hstate_vma(vma);
75449
75450 +#ifdef CONFIG_PAX_SEGMEXEC
75451 + struct vm_area_struct *vma_m;
75452 +#endif
75453 +
75454 address &= huge_page_mask(h);
75455
75456 ptep = huge_pte_offset(mm, address);
75457 @@ -2830,6 +2864,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
75458 VM_FAULT_SET_HINDEX(hstate_index(h));
75459 }
75460
75461 +#ifdef CONFIG_PAX_SEGMEXEC
75462 + vma_m = pax_find_mirror_vma(vma);
75463 + if (vma_m) {
75464 + unsigned long address_m;
75465 +
75466 + if (vma->vm_start > vma_m->vm_start) {
75467 + address_m = address;
75468 + address -= SEGMEXEC_TASK_SIZE;
75469 + vma = vma_m;
75470 + h = hstate_vma(vma);
75471 + } else
75472 + address_m = address + SEGMEXEC_TASK_SIZE;
75473 +
75474 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
75475 + return VM_FAULT_OOM;
75476 + address_m &= HPAGE_MASK;
75477 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
75478 + }
75479 +#endif
75480 +
75481 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
75482 if (!ptep)
75483 return VM_FAULT_OOM;
75484 diff --git a/mm/internal.h b/mm/internal.h
75485 index 9ba2110..eaf0674 100644
75486 --- a/mm/internal.h
75487 +++ b/mm/internal.h
75488 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
75489 * in mm/page_alloc.c
75490 */
75491 extern void __free_pages_bootmem(struct page *page, unsigned int order);
75492 +extern void free_compound_page(struct page *page);
75493 extern void prep_compound_page(struct page *page, unsigned long order);
75494 #ifdef CONFIG_MEMORY_FAILURE
75495 extern bool is_free_buddy_page(struct page *page);
75496 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
75497 index 752a705..6c3102e 100644
75498 --- a/mm/kmemleak.c
75499 +++ b/mm/kmemleak.c
75500 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
75501
75502 for (i = 0; i < object->trace_len; i++) {
75503 void *ptr = (void *)object->trace[i];
75504 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
75505 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
75506 }
75507 }
75508
75509 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
75510 return -ENOMEM;
75511 }
75512
75513 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
75514 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
75515 &kmemleak_fops);
75516 if (!dentry)
75517 pr_warning("Failed to create the debugfs kmemleak file\n");
75518 diff --git a/mm/maccess.c b/mm/maccess.c
75519 index d53adf9..03a24bf 100644
75520 --- a/mm/maccess.c
75521 +++ b/mm/maccess.c
75522 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
75523 set_fs(KERNEL_DS);
75524 pagefault_disable();
75525 ret = __copy_from_user_inatomic(dst,
75526 - (__force const void __user *)src, size);
75527 + (const void __force_user *)src, size);
75528 pagefault_enable();
75529 set_fs(old_fs);
75530
75531 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
75532
75533 set_fs(KERNEL_DS);
75534 pagefault_disable();
75535 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
75536 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
75537 pagefault_enable();
75538 set_fs(old_fs);
75539
75540 diff --git a/mm/madvise.c b/mm/madvise.c
75541 index 03dfa5c..b032917 100644
75542 --- a/mm/madvise.c
75543 +++ b/mm/madvise.c
75544 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
75545 pgoff_t pgoff;
75546 unsigned long new_flags = vma->vm_flags;
75547
75548 +#ifdef CONFIG_PAX_SEGMEXEC
75549 + struct vm_area_struct *vma_m;
75550 +#endif
75551 +
75552 switch (behavior) {
75553 case MADV_NORMAL:
75554 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
75555 @@ -123,6 +127,13 @@ success:
75556 /*
75557 * vm_flags is protected by the mmap_sem held in write mode.
75558 */
75559 +
75560 +#ifdef CONFIG_PAX_SEGMEXEC
75561 + vma_m = pax_find_mirror_vma(vma);
75562 + if (vma_m)
75563 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
75564 +#endif
75565 +
75566 vma->vm_flags = new_flags;
75567
75568 out:
75569 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75570 struct vm_area_struct ** prev,
75571 unsigned long start, unsigned long end)
75572 {
75573 +
75574 +#ifdef CONFIG_PAX_SEGMEXEC
75575 + struct vm_area_struct *vma_m;
75576 +#endif
75577 +
75578 *prev = vma;
75579 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
75580 return -EINVAL;
75581 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
75582 zap_page_range(vma, start, end - start, &details);
75583 } else
75584 zap_page_range(vma, start, end - start, NULL);
75585 +
75586 +#ifdef CONFIG_PAX_SEGMEXEC
75587 + vma_m = pax_find_mirror_vma(vma);
75588 + if (vma_m) {
75589 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
75590 + struct zap_details details = {
75591 + .nonlinear_vma = vma_m,
75592 + .last_index = ULONG_MAX,
75593 + };
75594 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
75595 + } else
75596 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
75597 + }
75598 +#endif
75599 +
75600 return 0;
75601 }
75602
75603 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
75604 if (end < start)
75605 goto out;
75606
75607 +#ifdef CONFIG_PAX_SEGMEXEC
75608 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
75609 + if (end > SEGMEXEC_TASK_SIZE)
75610 + goto out;
75611 + } else
75612 +#endif
75613 +
75614 + if (end > TASK_SIZE)
75615 + goto out;
75616 +
75617 error = 0;
75618 if (end == start)
75619 goto out;
75620 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
75621 index c6e4dd3..fdb2ca6 100644
75622 --- a/mm/memory-failure.c
75623 +++ b/mm/memory-failure.c
75624 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
75625
75626 int sysctl_memory_failure_recovery __read_mostly = 1;
75627
75628 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75629 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
75630
75631 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
75632
75633 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
75634 pfn, t->comm, t->pid);
75635 si.si_signo = SIGBUS;
75636 si.si_errno = 0;
75637 - si.si_addr = (void *)addr;
75638 + si.si_addr = (void __user *)addr;
75639 #ifdef __ARCH_SI_TRAPNO
75640 si.si_trapno = trapno;
75641 #endif
75642 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75643 }
75644
75645 nr_pages = 1 << compound_trans_order(hpage);
75646 - atomic_long_add(nr_pages, &mce_bad_pages);
75647 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
75648
75649 /*
75650 * We need/can do nothing about count=0 pages.
75651 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75652 if (!PageHWPoison(hpage)
75653 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
75654 || (p != hpage && TestSetPageHWPoison(hpage))) {
75655 - atomic_long_sub(nr_pages, &mce_bad_pages);
75656 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75657 return 0;
75658 }
75659 set_page_hwpoison_huge_page(hpage);
75660 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
75661 }
75662 if (hwpoison_filter(p)) {
75663 if (TestClearPageHWPoison(p))
75664 - atomic_long_sub(nr_pages, &mce_bad_pages);
75665 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75666 unlock_page(hpage);
75667 put_page(hpage);
75668 return 0;
75669 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
75670 return 0;
75671 }
75672 if (TestClearPageHWPoison(p))
75673 - atomic_long_sub(nr_pages, &mce_bad_pages);
75674 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75675 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
75676 return 0;
75677 }
75678 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
75679 */
75680 if (TestClearPageHWPoison(page)) {
75681 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
75682 - atomic_long_sub(nr_pages, &mce_bad_pages);
75683 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
75684 freeit = 1;
75685 if (PageHuge(page))
75686 clear_page_hwpoison_huge_page(page);
75687 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
75688 }
75689 done:
75690 if (!PageHWPoison(hpage))
75691 - atomic_long_add(1 << compound_trans_order(hpage),
75692 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
75693 &mce_bad_pages);
75694 set_page_hwpoison_huge_page(hpage);
75695 dequeue_hwpoisoned_huge_page(hpage);
75696 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
75697 return ret;
75698
75699 done:
75700 - atomic_long_add(1, &mce_bad_pages);
75701 + atomic_long_add_unchecked(1, &mce_bad_pages);
75702 SetPageHWPoison(page);
75703 /* keep elevated page count for bad page */
75704 return ret;
75705 diff --git a/mm/memory.c b/mm/memory.c
75706 index bb1369f..efb96b5 100644
75707 --- a/mm/memory.c
75708 +++ b/mm/memory.c
75709 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75710 free_pte_range(tlb, pmd, addr);
75711 } while (pmd++, addr = next, addr != end);
75712
75713 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
75714 start &= PUD_MASK;
75715 if (start < floor)
75716 return;
75717 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
75718 pmd = pmd_offset(pud, start);
75719 pud_clear(pud);
75720 pmd_free_tlb(tlb, pmd, start);
75721 +#endif
75722 +
75723 }
75724
75725 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75726 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75727 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
75728 } while (pud++, addr = next, addr != end);
75729
75730 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
75731 start &= PGDIR_MASK;
75732 if (start < floor)
75733 return;
75734 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
75735 pud = pud_offset(pgd, start);
75736 pgd_clear(pgd);
75737 pud_free_tlb(tlb, pud, start);
75738 +#endif
75739 +
75740 }
75741
75742 /*
75743 @@ -1618,12 +1624,6 @@ no_page_table:
75744 return page;
75745 }
75746
75747 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
75748 -{
75749 - return stack_guard_page_start(vma, addr) ||
75750 - stack_guard_page_end(vma, addr+PAGE_SIZE);
75751 -}
75752 -
75753 /**
75754 * __get_user_pages() - pin user pages in memory
75755 * @tsk: task_struct of target task
75756 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75757
75758 i = 0;
75759
75760 - do {
75761 + while (nr_pages) {
75762 struct vm_area_struct *vma;
75763
75764 - vma = find_extend_vma(mm, start);
75765 + vma = find_vma(mm, start);
75766 if (!vma && in_gate_area(mm, start)) {
75767 unsigned long pg = start & PAGE_MASK;
75768 pgd_t *pgd;
75769 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75770 goto next_page;
75771 }
75772
75773 - if (!vma ||
75774 + if (!vma || start < vma->vm_start ||
75775 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
75776 !(vm_flags & vma->vm_flags))
75777 return i ? : -EFAULT;
75778 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75779 int ret;
75780 unsigned int fault_flags = 0;
75781
75782 - /* For mlock, just skip the stack guard page. */
75783 - if (foll_flags & FOLL_MLOCK) {
75784 - if (stack_guard_page(vma, start))
75785 - goto next_page;
75786 - }
75787 if (foll_flags & FOLL_WRITE)
75788 fault_flags |= FAULT_FLAG_WRITE;
75789 if (nonblocking)
75790 @@ -1865,7 +1860,7 @@ next_page:
75791 start += PAGE_SIZE;
75792 nr_pages--;
75793 } while (nr_pages && start < vma->vm_end);
75794 - } while (nr_pages);
75795 + }
75796 return i;
75797 }
75798 EXPORT_SYMBOL(__get_user_pages);
75799 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
75800 page_add_file_rmap(page);
75801 set_pte_at(mm, addr, pte, mk_pte(page, prot));
75802
75803 +#ifdef CONFIG_PAX_SEGMEXEC
75804 + pax_mirror_file_pte(vma, addr, page, ptl);
75805 +#endif
75806 +
75807 retval = 0;
75808 pte_unmap_unlock(pte, ptl);
75809 return retval;
75810 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
75811 if (!page_count(page))
75812 return -EINVAL;
75813 if (!(vma->vm_flags & VM_MIXEDMAP)) {
75814 +
75815 +#ifdef CONFIG_PAX_SEGMEXEC
75816 + struct vm_area_struct *vma_m;
75817 +#endif
75818 +
75819 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
75820 BUG_ON(vma->vm_flags & VM_PFNMAP);
75821 vma->vm_flags |= VM_MIXEDMAP;
75822 +
75823 +#ifdef CONFIG_PAX_SEGMEXEC
75824 + vma_m = pax_find_mirror_vma(vma);
75825 + if (vma_m)
75826 + vma_m->vm_flags |= VM_MIXEDMAP;
75827 +#endif
75828 +
75829 }
75830 return insert_page(vma, addr, page, vma->vm_page_prot);
75831 }
75832 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
75833 unsigned long pfn)
75834 {
75835 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
75836 + BUG_ON(vma->vm_mirror);
75837
75838 if (addr < vma->vm_start || addr >= vma->vm_end)
75839 return -EFAULT;
75840 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
75841
75842 BUG_ON(pud_huge(*pud));
75843
75844 - pmd = pmd_alloc(mm, pud, addr);
75845 + pmd = (mm == &init_mm) ?
75846 + pmd_alloc_kernel(mm, pud, addr) :
75847 + pmd_alloc(mm, pud, addr);
75848 if (!pmd)
75849 return -ENOMEM;
75850 do {
75851 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
75852 unsigned long next;
75853 int err;
75854
75855 - pud = pud_alloc(mm, pgd, addr);
75856 + pud = (mm == &init_mm) ?
75857 + pud_alloc_kernel(mm, pgd, addr) :
75858 + pud_alloc(mm, pgd, addr);
75859 if (!pud)
75860 return -ENOMEM;
75861 do {
75862 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
75863 copy_user_highpage(dst, src, va, vma);
75864 }
75865
75866 +#ifdef CONFIG_PAX_SEGMEXEC
75867 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
75868 +{
75869 + struct mm_struct *mm = vma->vm_mm;
75870 + spinlock_t *ptl;
75871 + pte_t *pte, entry;
75872 +
75873 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
75874 + entry = *pte;
75875 + if (!pte_present(entry)) {
75876 + if (!pte_none(entry)) {
75877 + BUG_ON(pte_file(entry));
75878 + free_swap_and_cache(pte_to_swp_entry(entry));
75879 + pte_clear_not_present_full(mm, address, pte, 0);
75880 + }
75881 + } else {
75882 + struct page *page;
75883 +
75884 + flush_cache_page(vma, address, pte_pfn(entry));
75885 + entry = ptep_clear_flush(vma, address, pte);
75886 + BUG_ON(pte_dirty(entry));
75887 + page = vm_normal_page(vma, address, entry);
75888 + if (page) {
75889 + update_hiwater_rss(mm);
75890 + if (PageAnon(page))
75891 + dec_mm_counter_fast(mm, MM_ANONPAGES);
75892 + else
75893 + dec_mm_counter_fast(mm, MM_FILEPAGES);
75894 + page_remove_rmap(page);
75895 + page_cache_release(page);
75896 + }
75897 + }
75898 + pte_unmap_unlock(pte, ptl);
75899 +}
75900 +
75901 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
75902 + *
75903 + * the ptl of the lower mapped page is held on entry and is not released on exit
75904 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
75905 + */
75906 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75907 +{
75908 + struct mm_struct *mm = vma->vm_mm;
75909 + unsigned long address_m;
75910 + spinlock_t *ptl_m;
75911 + struct vm_area_struct *vma_m;
75912 + pmd_t *pmd_m;
75913 + pte_t *pte_m, entry_m;
75914 +
75915 + BUG_ON(!page_m || !PageAnon(page_m));
75916 +
75917 + vma_m = pax_find_mirror_vma(vma);
75918 + if (!vma_m)
75919 + return;
75920 +
75921 + BUG_ON(!PageLocked(page_m));
75922 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75923 + address_m = address + SEGMEXEC_TASK_SIZE;
75924 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75925 + pte_m = pte_offset_map(pmd_m, address_m);
75926 + ptl_m = pte_lockptr(mm, pmd_m);
75927 + if (ptl != ptl_m) {
75928 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75929 + if (!pte_none(*pte_m))
75930 + goto out;
75931 + }
75932 +
75933 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75934 + page_cache_get(page_m);
75935 + page_add_anon_rmap(page_m, vma_m, address_m);
75936 + inc_mm_counter_fast(mm, MM_ANONPAGES);
75937 + set_pte_at(mm, address_m, pte_m, entry_m);
75938 + update_mmu_cache(vma_m, address_m, entry_m);
75939 +out:
75940 + if (ptl != ptl_m)
75941 + spin_unlock(ptl_m);
75942 + pte_unmap(pte_m);
75943 + unlock_page(page_m);
75944 +}
75945 +
75946 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
75947 +{
75948 + struct mm_struct *mm = vma->vm_mm;
75949 + unsigned long address_m;
75950 + spinlock_t *ptl_m;
75951 + struct vm_area_struct *vma_m;
75952 + pmd_t *pmd_m;
75953 + pte_t *pte_m, entry_m;
75954 +
75955 + BUG_ON(!page_m || PageAnon(page_m));
75956 +
75957 + vma_m = pax_find_mirror_vma(vma);
75958 + if (!vma_m)
75959 + return;
75960 +
75961 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75962 + address_m = address + SEGMEXEC_TASK_SIZE;
75963 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
75964 + pte_m = pte_offset_map(pmd_m, address_m);
75965 + ptl_m = pte_lockptr(mm, pmd_m);
75966 + if (ptl != ptl_m) {
75967 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
75968 + if (!pte_none(*pte_m))
75969 + goto out;
75970 + }
75971 +
75972 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
75973 + page_cache_get(page_m);
75974 + page_add_file_rmap(page_m);
75975 + inc_mm_counter_fast(mm, MM_FILEPAGES);
75976 + set_pte_at(mm, address_m, pte_m, entry_m);
75977 + update_mmu_cache(vma_m, address_m, entry_m);
75978 +out:
75979 + if (ptl != ptl_m)
75980 + spin_unlock(ptl_m);
75981 + pte_unmap(pte_m);
75982 +}
75983 +
75984 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
75985 +{
75986 + struct mm_struct *mm = vma->vm_mm;
75987 + unsigned long address_m;
75988 + spinlock_t *ptl_m;
75989 + struct vm_area_struct *vma_m;
75990 + pmd_t *pmd_m;
75991 + pte_t *pte_m, entry_m;
75992 +
75993 + vma_m = pax_find_mirror_vma(vma);
75994 + if (!vma_m)
75995 + return;
75996 +
75997 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
75998 + address_m = address + SEGMEXEC_TASK_SIZE;
75999 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
76000 + pte_m = pte_offset_map(pmd_m, address_m);
76001 + ptl_m = pte_lockptr(mm, pmd_m);
76002 + if (ptl != ptl_m) {
76003 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
76004 + if (!pte_none(*pte_m))
76005 + goto out;
76006 + }
76007 +
76008 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
76009 + set_pte_at(mm, address_m, pte_m, entry_m);
76010 +out:
76011 + if (ptl != ptl_m)
76012 + spin_unlock(ptl_m);
76013 + pte_unmap(pte_m);
76014 +}
76015 +
76016 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
76017 +{
76018 + struct page *page_m;
76019 + pte_t entry;
76020 +
76021 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
76022 + goto out;
76023 +
76024 + entry = *pte;
76025 + page_m = vm_normal_page(vma, address, entry);
76026 + if (!page_m)
76027 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
76028 + else if (PageAnon(page_m)) {
76029 + if (pax_find_mirror_vma(vma)) {
76030 + pte_unmap_unlock(pte, ptl);
76031 + lock_page(page_m);
76032 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
76033 + if (pte_same(entry, *pte))
76034 + pax_mirror_anon_pte(vma, address, page_m, ptl);
76035 + else
76036 + unlock_page(page_m);
76037 + }
76038 + } else
76039 + pax_mirror_file_pte(vma, address, page_m, ptl);
76040 +
76041 +out:
76042 + pte_unmap_unlock(pte, ptl);
76043 +}
76044 +#endif
76045 +
76046 /*
76047 * This routine handles present pages, when users try to write
76048 * to a shared page. It is done by copying the page to a new address
76049 @@ -2725,6 +2921,12 @@ gotten:
76050 */
76051 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76052 if (likely(pte_same(*page_table, orig_pte))) {
76053 +
76054 +#ifdef CONFIG_PAX_SEGMEXEC
76055 + if (pax_find_mirror_vma(vma))
76056 + BUG_ON(!trylock_page(new_page));
76057 +#endif
76058 +
76059 if (old_page) {
76060 if (!PageAnon(old_page)) {
76061 dec_mm_counter_fast(mm, MM_FILEPAGES);
76062 @@ -2776,6 +2978,10 @@ gotten:
76063 page_remove_rmap(old_page);
76064 }
76065
76066 +#ifdef CONFIG_PAX_SEGMEXEC
76067 + pax_mirror_anon_pte(vma, address, new_page, ptl);
76068 +#endif
76069 +
76070 /* Free the old page.. */
76071 new_page = old_page;
76072 ret |= VM_FAULT_WRITE;
76073 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76074 swap_free(entry);
76075 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
76076 try_to_free_swap(page);
76077 +
76078 +#ifdef CONFIG_PAX_SEGMEXEC
76079 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
76080 +#endif
76081 +
76082 unlock_page(page);
76083 if (swapcache) {
76084 /*
76085 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
76086
76087 /* No need to invalidate - it was non-present before */
76088 update_mmu_cache(vma, address, page_table);
76089 +
76090 +#ifdef CONFIG_PAX_SEGMEXEC
76091 + pax_mirror_anon_pte(vma, address, page, ptl);
76092 +#endif
76093 +
76094 unlock:
76095 pte_unmap_unlock(page_table, ptl);
76096 out:
76097 @@ -3093,40 +3309,6 @@ out_release:
76098 }
76099
76100 /*
76101 - * This is like a special single-page "expand_{down|up}wards()",
76102 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
76103 - * doesn't hit another vma.
76104 - */
76105 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
76106 -{
76107 - address &= PAGE_MASK;
76108 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
76109 - struct vm_area_struct *prev = vma->vm_prev;
76110 -
76111 - /*
76112 - * Is there a mapping abutting this one below?
76113 - *
76114 - * That's only ok if it's the same stack mapping
76115 - * that has gotten split..
76116 - */
76117 - if (prev && prev->vm_end == address)
76118 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
76119 -
76120 - expand_downwards(vma, address - PAGE_SIZE);
76121 - }
76122 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
76123 - struct vm_area_struct *next = vma->vm_next;
76124 -
76125 - /* As VM_GROWSDOWN but s/below/above/ */
76126 - if (next && next->vm_start == address + PAGE_SIZE)
76127 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
76128 -
76129 - expand_upwards(vma, address + PAGE_SIZE);
76130 - }
76131 - return 0;
76132 -}
76133 -
76134 -/*
76135 * We enter with non-exclusive mmap_sem (to exclude vma changes,
76136 * but allow concurrent faults), and pte mapped but not yet locked.
76137 * We return with mmap_sem still held, but pte unmapped and unlocked.
76138 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76139 unsigned long address, pte_t *page_table, pmd_t *pmd,
76140 unsigned int flags)
76141 {
76142 - struct page *page;
76143 + struct page *page = NULL;
76144 spinlock_t *ptl;
76145 pte_t entry;
76146
76147 - pte_unmap(page_table);
76148 -
76149 - /* Check if we need to add a guard page to the stack */
76150 - if (check_stack_guard_page(vma, address) < 0)
76151 - return VM_FAULT_SIGBUS;
76152 -
76153 - /* Use the zero-page for reads */
76154 if (!(flags & FAULT_FLAG_WRITE)) {
76155 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
76156 vma->vm_page_prot));
76157 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
76158 + ptl = pte_lockptr(mm, pmd);
76159 + spin_lock(ptl);
76160 if (!pte_none(*page_table))
76161 goto unlock;
76162 goto setpte;
76163 }
76164
76165 /* Allocate our own private page. */
76166 + pte_unmap(page_table);
76167 +
76168 if (unlikely(anon_vma_prepare(vma)))
76169 goto oom;
76170 page = alloc_zeroed_user_highpage_movable(vma, address);
76171 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
76172 if (!pte_none(*page_table))
76173 goto release;
76174
76175 +#ifdef CONFIG_PAX_SEGMEXEC
76176 + if (pax_find_mirror_vma(vma))
76177 + BUG_ON(!trylock_page(page));
76178 +#endif
76179 +
76180 inc_mm_counter_fast(mm, MM_ANONPAGES);
76181 page_add_new_anon_rmap(page, vma, address);
76182 setpte:
76183 @@ -3181,6 +3364,12 @@ setpte:
76184
76185 /* No need to invalidate - it was non-present before */
76186 update_mmu_cache(vma, address, page_table);
76187 +
76188 +#ifdef CONFIG_PAX_SEGMEXEC
76189 + if (page)
76190 + pax_mirror_anon_pte(vma, address, page, ptl);
76191 +#endif
76192 +
76193 unlock:
76194 pte_unmap_unlock(page_table, ptl);
76195 return 0;
76196 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76197 */
76198 /* Only go through if we didn't race with anybody else... */
76199 if (likely(pte_same(*page_table, orig_pte))) {
76200 +
76201 +#ifdef CONFIG_PAX_SEGMEXEC
76202 + if (anon && pax_find_mirror_vma(vma))
76203 + BUG_ON(!trylock_page(page));
76204 +#endif
76205 +
76206 flush_icache_page(vma, page);
76207 entry = mk_pte(page, vma->vm_page_prot);
76208 if (flags & FAULT_FLAG_WRITE)
76209 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76210
76211 /* no need to invalidate: a not-present page won't be cached */
76212 update_mmu_cache(vma, address, page_table);
76213 +
76214 +#ifdef CONFIG_PAX_SEGMEXEC
76215 + if (anon)
76216 + pax_mirror_anon_pte(vma, address, page, ptl);
76217 + else
76218 + pax_mirror_file_pte(vma, address, page, ptl);
76219 +#endif
76220 +
76221 } else {
76222 if (cow_page)
76223 mem_cgroup_uncharge_page(cow_page);
76224 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
76225 if (flags & FAULT_FLAG_WRITE)
76226 flush_tlb_fix_spurious_fault(vma, address);
76227 }
76228 +
76229 +#ifdef CONFIG_PAX_SEGMEXEC
76230 + pax_mirror_pte(vma, address, pte, pmd, ptl);
76231 + return 0;
76232 +#endif
76233 +
76234 unlock:
76235 pte_unmap_unlock(pte, ptl);
76236 return 0;
76237 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76238 pmd_t *pmd;
76239 pte_t *pte;
76240
76241 +#ifdef CONFIG_PAX_SEGMEXEC
76242 + struct vm_area_struct *vma_m;
76243 +#endif
76244 +
76245 __set_current_state(TASK_RUNNING);
76246
76247 count_vm_event(PGFAULT);
76248 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
76249 if (unlikely(is_vm_hugetlb_page(vma)))
76250 return hugetlb_fault(mm, vma, address, flags);
76251
76252 +#ifdef CONFIG_PAX_SEGMEXEC
76253 + vma_m = pax_find_mirror_vma(vma);
76254 + if (vma_m) {
76255 + unsigned long address_m;
76256 + pgd_t *pgd_m;
76257 + pud_t *pud_m;
76258 + pmd_t *pmd_m;
76259 +
76260 + if (vma->vm_start > vma_m->vm_start) {
76261 + address_m = address;
76262 + address -= SEGMEXEC_TASK_SIZE;
76263 + vma = vma_m;
76264 + } else
76265 + address_m = address + SEGMEXEC_TASK_SIZE;
76266 +
76267 + pgd_m = pgd_offset(mm, address_m);
76268 + pud_m = pud_alloc(mm, pgd_m, address_m);
76269 + if (!pud_m)
76270 + return VM_FAULT_OOM;
76271 + pmd_m = pmd_alloc(mm, pud_m, address_m);
76272 + if (!pmd_m)
76273 + return VM_FAULT_OOM;
76274 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
76275 + return VM_FAULT_OOM;
76276 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
76277 + }
76278 +#endif
76279 +
76280 retry:
76281 pgd = pgd_offset(mm, address);
76282 pud = pud_alloc(mm, pgd, address);
76283 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76284 spin_unlock(&mm->page_table_lock);
76285 return 0;
76286 }
76287 +
76288 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
76289 +{
76290 + pud_t *new = pud_alloc_one(mm, address);
76291 + if (!new)
76292 + return -ENOMEM;
76293 +
76294 + smp_wmb(); /* See comment in __pte_alloc */
76295 +
76296 + spin_lock(&mm->page_table_lock);
76297 + if (pgd_present(*pgd)) /* Another has populated it */
76298 + pud_free(mm, new);
76299 + else
76300 + pgd_populate_kernel(mm, pgd, new);
76301 + spin_unlock(&mm->page_table_lock);
76302 + return 0;
76303 +}
76304 #endif /* __PAGETABLE_PUD_FOLDED */
76305
76306 #ifndef __PAGETABLE_PMD_FOLDED
76307 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
76308 spin_unlock(&mm->page_table_lock);
76309 return 0;
76310 }
76311 +
76312 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
76313 +{
76314 + pmd_t *new = pmd_alloc_one(mm, address);
76315 + if (!new)
76316 + return -ENOMEM;
76317 +
76318 + smp_wmb(); /* See comment in __pte_alloc */
76319 +
76320 + spin_lock(&mm->page_table_lock);
76321 +#ifndef __ARCH_HAS_4LEVEL_HACK
76322 + if (pud_present(*pud)) /* Another has populated it */
76323 + pmd_free(mm, new);
76324 + else
76325 + pud_populate_kernel(mm, pud, new);
76326 +#else
76327 + if (pgd_present(*pud)) /* Another has populated it */
76328 + pmd_free(mm, new);
76329 + else
76330 + pgd_populate_kernel(mm, pud, new);
76331 +#endif /* __ARCH_HAS_4LEVEL_HACK */
76332 + spin_unlock(&mm->page_table_lock);
76333 + return 0;
76334 +}
76335 #endif /* __PAGETABLE_PMD_FOLDED */
76336
76337 int make_pages_present(unsigned long addr, unsigned long end)
76338 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
76339 gate_vma.vm_start = FIXADDR_USER_START;
76340 gate_vma.vm_end = FIXADDR_USER_END;
76341 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
76342 - gate_vma.vm_page_prot = __P101;
76343 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
76344
76345 return 0;
76346 }
76347 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
76348 index e2df1c1..1e31d57 100644
76349 --- a/mm/mempolicy.c
76350 +++ b/mm/mempolicy.c
76351 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76352 unsigned long vmstart;
76353 unsigned long vmend;
76354
76355 +#ifdef CONFIG_PAX_SEGMEXEC
76356 + struct vm_area_struct *vma_m;
76357 +#endif
76358 +
76359 vma = find_vma(mm, start);
76360 if (!vma || vma->vm_start > start)
76361 return -EFAULT;
76362 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
76363 if (err)
76364 goto out;
76365 }
76366 +
76367 err = vma_replace_policy(vma, new_pol);
76368 if (err)
76369 goto out;
76370 +
76371 +#ifdef CONFIG_PAX_SEGMEXEC
76372 + vma_m = pax_find_mirror_vma(vma);
76373 + if (vma_m) {
76374 + err = vma_replace_policy(vma_m, new_pol);
76375 + if (err)
76376 + goto out;
76377 + }
76378 +#endif
76379 +
76380 }
76381
76382 out:
76383 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
76384
76385 if (end < start)
76386 return -EINVAL;
76387 +
76388 +#ifdef CONFIG_PAX_SEGMEXEC
76389 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
76390 + if (end > SEGMEXEC_TASK_SIZE)
76391 + return -EINVAL;
76392 + } else
76393 +#endif
76394 +
76395 + if (end > TASK_SIZE)
76396 + return -EINVAL;
76397 +
76398 if (end == start)
76399 return 0;
76400
76401 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76402 */
76403 tcred = __task_cred(task);
76404 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76405 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76406 - !capable(CAP_SYS_NICE)) {
76407 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76408 rcu_read_unlock();
76409 err = -EPERM;
76410 goto out_put;
76411 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
76412 goto out;
76413 }
76414
76415 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76416 + if (mm != current->mm &&
76417 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
76418 + mmput(mm);
76419 + err = -EPERM;
76420 + goto out;
76421 + }
76422 +#endif
76423 +
76424 err = do_migrate_pages(mm, old, new,
76425 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
76426
76427 diff --git a/mm/migrate.c b/mm/migrate.c
76428 index 2fd8b4a..d70358f 100644
76429 --- a/mm/migrate.c
76430 +++ b/mm/migrate.c
76431 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
76432 */
76433 tcred = __task_cred(task);
76434 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
76435 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
76436 - !capable(CAP_SYS_NICE)) {
76437 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
76438 rcu_read_unlock();
76439 err = -EPERM;
76440 goto out;
76441 diff --git a/mm/mlock.c b/mm/mlock.c
76442 index c9bd528..da8d069 100644
76443 --- a/mm/mlock.c
76444 +++ b/mm/mlock.c
76445 @@ -13,6 +13,7 @@
76446 #include <linux/pagemap.h>
76447 #include <linux/mempolicy.h>
76448 #include <linux/syscalls.h>
76449 +#include <linux/security.h>
76450 #include <linux/sched.h>
76451 #include <linux/export.h>
76452 #include <linux/rmap.h>
76453 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
76454 {
76455 unsigned long nstart, end, tmp;
76456 struct vm_area_struct * vma, * prev;
76457 - int error;
76458 + int error = 0;
76459
76460 VM_BUG_ON(start & ~PAGE_MASK);
76461 VM_BUG_ON(len != PAGE_ALIGN(len));
76462 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
76463 return -EINVAL;
76464 if (end == start)
76465 return 0;
76466 + if (end > TASK_SIZE)
76467 + return -EINVAL;
76468 +
76469 vma = find_vma(current->mm, start);
76470 if (!vma || vma->vm_start > start)
76471 return -ENOMEM;
76472 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
76473 for (nstart = start ; ; ) {
76474 vm_flags_t newflags;
76475
76476 +#ifdef CONFIG_PAX_SEGMEXEC
76477 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76478 + break;
76479 +#endif
76480 +
76481 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
76482
76483 newflags = vma->vm_flags | VM_LOCKED;
76484 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
76485 lock_limit >>= PAGE_SHIFT;
76486
76487 /* check against resource limits */
76488 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
76489 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
76490 error = do_mlock(start, len, 1);
76491 up_write(&current->mm->mmap_sem);
76492 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
76493 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
76494 vm_flags_t newflags;
76495
76496 +#ifdef CONFIG_PAX_SEGMEXEC
76497 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
76498 + break;
76499 +#endif
76500 +
76501 + BUG_ON(vma->vm_end > TASK_SIZE);
76502 newflags = vma->vm_flags | VM_LOCKED;
76503 if (!(flags & MCL_CURRENT))
76504 newflags &= ~VM_LOCKED;
76505 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
76506 lock_limit >>= PAGE_SHIFT;
76507
76508 ret = -ENOMEM;
76509 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
76510 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
76511 capable(CAP_IPC_LOCK))
76512 ret = do_mlockall(flags);
76513 diff --git a/mm/mmap.c b/mm/mmap.c
76514 index d1e4124..32a6988 100644
76515 --- a/mm/mmap.c
76516 +++ b/mm/mmap.c
76517 @@ -32,6 +32,7 @@
76518 #include <linux/khugepaged.h>
76519 #include <linux/uprobes.h>
76520 #include <linux/rbtree_augmented.h>
76521 +#include <linux/random.h>
76522
76523 #include <asm/uaccess.h>
76524 #include <asm/cacheflush.h>
76525 @@ -48,6 +49,16 @@
76526 #define arch_rebalance_pgtables(addr, len) (addr)
76527 #endif
76528
76529 +static inline void verify_mm_writelocked(struct mm_struct *mm)
76530 +{
76531 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
76532 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76533 + up_read(&mm->mmap_sem);
76534 + BUG();
76535 + }
76536 +#endif
76537 +}
76538 +
76539 static void unmap_region(struct mm_struct *mm,
76540 struct vm_area_struct *vma, struct vm_area_struct *prev,
76541 unsigned long start, unsigned long end);
76542 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
76543 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
76544 *
76545 */
76546 -pgprot_t protection_map[16] = {
76547 +pgprot_t protection_map[16] __read_only = {
76548 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
76549 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
76550 };
76551
76552 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
76553 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
76554 {
76555 - return __pgprot(pgprot_val(protection_map[vm_flags &
76556 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
76557 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
76558 pgprot_val(arch_vm_get_page_prot(vm_flags)));
76559 +
76560 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76561 + if (!(__supported_pte_mask & _PAGE_NX) &&
76562 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
76563 + (vm_flags & (VM_READ | VM_WRITE)))
76564 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
76565 +#endif
76566 +
76567 + return prot;
76568 }
76569 EXPORT_SYMBOL(vm_get_page_prot);
76570
76571 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
76572 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
76573 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
76574 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
76575 /*
76576 * Make sure vm_committed_as in one cacheline and not cacheline shared with
76577 * other variables. It can be updated by several CPUs frequently.
76578 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
76579 struct vm_area_struct *next = vma->vm_next;
76580
76581 might_sleep();
76582 + BUG_ON(vma->vm_mirror);
76583 if (vma->vm_ops && vma->vm_ops->close)
76584 vma->vm_ops->close(vma);
76585 if (vma->vm_file)
76586 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
76587 * not page aligned -Ram Gupta
76588 */
76589 rlim = rlimit(RLIMIT_DATA);
76590 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
76591 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
76592 (mm->end_data - mm->start_data) > rlim)
76593 goto out;
76594 @@ -888,6 +911,12 @@ static int
76595 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
76596 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76597 {
76598 +
76599 +#ifdef CONFIG_PAX_SEGMEXEC
76600 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
76601 + return 0;
76602 +#endif
76603 +
76604 if (is_mergeable_vma(vma, file, vm_flags) &&
76605 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76606 if (vma->vm_pgoff == vm_pgoff)
76607 @@ -907,6 +936,12 @@ static int
76608 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76609 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
76610 {
76611 +
76612 +#ifdef CONFIG_PAX_SEGMEXEC
76613 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
76614 + return 0;
76615 +#endif
76616 +
76617 if (is_mergeable_vma(vma, file, vm_flags) &&
76618 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
76619 pgoff_t vm_pglen;
76620 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
76621 struct vm_area_struct *vma_merge(struct mm_struct *mm,
76622 struct vm_area_struct *prev, unsigned long addr,
76623 unsigned long end, unsigned long vm_flags,
76624 - struct anon_vma *anon_vma, struct file *file,
76625 + struct anon_vma *anon_vma, struct file *file,
76626 pgoff_t pgoff, struct mempolicy *policy)
76627 {
76628 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
76629 struct vm_area_struct *area, *next;
76630 int err;
76631
76632 +#ifdef CONFIG_PAX_SEGMEXEC
76633 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
76634 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
76635 +
76636 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
76637 +#endif
76638 +
76639 /*
76640 * We later require that vma->vm_flags == vm_flags,
76641 * so this tests vma->vm_flags & VM_SPECIAL, too.
76642 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76643 if (next && next->vm_end == end) /* cases 6, 7, 8 */
76644 next = next->vm_next;
76645
76646 +#ifdef CONFIG_PAX_SEGMEXEC
76647 + if (prev)
76648 + prev_m = pax_find_mirror_vma(prev);
76649 + if (area)
76650 + area_m = pax_find_mirror_vma(area);
76651 + if (next)
76652 + next_m = pax_find_mirror_vma(next);
76653 +#endif
76654 +
76655 /*
76656 * Can it merge with the predecessor?
76657 */
76658 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76659 /* cases 1, 6 */
76660 err = vma_adjust(prev, prev->vm_start,
76661 next->vm_end, prev->vm_pgoff, NULL);
76662 - } else /* cases 2, 5, 7 */
76663 +
76664 +#ifdef CONFIG_PAX_SEGMEXEC
76665 + if (!err && prev_m)
76666 + err = vma_adjust(prev_m, prev_m->vm_start,
76667 + next_m->vm_end, prev_m->vm_pgoff, NULL);
76668 +#endif
76669 +
76670 + } else { /* cases 2, 5, 7 */
76671 err = vma_adjust(prev, prev->vm_start,
76672 end, prev->vm_pgoff, NULL);
76673 +
76674 +#ifdef CONFIG_PAX_SEGMEXEC
76675 + if (!err && prev_m)
76676 + err = vma_adjust(prev_m, prev_m->vm_start,
76677 + end_m, prev_m->vm_pgoff, NULL);
76678 +#endif
76679 +
76680 + }
76681 if (err)
76682 return NULL;
76683 khugepaged_enter_vma_merge(prev);
76684 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
76685 mpol_equal(policy, vma_policy(next)) &&
76686 can_vma_merge_before(next, vm_flags,
76687 anon_vma, file, pgoff+pglen)) {
76688 - if (prev && addr < prev->vm_end) /* case 4 */
76689 + if (prev && addr < prev->vm_end) { /* case 4 */
76690 err = vma_adjust(prev, prev->vm_start,
76691 addr, prev->vm_pgoff, NULL);
76692 - else /* cases 3, 8 */
76693 +
76694 +#ifdef CONFIG_PAX_SEGMEXEC
76695 + if (!err && prev_m)
76696 + err = vma_adjust(prev_m, prev_m->vm_start,
76697 + addr_m, prev_m->vm_pgoff, NULL);
76698 +#endif
76699 +
76700 + } else { /* cases 3, 8 */
76701 err = vma_adjust(area, addr, next->vm_end,
76702 next->vm_pgoff - pglen, NULL);
76703 +
76704 +#ifdef CONFIG_PAX_SEGMEXEC
76705 + if (!err && area_m)
76706 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
76707 + next_m->vm_pgoff - pglen, NULL);
76708 +#endif
76709 +
76710 + }
76711 if (err)
76712 return NULL;
76713 khugepaged_enter_vma_merge(area);
76714 @@ -1120,16 +1201,13 @@ none:
76715 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
76716 struct file *file, long pages)
76717 {
76718 - const unsigned long stack_flags
76719 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
76720 -
76721 mm->total_vm += pages;
76722
76723 if (file) {
76724 mm->shared_vm += pages;
76725 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
76726 mm->exec_vm += pages;
76727 - } else if (flags & stack_flags)
76728 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
76729 mm->stack_vm += pages;
76730 }
76731 #endif /* CONFIG_PROC_FS */
76732 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76733 * (the exception is when the underlying filesystem is noexec
76734 * mounted, in which case we dont add PROT_EXEC.)
76735 */
76736 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76737 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76738 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
76739 prot |= PROT_EXEC;
76740
76741 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76742 /* Obtain the address to map to. we verify (or select) it and ensure
76743 * that it represents a valid section of the address space.
76744 */
76745 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
76746 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
76747 if (addr & ~PAGE_MASK)
76748 return addr;
76749
76750 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76751 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
76752 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
76753
76754 +#ifdef CONFIG_PAX_MPROTECT
76755 + if (mm->pax_flags & MF_PAX_MPROTECT) {
76756 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
76757 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
76758 + gr_log_rwxmmap(file);
76759 +
76760 +#ifdef CONFIG_PAX_EMUPLT
76761 + vm_flags &= ~VM_EXEC;
76762 +#else
76763 + return -EPERM;
76764 +#endif
76765 +
76766 + }
76767 +
76768 + if (!(vm_flags & VM_EXEC))
76769 + vm_flags &= ~VM_MAYEXEC;
76770 +#else
76771 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76772 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76773 +#endif
76774 + else
76775 + vm_flags &= ~VM_MAYWRITE;
76776 + }
76777 +#endif
76778 +
76779 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76780 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
76781 + vm_flags &= ~VM_PAGEEXEC;
76782 +#endif
76783 +
76784 if (flags & MAP_LOCKED)
76785 if (!can_do_mlock())
76786 return -EPERM;
76787 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76788 locked += mm->locked_vm;
76789 lock_limit = rlimit(RLIMIT_MEMLOCK);
76790 lock_limit >>= PAGE_SHIFT;
76791 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
76792 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
76793 return -EAGAIN;
76794 }
76795 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
76796 }
76797 }
76798
76799 + if (!gr_acl_handle_mmap(file, prot))
76800 + return -EACCES;
76801 +
76802 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
76803 }
76804
76805 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
76806 vm_flags_t vm_flags = vma->vm_flags;
76807
76808 /* If it was private or non-writable, the write bit is already clear */
76809 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
76810 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
76811 return 0;
76812
76813 /* The backer wishes to know when pages are first written to? */
76814 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
76815 unsigned long charged = 0;
76816 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
76817
76818 +#ifdef CONFIG_PAX_SEGMEXEC
76819 + struct vm_area_struct *vma_m = NULL;
76820 +#endif
76821 +
76822 + /*
76823 + * mm->mmap_sem is required to protect against another thread
76824 + * changing the mappings in case we sleep.
76825 + */
76826 + verify_mm_writelocked(mm);
76827 +
76828 /* Clear old maps */
76829 error = -ENOMEM;
76830 -munmap_back:
76831 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76832 if (do_munmap(mm, addr, len))
76833 return -ENOMEM;
76834 - goto munmap_back;
76835 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76836 }
76837
76838 /* Check against address space limit. */
76839 @@ -1460,6 +1581,16 @@ munmap_back:
76840 goto unacct_error;
76841 }
76842
76843 +#ifdef CONFIG_PAX_SEGMEXEC
76844 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
76845 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76846 + if (!vma_m) {
76847 + error = -ENOMEM;
76848 + goto free_vma;
76849 + }
76850 + }
76851 +#endif
76852 +
76853 vma->vm_mm = mm;
76854 vma->vm_start = addr;
76855 vma->vm_end = addr + len;
76856 @@ -1484,6 +1615,13 @@ munmap_back:
76857 if (error)
76858 goto unmap_and_free_vma;
76859
76860 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
76861 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
76862 + vma->vm_flags |= VM_PAGEEXEC;
76863 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76864 + }
76865 +#endif
76866 +
76867 /* Can addr have changed??
76868 *
76869 * Answer: Yes, several device drivers can do it in their
76870 @@ -1522,6 +1660,11 @@ munmap_back:
76871 vma_link(mm, vma, prev, rb_link, rb_parent);
76872 file = vma->vm_file;
76873
76874 +#ifdef CONFIG_PAX_SEGMEXEC
76875 + if (vma_m)
76876 + BUG_ON(pax_mirror_vma(vma_m, vma));
76877 +#endif
76878 +
76879 /* Once vma denies write, undo our temporary denial count */
76880 if (correct_wcount)
76881 atomic_inc(&inode->i_writecount);
76882 @@ -1529,6 +1672,7 @@ out:
76883 perf_event_mmap(vma);
76884
76885 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
76886 + track_exec_limit(mm, addr, addr + len, vm_flags);
76887 if (vm_flags & VM_LOCKED) {
76888 if (!mlock_vma_pages_range(vma, addr, addr + len))
76889 mm->locked_vm += (len >> PAGE_SHIFT);
76890 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
76891 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
76892 charged = 0;
76893 free_vma:
76894 +
76895 +#ifdef CONFIG_PAX_SEGMEXEC
76896 + if (vma_m)
76897 + kmem_cache_free(vm_area_cachep, vma_m);
76898 +#endif
76899 +
76900 kmem_cache_free(vm_area_cachep, vma);
76901 unacct_error:
76902 if (charged)
76903 @@ -1557,6 +1707,62 @@ unacct_error:
76904 return error;
76905 }
76906
76907 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76908 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76909 +{
76910 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
76911 + return (random32() & 0xFF) << PAGE_SHIFT;
76912 +
76913 + return 0;
76914 +}
76915 +#endif
76916 +
76917 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
76918 +{
76919 + if (!vma) {
76920 +#ifdef CONFIG_STACK_GROWSUP
76921 + if (addr > sysctl_heap_stack_gap)
76922 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
76923 + else
76924 + vma = find_vma(current->mm, 0);
76925 + if (vma && (vma->vm_flags & VM_GROWSUP))
76926 + return false;
76927 +#endif
76928 + return true;
76929 + }
76930 +
76931 + if (addr + len > vma->vm_start)
76932 + return false;
76933 +
76934 + if (vma->vm_flags & VM_GROWSDOWN)
76935 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
76936 +#ifdef CONFIG_STACK_GROWSUP
76937 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
76938 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
76939 +#endif
76940 + else if (offset)
76941 + return offset <= vma->vm_start - addr - len;
76942 +
76943 + return true;
76944 +}
76945 +
76946 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
76947 +{
76948 + if (vma->vm_start < len)
76949 + return -ENOMEM;
76950 +
76951 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
76952 + if (offset <= vma->vm_start - len)
76953 + return vma->vm_start - len - offset;
76954 + else
76955 + return -ENOMEM;
76956 + }
76957 +
76958 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
76959 + return vma->vm_start - len - sysctl_heap_stack_gap;
76960 + return -ENOMEM;
76961 +}
76962 +
76963 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
76964 {
76965 /*
76966 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76967 struct mm_struct *mm = current->mm;
76968 struct vm_area_struct *vma;
76969 struct vm_unmapped_area_info info;
76970 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
76971
76972 if (len > TASK_SIZE)
76973 return -ENOMEM;
76974 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
76975 if (flags & MAP_FIXED)
76976 return addr;
76977
76978 +#ifdef CONFIG_PAX_RANDMMAP
76979 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
76980 +#endif
76981 +
76982 if (addr) {
76983 addr = PAGE_ALIGN(addr);
76984 vma = find_vma(mm, addr);
76985 - if (TASK_SIZE - len >= addr &&
76986 - (!vma || addr + len <= vma->vm_start))
76987 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
76988 return addr;
76989 }
76990
76991 info.flags = 0;
76992 info.length = len;
76993 info.low_limit = TASK_UNMAPPED_BASE;
76994 +
76995 +#ifdef CONFIG_PAX_RANDMMAP
76996 + if (mm->pax_flags & MF_PAX_RANDMMAP)
76997 + info.low_limit += mm->delta_mmap;
76998 +#endif
76999 +
77000 info.high_limit = TASK_SIZE;
77001 info.align_mask = 0;
77002 return vm_unmapped_area(&info);
77003 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
77004
77005 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
77006 {
77007 +
77008 +#ifdef CONFIG_PAX_SEGMEXEC
77009 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77010 + return;
77011 +#endif
77012 +
77013 /*
77014 * Is this a new hole at the lowest possible address?
77015 */
77016 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
77017 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
77018 mm->free_area_cache = addr;
77019 }
77020
77021 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77022 struct mm_struct *mm = current->mm;
77023 unsigned long addr = addr0;
77024 struct vm_unmapped_area_info info;
77025 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
77026
77027 /* requested length too big for entire address space */
77028 if (len > TASK_SIZE)
77029 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77030 if (flags & MAP_FIXED)
77031 return addr;
77032
77033 +#ifdef CONFIG_PAX_RANDMMAP
77034 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
77035 +#endif
77036 +
77037 /* requesting a specific address */
77038 if (addr) {
77039 addr = PAGE_ALIGN(addr);
77040 vma = find_vma(mm, addr);
77041 - if (TASK_SIZE - len >= addr &&
77042 - (!vma || addr + len <= vma->vm_start))
77043 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
77044 return addr;
77045 }
77046
77047 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77048 VM_BUG_ON(addr != -ENOMEM);
77049 info.flags = 0;
77050 info.low_limit = TASK_UNMAPPED_BASE;
77051 +
77052 +#ifdef CONFIG_PAX_RANDMMAP
77053 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77054 + info.low_limit += mm->delta_mmap;
77055 +#endif
77056 +
77057 info.high_limit = TASK_SIZE;
77058 addr = vm_unmapped_area(&info);
77059 }
77060 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
77061
77062 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77063 {
77064 +
77065 +#ifdef CONFIG_PAX_SEGMEXEC
77066 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
77067 + return;
77068 +#endif
77069 +
77070 /*
77071 * Is this a new hole at the highest possible address?
77072 */
77073 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
77074 mm->free_area_cache = addr;
77075
77076 /* dont allow allocations above current base */
77077 - if (mm->free_area_cache > mm->mmap_base)
77078 + if (mm->free_area_cache > mm->mmap_base) {
77079 mm->free_area_cache = mm->mmap_base;
77080 + mm->cached_hole_size = ~0UL;
77081 + }
77082 }
77083
77084 unsigned long
77085 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
77086 return vma;
77087 }
77088
77089 +#ifdef CONFIG_PAX_SEGMEXEC
77090 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
77091 +{
77092 + struct vm_area_struct *vma_m;
77093 +
77094 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
77095 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
77096 + BUG_ON(vma->vm_mirror);
77097 + return NULL;
77098 + }
77099 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
77100 + vma_m = vma->vm_mirror;
77101 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
77102 + BUG_ON(vma->vm_file != vma_m->vm_file);
77103 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
77104 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
77105 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
77106 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
77107 + return vma_m;
77108 +}
77109 +#endif
77110 +
77111 /*
77112 * Verify that the stack growth is acceptable and
77113 * update accounting. This is shared with both the
77114 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77115 return -ENOMEM;
77116
77117 /* Stack limit test */
77118 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
77119 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
77120 return -ENOMEM;
77121
77122 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77123 locked = mm->locked_vm + grow;
77124 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
77125 limit >>= PAGE_SHIFT;
77126 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
77127 if (locked > limit && !capable(CAP_IPC_LOCK))
77128 return -ENOMEM;
77129 }
77130 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
77131 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
77132 * vma is the last one with address > vma->vm_end. Have to extend vma.
77133 */
77134 +#ifndef CONFIG_IA64
77135 +static
77136 +#endif
77137 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77138 {
77139 int error;
77140 + bool locknext;
77141
77142 if (!(vma->vm_flags & VM_GROWSUP))
77143 return -EFAULT;
77144
77145 + /* Also guard against wrapping around to address 0. */
77146 + if (address < PAGE_ALIGN(address+1))
77147 + address = PAGE_ALIGN(address+1);
77148 + else
77149 + return -ENOMEM;
77150 +
77151 /*
77152 * We must make sure the anon_vma is allocated
77153 * so that the anon_vma locking is not a noop.
77154 */
77155 if (unlikely(anon_vma_prepare(vma)))
77156 return -ENOMEM;
77157 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
77158 + if (locknext && anon_vma_prepare(vma->vm_next))
77159 + return -ENOMEM;
77160 vma_lock_anon_vma(vma);
77161 + if (locknext)
77162 + vma_lock_anon_vma(vma->vm_next);
77163
77164 /*
77165 * vma->vm_start/vm_end cannot change under us because the caller
77166 * is required to hold the mmap_sem in read mode. We need the
77167 - * anon_vma lock to serialize against concurrent expand_stacks.
77168 - * Also guard against wrapping around to address 0.
77169 + * anon_vma locks to serialize against concurrent expand_stacks
77170 + * and expand_upwards.
77171 */
77172 - if (address < PAGE_ALIGN(address+4))
77173 - address = PAGE_ALIGN(address+4);
77174 - else {
77175 - vma_unlock_anon_vma(vma);
77176 - return -ENOMEM;
77177 - }
77178 error = 0;
77179
77180 /* Somebody else might have raced and expanded it already */
77181 - if (address > vma->vm_end) {
77182 + 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)
77183 + error = -ENOMEM;
77184 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
77185 unsigned long size, grow;
77186
77187 size = address - vma->vm_start;
77188 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
77189 }
77190 }
77191 }
77192 + if (locknext)
77193 + vma_unlock_anon_vma(vma->vm_next);
77194 vma_unlock_anon_vma(vma);
77195 khugepaged_enter_vma_merge(vma);
77196 validate_mm(vma->vm_mm);
77197 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
77198 unsigned long address)
77199 {
77200 int error;
77201 + bool lockprev = false;
77202 + struct vm_area_struct *prev;
77203
77204 /*
77205 * We must make sure the anon_vma is allocated
77206 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
77207 if (error)
77208 return error;
77209
77210 + prev = vma->vm_prev;
77211 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
77212 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
77213 +#endif
77214 + if (lockprev && anon_vma_prepare(prev))
77215 + return -ENOMEM;
77216 + if (lockprev)
77217 + vma_lock_anon_vma(prev);
77218 +
77219 vma_lock_anon_vma(vma);
77220
77221 /*
77222 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
77223 */
77224
77225 /* Somebody else might have raced and expanded it already */
77226 - if (address < vma->vm_start) {
77227 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
77228 + error = -ENOMEM;
77229 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
77230 unsigned long size, grow;
77231
77232 +#ifdef CONFIG_PAX_SEGMEXEC
77233 + struct vm_area_struct *vma_m;
77234 +
77235 + vma_m = pax_find_mirror_vma(vma);
77236 +#endif
77237 +
77238 size = vma->vm_end - address;
77239 grow = (vma->vm_start - address) >> PAGE_SHIFT;
77240
77241 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
77242 vma->vm_pgoff -= grow;
77243 anon_vma_interval_tree_post_update_vma(vma);
77244 vma_gap_update(vma);
77245 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
77246 +
77247 +#ifdef CONFIG_PAX_SEGMEXEC
77248 + if (vma_m) {
77249 + anon_vma_interval_tree_pre_update_vma(vma_m);
77250 + vma_m->vm_start -= grow << PAGE_SHIFT;
77251 + vma_m->vm_pgoff -= grow;
77252 + anon_vma_interval_tree_post_update_vma(vma_m);
77253 + vma_gap_update(vma_m);
77254 + }
77255 +#endif
77256 +
77257 spin_unlock(&vma->vm_mm->page_table_lock);
77258
77259 perf_event_mmap(vma);
77260 @@ -2236,6 +2544,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
77261 do {
77262 long nrpages = vma_pages(vma);
77263
77264 +#ifdef CONFIG_PAX_SEGMEXEC
77265 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
77266 + vma = remove_vma(vma);
77267 + continue;
77268 + }
77269 +#endif
77270 +
77271 if (vma->vm_flags & VM_ACCOUNT)
77272 nr_accounted += nrpages;
77273 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
77274 @@ -2281,6 +2596,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
77275 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
77276 vma->vm_prev = NULL;
77277 do {
77278 +
77279 +#ifdef CONFIG_PAX_SEGMEXEC
77280 + if (vma->vm_mirror) {
77281 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
77282 + vma->vm_mirror->vm_mirror = NULL;
77283 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
77284 + vma->vm_mirror = NULL;
77285 + }
77286 +#endif
77287 +
77288 vma_rb_erase(vma, &mm->mm_rb);
77289 mm->map_count--;
77290 tail_vma = vma;
77291 @@ -2312,14 +2637,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77292 struct vm_area_struct *new;
77293 int err = -ENOMEM;
77294
77295 +#ifdef CONFIG_PAX_SEGMEXEC
77296 + struct vm_area_struct *vma_m, *new_m = NULL;
77297 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
77298 +#endif
77299 +
77300 if (is_vm_hugetlb_page(vma) && (addr &
77301 ~(huge_page_mask(hstate_vma(vma)))))
77302 return -EINVAL;
77303
77304 +#ifdef CONFIG_PAX_SEGMEXEC
77305 + vma_m = pax_find_mirror_vma(vma);
77306 +#endif
77307 +
77308 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77309 if (!new)
77310 goto out_err;
77311
77312 +#ifdef CONFIG_PAX_SEGMEXEC
77313 + if (vma_m) {
77314 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
77315 + if (!new_m) {
77316 + kmem_cache_free(vm_area_cachep, new);
77317 + goto out_err;
77318 + }
77319 + }
77320 +#endif
77321 +
77322 /* most fields are the same, copy all, and then fixup */
77323 *new = *vma;
77324
77325 @@ -2332,6 +2676,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77326 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
77327 }
77328
77329 +#ifdef CONFIG_PAX_SEGMEXEC
77330 + if (vma_m) {
77331 + *new_m = *vma_m;
77332 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
77333 + new_m->vm_mirror = new;
77334 + new->vm_mirror = new_m;
77335 +
77336 + if (new_below)
77337 + new_m->vm_end = addr_m;
77338 + else {
77339 + new_m->vm_start = addr_m;
77340 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
77341 + }
77342 + }
77343 +#endif
77344 +
77345 pol = mpol_dup(vma_policy(vma));
77346 if (IS_ERR(pol)) {
77347 err = PTR_ERR(pol);
77348 @@ -2354,6 +2714,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77349 else
77350 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
77351
77352 +#ifdef CONFIG_PAX_SEGMEXEC
77353 + if (!err && vma_m) {
77354 + if (anon_vma_clone(new_m, vma_m))
77355 + goto out_free_mpol;
77356 +
77357 + mpol_get(pol);
77358 + vma_set_policy(new_m, pol);
77359 +
77360 + if (new_m->vm_file)
77361 + get_file(new_m->vm_file);
77362 +
77363 + if (new_m->vm_ops && new_m->vm_ops->open)
77364 + new_m->vm_ops->open(new_m);
77365 +
77366 + if (new_below)
77367 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
77368 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
77369 + else
77370 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
77371 +
77372 + if (err) {
77373 + if (new_m->vm_ops && new_m->vm_ops->close)
77374 + new_m->vm_ops->close(new_m);
77375 + if (new_m->vm_file)
77376 + fput(new_m->vm_file);
77377 + mpol_put(pol);
77378 + }
77379 + }
77380 +#endif
77381 +
77382 /* Success. */
77383 if (!err)
77384 return 0;
77385 @@ -2363,10 +2753,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77386 new->vm_ops->close(new);
77387 if (new->vm_file)
77388 fput(new->vm_file);
77389 - unlink_anon_vmas(new);
77390 out_free_mpol:
77391 mpol_put(pol);
77392 out_free_vma:
77393 +
77394 +#ifdef CONFIG_PAX_SEGMEXEC
77395 + if (new_m) {
77396 + unlink_anon_vmas(new_m);
77397 + kmem_cache_free(vm_area_cachep, new_m);
77398 + }
77399 +#endif
77400 +
77401 + unlink_anon_vmas(new);
77402 kmem_cache_free(vm_area_cachep, new);
77403 out_err:
77404 return err;
77405 @@ -2379,6 +2777,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
77406 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77407 unsigned long addr, int new_below)
77408 {
77409 +
77410 +#ifdef CONFIG_PAX_SEGMEXEC
77411 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
77412 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
77413 + if (mm->map_count >= sysctl_max_map_count-1)
77414 + return -ENOMEM;
77415 + } else
77416 +#endif
77417 +
77418 if (mm->map_count >= sysctl_max_map_count)
77419 return -ENOMEM;
77420
77421 @@ -2390,11 +2797,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
77422 * work. This now handles partial unmappings.
77423 * Jeremy Fitzhardinge <jeremy@goop.org>
77424 */
77425 +#ifdef CONFIG_PAX_SEGMEXEC
77426 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77427 {
77428 + int ret = __do_munmap(mm, start, len);
77429 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
77430 + return ret;
77431 +
77432 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
77433 +}
77434 +
77435 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77436 +#else
77437 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77438 +#endif
77439 +{
77440 unsigned long end;
77441 struct vm_area_struct *vma, *prev, *last;
77442
77443 + /*
77444 + * mm->mmap_sem is required to protect against another thread
77445 + * changing the mappings in case we sleep.
77446 + */
77447 + verify_mm_writelocked(mm);
77448 +
77449 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
77450 return -EINVAL;
77451
77452 @@ -2469,6 +2895,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
77453 /* Fix up all other VM information */
77454 remove_vma_list(mm, vma);
77455
77456 + track_exec_limit(mm, start, end, 0UL);
77457 +
77458 return 0;
77459 }
77460
77461 @@ -2477,6 +2905,13 @@ int vm_munmap(unsigned long start, size_t len)
77462 int ret;
77463 struct mm_struct *mm = current->mm;
77464
77465 +
77466 +#ifdef CONFIG_PAX_SEGMEXEC
77467 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
77468 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
77469 + return -EINVAL;
77470 +#endif
77471 +
77472 down_write(&mm->mmap_sem);
77473 ret = do_munmap(mm, start, len);
77474 up_write(&mm->mmap_sem);
77475 @@ -2490,16 +2925,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
77476 return vm_munmap(addr, len);
77477 }
77478
77479 -static inline void verify_mm_writelocked(struct mm_struct *mm)
77480 -{
77481 -#ifdef CONFIG_DEBUG_VM
77482 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
77483 - WARN_ON(1);
77484 - up_read(&mm->mmap_sem);
77485 - }
77486 -#endif
77487 -}
77488 -
77489 /*
77490 * this is really a simplified "do_mmap". it only handles
77491 * anonymous maps. eventually we may be able to do some
77492 @@ -2513,6 +2938,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77493 struct rb_node ** rb_link, * rb_parent;
77494 pgoff_t pgoff = addr >> PAGE_SHIFT;
77495 int error;
77496 + unsigned long charged;
77497
77498 len = PAGE_ALIGN(len);
77499 if (!len)
77500 @@ -2520,16 +2946,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77501
77502 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
77503
77504 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
77505 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
77506 + flags &= ~VM_EXEC;
77507 +
77508 +#ifdef CONFIG_PAX_MPROTECT
77509 + if (mm->pax_flags & MF_PAX_MPROTECT)
77510 + flags &= ~VM_MAYEXEC;
77511 +#endif
77512 +
77513 + }
77514 +#endif
77515 +
77516 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
77517 if (error & ~PAGE_MASK)
77518 return error;
77519
77520 + charged = len >> PAGE_SHIFT;
77521 +
77522 /*
77523 * mlock MCL_FUTURE?
77524 */
77525 if (mm->def_flags & VM_LOCKED) {
77526 unsigned long locked, lock_limit;
77527 - locked = len >> PAGE_SHIFT;
77528 + locked = charged;
77529 locked += mm->locked_vm;
77530 lock_limit = rlimit(RLIMIT_MEMLOCK);
77531 lock_limit >>= PAGE_SHIFT;
77532 @@ -2546,21 +2986,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77533 /*
77534 * Clear old maps. this also does some error checking for us
77535 */
77536 - munmap_back:
77537 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
77538 if (do_munmap(mm, addr, len))
77539 return -ENOMEM;
77540 - goto munmap_back;
77541 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
77542 }
77543
77544 /* Check against address space limits *after* clearing old maps... */
77545 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
77546 + if (!may_expand_vm(mm, charged))
77547 return -ENOMEM;
77548
77549 if (mm->map_count > sysctl_max_map_count)
77550 return -ENOMEM;
77551
77552 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
77553 + if (security_vm_enough_memory_mm(mm, charged))
77554 return -ENOMEM;
77555
77556 /* Can we just expand an old private anonymous mapping? */
77557 @@ -2574,7 +3013,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77558 */
77559 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77560 if (!vma) {
77561 - vm_unacct_memory(len >> PAGE_SHIFT);
77562 + vm_unacct_memory(charged);
77563 return -ENOMEM;
77564 }
77565
77566 @@ -2588,11 +3027,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
77567 vma_link(mm, vma, prev, rb_link, rb_parent);
77568 out:
77569 perf_event_mmap(vma);
77570 - mm->total_vm += len >> PAGE_SHIFT;
77571 + mm->total_vm += charged;
77572 if (flags & VM_LOCKED) {
77573 if (!mlock_vma_pages_range(vma, addr, addr + len))
77574 - mm->locked_vm += (len >> PAGE_SHIFT);
77575 + mm->locked_vm += charged;
77576 }
77577 + track_exec_limit(mm, addr, addr + len, flags);
77578 return addr;
77579 }
77580
77581 @@ -2650,6 +3090,7 @@ void exit_mmap(struct mm_struct *mm)
77582 while (vma) {
77583 if (vma->vm_flags & VM_ACCOUNT)
77584 nr_accounted += vma_pages(vma);
77585 + vma->vm_mirror = NULL;
77586 vma = remove_vma(vma);
77587 }
77588 vm_unacct_memory(nr_accounted);
77589 @@ -2666,6 +3107,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77590 struct vm_area_struct *prev;
77591 struct rb_node **rb_link, *rb_parent;
77592
77593 +#ifdef CONFIG_PAX_SEGMEXEC
77594 + struct vm_area_struct *vma_m = NULL;
77595 +#endif
77596 +
77597 + if (security_mmap_addr(vma->vm_start))
77598 + return -EPERM;
77599 +
77600 /*
77601 * The vm_pgoff of a purely anonymous vma should be irrelevant
77602 * until its first write fault, when page's anon_vma and index
77603 @@ -2689,7 +3137,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
77604 security_vm_enough_memory_mm(mm, vma_pages(vma)))
77605 return -ENOMEM;
77606
77607 +#ifdef CONFIG_PAX_SEGMEXEC
77608 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
77609 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77610 + if (!vma_m)
77611 + return -ENOMEM;
77612 + }
77613 +#endif
77614 +
77615 vma_link(mm, vma, prev, rb_link, rb_parent);
77616 +
77617 +#ifdef CONFIG_PAX_SEGMEXEC
77618 + if (vma_m)
77619 + BUG_ON(pax_mirror_vma(vma_m, vma));
77620 +#endif
77621 +
77622 return 0;
77623 }
77624
77625 @@ -2709,6 +3171,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77626 struct mempolicy *pol;
77627 bool faulted_in_anon_vma = true;
77628
77629 + BUG_ON(vma->vm_mirror);
77630 +
77631 /*
77632 * If anonymous vma has not yet been faulted, update new pgoff
77633 * to match new location, to increase its chance of merging.
77634 @@ -2775,6 +3239,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
77635 return NULL;
77636 }
77637
77638 +#ifdef CONFIG_PAX_SEGMEXEC
77639 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
77640 +{
77641 + struct vm_area_struct *prev_m;
77642 + struct rb_node **rb_link_m, *rb_parent_m;
77643 + struct mempolicy *pol_m;
77644 +
77645 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
77646 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
77647 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
77648 + *vma_m = *vma;
77649 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
77650 + if (anon_vma_clone(vma_m, vma))
77651 + return -ENOMEM;
77652 + pol_m = vma_policy(vma_m);
77653 + mpol_get(pol_m);
77654 + vma_set_policy(vma_m, pol_m);
77655 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
77656 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
77657 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
77658 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
77659 + if (vma_m->vm_file)
77660 + get_file(vma_m->vm_file);
77661 + if (vma_m->vm_ops && vma_m->vm_ops->open)
77662 + vma_m->vm_ops->open(vma_m);
77663 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
77664 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
77665 + vma_m->vm_mirror = vma;
77666 + vma->vm_mirror = vma_m;
77667 + return 0;
77668 +}
77669 +#endif
77670 +
77671 /*
77672 * Return true if the calling process may expand its vm space by the passed
77673 * number of pages
77674 @@ -2786,6 +3283,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
77675
77676 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
77677
77678 +#ifdef CONFIG_PAX_RANDMMAP
77679 + if (mm->pax_flags & MF_PAX_RANDMMAP)
77680 + cur -= mm->brk_gap;
77681 +#endif
77682 +
77683 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
77684 if (cur + npages > lim)
77685 return 0;
77686 return 1;
77687 @@ -2856,6 +3359,22 @@ int install_special_mapping(struct mm_struct *mm,
77688 vma->vm_start = addr;
77689 vma->vm_end = addr + len;
77690
77691 +#ifdef CONFIG_PAX_MPROTECT
77692 + if (mm->pax_flags & MF_PAX_MPROTECT) {
77693 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
77694 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
77695 + return -EPERM;
77696 + if (!(vm_flags & VM_EXEC))
77697 + vm_flags &= ~VM_MAYEXEC;
77698 +#else
77699 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
77700 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
77701 +#endif
77702 + else
77703 + vm_flags &= ~VM_MAYWRITE;
77704 + }
77705 +#endif
77706 +
77707 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
77708 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
77709
77710 diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c
77711 index 8a5ac8c..f5c3d96 100644
77712 --- a/mm/mmu_notifier.c
77713 +++ b/mm/mmu_notifier.c
77714 @@ -37,49 +37,51 @@ static struct srcu_struct srcu;
77715 void __mmu_notifier_release(struct mm_struct *mm)
77716 {
77717 struct mmu_notifier *mn;
77718 - struct hlist_node *n;
77719 int id;
77720
77721 /*
77722 - * SRCU here will block mmu_notifier_unregister until
77723 - * ->release returns.
77724 + * srcu_read_lock() here will block synchronize_srcu() in
77725 + * mmu_notifier_unregister() until all registered
77726 + * ->release() callouts this function makes have
77727 + * returned.
77728 */
77729 id = srcu_read_lock(&srcu);
77730 - hlist_for_each_entry_rcu(mn, n, &mm->mmu_notifier_mm->list, hlist)
77731 - /*
77732 - * if ->release runs before mmu_notifier_unregister it
77733 - * must be handled as it's the only way for the driver
77734 - * to flush all existing sptes and stop the driver
77735 - * from establishing any more sptes before all the
77736 - * pages in the mm are freed.
77737 - */
77738 - if (mn->ops->release)
77739 - mn->ops->release(mn, mm);
77740 - srcu_read_unlock(&srcu, id);
77741 -
77742 spin_lock(&mm->mmu_notifier_mm->lock);
77743 while (unlikely(!hlist_empty(&mm->mmu_notifier_mm->list))) {
77744 mn = hlist_entry(mm->mmu_notifier_mm->list.first,
77745 struct mmu_notifier,
77746 hlist);
77747 +
77748 /*
77749 - * We arrived before mmu_notifier_unregister so
77750 - * mmu_notifier_unregister will do nothing other than
77751 - * to wait ->release to finish and
77752 - * mmu_notifier_unregister to return.
77753 + * Unlink. This will prevent mmu_notifier_unregister()
77754 + * from also making the ->release() callout.
77755 */
77756 hlist_del_init_rcu(&mn->hlist);
77757 + spin_unlock(&mm->mmu_notifier_mm->lock);
77758 +
77759 + /*
77760 + * Clear sptes. (see 'release' description in mmu_notifier.h)
77761 + */
77762 + if (mn->ops->release)
77763 + mn->ops->release(mn, mm);
77764 +
77765 + spin_lock(&mm->mmu_notifier_mm->lock);
77766 }
77767 spin_unlock(&mm->mmu_notifier_mm->lock);
77768
77769 /*
77770 - * synchronize_srcu here prevents mmu_notifier_release to
77771 - * return to exit_mmap (which would proceed freeing all pages
77772 - * in the mm) until the ->release method returns, if it was
77773 - * invoked by mmu_notifier_unregister.
77774 - *
77775 - * The mmu_notifier_mm can't go away from under us because one
77776 - * mm_count is hold by exit_mmap.
77777 + * All callouts to ->release() which we have done are complete.
77778 + * Allow synchronize_srcu() in mmu_notifier_unregister() to complete
77779 + */
77780 + srcu_read_unlock(&srcu, id);
77781 +
77782 + /*
77783 + * mmu_notifier_unregister() may have unlinked a notifier and may
77784 + * still be calling out to it. Additionally, other notifiers
77785 + * may have been active via vmtruncate() et. al. Block here
77786 + * to ensure that all notifier callouts for this mm have been
77787 + * completed and the sptes are really cleaned up before returning
77788 + * to exit_mmap().
77789 */
77790 synchronize_srcu(&srcu);
77791 }
77792 @@ -294,31 +296,31 @@ void mmu_notifier_unregister(struct mmu_notifier *mn, struct mm_struct *mm)
77793 {
77794 BUG_ON(atomic_read(&mm->mm_count) <= 0);
77795
77796 + spin_lock(&mm->mmu_notifier_mm->lock);
77797 if (!hlist_unhashed(&mn->hlist)) {
77798 - /*
77799 - * SRCU here will force exit_mmap to wait ->release to finish
77800 - * before freeing the pages.
77801 - */
77802 int id;
77803
77804 + /*
77805 + * Ensure we synchronize up with __mmu_notifier_release().
77806 + */
77807 id = srcu_read_lock(&srcu);
77808 - /*
77809 - * exit_mmap will block in mmu_notifier_release to
77810 - * guarantee ->release is called before freeing the
77811 - * pages.
77812 - */
77813 - if (mn->ops->release)
77814 - mn->ops->release(mn, mm);
77815 - srcu_read_unlock(&srcu, id);
77816
77817 - spin_lock(&mm->mmu_notifier_mm->lock);
77818 hlist_del_rcu(&mn->hlist);
77819 spin_unlock(&mm->mmu_notifier_mm->lock);
77820 - }
77821 +
77822 + if (mn->ops->release)
77823 + mn->ops->release(mn, mm);
77824 +
77825 + /*
77826 + * Allow __mmu_notifier_release() to complete.
77827 + */
77828 + srcu_read_unlock(&srcu, id);
77829 + } else
77830 + spin_unlock(&mm->mmu_notifier_mm->lock);
77831
77832 /*
77833 - * Wait any running method to finish, of course including
77834 - * ->release if it was run by mmu_notifier_relase instead of us.
77835 + * Wait for any running method to finish, including ->release() if it
77836 + * was run by __mmu_notifier_release() instead of us.
77837 */
77838 synchronize_srcu(&srcu);
77839
77840 diff --git a/mm/mprotect.c b/mm/mprotect.c
77841 index 94722a4..9837984 100644
77842 --- a/mm/mprotect.c
77843 +++ b/mm/mprotect.c
77844 @@ -23,10 +23,17 @@
77845 #include <linux/mmu_notifier.h>
77846 #include <linux/migrate.h>
77847 #include <linux/perf_event.h>
77848 +
77849 +#ifdef CONFIG_PAX_MPROTECT
77850 +#include <linux/elf.h>
77851 +#include <linux/binfmts.h>
77852 +#endif
77853 +
77854 #include <asm/uaccess.h>
77855 #include <asm/pgtable.h>
77856 #include <asm/cacheflush.h>
77857 #include <asm/tlbflush.h>
77858 +#include <asm/mmu_context.h>
77859
77860 #ifndef pgprot_modify
77861 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
77862 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
77863 return pages;
77864 }
77865
77866 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
77867 +/* called while holding the mmap semaphor for writing except stack expansion */
77868 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
77869 +{
77870 + unsigned long oldlimit, newlimit = 0UL;
77871 +
77872 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
77873 + return;
77874 +
77875 + spin_lock(&mm->page_table_lock);
77876 + oldlimit = mm->context.user_cs_limit;
77877 + if ((prot & VM_EXEC) && oldlimit < end)
77878 + /* USER_CS limit moved up */
77879 + newlimit = end;
77880 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
77881 + /* USER_CS limit moved down */
77882 + newlimit = start;
77883 +
77884 + if (newlimit) {
77885 + mm->context.user_cs_limit = newlimit;
77886 +
77887 +#ifdef CONFIG_SMP
77888 + wmb();
77889 + cpus_clear(mm->context.cpu_user_cs_mask);
77890 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
77891 +#endif
77892 +
77893 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
77894 + }
77895 + spin_unlock(&mm->page_table_lock);
77896 + if (newlimit == end) {
77897 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
77898 +
77899 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
77900 + if (is_vm_hugetlb_page(vma))
77901 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
77902 + else
77903 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
77904 + }
77905 +}
77906 +#endif
77907 +
77908 int
77909 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77910 unsigned long start, unsigned long end, unsigned long newflags)
77911 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77912 int error;
77913 int dirty_accountable = 0;
77914
77915 +#ifdef CONFIG_PAX_SEGMEXEC
77916 + struct vm_area_struct *vma_m = NULL;
77917 + unsigned long start_m, end_m;
77918 +
77919 + start_m = start + SEGMEXEC_TASK_SIZE;
77920 + end_m = end + SEGMEXEC_TASK_SIZE;
77921 +#endif
77922 +
77923 if (newflags == oldflags) {
77924 *pprev = vma;
77925 return 0;
77926 }
77927
77928 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
77929 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
77930 +
77931 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
77932 + return -ENOMEM;
77933 +
77934 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
77935 + return -ENOMEM;
77936 + }
77937 +
77938 /*
77939 * If we make a private mapping writable we increase our commit;
77940 * but (without finer accounting) cannot reduce our commit if we
77941 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
77942 }
77943 }
77944
77945 +#ifdef CONFIG_PAX_SEGMEXEC
77946 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
77947 + if (start != vma->vm_start) {
77948 + error = split_vma(mm, vma, start, 1);
77949 + if (error)
77950 + goto fail;
77951 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
77952 + *pprev = (*pprev)->vm_next;
77953 + }
77954 +
77955 + if (end != vma->vm_end) {
77956 + error = split_vma(mm, vma, end, 0);
77957 + if (error)
77958 + goto fail;
77959 + }
77960 +
77961 + if (pax_find_mirror_vma(vma)) {
77962 + error = __do_munmap(mm, start_m, end_m - start_m);
77963 + if (error)
77964 + goto fail;
77965 + } else {
77966 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
77967 + if (!vma_m) {
77968 + error = -ENOMEM;
77969 + goto fail;
77970 + }
77971 + vma->vm_flags = newflags;
77972 + error = pax_mirror_vma(vma_m, vma);
77973 + if (error) {
77974 + vma->vm_flags = oldflags;
77975 + goto fail;
77976 + }
77977 + }
77978 + }
77979 +#endif
77980 +
77981 /*
77982 * First try to merge with previous and/or next vma.
77983 */
77984 @@ -296,9 +399,21 @@ success:
77985 * vm_flags and vm_page_prot are protected by the mmap_sem
77986 * held in write mode.
77987 */
77988 +
77989 +#ifdef CONFIG_PAX_SEGMEXEC
77990 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
77991 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
77992 +#endif
77993 +
77994 vma->vm_flags = newflags;
77995 +
77996 +#ifdef CONFIG_PAX_MPROTECT
77997 + if (mm->binfmt && mm->binfmt->handle_mprotect)
77998 + mm->binfmt->handle_mprotect(vma, newflags);
77999 +#endif
78000 +
78001 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
78002 - vm_get_page_prot(newflags));
78003 + vm_get_page_prot(vma->vm_flags));
78004
78005 if (vma_wants_writenotify(vma)) {
78006 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
78007 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78008 end = start + len;
78009 if (end <= start)
78010 return -ENOMEM;
78011 +
78012 +#ifdef CONFIG_PAX_SEGMEXEC
78013 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
78014 + if (end > SEGMEXEC_TASK_SIZE)
78015 + return -EINVAL;
78016 + } else
78017 +#endif
78018 +
78019 + if (end > TASK_SIZE)
78020 + return -EINVAL;
78021 +
78022 if (!arch_validate_prot(prot))
78023 return -EINVAL;
78024
78025 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78026 /*
78027 * Does the application expect PROT_READ to imply PROT_EXEC:
78028 */
78029 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
78030 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
78031 prot |= PROT_EXEC;
78032
78033 vm_flags = calc_vm_prot_bits(prot);
78034 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78035 if (start > vma->vm_start)
78036 prev = vma;
78037
78038 +#ifdef CONFIG_PAX_MPROTECT
78039 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
78040 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
78041 +#endif
78042 +
78043 for (nstart = start ; ; ) {
78044 unsigned long newflags;
78045
78046 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78047
78048 /* newflags >> 4 shift VM_MAY% in place of VM_% */
78049 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
78050 + if (prot & (PROT_WRITE | PROT_EXEC))
78051 + gr_log_rwxmprotect(vma->vm_file);
78052 +
78053 + error = -EACCES;
78054 + goto out;
78055 + }
78056 +
78057 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
78058 error = -EACCES;
78059 goto out;
78060 }
78061 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
78062 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
78063 if (error)
78064 goto out;
78065 +
78066 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
78067 +
78068 nstart = tmp;
78069
78070 if (nstart < prev->vm_end)
78071 diff --git a/mm/mremap.c b/mm/mremap.c
78072 index e1031e1..1f2a0a1 100644
78073 --- a/mm/mremap.c
78074 +++ b/mm/mremap.c
78075 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
78076 continue;
78077 pte = ptep_get_and_clear(mm, old_addr, old_pte);
78078 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
78079 +
78080 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
78081 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
78082 + pte = pte_exprotect(pte);
78083 +#endif
78084 +
78085 set_pte_at(mm, new_addr, new_pte, pte);
78086 }
78087
78088 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
78089 if (is_vm_hugetlb_page(vma))
78090 goto Einval;
78091
78092 +#ifdef CONFIG_PAX_SEGMEXEC
78093 + if (pax_find_mirror_vma(vma))
78094 + goto Einval;
78095 +#endif
78096 +
78097 /* We can't remap across vm area boundaries */
78098 if (old_len > vma->vm_end - addr)
78099 goto Efault;
78100 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
78101 unsigned long ret = -EINVAL;
78102 unsigned long charged = 0;
78103 unsigned long map_flags;
78104 + unsigned long pax_task_size = TASK_SIZE;
78105
78106 if (new_addr & ~PAGE_MASK)
78107 goto out;
78108
78109 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
78110 +#ifdef CONFIG_PAX_SEGMEXEC
78111 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
78112 + pax_task_size = SEGMEXEC_TASK_SIZE;
78113 +#endif
78114 +
78115 + pax_task_size -= PAGE_SIZE;
78116 +
78117 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
78118 goto out;
78119
78120 /* Check if the location we're moving into overlaps the
78121 * old location at all, and fail if it does.
78122 */
78123 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
78124 - goto out;
78125 -
78126 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
78127 + if (addr + old_len > new_addr && new_addr + new_len > addr)
78128 goto out;
78129
78130 ret = do_munmap(mm, new_addr, new_len);
78131 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78132 struct vm_area_struct *vma;
78133 unsigned long ret = -EINVAL;
78134 unsigned long charged = 0;
78135 + unsigned long pax_task_size = TASK_SIZE;
78136
78137 down_write(&current->mm->mmap_sem);
78138
78139 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78140 if (!new_len)
78141 goto out;
78142
78143 +#ifdef CONFIG_PAX_SEGMEXEC
78144 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
78145 + pax_task_size = SEGMEXEC_TASK_SIZE;
78146 +#endif
78147 +
78148 + pax_task_size -= PAGE_SIZE;
78149 +
78150 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
78151 + old_len > pax_task_size || addr > pax_task_size-old_len)
78152 + goto out;
78153 +
78154 if (flags & MREMAP_FIXED) {
78155 if (flags & MREMAP_MAYMOVE)
78156 ret = mremap_to(addr, old_len, new_addr, new_len);
78157 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78158 addr + new_len);
78159 }
78160 ret = addr;
78161 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
78162 goto out;
78163 }
78164 }
78165 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
78166 goto out;
78167 }
78168
78169 + map_flags = vma->vm_flags;
78170 ret = move_vma(vma, addr, old_len, new_len, new_addr);
78171 + if (!(ret & ~PAGE_MASK)) {
78172 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
78173 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
78174 + }
78175 }
78176 out:
78177 if (ret & ~PAGE_MASK)
78178 diff --git a/mm/nommu.c b/mm/nommu.c
78179 index 79c3cac..4d357e0 100644
78180 --- a/mm/nommu.c
78181 +++ b/mm/nommu.c
78182 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
78183 int sysctl_overcommit_ratio = 50; /* default is 50% */
78184 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
78185 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
78186 -int heap_stack_gap = 0;
78187
78188 atomic_long_t mmap_pages_allocated;
78189
78190 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
78191 EXPORT_SYMBOL(find_vma);
78192
78193 /*
78194 - * find a VMA
78195 - * - we don't extend stack VMAs under NOMMU conditions
78196 - */
78197 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
78198 -{
78199 - return find_vma(mm, addr);
78200 -}
78201 -
78202 -/*
78203 * expand a stack to a given address
78204 * - not supported under NOMMU conditions
78205 */
78206 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
78207
78208 /* most fields are the same, copy all, and then fixup */
78209 *new = *vma;
78210 + INIT_LIST_HEAD(&new->anon_vma_chain);
78211 *region = *vma->vm_region;
78212 new->vm_region = region;
78213
78214 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
78215 index 0713bfb..e3774e0 100644
78216 --- a/mm/page-writeback.c
78217 +++ b/mm/page-writeback.c
78218 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
78219 }
78220 }
78221
78222 -static struct notifier_block __cpuinitdata ratelimit_nb = {
78223 +static struct notifier_block ratelimit_nb = {
78224 .notifier_call = ratelimit_handler,
78225 .next = NULL,
78226 };
78227 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
78228 index 6a83cd3..bc2dcb6 100644
78229 --- a/mm/page_alloc.c
78230 +++ b/mm/page_alloc.c
78231 @@ -338,7 +338,7 @@ out:
78232 * This usage means that zero-order pages may not be compound.
78233 */
78234
78235 -static void free_compound_page(struct page *page)
78236 +void free_compound_page(struct page *page)
78237 {
78238 __free_pages_ok(page, compound_order(page));
78239 }
78240 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78241 int i;
78242 int bad = 0;
78243
78244 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
78245 + unsigned long index = 1UL << order;
78246 +#endif
78247 +
78248 trace_mm_page_free(page, order);
78249 kmemcheck_free_shadow(page, order);
78250
78251 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
78252 debug_check_no_obj_freed(page_address(page),
78253 PAGE_SIZE << order);
78254 }
78255 +
78256 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
78257 + for (; index; --index)
78258 + sanitize_highpage(page + index - 1);
78259 +#endif
78260 +
78261 arch_free_page(page, order);
78262 kernel_map_pages(page, 1 << order, 0);
78263
78264 @@ -861,8 +871,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
78265 arch_alloc_page(page, order);
78266 kernel_map_pages(page, 1 << order, 1);
78267
78268 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
78269 if (gfp_flags & __GFP_ZERO)
78270 prep_zero_page(page, order, gfp_flags);
78271 +#endif
78272
78273 if (order && (gfp_flags & __GFP_COMP))
78274 prep_compound_page(page, order);
78275 @@ -3752,7 +3764,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
78276 unsigned long pfn;
78277
78278 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
78279 +#ifdef CONFIG_X86_32
78280 + /* boot failures in VMware 8 on 32bit vanilla since
78281 + this change */
78282 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
78283 +#else
78284 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
78285 +#endif
78286 return 1;
78287 }
78288 return 0;
78289 diff --git a/mm/percpu.c b/mm/percpu.c
78290 index 8c8e08f..73a5cda 100644
78291 --- a/mm/percpu.c
78292 +++ b/mm/percpu.c
78293 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
78294 static unsigned int pcpu_high_unit_cpu __read_mostly;
78295
78296 /* the address of the first chunk which starts with the kernel static area */
78297 -void *pcpu_base_addr __read_mostly;
78298 +void *pcpu_base_addr __read_only;
78299 EXPORT_SYMBOL_GPL(pcpu_base_addr);
78300
78301 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
78302 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
78303 index 926b466..b23df53 100644
78304 --- a/mm/process_vm_access.c
78305 +++ b/mm/process_vm_access.c
78306 @@ -13,6 +13,7 @@
78307 #include <linux/uio.h>
78308 #include <linux/sched.h>
78309 #include <linux/highmem.h>
78310 +#include <linux/security.h>
78311 #include <linux/ptrace.h>
78312 #include <linux/slab.h>
78313 #include <linux/syscalls.h>
78314 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78315 size_t iov_l_curr_offset = 0;
78316 ssize_t iov_len;
78317
78318 + return -ENOSYS; // PaX: until properly audited
78319 +
78320 /*
78321 * Work out how many pages of struct pages we're going to need
78322 * when eventually calling get_user_pages
78323 */
78324 for (i = 0; i < riovcnt; i++) {
78325 iov_len = rvec[i].iov_len;
78326 - if (iov_len > 0) {
78327 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
78328 - + iov_len)
78329 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
78330 - / PAGE_SIZE + 1;
78331 - nr_pages = max(nr_pages, nr_pages_iov);
78332 - }
78333 + if (iov_len <= 0)
78334 + continue;
78335 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
78336 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
78337 + nr_pages = max(nr_pages, nr_pages_iov);
78338 }
78339
78340 if (nr_pages == 0)
78341 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
78342 goto free_proc_pages;
78343 }
78344
78345 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
78346 + rc = -EPERM;
78347 + goto put_task_struct;
78348 + }
78349 +
78350 mm = mm_access(task, PTRACE_MODE_ATTACH);
78351 if (!mm || IS_ERR(mm)) {
78352 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
78353 diff --git a/mm/rmap.c b/mm/rmap.c
78354 index 2c78f8c..9e9c624 100644
78355 --- a/mm/rmap.c
78356 +++ b/mm/rmap.c
78357 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78358 struct anon_vma *anon_vma = vma->anon_vma;
78359 struct anon_vma_chain *avc;
78360
78361 +#ifdef CONFIG_PAX_SEGMEXEC
78362 + struct anon_vma_chain *avc_m = NULL;
78363 +#endif
78364 +
78365 might_sleep();
78366 if (unlikely(!anon_vma)) {
78367 struct mm_struct *mm = vma->vm_mm;
78368 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78369 if (!avc)
78370 goto out_enomem;
78371
78372 +#ifdef CONFIG_PAX_SEGMEXEC
78373 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
78374 + if (!avc_m)
78375 + goto out_enomem_free_avc;
78376 +#endif
78377 +
78378 anon_vma = find_mergeable_anon_vma(vma);
78379 allocated = NULL;
78380 if (!anon_vma) {
78381 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78382 /* page_table_lock to protect against threads */
78383 spin_lock(&mm->page_table_lock);
78384 if (likely(!vma->anon_vma)) {
78385 +
78386 +#ifdef CONFIG_PAX_SEGMEXEC
78387 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
78388 +
78389 + if (vma_m) {
78390 + BUG_ON(vma_m->anon_vma);
78391 + vma_m->anon_vma = anon_vma;
78392 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
78393 + avc_m = NULL;
78394 + }
78395 +#endif
78396 +
78397 vma->anon_vma = anon_vma;
78398 anon_vma_chain_link(vma, avc, anon_vma);
78399 allocated = NULL;
78400 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
78401
78402 if (unlikely(allocated))
78403 put_anon_vma(allocated);
78404 +
78405 +#ifdef CONFIG_PAX_SEGMEXEC
78406 + if (unlikely(avc_m))
78407 + anon_vma_chain_free(avc_m);
78408 +#endif
78409 +
78410 if (unlikely(avc))
78411 anon_vma_chain_free(avc);
78412 }
78413 return 0;
78414
78415 out_enomem_free_avc:
78416 +
78417 +#ifdef CONFIG_PAX_SEGMEXEC
78418 + if (avc_m)
78419 + anon_vma_chain_free(avc_m);
78420 +#endif
78421 +
78422 anon_vma_chain_free(avc);
78423 out_enomem:
78424 return -ENOMEM;
78425 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
78426 * Attach the anon_vmas from src to dst.
78427 * Returns 0 on success, -ENOMEM on failure.
78428 */
78429 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78430 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
78431 {
78432 struct anon_vma_chain *avc, *pavc;
78433 struct anon_vma *root = NULL;
78434 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
78435 * the corresponding VMA in the parent process is attached to.
78436 * Returns 0 on success, non-zero on failure.
78437 */
78438 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
78439 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
78440 {
78441 struct anon_vma_chain *avc;
78442 struct anon_vma *anon_vma;
78443 diff --git a/mm/shmem.c b/mm/shmem.c
78444 index 5dd56f6..994b702 100644
78445 --- a/mm/shmem.c
78446 +++ b/mm/shmem.c
78447 @@ -31,7 +31,7 @@
78448 #include <linux/export.h>
78449 #include <linux/swap.h>
78450
78451 -static struct vfsmount *shm_mnt;
78452 +struct vfsmount *shm_mnt;
78453
78454 #ifdef CONFIG_SHMEM
78455 /*
78456 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
78457 #define BOGO_DIRENT_SIZE 20
78458
78459 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
78460 -#define SHORT_SYMLINK_LEN 128
78461 +#define SHORT_SYMLINK_LEN 64
78462
78463 /*
78464 * shmem_fallocate and shmem_writepage communicate via inode->i_private
78465 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
78466 static int shmem_xattr_validate(const char *name)
78467 {
78468 struct { const char *prefix; size_t len; } arr[] = {
78469 +
78470 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78471 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
78472 +#endif
78473 +
78474 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
78475 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
78476 };
78477 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
78478 if (err)
78479 return err;
78480
78481 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
78482 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
78483 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
78484 + return -EOPNOTSUPP;
78485 + if (size > 8)
78486 + return -EINVAL;
78487 + }
78488 +#endif
78489 +
78490 return simple_xattr_set(&info->xattrs, name, value, size, flags);
78491 }
78492
78493 @@ -2487,6 +2501,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
78494 unsigned long inodes;
78495 int error = -EINVAL;
78496
78497 + config.mpol = NULL;
78498 if (shmem_parse_options(data, &config, true))
78499 return error;
78500
78501 @@ -2511,8 +2526,13 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
78502 sbinfo->max_inodes = config.max_inodes;
78503 sbinfo->free_inodes = config.max_inodes - inodes;
78504
78505 - mpol_put(sbinfo->mpol);
78506 - sbinfo->mpol = config.mpol; /* transfers initial ref */
78507 + /*
78508 + * Preserve previous mempolicy unless mpol remount option was specified.
78509 + */
78510 + if (config.mpol) {
78511 + mpol_put(sbinfo->mpol);
78512 + sbinfo->mpol = config.mpol; /* transfers initial ref */
78513 + }
78514 out:
78515 spin_unlock(&sbinfo->stat_lock);
78516 return error;
78517 @@ -2556,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
78518 int err = -ENOMEM;
78519
78520 /* Round up to L1_CACHE_BYTES to resist false sharing */
78521 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
78522 - L1_CACHE_BYTES), GFP_KERNEL);
78523 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
78524 if (!sbinfo)
78525 return -ENOMEM;
78526
78527 diff --git a/mm/slab.c b/mm/slab.c
78528 index e7667a3..b62c169 100644
78529 --- a/mm/slab.c
78530 +++ b/mm/slab.c
78531 @@ -306,7 +306,7 @@ struct kmem_list3 {
78532 * Need this for bootstrapping a per node allocator.
78533 */
78534 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
78535 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
78536 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
78537 #define CACHE_CACHE 0
78538 #define SIZE_AC MAX_NUMNODES
78539 #define SIZE_L3 (2 * MAX_NUMNODES)
78540 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
78541 if ((x)->max_freeable < i) \
78542 (x)->max_freeable = i; \
78543 } while (0)
78544 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
78545 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
78546 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
78547 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
78548 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
78549 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
78550 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
78551 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
78552 #else
78553 #define STATS_INC_ACTIVE(x) do { } while (0)
78554 #define STATS_DEC_ACTIVE(x) do { } while (0)
78555 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
78556 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
78557 */
78558 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
78559 - const struct slab *slab, void *obj)
78560 + const struct slab *slab, const void *obj)
78561 {
78562 u32 offset = (obj - slab->s_mem);
78563 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
78564 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
78565 struct cache_names {
78566 char *name;
78567 char *name_dma;
78568 + char *name_usercopy;
78569 };
78570
78571 static struct cache_names __initdata cache_names[] = {
78572 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
78573 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
78574 #include <linux/kmalloc_sizes.h>
78575 - {NULL,}
78576 + {NULL}
78577 #undef CACHE
78578 };
78579
78580 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
78581 if (unlikely(gfpflags & GFP_DMA))
78582 return csizep->cs_dmacachep;
78583 #endif
78584 +
78585 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78586 + if (unlikely(gfpflags & GFP_USERCOPY))
78587 + return csizep->cs_usercopycachep;
78588 +#endif
78589 +
78590 return csizep->cs_cachep;
78591 }
78592
78593 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
78594 return notifier_from_errno(err);
78595 }
78596
78597 -static struct notifier_block __cpuinitdata cpucache_notifier = {
78598 +static struct notifier_block cpucache_notifier = {
78599 &cpuup_callback, NULL, 0
78600 };
78601
78602 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
78603 */
78604
78605 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
78606 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
78607 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78608
78609 if (INDEX_AC != INDEX_L3)
78610 sizes[INDEX_L3].cs_cachep =
78611 create_kmalloc_cache(names[INDEX_L3].name,
78612 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
78613 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78614
78615 slab_early_init = 0;
78616
78617 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
78618 */
78619 if (!sizes->cs_cachep)
78620 sizes->cs_cachep = create_kmalloc_cache(names->name,
78621 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
78622 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78623
78624 #ifdef CONFIG_ZONE_DMA
78625 sizes->cs_dmacachep = create_kmalloc_cache(
78626 names->name_dma, sizes->cs_size,
78627 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
78628 #endif
78629 +
78630 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78631 + sizes->cs_usercopycachep = create_kmalloc_cache(
78632 + names->name_usercopy, sizes->cs_size,
78633 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
78634 +#endif
78635 +
78636 sizes++;
78637 names++;
78638 }
78639 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
78640 }
78641 /* cpu stats */
78642 {
78643 - unsigned long allochit = atomic_read(&cachep->allochit);
78644 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
78645 - unsigned long freehit = atomic_read(&cachep->freehit);
78646 - unsigned long freemiss = atomic_read(&cachep->freemiss);
78647 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
78648 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
78649 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
78650 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
78651
78652 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
78653 allochit, allocmiss, freehit, freemiss);
78654 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
78655 static int __init slab_proc_init(void)
78656 {
78657 #ifdef CONFIG_DEBUG_SLAB_LEAK
78658 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
78659 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
78660 #endif
78661 return 0;
78662 }
78663 module_init(slab_proc_init);
78664 #endif
78665
78666 +bool is_usercopy_object(const void *ptr)
78667 +{
78668 + struct page *page;
78669 + struct kmem_cache *cachep;
78670 +
78671 + if (ZERO_OR_NULL_PTR(ptr))
78672 + return false;
78673 +
78674 + if (!slab_is_available())
78675 + return false;
78676 +
78677 + if (!virt_addr_valid(ptr))
78678 + return false;
78679 +
78680 + page = virt_to_head_page(ptr);
78681 +
78682 + if (!PageSlab(page))
78683 + return false;
78684 +
78685 + cachep = page->slab_cache;
78686 + return cachep->flags & SLAB_USERCOPY;
78687 +}
78688 +
78689 +#ifdef CONFIG_PAX_USERCOPY
78690 +const char *check_heap_object(const void *ptr, unsigned long n)
78691 +{
78692 + struct page *page;
78693 + struct kmem_cache *cachep;
78694 + struct slab *slabp;
78695 + unsigned int objnr;
78696 + unsigned long offset;
78697 +
78698 + if (ZERO_OR_NULL_PTR(ptr))
78699 + return "<null>";
78700 +
78701 + if (!virt_addr_valid(ptr))
78702 + return NULL;
78703 +
78704 + page = virt_to_head_page(ptr);
78705 +
78706 + if (!PageSlab(page))
78707 + return NULL;
78708 +
78709 + cachep = page->slab_cache;
78710 + if (!(cachep->flags & SLAB_USERCOPY))
78711 + return cachep->name;
78712 +
78713 + slabp = page->slab_page;
78714 + objnr = obj_to_index(cachep, slabp, ptr);
78715 + BUG_ON(objnr >= cachep->num);
78716 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
78717 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
78718 + return NULL;
78719 +
78720 + return cachep->name;
78721 +}
78722 +#endif
78723 +
78724 /**
78725 * ksize - get the actual amount of memory allocated for a given object
78726 * @objp: Pointer to the object
78727 diff --git a/mm/slab.h b/mm/slab.h
78728 index 34a98d6..73633d1 100644
78729 --- a/mm/slab.h
78730 +++ b/mm/slab.h
78731 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
78732
78733 /* Legal flag mask for kmem_cache_create(), for various configurations */
78734 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
78735 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
78736 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
78737
78738 #if defined(CONFIG_DEBUG_SLAB)
78739 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
78740 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
78741 return s;
78742
78743 page = virt_to_head_page(x);
78744 +
78745 + BUG_ON(!PageSlab(page));
78746 +
78747 cachep = page->slab_cache;
78748 if (slab_equal_or_root(cachep, s))
78749 return cachep;
78750 diff --git a/mm/slab_common.c b/mm/slab_common.c
78751 index 3f3cd97..e050794 100644
78752 --- a/mm/slab_common.c
78753 +++ b/mm/slab_common.c
78754 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
78755
78756 err = __kmem_cache_create(s, flags);
78757 if (!err) {
78758 - s->refcount = 1;
78759 + atomic_set(&s->refcount, 1);
78760 list_add(&s->list, &slab_caches);
78761 memcg_cache_list_add(memcg, s);
78762 } else {
78763 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
78764
78765 get_online_cpus();
78766 mutex_lock(&slab_mutex);
78767 - s->refcount--;
78768 - if (!s->refcount) {
78769 + if (atomic_dec_and_test(&s->refcount)) {
78770 list_del(&s->list);
78771
78772 if (!__kmem_cache_shutdown(s)) {
78773 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
78774 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
78775 name, size, err);
78776
78777 - s->refcount = -1; /* Exempt from merging for now */
78778 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
78779 }
78780
78781 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78782 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
78783
78784 create_boot_cache(s, name, size, flags);
78785 list_add(&s->list, &slab_caches);
78786 - s->refcount = 1;
78787 + atomic_set(&s->refcount, 1);
78788 return s;
78789 }
78790
78791 diff --git a/mm/slob.c b/mm/slob.c
78792 index a99fdf7..f5b6577 100644
78793 --- a/mm/slob.c
78794 +++ b/mm/slob.c
78795 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
78796 /*
78797 * Return the size of a slob block.
78798 */
78799 -static slobidx_t slob_units(slob_t *s)
78800 +static slobidx_t slob_units(const slob_t *s)
78801 {
78802 if (s->units > 0)
78803 return s->units;
78804 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
78805 /*
78806 * Return the next free slob block pointer after this one.
78807 */
78808 -static slob_t *slob_next(slob_t *s)
78809 +static slob_t *slob_next(const slob_t *s)
78810 {
78811 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
78812 slobidx_t next;
78813 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
78814 /*
78815 * Returns true if s is the last free block in its page.
78816 */
78817 -static int slob_last(slob_t *s)
78818 +static int slob_last(const slob_t *s)
78819 {
78820 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
78821 }
78822
78823 -static void *slob_new_pages(gfp_t gfp, int order, int node)
78824 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
78825 {
78826 - void *page;
78827 + struct page *page;
78828
78829 #ifdef CONFIG_NUMA
78830 if (node != NUMA_NO_NODE)
78831 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
78832 if (!page)
78833 return NULL;
78834
78835 - return page_address(page);
78836 + __SetPageSlab(page);
78837 + return page;
78838 }
78839
78840 -static void slob_free_pages(void *b, int order)
78841 +static void slob_free_pages(struct page *sp, int order)
78842 {
78843 if (current->reclaim_state)
78844 current->reclaim_state->reclaimed_slab += 1 << order;
78845 - free_pages((unsigned long)b, order);
78846 + __ClearPageSlab(sp);
78847 + reset_page_mapcount(sp);
78848 + sp->private = 0;
78849 + __free_pages(sp, order);
78850 }
78851
78852 /*
78853 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
78854
78855 /* Not enough space: must allocate a new page */
78856 if (!b) {
78857 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78858 - if (!b)
78859 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
78860 + if (!sp)
78861 return NULL;
78862 - sp = virt_to_page(b);
78863 - __SetPageSlab(sp);
78864 + b = page_address(sp);
78865
78866 spin_lock_irqsave(&slob_lock, flags);
78867 sp->units = SLOB_UNITS(PAGE_SIZE);
78868 sp->freelist = b;
78869 + sp->private = 0;
78870 INIT_LIST_HEAD(&sp->list);
78871 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
78872 set_slob_page_free(sp, slob_list);
78873 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
78874 if (slob_page_free(sp))
78875 clear_slob_page_free(sp);
78876 spin_unlock_irqrestore(&slob_lock, flags);
78877 - __ClearPageSlab(sp);
78878 - reset_page_mapcount(sp);
78879 - slob_free_pages(b, 0);
78880 + slob_free_pages(sp, 0);
78881 return;
78882 }
78883
78884 @@ -424,11 +426,10 @@ out:
78885 */
78886
78887 static __always_inline void *
78888 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78889 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
78890 {
78891 - unsigned int *m;
78892 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78893 - void *ret;
78894 + slob_t *m;
78895 + void *ret = NULL;
78896
78897 gfp &= gfp_allowed_mask;
78898
78899 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78900
78901 if (!m)
78902 return NULL;
78903 - *m = size;
78904 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
78905 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
78906 + m[0].units = size;
78907 + m[1].units = align;
78908 ret = (void *)m + align;
78909
78910 trace_kmalloc_node(caller, ret,
78911 size, size + align, gfp, node);
78912 } else {
78913 unsigned int order = get_order(size);
78914 + struct page *page;
78915
78916 if (likely(order))
78917 gfp |= __GFP_COMP;
78918 - ret = slob_new_pages(gfp, order, node);
78919 + page = slob_new_pages(gfp, order, node);
78920 + if (page) {
78921 + ret = page_address(page);
78922 + page->private = size;
78923 + }
78924
78925 trace_kmalloc_node(caller, ret,
78926 size, PAGE_SIZE << order, gfp, node);
78927 }
78928
78929 - kmemleak_alloc(ret, size, 1, gfp);
78930 + return ret;
78931 +}
78932 +
78933 +static __always_inline void *
78934 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
78935 +{
78936 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78937 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
78938 +
78939 + if (!ZERO_OR_NULL_PTR(ret))
78940 + kmemleak_alloc(ret, size, 1, gfp);
78941 return ret;
78942 }
78943
78944 @@ -494,33 +513,110 @@ void kfree(const void *block)
78945 kmemleak_free(block);
78946
78947 sp = virt_to_page(block);
78948 - if (PageSlab(sp)) {
78949 + VM_BUG_ON(!PageSlab(sp));
78950 + if (!sp->private) {
78951 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
78952 - unsigned int *m = (unsigned int *)(block - align);
78953 - slob_free(m, *m + align);
78954 - } else
78955 + slob_t *m = (slob_t *)(block - align);
78956 + slob_free(m, m[0].units + align);
78957 + } else {
78958 + __ClearPageSlab(sp);
78959 + reset_page_mapcount(sp);
78960 + sp->private = 0;
78961 __free_pages(sp, compound_order(sp));
78962 + }
78963 }
78964 EXPORT_SYMBOL(kfree);
78965
78966 +bool is_usercopy_object(const void *ptr)
78967 +{
78968 + if (!slab_is_available())
78969 + return false;
78970 +
78971 + // PAX: TODO
78972 +
78973 + return false;
78974 +}
78975 +
78976 +#ifdef CONFIG_PAX_USERCOPY
78977 +const char *check_heap_object(const void *ptr, unsigned long n)
78978 +{
78979 + struct page *page;
78980 + const slob_t *free;
78981 + const void *base;
78982 + unsigned long flags;
78983 +
78984 + if (ZERO_OR_NULL_PTR(ptr))
78985 + return "<null>";
78986 +
78987 + if (!virt_addr_valid(ptr))
78988 + return NULL;
78989 +
78990 + page = virt_to_head_page(ptr);
78991 + if (!PageSlab(page))
78992 + return NULL;
78993 +
78994 + if (page->private) {
78995 + base = page;
78996 + if (base <= ptr && n <= page->private - (ptr - base))
78997 + return NULL;
78998 + return "<slob>";
78999 + }
79000 +
79001 + /* some tricky double walking to find the chunk */
79002 + spin_lock_irqsave(&slob_lock, flags);
79003 + base = (void *)((unsigned long)ptr & PAGE_MASK);
79004 + free = page->freelist;
79005 +
79006 + while (!slob_last(free) && (void *)free <= ptr) {
79007 + base = free + slob_units(free);
79008 + free = slob_next(free);
79009 + }
79010 +
79011 + while (base < (void *)free) {
79012 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
79013 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
79014 + int offset;
79015 +
79016 + if (ptr < base + align)
79017 + break;
79018 +
79019 + offset = ptr - base - align;
79020 + if (offset >= m) {
79021 + base += size;
79022 + continue;
79023 + }
79024 +
79025 + if (n > m - offset)
79026 + break;
79027 +
79028 + spin_unlock_irqrestore(&slob_lock, flags);
79029 + return NULL;
79030 + }
79031 +
79032 + spin_unlock_irqrestore(&slob_lock, flags);
79033 + return "<slob>";
79034 +}
79035 +#endif
79036 +
79037 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
79038 size_t ksize(const void *block)
79039 {
79040 struct page *sp;
79041 int align;
79042 - unsigned int *m;
79043 + slob_t *m;
79044
79045 BUG_ON(!block);
79046 if (unlikely(block == ZERO_SIZE_PTR))
79047 return 0;
79048
79049 sp = virt_to_page(block);
79050 - if (unlikely(!PageSlab(sp)))
79051 - return PAGE_SIZE << compound_order(sp);
79052 + VM_BUG_ON(!PageSlab(sp));
79053 + if (sp->private)
79054 + return sp->private;
79055
79056 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
79057 - m = (unsigned int *)(block - align);
79058 - return SLOB_UNITS(*m) * SLOB_UNIT;
79059 + m = (slob_t *)(block - align);
79060 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
79061 }
79062 EXPORT_SYMBOL(ksize);
79063
79064 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
79065
79066 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
79067 {
79068 - void *b;
79069 + void *b = NULL;
79070
79071 flags &= gfp_allowed_mask;
79072
79073 lockdep_trace_alloc(flags);
79074
79075 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79076 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
79077 +#else
79078 if (c->size < PAGE_SIZE) {
79079 b = slob_alloc(c->size, flags, c->align, node);
79080 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
79081 SLOB_UNITS(c->size) * SLOB_UNIT,
79082 flags, node);
79083 } else {
79084 - b = slob_new_pages(flags, get_order(c->size), node);
79085 + struct page *sp;
79086 +
79087 + sp = slob_new_pages(flags, get_order(c->size), node);
79088 + if (sp) {
79089 + b = page_address(sp);
79090 + sp->private = c->size;
79091 + }
79092 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
79093 PAGE_SIZE << get_order(c->size),
79094 flags, node);
79095 }
79096 +#endif
79097
79098 if (c->ctor)
79099 c->ctor(b);
79100 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
79101
79102 static void __kmem_cache_free(void *b, int size)
79103 {
79104 - if (size < PAGE_SIZE)
79105 + struct page *sp;
79106 +
79107 + sp = virt_to_page(b);
79108 + BUG_ON(!PageSlab(sp));
79109 + if (!sp->private)
79110 slob_free(b, size);
79111 else
79112 - slob_free_pages(b, get_order(size));
79113 + slob_free_pages(sp, get_order(size));
79114 }
79115
79116 static void kmem_rcu_free(struct rcu_head *head)
79117 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
79118
79119 void kmem_cache_free(struct kmem_cache *c, void *b)
79120 {
79121 + int size = c->size;
79122 +
79123 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79124 + if (size + c->align < PAGE_SIZE) {
79125 + size += c->align;
79126 + b -= c->align;
79127 + }
79128 +#endif
79129 +
79130 kmemleak_free_recursive(b, c->flags);
79131 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
79132 struct slob_rcu *slob_rcu;
79133 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
79134 - slob_rcu->size = c->size;
79135 + slob_rcu = b + (size - sizeof(struct slob_rcu));
79136 + slob_rcu->size = size;
79137 call_rcu(&slob_rcu->head, kmem_rcu_free);
79138 } else {
79139 - __kmem_cache_free(b, c->size);
79140 + __kmem_cache_free(b, size);
79141 }
79142
79143 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79144 + trace_kfree(_RET_IP_, b);
79145 +#else
79146 trace_kmem_cache_free(_RET_IP_, b);
79147 +#endif
79148 +
79149 }
79150 EXPORT_SYMBOL(kmem_cache_free);
79151
79152 diff --git a/mm/slub.c b/mm/slub.c
79153 index ba2ca53..00b1f4e 100644
79154 --- a/mm/slub.c
79155 +++ b/mm/slub.c
79156 @@ -197,7 +197,7 @@ struct track {
79157
79158 enum track_item { TRACK_ALLOC, TRACK_FREE };
79159
79160 -#ifdef CONFIG_SYSFS
79161 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79162 static int sysfs_slab_add(struct kmem_cache *);
79163 static int sysfs_slab_alias(struct kmem_cache *, const char *);
79164 static void sysfs_slab_remove(struct kmem_cache *);
79165 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
79166 if (!t->addr)
79167 return;
79168
79169 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
79170 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
79171 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
79172 #ifdef CONFIG_STACKTRACE
79173 {
79174 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
79175 * Merge control. If this is set then no merging of slab caches will occur.
79176 * (Could be removed. This was introduced to pacify the merge skeptics.)
79177 */
79178 -static int slub_nomerge;
79179 +static int slub_nomerge = 1;
79180
79181 /*
79182 * Calculate the order of allocation given an slab object size.
79183 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
79184 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
79185 #endif
79186
79187 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79188 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
79189 +#endif
79190 +
79191 static int __init setup_slub_min_order(char *str)
79192 {
79193 get_option(&str, &slub_min_order);
79194 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
79195 return kmalloc_dma_caches[index];
79196
79197 #endif
79198 +
79199 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79200 + if (flags & SLAB_USERCOPY)
79201 + return kmalloc_usercopy_caches[index];
79202 +
79203 +#endif
79204 +
79205 return kmalloc_caches[index];
79206 }
79207
79208 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
79209 EXPORT_SYMBOL(__kmalloc_node);
79210 #endif
79211
79212 +bool is_usercopy_object(const void *ptr)
79213 +{
79214 + struct page *page;
79215 + struct kmem_cache *s;
79216 +
79217 + if (ZERO_OR_NULL_PTR(ptr))
79218 + return false;
79219 +
79220 + if (!slab_is_available())
79221 + return false;
79222 +
79223 + if (!virt_addr_valid(ptr))
79224 + return false;
79225 +
79226 + page = virt_to_head_page(ptr);
79227 +
79228 + if (!PageSlab(page))
79229 + return false;
79230 +
79231 + s = page->slab_cache;
79232 + return s->flags & SLAB_USERCOPY;
79233 +}
79234 +
79235 +#ifdef CONFIG_PAX_USERCOPY
79236 +const char *check_heap_object(const void *ptr, unsigned long n)
79237 +{
79238 + struct page *page;
79239 + struct kmem_cache *s;
79240 + unsigned long offset;
79241 +
79242 + if (ZERO_OR_NULL_PTR(ptr))
79243 + return "<null>";
79244 +
79245 + if (!virt_addr_valid(ptr))
79246 + return NULL;
79247 +
79248 + page = virt_to_head_page(ptr);
79249 +
79250 + if (!PageSlab(page))
79251 + return NULL;
79252 +
79253 + s = page->slab_cache;
79254 + if (!(s->flags & SLAB_USERCOPY))
79255 + return s->name;
79256 +
79257 + offset = (ptr - page_address(page)) % s->size;
79258 + if (offset <= s->object_size && n <= s->object_size - offset)
79259 + return NULL;
79260 +
79261 + return s->name;
79262 +}
79263 +#endif
79264 +
79265 size_t ksize(const void *object)
79266 {
79267 struct page *page;
79268 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
79269
79270 /* Caches that are not of the two-to-the-power-of size */
79271 if (KMALLOC_MIN_SIZE <= 32) {
79272 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
79273 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
79274 caches++;
79275 }
79276
79277 if (KMALLOC_MIN_SIZE <= 64) {
79278 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
79279 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
79280 caches++;
79281 }
79282
79283 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
79284 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
79285 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
79286 caches++;
79287 }
79288
79289 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
79290 }
79291 }
79292 #endif
79293 +
79294 +#ifdef CONFIG_PAX_USERCOPY_SLABS
79295 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
79296 + struct kmem_cache *s = kmalloc_caches[i];
79297 +
79298 + if (s && s->size) {
79299 + char *name = kasprintf(GFP_NOWAIT,
79300 + "usercopy-kmalloc-%d", s->object_size);
79301 +
79302 + BUG_ON(!name);
79303 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
79304 + s->object_size, SLAB_USERCOPY);
79305 + }
79306 + }
79307 +#endif
79308 +
79309 printk(KERN_INFO
79310 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
79311 " CPUs=%d, Nodes=%d\n",
79312 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
79313 /*
79314 * We may have set a slab to be unmergeable during bootstrap.
79315 */
79316 - if (s->refcount < 0)
79317 + if (atomic_read(&s->refcount) < 0)
79318 return 1;
79319
79320 return 0;
79321 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79322
79323 s = find_mergeable(memcg, size, align, flags, name, ctor);
79324 if (s) {
79325 - s->refcount++;
79326 + atomic_inc(&s->refcount);
79327 /*
79328 * Adjust the object sizes so that we clear
79329 * the complete object on kzalloc.
79330 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
79331 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
79332
79333 if (sysfs_slab_alias(s, name)) {
79334 - s->refcount--;
79335 + atomic_dec(&s->refcount);
79336 s = NULL;
79337 }
79338 }
79339 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
79340 return NOTIFY_OK;
79341 }
79342
79343 -static struct notifier_block __cpuinitdata slab_notifier = {
79344 +static struct notifier_block slab_notifier = {
79345 .notifier_call = slab_cpuup_callback
79346 };
79347
79348 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
79349 }
79350 #endif
79351
79352 -#ifdef CONFIG_SYSFS
79353 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79354 static int count_inuse(struct page *page)
79355 {
79356 return page->inuse;
79357 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
79358 validate_slab_cache(kmalloc_caches[9]);
79359 }
79360 #else
79361 -#ifdef CONFIG_SYSFS
79362 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79363 static void resiliency_test(void) {};
79364 #endif
79365 #endif
79366
79367 -#ifdef CONFIG_SYSFS
79368 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79369 enum slab_stat_type {
79370 SL_ALL, /* All slabs */
79371 SL_PARTIAL, /* Only partially allocated slabs */
79372 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
79373
79374 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
79375 {
79376 - return sprintf(buf, "%d\n", s->refcount - 1);
79377 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
79378 }
79379 SLAB_ATTR_RO(aliases);
79380
79381 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
79382 return name;
79383 }
79384
79385 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79386 static int sysfs_slab_add(struct kmem_cache *s)
79387 {
79388 int err;
79389 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
79390 kobject_del(&s->kobj);
79391 kobject_put(&s->kobj);
79392 }
79393 +#endif
79394
79395 /*
79396 * Need to buffer aliases during bootup until sysfs becomes
79397 @@ -5336,6 +5418,7 @@ struct saved_alias {
79398
79399 static struct saved_alias *alias_list;
79400
79401 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
79402 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79403 {
79404 struct saved_alias *al;
79405 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
79406 alias_list = al;
79407 return 0;
79408 }
79409 +#endif
79410
79411 static int __init slab_sysfs_init(void)
79412 {
79413 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
79414 index 1b7e22a..3fcd4f3 100644
79415 --- a/mm/sparse-vmemmap.c
79416 +++ b/mm/sparse-vmemmap.c
79417 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
79418 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79419 if (!p)
79420 return NULL;
79421 - pud_populate(&init_mm, pud, p);
79422 + pud_populate_kernel(&init_mm, pud, p);
79423 }
79424 return pud;
79425 }
79426 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
79427 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
79428 if (!p)
79429 return NULL;
79430 - pgd_populate(&init_mm, pgd, p);
79431 + pgd_populate_kernel(&init_mm, pgd, p);
79432 }
79433 return pgd;
79434 }
79435 diff --git a/mm/sparse.c b/mm/sparse.c
79436 index 6b5fb76..db0c190 100644
79437 --- a/mm/sparse.c
79438 +++ b/mm/sparse.c
79439 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
79440
79441 for (i = 0; i < PAGES_PER_SECTION; i++) {
79442 if (PageHWPoison(&memmap[i])) {
79443 - atomic_long_sub(1, &mce_bad_pages);
79444 + atomic_long_sub_unchecked(1, &mce_bad_pages);
79445 ClearPageHWPoison(&memmap[i]);
79446 }
79447 }
79448 diff --git a/mm/swap.c b/mm/swap.c
79449 index 6310dc2..3662b3f 100644
79450 --- a/mm/swap.c
79451 +++ b/mm/swap.c
79452 @@ -30,6 +30,7 @@
79453 #include <linux/backing-dev.h>
79454 #include <linux/memcontrol.h>
79455 #include <linux/gfp.h>
79456 +#include <linux/hugetlb.h>
79457
79458 #include "internal.h"
79459
79460 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
79461
79462 __page_cache_release(page);
79463 dtor = get_compound_page_dtor(page);
79464 + if (!PageHuge(page))
79465 + BUG_ON(dtor != free_compound_page);
79466 (*dtor)(page);
79467 }
79468
79469 diff --git a/mm/swapfile.c b/mm/swapfile.c
79470 index e97a0e5..b50e796 100644
79471 --- a/mm/swapfile.c
79472 +++ b/mm/swapfile.c
79473 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
79474
79475 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
79476 /* Activity counter to indicate that a swapon or swapoff has occurred */
79477 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
79478 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
79479
79480 static inline unsigned char swap_count(unsigned char ent)
79481 {
79482 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
79483 }
79484 filp_close(swap_file, NULL);
79485 err = 0;
79486 - atomic_inc(&proc_poll_event);
79487 + atomic_inc_unchecked(&proc_poll_event);
79488 wake_up_interruptible(&proc_poll_wait);
79489
79490 out_dput:
79491 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
79492
79493 poll_wait(file, &proc_poll_wait, wait);
79494
79495 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
79496 - seq->poll_event = atomic_read(&proc_poll_event);
79497 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
79498 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79499 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
79500 }
79501
79502 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
79503 return ret;
79504
79505 seq = file->private_data;
79506 - seq->poll_event = atomic_read(&proc_poll_event);
79507 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
79508 return 0;
79509 }
79510
79511 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
79512 (frontswap_map) ? "FS" : "");
79513
79514 mutex_unlock(&swapon_mutex);
79515 - atomic_inc(&proc_poll_event);
79516 + atomic_inc_unchecked(&proc_poll_event);
79517 wake_up_interruptible(&proc_poll_wait);
79518
79519 if (S_ISREG(inode->i_mode))
79520 diff --git a/mm/util.c b/mm/util.c
79521 index c55e26b..3f913a9 100644
79522 --- a/mm/util.c
79523 +++ b/mm/util.c
79524 @@ -292,6 +292,12 @@ done:
79525 void arch_pick_mmap_layout(struct mm_struct *mm)
79526 {
79527 mm->mmap_base = TASK_UNMAPPED_BASE;
79528 +
79529 +#ifdef CONFIG_PAX_RANDMMAP
79530 + if (mm->pax_flags & MF_PAX_RANDMMAP)
79531 + mm->mmap_base += mm->delta_mmap;
79532 +#endif
79533 +
79534 mm->get_unmapped_area = arch_get_unmapped_area;
79535 mm->unmap_area = arch_unmap_area;
79536 }
79537 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
79538 index 5123a16..f234a48 100644
79539 --- a/mm/vmalloc.c
79540 +++ b/mm/vmalloc.c
79541 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
79542
79543 pte = pte_offset_kernel(pmd, addr);
79544 do {
79545 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79546 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79547 +
79548 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79549 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
79550 + BUG_ON(!pte_exec(*pte));
79551 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
79552 + continue;
79553 + }
79554 +#endif
79555 +
79556 + {
79557 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
79558 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
79559 + }
79560 } while (pte++, addr += PAGE_SIZE, addr != end);
79561 }
79562
79563 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
79564 pte = pte_alloc_kernel(pmd, addr);
79565 if (!pte)
79566 return -ENOMEM;
79567 +
79568 + pax_open_kernel();
79569 do {
79570 struct page *page = pages[*nr];
79571
79572 - if (WARN_ON(!pte_none(*pte)))
79573 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79574 + if (pgprot_val(prot) & _PAGE_NX)
79575 +#endif
79576 +
79577 + if (!pte_none(*pte)) {
79578 + pax_close_kernel();
79579 + WARN_ON(1);
79580 return -EBUSY;
79581 - if (WARN_ON(!page))
79582 + }
79583 + if (!page) {
79584 + pax_close_kernel();
79585 + WARN_ON(1);
79586 return -ENOMEM;
79587 + }
79588 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
79589 (*nr)++;
79590 } while (pte++, addr += PAGE_SIZE, addr != end);
79591 + pax_close_kernel();
79592 return 0;
79593 }
79594
79595 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
79596 pmd_t *pmd;
79597 unsigned long next;
79598
79599 - pmd = pmd_alloc(&init_mm, pud, addr);
79600 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
79601 if (!pmd)
79602 return -ENOMEM;
79603 do {
79604 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
79605 pud_t *pud;
79606 unsigned long next;
79607
79608 - pud = pud_alloc(&init_mm, pgd, addr);
79609 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
79610 if (!pud)
79611 return -ENOMEM;
79612 do {
79613 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
79614 * and fall back on vmalloc() if that fails. Others
79615 * just put it in the vmalloc space.
79616 */
79617 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
79618 +#ifdef CONFIG_MODULES
79619 +#ifdef MODULES_VADDR
79620 unsigned long addr = (unsigned long)x;
79621 if (addr >= MODULES_VADDR && addr < MODULES_END)
79622 return 1;
79623 #endif
79624 +
79625 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
79626 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
79627 + return 1;
79628 +#endif
79629 +
79630 +#endif
79631 +
79632 return is_vmalloc_addr(x);
79633 }
79634
79635 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
79636
79637 if (!pgd_none(*pgd)) {
79638 pud_t *pud = pud_offset(pgd, addr);
79639 +#ifdef CONFIG_X86
79640 + if (!pud_large(*pud))
79641 +#endif
79642 if (!pud_none(*pud)) {
79643 pmd_t *pmd = pmd_offset(pud, addr);
79644 +#ifdef CONFIG_X86
79645 + if (!pmd_large(*pmd))
79646 +#endif
79647 if (!pmd_none(*pmd)) {
79648 pte_t *ptep, pte;
79649
79650 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
79651 * Allocate a region of KVA of the specified size and alignment, within the
79652 * vstart and vend.
79653 */
79654 -static struct vmap_area *alloc_vmap_area(unsigned long size,
79655 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
79656 unsigned long align,
79657 unsigned long vstart, unsigned long vend,
79658 int node, gfp_t gfp_mask)
79659 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
79660 struct vm_struct *area;
79661
79662 BUG_ON(in_interrupt());
79663 +
79664 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79665 + if (flags & VM_KERNEXEC) {
79666 + if (start != VMALLOC_START || end != VMALLOC_END)
79667 + return NULL;
79668 + start = (unsigned long)MODULES_EXEC_VADDR;
79669 + end = (unsigned long)MODULES_EXEC_END;
79670 + }
79671 +#endif
79672 +
79673 if (flags & VM_IOREMAP) {
79674 int bit = fls(size);
79675
79676 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
79677 if (count > totalram_pages)
79678 return NULL;
79679
79680 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79681 + if (!(pgprot_val(prot) & _PAGE_NX))
79682 + flags |= VM_KERNEXEC;
79683 +#endif
79684 +
79685 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
79686 __builtin_return_address(0));
79687 if (!area)
79688 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
79689 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
79690 goto fail;
79691
79692 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
79693 + if (!(pgprot_val(prot) & _PAGE_NX))
79694 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
79695 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
79696 + else
79697 +#endif
79698 +
79699 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
79700 start, end, node, gfp_mask, caller);
79701 if (!area)
79702 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
79703 * For tight control over page level allocator and protection flags
79704 * use __vmalloc() instead.
79705 */
79706 -
79707 void *vmalloc_exec(unsigned long size)
79708 {
79709 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
79710 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
79711 -1, __builtin_return_address(0));
79712 }
79713
79714 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
79715 unsigned long uaddr = vma->vm_start;
79716 unsigned long usize = vma->vm_end - vma->vm_start;
79717
79718 + BUG_ON(vma->vm_mirror);
79719 +
79720 if ((PAGE_SIZE-1) & (unsigned long)addr)
79721 return -EINVAL;
79722
79723 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
79724 v->addr, v->addr + v->size, v->size);
79725
79726 if (v->caller)
79727 +#ifdef CONFIG_GRKERNSEC_HIDESYM
79728 + seq_printf(m, " %pK", v->caller);
79729 +#else
79730 seq_printf(m, " %pS", v->caller);
79731 +#endif
79732
79733 if (v->nr_pages)
79734 seq_printf(m, " pages=%d", v->nr_pages);
79735 diff --git a/mm/vmstat.c b/mm/vmstat.c
79736 index 9800306..76b4b27 100644
79737 --- a/mm/vmstat.c
79738 +++ b/mm/vmstat.c
79739 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
79740 *
79741 * vm_stat contains the global counters
79742 */
79743 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79744 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
79745 EXPORT_SYMBOL(vm_stat);
79746
79747 #ifdef CONFIG_SMP
79748 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
79749 v = p->vm_stat_diff[i];
79750 p->vm_stat_diff[i] = 0;
79751 local_irq_restore(flags);
79752 - atomic_long_add(v, &zone->vm_stat[i]);
79753 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79754 global_diff[i] += v;
79755 #ifdef CONFIG_NUMA
79756 /* 3 seconds idle till flush */
79757 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
79758
79759 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
79760 if (global_diff[i])
79761 - atomic_long_add(global_diff[i], &vm_stat[i]);
79762 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
79763 }
79764
79765 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79766 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
79767 if (pset->vm_stat_diff[i]) {
79768 int v = pset->vm_stat_diff[i];
79769 pset->vm_stat_diff[i] = 0;
79770 - atomic_long_add(v, &zone->vm_stat[i]);
79771 - atomic_long_add(v, &vm_stat[i]);
79772 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
79773 + atomic_long_add_unchecked(v, &vm_stat[i]);
79774 }
79775 }
79776 #endif
79777 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
79778 return NOTIFY_OK;
79779 }
79780
79781 -static struct notifier_block __cpuinitdata vmstat_notifier =
79782 +static struct notifier_block vmstat_notifier =
79783 { &vmstat_cpuup_callback, NULL, 0 };
79784 #endif
79785
79786 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
79787 start_cpu_timer(cpu);
79788 #endif
79789 #ifdef CONFIG_PROC_FS
79790 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
79791 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
79792 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
79793 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
79794 + {
79795 + mode_t gr_mode = S_IRUGO;
79796 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
79797 + gr_mode = S_IRUSR;
79798 +#endif
79799 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
79800 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
79801 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79802 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
79803 +#else
79804 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
79805 +#endif
79806 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
79807 + }
79808 #endif
79809 return 0;
79810 }
79811 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
79812 index a292e80..785ee68 100644
79813 --- a/net/8021q/vlan.c
79814 +++ b/net/8021q/vlan.c
79815 @@ -485,7 +485,7 @@ out:
79816 return NOTIFY_DONE;
79817 }
79818
79819 -static struct notifier_block vlan_notifier_block __read_mostly = {
79820 +static struct notifier_block vlan_notifier_block = {
79821 .notifier_call = vlan_device_event,
79822 };
79823
79824 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
79825 err = -EPERM;
79826 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
79827 break;
79828 - if ((args.u.name_type >= 0) &&
79829 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
79830 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
79831 struct vlan_net *vn;
79832
79833 vn = net_generic(net, vlan_net_id);
79834 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
79835 index 02efb25..41541a9 100644
79836 --- a/net/9p/trans_fd.c
79837 +++ b/net/9p/trans_fd.c
79838 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
79839 oldfs = get_fs();
79840 set_fs(get_ds());
79841 /* The cast to a user pointer is valid due to the set_fs() */
79842 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
79843 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
79844 set_fs(oldfs);
79845
79846 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
79847 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
79848 index 876fbe8..8bbea9f 100644
79849 --- a/net/atm/atm_misc.c
79850 +++ b/net/atm/atm_misc.c
79851 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
79852 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
79853 return 1;
79854 atm_return(vcc, truesize);
79855 - atomic_inc(&vcc->stats->rx_drop);
79856 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79857 return 0;
79858 }
79859 EXPORT_SYMBOL(atm_charge);
79860 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
79861 }
79862 }
79863 atm_return(vcc, guess);
79864 - atomic_inc(&vcc->stats->rx_drop);
79865 + atomic_inc_unchecked(&vcc->stats->rx_drop);
79866 return NULL;
79867 }
79868 EXPORT_SYMBOL(atm_alloc_charge);
79869 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
79870
79871 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79872 {
79873 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79874 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79875 __SONET_ITEMS
79876 #undef __HANDLE_ITEM
79877 }
79878 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
79879
79880 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
79881 {
79882 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79883 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
79884 __SONET_ITEMS
79885 #undef __HANDLE_ITEM
79886 }
79887 diff --git a/net/atm/lec.h b/net/atm/lec.h
79888 index a86aff9..3a0d6f6 100644
79889 --- a/net/atm/lec.h
79890 +++ b/net/atm/lec.h
79891 @@ -48,7 +48,7 @@ struct lane2_ops {
79892 const u8 *tlvs, u32 sizeoftlvs);
79893 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
79894 const u8 *tlvs, u32 sizeoftlvs);
79895 -};
79896 +} __no_const;
79897
79898 /*
79899 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
79900 diff --git a/net/atm/proc.c b/net/atm/proc.c
79901 index 0d020de..011c7bb 100644
79902 --- a/net/atm/proc.c
79903 +++ b/net/atm/proc.c
79904 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
79905 const struct k_atm_aal_stats *stats)
79906 {
79907 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
79908 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
79909 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
79910 - atomic_read(&stats->rx_drop));
79911 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
79912 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
79913 + atomic_read_unchecked(&stats->rx_drop));
79914 }
79915
79916 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
79917 diff --git a/net/atm/resources.c b/net/atm/resources.c
79918 index 0447d5d..3cf4728 100644
79919 --- a/net/atm/resources.c
79920 +++ b/net/atm/resources.c
79921 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
79922 static void copy_aal_stats(struct k_atm_aal_stats *from,
79923 struct atm_aal_stats *to)
79924 {
79925 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
79926 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
79927 __AAL_STAT_ITEMS
79928 #undef __HANDLE_ITEM
79929 }
79930 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
79931 static void subtract_aal_stats(struct k_atm_aal_stats *from,
79932 struct atm_aal_stats *to)
79933 {
79934 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
79935 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
79936 __AAL_STAT_ITEMS
79937 #undef __HANDLE_ITEM
79938 }
79939 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
79940 index 7d02ebd..4d4cc01 100644
79941 --- a/net/batman-adv/bat_iv_ogm.c
79942 +++ b/net/batman-adv/bat_iv_ogm.c
79943 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
79944
79945 /* randomize initial seqno to avoid collision */
79946 get_random_bytes(&random_seqno, sizeof(random_seqno));
79947 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79948 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
79949
79950 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
79951 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
79952 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
79953 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
79954
79955 /* change sequence number to network order */
79956 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
79957 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
79958 batadv_ogm_packet->seqno = htonl(seqno);
79959 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
79960 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
79961
79962 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
79963 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
79964 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
79965 return;
79966
79967 /* could be changed by schedule_own_packet() */
79968 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
79969 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
79970
79971 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
79972 has_directlink_flag = 1;
79973 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
79974 index f1d37cd..4190879 100644
79975 --- a/net/batman-adv/hard-interface.c
79976 +++ b/net/batman-adv/hard-interface.c
79977 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
79978 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
79979 dev_add_pack(&hard_iface->batman_adv_ptype);
79980
79981 - atomic_set(&hard_iface->frag_seqno, 1);
79982 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
79983 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
79984 hard_iface->net_dev->name);
79985
79986 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
79987 /* This can't be called via a bat_priv callback because
79988 * we have no bat_priv yet.
79989 */
79990 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
79991 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
79992 hard_iface->bat_iv.ogm_buff = NULL;
79993
79994 return hard_iface;
79995 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
79996 index 6b548fd..fc32c8d 100644
79997 --- a/net/batman-adv/soft-interface.c
79998 +++ b/net/batman-adv/soft-interface.c
79999 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
80000 primary_if->net_dev->dev_addr, ETH_ALEN);
80001
80002 /* set broadcast sequence number */
80003 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
80004 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
80005 bcast_packet->seqno = htonl(seqno);
80006
80007 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
80008 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
80009 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
80010
80011 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
80012 - atomic_set(&bat_priv->bcast_seqno, 1);
80013 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
80014 atomic_set(&bat_priv->tt.vn, 0);
80015 atomic_set(&bat_priv->tt.local_changes, 0);
80016 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
80017 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
80018 index ae9ac9a..11e0fe7 100644
80019 --- a/net/batman-adv/types.h
80020 +++ b/net/batman-adv/types.h
80021 @@ -48,7 +48,7 @@
80022 struct batadv_hard_iface_bat_iv {
80023 unsigned char *ogm_buff;
80024 int ogm_buff_len;
80025 - atomic_t ogm_seqno;
80026 + atomic_unchecked_t ogm_seqno;
80027 };
80028
80029 struct batadv_hard_iface {
80030 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
80031 int16_t if_num;
80032 char if_status;
80033 struct net_device *net_dev;
80034 - atomic_t frag_seqno;
80035 + atomic_unchecked_t frag_seqno;
80036 struct kobject *hardif_obj;
80037 atomic_t refcount;
80038 struct packet_type batman_adv_ptype;
80039 @@ -284,7 +284,7 @@ struct batadv_priv {
80040 atomic_t orig_interval; /* uint */
80041 atomic_t hop_penalty; /* uint */
80042 atomic_t log_level; /* uint */
80043 - atomic_t bcast_seqno;
80044 + atomic_unchecked_t bcast_seqno;
80045 atomic_t bcast_queue_left;
80046 atomic_t batman_queue_left;
80047 char num_ifaces;
80048 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
80049 index 10aff49..ea8e021 100644
80050 --- a/net/batman-adv/unicast.c
80051 +++ b/net/batman-adv/unicast.c
80052 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
80053 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
80054 frag2->flags = large_tail;
80055
80056 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
80057 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
80058 frag1->seqno = htons(seqno - 1);
80059 frag2->seqno = htons(seqno);
80060
80061 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
80062 index 07f0739..3c42e34 100644
80063 --- a/net/bluetooth/hci_sock.c
80064 +++ b/net/bluetooth/hci_sock.c
80065 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
80066 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
80067 }
80068
80069 - len = min_t(unsigned int, len, sizeof(uf));
80070 + len = min((size_t)len, sizeof(uf));
80071 if (copy_from_user(&uf, optval, len)) {
80072 err = -EFAULT;
80073 break;
80074 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
80075 index 22e6583..426e2f3 100644
80076 --- a/net/bluetooth/l2cap_core.c
80077 +++ b/net/bluetooth/l2cap_core.c
80078 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
80079 break;
80080
80081 case L2CAP_CONF_RFC:
80082 - if (olen == sizeof(rfc))
80083 - memcpy(&rfc, (void *)val, olen);
80084 + if (olen != sizeof(rfc))
80085 + break;
80086 +
80087 + memcpy(&rfc, (void *)val, olen);
80088
80089 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
80090 rfc.mode != chan->mode)
80091 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
80092 index 1bcfb84..dad9f98 100644
80093 --- a/net/bluetooth/l2cap_sock.c
80094 +++ b/net/bluetooth/l2cap_sock.c
80095 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
80096 struct sock *sk = sock->sk;
80097 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
80098 struct l2cap_options opts;
80099 - int len, err = 0;
80100 + int err = 0;
80101 + size_t len = optlen;
80102 u32 opt;
80103
80104 BT_DBG("sk %p", sk);
80105 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
80106 opts.max_tx = chan->max_tx;
80107 opts.txwin_size = chan->tx_win;
80108
80109 - len = min_t(unsigned int, sizeof(opts), optlen);
80110 + len = min(sizeof(opts), len);
80111 if (copy_from_user((char *) &opts, optval, len)) {
80112 err = -EFAULT;
80113 break;
80114 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80115 struct bt_security sec;
80116 struct bt_power pwr;
80117 struct l2cap_conn *conn;
80118 - int len, err = 0;
80119 + int err = 0;
80120 + size_t len = optlen;
80121 u32 opt;
80122
80123 BT_DBG("sk %p", sk);
80124 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80125
80126 sec.level = BT_SECURITY_LOW;
80127
80128 - len = min_t(unsigned int, sizeof(sec), optlen);
80129 + len = min(sizeof(sec), len);
80130 if (copy_from_user((char *) &sec, optval, len)) {
80131 err = -EFAULT;
80132 break;
80133 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
80134
80135 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
80136
80137 - len = min_t(unsigned int, sizeof(pwr), optlen);
80138 + len = min(sizeof(pwr), len);
80139 if (copy_from_user((char *) &pwr, optval, len)) {
80140 err = -EFAULT;
80141 break;
80142 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
80143 index ce3f665..2c7d08f 100644
80144 --- a/net/bluetooth/rfcomm/sock.c
80145 +++ b/net/bluetooth/rfcomm/sock.c
80146 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
80147 struct sock *sk = sock->sk;
80148 struct bt_security sec;
80149 int err = 0;
80150 - size_t len;
80151 + size_t len = optlen;
80152 u32 opt;
80153
80154 BT_DBG("sk %p", sk);
80155 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
80156
80157 sec.level = BT_SECURITY_LOW;
80158
80159 - len = min_t(unsigned int, sizeof(sec), optlen);
80160 + len = min(sizeof(sec), len);
80161 if (copy_from_user((char *) &sec, optval, len)) {
80162 err = -EFAULT;
80163 break;
80164 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
80165 index bd6fd0f..6492cba 100644
80166 --- a/net/bluetooth/rfcomm/tty.c
80167 +++ b/net/bluetooth/rfcomm/tty.c
80168 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
80169 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
80170
80171 spin_lock_irqsave(&dev->port.lock, flags);
80172 - if (dev->port.count > 0) {
80173 + if (atomic_read(&dev->port.count) > 0) {
80174 spin_unlock_irqrestore(&dev->port.lock, flags);
80175 return;
80176 }
80177 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
80178 return -ENODEV;
80179
80180 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
80181 - dev->channel, dev->port.count);
80182 + dev->channel, atomic_read(&dev->port.count));
80183
80184 spin_lock_irqsave(&dev->port.lock, flags);
80185 - if (++dev->port.count > 1) {
80186 + if (atomic_inc_return(&dev->port.count) > 1) {
80187 spin_unlock_irqrestore(&dev->port.lock, flags);
80188 return 0;
80189 }
80190 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
80191 return;
80192
80193 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
80194 - dev->port.count);
80195 + atomic_read(&dev->port.count));
80196
80197 spin_lock_irqsave(&dev->port.lock, flags);
80198 - if (!--dev->port.count) {
80199 + if (!atomic_dec_return(&dev->port.count)) {
80200 spin_unlock_irqrestore(&dev->port.lock, flags);
80201 if (dev->tty_dev->parent)
80202 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
80203 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
80204 index 5fe2ff3..121d696 100644
80205 --- a/net/bridge/netfilter/ebtables.c
80206 +++ b/net/bridge/netfilter/ebtables.c
80207 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
80208 tmp.valid_hooks = t->table->valid_hooks;
80209 }
80210 mutex_unlock(&ebt_mutex);
80211 - if (copy_to_user(user, &tmp, *len) != 0){
80212 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
80213 BUGPRINT("c2u Didn't work\n");
80214 ret = -EFAULT;
80215 break;
80216 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
80217 goto out;
80218 tmp.valid_hooks = t->valid_hooks;
80219
80220 - if (copy_to_user(user, &tmp, *len) != 0) {
80221 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
80222 ret = -EFAULT;
80223 break;
80224 }
80225 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
80226 tmp.entries_size = t->table->entries_size;
80227 tmp.valid_hooks = t->table->valid_hooks;
80228
80229 - if (copy_to_user(user, &tmp, *len) != 0) {
80230 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
80231 ret = -EFAULT;
80232 break;
80233 }
80234 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
80235 index a376ec1..1fbd6be 100644
80236 --- a/net/caif/cfctrl.c
80237 +++ b/net/caif/cfctrl.c
80238 @@ -10,6 +10,7 @@
80239 #include <linux/spinlock.h>
80240 #include <linux/slab.h>
80241 #include <linux/pkt_sched.h>
80242 +#include <linux/sched.h>
80243 #include <net/caif/caif_layer.h>
80244 #include <net/caif/cfpkt.h>
80245 #include <net/caif/cfctrl.h>
80246 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
80247 memset(&dev_info, 0, sizeof(dev_info));
80248 dev_info.id = 0xff;
80249 cfsrvl_init(&this->serv, 0, &dev_info, false);
80250 - atomic_set(&this->req_seq_no, 1);
80251 - atomic_set(&this->rsp_seq_no, 1);
80252 + atomic_set_unchecked(&this->req_seq_no, 1);
80253 + atomic_set_unchecked(&this->rsp_seq_no, 1);
80254 this->serv.layer.receive = cfctrl_recv;
80255 sprintf(this->serv.layer.name, "ctrl");
80256 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
80257 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
80258 struct cfctrl_request_info *req)
80259 {
80260 spin_lock_bh(&ctrl->info_list_lock);
80261 - atomic_inc(&ctrl->req_seq_no);
80262 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
80263 + atomic_inc_unchecked(&ctrl->req_seq_no);
80264 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
80265 list_add_tail(&req->list, &ctrl->list);
80266 spin_unlock_bh(&ctrl->info_list_lock);
80267 }
80268 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
80269 if (p != first)
80270 pr_warn("Requests are not received in order\n");
80271
80272 - atomic_set(&ctrl->rsp_seq_no,
80273 + atomic_set_unchecked(&ctrl->rsp_seq_no,
80274 p->sequence_no);
80275 list_del(&p->list);
80276 goto out;
80277 diff --git a/net/can/af_can.c b/net/can/af_can.c
80278 index ddac1ee..3ee0a78 100644
80279 --- a/net/can/af_can.c
80280 +++ b/net/can/af_can.c
80281 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
80282 };
80283
80284 /* notifier block for netdevice event */
80285 -static struct notifier_block can_netdev_notifier __read_mostly = {
80286 +static struct notifier_block can_netdev_notifier = {
80287 .notifier_call = can_notifier,
80288 };
80289
80290 diff --git a/net/can/gw.c b/net/can/gw.c
80291 index 574dda78e..3d2b3da 100644
80292 --- a/net/can/gw.c
80293 +++ b/net/can/gw.c
80294 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
80295 MODULE_ALIAS("can-gw");
80296
80297 static HLIST_HEAD(cgw_list);
80298 -static struct notifier_block notifier;
80299
80300 static struct kmem_cache *cgw_cache __read_mostly;
80301
80302 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
80303 return err;
80304 }
80305
80306 +static struct notifier_block notifier = {
80307 + .notifier_call = cgw_notifier
80308 +};
80309 +
80310 static __init int cgw_module_init(void)
80311 {
80312 printk(banner);
80313 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
80314 return -ENOMEM;
80315
80316 /* set notifier */
80317 - notifier.notifier_call = cgw_notifier;
80318 register_netdevice_notifier(&notifier);
80319
80320 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
80321 diff --git a/net/compat.c b/net/compat.c
80322 index 79ae884..17c5c09 100644
80323 --- a/net/compat.c
80324 +++ b/net/compat.c
80325 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
80326 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
80327 __get_user(kmsg->msg_flags, &umsg->msg_flags))
80328 return -EFAULT;
80329 - kmsg->msg_name = compat_ptr(tmp1);
80330 - kmsg->msg_iov = compat_ptr(tmp2);
80331 - kmsg->msg_control = compat_ptr(tmp3);
80332 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
80333 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
80334 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
80335 return 0;
80336 }
80337
80338 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80339
80340 if (kern_msg->msg_namelen) {
80341 if (mode == VERIFY_READ) {
80342 - int err = move_addr_to_kernel(kern_msg->msg_name,
80343 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
80344 kern_msg->msg_namelen,
80345 kern_address);
80346 if (err < 0)
80347 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80348 kern_msg->msg_name = NULL;
80349
80350 tot_len = iov_from_user_compat_to_kern(kern_iov,
80351 - (struct compat_iovec __user *)kern_msg->msg_iov,
80352 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
80353 kern_msg->msg_iovlen);
80354 if (tot_len >= 0)
80355 kern_msg->msg_iov = kern_iov;
80356 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
80357
80358 #define CMSG_COMPAT_FIRSTHDR(msg) \
80359 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
80360 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
80361 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
80362 (struct compat_cmsghdr __user *)NULL)
80363
80364 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
80365 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
80366 (ucmlen) <= (unsigned long) \
80367 ((mhdr)->msg_controllen - \
80368 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
80369 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
80370
80371 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
80372 struct compat_cmsghdr __user *cmsg, int cmsg_len)
80373 {
80374 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
80375 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
80376 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
80377 msg->msg_controllen)
80378 return NULL;
80379 return (struct compat_cmsghdr __user *)ptr;
80380 @@ -219,7 +219,7 @@ Efault:
80381
80382 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
80383 {
80384 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80385 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80386 struct compat_cmsghdr cmhdr;
80387 struct compat_timeval ctv;
80388 struct compat_timespec cts[3];
80389 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
80390
80391 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
80392 {
80393 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
80394 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
80395 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
80396 int fdnum = scm->fp->count;
80397 struct file **fp = scm->fp->fp;
80398 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
80399 return -EFAULT;
80400 old_fs = get_fs();
80401 set_fs(KERNEL_DS);
80402 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
80403 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
80404 set_fs(old_fs);
80405
80406 return err;
80407 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
80408 len = sizeof(ktime);
80409 old_fs = get_fs();
80410 set_fs(KERNEL_DS);
80411 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
80412 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
80413 set_fs(old_fs);
80414
80415 if (!err) {
80416 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80417 case MCAST_JOIN_GROUP:
80418 case MCAST_LEAVE_GROUP:
80419 {
80420 - struct compat_group_req __user *gr32 = (void *)optval;
80421 + struct compat_group_req __user *gr32 = (void __user *)optval;
80422 struct group_req __user *kgr =
80423 compat_alloc_user_space(sizeof(struct group_req));
80424 u32 interface;
80425 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80426 case MCAST_BLOCK_SOURCE:
80427 case MCAST_UNBLOCK_SOURCE:
80428 {
80429 - struct compat_group_source_req __user *gsr32 = (void *)optval;
80430 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
80431 struct group_source_req __user *kgsr = compat_alloc_user_space(
80432 sizeof(struct group_source_req));
80433 u32 interface;
80434 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
80435 }
80436 case MCAST_MSFILTER:
80437 {
80438 - struct compat_group_filter __user *gf32 = (void *)optval;
80439 + struct compat_group_filter __user *gf32 = (void __user *)optval;
80440 struct group_filter __user *kgf;
80441 u32 interface, fmode, numsrc;
80442
80443 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
80444 char __user *optval, int __user *optlen,
80445 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
80446 {
80447 - struct compat_group_filter __user *gf32 = (void *)optval;
80448 + struct compat_group_filter __user *gf32 = (void __user *)optval;
80449 struct group_filter __user *kgf;
80450 int __user *koptlen;
80451 u32 interface, fmode, numsrc;
80452 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
80453
80454 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
80455 return -EINVAL;
80456 - if (copy_from_user(a, args, nas[call]))
80457 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
80458 return -EFAULT;
80459 a0 = a[0];
80460 a1 = a[1];
80461 diff --git a/net/core/datagram.c b/net/core/datagram.c
80462 index 368f9c3..f82d4a3 100644
80463 --- a/net/core/datagram.c
80464 +++ b/net/core/datagram.c
80465 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
80466 }
80467
80468 kfree_skb(skb);
80469 - atomic_inc(&sk->sk_drops);
80470 + atomic_inc_unchecked(&sk->sk_drops);
80471 sk_mem_reclaim_partial(sk);
80472
80473 return err;
80474 diff --git a/net/core/dev.c b/net/core/dev.c
80475 index f64e439..8f959e6 100644
80476 --- a/net/core/dev.c
80477 +++ b/net/core/dev.c
80478 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
80479 if (no_module && capable(CAP_NET_ADMIN))
80480 no_module = request_module("netdev-%s", name);
80481 if (no_module && capable(CAP_SYS_MODULE)) {
80482 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
80483 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
80484 +#else
80485 if (!request_module("%s", name))
80486 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
80487 name);
80488 +#endif
80489 }
80490 }
80491 EXPORT_SYMBOL(dev_load);
80492 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80493 {
80494 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
80495 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
80496 - atomic_long_inc(&dev->rx_dropped);
80497 + atomic_long_inc_unchecked(&dev->rx_dropped);
80498 kfree_skb(skb);
80499 return NET_RX_DROP;
80500 }
80501 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
80502 nf_reset(skb);
80503
80504 if (unlikely(!is_skb_forwardable(dev, skb))) {
80505 - atomic_long_inc(&dev->rx_dropped);
80506 + atomic_long_inc_unchecked(&dev->rx_dropped);
80507 kfree_skb(skb);
80508 return NET_RX_DROP;
80509 }
80510 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
80511
80512 struct dev_gso_cb {
80513 void (*destructor)(struct sk_buff *skb);
80514 -};
80515 +} __no_const;
80516
80517 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
80518
80519 @@ -3053,7 +3057,7 @@ enqueue:
80520
80521 local_irq_restore(flags);
80522
80523 - atomic_long_inc(&skb->dev->rx_dropped);
80524 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80525 kfree_skb(skb);
80526 return NET_RX_DROP;
80527 }
80528 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
80529 }
80530 EXPORT_SYMBOL(netif_rx_ni);
80531
80532 -static void net_tx_action(struct softirq_action *h)
80533 +static void net_tx_action(void)
80534 {
80535 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80536
80537 @@ -3456,7 +3460,7 @@ ncls:
80538 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
80539 } else {
80540 drop:
80541 - atomic_long_inc(&skb->dev->rx_dropped);
80542 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
80543 kfree_skb(skb);
80544 /* Jamal, now you will not able to escape explaining
80545 * me how you were going to use this. :-)
80546 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
80547 }
80548 EXPORT_SYMBOL(netif_napi_del);
80549
80550 -static void net_rx_action(struct softirq_action *h)
80551 +static void net_rx_action(void)
80552 {
80553 struct softnet_data *sd = &__get_cpu_var(softnet_data);
80554 unsigned long time_limit = jiffies + 2;
80555 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
80556 else
80557 seq_printf(seq, "%04x", ntohs(pt->type));
80558
80559 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80560 + seq_printf(seq, " %-8s %p\n",
80561 + pt->dev ? pt->dev->name : "", NULL);
80562 +#else
80563 seq_printf(seq, " %-8s %pF\n",
80564 pt->dev ? pt->dev->name : "", pt->func);
80565 +#endif
80566 }
80567
80568 return 0;
80569 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
80570 } else {
80571 netdev_stats_to_stats64(storage, &dev->stats);
80572 }
80573 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
80574 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
80575 return storage;
80576 }
80577 EXPORT_SYMBOL(dev_get_stats);
80578 diff --git a/net/core/flow.c b/net/core/flow.c
80579 index b0901ee..7d3c2ca 100644
80580 --- a/net/core/flow.c
80581 +++ b/net/core/flow.c
80582 @@ -61,7 +61,7 @@ struct flow_cache {
80583 struct timer_list rnd_timer;
80584 };
80585
80586 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
80587 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
80588 EXPORT_SYMBOL(flow_cache_genid);
80589 static struct flow_cache flow_cache_global;
80590 static struct kmem_cache *flow_cachep __read_mostly;
80591 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
80592
80593 static int flow_entry_valid(struct flow_cache_entry *fle)
80594 {
80595 - if (atomic_read(&flow_cache_genid) != fle->genid)
80596 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
80597 return 0;
80598 if (fle->object && !fle->object->ops->check(fle->object))
80599 return 0;
80600 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
80601 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
80602 fcp->hash_count++;
80603 }
80604 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
80605 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
80606 flo = fle->object;
80607 if (!flo)
80608 goto ret_object;
80609 @@ -280,7 +280,7 @@ nocache:
80610 }
80611 flo = resolver(net, key, family, dir, flo, ctx);
80612 if (fle) {
80613 - fle->genid = atomic_read(&flow_cache_genid);
80614 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
80615 if (!IS_ERR(flo))
80616 fle->object = flo;
80617 else
80618 diff --git a/net/core/iovec.c b/net/core/iovec.c
80619 index 7e7aeb0..2a998cb 100644
80620 --- a/net/core/iovec.c
80621 +++ b/net/core/iovec.c
80622 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80623 if (m->msg_namelen) {
80624 if (mode == VERIFY_READ) {
80625 void __user *namep;
80626 - namep = (void __user __force *) m->msg_name;
80627 + namep = (void __force_user *) m->msg_name;
80628 err = move_addr_to_kernel(namep, m->msg_namelen,
80629 address);
80630 if (err < 0)
80631 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
80632 }
80633
80634 size = m->msg_iovlen * sizeof(struct iovec);
80635 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
80636 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
80637 return -EFAULT;
80638
80639 m->msg_iov = iov;
80640 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
80641 index 1868625..5f4de62 100644
80642 --- a/net/core/rtnetlink.c
80643 +++ b/net/core/rtnetlink.c
80644 @@ -58,7 +58,7 @@ struct rtnl_link {
80645 rtnl_doit_func doit;
80646 rtnl_dumpit_func dumpit;
80647 rtnl_calcit_func calcit;
80648 -};
80649 +} __no_const;
80650
80651 static DEFINE_MUTEX(rtnl_mutex);
80652
80653 diff --git a/net/core/scm.c b/net/core/scm.c
80654 index 905dcc6..14ee2d6 100644
80655 --- a/net/core/scm.c
80656 +++ b/net/core/scm.c
80657 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
80658 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80659 {
80660 struct cmsghdr __user *cm
80661 - = (__force struct cmsghdr __user *)msg->msg_control;
80662 + = (struct cmsghdr __force_user *)msg->msg_control;
80663 struct cmsghdr cmhdr;
80664 int cmlen = CMSG_LEN(len);
80665 int err;
80666 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
80667 err = -EFAULT;
80668 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
80669 goto out;
80670 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
80671 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
80672 goto out;
80673 cmlen = CMSG_SPACE(len);
80674 if (msg->msg_controllen < cmlen)
80675 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
80676 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80677 {
80678 struct cmsghdr __user *cm
80679 - = (__force struct cmsghdr __user*)msg->msg_control;
80680 + = (struct cmsghdr __force_user *)msg->msg_control;
80681
80682 int fdmax = 0;
80683 int fdnum = scm->fp->count;
80684 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
80685 if (fdnum < fdmax)
80686 fdmax = fdnum;
80687
80688 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
80689 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
80690 i++, cmfptr++)
80691 {
80692 struct socket *sock;
80693 diff --git a/net/core/sock.c b/net/core/sock.c
80694 index bc131d4..029e378 100644
80695 --- a/net/core/sock.c
80696 +++ b/net/core/sock.c
80697 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80698 struct sk_buff_head *list = &sk->sk_receive_queue;
80699
80700 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
80701 - atomic_inc(&sk->sk_drops);
80702 + atomic_inc_unchecked(&sk->sk_drops);
80703 trace_sock_rcvqueue_full(sk, skb);
80704 return -ENOMEM;
80705 }
80706 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80707 return err;
80708
80709 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
80710 - atomic_inc(&sk->sk_drops);
80711 + atomic_inc_unchecked(&sk->sk_drops);
80712 return -ENOBUFS;
80713 }
80714
80715 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80716 skb_dst_force(skb);
80717
80718 spin_lock_irqsave(&list->lock, flags);
80719 - skb->dropcount = atomic_read(&sk->sk_drops);
80720 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
80721 __skb_queue_tail(list, skb);
80722 spin_unlock_irqrestore(&list->lock, flags);
80723
80724 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80725 skb->dev = NULL;
80726
80727 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
80728 - atomic_inc(&sk->sk_drops);
80729 + atomic_inc_unchecked(&sk->sk_drops);
80730 goto discard_and_relse;
80731 }
80732 if (nested)
80733 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
80734 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
80735 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
80736 bh_unlock_sock(sk);
80737 - atomic_inc(&sk->sk_drops);
80738 + atomic_inc_unchecked(&sk->sk_drops);
80739 goto discard_and_relse;
80740 }
80741
80742 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80743 struct timeval tm;
80744 } v;
80745
80746 - int lv = sizeof(int);
80747 - int len;
80748 + unsigned int lv = sizeof(int);
80749 + unsigned int len;
80750
80751 if (get_user(len, optlen))
80752 return -EFAULT;
80753 - if (len < 0)
80754 + if (len > INT_MAX)
80755 return -EINVAL;
80756
80757 memset(&v, 0, sizeof(v));
80758 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80759
80760 case SO_PEERNAME:
80761 {
80762 - char address[128];
80763 + char address[_K_SS_MAXSIZE];
80764
80765 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
80766 return -ENOTCONN;
80767 - if (lv < len)
80768 + if (lv < len || sizeof address < len)
80769 return -EINVAL;
80770 if (copy_to_user(optval, address, len))
80771 return -EFAULT;
80772 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
80773
80774 if (len > lv)
80775 len = lv;
80776 - if (copy_to_user(optval, &v, len))
80777 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
80778 return -EFAULT;
80779 lenout:
80780 if (put_user(len, optlen))
80781 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
80782 */
80783 smp_wmb();
80784 atomic_set(&sk->sk_refcnt, 1);
80785 - atomic_set(&sk->sk_drops, 0);
80786 + atomic_set_unchecked(&sk->sk_drops, 0);
80787 }
80788 EXPORT_SYMBOL(sock_init_data);
80789
80790 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
80791 index 602cd63..0a699b1 100644
80792 --- a/net/core/sock_diag.c
80793 +++ b/net/core/sock_diag.c
80794 @@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
80795
80796 int sock_diag_check_cookie(void *sk, __u32 *cookie)
80797 {
80798 +#ifndef CONFIG_GRKERNSEC_HIDESYM
80799 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
80800 cookie[1] != INET_DIAG_NOCOOKIE) &&
80801 ((u32)(unsigned long)sk != cookie[0] ||
80802 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
80803 return -ESTALE;
80804 else
80805 +#endif
80806 return 0;
80807 }
80808 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
80809
80810 void sock_diag_save_cookie(void *sk, __u32 *cookie)
80811 {
80812 +#ifdef CONFIG_GRKERNSEC_HIDESYM
80813 + cookie[0] = 0;
80814 + cookie[1] = 0;
80815 +#else
80816 cookie[0] = (u32)(unsigned long)sk;
80817 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
80818 +#endif
80819 }
80820 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
80821
80822 @@ -97,21 +104,6 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
80823 }
80824 EXPORT_SYMBOL_GPL(sock_diag_unregister);
80825
80826 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
80827 -{
80828 - if (sock_diag_handlers[family] == NULL)
80829 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80830 - NETLINK_SOCK_DIAG, family);
80831 -
80832 - mutex_lock(&sock_diag_table_mutex);
80833 - return sock_diag_handlers[family];
80834 -}
80835 -
80836 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
80837 -{
80838 - mutex_unlock(&sock_diag_table_mutex);
80839 -}
80840 -
80841 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80842 {
80843 int err;
80844 @@ -121,12 +113,20 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
80845 if (nlmsg_len(nlh) < sizeof(*req))
80846 return -EINVAL;
80847
80848 - hndl = sock_diag_lock_handler(req->sdiag_family);
80849 + if (req->sdiag_family >= AF_MAX)
80850 + return -EINVAL;
80851 +
80852 + if (sock_diag_handlers[req->sdiag_family] == NULL)
80853 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
80854 + NETLINK_SOCK_DIAG, req->sdiag_family);
80855 +
80856 + mutex_lock(&sock_diag_table_mutex);
80857 + hndl = sock_diag_handlers[req->sdiag_family];
80858 if (hndl == NULL)
80859 err = -ENOENT;
80860 else
80861 err = hndl->dump(skb, nlh);
80862 - sock_diag_unlock_handler(hndl);
80863 + mutex_unlock(&sock_diag_table_mutex);
80864
80865 return err;
80866 }
80867 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
80868 index a55eecc..dd8428c 100644
80869 --- a/net/decnet/sysctl_net_decnet.c
80870 +++ b/net/decnet/sysctl_net_decnet.c
80871 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
80872
80873 if (len > *lenp) len = *lenp;
80874
80875 - if (copy_to_user(buffer, addr, len))
80876 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
80877 return -EFAULT;
80878
80879 *lenp = len;
80880 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
80881
80882 if (len > *lenp) len = *lenp;
80883
80884 - if (copy_to_user(buffer, devname, len))
80885 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
80886 return -EFAULT;
80887
80888 *lenp = len;
80889 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
80890 index a69b4e4..dbccba5 100644
80891 --- a/net/ipv4/ah4.c
80892 +++ b/net/ipv4/ah4.c
80893 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
80894 return;
80895
80896 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80897 - atomic_inc(&flow_cache_genid);
80898 + atomic_inc_unchecked(&flow_cache_genid);
80899 rt_genid_bump(net);
80900
80901 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
80902 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
80903 index 3b4f0cd..8cb864c 100644
80904 --- a/net/ipv4/esp4.c
80905 +++ b/net/ipv4/esp4.c
80906 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
80907 return;
80908
80909 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
80910 - atomic_inc(&flow_cache_genid);
80911 + atomic_inc_unchecked(&flow_cache_genid);
80912 rt_genid_bump(net);
80913
80914 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
80915 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
80916 index 5cd75e2..f57ef39 100644
80917 --- a/net/ipv4/fib_frontend.c
80918 +++ b/net/ipv4/fib_frontend.c
80919 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
80920 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80921 fib_sync_up(dev);
80922 #endif
80923 - atomic_inc(&net->ipv4.dev_addr_genid);
80924 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80925 rt_cache_flush(dev_net(dev));
80926 break;
80927 case NETDEV_DOWN:
80928 fib_del_ifaddr(ifa, NULL);
80929 - atomic_inc(&net->ipv4.dev_addr_genid);
80930 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80931 if (ifa->ifa_dev->ifa_list == NULL) {
80932 /* Last address was deleted from this interface.
80933 * Disable IP.
80934 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
80935 #ifdef CONFIG_IP_ROUTE_MULTIPATH
80936 fib_sync_up(dev);
80937 #endif
80938 - atomic_inc(&net->ipv4.dev_addr_genid);
80939 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
80940 rt_cache_flush(net);
80941 break;
80942 case NETDEV_DOWN:
80943 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
80944 index 4797a80..2bd54e9 100644
80945 --- a/net/ipv4/fib_semantics.c
80946 +++ b/net/ipv4/fib_semantics.c
80947 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
80948 nh->nh_saddr = inet_select_addr(nh->nh_dev,
80949 nh->nh_gw,
80950 nh->nh_parent->fib_scope);
80951 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
80952 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
80953
80954 return nh->nh_saddr;
80955 }
80956 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
80957 index fa3ae81..0dbe6b8 100644
80958 --- a/net/ipv4/inet_hashtables.c
80959 +++ b/net/ipv4/inet_hashtables.c
80960 @@ -18,12 +18,15 @@
80961 #include <linux/sched.h>
80962 #include <linux/slab.h>
80963 #include <linux/wait.h>
80964 +#include <linux/security.h>
80965
80966 #include <net/inet_connection_sock.h>
80967 #include <net/inet_hashtables.h>
80968 #include <net/secure_seq.h>
80969 #include <net/ip.h>
80970
80971 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
80972 +
80973 /*
80974 * Allocate and initialize a new local port bind bucket.
80975 * The bindhash mutex for snum's hash chain must be held here.
80976 @@ -540,6 +543,8 @@ ok:
80977 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
80978 spin_unlock(&head->lock);
80979
80980 + gr_update_task_in_ip_table(current, inet_sk(sk));
80981 +
80982 if (tw) {
80983 inet_twsk_deschedule(tw, death_row);
80984 while (twrefcnt) {
80985 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
80986 index 000e3d2..5472da3 100644
80987 --- a/net/ipv4/inetpeer.c
80988 +++ b/net/ipv4/inetpeer.c
80989 @@ -503,8 +503,8 @@ relookup:
80990 if (p) {
80991 p->daddr = *daddr;
80992 atomic_set(&p->refcnt, 1);
80993 - atomic_set(&p->rid, 0);
80994 - atomic_set(&p->ip_id_count,
80995 + atomic_set_unchecked(&p->rid, 0);
80996 + atomic_set_unchecked(&p->ip_id_count,
80997 (daddr->family == AF_INET) ?
80998 secure_ip_id(daddr->addr.a4) :
80999 secure_ipv6_id(daddr->addr.a6));
81000 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
81001 index eb9d63a..50babc1 100644
81002 --- a/net/ipv4/ip_fragment.c
81003 +++ b/net/ipv4/ip_fragment.c
81004 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
81005 return 0;
81006
81007 start = qp->rid;
81008 - end = atomic_inc_return(&peer->rid);
81009 + end = atomic_inc_return_unchecked(&peer->rid);
81010 qp->rid = end;
81011
81012 rc = qp->q.fragments && (end - start) > max;
81013 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
81014 index d9c4f11..02b82db 100644
81015 --- a/net/ipv4/ip_sockglue.c
81016 +++ b/net/ipv4/ip_sockglue.c
81017 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
81018 len = min_t(unsigned int, len, opt->optlen);
81019 if (put_user(len, optlen))
81020 return -EFAULT;
81021 - if (copy_to_user(optval, opt->__data, len))
81022 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
81023 + copy_to_user(optval, opt->__data, len))
81024 return -EFAULT;
81025 return 0;
81026 }
81027 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
81028 if (sk->sk_type != SOCK_STREAM)
81029 return -ENOPROTOOPT;
81030
81031 - msg.msg_control = optval;
81032 + msg.msg_control = (void __force_kernel *)optval;
81033 msg.msg_controllen = len;
81034 msg.msg_flags = flags;
81035
81036 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
81037 index 9a46dae..5f793a0 100644
81038 --- a/net/ipv4/ipcomp.c
81039 +++ b/net/ipv4/ipcomp.c
81040 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
81041 return;
81042
81043 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
81044 - atomic_inc(&flow_cache_genid);
81045 + atomic_inc_unchecked(&flow_cache_genid);
81046 rt_genid_bump(net);
81047
81048 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
81049 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
81050 index a2e50ae..e152b7c 100644
81051 --- a/net/ipv4/ipconfig.c
81052 +++ b/net/ipv4/ipconfig.c
81053 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
81054
81055 mm_segment_t oldfs = get_fs();
81056 set_fs(get_ds());
81057 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
81058 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
81059 set_fs(oldfs);
81060 return res;
81061 }
81062 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
81063
81064 mm_segment_t oldfs = get_fs();
81065 set_fs(get_ds());
81066 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
81067 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
81068 set_fs(oldfs);
81069 return res;
81070 }
81071 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
81072
81073 mm_segment_t oldfs = get_fs();
81074 set_fs(get_ds());
81075 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
81076 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
81077 set_fs(oldfs);
81078 return res;
81079 }
81080 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
81081 index 3ea4127..849297b 100644
81082 --- a/net/ipv4/netfilter/arp_tables.c
81083 +++ b/net/ipv4/netfilter/arp_tables.c
81084 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
81085 #endif
81086
81087 static int get_info(struct net *net, void __user *user,
81088 - const int *len, int compat)
81089 + int len, int compat)
81090 {
81091 char name[XT_TABLE_MAXNAMELEN];
81092 struct xt_table *t;
81093 int ret;
81094
81095 - if (*len != sizeof(struct arpt_getinfo)) {
81096 - duprintf("length %u != %Zu\n", *len,
81097 + if (len != sizeof(struct arpt_getinfo)) {
81098 + duprintf("length %u != %Zu\n", len,
81099 sizeof(struct arpt_getinfo));
81100 return -EINVAL;
81101 }
81102 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
81103 info.size = private->size;
81104 strcpy(info.name, name);
81105
81106 - if (copy_to_user(user, &info, *len) != 0)
81107 + if (copy_to_user(user, &info, len) != 0)
81108 ret = -EFAULT;
81109 else
81110 ret = 0;
81111 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
81112
81113 switch (cmd) {
81114 case ARPT_SO_GET_INFO:
81115 - ret = get_info(sock_net(sk), user, len, 1);
81116 + ret = get_info(sock_net(sk), user, *len, 1);
81117 break;
81118 case ARPT_SO_GET_ENTRIES:
81119 ret = compat_get_entries(sock_net(sk), user, len);
81120 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
81121
81122 switch (cmd) {
81123 case ARPT_SO_GET_INFO:
81124 - ret = get_info(sock_net(sk), user, len, 0);
81125 + ret = get_info(sock_net(sk), user, *len, 0);
81126 break;
81127
81128 case ARPT_SO_GET_ENTRIES:
81129 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
81130 index 17c5e06..1b91206 100644
81131 --- a/net/ipv4/netfilter/ip_tables.c
81132 +++ b/net/ipv4/netfilter/ip_tables.c
81133 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
81134 #endif
81135
81136 static int get_info(struct net *net, void __user *user,
81137 - const int *len, int compat)
81138 + int len, int compat)
81139 {
81140 char name[XT_TABLE_MAXNAMELEN];
81141 struct xt_table *t;
81142 int ret;
81143
81144 - if (*len != sizeof(struct ipt_getinfo)) {
81145 - duprintf("length %u != %zu\n", *len,
81146 + if (len != sizeof(struct ipt_getinfo)) {
81147 + duprintf("length %u != %zu\n", len,
81148 sizeof(struct ipt_getinfo));
81149 return -EINVAL;
81150 }
81151 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
81152 info.size = private->size;
81153 strcpy(info.name, name);
81154
81155 - if (copy_to_user(user, &info, *len) != 0)
81156 + if (copy_to_user(user, &info, len) != 0)
81157 ret = -EFAULT;
81158 else
81159 ret = 0;
81160 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81161
81162 switch (cmd) {
81163 case IPT_SO_GET_INFO:
81164 - ret = get_info(sock_net(sk), user, len, 1);
81165 + ret = get_info(sock_net(sk), user, *len, 1);
81166 break;
81167 case IPT_SO_GET_ENTRIES:
81168 ret = compat_get_entries(sock_net(sk), user, len);
81169 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81170
81171 switch (cmd) {
81172 case IPT_SO_GET_INFO:
81173 - ret = get_info(sock_net(sk), user, len, 0);
81174 + ret = get_info(sock_net(sk), user, *len, 0);
81175 break;
81176
81177 case IPT_SO_GET_ENTRIES:
81178 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
81179 index 6f9c072..38ea6c6 100644
81180 --- a/net/ipv4/ping.c
81181 +++ b/net/ipv4/ping.c
81182 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
81183 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81184 0, sock_i_ino(sp),
81185 atomic_read(&sp->sk_refcnt), sp,
81186 - atomic_read(&sp->sk_drops), len);
81187 + atomic_read_unchecked(&sp->sk_drops), len);
81188 }
81189
81190 static int ping_seq_show(struct seq_file *seq, void *v)
81191 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
81192 index 6f08991..55867ad 100644
81193 --- a/net/ipv4/raw.c
81194 +++ b/net/ipv4/raw.c
81195 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
81196 int raw_rcv(struct sock *sk, struct sk_buff *skb)
81197 {
81198 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
81199 - atomic_inc(&sk->sk_drops);
81200 + atomic_inc_unchecked(&sk->sk_drops);
81201 kfree_skb(skb);
81202 return NET_RX_DROP;
81203 }
81204 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
81205
81206 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
81207 {
81208 + struct icmp_filter filter;
81209 +
81210 if (optlen > sizeof(struct icmp_filter))
81211 optlen = sizeof(struct icmp_filter);
81212 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
81213 + if (copy_from_user(&filter, optval, optlen))
81214 return -EFAULT;
81215 + raw_sk(sk)->filter = filter;
81216 return 0;
81217 }
81218
81219 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
81220 {
81221 int len, ret = -EFAULT;
81222 + struct icmp_filter filter;
81223
81224 if (get_user(len, optlen))
81225 goto out;
81226 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
81227 if (len > sizeof(struct icmp_filter))
81228 len = sizeof(struct icmp_filter);
81229 ret = -EFAULT;
81230 - if (put_user(len, optlen) ||
81231 - copy_to_user(optval, &raw_sk(sk)->filter, len))
81232 + filter = raw_sk(sk)->filter;
81233 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
81234 goto out;
81235 ret = 0;
81236 out: return ret;
81237 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81238 0, 0L, 0,
81239 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81240 0, sock_i_ino(sp),
81241 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81242 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81243 }
81244
81245 static int raw_seq_show(struct seq_file *seq, void *v)
81246 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
81247 index a0fcc47..5949bba1 100644
81248 --- a/net/ipv4/route.c
81249 +++ b/net/ipv4/route.c
81250 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
81251
81252 static __net_init int rt_genid_init(struct net *net)
81253 {
81254 - atomic_set(&net->rt_genid, 0);
81255 + atomic_set_unchecked(&net->rt_genid, 0);
81256 get_random_bytes(&net->ipv4.dev_addr_genid,
81257 sizeof(net->ipv4.dev_addr_genid));
81258 return 0;
81259 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
81260 index ad70a96..50cb55b 100644
81261 --- a/net/ipv4/tcp_input.c
81262 +++ b/net/ipv4/tcp_input.c
81263 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
81264 * simplifies code)
81265 */
81266 static void
81267 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81268 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
81269 struct sk_buff *head, struct sk_buff *tail,
81270 u32 start, u32 end)
81271 {
81272 @@ -5850,6 +5850,7 @@ discard:
81273 tcp_paws_reject(&tp->rx_opt, 0))
81274 goto discard_and_undo;
81275
81276 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
81277 if (th->syn) {
81278 /* We see SYN without ACK. It is attempt of
81279 * simultaneous connect with crossed SYNs.
81280 @@ -5900,6 +5901,7 @@ discard:
81281 goto discard;
81282 #endif
81283 }
81284 +#endif
81285 /* "fifth, if neither of the SYN or RST bits is set then
81286 * drop the segment and return."
81287 */
81288 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
81289 goto discard;
81290
81291 if (th->syn) {
81292 - if (th->fin)
81293 + if (th->fin || th->urg || th->psh)
81294 goto discard;
81295 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
81296 return 1;
81297 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
81298 index eadb693..e8f7251 100644
81299 --- a/net/ipv4/tcp_ipv4.c
81300 +++ b/net/ipv4/tcp_ipv4.c
81301 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
81302 EXPORT_SYMBOL(sysctl_tcp_low_latency);
81303
81304
81305 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81306 +extern int grsec_enable_blackhole;
81307 +#endif
81308 +
81309 #ifdef CONFIG_TCP_MD5SIG
81310 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
81311 __be32 daddr, __be32 saddr, const struct tcphdr *th);
81312 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
81313 return 0;
81314
81315 reset:
81316 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81317 + if (!grsec_enable_blackhole)
81318 +#endif
81319 tcp_v4_send_reset(rsk, skb);
81320 discard:
81321 kfree_skb(skb);
81322 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
81323 TCP_SKB_CB(skb)->sacked = 0;
81324
81325 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81326 - if (!sk)
81327 + if (!sk) {
81328 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81329 + ret = 1;
81330 +#endif
81331 goto no_tcp_socket;
81332 -
81333 + }
81334 process:
81335 - if (sk->sk_state == TCP_TIME_WAIT)
81336 + if (sk->sk_state == TCP_TIME_WAIT) {
81337 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81338 + ret = 2;
81339 +#endif
81340 goto do_time_wait;
81341 + }
81342
81343 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
81344 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81345 @@ -2050,6 +2064,10 @@ no_tcp_socket:
81346 bad_packet:
81347 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81348 } else {
81349 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81350 + if (!grsec_enable_blackhole || (ret == 1 &&
81351 + (skb->dev->flags & IFF_LOOPBACK)))
81352 +#endif
81353 tcp_v4_send_reset(NULL, skb);
81354 }
81355
81356 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
81357 index f35f2df..ccb5ca6 100644
81358 --- a/net/ipv4/tcp_minisocks.c
81359 +++ b/net/ipv4/tcp_minisocks.c
81360 @@ -27,6 +27,10 @@
81361 #include <net/inet_common.h>
81362 #include <net/xfrm.h>
81363
81364 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81365 +extern int grsec_enable_blackhole;
81366 +#endif
81367 +
81368 int sysctl_tcp_syncookies __read_mostly = 1;
81369 EXPORT_SYMBOL(sysctl_tcp_syncookies);
81370
81371 @@ -742,7 +746,10 @@ embryonic_reset:
81372 * avoid becoming vulnerable to outside attack aiming at
81373 * resetting legit local connections.
81374 */
81375 - req->rsk_ops->send_reset(sk, skb);
81376 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81377 + if (!grsec_enable_blackhole)
81378 +#endif
81379 + req->rsk_ops->send_reset(sk, skb);
81380 } else if (fastopen) { /* received a valid RST pkt */
81381 reqsk_fastopen_remove(sk, req, true);
81382 tcp_reset(sk);
81383 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
81384 index 4526fe6..1a34e43 100644
81385 --- a/net/ipv4/tcp_probe.c
81386 +++ b/net/ipv4/tcp_probe.c
81387 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
81388 if (cnt + width >= len)
81389 break;
81390
81391 - if (copy_to_user(buf + cnt, tbuf, width))
81392 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
81393 return -EFAULT;
81394 cnt += width;
81395 }
81396 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
81397 index b78aac3..e18230b 100644
81398 --- a/net/ipv4/tcp_timer.c
81399 +++ b/net/ipv4/tcp_timer.c
81400 @@ -22,6 +22,10 @@
81401 #include <linux/gfp.h>
81402 #include <net/tcp.h>
81403
81404 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81405 +extern int grsec_lastack_retries;
81406 +#endif
81407 +
81408 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
81409 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
81410 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
81411 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
81412 }
81413 }
81414
81415 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81416 + if ((sk->sk_state == TCP_LAST_ACK) &&
81417 + (grsec_lastack_retries > 0) &&
81418 + (grsec_lastack_retries < retry_until))
81419 + retry_until = grsec_lastack_retries;
81420 +#endif
81421 +
81422 if (retransmits_timed_out(sk, retry_until,
81423 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
81424 /* Has it gone just too far? */
81425 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
81426 index 1f4d405..3524677 100644
81427 --- a/net/ipv4/udp.c
81428 +++ b/net/ipv4/udp.c
81429 @@ -87,6 +87,7 @@
81430 #include <linux/types.h>
81431 #include <linux/fcntl.h>
81432 #include <linux/module.h>
81433 +#include <linux/security.h>
81434 #include <linux/socket.h>
81435 #include <linux/sockios.h>
81436 #include <linux/igmp.h>
81437 @@ -111,6 +112,10 @@
81438 #include <trace/events/skb.h>
81439 #include "udp_impl.h"
81440
81441 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81442 +extern int grsec_enable_blackhole;
81443 +#endif
81444 +
81445 struct udp_table udp_table __read_mostly;
81446 EXPORT_SYMBOL(udp_table);
81447
81448 @@ -569,6 +574,9 @@ found:
81449 return s;
81450 }
81451
81452 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
81453 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
81454 +
81455 /*
81456 * This routine is called by the ICMP module when it gets some
81457 * sort of error condition. If err < 0 then the socket should
81458 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
81459 dport = usin->sin_port;
81460 if (dport == 0)
81461 return -EINVAL;
81462 +
81463 + err = gr_search_udp_sendmsg(sk, usin);
81464 + if (err)
81465 + return err;
81466 } else {
81467 if (sk->sk_state != TCP_ESTABLISHED)
81468 return -EDESTADDRREQ;
81469 +
81470 + err = gr_search_udp_sendmsg(sk, NULL);
81471 + if (err)
81472 + return err;
81473 +
81474 daddr = inet->inet_daddr;
81475 dport = inet->inet_dport;
81476 /* Open fast path for connected socket.
81477 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
81478 udp_lib_checksum_complete(skb)) {
81479 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81480 IS_UDPLITE(sk));
81481 - atomic_inc(&sk->sk_drops);
81482 + atomic_inc_unchecked(&sk->sk_drops);
81483 __skb_unlink(skb, rcvq);
81484 __skb_queue_tail(&list_kill, skb);
81485 }
81486 @@ -1194,6 +1211,10 @@ try_again:
81487 if (!skb)
81488 goto out;
81489
81490 + err = gr_search_udp_recvmsg(sk, skb);
81491 + if (err)
81492 + goto out_free;
81493 +
81494 ulen = skb->len - sizeof(struct udphdr);
81495 copied = len;
81496 if (copied > ulen)
81497 @@ -1227,7 +1248,7 @@ try_again:
81498 if (unlikely(err)) {
81499 trace_kfree_skb(skb, udp_recvmsg);
81500 if (!peeked) {
81501 - atomic_inc(&sk->sk_drops);
81502 + atomic_inc_unchecked(&sk->sk_drops);
81503 UDP_INC_STATS_USER(sock_net(sk),
81504 UDP_MIB_INERRORS, is_udplite);
81505 }
81506 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81507
81508 drop:
81509 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81510 - atomic_inc(&sk->sk_drops);
81511 + atomic_inc_unchecked(&sk->sk_drops);
81512 kfree_skb(skb);
81513 return -1;
81514 }
81515 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81516 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81517
81518 if (!skb1) {
81519 - atomic_inc(&sk->sk_drops);
81520 + atomic_inc_unchecked(&sk->sk_drops);
81521 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81522 IS_UDPLITE(sk));
81523 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81524 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81525 goto csum_error;
81526
81527 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81528 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81529 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81530 +#endif
81531 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
81532
81533 /*
81534 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
81535 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
81536 0, sock_i_ino(sp),
81537 atomic_read(&sp->sk_refcnt), sp,
81538 - atomic_read(&sp->sk_drops), len);
81539 + atomic_read_unchecked(&sp->sk_drops), len);
81540 }
81541
81542 int udp4_seq_show(struct seq_file *seq, void *v)
81543 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
81544 index 1b5d8cb..2e8c2d9 100644
81545 --- a/net/ipv6/addrconf.c
81546 +++ b/net/ipv6/addrconf.c
81547 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
81548 p.iph.ihl = 5;
81549 p.iph.protocol = IPPROTO_IPV6;
81550 p.iph.ttl = 64;
81551 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
81552 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
81553
81554 if (ops->ndo_do_ioctl) {
81555 mm_segment_t oldfs = get_fs();
81556 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
81557 index 131dd09..7647ada 100644
81558 --- a/net/ipv6/ip6_gre.c
81559 +++ b/net/ipv6/ip6_gre.c
81560 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
81561 }
81562
81563
81564 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
81565 +static struct inet6_protocol ip6gre_protocol = {
81566 .handler = ip6gre_rcv,
81567 .err_handler = ip6gre_err,
81568 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
81569 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
81570 index d1e2e8e..51c19ae 100644
81571 --- a/net/ipv6/ipv6_sockglue.c
81572 +++ b/net/ipv6/ipv6_sockglue.c
81573 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
81574 if (sk->sk_type != SOCK_STREAM)
81575 return -ENOPROTOOPT;
81576
81577 - msg.msg_control = optval;
81578 + msg.msg_control = (void __force_kernel *)optval;
81579 msg.msg_controllen = len;
81580 msg.msg_flags = flags;
81581
81582 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
81583 index 125a90d..2a11f36 100644
81584 --- a/net/ipv6/netfilter/ip6_tables.c
81585 +++ b/net/ipv6/netfilter/ip6_tables.c
81586 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
81587 #endif
81588
81589 static int get_info(struct net *net, void __user *user,
81590 - const int *len, int compat)
81591 + int len, int compat)
81592 {
81593 char name[XT_TABLE_MAXNAMELEN];
81594 struct xt_table *t;
81595 int ret;
81596
81597 - if (*len != sizeof(struct ip6t_getinfo)) {
81598 - duprintf("length %u != %zu\n", *len,
81599 + if (len != sizeof(struct ip6t_getinfo)) {
81600 + duprintf("length %u != %zu\n", len,
81601 sizeof(struct ip6t_getinfo));
81602 return -EINVAL;
81603 }
81604 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
81605 info.size = private->size;
81606 strcpy(info.name, name);
81607
81608 - if (copy_to_user(user, &info, *len) != 0)
81609 + if (copy_to_user(user, &info, len) != 0)
81610 ret = -EFAULT;
81611 else
81612 ret = 0;
81613 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81614
81615 switch (cmd) {
81616 case IP6T_SO_GET_INFO:
81617 - ret = get_info(sock_net(sk), user, len, 1);
81618 + ret = get_info(sock_net(sk), user, *len, 1);
81619 break;
81620 case IP6T_SO_GET_ENTRIES:
81621 ret = compat_get_entries(sock_net(sk), user, len);
81622 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
81623
81624 switch (cmd) {
81625 case IP6T_SO_GET_INFO:
81626 - ret = get_info(sock_net(sk), user, len, 0);
81627 + ret = get_info(sock_net(sk), user, *len, 0);
81628 break;
81629
81630 case IP6T_SO_GET_ENTRIES:
81631 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
81632 index 70fa814..d70c28c 100644
81633 --- a/net/ipv6/raw.c
81634 +++ b/net/ipv6/raw.c
81635 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
81636 {
81637 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
81638 skb_checksum_complete(skb)) {
81639 - atomic_inc(&sk->sk_drops);
81640 + atomic_inc_unchecked(&sk->sk_drops);
81641 kfree_skb(skb);
81642 return NET_RX_DROP;
81643 }
81644 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81645 struct raw6_sock *rp = raw6_sk(sk);
81646
81647 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
81648 - atomic_inc(&sk->sk_drops);
81649 + atomic_inc_unchecked(&sk->sk_drops);
81650 kfree_skb(skb);
81651 return NET_RX_DROP;
81652 }
81653 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
81654
81655 if (inet->hdrincl) {
81656 if (skb_checksum_complete(skb)) {
81657 - atomic_inc(&sk->sk_drops);
81658 + atomic_inc_unchecked(&sk->sk_drops);
81659 kfree_skb(skb);
81660 return NET_RX_DROP;
81661 }
81662 @@ -604,7 +604,7 @@ out:
81663 return err;
81664 }
81665
81666 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
81667 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
81668 struct flowi6 *fl6, struct dst_entry **dstp,
81669 unsigned int flags)
81670 {
81671 @@ -916,12 +916,15 @@ do_confirm:
81672 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
81673 char __user *optval, int optlen)
81674 {
81675 + struct icmp6_filter filter;
81676 +
81677 switch (optname) {
81678 case ICMPV6_FILTER:
81679 if (optlen > sizeof(struct icmp6_filter))
81680 optlen = sizeof(struct icmp6_filter);
81681 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
81682 + if (copy_from_user(&filter, optval, optlen))
81683 return -EFAULT;
81684 + raw6_sk(sk)->filter = filter;
81685 return 0;
81686 default:
81687 return -ENOPROTOOPT;
81688 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81689 char __user *optval, int __user *optlen)
81690 {
81691 int len;
81692 + struct icmp6_filter filter;
81693
81694 switch (optname) {
81695 case ICMPV6_FILTER:
81696 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
81697 len = sizeof(struct icmp6_filter);
81698 if (put_user(len, optlen))
81699 return -EFAULT;
81700 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
81701 + filter = raw6_sk(sk)->filter;
81702 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
81703 return -EFAULT;
81704 return 0;
81705 default:
81706 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
81707 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
81708 0,
81709 sock_i_ino(sp),
81710 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
81711 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
81712 }
81713
81714 static int raw6_seq_show(struct seq_file *seq, void *v)
81715 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
81716 index 4f435371..5de9da7 100644
81717 --- a/net/ipv6/tcp_ipv6.c
81718 +++ b/net/ipv6/tcp_ipv6.c
81719 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
81720 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
81721 }
81722
81723 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81724 +extern int grsec_enable_blackhole;
81725 +#endif
81726 +
81727 static void tcp_v6_hash(struct sock *sk)
81728 {
81729 if (sk->sk_state != TCP_CLOSE) {
81730 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
81731 return 0;
81732
81733 reset:
81734 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81735 + if (!grsec_enable_blackhole)
81736 +#endif
81737 tcp_v6_send_reset(sk, skb);
81738 discard:
81739 if (opt_skb)
81740 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
81741 TCP_SKB_CB(skb)->sacked = 0;
81742
81743 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
81744 - if (!sk)
81745 + if (!sk) {
81746 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81747 + ret = 1;
81748 +#endif
81749 goto no_tcp_socket;
81750 + }
81751
81752 process:
81753 - if (sk->sk_state == TCP_TIME_WAIT)
81754 + if (sk->sk_state == TCP_TIME_WAIT) {
81755 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81756 + ret = 2;
81757 +#endif
81758 goto do_time_wait;
81759 + }
81760
81761 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
81762 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
81763 @@ -1568,6 +1583,10 @@ no_tcp_socket:
81764 bad_packet:
81765 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
81766 } else {
81767 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81768 + if (!grsec_enable_blackhole || (ret == 1 &&
81769 + (skb->dev->flags & IFF_LOOPBACK)))
81770 +#endif
81771 tcp_v6_send_reset(NULL, skb);
81772 }
81773
81774 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
81775 index fb08329..2d6919e 100644
81776 --- a/net/ipv6/udp.c
81777 +++ b/net/ipv6/udp.c
81778 @@ -51,6 +51,10 @@
81779 #include <trace/events/skb.h>
81780 #include "udp_impl.h"
81781
81782 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81783 +extern int grsec_enable_blackhole;
81784 +#endif
81785 +
81786 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
81787 {
81788 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
81789 @@ -395,7 +399,7 @@ try_again:
81790 if (unlikely(err)) {
81791 trace_kfree_skb(skb, udpv6_recvmsg);
81792 if (!peeked) {
81793 - atomic_inc(&sk->sk_drops);
81794 + atomic_inc_unchecked(&sk->sk_drops);
81795 if (is_udp4)
81796 UDP_INC_STATS_USER(sock_net(sk),
81797 UDP_MIB_INERRORS,
81798 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
81799 return rc;
81800 drop:
81801 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
81802 - atomic_inc(&sk->sk_drops);
81803 + atomic_inc_unchecked(&sk->sk_drops);
81804 kfree_skb(skb);
81805 return -1;
81806 }
81807 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
81808 if (likely(skb1 == NULL))
81809 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
81810 if (!skb1) {
81811 - atomic_inc(&sk->sk_drops);
81812 + atomic_inc_unchecked(&sk->sk_drops);
81813 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
81814 IS_UDPLITE(sk));
81815 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
81816 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
81817 goto discard;
81818
81819 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
81820 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
81821 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
81822 +#endif
81823 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
81824
81825 kfree_skb(skb);
81826 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
81827 0,
81828 sock_i_ino(sp),
81829 atomic_read(&sp->sk_refcnt), sp,
81830 - atomic_read(&sp->sk_drops));
81831 + atomic_read_unchecked(&sp->sk_drops));
81832 }
81833
81834 int udp6_seq_show(struct seq_file *seq, void *v)
81835 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
81836 index a68c88c..d55b0c5 100644
81837 --- a/net/irda/ircomm/ircomm_tty.c
81838 +++ b/net/irda/ircomm/ircomm_tty.c
81839 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81840 add_wait_queue(&port->open_wait, &wait);
81841
81842 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
81843 - __FILE__, __LINE__, tty->driver->name, port->count);
81844 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81845
81846 spin_lock_irqsave(&port->lock, flags);
81847 if (!tty_hung_up_p(filp)) {
81848 extra_count = 1;
81849 - port->count--;
81850 + atomic_dec(&port->count);
81851 }
81852 spin_unlock_irqrestore(&port->lock, flags);
81853 port->blocked_open++;
81854 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81855 }
81856
81857 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
81858 - __FILE__, __LINE__, tty->driver->name, port->count);
81859 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81860
81861 schedule();
81862 }
81863 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
81864 if (extra_count) {
81865 /* ++ is not atomic, so this should be protected - Jean II */
81866 spin_lock_irqsave(&port->lock, flags);
81867 - port->count++;
81868 + atomic_inc(&port->count);
81869 spin_unlock_irqrestore(&port->lock, flags);
81870 }
81871 port->blocked_open--;
81872
81873 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
81874 - __FILE__, __LINE__, tty->driver->name, port->count);
81875 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
81876
81877 if (!retval)
81878 port->flags |= ASYNC_NORMAL_ACTIVE;
81879 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
81880
81881 /* ++ is not atomic, so this should be protected - Jean II */
81882 spin_lock_irqsave(&self->port.lock, flags);
81883 - self->port.count++;
81884 + atomic_inc(&self->port.count);
81885 spin_unlock_irqrestore(&self->port.lock, flags);
81886 tty_port_tty_set(&self->port, tty);
81887
81888 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
81889 - self->line, self->port.count);
81890 + self->line, atomic_read(&self->port.count));
81891
81892 /* Not really used by us, but lets do it anyway */
81893 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
81894 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
81895 tty_kref_put(port->tty);
81896 }
81897 port->tty = NULL;
81898 - port->count = 0;
81899 + atomic_set(&port->count, 0);
81900 spin_unlock_irqrestore(&port->lock, flags);
81901
81902 wake_up_interruptible(&port->open_wait);
81903 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
81904 seq_putc(m, '\n');
81905
81906 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
81907 - seq_printf(m, "Open count: %d\n", self->port.count);
81908 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
81909 seq_printf(m, "Max data size: %d\n", self->max_data_size);
81910 seq_printf(m, "Max header size: %d\n", self->max_header_size);
81911
81912 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
81913 index cd6f7a9..e63fe89 100644
81914 --- a/net/iucv/af_iucv.c
81915 +++ b/net/iucv/af_iucv.c
81916 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
81917
81918 write_lock_bh(&iucv_sk_list.lock);
81919
81920 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
81921 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81922 while (__iucv_get_sock_by_name(name)) {
81923 sprintf(name, "%08x",
81924 - atomic_inc_return(&iucv_sk_list.autobind_name));
81925 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
81926 }
81927
81928 write_unlock_bh(&iucv_sk_list.lock);
81929 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
81930 index df08250..02021fe 100644
81931 --- a/net/iucv/iucv.c
81932 +++ b/net/iucv/iucv.c
81933 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
81934 return NOTIFY_OK;
81935 }
81936
81937 -static struct notifier_block __refdata iucv_cpu_notifier = {
81938 +static struct notifier_block iucv_cpu_notifier = {
81939 .notifier_call = iucv_cpu_notify,
81940 };
81941
81942 diff --git a/net/key/af_key.c b/net/key/af_key.c
81943 index 5b426a6..970032b 100644
81944 --- a/net/key/af_key.c
81945 +++ b/net/key/af_key.c
81946 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
81947 static u32 get_acqseq(void)
81948 {
81949 u32 res;
81950 - static atomic_t acqseq;
81951 + static atomic_unchecked_t acqseq;
81952
81953 do {
81954 - res = atomic_inc_return(&acqseq);
81955 + res = atomic_inc_return_unchecked(&acqseq);
81956 } while (!res);
81957 return res;
81958 }
81959 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
81960 index 0479c64..d031db6 100644
81961 --- a/net/mac80211/cfg.c
81962 +++ b/net/mac80211/cfg.c
81963 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
81964 ret = ieee80211_vif_use_channel(sdata, chandef,
81965 IEEE80211_CHANCTX_EXCLUSIVE);
81966 }
81967 - } else if (local->open_count == local->monitors) {
81968 + } else if (local_read(&local->open_count) == local->monitors) {
81969 local->_oper_channel = chandef->chan;
81970 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
81971 ieee80211_hw_config(local, 0);
81972 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
81973 else
81974 local->probe_req_reg--;
81975
81976 - if (!local->open_count)
81977 + if (!local_read(&local->open_count))
81978 break;
81979
81980 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
81981 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
81982 index 2ed065c..948177f 100644
81983 --- a/net/mac80211/ieee80211_i.h
81984 +++ b/net/mac80211/ieee80211_i.h
81985 @@ -28,6 +28,7 @@
81986 #include <net/ieee80211_radiotap.h>
81987 #include <net/cfg80211.h>
81988 #include <net/mac80211.h>
81989 +#include <asm/local.h>
81990 #include "key.h"
81991 #include "sta_info.h"
81992 #include "debug.h"
81993 @@ -909,7 +910,7 @@ struct ieee80211_local {
81994 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
81995 spinlock_t queue_stop_reason_lock;
81996
81997 - int open_count;
81998 + local_t open_count;
81999 int monitors, cooked_mntrs;
82000 /* number of interfaces with corresponding FIF_ flags */
82001 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
82002 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
82003 index 8be854e..ad72a69 100644
82004 --- a/net/mac80211/iface.c
82005 +++ b/net/mac80211/iface.c
82006 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
82007 break;
82008 }
82009
82010 - if (local->open_count == 0) {
82011 + if (local_read(&local->open_count) == 0) {
82012 res = drv_start(local);
82013 if (res)
82014 goto err_del_bss;
82015 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
82016 break;
82017 }
82018
82019 - if (local->monitors == 0 && local->open_count == 0) {
82020 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
82021 res = ieee80211_add_virtual_monitor(local);
82022 if (res)
82023 goto err_stop;
82024 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
82025 mutex_unlock(&local->mtx);
82026
82027 if (coming_up)
82028 - local->open_count++;
82029 + local_inc(&local->open_count);
82030
82031 if (hw_reconf_flags)
82032 ieee80211_hw_config(local, hw_reconf_flags);
82033 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
82034 err_del_interface:
82035 drv_remove_interface(local, sdata);
82036 err_stop:
82037 - if (!local->open_count)
82038 + if (!local_read(&local->open_count))
82039 drv_stop(local);
82040 err_del_bss:
82041 sdata->bss = NULL;
82042 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
82043 }
82044
82045 if (going_down)
82046 - local->open_count--;
82047 + local_dec(&local->open_count);
82048
82049 switch (sdata->vif.type) {
82050 case NL80211_IFTYPE_AP_VLAN:
82051 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
82052
82053 ieee80211_recalc_ps(local, -1);
82054
82055 - if (local->open_count == 0) {
82056 + if (local_read(&local->open_count) == 0) {
82057 if (local->ops->napi_poll)
82058 napi_disable(&local->napi);
82059 ieee80211_clear_tx_pending(local);
82060 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
82061 }
82062 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
82063
82064 - if (local->monitors == local->open_count && local->monitors > 0)
82065 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
82066 ieee80211_add_virtual_monitor(local);
82067 }
82068
82069 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
82070 index 1b087ff..bf600e9 100644
82071 --- a/net/mac80211/main.c
82072 +++ b/net/mac80211/main.c
82073 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
82074 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
82075 IEEE80211_CONF_CHANGE_POWER);
82076
82077 - if (changed && local->open_count) {
82078 + if (changed && local_read(&local->open_count)) {
82079 ret = drv_config(local, changed);
82080 /*
82081 * Goal:
82082 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
82083 index 79a48f3..5e185c9 100644
82084 --- a/net/mac80211/pm.c
82085 +++ b/net/mac80211/pm.c
82086 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82087 struct sta_info *sta;
82088 struct ieee80211_chanctx *ctx;
82089
82090 - if (!local->open_count)
82091 + if (!local_read(&local->open_count))
82092 goto suspend;
82093
82094 ieee80211_scan_cancel(local);
82095 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82096 cancel_work_sync(&local->dynamic_ps_enable_work);
82097 del_timer_sync(&local->dynamic_ps_timer);
82098
82099 - local->wowlan = wowlan && local->open_count;
82100 + local->wowlan = wowlan && local_read(&local->open_count);
82101 if (local->wowlan) {
82102 int err = drv_suspend(local, wowlan);
82103 if (err < 0) {
82104 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
82105 mutex_unlock(&local->chanctx_mtx);
82106
82107 /* stop hardware - this must stop RX */
82108 - if (local->open_count)
82109 + if (local_read(&local->open_count))
82110 ieee80211_stop_device(local);
82111
82112 suspend:
82113 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
82114 index dd88381..eef4dd6 100644
82115 --- a/net/mac80211/rate.c
82116 +++ b/net/mac80211/rate.c
82117 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
82118
82119 ASSERT_RTNL();
82120
82121 - if (local->open_count)
82122 + if (local_read(&local->open_count))
82123 return -EBUSY;
82124
82125 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
82126 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
82127 index c97a065..ff61928 100644
82128 --- a/net/mac80211/rc80211_pid_debugfs.c
82129 +++ b/net/mac80211/rc80211_pid_debugfs.c
82130 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
82131
82132 spin_unlock_irqrestore(&events->lock, status);
82133
82134 - if (copy_to_user(buf, pb, p))
82135 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
82136 return -EFAULT;
82137
82138 return p;
82139 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
82140 index f11e8c5..08d0013 100644
82141 --- a/net/mac80211/util.c
82142 +++ b/net/mac80211/util.c
82143 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
82144 }
82145 #endif
82146 /* everything else happens only if HW was up & running */
82147 - if (!local->open_count)
82148 + if (!local_read(&local->open_count))
82149 goto wake_up;
82150
82151 /*
82152 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
82153 index 49e96df..63a51c3 100644
82154 --- a/net/netfilter/Kconfig
82155 +++ b/net/netfilter/Kconfig
82156 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
82157
82158 To compile it as a module, choose M here. If unsure, say N.
82159
82160 +config NETFILTER_XT_MATCH_GRADM
82161 + tristate '"gradm" match support'
82162 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
82163 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
82164 + ---help---
82165 + The gradm match allows to match on grsecurity RBAC being enabled.
82166 + It is useful when iptables rules are applied early on bootup to
82167 + prevent connections to the machine (except from a trusted host)
82168 + while the RBAC system is disabled.
82169 +
82170 config NETFILTER_XT_MATCH_HASHLIMIT
82171 tristate '"hashlimit" match support'
82172 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
82173 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
82174 index 3259697..54d5393 100644
82175 --- a/net/netfilter/Makefile
82176 +++ b/net/netfilter/Makefile
82177 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
82178 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
82179 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
82180 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
82181 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
82182 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
82183 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
82184 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
82185 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
82186 index 30e764a..c3b6a9d 100644
82187 --- a/net/netfilter/ipvs/ip_vs_conn.c
82188 +++ b/net/netfilter/ipvs/ip_vs_conn.c
82189 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
82190 /* Increase the refcnt counter of the dest */
82191 atomic_inc(&dest->refcnt);
82192
82193 - conn_flags = atomic_read(&dest->conn_flags);
82194 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
82195 if (cp->protocol != IPPROTO_UDP)
82196 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
82197 flags = cp->flags;
82198 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
82199 atomic_set(&cp->refcnt, 1);
82200
82201 atomic_set(&cp->n_control, 0);
82202 - atomic_set(&cp->in_pkts, 0);
82203 + atomic_set_unchecked(&cp->in_pkts, 0);
82204
82205 atomic_inc(&ipvs->conn_count);
82206 if (flags & IP_VS_CONN_F_NO_CPORT)
82207 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
82208
82209 /* Don't drop the entry if its number of incoming packets is not
82210 located in [0, 8] */
82211 - i = atomic_read(&cp->in_pkts);
82212 + i = atomic_read_unchecked(&cp->in_pkts);
82213 if (i > 8 || i < 0) return 0;
82214
82215 if (!todrop_rate[i]) return 0;
82216 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
82217 index 47edf5a..235b07d 100644
82218 --- a/net/netfilter/ipvs/ip_vs_core.c
82219 +++ b/net/netfilter/ipvs/ip_vs_core.c
82220 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
82221 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
82222 /* do not touch skb anymore */
82223
82224 - atomic_inc(&cp->in_pkts);
82225 + atomic_inc_unchecked(&cp->in_pkts);
82226 ip_vs_conn_put(cp);
82227 return ret;
82228 }
82229 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
82230 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
82231 pkts = sysctl_sync_threshold(ipvs);
82232 else
82233 - pkts = atomic_add_return(1, &cp->in_pkts);
82234 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82235
82236 if (ipvs->sync_state & IP_VS_STATE_MASTER)
82237 ip_vs_sync_conn(net, cp, pkts);
82238 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
82239 index ec664cb..cd576ab 100644
82240 --- a/net/netfilter/ipvs/ip_vs_ctl.c
82241 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
82242 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
82243 ip_vs_rs_hash(ipvs, dest);
82244 write_unlock_bh(&ipvs->rs_lock);
82245 }
82246 - atomic_set(&dest->conn_flags, conn_flags);
82247 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
82248
82249 /* bind the service */
82250 if (!dest->svc) {
82251 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82252 " %-7s %-6d %-10d %-10d\n",
82253 &dest->addr.in6,
82254 ntohs(dest->port),
82255 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82256 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82257 atomic_read(&dest->weight),
82258 atomic_read(&dest->activeconns),
82259 atomic_read(&dest->inactconns));
82260 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
82261 "%-7s %-6d %-10d %-10d\n",
82262 ntohl(dest->addr.ip),
82263 ntohs(dest->port),
82264 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
82265 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
82266 atomic_read(&dest->weight),
82267 atomic_read(&dest->activeconns),
82268 atomic_read(&dest->inactconns));
82269 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
82270
82271 entry.addr = dest->addr.ip;
82272 entry.port = dest->port;
82273 - entry.conn_flags = atomic_read(&dest->conn_flags);
82274 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
82275 entry.weight = atomic_read(&dest->weight);
82276 entry.u_threshold = dest->u_threshold;
82277 entry.l_threshold = dest->l_threshold;
82278 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
82279 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
82280 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
82281 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
82282 - (atomic_read(&dest->conn_flags) &
82283 + (atomic_read_unchecked(&dest->conn_flags) &
82284 IP_VS_CONN_F_FWD_MASK)) ||
82285 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
82286 atomic_read(&dest->weight)) ||
82287 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
82288 index 44fd10c..2a163b3 100644
82289 --- a/net/netfilter/ipvs/ip_vs_sync.c
82290 +++ b/net/netfilter/ipvs/ip_vs_sync.c
82291 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
82292 cp = cp->control;
82293 if (cp) {
82294 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82295 - pkts = atomic_add_return(1, &cp->in_pkts);
82296 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82297 else
82298 pkts = sysctl_sync_threshold(ipvs);
82299 ip_vs_sync_conn(net, cp->control, pkts);
82300 @@ -758,7 +758,7 @@ control:
82301 if (!cp)
82302 return;
82303 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
82304 - pkts = atomic_add_return(1, &cp->in_pkts);
82305 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
82306 else
82307 pkts = sysctl_sync_threshold(ipvs);
82308 goto sloop;
82309 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
82310
82311 if (opt)
82312 memcpy(&cp->in_seq, opt, sizeof(*opt));
82313 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82314 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
82315 cp->state = state;
82316 cp->old_state = cp->state;
82317 /*
82318 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
82319 index ee6b7a9..f9a89f6 100644
82320 --- a/net/netfilter/ipvs/ip_vs_xmit.c
82321 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
82322 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
82323 else
82324 rc = NF_ACCEPT;
82325 /* do not touch skb anymore */
82326 - atomic_inc(&cp->in_pkts);
82327 + atomic_inc_unchecked(&cp->in_pkts);
82328 goto out;
82329 }
82330
82331 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
82332 else
82333 rc = NF_ACCEPT;
82334 /* do not touch skb anymore */
82335 - atomic_inc(&cp->in_pkts);
82336 + atomic_inc_unchecked(&cp->in_pkts);
82337 goto out;
82338 }
82339
82340 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
82341 index e4a0c4f..c263f28 100644
82342 --- a/net/netfilter/nf_conntrack_core.c
82343 +++ b/net/netfilter/nf_conntrack_core.c
82344 @@ -1529,6 +1529,10 @@ err_extend:
82345 #define DYING_NULLS_VAL ((1<<30)+1)
82346 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
82347
82348 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82349 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
82350 +#endif
82351 +
82352 static int nf_conntrack_init_net(struct net *net)
82353 {
82354 int ret;
82355 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
82356 goto err_stat;
82357 }
82358
82359 +#ifdef CONFIG_GRKERNSEC_HIDESYM
82360 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
82361 +#else
82362 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
82363 +#endif
82364 if (!net->ct.slabname) {
82365 ret = -ENOMEM;
82366 goto err_slabname;
82367 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
82368 index 92fd8ec..3f6ea4b 100644
82369 --- a/net/netfilter/nfnetlink_log.c
82370 +++ b/net/netfilter/nfnetlink_log.c
82371 @@ -72,7 +72,7 @@ struct nfulnl_instance {
82372 };
82373
82374 static DEFINE_SPINLOCK(instances_lock);
82375 -static atomic_t global_seq;
82376 +static atomic_unchecked_t global_seq;
82377
82378 #define INSTANCE_BUCKETS 16
82379 static struct hlist_head instance_table[INSTANCE_BUCKETS];
82380 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
82381 /* global sequence number */
82382 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
82383 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
82384 - htonl(atomic_inc_return(&global_seq))))
82385 + htonl(atomic_inc_return_unchecked(&global_seq))))
82386 goto nla_put_failure;
82387
82388 if (data_len) {
82389 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
82390 new file mode 100644
82391 index 0000000..c566332
82392 --- /dev/null
82393 +++ b/net/netfilter/xt_gradm.c
82394 @@ -0,0 +1,51 @@
82395 +/*
82396 + * gradm match for netfilter
82397 + * Copyright © Zbigniew Krzystolik, 2010
82398 + *
82399 + * This program is free software; you can redistribute it and/or modify
82400 + * it under the terms of the GNU General Public License; either version
82401 + * 2 or 3 as published by the Free Software Foundation.
82402 + */
82403 +#include <linux/module.h>
82404 +#include <linux/moduleparam.h>
82405 +#include <linux/skbuff.h>
82406 +#include <linux/netfilter/x_tables.h>
82407 +#include <linux/grsecurity.h>
82408 +#include <linux/netfilter/xt_gradm.h>
82409 +
82410 +static bool
82411 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
82412 +{
82413 + const struct xt_gradm_mtinfo *info = par->matchinfo;
82414 + bool retval = false;
82415 + if (gr_acl_is_enabled())
82416 + retval = true;
82417 + return retval ^ info->invflags;
82418 +}
82419 +
82420 +static struct xt_match gradm_mt_reg __read_mostly = {
82421 + .name = "gradm",
82422 + .revision = 0,
82423 + .family = NFPROTO_UNSPEC,
82424 + .match = gradm_mt,
82425 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
82426 + .me = THIS_MODULE,
82427 +};
82428 +
82429 +static int __init gradm_mt_init(void)
82430 +{
82431 + return xt_register_match(&gradm_mt_reg);
82432 +}
82433 +
82434 +static void __exit gradm_mt_exit(void)
82435 +{
82436 + xt_unregister_match(&gradm_mt_reg);
82437 +}
82438 +
82439 +module_init(gradm_mt_init);
82440 +module_exit(gradm_mt_exit);
82441 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
82442 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
82443 +MODULE_LICENSE("GPL");
82444 +MODULE_ALIAS("ipt_gradm");
82445 +MODULE_ALIAS("ip6t_gradm");
82446 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
82447 index 4fe4fb4..87a89e5 100644
82448 --- a/net/netfilter/xt_statistic.c
82449 +++ b/net/netfilter/xt_statistic.c
82450 @@ -19,7 +19,7 @@
82451 #include <linux/module.h>
82452
82453 struct xt_statistic_priv {
82454 - atomic_t count;
82455 + atomic_unchecked_t count;
82456 } ____cacheline_aligned_in_smp;
82457
82458 MODULE_LICENSE("GPL");
82459 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
82460 break;
82461 case XT_STATISTIC_MODE_NTH:
82462 do {
82463 - oval = atomic_read(&info->master->count);
82464 + oval = atomic_read_unchecked(&info->master->count);
82465 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
82466 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
82467 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
82468 if (nval == 0)
82469 ret = !ret;
82470 break;
82471 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
82472 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
82473 if (info->master == NULL)
82474 return -ENOMEM;
82475 - atomic_set(&info->master->count, info->u.nth.count);
82476 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
82477
82478 return 0;
82479 }
82480 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
82481 index c0353d5..fcb0270 100644
82482 --- a/net/netlink/af_netlink.c
82483 +++ b/net/netlink/af_netlink.c
82484 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
82485 sk->sk_error_report(sk);
82486 }
82487 }
82488 - atomic_inc(&sk->sk_drops);
82489 + atomic_inc_unchecked(&sk->sk_drops);
82490 }
82491
82492 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
82493 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
82494 sk_wmem_alloc_get(s),
82495 nlk->cb,
82496 atomic_read(&s->sk_refcnt),
82497 - atomic_read(&s->sk_drops),
82498 + atomic_read_unchecked(&s->sk_drops),
82499 sock_i_ino(s)
82500 );
82501
82502 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
82503 index 7261eb8..44e8ac6 100644
82504 --- a/net/netrom/af_netrom.c
82505 +++ b/net/netrom/af_netrom.c
82506 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
82507 struct sock *sk = sock->sk;
82508 struct nr_sock *nr = nr_sk(sk);
82509
82510 + memset(sax, 0, sizeof(*sax));
82511 lock_sock(sk);
82512 if (peer != 0) {
82513 if (sk->sk_state != TCP_ESTABLISHED) {
82514 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
82515 *uaddr_len = sizeof(struct full_sockaddr_ax25);
82516 } else {
82517 sax->fsa_ax25.sax25_family = AF_NETROM;
82518 - sax->fsa_ax25.sax25_ndigis = 0;
82519 sax->fsa_ax25.sax25_call = nr->source_addr;
82520 *uaddr_len = sizeof(struct sockaddr_ax25);
82521 }
82522 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
82523 index c111bd0..7788ff7 100644
82524 --- a/net/packet/af_packet.c
82525 +++ b/net/packet/af_packet.c
82526 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
82527
82528 spin_lock(&sk->sk_receive_queue.lock);
82529 po->stats.tp_packets++;
82530 - skb->dropcount = atomic_read(&sk->sk_drops);
82531 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
82532 __skb_queue_tail(&sk->sk_receive_queue, skb);
82533 spin_unlock(&sk->sk_receive_queue.lock);
82534 sk->sk_data_ready(sk, skb->len);
82535 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
82536 drop_n_acct:
82537 spin_lock(&sk->sk_receive_queue.lock);
82538 po->stats.tp_drops++;
82539 - atomic_inc(&sk->sk_drops);
82540 + atomic_inc_unchecked(&sk->sk_drops);
82541 spin_unlock(&sk->sk_receive_queue.lock);
82542
82543 drop_n_restore:
82544 @@ -2565,6 +2565,7 @@ out:
82545
82546 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
82547 {
82548 + struct sock_extended_err ee;
82549 struct sock_exterr_skb *serr;
82550 struct sk_buff *skb, *skb2;
82551 int copied, err;
82552 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
82553 sock_recv_timestamp(msg, sk, skb);
82554
82555 serr = SKB_EXT_ERR(skb);
82556 + ee = serr->ee;
82557 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
82558 - sizeof(serr->ee), &serr->ee);
82559 + sizeof ee, &ee);
82560
82561 msg->msg_flags |= MSG_ERRQUEUE;
82562 err = copied;
82563 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
82564 case PACKET_HDRLEN:
82565 if (len > sizeof(int))
82566 len = sizeof(int);
82567 - if (copy_from_user(&val, optval, len))
82568 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
82569 return -EFAULT;
82570 switch (val) {
82571 case TPACKET_V1:
82572 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
82573 len = lv;
82574 if (put_user(len, optlen))
82575 return -EFAULT;
82576 - if (copy_to_user(optval, data, len))
82577 + if (len > sizeof(st) || copy_to_user(optval, data, len))
82578 return -EFAULT;
82579 return 0;
82580 }
82581 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
82582 index 5a940db..f0b9c12 100644
82583 --- a/net/phonet/af_phonet.c
82584 +++ b/net/phonet/af_phonet.c
82585 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
82586 {
82587 struct phonet_protocol *pp;
82588
82589 - if (protocol >= PHONET_NPROTO)
82590 + if (protocol < 0 || protocol >= PHONET_NPROTO)
82591 return NULL;
82592
82593 rcu_read_lock();
82594 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
82595 {
82596 int err = 0;
82597
82598 - if (protocol >= PHONET_NPROTO)
82599 + if (protocol < 0 || protocol >= PHONET_NPROTO)
82600 return -EINVAL;
82601
82602 err = proto_register(pp->prot, 1);
82603 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
82604 index 576f22c..bc7a71b 100644
82605 --- a/net/phonet/pep.c
82606 +++ b/net/phonet/pep.c
82607 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82608
82609 case PNS_PEP_CTRL_REQ:
82610 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
82611 - atomic_inc(&sk->sk_drops);
82612 + atomic_inc_unchecked(&sk->sk_drops);
82613 break;
82614 }
82615 __skb_pull(skb, 4);
82616 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
82617 }
82618
82619 if (pn->rx_credits == 0) {
82620 - atomic_inc(&sk->sk_drops);
82621 + atomic_inc_unchecked(&sk->sk_drops);
82622 err = -ENOBUFS;
82623 break;
82624 }
82625 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
82626 }
82627
82628 if (pn->rx_credits == 0) {
82629 - atomic_inc(&sk->sk_drops);
82630 + atomic_inc_unchecked(&sk->sk_drops);
82631 err = NET_RX_DROP;
82632 break;
82633 }
82634 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
82635 index b7e9827..c264c85 100644
82636 --- a/net/phonet/socket.c
82637 +++ b/net/phonet/socket.c
82638 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
82639 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
82640 sock_i_ino(sk),
82641 atomic_read(&sk->sk_refcnt), sk,
82642 - atomic_read(&sk->sk_drops), &len);
82643 + atomic_read_unchecked(&sk->sk_drops), &len);
82644 }
82645 seq_printf(seq, "%*s\n", 127 - len, "");
82646 return 0;
82647 diff --git a/net/rds/cong.c b/net/rds/cong.c
82648 index e5b65ac..f3b6fb7 100644
82649 --- a/net/rds/cong.c
82650 +++ b/net/rds/cong.c
82651 @@ -78,7 +78,7 @@
82652 * finds that the saved generation number is smaller than the global generation
82653 * number, it wakes up the process.
82654 */
82655 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
82656 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
82657
82658 /*
82659 * Congestion monitoring
82660 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
82661 rdsdebug("waking map %p for %pI4\n",
82662 map, &map->m_addr);
82663 rds_stats_inc(s_cong_update_received);
82664 - atomic_inc(&rds_cong_generation);
82665 + atomic_inc_unchecked(&rds_cong_generation);
82666 if (waitqueue_active(&map->m_waitq))
82667 wake_up(&map->m_waitq);
82668 if (waitqueue_active(&rds_poll_waitq))
82669 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
82670
82671 int rds_cong_updated_since(unsigned long *recent)
82672 {
82673 - unsigned long gen = atomic_read(&rds_cong_generation);
82674 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
82675
82676 if (likely(*recent == gen))
82677 return 0;
82678 diff --git a/net/rds/ib.h b/net/rds/ib.h
82679 index 7280ab8..e04f4ea 100644
82680 --- a/net/rds/ib.h
82681 +++ b/net/rds/ib.h
82682 @@ -128,7 +128,7 @@ struct rds_ib_connection {
82683 /* sending acks */
82684 unsigned long i_ack_flags;
82685 #ifdef KERNEL_HAS_ATOMIC64
82686 - atomic64_t i_ack_next; /* next ACK to send */
82687 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
82688 #else
82689 spinlock_t i_ack_lock; /* protect i_ack_next */
82690 u64 i_ack_next; /* next ACK to send */
82691 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
82692 index 31b74f5..dc1fbfa 100644
82693 --- a/net/rds/ib_cm.c
82694 +++ b/net/rds/ib_cm.c
82695 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
82696 /* Clear the ACK state */
82697 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
82698 #ifdef KERNEL_HAS_ATOMIC64
82699 - atomic64_set(&ic->i_ack_next, 0);
82700 + atomic64_set_unchecked(&ic->i_ack_next, 0);
82701 #else
82702 ic->i_ack_next = 0;
82703 #endif
82704 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
82705 index 8eb9501..0c386ff 100644
82706 --- a/net/rds/ib_recv.c
82707 +++ b/net/rds/ib_recv.c
82708 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
82709 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
82710 int ack_required)
82711 {
82712 - atomic64_set(&ic->i_ack_next, seq);
82713 + atomic64_set_unchecked(&ic->i_ack_next, seq);
82714 if (ack_required) {
82715 smp_mb__before_clear_bit();
82716 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82717 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
82718 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82719 smp_mb__after_clear_bit();
82720
82721 - return atomic64_read(&ic->i_ack_next);
82722 + return atomic64_read_unchecked(&ic->i_ack_next);
82723 }
82724 #endif
82725
82726 diff --git a/net/rds/iw.h b/net/rds/iw.h
82727 index 04ce3b1..48119a6 100644
82728 --- a/net/rds/iw.h
82729 +++ b/net/rds/iw.h
82730 @@ -134,7 +134,7 @@ struct rds_iw_connection {
82731 /* sending acks */
82732 unsigned long i_ack_flags;
82733 #ifdef KERNEL_HAS_ATOMIC64
82734 - atomic64_t i_ack_next; /* next ACK to send */
82735 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
82736 #else
82737 spinlock_t i_ack_lock; /* protect i_ack_next */
82738 u64 i_ack_next; /* next ACK to send */
82739 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
82740 index a91e1db..cf3053f 100644
82741 --- a/net/rds/iw_cm.c
82742 +++ b/net/rds/iw_cm.c
82743 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
82744 /* Clear the ACK state */
82745 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
82746 #ifdef KERNEL_HAS_ATOMIC64
82747 - atomic64_set(&ic->i_ack_next, 0);
82748 + atomic64_set_unchecked(&ic->i_ack_next, 0);
82749 #else
82750 ic->i_ack_next = 0;
82751 #endif
82752 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
82753 index 4503335..db566b4 100644
82754 --- a/net/rds/iw_recv.c
82755 +++ b/net/rds/iw_recv.c
82756 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
82757 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
82758 int ack_required)
82759 {
82760 - atomic64_set(&ic->i_ack_next, seq);
82761 + atomic64_set_unchecked(&ic->i_ack_next, seq);
82762 if (ack_required) {
82763 smp_mb__before_clear_bit();
82764 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82765 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
82766 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
82767 smp_mb__after_clear_bit();
82768
82769 - return atomic64_read(&ic->i_ack_next);
82770 + return atomic64_read_unchecked(&ic->i_ack_next);
82771 }
82772 #endif
82773
82774 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
82775 index edac9ef..16bcb98 100644
82776 --- a/net/rds/tcp.c
82777 +++ b/net/rds/tcp.c
82778 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
82779 int val = 1;
82780
82781 set_fs(KERNEL_DS);
82782 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
82783 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
82784 sizeof(val));
82785 set_fs(oldfs);
82786 }
82787 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
82788 index 81cf5a4..b5826ff 100644
82789 --- a/net/rds/tcp_send.c
82790 +++ b/net/rds/tcp_send.c
82791 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
82792
82793 oldfs = get_fs();
82794 set_fs(KERNEL_DS);
82795 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
82796 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
82797 sizeof(val));
82798 set_fs(oldfs);
82799 }
82800 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
82801 index 05996d0..5a1dfe0 100644
82802 --- a/net/rxrpc/af_rxrpc.c
82803 +++ b/net/rxrpc/af_rxrpc.c
82804 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
82805 __be32 rxrpc_epoch;
82806
82807 /* current debugging ID */
82808 -atomic_t rxrpc_debug_id;
82809 +atomic_unchecked_t rxrpc_debug_id;
82810
82811 /* count of skbs currently in use */
82812 atomic_t rxrpc_n_skbs;
82813 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
82814 index e4d9cbc..b229649 100644
82815 --- a/net/rxrpc/ar-ack.c
82816 +++ b/net/rxrpc/ar-ack.c
82817 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82818
82819 _enter("{%d,%d,%d,%d},",
82820 call->acks_hard, call->acks_unacked,
82821 - atomic_read(&call->sequence),
82822 + atomic_read_unchecked(&call->sequence),
82823 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
82824
82825 stop = 0;
82826 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
82827
82828 /* each Tx packet has a new serial number */
82829 sp->hdr.serial =
82830 - htonl(atomic_inc_return(&call->conn->serial));
82831 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
82832
82833 hdr = (struct rxrpc_header *) txb->head;
82834 hdr->serial = sp->hdr.serial;
82835 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
82836 */
82837 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
82838 {
82839 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
82840 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
82841 }
82842
82843 /*
82844 @@ -629,7 +629,7 @@ process_further:
82845
82846 latest = ntohl(sp->hdr.serial);
82847 hard = ntohl(ack.firstPacket);
82848 - tx = atomic_read(&call->sequence);
82849 + tx = atomic_read_unchecked(&call->sequence);
82850
82851 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82852 latest,
82853 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
82854 goto maybe_reschedule;
82855
82856 send_ACK_with_skew:
82857 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
82858 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
82859 ntohl(ack.serial));
82860 send_ACK:
82861 mtu = call->conn->trans->peer->if_mtu;
82862 @@ -1173,7 +1173,7 @@ send_ACK:
82863 ackinfo.rxMTU = htonl(5692);
82864 ackinfo.jumbo_max = htonl(4);
82865
82866 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82867 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82868 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
82869 ntohl(hdr.serial),
82870 ntohs(ack.maxSkew),
82871 @@ -1191,7 +1191,7 @@ send_ACK:
82872 send_message:
82873 _debug("send message");
82874
82875 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
82876 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
82877 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
82878 send_message_2:
82879
82880 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
82881 index a3bbb36..3341fb9 100644
82882 --- a/net/rxrpc/ar-call.c
82883 +++ b/net/rxrpc/ar-call.c
82884 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
82885 spin_lock_init(&call->lock);
82886 rwlock_init(&call->state_lock);
82887 atomic_set(&call->usage, 1);
82888 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
82889 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82890 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
82891
82892 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
82893 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
82894 index 4106ca9..a338d7a 100644
82895 --- a/net/rxrpc/ar-connection.c
82896 +++ b/net/rxrpc/ar-connection.c
82897 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
82898 rwlock_init(&conn->lock);
82899 spin_lock_init(&conn->state_lock);
82900 atomic_set(&conn->usage, 1);
82901 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
82902 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82903 conn->avail_calls = RXRPC_MAXCALLS;
82904 conn->size_align = 4;
82905 conn->header_size = sizeof(struct rxrpc_header);
82906 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
82907 index e7ed43a..6afa140 100644
82908 --- a/net/rxrpc/ar-connevent.c
82909 +++ b/net/rxrpc/ar-connevent.c
82910 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
82911
82912 len = iov[0].iov_len + iov[1].iov_len;
82913
82914 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
82915 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
82916 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
82917
82918 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
82919 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
82920 index 529572f..c758ca7 100644
82921 --- a/net/rxrpc/ar-input.c
82922 +++ b/net/rxrpc/ar-input.c
82923 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
82924 /* track the latest serial number on this connection for ACK packet
82925 * information */
82926 serial = ntohl(sp->hdr.serial);
82927 - hi_serial = atomic_read(&call->conn->hi_serial);
82928 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
82929 while (serial > hi_serial)
82930 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
82931 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
82932 serial);
82933
82934 /* request ACK generation for any ACK or DATA packet that requests
82935 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
82936 index a693aca..81e7293 100644
82937 --- a/net/rxrpc/ar-internal.h
82938 +++ b/net/rxrpc/ar-internal.h
82939 @@ -272,8 +272,8 @@ struct rxrpc_connection {
82940 int error; /* error code for local abort */
82941 int debug_id; /* debug ID for printks */
82942 unsigned int call_counter; /* call ID counter */
82943 - atomic_t serial; /* packet serial number counter */
82944 - atomic_t hi_serial; /* highest serial number received */
82945 + atomic_unchecked_t serial; /* packet serial number counter */
82946 + atomic_unchecked_t hi_serial; /* highest serial number received */
82947 u8 avail_calls; /* number of calls available */
82948 u8 size_align; /* data size alignment (for security) */
82949 u8 header_size; /* rxrpc + security header size */
82950 @@ -346,7 +346,7 @@ struct rxrpc_call {
82951 spinlock_t lock;
82952 rwlock_t state_lock; /* lock for state transition */
82953 atomic_t usage;
82954 - atomic_t sequence; /* Tx data packet sequence counter */
82955 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
82956 u32 abort_code; /* local/remote abort code */
82957 enum { /* current state of call */
82958 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
82959 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
82960 */
82961 extern atomic_t rxrpc_n_skbs;
82962 extern __be32 rxrpc_epoch;
82963 -extern atomic_t rxrpc_debug_id;
82964 +extern atomic_unchecked_t rxrpc_debug_id;
82965 extern struct workqueue_struct *rxrpc_workqueue;
82966
82967 /*
82968 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
82969 index 87f7135..74d3703 100644
82970 --- a/net/rxrpc/ar-local.c
82971 +++ b/net/rxrpc/ar-local.c
82972 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
82973 spin_lock_init(&local->lock);
82974 rwlock_init(&local->services_lock);
82975 atomic_set(&local->usage, 1);
82976 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
82977 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
82978 memcpy(&local->srx, srx, sizeof(*srx));
82979 }
82980
82981 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
82982 index e1ac183..b43e10e 100644
82983 --- a/net/rxrpc/ar-output.c
82984 +++ b/net/rxrpc/ar-output.c
82985 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
82986 sp->hdr.cid = call->cid;
82987 sp->hdr.callNumber = call->call_id;
82988 sp->hdr.seq =
82989 - htonl(atomic_inc_return(&call->sequence));
82990 + htonl(atomic_inc_return_unchecked(&call->sequence));
82991 sp->hdr.serial =
82992 - htonl(atomic_inc_return(&conn->serial));
82993 + htonl(atomic_inc_return_unchecked(&conn->serial));
82994 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
82995 sp->hdr.userStatus = 0;
82996 sp->hdr.securityIndex = conn->security_ix;
82997 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
82998 index bebaa43..2644591 100644
82999 --- a/net/rxrpc/ar-peer.c
83000 +++ b/net/rxrpc/ar-peer.c
83001 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
83002 INIT_LIST_HEAD(&peer->error_targets);
83003 spin_lock_init(&peer->lock);
83004 atomic_set(&peer->usage, 1);
83005 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
83006 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
83007 memcpy(&peer->srx, srx, sizeof(*srx));
83008
83009 rxrpc_assess_MTU_size(peer);
83010 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
83011 index 38047f7..9f48511 100644
83012 --- a/net/rxrpc/ar-proc.c
83013 +++ b/net/rxrpc/ar-proc.c
83014 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
83015 atomic_read(&conn->usage),
83016 rxrpc_conn_states[conn->state],
83017 key_serial(conn->key),
83018 - atomic_read(&conn->serial),
83019 - atomic_read(&conn->hi_serial));
83020 + atomic_read_unchecked(&conn->serial),
83021 + atomic_read_unchecked(&conn->hi_serial));
83022
83023 return 0;
83024 }
83025 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
83026 index 92df566..87ec1bf 100644
83027 --- a/net/rxrpc/ar-transport.c
83028 +++ b/net/rxrpc/ar-transport.c
83029 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
83030 spin_lock_init(&trans->client_lock);
83031 rwlock_init(&trans->conn_lock);
83032 atomic_set(&trans->usage, 1);
83033 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
83034 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
83035
83036 if (peer->srx.transport.family == AF_INET) {
83037 switch (peer->srx.transport_type) {
83038 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
83039 index f226709..0e735a8 100644
83040 --- a/net/rxrpc/rxkad.c
83041 +++ b/net/rxrpc/rxkad.c
83042 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
83043
83044 len = iov[0].iov_len + iov[1].iov_len;
83045
83046 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
83047 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
83048 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
83049
83050 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
83051 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
83052
83053 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
83054
83055 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
83056 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
83057 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
83058
83059 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
83060 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
83061 index 391a245..8f6a898 100644
83062 --- a/net/sctp/ipv6.c
83063 +++ b/net/sctp/ipv6.c
83064 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
83065
83066 void sctp_v6_pf_exit(void)
83067 {
83068 - list_del(&sctp_af_inet6.list);
83069 + pax_list_del((struct list_head *)&sctp_af_inet6.list);
83070 }
83071
83072 /* Initialize IPv6 support and register with socket layer. */
83073 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
83074 index 8c19e97..16264b8 100644
83075 --- a/net/sctp/proc.c
83076 +++ b/net/sctp/proc.c
83077 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
83078 seq_printf(seq,
83079 "%8pK %8pK %-3d %-3d %-2d %-4d "
83080 "%4d %8d %8d %7d %5lu %-5d %5d ",
83081 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
83082 + assoc, sk,
83083 + sctp_sk(sk)->type, sk->sk_state,
83084 assoc->state, hash,
83085 assoc->assoc_id,
83086 assoc->sndbuf_used,
83087 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
83088 index f898b1c..60bf8f2 100644
83089 --- a/net/sctp/protocol.c
83090 +++ b/net/sctp/protocol.c
83091 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
83092 return 0;
83093 }
83094
83095 - INIT_LIST_HEAD(&af->list);
83096 - list_add_tail(&af->list, &sctp_address_families);
83097 + pax_open_kernel();
83098 + INIT_LIST_HEAD((struct list_head *)&af->list);
83099 + pax_close_kernel();
83100 + pax_list_add_tail((struct list_head *)&af->list, &sctp_address_families);
83101 return 1;
83102 }
83103
83104 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
83105
83106 static void sctp_v4_pf_exit(void)
83107 {
83108 - list_del(&sctp_af_inet.list);
83109 + pax_list_del((struct list_head *)&sctp_af_inet.list);
83110 }
83111
83112 static int sctp_v4_protosw_init(void)
83113 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
83114 index cedd9bf..b1fddeb 100644
83115 --- a/net/sctp/socket.c
83116 +++ b/net/sctp/socket.c
83117 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
83118 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
83119 if (space_left < addrlen)
83120 return -ENOMEM;
83121 + if (addrlen > sizeof(temp) || addrlen < 0)
83122 + return -EFAULT;
83123 if (copy_to_user(to, &temp, addrlen))
83124 return -EFAULT;
83125 to += addrlen;
83126 diff --git a/net/socket.c b/net/socket.c
83127 index 2ca51c7..45d0b31 100644
83128 --- a/net/socket.c
83129 +++ b/net/socket.c
83130 @@ -89,6 +89,7 @@
83131 #include <linux/magic.h>
83132 #include <linux/slab.h>
83133 #include <linux/xattr.h>
83134 +#include <linux/in.h>
83135
83136 #include <asm/uaccess.h>
83137 #include <asm/unistd.h>
83138 @@ -106,6 +107,8 @@
83139 #include <linux/sockios.h>
83140 #include <linux/atalk.h>
83141
83142 +#include <linux/grsock.h>
83143 +
83144 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
83145 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
83146 unsigned long nr_segs, loff_t pos);
83147 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
83148 &sockfs_dentry_operations, SOCKFS_MAGIC);
83149 }
83150
83151 -static struct vfsmount *sock_mnt __read_mostly;
83152 +struct vfsmount *sock_mnt __read_mostly;
83153
83154 static struct file_system_type sock_fs_type = {
83155 .name = "sockfs",
83156 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
83157 return -EAFNOSUPPORT;
83158 if (type < 0 || type >= SOCK_MAX)
83159 return -EINVAL;
83160 + if (protocol < 0)
83161 + return -EINVAL;
83162
83163 /* Compatibility.
83164
83165 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
83166 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
83167 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
83168
83169 + if(!gr_search_socket(family, type, protocol)) {
83170 + retval = -EACCES;
83171 + goto out;
83172 + }
83173 +
83174 + if (gr_handle_sock_all(family, type, protocol)) {
83175 + retval = -EACCES;
83176 + goto out;
83177 + }
83178 +
83179 retval = sock_create(family, type, protocol, &sock);
83180 if (retval < 0)
83181 goto out;
83182 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
83183 if (sock) {
83184 err = move_addr_to_kernel(umyaddr, addrlen, &address);
83185 if (err >= 0) {
83186 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
83187 + err = -EACCES;
83188 + goto error;
83189 + }
83190 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
83191 + if (err)
83192 + goto error;
83193 +
83194 err = security_socket_bind(sock,
83195 (struct sockaddr *)&address,
83196 addrlen);
83197 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
83198 (struct sockaddr *)
83199 &address, addrlen);
83200 }
83201 +error:
83202 fput_light(sock->file, fput_needed);
83203 }
83204 return err;
83205 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
83206 if ((unsigned int)backlog > somaxconn)
83207 backlog = somaxconn;
83208
83209 + if (gr_handle_sock_server_other(sock->sk)) {
83210 + err = -EPERM;
83211 + goto error;
83212 + }
83213 +
83214 + err = gr_search_listen(sock);
83215 + if (err)
83216 + goto error;
83217 +
83218 err = security_socket_listen(sock, backlog);
83219 if (!err)
83220 err = sock->ops->listen(sock, backlog);
83221
83222 +error:
83223 fput_light(sock->file, fput_needed);
83224 }
83225 return err;
83226 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
83227 newsock->type = sock->type;
83228 newsock->ops = sock->ops;
83229
83230 + if (gr_handle_sock_server_other(sock->sk)) {
83231 + err = -EPERM;
83232 + sock_release(newsock);
83233 + goto out_put;
83234 + }
83235 +
83236 + err = gr_search_accept(sock);
83237 + if (err) {
83238 + sock_release(newsock);
83239 + goto out_put;
83240 + }
83241 +
83242 /*
83243 * We don't need try_module_get here, as the listening socket (sock)
83244 * has the protocol module (sock->ops->owner) held.
83245 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
83246 fd_install(newfd, newfile);
83247 err = newfd;
83248
83249 + gr_attach_curr_ip(newsock->sk);
83250 +
83251 out_put:
83252 fput_light(sock->file, fput_needed);
83253 out:
83254 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
83255 int, addrlen)
83256 {
83257 struct socket *sock;
83258 + struct sockaddr *sck;
83259 struct sockaddr_storage address;
83260 int err, fput_needed;
83261
83262 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
83263 if (err < 0)
83264 goto out_put;
83265
83266 + sck = (struct sockaddr *)&address;
83267 +
83268 + if (gr_handle_sock_client(sck)) {
83269 + err = -EACCES;
83270 + goto out_put;
83271 + }
83272 +
83273 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
83274 + if (err)
83275 + goto out_put;
83276 +
83277 err =
83278 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
83279 if (err)
83280 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
83281 * checking falls down on this.
83282 */
83283 if (copy_from_user(ctl_buf,
83284 - (void __user __force *)msg_sys->msg_control,
83285 + (void __force_user *)msg_sys->msg_control,
83286 ctl_len))
83287 goto out_freectl;
83288 msg_sys->msg_control = ctl_buf;
83289 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
83290 * kernel msghdr to use the kernel address space)
83291 */
83292
83293 - uaddr = (__force void __user *)msg_sys->msg_name;
83294 + uaddr = (void __force_user *)msg_sys->msg_name;
83295 uaddr_len = COMPAT_NAMELEN(msg);
83296 if (MSG_CMSG_COMPAT & flags) {
83297 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
83298 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
83299 }
83300
83301 ifr = compat_alloc_user_space(buf_size);
83302 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
83303 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
83304
83305 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
83306 return -EFAULT;
83307 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
83308 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
83309
83310 if (copy_in_user(rxnfc, compat_rxnfc,
83311 - (void *)(&rxnfc->fs.m_ext + 1) -
83312 - (void *)rxnfc) ||
83313 + (void __user *)(&rxnfc->fs.m_ext + 1) -
83314 + (void __user *)rxnfc) ||
83315 copy_in_user(&rxnfc->fs.ring_cookie,
83316 &compat_rxnfc->fs.ring_cookie,
83317 - (void *)(&rxnfc->fs.location + 1) -
83318 - (void *)&rxnfc->fs.ring_cookie) ||
83319 + (void __user *)(&rxnfc->fs.location + 1) -
83320 + (void __user *)&rxnfc->fs.ring_cookie) ||
83321 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
83322 sizeof(rxnfc->rule_cnt)))
83323 return -EFAULT;
83324 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
83325
83326 if (convert_out) {
83327 if (copy_in_user(compat_rxnfc, rxnfc,
83328 - (const void *)(&rxnfc->fs.m_ext + 1) -
83329 - (const void *)rxnfc) ||
83330 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
83331 + (const void __user *)rxnfc) ||
83332 copy_in_user(&compat_rxnfc->fs.ring_cookie,
83333 &rxnfc->fs.ring_cookie,
83334 - (const void *)(&rxnfc->fs.location + 1) -
83335 - (const void *)&rxnfc->fs.ring_cookie) ||
83336 + (const void __user *)(&rxnfc->fs.location + 1) -
83337 + (const void __user *)&rxnfc->fs.ring_cookie) ||
83338 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
83339 sizeof(rxnfc->rule_cnt)))
83340 return -EFAULT;
83341 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
83342 old_fs = get_fs();
83343 set_fs(KERNEL_DS);
83344 err = dev_ioctl(net, cmd,
83345 - (struct ifreq __user __force *) &kifr);
83346 + (struct ifreq __force_user *) &kifr);
83347 set_fs(old_fs);
83348
83349 return err;
83350 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
83351
83352 old_fs = get_fs();
83353 set_fs(KERNEL_DS);
83354 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
83355 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
83356 set_fs(old_fs);
83357
83358 if (cmd == SIOCGIFMAP && !err) {
83359 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
83360 ret |= __get_user(rtdev, &(ur4->rt_dev));
83361 if (rtdev) {
83362 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
83363 - r4.rt_dev = (char __user __force *)devname;
83364 + r4.rt_dev = (char __force_user *)devname;
83365 devname[15] = 0;
83366 } else
83367 r4.rt_dev = NULL;
83368 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
83369 int __user *uoptlen;
83370 int err;
83371
83372 - uoptval = (char __user __force *) optval;
83373 - uoptlen = (int __user __force *) optlen;
83374 + uoptval = (char __force_user *) optval;
83375 + uoptlen = (int __force_user *) optlen;
83376
83377 set_fs(KERNEL_DS);
83378 if (level == SOL_SOCKET)
83379 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
83380 char __user *uoptval;
83381 int err;
83382
83383 - uoptval = (char __user __force *) optval;
83384 + uoptval = (char __force_user *) optval;
83385
83386 set_fs(KERNEL_DS);
83387 if (level == SOL_SOCKET)
83388 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
83389 index fb20f25..e3ba316 100644
83390 --- a/net/sunrpc/sched.c
83391 +++ b/net/sunrpc/sched.c
83392 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
83393 #ifdef RPC_DEBUG
83394 static void rpc_task_set_debuginfo(struct rpc_task *task)
83395 {
83396 - static atomic_t rpc_pid;
83397 + static atomic_unchecked_t rpc_pid;
83398
83399 - task->tk_pid = atomic_inc_return(&rpc_pid);
83400 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
83401 }
83402 #else
83403 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
83404 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
83405 index 8343737..677025e 100644
83406 --- a/net/sunrpc/xprtrdma/svc_rdma.c
83407 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
83408 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
83409 static unsigned int min_max_inline = 4096;
83410 static unsigned int max_max_inline = 65536;
83411
83412 -atomic_t rdma_stat_recv;
83413 -atomic_t rdma_stat_read;
83414 -atomic_t rdma_stat_write;
83415 -atomic_t rdma_stat_sq_starve;
83416 -atomic_t rdma_stat_rq_starve;
83417 -atomic_t rdma_stat_rq_poll;
83418 -atomic_t rdma_stat_rq_prod;
83419 -atomic_t rdma_stat_sq_poll;
83420 -atomic_t rdma_stat_sq_prod;
83421 +atomic_unchecked_t rdma_stat_recv;
83422 +atomic_unchecked_t rdma_stat_read;
83423 +atomic_unchecked_t rdma_stat_write;
83424 +atomic_unchecked_t rdma_stat_sq_starve;
83425 +atomic_unchecked_t rdma_stat_rq_starve;
83426 +atomic_unchecked_t rdma_stat_rq_poll;
83427 +atomic_unchecked_t rdma_stat_rq_prod;
83428 +atomic_unchecked_t rdma_stat_sq_poll;
83429 +atomic_unchecked_t rdma_stat_sq_prod;
83430
83431 /* Temporary NFS request map and context caches */
83432 struct kmem_cache *svc_rdma_map_cachep;
83433 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
83434 len -= *ppos;
83435 if (len > *lenp)
83436 len = *lenp;
83437 - if (len && copy_to_user(buffer, str_buf, len))
83438 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
83439 return -EFAULT;
83440 *lenp = len;
83441 *ppos += len;
83442 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
83443 {
83444 .procname = "rdma_stat_read",
83445 .data = &rdma_stat_read,
83446 - .maxlen = sizeof(atomic_t),
83447 + .maxlen = sizeof(atomic_unchecked_t),
83448 .mode = 0644,
83449 .proc_handler = read_reset_stat,
83450 },
83451 {
83452 .procname = "rdma_stat_recv",
83453 .data = &rdma_stat_recv,
83454 - .maxlen = sizeof(atomic_t),
83455 + .maxlen = sizeof(atomic_unchecked_t),
83456 .mode = 0644,
83457 .proc_handler = read_reset_stat,
83458 },
83459 {
83460 .procname = "rdma_stat_write",
83461 .data = &rdma_stat_write,
83462 - .maxlen = sizeof(atomic_t),
83463 + .maxlen = sizeof(atomic_unchecked_t),
83464 .mode = 0644,
83465 .proc_handler = read_reset_stat,
83466 },
83467 {
83468 .procname = "rdma_stat_sq_starve",
83469 .data = &rdma_stat_sq_starve,
83470 - .maxlen = sizeof(atomic_t),
83471 + .maxlen = sizeof(atomic_unchecked_t),
83472 .mode = 0644,
83473 .proc_handler = read_reset_stat,
83474 },
83475 {
83476 .procname = "rdma_stat_rq_starve",
83477 .data = &rdma_stat_rq_starve,
83478 - .maxlen = sizeof(atomic_t),
83479 + .maxlen = sizeof(atomic_unchecked_t),
83480 .mode = 0644,
83481 .proc_handler = read_reset_stat,
83482 },
83483 {
83484 .procname = "rdma_stat_rq_poll",
83485 .data = &rdma_stat_rq_poll,
83486 - .maxlen = sizeof(atomic_t),
83487 + .maxlen = sizeof(atomic_unchecked_t),
83488 .mode = 0644,
83489 .proc_handler = read_reset_stat,
83490 },
83491 {
83492 .procname = "rdma_stat_rq_prod",
83493 .data = &rdma_stat_rq_prod,
83494 - .maxlen = sizeof(atomic_t),
83495 + .maxlen = sizeof(atomic_unchecked_t),
83496 .mode = 0644,
83497 .proc_handler = read_reset_stat,
83498 },
83499 {
83500 .procname = "rdma_stat_sq_poll",
83501 .data = &rdma_stat_sq_poll,
83502 - .maxlen = sizeof(atomic_t),
83503 + .maxlen = sizeof(atomic_unchecked_t),
83504 .mode = 0644,
83505 .proc_handler = read_reset_stat,
83506 },
83507 {
83508 .procname = "rdma_stat_sq_prod",
83509 .data = &rdma_stat_sq_prod,
83510 - .maxlen = sizeof(atomic_t),
83511 + .maxlen = sizeof(atomic_unchecked_t),
83512 .mode = 0644,
83513 .proc_handler = read_reset_stat,
83514 },
83515 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83516 index 0ce7552..d074459 100644
83517 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83518 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
83519 @@ -501,7 +501,7 @@ next_sge:
83520 svc_rdma_put_context(ctxt, 0);
83521 goto out;
83522 }
83523 - atomic_inc(&rdma_stat_read);
83524 + atomic_inc_unchecked(&rdma_stat_read);
83525
83526 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
83527 chl_map->ch[ch_no].count -= read_wr.num_sge;
83528 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
83529 dto_q);
83530 list_del_init(&ctxt->dto_q);
83531 } else {
83532 - atomic_inc(&rdma_stat_rq_starve);
83533 + atomic_inc_unchecked(&rdma_stat_rq_starve);
83534 clear_bit(XPT_DATA, &xprt->xpt_flags);
83535 ctxt = NULL;
83536 }
83537 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
83538 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
83539 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
83540 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
83541 - atomic_inc(&rdma_stat_recv);
83542 + atomic_inc_unchecked(&rdma_stat_recv);
83543
83544 /* Build up the XDR from the receive buffers. */
83545 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
83546 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83547 index c1d124d..acfc59e 100644
83548 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83549 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
83550 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
83551 write_wr.wr.rdma.remote_addr = to;
83552
83553 /* Post It */
83554 - atomic_inc(&rdma_stat_write);
83555 + atomic_inc_unchecked(&rdma_stat_write);
83556 if (svc_rdma_send(xprt, &write_wr))
83557 goto err;
83558 return 0;
83559 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
83560 index 62e4f9b..dd3f2d7 100644
83561 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
83562 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
83563 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
83564 return;
83565
83566 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
83567 - atomic_inc(&rdma_stat_rq_poll);
83568 + atomic_inc_unchecked(&rdma_stat_rq_poll);
83569
83570 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
83571 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
83572 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
83573 }
83574
83575 if (ctxt)
83576 - atomic_inc(&rdma_stat_rq_prod);
83577 + atomic_inc_unchecked(&rdma_stat_rq_prod);
83578
83579 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
83580 /*
83581 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
83582 return;
83583
83584 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
83585 - atomic_inc(&rdma_stat_sq_poll);
83586 + atomic_inc_unchecked(&rdma_stat_sq_poll);
83587 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
83588 if (wc.status != IB_WC_SUCCESS)
83589 /* Close the transport */
83590 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
83591 }
83592
83593 if (ctxt)
83594 - atomic_inc(&rdma_stat_sq_prod);
83595 + atomic_inc_unchecked(&rdma_stat_sq_prod);
83596 }
83597
83598 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
83599 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
83600 spin_lock_bh(&xprt->sc_lock);
83601 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
83602 spin_unlock_bh(&xprt->sc_lock);
83603 - atomic_inc(&rdma_stat_sq_starve);
83604 + atomic_inc_unchecked(&rdma_stat_sq_starve);
83605
83606 /* See if we can opportunistically reap SQ WR to make room */
83607 sq_cq_reap(xprt);
83608 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
83609 index 9bc6db0..47ac8c0 100644
83610 --- a/net/sysctl_net.c
83611 +++ b/net/sysctl_net.c
83612 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
83613 kgid_t root_gid = make_kgid(net->user_ns, 0);
83614
83615 /* Allow network administrator to have same access as root. */
83616 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
83617 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
83618 uid_eq(root_uid, current_uid())) {
83619 int mode = (table->mode >> 6) & 7;
83620 return (mode << 6) | (mode << 3) | mode;
83621 diff --git a/net/tipc/link.c b/net/tipc/link.c
83622 index daa6080..02d357f 100644
83623 --- a/net/tipc/link.c
83624 +++ b/net/tipc/link.c
83625 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
83626 struct tipc_msg fragm_hdr;
83627 struct sk_buff *buf, *buf_chain, *prev;
83628 u32 fragm_crs, fragm_rest, hsz, sect_rest;
83629 - const unchar *sect_crs;
83630 + const unchar __user *sect_crs;
83631 int curr_sect;
83632 u32 fragm_no;
83633
83634 @@ -1242,7 +1242,7 @@ again:
83635
83636 if (!sect_rest) {
83637 sect_rest = msg_sect[++curr_sect].iov_len;
83638 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
83639 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
83640 }
83641
83642 if (sect_rest < fragm_rest)
83643 @@ -1261,7 +1261,7 @@ error:
83644 }
83645 } else
83646 skb_copy_to_linear_data_offset(buf, fragm_crs,
83647 - sect_crs, sz);
83648 + (const void __force_kernel *)sect_crs, sz);
83649 sect_crs += sz;
83650 sect_rest -= sz;
83651 fragm_crs += sz;
83652 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
83653 index f2db8a8..9245aa4 100644
83654 --- a/net/tipc/msg.c
83655 +++ b/net/tipc/msg.c
83656 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
83657 msg_sect[cnt].iov_len);
83658 else
83659 skb_copy_to_linear_data_offset(*buf, pos,
83660 - msg_sect[cnt].iov_base,
83661 + (const void __force_kernel *)msg_sect[cnt].iov_base,
83662 msg_sect[cnt].iov_len);
83663 pos += msg_sect[cnt].iov_len;
83664 }
83665 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
83666 index 6b42d47..2ac24d5 100644
83667 --- a/net/tipc/subscr.c
83668 +++ b/net/tipc/subscr.c
83669 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
83670 {
83671 struct iovec msg_sect;
83672
83673 - msg_sect.iov_base = (void *)&sub->evt;
83674 + msg_sect.iov_base = (void __force_user *)&sub->evt;
83675 msg_sect.iov_len = sizeof(struct tipc_event);
83676
83677 sub->evt.event = htohl(event, sub->swap);
83678 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
83679 index 5b5c876..3127bf7 100644
83680 --- a/net/unix/af_unix.c
83681 +++ b/net/unix/af_unix.c
83682 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
83683 err = -ECONNREFUSED;
83684 if (!S_ISSOCK(inode->i_mode))
83685 goto put_fail;
83686 +
83687 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
83688 + err = -EACCES;
83689 + goto put_fail;
83690 + }
83691 +
83692 u = unix_find_socket_byinode(inode);
83693 if (!u)
83694 goto put_fail;
83695 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
83696 if (u) {
83697 struct dentry *dentry;
83698 dentry = unix_sk(u)->path.dentry;
83699 +
83700 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
83701 + err = -EPERM;
83702 + sock_put(u);
83703 + goto fail;
83704 + }
83705 +
83706 if (dentry)
83707 touch_atime(&unix_sk(u)->path);
83708 } else
83709 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
83710 */
83711 err = security_path_mknod(&path, dentry, mode, 0);
83712 if (!err) {
83713 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
83714 + err = -EACCES;
83715 + goto out;
83716 + }
83717 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
83718 if (!err) {
83719 res->mnt = mntget(path.mnt);
83720 res->dentry = dget(dentry);
83721 + gr_handle_create(dentry, path.mnt);
83722 }
83723 }
83724 +out:
83725 done_path_create(&path, dentry);
83726 return err;
83727 }
83728 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
83729 index c8717c1..08539f5 100644
83730 --- a/net/wireless/wext-core.c
83731 +++ b/net/wireless/wext-core.c
83732 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83733 */
83734
83735 /* Support for very large requests */
83736 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
83737 - (user_length > descr->max_tokens)) {
83738 + if (user_length > descr->max_tokens) {
83739 /* Allow userspace to GET more than max so
83740 * we can support any size GET requests.
83741 * There is still a limit : -ENOMEM.
83742 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
83743 }
83744 }
83745
83746 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
83747 - /*
83748 - * If this is a GET, but not NOMAX, it means that the extra
83749 - * data is not bounded by userspace, but by max_tokens. Thus
83750 - * set the length to max_tokens. This matches the extra data
83751 - * allocation.
83752 - * The driver should fill it with the number of tokens it
83753 - * provided, and it may check iwp->length rather than having
83754 - * knowledge of max_tokens. If the driver doesn't change the
83755 - * iwp->length, this ioctl just copies back max_token tokens
83756 - * filled with zeroes. Hopefully the driver isn't claiming
83757 - * them to be valid data.
83758 - */
83759 - iwp->length = descr->max_tokens;
83760 - }
83761 -
83762 err = handler(dev, info, (union iwreq_data *) iwp, extra);
83763
83764 iwp->length += essid_compat;
83765 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
83766 index 07c5857..edc6dc0 100644
83767 --- a/net/xfrm/xfrm_policy.c
83768 +++ b/net/xfrm/xfrm_policy.c
83769 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
83770 {
83771 policy->walk.dead = 1;
83772
83773 - atomic_inc(&policy->genid);
83774 + atomic_inc_unchecked(&policy->genid);
83775
83776 if (del_timer(&policy->timer))
83777 xfrm_pol_put(policy);
83778 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
83779 hlist_add_head(&policy->bydst, chain);
83780 xfrm_pol_hold(policy);
83781 net->xfrm.policy_count[dir]++;
83782 - atomic_inc(&flow_cache_genid);
83783 + atomic_inc_unchecked(&flow_cache_genid);
83784 rt_genid_bump(net);
83785 if (delpol)
83786 __xfrm_policy_unlink(delpol, dir);
83787 @@ -1550,7 +1550,7 @@ free_dst:
83788 goto out;
83789 }
83790
83791 -static int inline
83792 +static inline int
83793 xfrm_dst_alloc_copy(void **target, const void *src, int size)
83794 {
83795 if (!*target) {
83796 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
83797 return 0;
83798 }
83799
83800 -static int inline
83801 +static inline int
83802 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
83803 {
83804 #ifdef CONFIG_XFRM_SUB_POLICY
83805 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
83806 #endif
83807 }
83808
83809 -static int inline
83810 +static inline int
83811 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
83812 {
83813 #ifdef CONFIG_XFRM_SUB_POLICY
83814 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
83815
83816 xdst->num_pols = num_pols;
83817 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
83818 - xdst->policy_genid = atomic_read(&pols[0]->genid);
83819 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
83820
83821 return xdst;
83822 }
83823 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
83824 if (xdst->xfrm_genid != dst->xfrm->genid)
83825 return 0;
83826 if (xdst->num_pols > 0 &&
83827 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
83828 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
83829 return 0;
83830
83831 mtu = dst_mtu(dst->child);
83832 @@ -2896,7 +2896,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
83833 sizeof(pol->xfrm_vec[i].saddr));
83834 pol->xfrm_vec[i].encap_family = mp->new_family;
83835 /* flush bundles */
83836 - atomic_inc(&pol->genid);
83837 + atomic_inc_unchecked(&pol->genid);
83838 }
83839 }
83840
83841 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
83842 index 3459692..eefb515 100644
83843 --- a/net/xfrm/xfrm_state.c
83844 +++ b/net/xfrm/xfrm_state.c
83845 @@ -278,7 +278,9 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
83846 if (!try_module_get(afinfo->owner))
83847 goto out;
83848
83849 - mode->afinfo = afinfo;
83850 + pax_open_kernel();
83851 + *(void **)&mode->afinfo = afinfo;
83852 + pax_close_kernel();
83853 modemap[mode->encap] = mode;
83854 err = 0;
83855
83856 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
83857 index 0e801c3..5c8ad3b 100644
83858 --- a/scripts/Makefile.build
83859 +++ b/scripts/Makefile.build
83860 @@ -111,7 +111,7 @@ endif
83861 endif
83862
83863 # Do not include host rules unless needed
83864 -ifneq ($(hostprogs-y)$(hostprogs-m),)
83865 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
83866 include scripts/Makefile.host
83867 endif
83868
83869 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
83870 index 686cb0d..9d653bf 100644
83871 --- a/scripts/Makefile.clean
83872 +++ b/scripts/Makefile.clean
83873 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
83874 __clean-files := $(extra-y) $(always) \
83875 $(targets) $(clean-files) \
83876 $(host-progs) \
83877 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
83878 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
83879 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
83880
83881 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
83882
83883 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
83884 index 1ac414f..38575f7 100644
83885 --- a/scripts/Makefile.host
83886 +++ b/scripts/Makefile.host
83887 @@ -31,6 +31,8 @@
83888 # Note: Shared libraries consisting of C++ files are not supported
83889
83890 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
83891 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
83892 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
83893
83894 # C code
83895 # Executables compiled from a single .c file
83896 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
83897 # Shared libaries (only .c supported)
83898 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
83899 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
83900 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
83901 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
83902 # Remove .so files from "xxx-objs"
83903 host-cobjs := $(filter-out %.so,$(host-cobjs))
83904 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
83905
83906 -#Object (.o) files used by the shared libaries
83907 +# Object (.o) files used by the shared libaries
83908 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
83909 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
83910
83911 # output directory for programs/.o files
83912 # hostprogs-y := tools/build may have been specified. Retrieve directory
83913 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
83914 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
83915 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
83916 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
83917 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
83918 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
83919 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
83920 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
83921
83922 obj-dirs += $(host-objdirs)
83923 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
83924 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
83925 $(call if_changed_dep,host-cshobjs)
83926
83927 +# Compile .c file, create position independent .o file
83928 +# host-cxxshobjs -> .o
83929 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
83930 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
83931 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
83932 + $(call if_changed_dep,host-cxxshobjs)
83933 +
83934 # Link a shared library, based on position independent .o files
83935 # *.o -> .so shared library (host-cshlib)
83936 quiet_cmd_host-cshlib = HOSTLLD -shared $@
83937 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
83938 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
83939 $(call if_changed,host-cshlib)
83940
83941 +# Link a shared library, based on position independent .o files
83942 +# *.o -> .so shared library (host-cxxshlib)
83943 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
83944 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
83945 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
83946 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
83947 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
83948 + $(call if_changed,host-cxxshlib)
83949 +
83950 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
83951 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
83952 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
83953
83954 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
83955 index cb1f50c..cef2a7c 100644
83956 --- a/scripts/basic/fixdep.c
83957 +++ b/scripts/basic/fixdep.c
83958 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
83959 /*
83960 * Lookup a value in the configuration string.
83961 */
83962 -static int is_defined_config(const char *name, int len, unsigned int hash)
83963 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
83964 {
83965 struct item *aux;
83966
83967 @@ -211,10 +211,10 @@ static void clear_config(void)
83968 /*
83969 * Record the use of a CONFIG_* word.
83970 */
83971 -static void use_config(const char *m, int slen)
83972 +static void use_config(const char *m, unsigned int slen)
83973 {
83974 unsigned int hash = strhash(m, slen);
83975 - int c, i;
83976 + unsigned int c, i;
83977
83978 if (is_defined_config(m, slen, hash))
83979 return;
83980 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
83981
83982 static void parse_config_file(const char *map, size_t len)
83983 {
83984 - const int *end = (const int *) (map + len);
83985 + const unsigned int *end = (const unsigned int *) (map + len);
83986 /* start at +1, so that p can never be < map */
83987 - const int *m = (const int *) map + 1;
83988 + const unsigned int *m = (const unsigned int *) map + 1;
83989 const char *p, *q;
83990
83991 for (; m < end; m++) {
83992 @@ -406,7 +406,7 @@ static void print_deps(void)
83993 static void traps(void)
83994 {
83995 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
83996 - int *p = (int *)test;
83997 + unsigned int *p = (unsigned int *)test;
83998
83999 if (*p != INT_CONF) {
84000 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
84001 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
84002 new file mode 100644
84003 index 0000000..5e0222d
84004 --- /dev/null
84005 +++ b/scripts/gcc-plugin.sh
84006 @@ -0,0 +1,17 @@
84007 +#!/bin/bash
84008 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
84009 +#include "gcc-plugin.h"
84010 +#include "tree.h"
84011 +#include "tm.h"
84012 +#include "rtl.h"
84013 +#ifdef ENABLE_BUILD_WITH_CXX
84014 +#warning $2
84015 +#else
84016 +#warning $1
84017 +#endif
84018 +EOF`
84019 +if [ $? -eq 0 ]
84020 +then
84021 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
84022 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
84023 +fi
84024 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
84025 index b3d907e..a4782ab 100644
84026 --- a/scripts/link-vmlinux.sh
84027 +++ b/scripts/link-vmlinux.sh
84028 @@ -152,7 +152,7 @@ else
84029 fi;
84030
84031 # final build of init/
84032 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
84033 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
84034
84035 kallsymso=""
84036 kallsyms_vmlinux=""
84037 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
84038 index df4fc23..0ea719d 100644
84039 --- a/scripts/mod/file2alias.c
84040 +++ b/scripts/mod/file2alias.c
84041 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
84042 unsigned long size, unsigned long id_size,
84043 void *symval)
84044 {
84045 - int i;
84046 + unsigned int i;
84047
84048 if (size % id_size || size < id_size) {
84049 if (cross_build != 0)
84050 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
84051 /* USB is special because the bcdDevice can be matched against a numeric range */
84052 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
84053 static void do_usb_entry(struct usb_device_id *id,
84054 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
84055 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
84056 unsigned char range_lo, unsigned char range_hi,
84057 unsigned char max, struct module *mod)
84058 {
84059 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
84060 {
84061 unsigned int devlo, devhi;
84062 unsigned char chi, clo, max;
84063 - int ndigits;
84064 + unsigned int ndigits;
84065
84066 id->match_flags = TO_NATIVE(id->match_flags);
84067 id->idVendor = TO_NATIVE(id->idVendor);
84068 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
84069 for (i = 0; i < count; i++) {
84070 const char *id = (char *)devs[i].id;
84071 char acpi_id[sizeof(devs[0].id)];
84072 - int j;
84073 + unsigned int j;
84074
84075 buf_printf(&mod->dev_table_buf,
84076 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
84077 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
84078
84079 for (j = 0; j < PNP_MAX_DEVICES; j++) {
84080 const char *id = (char *)card->devs[j].id;
84081 - int i2, j2;
84082 + unsigned int i2, j2;
84083 int dup = 0;
84084
84085 if (!id[0])
84086 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
84087 /* add an individual alias for every device entry */
84088 if (!dup) {
84089 char acpi_id[sizeof(card->devs[0].id)];
84090 - int k;
84091 + unsigned int k;
84092
84093 buf_printf(&mod->dev_table_buf,
84094 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
84095 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
84096 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
84097 char *alias)
84098 {
84099 - int i, j;
84100 + unsigned int i, j;
84101
84102 sprintf(alias, "dmi*");
84103
84104 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
84105 index ff36c50..7ab4fa9 100644
84106 --- a/scripts/mod/modpost.c
84107 +++ b/scripts/mod/modpost.c
84108 @@ -929,6 +929,7 @@ enum mismatch {
84109 ANY_INIT_TO_ANY_EXIT,
84110 ANY_EXIT_TO_ANY_INIT,
84111 EXPORT_TO_INIT_EXIT,
84112 + DATA_TO_TEXT
84113 };
84114
84115 struct sectioncheck {
84116 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
84117 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
84118 .mismatch = EXPORT_TO_INIT_EXIT,
84119 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
84120 +},
84121 +/* Do not reference code from writable data */
84122 +{
84123 + .fromsec = { DATA_SECTIONS, NULL },
84124 + .tosec = { TEXT_SECTIONS, NULL },
84125 + .mismatch = DATA_TO_TEXT
84126 }
84127 };
84128
84129 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
84130 continue;
84131 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
84132 continue;
84133 - if (sym->st_value == addr)
84134 - return sym;
84135 /* Find a symbol nearby - addr are maybe negative */
84136 d = sym->st_value - addr;
84137 + if (d == 0)
84138 + return sym;
84139 if (d < 0)
84140 d = addr - sym->st_value;
84141 if (d < distance) {
84142 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
84143 tosym, prl_to, prl_to, tosym);
84144 free(prl_to);
84145 break;
84146 + case DATA_TO_TEXT:
84147 +#if 0
84148 + fprintf(stderr,
84149 + "The %s %s:%s references\n"
84150 + "the %s %s:%s%s\n",
84151 + from, fromsec, fromsym, to, tosec, tosym, to_p);
84152 +#endif
84153 + break;
84154 }
84155 fprintf(stderr, "\n");
84156 }
84157 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
84158 static void check_sec_ref(struct module *mod, const char *modname,
84159 struct elf_info *elf)
84160 {
84161 - int i;
84162 + unsigned int i;
84163 Elf_Shdr *sechdrs = elf->sechdrs;
84164
84165 /* Walk through all sections */
84166 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
84167 va_end(ap);
84168 }
84169
84170 -void buf_write(struct buffer *buf, const char *s, int len)
84171 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
84172 {
84173 if (buf->size - buf->pos < len) {
84174 buf->size += len + SZ;
84175 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
84176 if (fstat(fileno(file), &st) < 0)
84177 goto close_write;
84178
84179 - if (st.st_size != b->pos)
84180 + if (st.st_size != (off_t)b->pos)
84181 goto close_write;
84182
84183 tmp = NOFAIL(malloc(b->pos));
84184 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
84185 index 51207e4..f7d603d 100644
84186 --- a/scripts/mod/modpost.h
84187 +++ b/scripts/mod/modpost.h
84188 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
84189
84190 struct buffer {
84191 char *p;
84192 - int pos;
84193 - int size;
84194 + unsigned int pos;
84195 + unsigned int size;
84196 };
84197
84198 void __attribute__((format(printf, 2, 3)))
84199 buf_printf(struct buffer *buf, const char *fmt, ...);
84200
84201 void
84202 -buf_write(struct buffer *buf, const char *s, int len);
84203 +buf_write(struct buffer *buf, const char *s, unsigned int len);
84204
84205 struct module {
84206 struct module *next;
84207 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
84208 index 9dfcd6d..099068e 100644
84209 --- a/scripts/mod/sumversion.c
84210 +++ b/scripts/mod/sumversion.c
84211 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
84212 goto out;
84213 }
84214
84215 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
84216 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
84217 warn("writing sum in %s failed: %s\n",
84218 filename, strerror(errno));
84219 goto out;
84220 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
84221 index 68bb4ef..2f419e1 100644
84222 --- a/scripts/pnmtologo.c
84223 +++ b/scripts/pnmtologo.c
84224 @@ -244,14 +244,14 @@ static void write_header(void)
84225 fprintf(out, " * Linux logo %s\n", logoname);
84226 fputs(" */\n\n", out);
84227 fputs("#include <linux/linux_logo.h>\n\n", out);
84228 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
84229 + fprintf(out, "static unsigned char %s_data[] = {\n",
84230 logoname);
84231 }
84232
84233 static void write_footer(void)
84234 {
84235 fputs("\n};\n\n", out);
84236 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
84237 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
84238 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
84239 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
84240 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
84241 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
84242 fputs("\n};\n\n", out);
84243
84244 /* write logo clut */
84245 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
84246 + fprintf(out, "static unsigned char %s_clut[] = {\n",
84247 logoname);
84248 write_hex_cnt = 0;
84249 for (i = 0; i < logo_clutsize; i++) {
84250 diff --git a/security/Kconfig b/security/Kconfig
84251 index e9c6ac7..ab9590d 100644
84252 --- a/security/Kconfig
84253 +++ b/security/Kconfig
84254 @@ -4,6 +4,902 @@
84255
84256 menu "Security options"
84257
84258 +menu "Grsecurity"
84259 +
84260 + config ARCH_TRACK_EXEC_LIMIT
84261 + bool
84262 +
84263 + config PAX_KERNEXEC_PLUGIN
84264 + bool
84265 +
84266 + config PAX_PER_CPU_PGD
84267 + bool
84268 +
84269 + config TASK_SIZE_MAX_SHIFT
84270 + int
84271 + depends on X86_64
84272 + default 47 if !PAX_PER_CPU_PGD
84273 + default 42 if PAX_PER_CPU_PGD
84274 +
84275 + config PAX_ENABLE_PAE
84276 + bool
84277 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
84278 +
84279 + config PAX_USERCOPY_SLABS
84280 + bool
84281 +
84282 +config GRKERNSEC
84283 + bool "Grsecurity"
84284 + select CRYPTO
84285 + select CRYPTO_SHA256
84286 + select PROC_FS
84287 + select STOP_MACHINE
84288 + help
84289 + If you say Y here, you will be able to configure many features
84290 + that will enhance the security of your system. It is highly
84291 + recommended that you say Y here and read through the help
84292 + for each option so that you fully understand the features and
84293 + can evaluate their usefulness for your machine.
84294 +
84295 +choice
84296 + prompt "Configuration Method"
84297 + depends on GRKERNSEC
84298 + default GRKERNSEC_CONFIG_CUSTOM
84299 + help
84300 +
84301 +config GRKERNSEC_CONFIG_AUTO
84302 + bool "Automatic"
84303 + help
84304 + If you choose this configuration method, you'll be able to answer a small
84305 + number of simple questions about how you plan to use this kernel.
84306 + The settings of grsecurity and PaX will be automatically configured for
84307 + the highest commonly-used settings within the provided constraints.
84308 +
84309 + If you require additional configuration, custom changes can still be made
84310 + from the "custom configuration" menu.
84311 +
84312 +config GRKERNSEC_CONFIG_CUSTOM
84313 + bool "Custom"
84314 + help
84315 + If you choose this configuration method, you'll be able to configure all
84316 + grsecurity and PaX settings manually. Via this method, no options are
84317 + automatically enabled.
84318 +
84319 +endchoice
84320 +
84321 +choice
84322 + prompt "Usage Type"
84323 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84324 + default GRKERNSEC_CONFIG_SERVER
84325 + help
84326 +
84327 +config GRKERNSEC_CONFIG_SERVER
84328 + bool "Server"
84329 + help
84330 + Choose this option if you plan to use this kernel on a server.
84331 +
84332 +config GRKERNSEC_CONFIG_DESKTOP
84333 + bool "Desktop"
84334 + help
84335 + Choose this option if you plan to use this kernel on a desktop.
84336 +
84337 +endchoice
84338 +
84339 +choice
84340 + prompt "Virtualization Type"
84341 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
84342 + default GRKERNSEC_CONFIG_VIRT_NONE
84343 + help
84344 +
84345 +config GRKERNSEC_CONFIG_VIRT_NONE
84346 + bool "None"
84347 + help
84348 + Choose this option if this kernel will be run on bare metal.
84349 +
84350 +config GRKERNSEC_CONFIG_VIRT_GUEST
84351 + bool "Guest"
84352 + help
84353 + Choose this option if this kernel will be run as a VM guest.
84354 +
84355 +config GRKERNSEC_CONFIG_VIRT_HOST
84356 + bool "Host"
84357 + help
84358 + Choose this option if this kernel will be run as a VM host.
84359 +
84360 +endchoice
84361 +
84362 +choice
84363 + prompt "Virtualization Hardware"
84364 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
84365 + help
84366 +
84367 +config GRKERNSEC_CONFIG_VIRT_EPT
84368 + bool "EPT/RVI Processor Support"
84369 + depends on X86
84370 + help
84371 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
84372 + hardware virtualization. This allows for additional kernel hardening protections
84373 + to operate without additional performance impact.
84374 +
84375 + To see if your Intel processor supports EPT, see:
84376 + http://ark.intel.com/Products/VirtualizationTechnology
84377 + (Most Core i3/5/7 support EPT)
84378 +
84379 + To see if your AMD processor supports RVI, see:
84380 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
84381 +
84382 +config GRKERNSEC_CONFIG_VIRT_SOFT
84383 + bool "First-gen/No Hardware Virtualization"
84384 + help
84385 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
84386 + support hardware virtualization or doesn't support the EPT/RVI extensions.
84387 +
84388 +endchoice
84389 +
84390 +choice
84391 + prompt "Virtualization Software"
84392 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
84393 + help
84394 +
84395 +config GRKERNSEC_CONFIG_VIRT_XEN
84396 + bool "Xen"
84397 + help
84398 + Choose this option if this kernel is running as a Xen guest or host.
84399 +
84400 +config GRKERNSEC_CONFIG_VIRT_VMWARE
84401 + bool "VMWare"
84402 + help
84403 + Choose this option if this kernel is running as a VMWare guest or host.
84404 +
84405 +config GRKERNSEC_CONFIG_VIRT_KVM
84406 + bool "KVM"
84407 + help
84408 + Choose this option if this kernel is running as a KVM guest or host.
84409 +
84410 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
84411 + bool "VirtualBox"
84412 + help
84413 + Choose this option if this kernel is running as a VirtualBox guest or host.
84414 +
84415 +endchoice
84416 +
84417 +choice
84418 + prompt "Required Priorities"
84419 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84420 + default GRKERNSEC_CONFIG_PRIORITY_PERF
84421 + help
84422 +
84423 +config GRKERNSEC_CONFIG_PRIORITY_PERF
84424 + bool "Performance"
84425 + help
84426 + Choose this option if performance is of highest priority for this deployment
84427 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
84428 + and freed memory sanitizing will be disabled.
84429 +
84430 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
84431 + bool "Security"
84432 + help
84433 + Choose this option if security is of highest priority for this deployment of
84434 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
84435 + be enabled for this kernel. In a worst-case scenario, these features can
84436 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
84437 +
84438 +endchoice
84439 +
84440 +menu "Default Special Groups"
84441 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
84442 +
84443 +config GRKERNSEC_PROC_GID
84444 + int "GID exempted from /proc restrictions"
84445 + default 1001
84446 + help
84447 + Setting this GID determines which group will be exempted from
84448 + grsecurity's /proc restrictions, allowing users of the specified
84449 + group to view network statistics and the existence of other users'
84450 + processes on the system. This GID may also be chosen at boot time
84451 + via "grsec_proc_gid=" on the kernel commandline.
84452 +
84453 +config GRKERNSEC_TPE_UNTRUSTED_GID
84454 + int "GID for TPE-untrusted users"
84455 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
84456 + default 1005
84457 + help
84458 + Setting this GID determines which group untrusted users should
84459 + be added to. These users will be placed under grsecurity's Trusted Path
84460 + Execution mechanism, preventing them from executing their own binaries.
84461 + The users will only be able to execute binaries in directories owned and
84462 + writable only by the root user. If the sysctl option is enabled, a sysctl
84463 + option with name "tpe_gid" is created.
84464 +
84465 +config GRKERNSEC_TPE_TRUSTED_GID
84466 + int "GID for TPE-trusted users"
84467 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
84468 + default 1005
84469 + help
84470 + Setting this GID determines what group TPE restrictions will be
84471 + *disabled* for. If the sysctl option is enabled, a sysctl option
84472 + with name "tpe_gid" is created.
84473 +
84474 +config GRKERNSEC_SYMLINKOWN_GID
84475 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
84476 + depends on GRKERNSEC_CONFIG_SERVER
84477 + default 1006
84478 + help
84479 + Setting this GID determines what group kernel-enforced
84480 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
84481 + is enabled, a sysctl option with name "symlinkown_gid" is created.
84482 +
84483 +
84484 +endmenu
84485 +
84486 +menu "Customize Configuration"
84487 +depends on GRKERNSEC
84488 +
84489 +menu "PaX"
84490 +
84491 +config PAX
84492 + bool "Enable various PaX features"
84493 + default y if GRKERNSEC_CONFIG_AUTO
84494 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
84495 + help
84496 + This allows you to enable various PaX features. PaX adds
84497 + intrusion prevention mechanisms to the kernel that reduce
84498 + the risks posed by exploitable memory corruption bugs.
84499 +
84500 +menu "PaX Control"
84501 + depends on PAX
84502 +
84503 +config PAX_SOFTMODE
84504 + bool 'Support soft mode'
84505 + help
84506 + Enabling this option will allow you to run PaX in soft mode, that
84507 + is, PaX features will not be enforced by default, only on executables
84508 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
84509 + support as they are the only way to mark executables for soft mode use.
84510 +
84511 + Soft mode can be activated by using the "pax_softmode=1" kernel command
84512 + line option on boot. Furthermore you can control various PaX features
84513 + at runtime via the entries in /proc/sys/kernel/pax.
84514 +
84515 +config PAX_EI_PAX
84516 + bool 'Use legacy ELF header marking'
84517 + default y if GRKERNSEC_CONFIG_AUTO
84518 + help
84519 + Enabling this option will allow you to control PaX features on
84520 + a per executable basis via the 'chpax' utility available at
84521 + http://pax.grsecurity.net/. The control flags will be read from
84522 + an otherwise reserved part of the ELF header. This marking has
84523 + numerous drawbacks (no support for soft-mode, toolchain does not
84524 + know about the non-standard use of the ELF header) therefore it
84525 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
84526 + support.
84527 +
84528 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
84529 + support as well, they will override the legacy EI_PAX marks.
84530 +
84531 + If you enable none of the marking options then all applications
84532 + will run with PaX enabled on them by default.
84533 +
84534 +config PAX_PT_PAX_FLAGS
84535 + bool 'Use ELF program header marking'
84536 + default y if GRKERNSEC_CONFIG_AUTO
84537 + help
84538 + Enabling this option will allow you to control PaX features on
84539 + a per executable basis via the 'paxctl' utility available at
84540 + http://pax.grsecurity.net/. The control flags will be read from
84541 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
84542 + has the benefits of supporting both soft mode and being fully
84543 + integrated into the toolchain (the binutils patch is available
84544 + from http://pax.grsecurity.net).
84545 +
84546 + Note that if you enable the legacy EI_PAX marking support as well,
84547 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
84548 +
84549 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
84550 + must make sure that the marks are the same if a binary has both marks.
84551 +
84552 + If you enable none of the marking options then all applications
84553 + will run with PaX enabled on them by default.
84554 +
84555 +config PAX_XATTR_PAX_FLAGS
84556 + bool 'Use filesystem extended attributes marking'
84557 + default y if GRKERNSEC_CONFIG_AUTO
84558 + select CIFS_XATTR if CIFS
84559 + select EXT2_FS_XATTR if EXT2_FS
84560 + select EXT3_FS_XATTR if EXT3_FS
84561 + select EXT4_FS_XATTR if EXT4_FS
84562 + select JFFS2_FS_XATTR if JFFS2_FS
84563 + select REISERFS_FS_XATTR if REISERFS_FS
84564 + select SQUASHFS_XATTR if SQUASHFS
84565 + select TMPFS_XATTR if TMPFS
84566 + select UBIFS_FS_XATTR if UBIFS_FS
84567 + help
84568 + Enabling this option will allow you to control PaX features on
84569 + a per executable basis via the 'setfattr' utility. The control
84570 + flags will be read from the user.pax.flags extended attribute of
84571 + the file. This marking has the benefit of supporting binary-only
84572 + applications that self-check themselves (e.g., skype) and would
84573 + not tolerate chpax/paxctl changes. The main drawback is that
84574 + extended attributes are not supported by some filesystems (e.g.,
84575 + isofs, udf, vfat) so copying files through such filesystems will
84576 + lose the extended attributes and these PaX markings.
84577 +
84578 + Note that if you enable the legacy EI_PAX marking support as well,
84579 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
84580 +
84581 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
84582 + must make sure that the marks are the same if a binary has both marks.
84583 +
84584 + If you enable none of the marking options then all applications
84585 + will run with PaX enabled on them by default.
84586 +
84587 +choice
84588 + prompt 'MAC system integration'
84589 + default PAX_HAVE_ACL_FLAGS
84590 + help
84591 + Mandatory Access Control systems have the option of controlling
84592 + PaX flags on a per executable basis, choose the method supported
84593 + by your particular system.
84594 +
84595 + - "none": if your MAC system does not interact with PaX,
84596 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
84597 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
84598 +
84599 + NOTE: this option is for developers/integrators only.
84600 +
84601 + config PAX_NO_ACL_FLAGS
84602 + bool 'none'
84603 +
84604 + config PAX_HAVE_ACL_FLAGS
84605 + bool 'direct'
84606 +
84607 + config PAX_HOOK_ACL_FLAGS
84608 + bool 'hook'
84609 +endchoice
84610 +
84611 +endmenu
84612 +
84613 +menu "Non-executable pages"
84614 + depends on PAX
84615 +
84616 +config PAX_NOEXEC
84617 + bool "Enforce non-executable pages"
84618 + default y if GRKERNSEC_CONFIG_AUTO
84619 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
84620 + help
84621 + By design some architectures do not allow for protecting memory
84622 + pages against execution or even if they do, Linux does not make
84623 + use of this feature. In practice this means that if a page is
84624 + readable (such as the stack or heap) it is also executable.
84625 +
84626 + There is a well known exploit technique that makes use of this
84627 + fact and a common programming mistake where an attacker can
84628 + introduce code of his choice somewhere in the attacked program's
84629 + memory (typically the stack or the heap) and then execute it.
84630 +
84631 + If the attacked program was running with different (typically
84632 + higher) privileges than that of the attacker, then he can elevate
84633 + his own privilege level (e.g. get a root shell, write to files for
84634 + which he does not have write access to, etc).
84635 +
84636 + Enabling this option will let you choose from various features
84637 + that prevent the injection and execution of 'foreign' code in
84638 + a program.
84639 +
84640 + This will also break programs that rely on the old behaviour and
84641 + expect that dynamically allocated memory via the malloc() family
84642 + of functions is executable (which it is not). Notable examples
84643 + are the XFree86 4.x server, the java runtime and wine.
84644 +
84645 +config PAX_PAGEEXEC
84646 + bool "Paging based non-executable pages"
84647 + default y if GRKERNSEC_CONFIG_AUTO
84648 + depends on PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MATOM || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
84649 + select S390_SWITCH_AMODE if S390
84650 + select S390_EXEC_PROTECT if S390
84651 + select ARCH_TRACK_EXEC_LIMIT if X86_32
84652 + help
84653 + This implementation is based on the paging feature of the CPU.
84654 + On i386 without hardware non-executable bit support there is a
84655 + variable but usually low performance impact, however on Intel's
84656 + P4 core based CPUs it is very high so you should not enable this
84657 + for kernels meant to be used on such CPUs.
84658 +
84659 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
84660 + with hardware non-executable bit support there is no performance
84661 + impact, on ppc the impact is negligible.
84662 +
84663 + Note that several architectures require various emulations due to
84664 + badly designed userland ABIs, this will cause a performance impact
84665 + but will disappear as soon as userland is fixed. For example, ppc
84666 + userland MUST have been built with secure-plt by a recent toolchain.
84667 +
84668 +config PAX_SEGMEXEC
84669 + bool "Segmentation based non-executable pages"
84670 + default y if GRKERNSEC_CONFIG_AUTO
84671 + depends on PAX_NOEXEC && X86_32
84672 + help
84673 + This implementation is based on the segmentation feature of the
84674 + CPU and has a very small performance impact, however applications
84675 + will be limited to a 1.5 GB address space instead of the normal
84676 + 3 GB.
84677 +
84678 +config PAX_EMUTRAMP
84679 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
84680 + default y if PARISC
84681 + help
84682 + There are some programs and libraries that for one reason or
84683 + another attempt to execute special small code snippets from
84684 + non-executable memory pages. Most notable examples are the
84685 + signal handler return code generated by the kernel itself and
84686 + the GCC trampolines.
84687 +
84688 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
84689 + such programs will no longer work under your kernel.
84690 +
84691 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
84692 + utilities to enable trampoline emulation for the affected programs
84693 + yet still have the protection provided by the non-executable pages.
84694 +
84695 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
84696 + your system will not even boot.
84697 +
84698 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
84699 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
84700 + for the affected files.
84701 +
84702 + NOTE: enabling this feature *may* open up a loophole in the
84703 + protection provided by non-executable pages that an attacker
84704 + could abuse. Therefore the best solution is to not have any
84705 + files on your system that would require this option. This can
84706 + be achieved by not using libc5 (which relies on the kernel
84707 + signal handler return code) and not using or rewriting programs
84708 + that make use of the nested function implementation of GCC.
84709 + Skilled users can just fix GCC itself so that it implements
84710 + nested function calls in a way that does not interfere with PaX.
84711 +
84712 +config PAX_EMUSIGRT
84713 + bool "Automatically emulate sigreturn trampolines"
84714 + depends on PAX_EMUTRAMP && PARISC
84715 + default y
84716 + help
84717 + Enabling this option will have the kernel automatically detect
84718 + and emulate signal return trampolines executing on the stack
84719 + that would otherwise lead to task termination.
84720 +
84721 + This solution is intended as a temporary one for users with
84722 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
84723 + Modula-3 runtime, etc) or executables linked to such, basically
84724 + everything that does not specify its own SA_RESTORER function in
84725 + normal executable memory like glibc 2.1+ does.
84726 +
84727 + On parisc you MUST enable this option, otherwise your system will
84728 + not even boot.
84729 +
84730 + NOTE: this feature cannot be disabled on a per executable basis
84731 + and since it *does* open up a loophole in the protection provided
84732 + by non-executable pages, the best solution is to not have any
84733 + files on your system that would require this option.
84734 +
84735 +config PAX_MPROTECT
84736 + bool "Restrict mprotect()"
84737 + default y if GRKERNSEC_CONFIG_AUTO
84738 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
84739 + help
84740 + Enabling this option will prevent programs from
84741 + - changing the executable status of memory pages that were
84742 + not originally created as executable,
84743 + - making read-only executable pages writable again,
84744 + - creating executable pages from anonymous memory,
84745 + - making read-only-after-relocations (RELRO) data pages writable again.
84746 +
84747 + You should say Y here to complete the protection provided by
84748 + the enforcement of non-executable pages.
84749 +
84750 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
84751 + this feature on a per file basis.
84752 +
84753 +config PAX_MPROTECT_COMPAT
84754 + bool "Use legacy/compat protection demoting (read help)"
84755 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
84756 + depends on PAX_MPROTECT
84757 + help
84758 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
84759 + by sending the proper error code to the application. For some broken
84760 + userland, this can cause problems with Python or other applications. The
84761 + current implementation however allows for applications like clamav to
84762 + detect if JIT compilation/execution is allowed and to fall back gracefully
84763 + to an interpreter-based mode if it does not. While we encourage everyone
84764 + to use the current implementation as-is and push upstream to fix broken
84765 + userland (note that the RWX logging option can assist with this), in some
84766 + environments this may not be possible. Having to disable MPROTECT
84767 + completely on certain binaries reduces the security benefit of PaX,
84768 + so this option is provided for those environments to revert to the old
84769 + behavior.
84770 +
84771 +config PAX_ELFRELOCS
84772 + bool "Allow ELF text relocations (read help)"
84773 + depends on PAX_MPROTECT
84774 + default n
84775 + help
84776 + Non-executable pages and mprotect() restrictions are effective
84777 + in preventing the introduction of new executable code into an
84778 + attacked task's address space. There remain only two venues
84779 + for this kind of attack: if the attacker can execute already
84780 + existing code in the attacked task then he can either have it
84781 + create and mmap() a file containing his code or have it mmap()
84782 + an already existing ELF library that does not have position
84783 + independent code in it and use mprotect() on it to make it
84784 + writable and copy his code there. While protecting against
84785 + the former approach is beyond PaX, the latter can be prevented
84786 + by having only PIC ELF libraries on one's system (which do not
84787 + need to relocate their code). If you are sure this is your case,
84788 + as is the case with all modern Linux distributions, then leave
84789 + this option disabled. You should say 'n' here.
84790 +
84791 +config PAX_ETEXECRELOCS
84792 + bool "Allow ELF ET_EXEC text relocations"
84793 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
84794 + select PAX_ELFRELOCS
84795 + default y
84796 + help
84797 + On some architectures there are incorrectly created applications
84798 + that require text relocations and would not work without enabling
84799 + this option. If you are an alpha, ia64 or parisc user, you should
84800 + enable this option and disable it once you have made sure that
84801 + none of your applications need it.
84802 +
84803 +config PAX_EMUPLT
84804 + bool "Automatically emulate ELF PLT"
84805 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
84806 + default y
84807 + help
84808 + Enabling this option will have the kernel automatically detect
84809 + and emulate the Procedure Linkage Table entries in ELF files.
84810 + On some architectures such entries are in writable memory, and
84811 + become non-executable leading to task termination. Therefore
84812 + it is mandatory that you enable this option on alpha, parisc,
84813 + sparc and sparc64, otherwise your system would not even boot.
84814 +
84815 + NOTE: this feature *does* open up a loophole in the protection
84816 + provided by the non-executable pages, therefore the proper
84817 + solution is to modify the toolchain to produce a PLT that does
84818 + not need to be writable.
84819 +
84820 +config PAX_DLRESOLVE
84821 + bool 'Emulate old glibc resolver stub'
84822 + depends on PAX_EMUPLT && SPARC
84823 + default n
84824 + help
84825 + This option is needed if userland has an old glibc (before 2.4)
84826 + that puts a 'save' instruction into the runtime generated resolver
84827 + stub that needs special emulation.
84828 +
84829 +config PAX_KERNEXEC
84830 + bool "Enforce non-executable kernel pages"
84831 + default y if GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
84832 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
84833 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
84834 + select PAX_KERNEXEC_PLUGIN if X86_64
84835 + help
84836 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
84837 + that is, enabling this option will make it harder to inject
84838 + and execute 'foreign' code in kernel memory itself.
84839 +
84840 +choice
84841 + prompt "Return Address Instrumentation Method"
84842 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
84843 + depends on PAX_KERNEXEC_PLUGIN
84844 + help
84845 + Select the method used to instrument function pointer dereferences.
84846 + Note that binary modules cannot be instrumented by this approach.
84847 +
84848 + Note that the implementation requires a gcc with plugin support,
84849 + i.e., gcc 4.5 or newer. You may need to install the supporting
84850 + headers explicitly in addition to the normal gcc package.
84851 +
84852 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
84853 + bool "bts"
84854 + help
84855 + This method is compatible with binary only modules but has
84856 + a higher runtime overhead.
84857 +
84858 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
84859 + bool "or"
84860 + depends on !PARAVIRT
84861 + help
84862 + This method is incompatible with binary only modules but has
84863 + a lower runtime overhead.
84864 +endchoice
84865 +
84866 +config PAX_KERNEXEC_PLUGIN_METHOD
84867 + string
84868 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
84869 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
84870 + default ""
84871 +
84872 +config PAX_KERNEXEC_MODULE_TEXT
84873 + int "Minimum amount of memory reserved for module code"
84874 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
84875 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
84876 + depends on PAX_KERNEXEC && X86_32 && MODULES
84877 + help
84878 + Due to implementation details the kernel must reserve a fixed
84879 + amount of memory for module code at compile time that cannot be
84880 + changed at runtime. Here you can specify the minimum amount
84881 + in MB that will be reserved. Due to the same implementation
84882 + details this size will always be rounded up to the next 2/4 MB
84883 + boundary (depends on PAE) so the actually available memory for
84884 + module code will usually be more than this minimum.
84885 +
84886 + The default 4 MB should be enough for most users but if you have
84887 + an excessive number of modules (e.g., most distribution configs
84888 + compile many drivers as modules) or use huge modules such as
84889 + nvidia's kernel driver, you will need to adjust this amount.
84890 + A good rule of thumb is to look at your currently loaded kernel
84891 + modules and add up their sizes.
84892 +
84893 +endmenu
84894 +
84895 +menu "Address Space Layout Randomization"
84896 + depends on PAX
84897 +
84898 +config PAX_ASLR
84899 + bool "Address Space Layout Randomization"
84900 + default y if GRKERNSEC_CONFIG_AUTO
84901 + help
84902 + Many if not most exploit techniques rely on the knowledge of
84903 + certain addresses in the attacked program. The following options
84904 + will allow the kernel to apply a certain amount of randomization
84905 + to specific parts of the program thereby forcing an attacker to
84906 + guess them in most cases. Any failed guess will most likely crash
84907 + the attacked program which allows the kernel to detect such attempts
84908 + and react on them. PaX itself provides no reaction mechanisms,
84909 + instead it is strongly encouraged that you make use of Nergal's
84910 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
84911 + (http://www.grsecurity.net/) built-in crash detection features or
84912 + develop one yourself.
84913 +
84914 + By saying Y here you can choose to randomize the following areas:
84915 + - top of the task's kernel stack
84916 + - top of the task's userland stack
84917 + - base address for mmap() requests that do not specify one
84918 + (this includes all libraries)
84919 + - base address of the main executable
84920 +
84921 + It is strongly recommended to say Y here as address space layout
84922 + randomization has negligible impact on performance yet it provides
84923 + a very effective protection.
84924 +
84925 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
84926 + this feature on a per file basis.
84927 +
84928 +config PAX_RANDKSTACK
84929 + bool "Randomize kernel stack base"
84930 + default y if GRKERNSEC_CONFIG_AUTO
84931 + depends on X86_TSC && X86
84932 + help
84933 + By saying Y here the kernel will randomize every task's kernel
84934 + stack on every system call. This will not only force an attacker
84935 + to guess it but also prevent him from making use of possible
84936 + leaked information about it.
84937 +
84938 + Since the kernel stack is a rather scarce resource, randomization
84939 + may cause unexpected stack overflows, therefore you should very
84940 + carefully test your system. Note that once enabled in the kernel
84941 + configuration, this feature cannot be disabled on a per file basis.
84942 +
84943 +config PAX_RANDUSTACK
84944 + bool "Randomize user stack base"
84945 + default y if GRKERNSEC_CONFIG_AUTO
84946 + depends on PAX_ASLR
84947 + help
84948 + By saying Y here the kernel will randomize every task's userland
84949 + stack. The randomization is done in two steps where the second
84950 + one may apply a big amount of shift to the top of the stack and
84951 + cause problems for programs that want to use lots of memory (more
84952 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
84953 + For this reason the second step can be controlled by 'chpax' or
84954 + 'paxctl' on a per file basis.
84955 +
84956 +config PAX_RANDMMAP
84957 + bool "Randomize mmap() base"
84958 + default y if GRKERNSEC_CONFIG_AUTO
84959 + depends on PAX_ASLR
84960 + help
84961 + By saying Y here the kernel will use a randomized base address for
84962 + mmap() requests that do not specify one themselves. As a result
84963 + all dynamically loaded libraries will appear at random addresses
84964 + and therefore be harder to exploit by a technique where an attacker
84965 + attempts to execute library code for his purposes (e.g. spawn a
84966 + shell from an exploited program that is running at an elevated
84967 + privilege level).
84968 +
84969 + Furthermore, if a program is relinked as a dynamic ELF file, its
84970 + base address will be randomized as well, completing the full
84971 + randomization of the address space layout. Attacking such programs
84972 + becomes a guess game. You can find an example of doing this at
84973 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
84974 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
84975 +
84976 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
84977 + feature on a per file basis.
84978 +
84979 +endmenu
84980 +
84981 +menu "Miscellaneous hardening features"
84982 +
84983 +config PAX_MEMORY_SANITIZE
84984 + bool "Sanitize all freed memory"
84985 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
84986 + depends on !HIBERNATION
84987 + help
84988 + By saying Y here the kernel will erase memory pages as soon as they
84989 + are freed. This in turn reduces the lifetime of data stored in the
84990 + pages, making it less likely that sensitive information such as
84991 + passwords, cryptographic secrets, etc stay in memory for too long.
84992 +
84993 + This is especially useful for programs whose runtime is short, long
84994 + lived processes and the kernel itself benefit from this as long as
84995 + they operate on whole memory pages and ensure timely freeing of pages
84996 + that may hold sensitive information.
84997 +
84998 + The tradeoff is performance impact, on a single CPU system kernel
84999 + compilation sees a 3% slowdown, other systems and workloads may vary
85000 + and you are advised to test this feature on your expected workload
85001 + before deploying it.
85002 +
85003 + Note that this feature does not protect data stored in live pages,
85004 + e.g., process memory swapped to disk may stay there for a long time.
85005 +
85006 +config PAX_MEMORY_STACKLEAK
85007 + bool "Sanitize kernel stack"
85008 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
85009 + depends on X86
85010 + help
85011 + By saying Y here the kernel will erase the kernel stack before it
85012 + returns from a system call. This in turn reduces the information
85013 + that a kernel stack leak bug can reveal.
85014 +
85015 + Note that such a bug can still leak information that was put on
85016 + the stack by the current system call (the one eventually triggering
85017 + the bug) but traces of earlier system calls on the kernel stack
85018 + cannot leak anymore.
85019 +
85020 + The tradeoff is performance impact: on a single CPU system kernel
85021 + compilation sees a 1% slowdown, other systems and workloads may vary
85022 + and you are advised to test this feature on your expected workload
85023 + before deploying it.
85024 +
85025 + Note that the full feature requires a gcc with plugin support,
85026 + i.e., gcc 4.5 or newer. You may need to install the supporting
85027 + headers explicitly in addition to the normal gcc package. Using
85028 + older gcc versions means that functions with large enough stack
85029 + frames may leave uninitialized memory behind that may be exposed
85030 + to a later syscall leaking the stack.
85031 +
85032 +config PAX_MEMORY_UDEREF
85033 + bool "Prevent invalid userland pointer dereference"
85034 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
85035 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
85036 + select PAX_PER_CPU_PGD if X86_64
85037 + help
85038 + By saying Y here the kernel will be prevented from dereferencing
85039 + userland pointers in contexts where the kernel expects only kernel
85040 + pointers. This is both a useful runtime debugging feature and a
85041 + security measure that prevents exploiting a class of kernel bugs.
85042 +
85043 + The tradeoff is that some virtualization solutions may experience
85044 + a huge slowdown and therefore you should not enable this feature
85045 + for kernels meant to run in such environments. Whether a given VM
85046 + solution is affected or not is best determined by simply trying it
85047 + out, the performance impact will be obvious right on boot as this
85048 + mechanism engages from very early on. A good rule of thumb is that
85049 + VMs running on CPUs without hardware virtualization support (i.e.,
85050 + the majority of IA-32 CPUs) will likely experience the slowdown.
85051 +
85052 +config PAX_REFCOUNT
85053 + bool "Prevent various kernel object reference counter overflows"
85054 + default y if GRKERNSEC_CONFIG_AUTO
85055 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
85056 + help
85057 + By saying Y here the kernel will detect and prevent overflowing
85058 + various (but not all) kinds of object reference counters. Such
85059 + overflows can normally occur due to bugs only and are often, if
85060 + not always, exploitable.
85061 +
85062 + The tradeoff is that data structures protected by an overflowed
85063 + refcount will never be freed and therefore will leak memory. Note
85064 + that this leak also happens even without this protection but in
85065 + that case the overflow can eventually trigger the freeing of the
85066 + data structure while it is still being used elsewhere, resulting
85067 + in the exploitable situation that this feature prevents.
85068 +
85069 + Since this has a negligible performance impact, you should enable
85070 + this feature.
85071 +
85072 +config PAX_USERCOPY
85073 + bool "Harden heap object copies between kernel and userland"
85074 + default y if GRKERNSEC_CONFIG_AUTO
85075 + depends on ARM || IA64 || PPC || SPARC || X86
85076 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
85077 + select PAX_USERCOPY_SLABS
85078 + help
85079 + By saying Y here the kernel will enforce the size of heap objects
85080 + when they are copied in either direction between the kernel and
85081 + userland, even if only a part of the heap object is copied.
85082 +
85083 + Specifically, this checking prevents information leaking from the
85084 + kernel heap during kernel to userland copies (if the kernel heap
85085 + object is otherwise fully initialized) and prevents kernel heap
85086 + overflows during userland to kernel copies.
85087 +
85088 + Note that the current implementation provides the strictest bounds
85089 + checks for the SLUB allocator.
85090 +
85091 + Enabling this option also enables per-slab cache protection against
85092 + data in a given cache being copied into/out of via userland
85093 + accessors. Though the whitelist of regions will be reduced over
85094 + time, it notably protects important data structures like task structs.
85095 +
85096 + If frame pointers are enabled on x86, this option will also restrict
85097 + copies into and out of the kernel stack to local variables within a
85098 + single frame.
85099 +
85100 + Since this has a negligible performance impact, you should enable
85101 + this feature.
85102 +
85103 +
85104 +config PAX_USERCOPY_DEBUG
85105 + bool
85106 + depends on X86 && PAX_USERCOPY
85107 + default n
85108 +
85109 +config PAX_SIZE_OVERFLOW
85110 + bool "Prevent various integer overflows in function size parameters"
85111 + default y if GRKERNSEC_CONFIG_AUTO
85112 + depends on X86
85113 + help
85114 + By saying Y here the kernel recomputes expressions of function
85115 + arguments marked by a size_overflow attribute with double integer
85116 + precision (DImode/TImode for 32/64 bit integer types).
85117 +
85118 + The recomputed argument is checked against TYPE_MAX and an event
85119 + is logged on overflow and the triggering process is killed.
85120 +
85121 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
85122 +
85123 + Note that the implementation requires a gcc with plugin support,
85124 + i.e., gcc 4.5 or newer. You may need to install the supporting
85125 + headers explicitly in addition to the normal gcc package.
85126 +
85127 +config PAX_LATENT_ENTROPY
85128 + bool "Generate some entropy during boot"
85129 + default y if GRKERNSEC_CONFIG_AUTO
85130 + help
85131 + By saying Y here the kernel will instrument early boot code to
85132 + extract some entropy from both original and artificially created
85133 + program state. This will help especially embedded systems where
85134 + there is little 'natural' source of entropy normally. The cost
85135 + is some slowdown of the boot process.
85136 +
85137 + Note that the implementation requires a gcc with plugin support,
85138 + i.e., gcc 4.5 or newer. You may need to install the supporting
85139 + headers explicitly in addition to the normal gcc package.
85140 +
85141 + Note that entropy extracted this way is not cryptographically
85142 + secure!
85143 +
85144 +endmenu
85145 +
85146 +endmenu
85147 +
85148 +source grsecurity/Kconfig
85149 +
85150 +endmenu
85151 +
85152 +endmenu
85153 +
85154 source security/keys/Kconfig
85155
85156 config SECURITY_DMESG_RESTRICT
85157 @@ -103,7 +999,7 @@ config INTEL_TXT
85158 config LSM_MMAP_MIN_ADDR
85159 int "Low address space for LSM to protect from user allocation"
85160 depends on SECURITY && SECURITY_SELINUX
85161 - default 32768 if ARM
85162 + default 32768 if ALPHA || ARM || PARISC || SPARC32
85163 default 65536
85164 help
85165 This is the portion of low virtual memory which should be protected
85166 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
85167 index 8c2a7f6..b133ac9 100644
85168 --- a/security/apparmor/lsm.c
85169 +++ b/security/apparmor/lsm.c
85170 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
85171 return error;
85172 }
85173
85174 -static struct security_operations apparmor_ops = {
85175 +static struct security_operations apparmor_ops __read_only = {
85176 .name = "apparmor",
85177
85178 .ptrace_access_check = apparmor_ptrace_access_check,
85179 diff --git a/security/commoncap.c b/security/commoncap.c
85180 index 7ee08c7..8d1a9d6 100644
85181 --- a/security/commoncap.c
85182 +++ b/security/commoncap.c
85183 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
85184 return 0;
85185 }
85186
85187 +/* returns:
85188 + 1 for suid privilege
85189 + 2 for sgid privilege
85190 + 3 for fscap privilege
85191 +*/
85192 +int is_privileged_binary(const struct dentry *dentry)
85193 +{
85194 + struct cpu_vfs_cap_data capdata;
85195 + struct inode *inode = dentry->d_inode;
85196 +
85197 + if (!inode || S_ISDIR(inode->i_mode))
85198 + return 0;
85199 +
85200 + if (inode->i_mode & S_ISUID)
85201 + return 1;
85202 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
85203 + return 2;
85204 +
85205 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
85206 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
85207 + return 3;
85208 + }
85209 +
85210 + return 0;
85211 +}
85212 +
85213 /*
85214 * Attempt to get the on-exec apply capability sets for an executable file from
85215 * its xattrs and, if present, apply them to the proposed credentials being
85216 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
85217 const struct cred *cred = current_cred();
85218 kuid_t root_uid = make_kuid(cred->user_ns, 0);
85219
85220 + if (gr_acl_enable_at_secure())
85221 + return 1;
85222 +
85223 if (!uid_eq(cred->uid, root_uid)) {
85224 if (bprm->cap_effective)
85225 return 1;
85226 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
85227 index 079a85d..12e93f8 100644
85228 --- a/security/integrity/ima/ima.h
85229 +++ b/security/integrity/ima/ima.h
85230 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
85231 extern spinlock_t ima_queue_lock;
85232
85233 struct ima_h_table {
85234 - atomic_long_t len; /* number of stored measurements in the list */
85235 - atomic_long_t violations;
85236 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
85237 + atomic_long_unchecked_t violations;
85238 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
85239 };
85240 extern struct ima_h_table ima_htable;
85241 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
85242 index 0cea3db..2f0ef77 100644
85243 --- a/security/integrity/ima/ima_api.c
85244 +++ b/security/integrity/ima/ima_api.c
85245 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
85246 int result;
85247
85248 /* can overflow, only indicator */
85249 - atomic_long_inc(&ima_htable.violations);
85250 + atomic_long_inc_unchecked(&ima_htable.violations);
85251
85252 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
85253 if (!entry) {
85254 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
85255 index 38477c9..87a60c7 100644
85256 --- a/security/integrity/ima/ima_fs.c
85257 +++ b/security/integrity/ima/ima_fs.c
85258 @@ -28,12 +28,12 @@
85259 static int valid_policy = 1;
85260 #define TMPBUFLEN 12
85261 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
85262 - loff_t *ppos, atomic_long_t *val)
85263 + loff_t *ppos, atomic_long_unchecked_t *val)
85264 {
85265 char tmpbuf[TMPBUFLEN];
85266 ssize_t len;
85267
85268 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
85269 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
85270 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
85271 }
85272
85273 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
85274 index 55a6271..ad829c3 100644
85275 --- a/security/integrity/ima/ima_queue.c
85276 +++ b/security/integrity/ima/ima_queue.c
85277 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
85278 INIT_LIST_HEAD(&qe->later);
85279 list_add_tail_rcu(&qe->later, &ima_measurements);
85280
85281 - atomic_long_inc(&ima_htable.len);
85282 + atomic_long_inc_unchecked(&ima_htable.len);
85283 key = ima_hash_key(entry->digest);
85284 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
85285 return 0;
85286 diff --git a/security/keys/compat.c b/security/keys/compat.c
85287 index 1c26176..64a1ba2 100644
85288 --- a/security/keys/compat.c
85289 +++ b/security/keys/compat.c
85290 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
85291 if (ret == 0)
85292 goto no_payload_free;
85293
85294 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
85295 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
85296
85297 if (iov != iovstack)
85298 kfree(iov);
85299 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
85300 index 4b5c948..2054dc1 100644
85301 --- a/security/keys/keyctl.c
85302 +++ b/security/keys/keyctl.c
85303 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
85304 /*
85305 * Copy the iovec data from userspace
85306 */
85307 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
85308 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
85309 unsigned ioc)
85310 {
85311 for (; ioc > 0; ioc--) {
85312 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
85313 * If successful, 0 will be returned.
85314 */
85315 long keyctl_instantiate_key_common(key_serial_t id,
85316 - const struct iovec *payload_iov,
85317 + const struct iovec __user *payload_iov,
85318 unsigned ioc,
85319 size_t plen,
85320 key_serial_t ringid)
85321 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
85322 [0].iov_len = plen
85323 };
85324
85325 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
85326 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
85327 }
85328
85329 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
85330 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
85331 if (ret == 0)
85332 goto no_payload_free;
85333
85334 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
85335 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
85336 err:
85337 if (iov != iovstack)
85338 kfree(iov);
85339 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
85340 index 6ece7f2..ecdb55c 100644
85341 --- a/security/keys/keyring.c
85342 +++ b/security/keys/keyring.c
85343 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
85344 ret = -EFAULT;
85345
85346 for (loop = 0; loop < klist->nkeys; loop++) {
85347 + key_serial_t serial;
85348 key = rcu_deref_link_locked(klist, loop,
85349 keyring);
85350 + serial = key->serial;
85351
85352 tmp = sizeof(key_serial_t);
85353 if (tmp > buflen)
85354 tmp = buflen;
85355
85356 - if (copy_to_user(buffer,
85357 - &key->serial,
85358 - tmp) != 0)
85359 + if (copy_to_user(buffer, &serial, tmp))
85360 goto error;
85361
85362 buflen -= tmp;
85363 diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
85364 index 20e4bf5..58dfe08 100644
85365 --- a/security/keys/process_keys.c
85366 +++ b/security/keys/process_keys.c
85367 @@ -367,6 +367,8 @@ key_ref_t search_my_process_keyrings(struct key_type *type,
85368
85369 switch (PTR_ERR(key_ref)) {
85370 case -EAGAIN: /* no key */
85371 + if (ret)
85372 + break;
85373 case -ENOKEY: /* negative key */
85374 ret = key_ref;
85375 break;
85376 diff --git a/security/min_addr.c b/security/min_addr.c
85377 index f728728..6457a0c 100644
85378 --- a/security/min_addr.c
85379 +++ b/security/min_addr.c
85380 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
85381 */
85382 static void update_mmap_min_addr(void)
85383 {
85384 +#ifndef SPARC
85385 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
85386 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
85387 mmap_min_addr = dac_mmap_min_addr;
85388 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
85389 #else
85390 mmap_min_addr = dac_mmap_min_addr;
85391 #endif
85392 +#endif
85393 }
85394
85395 /*
85396 diff --git a/security/security.c b/security/security.c
85397 index 7b88c6a..1e3ea8f 100644
85398 --- a/security/security.c
85399 +++ b/security/security.c
85400 @@ -20,6 +20,7 @@
85401 #include <linux/ima.h>
85402 #include <linux/evm.h>
85403 #include <linux/fsnotify.h>
85404 +#include <linux/mm.h>
85405 #include <linux/mman.h>
85406 #include <linux/mount.h>
85407 #include <linux/personality.h>
85408 @@ -32,8 +33,8 @@
85409 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
85410 CONFIG_DEFAULT_SECURITY;
85411
85412 -static struct security_operations *security_ops;
85413 -static struct security_operations default_security_ops = {
85414 +static struct security_operations *security_ops __read_only;
85415 +static struct security_operations default_security_ops __read_only = {
85416 .name = "default",
85417 };
85418
85419 @@ -74,7 +75,9 @@ int __init security_init(void)
85420
85421 void reset_security_ops(void)
85422 {
85423 + pax_open_kernel();
85424 security_ops = &default_security_ops;
85425 + pax_close_kernel();
85426 }
85427
85428 /* Save user chosen LSM */
85429 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
85430 index ef26e96..642fb78 100644
85431 --- a/security/selinux/hooks.c
85432 +++ b/security/selinux/hooks.c
85433 @@ -95,8 +95,6 @@
85434
85435 #define NUM_SEL_MNT_OPTS 5
85436
85437 -extern struct security_operations *security_ops;
85438 -
85439 /* SECMARK reference count */
85440 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
85441
85442 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
85443
85444 #endif
85445
85446 -static struct security_operations selinux_ops = {
85447 +static struct security_operations selinux_ops __read_only = {
85448 .name = "selinux",
85449
85450 .ptrace_access_check = selinux_ptrace_access_check,
85451 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
85452 index 65f67cb..3f141ef 100644
85453 --- a/security/selinux/include/xfrm.h
85454 +++ b/security/selinux/include/xfrm.h
85455 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
85456
85457 static inline void selinux_xfrm_notify_policyload(void)
85458 {
85459 - atomic_inc(&flow_cache_genid);
85460 + atomic_inc_unchecked(&flow_cache_genid);
85461 rt_genid_bump(&init_net);
85462 }
85463 #else
85464 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
85465 index 38be92c..21f49ee 100644
85466 --- a/security/smack/smack_lsm.c
85467 +++ b/security/smack/smack_lsm.c
85468 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
85469 return 0;
85470 }
85471
85472 -struct security_operations smack_ops = {
85473 +struct security_operations smack_ops __read_only = {
85474 .name = "smack",
85475
85476 .ptrace_access_check = smack_ptrace_access_check,
85477 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
85478 index a2ee362..5754f34 100644
85479 --- a/security/tomoyo/tomoyo.c
85480 +++ b/security/tomoyo/tomoyo.c
85481 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
85482 * tomoyo_security_ops is a "struct security_operations" which is used for
85483 * registering TOMOYO.
85484 */
85485 -static struct security_operations tomoyo_security_ops = {
85486 +static struct security_operations tomoyo_security_ops __read_only = {
85487 .name = "tomoyo",
85488 .cred_alloc_blank = tomoyo_cred_alloc_blank,
85489 .cred_prepare = tomoyo_cred_prepare,
85490 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
85491 index 20ef514..4182bed 100644
85492 --- a/security/yama/Kconfig
85493 +++ b/security/yama/Kconfig
85494 @@ -1,6 +1,6 @@
85495 config SECURITY_YAMA
85496 bool "Yama support"
85497 - depends on SECURITY
85498 + depends on SECURITY && !GRKERNSEC
85499 select SECURITYFS
85500 select SECURITY_PATH
85501 default n
85502 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
85503 index 4cedc69..e59d8a3 100644
85504 --- a/sound/aoa/codecs/onyx.c
85505 +++ b/sound/aoa/codecs/onyx.c
85506 @@ -54,7 +54,7 @@ struct onyx {
85507 spdif_locked:1,
85508 analog_locked:1,
85509 original_mute:2;
85510 - int open_count;
85511 + local_t open_count;
85512 struct codec_info *codec_info;
85513
85514 /* mutex serializes concurrent access to the device
85515 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
85516 struct onyx *onyx = cii->codec_data;
85517
85518 mutex_lock(&onyx->mutex);
85519 - onyx->open_count++;
85520 + local_inc(&onyx->open_count);
85521 mutex_unlock(&onyx->mutex);
85522
85523 return 0;
85524 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
85525 struct onyx *onyx = cii->codec_data;
85526
85527 mutex_lock(&onyx->mutex);
85528 - onyx->open_count--;
85529 - if (!onyx->open_count)
85530 + if (local_dec_and_test(&onyx->open_count))
85531 onyx->spdif_locked = onyx->analog_locked = 0;
85532 mutex_unlock(&onyx->mutex);
85533
85534 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
85535 index ffd2025..df062c9 100644
85536 --- a/sound/aoa/codecs/onyx.h
85537 +++ b/sound/aoa/codecs/onyx.h
85538 @@ -11,6 +11,7 @@
85539 #include <linux/i2c.h>
85540 #include <asm/pmac_low_i2c.h>
85541 #include <asm/prom.h>
85542 +#include <asm/local.h>
85543
85544 /* PCM3052 register definitions */
85545
85546 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
85547 index 4c1cc51..16040040 100644
85548 --- a/sound/core/oss/pcm_oss.c
85549 +++ b/sound/core/oss/pcm_oss.c
85550 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
85551 if (in_kernel) {
85552 mm_segment_t fs;
85553 fs = snd_enter_user();
85554 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
85555 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
85556 snd_leave_user(fs);
85557 } else {
85558 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
85559 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
85560 }
85561 if (ret != -EPIPE && ret != -ESTRPIPE)
85562 break;
85563 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
85564 if (in_kernel) {
85565 mm_segment_t fs;
85566 fs = snd_enter_user();
85567 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
85568 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
85569 snd_leave_user(fs);
85570 } else {
85571 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
85572 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
85573 }
85574 if (ret == -EPIPE) {
85575 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
85576 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
85577 struct snd_pcm_plugin_channel *channels;
85578 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
85579 if (!in_kernel) {
85580 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
85581 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
85582 return -EFAULT;
85583 buf = runtime->oss.buffer;
85584 }
85585 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
85586 }
85587 } else {
85588 tmp = snd_pcm_oss_write2(substream,
85589 - (const char __force *)buf,
85590 + (const char __force_kernel *)buf,
85591 runtime->oss.period_bytes, 0);
85592 if (tmp <= 0)
85593 goto err;
85594 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
85595 struct snd_pcm_runtime *runtime = substream->runtime;
85596 snd_pcm_sframes_t frames, frames1;
85597 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
85598 - char __user *final_dst = (char __force __user *)buf;
85599 + char __user *final_dst = (char __force_user *)buf;
85600 if (runtime->oss.plugin_first) {
85601 struct snd_pcm_plugin_channel *channels;
85602 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
85603 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
85604 xfer += tmp;
85605 runtime->oss.buffer_used -= tmp;
85606 } else {
85607 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
85608 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
85609 runtime->oss.period_bytes, 0);
85610 if (tmp <= 0)
85611 goto err;
85612 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
85613 size1);
85614 size1 /= runtime->channels; /* frames */
85615 fs = snd_enter_user();
85616 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
85617 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
85618 snd_leave_user(fs);
85619 }
85620 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
85621 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
85622 index af49721..e85058e 100644
85623 --- a/sound/core/pcm_compat.c
85624 +++ b/sound/core/pcm_compat.c
85625 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
85626 int err;
85627
85628 fs = snd_enter_user();
85629 - err = snd_pcm_delay(substream, &delay);
85630 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
85631 snd_leave_user(fs);
85632 if (err < 0)
85633 return err;
85634 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
85635 index 09b4286..8620fac 100644
85636 --- a/sound/core/pcm_native.c
85637 +++ b/sound/core/pcm_native.c
85638 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
85639 switch (substream->stream) {
85640 case SNDRV_PCM_STREAM_PLAYBACK:
85641 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
85642 - (void __user *)arg);
85643 + (void __force_user *)arg);
85644 break;
85645 case SNDRV_PCM_STREAM_CAPTURE:
85646 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
85647 - (void __user *)arg);
85648 + (void __force_user *)arg);
85649 break;
85650 default:
85651 result = -EINVAL;
85652 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
85653 index 040c60e..989a19a 100644
85654 --- a/sound/core/seq/seq_device.c
85655 +++ b/sound/core/seq/seq_device.c
85656 @@ -64,7 +64,7 @@ struct ops_list {
85657 int argsize; /* argument size */
85658
85659 /* operators */
85660 - struct snd_seq_dev_ops ops;
85661 + struct snd_seq_dev_ops *ops;
85662
85663 /* registered devices */
85664 struct list_head dev_list; /* list of devices */
85665 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
85666
85667 mutex_lock(&ops->reg_mutex);
85668 /* copy driver operators */
85669 - ops->ops = *entry;
85670 + ops->ops = entry;
85671 ops->driver |= DRIVER_LOADED;
85672 ops->argsize = argsize;
85673
85674 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
85675 dev->name, ops->id, ops->argsize, dev->argsize);
85676 return -EINVAL;
85677 }
85678 - if (ops->ops.init_device(dev) >= 0) {
85679 + if (ops->ops->init_device(dev) >= 0) {
85680 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
85681 ops->num_init_devices++;
85682 } else {
85683 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
85684 dev->name, ops->id, ops->argsize, dev->argsize);
85685 return -EINVAL;
85686 }
85687 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
85688 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
85689 dev->status = SNDRV_SEQ_DEVICE_FREE;
85690 dev->driver_data = NULL;
85691 ops->num_init_devices--;
85692 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
85693 index 4e0dd22..7a1f32c 100644
85694 --- a/sound/drivers/mts64.c
85695 +++ b/sound/drivers/mts64.c
85696 @@ -29,6 +29,7 @@
85697 #include <sound/initval.h>
85698 #include <sound/rawmidi.h>
85699 #include <sound/control.h>
85700 +#include <asm/local.h>
85701
85702 #define CARD_NAME "Miditerminal 4140"
85703 #define DRIVER_NAME "MTS64"
85704 @@ -67,7 +68,7 @@ struct mts64 {
85705 struct pardevice *pardev;
85706 int pardev_claimed;
85707
85708 - int open_count;
85709 + local_t open_count;
85710 int current_midi_output_port;
85711 int current_midi_input_port;
85712 u8 mode[MTS64_NUM_INPUT_PORTS];
85713 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
85714 {
85715 struct mts64 *mts = substream->rmidi->private_data;
85716
85717 - if (mts->open_count == 0) {
85718 + if (local_read(&mts->open_count) == 0) {
85719 /* We don't need a spinlock here, because this is just called
85720 if the device has not been opened before.
85721 So there aren't any IRQs from the device */
85722 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
85723
85724 msleep(50);
85725 }
85726 - ++(mts->open_count);
85727 + local_inc(&mts->open_count);
85728
85729 return 0;
85730 }
85731 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
85732 struct mts64 *mts = substream->rmidi->private_data;
85733 unsigned long flags;
85734
85735 - --(mts->open_count);
85736 - if (mts->open_count == 0) {
85737 + if (local_dec_return(&mts->open_count) == 0) {
85738 /* We need the spinlock_irqsave here because we can still
85739 have IRQs at this point */
85740 spin_lock_irqsave(&mts->lock, flags);
85741 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
85742
85743 msleep(500);
85744
85745 - } else if (mts->open_count < 0)
85746 - mts->open_count = 0;
85747 + } else if (local_read(&mts->open_count) < 0)
85748 + local_set(&mts->open_count, 0);
85749
85750 return 0;
85751 }
85752 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
85753 index b953fb4..1999c01 100644
85754 --- a/sound/drivers/opl4/opl4_lib.c
85755 +++ b/sound/drivers/opl4/opl4_lib.c
85756 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
85757 MODULE_DESCRIPTION("OPL4 driver");
85758 MODULE_LICENSE("GPL");
85759
85760 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
85761 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
85762 {
85763 int timeout = 10;
85764 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
85765 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
85766 index 991018d..8984740 100644
85767 --- a/sound/drivers/portman2x4.c
85768 +++ b/sound/drivers/portman2x4.c
85769 @@ -48,6 +48,7 @@
85770 #include <sound/initval.h>
85771 #include <sound/rawmidi.h>
85772 #include <sound/control.h>
85773 +#include <asm/local.h>
85774
85775 #define CARD_NAME "Portman 2x4"
85776 #define DRIVER_NAME "portman"
85777 @@ -85,7 +86,7 @@ struct portman {
85778 struct pardevice *pardev;
85779 int pardev_claimed;
85780
85781 - int open_count;
85782 + local_t open_count;
85783 int mode[PORTMAN_NUM_INPUT_PORTS];
85784 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
85785 };
85786 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
85787 index ea995af..f1bfa37 100644
85788 --- a/sound/firewire/amdtp.c
85789 +++ b/sound/firewire/amdtp.c
85790 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
85791 ptr = s->pcm_buffer_pointer + data_blocks;
85792 if (ptr >= pcm->runtime->buffer_size)
85793 ptr -= pcm->runtime->buffer_size;
85794 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
85795 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
85796
85797 s->pcm_period_pointer += data_blocks;
85798 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
85799 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
85800 */
85801 void amdtp_out_stream_update(struct amdtp_out_stream *s)
85802 {
85803 - ACCESS_ONCE(s->source_node_id_field) =
85804 + ACCESS_ONCE_RW(s->source_node_id_field) =
85805 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
85806 }
85807 EXPORT_SYMBOL(amdtp_out_stream_update);
85808 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
85809 index b680c5e..061b7a0 100644
85810 --- a/sound/firewire/amdtp.h
85811 +++ b/sound/firewire/amdtp.h
85812 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
85813 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
85814 struct snd_pcm_substream *pcm)
85815 {
85816 - ACCESS_ONCE(s->pcm) = pcm;
85817 + ACCESS_ONCE_RW(s->pcm) = pcm;
85818 }
85819
85820 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
85821 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
85822 index d428ffe..751ef78 100644
85823 --- a/sound/firewire/isight.c
85824 +++ b/sound/firewire/isight.c
85825 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
85826 ptr += count;
85827 if (ptr >= runtime->buffer_size)
85828 ptr -= runtime->buffer_size;
85829 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
85830 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
85831
85832 isight->period_counter += count;
85833 if (isight->period_counter >= runtime->period_size) {
85834 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
85835 if (err < 0)
85836 return err;
85837
85838 - ACCESS_ONCE(isight->pcm_active) = true;
85839 + ACCESS_ONCE_RW(isight->pcm_active) = true;
85840
85841 return 0;
85842 }
85843 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
85844 {
85845 struct isight *isight = substream->private_data;
85846
85847 - ACCESS_ONCE(isight->pcm_active) = false;
85848 + ACCESS_ONCE_RW(isight->pcm_active) = false;
85849
85850 mutex_lock(&isight->mutex);
85851 isight_stop_streaming(isight);
85852 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
85853
85854 switch (cmd) {
85855 case SNDRV_PCM_TRIGGER_START:
85856 - ACCESS_ONCE(isight->pcm_running) = true;
85857 + ACCESS_ONCE_RW(isight->pcm_running) = true;
85858 break;
85859 case SNDRV_PCM_TRIGGER_STOP:
85860 - ACCESS_ONCE(isight->pcm_running) = false;
85861 + ACCESS_ONCE_RW(isight->pcm_running) = false;
85862 break;
85863 default:
85864 return -EINVAL;
85865 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
85866 index 844a555..985ab83 100644
85867 --- a/sound/firewire/scs1x.c
85868 +++ b/sound/firewire/scs1x.c
85869 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
85870 {
85871 struct scs *scs = stream->rmidi->private_data;
85872
85873 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
85874 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
85875 if (up) {
85876 scs->output_idle = false;
85877 tasklet_schedule(&scs->tasklet);
85878 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
85879 {
85880 struct scs *scs = stream->rmidi->private_data;
85881
85882 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
85883 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
85884 }
85885
85886 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
85887 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
85888
85889 snd_card_disconnect(scs->card);
85890
85891 - ACCESS_ONCE(scs->output) = NULL;
85892 - ACCESS_ONCE(scs->input) = NULL;
85893 + ACCESS_ONCE_RW(scs->output) = NULL;
85894 + ACCESS_ONCE_RW(scs->input) = NULL;
85895
85896 wait_event(scs->idle_wait, scs->output_idle);
85897
85898 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
85899 index 048439a..3be9f6f 100644
85900 --- a/sound/oss/sb_audio.c
85901 +++ b/sound/oss/sb_audio.c
85902 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
85903 buf16 = (signed short *)(localbuf + localoffs);
85904 while (c)
85905 {
85906 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
85907 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
85908 if (copy_from_user(lbuf8,
85909 userbuf+useroffs + p,
85910 locallen))
85911 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
85912 index 7d8803a..559f8d0 100644
85913 --- a/sound/oss/swarm_cs4297a.c
85914 +++ b/sound/oss/swarm_cs4297a.c
85915 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
85916 {
85917 struct cs4297a_state *s;
85918 u32 pwr, id;
85919 - mm_segment_t fs;
85920 int rval;
85921 #ifndef CONFIG_BCM_CS4297A_CSWARM
85922 u64 cfg;
85923 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
85924 if (!rval) {
85925 char *sb1250_duart_present;
85926
85927 +#if 0
85928 + mm_segment_t fs;
85929 fs = get_fs();
85930 set_fs(KERNEL_DS);
85931 -#if 0
85932 val = SOUND_MASK_LINE;
85933 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
85934 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
85935 val = initvol[i].vol;
85936 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
85937 }
85938 + set_fs(fs);
85939 // cs4297a_write_ac97(s, 0x18, 0x0808);
85940 #else
85941 // cs4297a_write_ac97(s, 0x5e, 0x180);
85942 cs4297a_write_ac97(s, 0x02, 0x0808);
85943 cs4297a_write_ac97(s, 0x18, 0x0808);
85944 #endif
85945 - set_fs(fs);
85946
85947 list_add(&s->list, &cs4297a_devs);
85948
85949 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
85950 index 4631a23..001ae57 100644
85951 --- a/sound/pci/ymfpci/ymfpci.h
85952 +++ b/sound/pci/ymfpci/ymfpci.h
85953 @@ -358,7 +358,7 @@ struct snd_ymfpci {
85954 spinlock_t reg_lock;
85955 spinlock_t voice_lock;
85956 wait_queue_head_t interrupt_sleep;
85957 - atomic_t interrupt_sleep_count;
85958 + atomic_unchecked_t interrupt_sleep_count;
85959 struct snd_info_entry *proc_entry;
85960 const struct firmware *dsp_microcode;
85961 const struct firmware *controller_microcode;
85962 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
85963 index 22056c5..25d3244 100644
85964 --- a/sound/pci/ymfpci/ymfpci_main.c
85965 +++ b/sound/pci/ymfpci/ymfpci_main.c
85966 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
85967 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
85968 break;
85969 }
85970 - if (atomic_read(&chip->interrupt_sleep_count)) {
85971 - atomic_set(&chip->interrupt_sleep_count, 0);
85972 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85973 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85974 wake_up(&chip->interrupt_sleep);
85975 }
85976 __end:
85977 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
85978 continue;
85979 init_waitqueue_entry(&wait, current);
85980 add_wait_queue(&chip->interrupt_sleep, &wait);
85981 - atomic_inc(&chip->interrupt_sleep_count);
85982 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
85983 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
85984 remove_wait_queue(&chip->interrupt_sleep, &wait);
85985 }
85986 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
85987 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
85988 spin_unlock(&chip->reg_lock);
85989
85990 - if (atomic_read(&chip->interrupt_sleep_count)) {
85991 - atomic_set(&chip->interrupt_sleep_count, 0);
85992 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
85993 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
85994 wake_up(&chip->interrupt_sleep);
85995 }
85996 }
85997 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
85998 spin_lock_init(&chip->reg_lock);
85999 spin_lock_init(&chip->voice_lock);
86000 init_waitqueue_head(&chip->interrupt_sleep);
86001 - atomic_set(&chip->interrupt_sleep_count, 0);
86002 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
86003 chip->card = card;
86004 chip->pci = pci;
86005 chip->irq = -1;
86006 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
86007 new file mode 100644
86008 index 0000000..50f2f2f
86009 --- /dev/null
86010 +++ b/tools/gcc/.gitignore
86011 @@ -0,0 +1 @@
86012 +size_overflow_hash.h
86013 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
86014 new file mode 100644
86015 index 0000000..1d09b7e
86016 --- /dev/null
86017 +++ b/tools/gcc/Makefile
86018 @@ -0,0 +1,43 @@
86019 +#CC := gcc
86020 +#PLUGIN_SOURCE_FILES := pax_plugin.c
86021 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
86022 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
86023 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
86024 +
86025 +ifeq ($(PLUGINCC),$(HOSTCC))
86026 +HOSTLIBS := hostlibs
86027 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
86028 +else
86029 +HOSTLIBS := hostcxxlibs
86030 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
86031 +endif
86032 +
86033 +$(HOSTLIBS)-y := constify_plugin.so
86034 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
86035 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
86036 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
86037 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
86038 +$(HOSTLIBS)-y += colorize_plugin.so
86039 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
86040 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
86041 +
86042 +always := $($(HOSTLIBS)-y)
86043 +
86044 +constify_plugin-objs := constify_plugin.o
86045 +stackleak_plugin-objs := stackleak_plugin.o
86046 +kallocstat_plugin-objs := kallocstat_plugin.o
86047 +kernexec_plugin-objs := kernexec_plugin.o
86048 +checker_plugin-objs := checker_plugin.o
86049 +colorize_plugin-objs := colorize_plugin.o
86050 +size_overflow_plugin-objs := size_overflow_plugin.o
86051 +latent_entropy_plugin-objs := latent_entropy_plugin.o
86052 +
86053 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
86054 +
86055 +quiet_cmd_build_size_overflow_hash = GENHASH $@
86056 + cmd_build_size_overflow_hash = \
86057 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
86058 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
86059 + $(call if_changed,build_size_overflow_hash)
86060 +
86061 +targets += size_overflow_hash.h
86062 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
86063 new file mode 100644
86064 index 0000000..d41b5af
86065 --- /dev/null
86066 +++ b/tools/gcc/checker_plugin.c
86067 @@ -0,0 +1,171 @@
86068 +/*
86069 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
86070 + * Licensed under the GPL v2
86071 + *
86072 + * Note: the choice of the license means that the compilation process is
86073 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86074 + * but for the kernel it doesn't matter since it doesn't link against
86075 + * any of the gcc libraries
86076 + *
86077 + * gcc plugin to implement various sparse (source code checker) features
86078 + *
86079 + * TODO:
86080 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
86081 + *
86082 + * BUGS:
86083 + * - none known
86084 + */
86085 +#include "gcc-plugin.h"
86086 +#include "config.h"
86087 +#include "system.h"
86088 +#include "coretypes.h"
86089 +#include "tree.h"
86090 +#include "tree-pass.h"
86091 +#include "flags.h"
86092 +#include "intl.h"
86093 +#include "toplev.h"
86094 +#include "plugin.h"
86095 +//#include "expr.h" where are you...
86096 +#include "diagnostic.h"
86097 +#include "plugin-version.h"
86098 +#include "tm.h"
86099 +#include "function.h"
86100 +#include "basic-block.h"
86101 +#include "gimple.h"
86102 +#include "rtl.h"
86103 +#include "emit-rtl.h"
86104 +#include "tree-flow.h"
86105 +#include "target.h"
86106 +
86107 +extern void c_register_addr_space (const char *str, addr_space_t as);
86108 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
86109 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
86110 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
86111 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
86112 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
86113 +
86114 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86115 +extern rtx emit_move_insn(rtx x, rtx y);
86116 +
86117 +int plugin_is_GPL_compatible;
86118 +
86119 +static struct plugin_info checker_plugin_info = {
86120 + .version = "201111150100",
86121 +};
86122 +
86123 +#define ADDR_SPACE_KERNEL 0
86124 +#define ADDR_SPACE_FORCE_KERNEL 1
86125 +#define ADDR_SPACE_USER 2
86126 +#define ADDR_SPACE_FORCE_USER 3
86127 +#define ADDR_SPACE_IOMEM 0
86128 +#define ADDR_SPACE_FORCE_IOMEM 0
86129 +#define ADDR_SPACE_PERCPU 0
86130 +#define ADDR_SPACE_FORCE_PERCPU 0
86131 +#define ADDR_SPACE_RCU 0
86132 +#define ADDR_SPACE_FORCE_RCU 0
86133 +
86134 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
86135 +{
86136 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
86137 +}
86138 +
86139 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
86140 +{
86141 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
86142 +}
86143 +
86144 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
86145 +{
86146 + return default_addr_space_valid_pointer_mode(mode, as);
86147 +}
86148 +
86149 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
86150 +{
86151 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
86152 +}
86153 +
86154 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
86155 +{
86156 + return default_addr_space_legitimize_address(x, oldx, mode, as);
86157 +}
86158 +
86159 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
86160 +{
86161 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
86162 + return true;
86163 +
86164 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
86165 + return true;
86166 +
86167 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
86168 + return true;
86169 +
86170 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
86171 + return true;
86172 +
86173 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
86174 + return true;
86175 +
86176 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
86177 + return true;
86178 +
86179 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
86180 + return true;
86181 +
86182 + return subset == superset;
86183 +}
86184 +
86185 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
86186 +{
86187 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
86188 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
86189 +
86190 + return op;
86191 +}
86192 +
86193 +static void register_checker_address_spaces(void *event_data, void *data)
86194 +{
86195 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
86196 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
86197 + c_register_addr_space("__user", ADDR_SPACE_USER);
86198 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
86199 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
86200 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
86201 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
86202 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
86203 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
86204 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
86205 +
86206 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
86207 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
86208 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
86209 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
86210 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
86211 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
86212 + targetm.addr_space.convert = checker_addr_space_convert;
86213 +}
86214 +
86215 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86216 +{
86217 + const char * const plugin_name = plugin_info->base_name;
86218 + const int argc = plugin_info->argc;
86219 + const struct plugin_argument * const argv = plugin_info->argv;
86220 + int i;
86221 +
86222 + if (!plugin_default_version_check(version, &gcc_version)) {
86223 + error(G_("incompatible gcc/plugin versions"));
86224 + return 1;
86225 + }
86226 +
86227 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
86228 +
86229 + for (i = 0; i < argc; ++i)
86230 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86231 +
86232 + if (TARGET_64BIT == 0)
86233 + return 0;
86234 +
86235 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
86236 +
86237 + return 0;
86238 +}
86239 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
86240 new file mode 100644
86241 index 0000000..414fe5e
86242 --- /dev/null
86243 +++ b/tools/gcc/colorize_plugin.c
86244 @@ -0,0 +1,151 @@
86245 +/*
86246 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
86247 + * Licensed under the GPL v2
86248 + *
86249 + * Note: the choice of the license means that the compilation process is
86250 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86251 + * but for the kernel it doesn't matter since it doesn't link against
86252 + * any of the gcc libraries
86253 + *
86254 + * gcc plugin to colorize diagnostic output
86255 + *
86256 + */
86257 +
86258 +#include "gcc-plugin.h"
86259 +#include "config.h"
86260 +#include "system.h"
86261 +#include "coretypes.h"
86262 +#include "tree.h"
86263 +#include "tree-pass.h"
86264 +#include "flags.h"
86265 +#include "intl.h"
86266 +#include "toplev.h"
86267 +#include "plugin.h"
86268 +#include "diagnostic.h"
86269 +#include "plugin-version.h"
86270 +#include "tm.h"
86271 +
86272 +int plugin_is_GPL_compatible;
86273 +
86274 +static struct plugin_info colorize_plugin_info = {
86275 + .version = "201302112000",
86276 + .help = NULL,
86277 +};
86278 +
86279 +#define GREEN "\033[32m\033[2m"
86280 +#define LIGHTGREEN "\033[32m\033[1m"
86281 +#define YELLOW "\033[33m\033[2m"
86282 +#define LIGHTYELLOW "\033[33m\033[1m"
86283 +#define RED "\033[31m\033[2m"
86284 +#define LIGHTRED "\033[31m\033[1m"
86285 +#define BLUE "\033[34m\033[2m"
86286 +#define LIGHTBLUE "\033[34m\033[1m"
86287 +#define BRIGHT "\033[m\033[1m"
86288 +#define NORMAL "\033[m"
86289 +
86290 +static diagnostic_starter_fn old_starter;
86291 +static diagnostic_finalizer_fn old_finalizer;
86292 +
86293 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
86294 +{
86295 + const char *color;
86296 + char *newprefix;
86297 +
86298 + switch (diagnostic->kind) {
86299 + case DK_NOTE:
86300 + color = LIGHTBLUE;
86301 + break;
86302 +
86303 + case DK_PEDWARN:
86304 + case DK_WARNING:
86305 + color = LIGHTYELLOW;
86306 + break;
86307 +
86308 + case DK_ERROR:
86309 + case DK_FATAL:
86310 + case DK_ICE:
86311 + case DK_PERMERROR:
86312 + case DK_SORRY:
86313 + color = LIGHTRED;
86314 + break;
86315 +
86316 + default:
86317 + color = NORMAL;
86318 + }
86319 +
86320 + old_starter(context, diagnostic);
86321 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
86322 + return;
86323 + pp_destroy_prefix(context->printer);
86324 + pp_set_prefix(context->printer, newprefix);
86325 +}
86326 +
86327 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
86328 +{
86329 + old_finalizer(context, diagnostic);
86330 +}
86331 +
86332 +static void colorize_arm(void)
86333 +{
86334 + old_starter = diagnostic_starter(global_dc);
86335 + old_finalizer = diagnostic_finalizer(global_dc);
86336 +
86337 + diagnostic_starter(global_dc) = start_colorize;
86338 + diagnostic_finalizer(global_dc) = finalize_colorize;
86339 +}
86340 +
86341 +static unsigned int execute_colorize_rearm(void)
86342 +{
86343 + if (diagnostic_starter(global_dc) == start_colorize)
86344 + return 0;
86345 +
86346 + colorize_arm();
86347 + return 0;
86348 +}
86349 +
86350 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
86351 + .pass = {
86352 + .type = SIMPLE_IPA_PASS,
86353 + .name = "colorize_rearm",
86354 +#if BUILDING_GCC_VERSION >= 4008
86355 + .optinfo_flags = OPTGROUP_NONE,
86356 +#endif
86357 + .gate = NULL,
86358 + .execute = execute_colorize_rearm,
86359 + .sub = NULL,
86360 + .next = NULL,
86361 + .static_pass_number = 0,
86362 + .tv_id = TV_NONE,
86363 + .properties_required = 0,
86364 + .properties_provided = 0,
86365 + .properties_destroyed = 0,
86366 + .todo_flags_start = 0,
86367 + .todo_flags_finish = 0
86368 + }
86369 +};
86370 +
86371 +static void colorize_start_unit(void *gcc_data, void *user_data)
86372 +{
86373 + colorize_arm();
86374 +}
86375 +
86376 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86377 +{
86378 + const char * const plugin_name = plugin_info->base_name;
86379 + struct register_pass_info colorize_rearm_pass_info = {
86380 + .pass = &pass_ipa_colorize_rearm.pass,
86381 + .reference_pass_name = "*free_lang_data",
86382 + .ref_pass_instance_number = 1,
86383 + .pos_op = PASS_POS_INSERT_AFTER
86384 + };
86385 +
86386 + if (!plugin_default_version_check(version, &gcc_version)) {
86387 + error(G_("incompatible gcc/plugin versions"));
86388 + return 1;
86389 + }
86390 +
86391 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
86392 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
86393 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
86394 + return 0;
86395 +}
86396 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
86397 new file mode 100644
86398 index 0000000..8bd6f995
86399 --- /dev/null
86400 +++ b/tools/gcc/constify_plugin.c
86401 @@ -0,0 +1,359 @@
86402 +/*
86403 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
86404 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
86405 + * Licensed under the GPL v2, or (at your option) v3
86406 + *
86407 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
86408 + *
86409 + * Homepage:
86410 + * http://www.grsecurity.net/~ephox/const_plugin/
86411 + *
86412 + * Usage:
86413 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
86414 + * $ gcc -fplugin=constify_plugin.so test.c -O2
86415 + */
86416 +
86417 +#include "gcc-plugin.h"
86418 +#include "config.h"
86419 +#include "system.h"
86420 +#include "coretypes.h"
86421 +#include "tree.h"
86422 +#include "tree-pass.h"
86423 +#include "flags.h"
86424 +#include "intl.h"
86425 +#include "toplev.h"
86426 +#include "plugin.h"
86427 +#include "diagnostic.h"
86428 +#include "plugin-version.h"
86429 +#include "tm.h"
86430 +#include "function.h"
86431 +#include "basic-block.h"
86432 +#include "gimple.h"
86433 +#include "rtl.h"
86434 +#include "emit-rtl.h"
86435 +#include "tree-flow.h"
86436 +
86437 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
86438 +
86439 +int plugin_is_GPL_compatible;
86440 +
86441 +static struct plugin_info const_plugin_info = {
86442 + .version = "201302112000",
86443 + .help = "no-constify\tturn off constification\n",
86444 +};
86445 +
86446 +static tree get_field_type(tree field)
86447 +{
86448 + return strip_array_types(TREE_TYPE(field));
86449 +}
86450 +
86451 +static bool walk_struct(tree node, bool all);
86452 +static void deconstify_tree(tree node);
86453 +
86454 +static void deconstify_type(tree type)
86455 +{
86456 + tree field;
86457 +
86458 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
86459 + tree fieldtype = get_field_type(field);
86460 +
86461 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
86462 + continue;
86463 + if (!TYPE_READONLY(fieldtype))
86464 + continue;
86465 + if (!walk_struct(fieldtype, true))
86466 + continue;
86467 +
86468 + deconstify_tree(field);
86469 + TREE_READONLY(field) = 0;
86470 + }
86471 + TYPE_READONLY(type) = 0;
86472 + C_TYPE_FIELDS_READONLY(type) = 0;
86473 +}
86474 +
86475 +static void deconstify_tree(tree node)
86476 +{
86477 + tree old_type, new_type, field;
86478 +
86479 +// TREE_READONLY(node) = 0;
86480 + old_type = TREE_TYPE(node);
86481 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
86482 + node = old_type;
86483 + old_type = TREE_TYPE(old_type);
86484 + }
86485 +
86486 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
86487 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
86488 +
86489 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
86490 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
86491 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
86492 + DECL_FIELD_CONTEXT(field) = new_type;
86493 +
86494 + deconstify_type(new_type);
86495 +
86496 + TREE_TYPE(node) = new_type;
86497 +}
86498 +
86499 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86500 +{
86501 + tree type;
86502 +
86503 + *no_add_attrs = true;
86504 + if (TREE_CODE(*node) == FUNCTION_DECL) {
86505 + error("%qE attribute does not apply to functions", name);
86506 + return NULL_TREE;
86507 + }
86508 +
86509 + if (TREE_CODE(*node) == VAR_DECL) {
86510 + error("%qE attribute does not apply to variables", name);
86511 + return NULL_TREE;
86512 + }
86513 +
86514 + if (TYPE_P(*node)) {
86515 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
86516 + *no_add_attrs = false;
86517 + else
86518 + error("%qE attribute applies to struct and union types only", name);
86519 + return NULL_TREE;
86520 + }
86521 +
86522 + type = TREE_TYPE(*node);
86523 +
86524 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
86525 + error("%qE attribute applies to struct and union types only", name);
86526 + return NULL_TREE;
86527 + }
86528 +
86529 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
86530 + error("%qE attribute is already applied to the type", name);
86531 + return NULL_TREE;
86532 + }
86533 +
86534 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
86535 + error("%qE attribute used on type that is not constified", name);
86536 + return NULL_TREE;
86537 + }
86538 +
86539 + if (TREE_CODE(*node) == TYPE_DECL) {
86540 + deconstify_tree(*node);
86541 + return NULL_TREE;
86542 + }
86543 +
86544 + return NULL_TREE;
86545 +}
86546 +
86547 +static void constify_type(tree type)
86548 +{
86549 + TYPE_READONLY(type) = 1;
86550 + C_TYPE_FIELDS_READONLY(type) = 1;
86551 +}
86552 +
86553 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
86554 +{
86555 + *no_add_attrs = true;
86556 + if (!TYPE_P(*node)) {
86557 + error("%qE attribute applies to types only", name);
86558 + return NULL_TREE;
86559 + }
86560 +
86561 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
86562 + error("%qE attribute applies to struct and union types only", name);
86563 + return NULL_TREE;
86564 + }
86565 +
86566 + *no_add_attrs = false;
86567 + constify_type(*node);
86568 + return NULL_TREE;
86569 +}
86570 +
86571 +static struct attribute_spec no_const_attr = {
86572 + .name = "no_const",
86573 + .min_length = 0,
86574 + .max_length = 0,
86575 + .decl_required = false,
86576 + .type_required = false,
86577 + .function_type_required = false,
86578 + .handler = handle_no_const_attribute,
86579 +#if BUILDING_GCC_VERSION >= 4007
86580 + .affects_type_identity = true
86581 +#endif
86582 +};
86583 +
86584 +static struct attribute_spec do_const_attr = {
86585 + .name = "do_const",
86586 + .min_length = 0,
86587 + .max_length = 0,
86588 + .decl_required = false,
86589 + .type_required = false,
86590 + .function_type_required = false,
86591 + .handler = handle_do_const_attribute,
86592 +#if BUILDING_GCC_VERSION >= 4007
86593 + .affects_type_identity = true
86594 +#endif
86595 +};
86596 +
86597 +static void register_attributes(void *event_data, void *data)
86598 +{
86599 + register_attribute(&no_const_attr);
86600 + register_attribute(&do_const_attr);
86601 +}
86602 +
86603 +static bool is_fptr(tree field)
86604 +{
86605 + tree ptr = get_field_type(field);
86606 +
86607 + if (TREE_CODE(ptr) != POINTER_TYPE)
86608 + return false;
86609 +
86610 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
86611 +}
86612 +
86613 +static bool walk_struct(tree node, bool all)
86614 +{
86615 + tree field;
86616 +
86617 + if (TYPE_FIELDS(node) == NULL_TREE)
86618 + return false;
86619 +
86620 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node)))
86621 + return true;
86622 +
86623 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
86624 + gcc_assert(!TYPE_READONLY(node));
86625 + deconstify_type(node);
86626 + return false;
86627 + }
86628 +
86629 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
86630 + tree type = get_field_type(field);
86631 + enum tree_code code = TREE_CODE(type);
86632 +
86633 + if (node == type)
86634 + return false;
86635 + if (code == RECORD_TYPE || code == UNION_TYPE) {
86636 + if (!(walk_struct(type, all)))
86637 + return false;
86638 + } else if (!is_fptr(field) && (!all || !TREE_READONLY(field)))
86639 + return false;
86640 + }
86641 + return true;
86642 +}
86643 +
86644 +static void finish_type(void *event_data, void *data)
86645 +{
86646 + tree type = (tree)event_data;
86647 +
86648 + if (type == NULL_TREE || type == error_mark_node)
86649 + return;
86650 +
86651 + if (TYPE_READONLY(type))
86652 + return;
86653 +
86654 + if (walk_struct(type, true))
86655 + constify_type(type);
86656 + else
86657 + deconstify_type(type);
86658 +}
86659 +
86660 +static unsigned int check_local_variables(void)
86661 +{
86662 + unsigned int ret = 0;
86663 + tree var;
86664 +
86665 +#if BUILDING_GCC_VERSION == 4005
86666 + tree vars;
86667 +#else
86668 + unsigned int i;
86669 +#endif
86670 +
86671 +#if BUILDING_GCC_VERSION == 4005
86672 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
86673 + var = TREE_VALUE(vars);
86674 +#else
86675 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
86676 +#endif
86677 + tree type = TREE_TYPE(var);
86678 +
86679 + gcc_assert(DECL_P(var));
86680 + if (is_global_var(var))
86681 + continue;
86682 +
86683 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
86684 + continue;
86685 +
86686 + if (!TYPE_READONLY(type))
86687 + continue;
86688 +
86689 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
86690 +// continue;
86691 +
86692 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
86693 + continue;
86694 +
86695 + if (walk_struct(type, false)) {
86696 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
86697 + ret = 1;
86698 + }
86699 + }
86700 + return ret;
86701 +}
86702 +
86703 +struct gimple_opt_pass pass_local_variable = {
86704 + {
86705 + .type = GIMPLE_PASS,
86706 + .name = "check_local_variables",
86707 +#if BUILDING_GCC_VERSION >= 4008
86708 + .optinfo_flags = OPTGROUP_NONE,
86709 +#endif
86710 + .gate = NULL,
86711 + .execute = check_local_variables,
86712 + .sub = NULL,
86713 + .next = NULL,
86714 + .static_pass_number = 0,
86715 + .tv_id = TV_NONE,
86716 + .properties_required = 0,
86717 + .properties_provided = 0,
86718 + .properties_destroyed = 0,
86719 + .todo_flags_start = 0,
86720 + .todo_flags_finish = 0
86721 + }
86722 +};
86723 +
86724 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
86725 +{
86726 + const char * const plugin_name = plugin_info->base_name;
86727 + const int argc = plugin_info->argc;
86728 + const struct plugin_argument * const argv = plugin_info->argv;
86729 + int i;
86730 + bool constify = true;
86731 +
86732 + struct register_pass_info local_variable_pass_info = {
86733 + .pass = &pass_local_variable.pass,
86734 + .reference_pass_name = "ssa",
86735 + .ref_pass_instance_number = 1,
86736 + .pos_op = PASS_POS_INSERT_BEFORE
86737 + };
86738 +
86739 + if (!plugin_default_version_check(version, &gcc_version)) {
86740 + error(G_("incompatible gcc/plugin versions"));
86741 + return 1;
86742 + }
86743 +
86744 + for (i = 0; i < argc; ++i) {
86745 + if (!(strcmp(argv[i].key, "no-constify"))) {
86746 + constify = false;
86747 + continue;
86748 + }
86749 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
86750 + }
86751 +
86752 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
86753 + if (constify) {
86754 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
86755 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
86756 + }
86757 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
86758 +
86759 + return 0;
86760 +}
86761 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
86762 new file mode 100644
86763 index 0000000..e518932
86764 --- /dev/null
86765 +++ b/tools/gcc/generate_size_overflow_hash.sh
86766 @@ -0,0 +1,94 @@
86767 +#!/bin/bash
86768 +
86769 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
86770 +
86771 +header1="size_overflow_hash.h"
86772 +database="size_overflow_hash.data"
86773 +n=65536
86774 +
86775 +usage() {
86776 +cat <<EOF
86777 +usage: $0 options
86778 +OPTIONS:
86779 + -h|--help help
86780 + -o header file
86781 + -d database file
86782 + -n hash array size
86783 +EOF
86784 + return 0
86785 +}
86786 +
86787 +while true
86788 +do
86789 + case "$1" in
86790 + -h|--help) usage && exit 0;;
86791 + -n) n=$2; shift 2;;
86792 + -o) header1="$2"; shift 2;;
86793 + -d) database="$2"; shift 2;;
86794 + --) shift 1; break ;;
86795 + *) break ;;
86796 + esac
86797 +done
86798 +
86799 +create_defines() {
86800 + for i in `seq 0 31`
86801 + do
86802 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
86803 + done
86804 + echo >> "$header1"
86805 +}
86806 +
86807 +create_structs() {
86808 + rm -f "$header1"
86809 +
86810 + create_defines
86811 +
86812 + cat "$database" | while read data
86813 + do
86814 + data_array=($data)
86815 + struct_hash_name="${data_array[0]}"
86816 + funcn="${data_array[1]}"
86817 + params="${data_array[2]}"
86818 + next="${data_array[4]}"
86819 +
86820 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
86821 +
86822 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
86823 + echo -en "\t.param\t= " >> "$header1"
86824 + line=
86825 + for param_num in ${params//-/ };
86826 + do
86827 + line="${line}PARAM"$param_num"|"
86828 + done
86829 +
86830 + echo -e "${line%?},\n};\n" >> "$header1"
86831 + done
86832 +}
86833 +
86834 +create_headers() {
86835 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
86836 +}
86837 +
86838 +create_array_elements() {
86839 + index=0
86840 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
86841 + do
86842 + data_array=($data)
86843 + i="${data_array[3]}"
86844 + hash="${data_array[0]}"
86845 + while [[ $index -lt $i ]]
86846 + do
86847 + echo -e "\t["$index"]\t= NULL," >> "$header1"
86848 + index=$(($index + 1))
86849 + done
86850 + index=$(($index + 1))
86851 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
86852 + done
86853 + echo '};' >> $header1
86854 +}
86855 +
86856 +create_structs
86857 +create_headers
86858 +create_array_elements
86859 +
86860 +exit 0
86861 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
86862 new file mode 100644
86863 index 0000000..568b360
86864 --- /dev/null
86865 +++ b/tools/gcc/kallocstat_plugin.c
86866 @@ -0,0 +1,170 @@
86867 +/*
86868 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
86869 + * Licensed under the GPL v2
86870 + *
86871 + * Note: the choice of the license means that the compilation process is
86872 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
86873 + * but for the kernel it doesn't matter since it doesn't link against
86874 + * any of the gcc libraries
86875 + *
86876 + * gcc plugin to find the distribution of k*alloc sizes
86877 + *
86878 + * TODO:
86879 + *
86880 + * BUGS:
86881 + * - none known
86882 + */
86883 +#include "gcc-plugin.h"
86884 +#include "config.h"
86885 +#include "system.h"
86886 +#include "coretypes.h"
86887 +#include "tree.h"
86888 +#include "tree-pass.h"
86889 +#include "flags.h"
86890 +#include "intl.h"
86891 +#include "toplev.h"
86892 +#include "plugin.h"
86893 +//#include "expr.h" where are you...
86894 +#include "diagnostic.h"
86895 +#include "plugin-version.h"
86896 +#include "tm.h"
86897 +#include "function.h"
86898 +#include "basic-block.h"
86899 +#include "gimple.h"
86900 +#include "rtl.h"
86901 +#include "emit-rtl.h"
86902 +
86903 +extern void print_gimple_stmt(FILE *, gimple, int, int);
86904 +
86905 +int plugin_is_GPL_compatible;
86906 +
86907 +static const char * const kalloc_functions[] = {
86908 + "__kmalloc",
86909 + "kmalloc",
86910 + "kmalloc_large",
86911 + "kmalloc_node",
86912 + "kmalloc_order",
86913 + "kmalloc_order_trace",
86914 + "kmalloc_slab",
86915 + "kzalloc",
86916 + "kzalloc_node",
86917 +};
86918 +
86919 +static struct plugin_info kallocstat_plugin_info = {
86920 + .version = "201302112000",
86921 +};
86922 +
86923 +static unsigned int execute_kallocstat(void);
86924 +
86925 +static struct gimple_opt_pass kallocstat_pass = {
86926 + .pass = {
86927 + .type = GIMPLE_PASS,
86928 + .name = "kallocstat",
86929 +#if BUILDING_GCC_VERSION >= 4008
86930 + .optinfo_flags = OPTGROUP_NONE,
86931 +#endif
86932 + .gate = NULL,
86933 + .execute = execute_kallocstat,
86934 + .sub = NULL,
86935 + .next = NULL,
86936 + .static_pass_number = 0,
86937 + .tv_id = TV_NONE,
86938 + .properties_required = 0,
86939 + .properties_provided = 0,
86940 + .properties_destroyed = 0,
86941 + .todo_flags_start = 0,
86942 + .todo_flags_finish = 0
86943 + }
86944 +};
86945 +
86946 +static bool is_kalloc(const char *fnname)
86947 +{
86948 + size_t i;
86949 +
86950 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
86951 + if (!strcmp(fnname, kalloc_functions[i]))
86952 + return true;
86953 + return false;
86954 +}
86955 +
86956 +static unsigned int execute_kallocstat(void)
86957 +{
86958 + basic_block bb;
86959 +
86960 + // 1. loop through BBs and GIMPLE statements
86961 + FOR_EACH_BB(bb) {
86962 + gimple_stmt_iterator gsi;
86963 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
86964 + // gimple match:
86965 + tree fndecl, size;
86966 + gimple call_stmt;
86967 + const char *fnname;
86968 +
86969 + // is it a call
86970 + call_stmt = gsi_stmt(gsi);
86971 + if (!is_gimple_call(call_stmt))
86972 + continue;
86973 + fndecl = gimple_call_fndecl(call_stmt);
86974 + if (fndecl == NULL_TREE)
86975 + continue;
86976 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
86977 + continue;
86978 +
86979 + // is it a call to k*alloc
86980 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
86981 + if (!is_kalloc(fnname))
86982 + continue;
86983 +
86984 + // is the size arg the result of a simple const assignment
86985 + size = gimple_call_arg(call_stmt, 0);
86986 + while (true) {
86987 + gimple def_stmt;
86988 + expanded_location xloc;
86989 + size_t size_val;
86990 +
86991 + if (TREE_CODE(size) != SSA_NAME)
86992 + break;
86993 + def_stmt = SSA_NAME_DEF_STMT(size);
86994 + if (!def_stmt || !is_gimple_assign(def_stmt))
86995 + break;
86996 + if (gimple_num_ops(def_stmt) != 2)
86997 + break;
86998 + size = gimple_assign_rhs1(def_stmt);
86999 + if (!TREE_CONSTANT(size))
87000 + continue;
87001 + xloc = expand_location(gimple_location(def_stmt));
87002 + if (!xloc.file)
87003 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
87004 + size_val = TREE_INT_CST_LOW(size);
87005 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
87006 + break;
87007 + }
87008 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
87009 +//debug_tree(gimple_call_fn(call_stmt));
87010 +//print_node(stderr, "pax", fndecl, 4);
87011 + }
87012 + }
87013 +
87014 + return 0;
87015 +}
87016 +
87017 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87018 +{
87019 + const char * const plugin_name = plugin_info->base_name;
87020 + struct register_pass_info kallocstat_pass_info = {
87021 + .pass = &kallocstat_pass.pass,
87022 + .reference_pass_name = "ssa",
87023 + .ref_pass_instance_number = 1,
87024 + .pos_op = PASS_POS_INSERT_AFTER
87025 + };
87026 +
87027 + if (!plugin_default_version_check(version, &gcc_version)) {
87028 + error(G_("incompatible gcc/plugin versions"));
87029 + return 1;
87030 + }
87031 +
87032 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
87033 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
87034 +
87035 + return 0;
87036 +}
87037 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
87038 new file mode 100644
87039 index 0000000..0408e06
87040 --- /dev/null
87041 +++ b/tools/gcc/kernexec_plugin.c
87042 @@ -0,0 +1,465 @@
87043 +/*
87044 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
87045 + * Licensed under the GPL v2
87046 + *
87047 + * Note: the choice of the license means that the compilation process is
87048 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87049 + * but for the kernel it doesn't matter since it doesn't link against
87050 + * any of the gcc libraries
87051 + *
87052 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
87053 + *
87054 + * TODO:
87055 + *
87056 + * BUGS:
87057 + * - none known
87058 + */
87059 +#include "gcc-plugin.h"
87060 +#include "config.h"
87061 +#include "system.h"
87062 +#include "coretypes.h"
87063 +#include "tree.h"
87064 +#include "tree-pass.h"
87065 +#include "flags.h"
87066 +#include "intl.h"
87067 +#include "toplev.h"
87068 +#include "plugin.h"
87069 +//#include "expr.h" where are you...
87070 +#include "diagnostic.h"
87071 +#include "plugin-version.h"
87072 +#include "tm.h"
87073 +#include "function.h"
87074 +#include "basic-block.h"
87075 +#include "gimple.h"
87076 +#include "rtl.h"
87077 +#include "emit-rtl.h"
87078 +#include "tree-flow.h"
87079 +
87080 +extern void print_gimple_stmt(FILE *, gimple, int, int);
87081 +extern rtx emit_move_insn(rtx x, rtx y);
87082 +
87083 +#if BUILDING_GCC_VERSION <= 4006
87084 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
87085 +#endif
87086 +
87087 +#if BUILDING_GCC_VERSION >= 4008
87088 +#define TODO_dump_func 0
87089 +#endif
87090 +
87091 +int plugin_is_GPL_compatible;
87092 +
87093 +static struct plugin_info kernexec_plugin_info = {
87094 + .version = "201302112000",
87095 + .help = "method=[bts|or]\tinstrumentation method\n"
87096 +};
87097 +
87098 +static unsigned int execute_kernexec_reload(void);
87099 +static unsigned int execute_kernexec_fptr(void);
87100 +static unsigned int execute_kernexec_retaddr(void);
87101 +static bool kernexec_cmodel_check(void);
87102 +
87103 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
87104 +static void (*kernexec_instrument_retaddr)(rtx);
87105 +
87106 +static struct gimple_opt_pass kernexec_reload_pass = {
87107 + .pass = {
87108 + .type = GIMPLE_PASS,
87109 + .name = "kernexec_reload",
87110 +#if BUILDING_GCC_VERSION >= 4008
87111 + .optinfo_flags = OPTGROUP_NONE,
87112 +#endif
87113 + .gate = kernexec_cmodel_check,
87114 + .execute = execute_kernexec_reload,
87115 + .sub = NULL,
87116 + .next = NULL,
87117 + .static_pass_number = 0,
87118 + .tv_id = TV_NONE,
87119 + .properties_required = 0,
87120 + .properties_provided = 0,
87121 + .properties_destroyed = 0,
87122 + .todo_flags_start = 0,
87123 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
87124 + }
87125 +};
87126 +
87127 +static struct gimple_opt_pass kernexec_fptr_pass = {
87128 + .pass = {
87129 + .type = GIMPLE_PASS,
87130 + .name = "kernexec_fptr",
87131 +#if BUILDING_GCC_VERSION >= 4008
87132 + .optinfo_flags = OPTGROUP_NONE,
87133 +#endif
87134 + .gate = kernexec_cmodel_check,
87135 + .execute = execute_kernexec_fptr,
87136 + .sub = NULL,
87137 + .next = NULL,
87138 + .static_pass_number = 0,
87139 + .tv_id = TV_NONE,
87140 + .properties_required = 0,
87141 + .properties_provided = 0,
87142 + .properties_destroyed = 0,
87143 + .todo_flags_start = 0,
87144 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
87145 + }
87146 +};
87147 +
87148 +static struct rtl_opt_pass kernexec_retaddr_pass = {
87149 + .pass = {
87150 + .type = RTL_PASS,
87151 + .name = "kernexec_retaddr",
87152 +#if BUILDING_GCC_VERSION >= 4008
87153 + .optinfo_flags = OPTGROUP_NONE,
87154 +#endif
87155 + .gate = kernexec_cmodel_check,
87156 + .execute = execute_kernexec_retaddr,
87157 + .sub = NULL,
87158 + .next = NULL,
87159 + .static_pass_number = 0,
87160 + .tv_id = TV_NONE,
87161 + .properties_required = 0,
87162 + .properties_provided = 0,
87163 + .properties_destroyed = 0,
87164 + .todo_flags_start = 0,
87165 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
87166 + }
87167 +};
87168 +
87169 +static bool kernexec_cmodel_check(void)
87170 +{
87171 + tree section;
87172 +
87173 + if (ix86_cmodel != CM_KERNEL)
87174 + return false;
87175 +
87176 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
87177 + if (!section || !TREE_VALUE(section))
87178 + return true;
87179 +
87180 + section = TREE_VALUE(TREE_VALUE(section));
87181 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
87182 + return true;
87183 +
87184 + return false;
87185 +}
87186 +
87187 +/*
87188 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
87189 + */
87190 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
87191 +{
87192 + gimple asm_movabs_stmt;
87193 +
87194 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
87195 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
87196 + gimple_asm_set_volatile(asm_movabs_stmt, true);
87197 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
87198 + update_stmt(asm_movabs_stmt);
87199 +}
87200 +
87201 +/*
87202 + * find all asm() stmts that clobber r10 and add a reload of r10
87203 + */
87204 +static unsigned int execute_kernexec_reload(void)
87205 +{
87206 + basic_block bb;
87207 +
87208 + // 1. loop through BBs and GIMPLE statements
87209 + FOR_EACH_BB(bb) {
87210 + gimple_stmt_iterator gsi;
87211 +
87212 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87213 + // gimple match: __asm__ ("" : : : "r10");
87214 + gimple asm_stmt;
87215 + size_t nclobbers;
87216 +
87217 + // is it an asm ...
87218 + asm_stmt = gsi_stmt(gsi);
87219 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
87220 + continue;
87221 +
87222 + // ... clobbering r10
87223 + nclobbers = gimple_asm_nclobbers(asm_stmt);
87224 + while (nclobbers--) {
87225 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
87226 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
87227 + continue;
87228 + kernexec_reload_fptr_mask(&gsi);
87229 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
87230 + break;
87231 + }
87232 + }
87233 + }
87234 +
87235 + return 0;
87236 +}
87237 +
87238 +/*
87239 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
87240 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
87241 + */
87242 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
87243 +{
87244 + gimple assign_intptr, assign_new_fptr, call_stmt;
87245 + tree intptr, old_fptr, new_fptr, kernexec_mask;
87246 +
87247 + call_stmt = gsi_stmt(*gsi);
87248 + old_fptr = gimple_call_fn(call_stmt);
87249 +
87250 + // create temporary unsigned long variable used for bitops and cast fptr to it
87251 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
87252 +#if BUILDING_GCC_VERSION <= 4007
87253 + add_referenced_var(intptr);
87254 + mark_sym_for_renaming(intptr);
87255 +#endif
87256 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
87257 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
87258 + update_stmt(assign_intptr);
87259 +
87260 + // apply logical or to temporary unsigned long and bitmask
87261 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
87262 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
87263 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
87264 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
87265 + update_stmt(assign_intptr);
87266 +
87267 + // cast temporary unsigned long back to a temporary fptr variable
87268 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
87269 +#if BUILDING_GCC_VERSION <= 4007
87270 + add_referenced_var(new_fptr);
87271 + mark_sym_for_renaming(new_fptr);
87272 +#endif
87273 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
87274 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
87275 + update_stmt(assign_new_fptr);
87276 +
87277 + // replace call stmt fn with the new fptr
87278 + gimple_call_set_fn(call_stmt, new_fptr);
87279 + update_stmt(call_stmt);
87280 +}
87281 +
87282 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
87283 +{
87284 + gimple asm_or_stmt, call_stmt;
87285 + tree old_fptr, new_fptr, input, output;
87286 +#if BUILDING_GCC_VERSION <= 4007
87287 + VEC(tree, gc) *inputs = NULL;
87288 + VEC(tree, gc) *outputs = NULL;
87289 +#else
87290 + vec<tree, va_gc> *inputs = NULL;
87291 + vec<tree, va_gc> *outputs = NULL;
87292 +#endif
87293 +
87294 + call_stmt = gsi_stmt(*gsi);
87295 + old_fptr = gimple_call_fn(call_stmt);
87296 +
87297 + // create temporary fptr variable
87298 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
87299 +#if BUILDING_GCC_VERSION <= 4007
87300 + add_referenced_var(new_fptr);
87301 + mark_sym_for_renaming(new_fptr);
87302 +#endif
87303 +
87304 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
87305 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
87306 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
87307 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
87308 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
87309 +#if BUILDING_GCC_VERSION <= 4007
87310 + VEC_safe_push(tree, gc, inputs, input);
87311 + VEC_safe_push(tree, gc, outputs, output);
87312 +#else
87313 + vec_safe_push(inputs, input);
87314 + vec_safe_push(outputs, output);
87315 +#endif
87316 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
87317 + gimple_asm_set_volatile(asm_or_stmt, true);
87318 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
87319 + update_stmt(asm_or_stmt);
87320 +
87321 + // replace call stmt fn with the new fptr
87322 + gimple_call_set_fn(call_stmt, new_fptr);
87323 + update_stmt(call_stmt);
87324 +}
87325 +
87326 +/*
87327 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
87328 + */
87329 +static unsigned int execute_kernexec_fptr(void)
87330 +{
87331 + basic_block bb;
87332 +
87333 + // 1. loop through BBs and GIMPLE statements
87334 + FOR_EACH_BB(bb) {
87335 + gimple_stmt_iterator gsi;
87336 +
87337 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
87338 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
87339 + tree fn;
87340 + gimple call_stmt;
87341 +
87342 + // is it a call ...
87343 + call_stmt = gsi_stmt(gsi);
87344 + if (!is_gimple_call(call_stmt))
87345 + continue;
87346 + fn = gimple_call_fn(call_stmt);
87347 + if (TREE_CODE(fn) == ADDR_EXPR)
87348 + continue;
87349 + if (TREE_CODE(fn) != SSA_NAME)
87350 + gcc_unreachable();
87351 +
87352 + // ... through a function pointer
87353 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
87354 + fn = SSA_NAME_VAR(fn);
87355 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
87356 + debug_tree(fn);
87357 + gcc_unreachable();
87358 + }
87359 + }
87360 + fn = TREE_TYPE(fn);
87361 + if (TREE_CODE(fn) != POINTER_TYPE)
87362 + continue;
87363 + fn = TREE_TYPE(fn);
87364 + if (TREE_CODE(fn) != FUNCTION_TYPE)
87365 + continue;
87366 +
87367 + kernexec_instrument_fptr(&gsi);
87368 +
87369 +//debug_tree(gimple_call_fn(call_stmt));
87370 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
87371 + }
87372 + }
87373 +
87374 + return 0;
87375 +}
87376 +
87377 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
87378 +static void kernexec_instrument_retaddr_bts(rtx insn)
87379 +{
87380 + rtx btsq;
87381 + rtvec argvec, constraintvec, labelvec;
87382 + int line;
87383 +
87384 + // create asm volatile("btsq $63,(%%rsp)":::)
87385 + argvec = rtvec_alloc(0);
87386 + constraintvec = rtvec_alloc(0);
87387 + labelvec = rtvec_alloc(0);
87388 + line = expand_location(RTL_LOCATION(insn)).line;
87389 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
87390 + MEM_VOLATILE_P(btsq) = 1;
87391 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
87392 + emit_insn_before(btsq, insn);
87393 +}
87394 +
87395 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
87396 +static void kernexec_instrument_retaddr_or(rtx insn)
87397 +{
87398 + rtx orq;
87399 + rtvec argvec, constraintvec, labelvec;
87400 + int line;
87401 +
87402 + // create asm volatile("orq %%r10,(%%rsp)":::)
87403 + argvec = rtvec_alloc(0);
87404 + constraintvec = rtvec_alloc(0);
87405 + labelvec = rtvec_alloc(0);
87406 + line = expand_location(RTL_LOCATION(insn)).line;
87407 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
87408 + MEM_VOLATILE_P(orq) = 1;
87409 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
87410 + emit_insn_before(orq, insn);
87411 +}
87412 +
87413 +/*
87414 + * find all asm level function returns and forcibly set the highest bit of the return address
87415 + */
87416 +static unsigned int execute_kernexec_retaddr(void)
87417 +{
87418 + rtx insn;
87419 +
87420 + // 1. find function returns
87421 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
87422 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
87423 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
87424 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
87425 + rtx body;
87426 +
87427 + // is it a retn
87428 + if (!JUMP_P(insn))
87429 + continue;
87430 + body = PATTERN(insn);
87431 + if (GET_CODE(body) == PARALLEL)
87432 + body = XVECEXP(body, 0, 0);
87433 + if (!ANY_RETURN_P(body))
87434 + continue;
87435 + kernexec_instrument_retaddr(insn);
87436 + }
87437 +
87438 +// print_simple_rtl(stderr, get_insns());
87439 +// print_rtl(stderr, get_insns());
87440 +
87441 + return 0;
87442 +}
87443 +
87444 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87445 +{
87446 + const char * const plugin_name = plugin_info->base_name;
87447 + const int argc = plugin_info->argc;
87448 + const struct plugin_argument * const argv = plugin_info->argv;
87449 + int i;
87450 + struct register_pass_info kernexec_reload_pass_info = {
87451 + .pass = &kernexec_reload_pass.pass,
87452 + .reference_pass_name = "ssa",
87453 + .ref_pass_instance_number = 1,
87454 + .pos_op = PASS_POS_INSERT_AFTER
87455 + };
87456 + struct register_pass_info kernexec_fptr_pass_info = {
87457 + .pass = &kernexec_fptr_pass.pass,
87458 + .reference_pass_name = "ssa",
87459 + .ref_pass_instance_number = 1,
87460 + .pos_op = PASS_POS_INSERT_AFTER
87461 + };
87462 + struct register_pass_info kernexec_retaddr_pass_info = {
87463 + .pass = &kernexec_retaddr_pass.pass,
87464 + .reference_pass_name = "pro_and_epilogue",
87465 + .ref_pass_instance_number = 1,
87466 + .pos_op = PASS_POS_INSERT_AFTER
87467 + };
87468 +
87469 + if (!plugin_default_version_check(version, &gcc_version)) {
87470 + error(G_("incompatible gcc/plugin versions"));
87471 + return 1;
87472 + }
87473 +
87474 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
87475 +
87476 + if (TARGET_64BIT == 0)
87477 + return 0;
87478 +
87479 + for (i = 0; i < argc; ++i) {
87480 + if (!strcmp(argv[i].key, "method")) {
87481 + if (!argv[i].value) {
87482 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87483 + continue;
87484 + }
87485 + if (!strcmp(argv[i].value, "bts")) {
87486 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
87487 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
87488 + } else if (!strcmp(argv[i].value, "or")) {
87489 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
87490 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
87491 + fix_register("r10", 1, 1);
87492 + } else
87493 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
87494 + continue;
87495 + }
87496 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
87497 + }
87498 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
87499 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
87500 +
87501 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
87502 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
87503 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
87504 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
87505 +
87506 + return 0;
87507 +}
87508 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
87509 new file mode 100644
87510 index 0000000..1276616
87511 --- /dev/null
87512 +++ b/tools/gcc/latent_entropy_plugin.c
87513 @@ -0,0 +1,321 @@
87514 +/*
87515 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
87516 + * Licensed under the GPL v2
87517 + *
87518 + * Note: the choice of the license means that the compilation process is
87519 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
87520 + * but for the kernel it doesn't matter since it doesn't link against
87521 + * any of the gcc libraries
87522 + *
87523 + * gcc plugin to help generate a little bit of entropy from program state,
87524 + * used during boot in the kernel
87525 + *
87526 + * TODO:
87527 + * - add ipa pass to identify not explicitly marked candidate functions
87528 + * - mix in more program state (function arguments/return values, loop variables, etc)
87529 + * - more instrumentation control via attribute parameters
87530 + *
87531 + * BUGS:
87532 + * - LTO needs -flto-partition=none for now
87533 + */
87534 +#include "gcc-plugin.h"
87535 +#include "config.h"
87536 +#include "system.h"
87537 +#include "coretypes.h"
87538 +#include "tree.h"
87539 +#include "tree-pass.h"
87540 +#include "flags.h"
87541 +#include "intl.h"
87542 +#include "toplev.h"
87543 +#include "plugin.h"
87544 +//#include "expr.h" where are you...
87545 +#include "diagnostic.h"
87546 +#include "plugin-version.h"
87547 +#include "tm.h"
87548 +#include "function.h"
87549 +#include "basic-block.h"
87550 +#include "gimple.h"
87551 +#include "rtl.h"
87552 +#include "emit-rtl.h"
87553 +#include "tree-flow.h"
87554 +
87555 +#if BUILDING_GCC_VERSION >= 4008
87556 +#define TODO_dump_func 0
87557 +#endif
87558 +
87559 +int plugin_is_GPL_compatible;
87560 +
87561 +static tree latent_entropy_decl;
87562 +
87563 +static struct plugin_info latent_entropy_plugin_info = {
87564 + .version = "201302112000",
87565 + .help = NULL
87566 +};
87567 +
87568 +static unsigned int execute_latent_entropy(void);
87569 +static bool gate_latent_entropy(void);
87570 +
87571 +static struct gimple_opt_pass latent_entropy_pass = {
87572 + .pass = {
87573 + .type = GIMPLE_PASS,
87574 + .name = "latent_entropy",
87575 +#if BUILDING_GCC_VERSION >= 4008
87576 + .optinfo_flags = OPTGROUP_NONE,
87577 +#endif
87578 + .gate = gate_latent_entropy,
87579 + .execute = execute_latent_entropy,
87580 + .sub = NULL,
87581 + .next = NULL,
87582 + .static_pass_number = 0,
87583 + .tv_id = TV_NONE,
87584 + .properties_required = PROP_gimple_leh | PROP_cfg,
87585 + .properties_provided = 0,
87586 + .properties_destroyed = 0,
87587 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
87588 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
87589 + }
87590 +};
87591 +
87592 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
87593 +{
87594 + if (TREE_CODE(*node) != FUNCTION_DECL) {
87595 + *no_add_attrs = true;
87596 + error("%qE attribute only applies to functions", name);
87597 + }
87598 + return NULL_TREE;
87599 +}
87600 +
87601 +static struct attribute_spec latent_entropy_attr = {
87602 + .name = "latent_entropy",
87603 + .min_length = 0,
87604 + .max_length = 0,
87605 + .decl_required = true,
87606 + .type_required = false,
87607 + .function_type_required = false,
87608 + .handler = handle_latent_entropy_attribute,
87609 +#if BUILDING_GCC_VERSION >= 4007
87610 + .affects_type_identity = false
87611 +#endif
87612 +};
87613 +
87614 +static void register_attributes(void *event_data, void *data)
87615 +{
87616 + register_attribute(&latent_entropy_attr);
87617 +}
87618 +
87619 +static bool gate_latent_entropy(void)
87620 +{
87621 + tree latent_entropy_attr;
87622 +
87623 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
87624 + return latent_entropy_attr != NULL_TREE;
87625 +}
87626 +
87627 +static unsigned HOST_WIDE_INT seed;
87628 +static unsigned HOST_WIDE_INT get_random_const(void)
87629 +{
87630 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
87631 + return seed;
87632 +}
87633 +
87634 +static enum tree_code get_op(tree *rhs)
87635 +{
87636 + static enum tree_code op;
87637 + unsigned HOST_WIDE_INT random_const;
87638 +
87639 + random_const = get_random_const();
87640 +
87641 + switch (op) {
87642 + case BIT_XOR_EXPR:
87643 + op = PLUS_EXPR;
87644 + break;
87645 +
87646 + case PLUS_EXPR:
87647 + if (rhs) {
87648 + op = LROTATE_EXPR;
87649 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
87650 + break;
87651 + }
87652 +
87653 + case LROTATE_EXPR:
87654 + default:
87655 + op = BIT_XOR_EXPR;
87656 + break;
87657 + }
87658 + if (rhs)
87659 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
87660 + return op;
87661 +}
87662 +
87663 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
87664 +{
87665 + gimple_stmt_iterator gsi;
87666 + gimple assign;
87667 + tree addxorrol, rhs;
87668 + enum tree_code op;
87669 +
87670 + op = get_op(&rhs);
87671 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
87672 + assign = gimple_build_assign(local_entropy, addxorrol);
87673 +#if BUILDING_GCC_VERSION <= 4007
87674 + find_referenced_vars_in(assign);
87675 +#endif
87676 +//debug_bb(bb);
87677 + gsi = gsi_after_labels(bb);
87678 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
87679 + update_stmt(assign);
87680 +}
87681 +
87682 +static void perturb_latent_entropy(basic_block bb, tree rhs)
87683 +{
87684 + gimple_stmt_iterator gsi;
87685 + gimple assign;
87686 + tree addxorrol, temp;
87687 +
87688 + // 1. create temporary copy of latent_entropy
87689 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
87690 +#if BUILDING_GCC_VERSION <= 4007
87691 + add_referenced_var(temp);
87692 + mark_sym_for_renaming(temp);
87693 +#endif
87694 +
87695 + // 2. read...
87696 + assign = gimple_build_assign(temp, latent_entropy_decl);
87697 +#if BUILDING_GCC_VERSION <= 4007
87698 + find_referenced_vars_in(assign);
87699 +#endif
87700 + gsi = gsi_after_labels(bb);
87701 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87702 + update_stmt(assign);
87703 +
87704 + // 3. ...modify...
87705 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
87706 + assign = gimple_build_assign(temp, addxorrol);
87707 +#if BUILDING_GCC_VERSION <= 4007
87708 + find_referenced_vars_in(assign);
87709 +#endif
87710 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87711 + update_stmt(assign);
87712 +
87713 + // 4. ...write latent_entropy
87714 + assign = gimple_build_assign(latent_entropy_decl, temp);
87715 +#if BUILDING_GCC_VERSION <= 4007
87716 + find_referenced_vars_in(assign);
87717 +#endif
87718 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87719 + update_stmt(assign);
87720 +}
87721 +
87722 +static unsigned int execute_latent_entropy(void)
87723 +{
87724 + basic_block bb;
87725 + gimple assign;
87726 + gimple_stmt_iterator gsi;
87727 + tree local_entropy;
87728 +
87729 + if (!latent_entropy_decl) {
87730 + struct varpool_node *node;
87731 +
87732 +#if BUILDING_GCC_VERSION <= 4007
87733 + for (node = varpool_nodes; node; node = node->next) {
87734 + tree var = node->decl;
87735 +#else
87736 + FOR_EACH_VARIABLE(node) {
87737 + tree var = node->symbol.decl;
87738 +#endif
87739 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
87740 + continue;
87741 + latent_entropy_decl = var;
87742 +// debug_tree(var);
87743 + break;
87744 + }
87745 + if (!latent_entropy_decl) {
87746 +// debug_tree(current_function_decl);
87747 + return 0;
87748 + }
87749 + }
87750 +
87751 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
87752 +
87753 + // 1. create local entropy variable
87754 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
87755 +#if BUILDING_GCC_VERSION <= 4007
87756 + add_referenced_var(local_entropy);
87757 + mark_sym_for_renaming(local_entropy);
87758 +#endif
87759 +
87760 + // 2. initialize local entropy variable
87761 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
87762 + if (dom_info_available_p(CDI_DOMINATORS))
87763 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
87764 + gsi = gsi_start_bb(bb);
87765 +
87766 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
87767 +// gimple_set_location(assign, loc);
87768 +#if BUILDING_GCC_VERSION <= 4007
87769 + find_referenced_vars_in(assign);
87770 +#endif
87771 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
87772 + update_stmt(assign);
87773 + bb = bb->next_bb;
87774 +
87775 + // 3. instrument each BB with an operation on the local entropy variable
87776 + while (bb != EXIT_BLOCK_PTR) {
87777 + perturb_local_entropy(bb, local_entropy);
87778 + bb = bb->next_bb;
87779 + };
87780 +
87781 + // 4. mix local entropy into the global entropy variable
87782 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
87783 + return 0;
87784 +}
87785 +
87786 +static void start_unit_callback(void *gcc_data, void *user_data)
87787 +{
87788 +#if BUILDING_GCC_VERSION >= 4007
87789 + seed = get_random_seed(false);
87790 +#else
87791 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
87792 + seed *= seed;
87793 +#endif
87794 +
87795 + if (in_lto_p)
87796 + return;
87797 +
87798 + // extern u64 latent_entropy
87799 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
87800 +
87801 + TREE_STATIC(latent_entropy_decl) = 1;
87802 + TREE_PUBLIC(latent_entropy_decl) = 1;
87803 + TREE_USED(latent_entropy_decl) = 1;
87804 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
87805 + DECL_EXTERNAL(latent_entropy_decl) = 1;
87806 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
87807 + DECL_INITIAL(latent_entropy_decl) = NULL;
87808 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
87809 +// varpool_finalize_decl(latent_entropy_decl);
87810 +// varpool_mark_needed_node(latent_entropy_decl);
87811 +}
87812 +
87813 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
87814 +{
87815 + const char * const plugin_name = plugin_info->base_name;
87816 + struct register_pass_info latent_entropy_pass_info = {
87817 + .pass = &latent_entropy_pass.pass,
87818 + .reference_pass_name = "optimized",
87819 + .ref_pass_instance_number = 1,
87820 + .pos_op = PASS_POS_INSERT_BEFORE
87821 + };
87822 +
87823 + if (!plugin_default_version_check(version, &gcc_version)) {
87824 + error(G_("incompatible gcc/plugin versions"));
87825 + return 1;
87826 + }
87827 +
87828 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
87829 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
87830 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
87831 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
87832 +
87833 + return 0;
87834 +}
87835 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
87836 new file mode 100644
87837 index 0000000..5921fd7
87838 --- /dev/null
87839 +++ b/tools/gcc/size_overflow_hash.data
87840 @@ -0,0 +1,3713 @@
87841 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
87842 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
87843 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
87844 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
87845 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
87846 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
87847 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
87848 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
87849 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
87850 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
87851 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
87852 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
87853 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
87854 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
87855 +create_log_8225 create_log 2 8225 NULL
87856 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
87857 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
87858 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
87859 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
87860 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
87861 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
87862 +padzero_55 padzero 1 55 &sel_read_policyvers_55
87863 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
87864 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
87865 +read_file_blob_57406 read_file_blob 3 57406 NULL
87866 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
87867 +enclosure_register_57412 enclosure_register 3 57412 NULL
87868 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
87869 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
87870 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
87871 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
87872 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
87873 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
87874 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
87875 +init_cdev_8274 init_cdev 1 8274 NULL
87876 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
87877 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
87878 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
87879 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
87880 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
87881 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
87882 +load_msg_95 load_msg 2 95 NULL
87883 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
87884 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
87885 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
87886 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
87887 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
87888 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
87889 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
87890 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
87891 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
87892 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
87893 +send_midi_async_57463 send_midi_async 3 57463 NULL
87894 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
87895 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
87896 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
87897 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
87898 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
87899 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
87900 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
87901 +init_q_132 init_q 4 132 NULL
87902 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
87903 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
87904 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
87905 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
87906 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
87907 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
87908 +uio_read_49300 uio_read 3 49300 NULL
87909 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
87910 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
87911 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
87912 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
87913 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
87914 +play_iframe_8219 play_iframe 3 8219 NULL
87915 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
87916 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
87917 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
87918 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
87919 +init_tag_map_57515 init_tag_map 3 57515 NULL
87920 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
87921 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
87922 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
87923 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
87924 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
87925 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
87926 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
87927 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
87928 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
87929 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
87930 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
87931 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
87932 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
87933 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
87934 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
87935 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
87936 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
87937 +cache_read_24790 cache_read 3 24790 NULL
87938 +px_raw_event_49371 px_raw_event 4 49371 NULL
87939 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
87940 +compat_filldir_32999 compat_filldir 3 32999 NULL
87941 +hci_si_event_1404 hci_si_event 3 1404 NULL
87942 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
87943 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
87944 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
87945 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
87946 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
87947 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
87948 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
87949 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
87950 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
87951 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
87952 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
87953 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
87954 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
87955 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
87956 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
87957 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
87958 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
87959 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
87960 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
87961 +mem_read_57631 mem_read 3 57631 NULL
87962 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
87963 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
87964 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
87965 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
87966 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
87967 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
87968 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
87969 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
87970 +queues_read_24877 queues_read 3 24877 NULL
87971 +__fprog_create_41263 __fprog_create 2 41263 NULL
87972 +syslog_print_307 syslog_print 2 307 NULL
87973 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
87974 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
87975 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
87976 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
87977 +r3964_write_57662 r3964_write 4 57662 NULL
87978 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
87979 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
87980 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
87981 +alloc_context_41283 alloc_context 1 41283 NULL
87982 +__lgwrite_57669 __lgwrite 4 57669 NULL
87983 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
87984 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
87985 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
87986 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
87987 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
87988 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
87989 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
87990 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
87991 +write_node_33121 write_node 4 33121 NULL
87992 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
87993 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
87994 +profile_remove_8556 profile_remove 3 8556 NULL
87995 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
87996 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
87997 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
87998 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
87999 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
88000 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
88001 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
88002 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
88003 +tower_write_8580 tower_write 3 8580 NULL
88004 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
88005 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
88006 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
88007 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
88008 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
88009 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
88010 +smk_write_access_49561 smk_write_access 3 49561 NULL
88011 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
88012 +kmp_init_41373 kmp_init 2 41373 NULL
88013 +context_alloc_24645 context_alloc 3 24645 NULL
88014 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
88015 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
88016 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
88017 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
88018 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
88019 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
88020 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
88021 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
88022 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
88023 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
88024 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
88025 +pp_read_33210 pp_read 3 33210 NULL
88026 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
88027 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
88028 +ivtv_read_57796 ivtv_read 3 57796 NULL
88029 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
88030 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
88031 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
88032 +heap_init_49617 heap_init 2 49617 NULL
88033 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
88034 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
88035 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
88036 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
88037 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
88038 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
88039 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
88040 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
88041 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
88042 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
88043 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
88044 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
88045 +st_write_16874 st_write 3 16874 NULL
88046 +copy_to_user_57835 copy_to_user 3 57835 NULL
88047 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
88048 +pidlist_resize_496 pidlist_resize 2 496 NULL
88049 +flash_read_57843 flash_read 3 57843 NULL
88050 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
88051 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
88052 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
88053 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
88054 +arcfb_write_8702 arcfb_write 3 8702 NULL
88055 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
88056 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
88057 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
88058 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
88059 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
88060 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
88061 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
88062 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
88063 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
88064 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
88065 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
88066 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
88067 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
88068 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
88069 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
88070 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
88071 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
88072 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
88073 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
88074 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
88075 +devres_alloc_551 devres_alloc 2 551 NULL
88076 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
88077 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
88078 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
88079 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
88080 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
88081 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
88082 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
88083 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
88084 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
88085 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
88086 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
88087 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
88088 +sys_prctl_8766 sys_prctl 4 8766 NULL
88089 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
88090 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
88091 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
88092 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
88093 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
88094 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
88095 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
88096 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
88097 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
88098 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
88099 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
88100 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
88101 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
88102 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
88103 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
88104 +gserial_setup_41558 gserial_setup 2 41558 NULL
88105 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
88106 +rx_57944 rx 4 57944 NULL
88107 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
88108 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
88109 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
88110 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
88111 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
88112 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
88113 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
88114 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
88115 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
88116 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
88117 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
88118 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
88119 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
88120 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
88121 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
88122 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
88123 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
88124 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
88125 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
88126 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
88127 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
88128 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
88129 +a2mp_send_41615 a2mp_send 4 41615 NULL
88130 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
88131 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
88132 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
88133 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
88134 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
88135 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
88136 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
88137 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
88138 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
88139 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
88140 +add_uuid_49831 add_uuid 4 49831 NULL
88141 +send_pages_8872 send_pages 3 8872 NULL
88142 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
88143 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
88144 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
88145 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
88146 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
88147 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
88148 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
88149 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
88150 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
88151 +vfs_writev_25278 vfs_writev 3 25278 NULL
88152 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
88153 +alloc_async_14208 alloc_async 1 14208 NULL
88154 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
88155 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
88156 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
88157 +create_entry_33479 create_entry 2 33479 NULL
88158 +mce_async_out_58056 mce_async_out 3 58056 NULL
88159 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
88160 +sys_preadv_17100 sys_preadv 3 17100 NULL
88161 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
88162 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
88163 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
88164 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
88165 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
88166 +res_counter_read_33499 res_counter_read 4 33499 NULL
88167 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
88168 +cm4040_write_58079 cm4040_write 3 58079 NULL
88169 +fb_read_33506 fb_read 3 33506 NULL
88170 +help_25316 help 5 25316 NULL nohasharray
88171 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
88172 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
88173 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
88174 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
88175 +ddp_set_map_751 ddp_set_map 4 751 NULL
88176 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
88177 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
88178 +dvb_video_write_754 dvb_video_write 3 754 NULL
88179 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
88180 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
88181 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
88182 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
88183 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
88184 +udi_log_event_58105 udi_log_event 3 58105 NULL
88185 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
88186 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
88187 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
88188 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
88189 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
88190 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
88191 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
88192 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
88193 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
88194 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
88195 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
88196 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
88197 +sep_read_17161 sep_read 3 17161 NULL
88198 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
88199 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
88200 +dup_array_33551 dup_array 3 33551 NULL
88201 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
88202 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
88203 +fillonedir_41746 fillonedir 3 41746 NULL
88204 +init_bch_64130 init_bch 1-2 64130 NULL
88205 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
88206 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
88207 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
88208 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
88209 +savemem_58129 savemem 3 58129 NULL
88210 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
88211 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
88212 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
88213 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
88214 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
88215 +if_writecmd_815 if_writecmd 2 815 NULL
88216 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
88217 +read_fifo_826 read_fifo 3 826 NULL
88218 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
88219 +scsi_execute_33596 scsi_execute 5 33596 NULL
88220 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
88221 +ms_rw_17220 ms_rw 3-4 17220 NULL
88222 +read_tree_block_841 read_tree_block 3 841 NULL
88223 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
88224 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
88225 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
88226 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
88227 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
88228 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
88229 +um_idi_read_850 um_idi_read 3 850 NULL
88230 +__module_alloc_50004 __module_alloc 1 50004 NULL
88231 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
88232 +ts_read_44687 ts_read 3 44687 NULL
88233 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
88234 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
88235 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
88236 +provide_user_output_41105 provide_user_output 3 41105 NULL
88237 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
88238 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
88239 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
88240 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
88241 +alloc_ep_17269 alloc_ep 1 17269 NULL
88242 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
88243 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
88244 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
88245 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
88246 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
88247 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
88248 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
88249 +create_queues_9088 create_queues 2-3 9088 NULL
88250 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
88251 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
88252 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
88253 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
88254 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
88255 +read_file_debug_58256 read_file_debug 3 58256 NULL
88256 +skb_pad_17302 skb_pad 2 17302 NULL
88257 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
88258 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
88259 +profile_load_58267 profile_load 3 58267 NULL
88260 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
88261 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
88262 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
88263 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
88264 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
88265 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
88266 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
88267 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
88268 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
88269 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
88270 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
88271 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
88272 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
88273 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
88274 +get_packet_41914 get_packet 3 41914 NULL
88275 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
88276 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
88277 +read_file_slot_50111 read_file_slot 3 50111 NULL
88278 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
88279 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
88280 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
88281 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
88282 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
88283 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
88284 +copy_items_50140 copy_items 6 50140 NULL
88285 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
88286 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
88287 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
88288 +map_addr_56144 map_addr 7 56144 NULL
88289 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
88290 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
88291 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
88292 +portnames_read_41958 portnames_read 3 41958 NULL
88293 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
88294 +hashtab_create_33769 hashtab_create 3 33769 NULL
88295 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
88296 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
88297 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
88298 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
88299 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
88300 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
88301 +odev_update_50169 odev_update 2 50169 NULL
88302 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
88303 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
88304 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
88305 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
88306 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
88307 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
88308 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
88309 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
88310 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
88311 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
88312 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
88313 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
88314 +lguest_map_42008 lguest_map 1-2 42008 NULL
88315 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
88316 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
88317 +pool_allocate_42012 pool_allocate 3 42012 NULL
88318 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
88319 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
88320 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
88321 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
88322 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
88323 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
88324 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
88325 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
88326 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
88327 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
88328 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
88329 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
88330 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
88331 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
88332 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
88333 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
88334 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
88335 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
88336 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
88337 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
88338 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
88339 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
88340 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
88341 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
88342 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
88343 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
88344 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
88345 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
88346 +config_proc_write_33878 config_proc_write 3 33878 NULL
88347 +capabilities_read_58457 capabilities_read 3 58457 NULL
88348 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
88349 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
88350 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
88351 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
88352 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
88353 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
88354 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
88355 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
88356 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
88357 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
88358 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
88359 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
88360 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
88361 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
88362 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
88363 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
88364 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
88365 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
88366 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
88367 +vme_user_write_15587 vme_user_write 3 15587 NULL
88368 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
88369 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
88370 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
88371 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
88372 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
88373 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
88374 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
88375 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
88376 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
88377 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
88378 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
88379 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
88380 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
88381 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
88382 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
88383 +read_9397 read 3 9397 NULL
88384 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
88385 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
88386 +printer_write_60276 printer_write 3 60276 NULL
88387 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
88388 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
88389 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
88390 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
88391 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
88392 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
88393 +osst_execute_17607 osst_execute 7-6 17607 NULL
88394 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
88395 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
88396 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
88397 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
88398 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
88399 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
88400 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
88401 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
88402 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
88403 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
88404 +xip_file_read_58592 xip_file_read 3 58592 NULL
88405 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
88406 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
88407 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
88408 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
88409 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
88410 +ppp_write_34034 ppp_write 3 34034 NULL
88411 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
88412 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
88413 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
88414 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
88415 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
88416 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
88417 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
88418 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
88419 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
88420 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
88421 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
88422 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
88423 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
88424 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
88425 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
88426 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
88427 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
88428 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
88429 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
88430 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
88431 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
88432 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
88433 +lp_write_9511 lp_write 3 9511 NULL
88434 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
88435 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
88436 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
88437 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
88438 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
88439 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
88440 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
88441 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
88442 +read_file_dma_9530 read_file_dma 3 9530 NULL
88443 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
88444 +rcname_read_25919 rcname_read 3 25919 NULL
88445 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
88446 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
88447 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
88448 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
88449 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
88450 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
88451 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
88452 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
88453 +key_flags_read_25931 key_flags_read 3 25931 NULL
88454 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
88455 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
88456 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
88457 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
88458 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
88459 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
88460 +fw_node_create_9559 fw_node_create 2 9559 NULL
88461 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
88462 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
88463 +kobj_map_9566 kobj_map 2-3 9566 NULL
88464 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
88465 +acpi_map_58725 acpi_map 1-2 58725 NULL
88466 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
88467 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
88468 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
88469 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
88470 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
88471 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
88472 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
88473 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
88474 +file_read_actor_1401 file_read_actor 4 1401 NULL
88475 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
88476 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
88477 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
88478 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
88479 +do_sync_9604 do_sync 1 9604 NULL
88480 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
88481 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
88482 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
88483 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
88484 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
88485 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
88486 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
88487 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
88488 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
88489 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
88490 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
88491 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
88492 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
88493 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
88494 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
88495 +sge_rx_50594 sge_rx 3 50594 NULL
88496 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
88497 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
88498 +skb_padto_50759 skb_padto 2 50759 NULL
88499 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
88500 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
88501 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
88502 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
88503 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
88504 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
88505 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
88506 +ep_read_58813 ep_read 3 58813 NULL
88507 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
88508 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
88509 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
88510 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
88511 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
88512 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
88513 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
88514 +dns_query_9676 dns_query 3 9676 NULL
88515 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
88516 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
88517 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
88518 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
88519 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
88520 +command_write_58841 command_write 3 58841 NULL
88521 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
88522 +dev_config_8506 dev_config 3 8506 NULL
88523 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
88524 +sys_readv_50664 sys_readv 3 50664 NULL
88525 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
88526 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
88527 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
88528 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
88529 +recover_head_17904 recover_head 3 17904 NULL
88530 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
88531 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
88532 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
88533 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
88534 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
88535 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
88536 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
88537 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
88538 +skb_cow_26138 skb_cow 2 26138 NULL
88539 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
88540 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
88541 +do_sigpending_9766 do_sigpending 2 9766 NULL
88542 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
88543 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
88544 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
88545 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
88546 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
88547 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
88548 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
88549 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
88550 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
88551 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
88552 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
88553 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
88554 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
88555 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
88556 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
88557 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
88558 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
88559 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
88560 +get_registers_26187 get_registers 3 26187 NULL
88561 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
88562 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
88563 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
88564 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
88565 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
88566 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
88567 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
88568 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
88569 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
88570 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
88571 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
88572 +mce_write_26201 mce_write 3 26201 NULL
88573 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
88574 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
88575 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
88576 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
88577 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
88578 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
88579 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
88580 +tpm_write_50798 tpm_write 3 50798 NULL
88581 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
88582 +tun_do_read_50800 tun_do_read 4 50800 NULL
88583 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
88584 +write_flush_50803 write_flush 3 50803 NULL
88585 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
88586 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
88587 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
88588 +dvb_play_50814 dvb_play 3 50814 NULL
88589 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
88590 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
88591 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
88592 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
88593 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
88594 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
88595 +dma_attach_50831 dma_attach 6-7 50831 NULL
88596 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
88597 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
88598 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
88599 +packet_came_18072 packet_came 3 18072 NULL
88600 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
88601 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
88602 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
88603 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
88604 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
88605 +get_vm_area_18080 get_vm_area 1 18080 NULL
88606 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
88607 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
88608 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
88609 +self_check_write_50856 self_check_write 5 50856 NULL
88610 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
88611 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
88612 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
88613 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
88614 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
88615 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
88616 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
88617 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
88618 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
88619 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
88620 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
88621 +vb2_read_42703 vb2_read 3 42703 NULL
88622 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
88623 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
88624 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
88625 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
88626 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
88627 +read_file_misc_9948 read_file_misc 3 9948 NULL
88628 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
88629 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
88630 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
88631 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
88632 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
88633 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
88634 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
88635 +cosa_write_1774 cosa_write 3 1774 NULL
88636 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
88637 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
88638 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
88639 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
88640 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
88641 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
88642 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
88643 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
88644 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
88645 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
88646 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
88647 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
88648 +mld_newpack_50950 mld_newpack 2 50950 NULL
88649 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
88650 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
88651 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
88652 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
88653 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
88654 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
88655 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
88656 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
88657 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
88658 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
88659 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
88660 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
88661 +handle_request_10024 handle_request 9 10024 NULL
88662 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
88663 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
88664 +timeout_write_50991 timeout_write 3 50991 NULL
88665 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
88666 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
88667 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
88668 +proc_write_51003 proc_write 3 51003 NULL
88669 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
88670 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
88671 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
88672 +set_arg_42824 set_arg 3 42824 NULL
88673 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
88674 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
88675 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
88676 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
88677 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
88678 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
88679 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
88680 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
88681 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
88682 +dt3155_read_59226 dt3155_read 3 59226 NULL
88683 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
88684 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
88685 +dump_midi_51040 dump_midi 3 51040 NULL
88686 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
88687 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
88688 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
88689 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
88690 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
88691 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
88692 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
88693 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
88694 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
88695 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
88696 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
88697 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
88698 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
88699 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
88700 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
88701 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
88702 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
88703 +read_vmcore_26501 read_vmcore 3 26501 NULL
88704 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
88705 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
88706 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
88707 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
88708 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
88709 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
88710 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
88711 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
88712 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
88713 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
88714 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
88715 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
88716 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
88717 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
88718 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
88719 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
88720 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
88721 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
88722 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
88723 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
88724 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
88725 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
88726 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
88727 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
88728 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
88729 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
88730 +fd_copyout_59323 fd_copyout 3 59323 NULL
88731 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
88732 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
88733 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
88734 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
88735 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
88736 +solos_param_store_34755 solos_param_store 4 34755 NULL
88737 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
88738 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
88739 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
88740 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
88741 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
88742 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
88743 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
88744 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
88745 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
88746 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
88747 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
88748 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
88749 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
88750 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
88751 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
88752 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
88753 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
88754 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
88755 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
88756 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
88757 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
88758 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
88759 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
88760 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
88761 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
88762 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
88763 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
88764 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
88765 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
88766 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
88767 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
88768 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
88769 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
88770 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
88771 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
88772 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
88773 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
88774 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
88775 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
88776 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
88777 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
88778 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
88779 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
88780 +tipc_send_51238 tipc_send 4 51238 NULL
88781 +drm_property_create_51239 drm_property_create 4 51239 NULL
88782 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
88783 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
88784 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
88785 +audit_expand_2098 audit_expand 2 2098 NULL
88786 +st_read_51251 st_read 3 51251 NULL
88787 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
88788 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
88789 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
88790 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
88791 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
88792 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
88793 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
88794 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
88795 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
88796 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
88797 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
88798 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
88799 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
88800 +c4_add_card_54968 c4_add_card 3 54968 NULL
88801 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
88802 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
88803 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
88804 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
88805 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
88806 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
88807 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
88808 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
88809 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
88810 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
88811 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
88812 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
88813 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
88814 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
88815 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
88816 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
88817 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
88818 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
88819 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
88820 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
88821 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
88822 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
88823 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
88824 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
88825 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
88826 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
88827 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
88828 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
88829 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
88830 +debug_output_18575 debug_output 3 18575 NULL
88831 +Realloc_34961 Realloc 2 34961 NULL
88832 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
88833 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
88834 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
88835 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
88836 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
88837 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
88838 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
88839 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
88840 +vhci_write_2224 vhci_write 3 2224 NULL
88841 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
88842 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
88843 +rb_alloc_3102 rb_alloc 1 3102 NULL
88844 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
88845 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
88846 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
88847 +write_pbl_59583 write_pbl 4 59583 NULL
88848 +from_buffer_18625 from_buffer 3 18625 NULL
88849 +uio_write_43202 uio_write 3 43202 NULL
88850 +memdup_user_59590 memdup_user 2 59590 NULL
88851 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
88852 +iso_callback_43208 iso_callback 3 43208 NULL
88853 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
88854 +smk_write_load_26829 smk_write_load 3 26829 NULL
88855 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
88856 +do_update_counters_2259 do_update_counters 4 2259 NULL
88857 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
88858 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
88859 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
88860 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
88861 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
88862 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
88863 +mtrr_write_59622 mtrr_write 3 59622 NULL
88864 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
88865 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
88866 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
88867 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
88868 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
88869 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
88870 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
88871 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
88872 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
88873 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
88874 +fixup_leb_43256 fixup_leb 3 43256 NULL
88875 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
88876 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
88877 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
88878 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
88879 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
88880 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
88881 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
88882 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
88883 +evtchn_write_43278 evtchn_write 3 43278 NULL
88884 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
88885 +store_ifalias_35088 store_ifalias 4 35088 NULL
88886 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
88887 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
88888 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
88889 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
88890 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
88891 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
88892 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
88893 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
88894 +capi_write_35104 capi_write 3 35104 NULL nohasharray
88895 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
88896 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
88897 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
88898 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
88899 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
88900 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
88901 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
88902 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
88903 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
88904 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
88905 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
88906 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
88907 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
88908 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
88909 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
88910 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
88911 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
88912 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
88913 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
88914 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
88915 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
88916 +do_trimming_26952 do_trimming 3 26952 NULL
88917 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
88918 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
88919 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
88920 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
88921 +alloc_buf_34532 alloc_buf 1 34532 NULL
88922 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
88923 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
88924 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
88925 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
88926 +otp_read_10594 otp_read 2-4-5 10594 NULL
88927 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
88928 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
88929 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
88930 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
88931 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
88932 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
88933 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
88934 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
88935 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
88936 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
88937 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
88938 +venus_remove_59781 venus_remove 4 59781 NULL
88939 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
88940 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
88941 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
88942 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
88943 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
88944 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
88945 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
88946 +xenfb_write_43412 xenfb_write 3 43412 NULL
88947 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
88948 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
88949 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
88950 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
88951 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
88952 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
88953 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
88954 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
88955 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
88956 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
88957 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
88958 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
88959 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
88960 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
88961 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
88962 +cmd_complete_51629 cmd_complete 6 51629 NULL
88963 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
88964 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
88965 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
88966 +set_fd_set_35249 set_fd_set 1 35249 NULL
88967 +wiphy_new_2482 wiphy_new 2 2482 NULL
88968 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
88969 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
88970 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
88971 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
88972 +tcp_push_10680 tcp_push 3 10680 NULL
88973 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
88974 +c101_run_37279 c101_run 2 37279 NULL
88975 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
88976 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
88977 +tun_put_user_59849 tun_put_user 4 59849 NULL
88978 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
88979 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
88980 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
88981 +dm_write_2513 dm_write 3 2513 NULL
88982 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
88983 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
88984 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
88985 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
88986 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
88987 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
88988 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
88989 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
88990 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
88991 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
88992 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
88993 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
88994 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
88995 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
88996 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
88997 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
88998 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
88999 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
89000 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
89001 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
89002 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
89003 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
89004 +sel_write_access_51704 sel_write_access 3 51704 NULL
89005 +sys_syslog_10746 sys_syslog 3 10746 NULL
89006 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
89007 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
89008 +do_readlink_43518 do_readlink 2 43518 NULL
89009 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
89010 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
89011 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
89012 +read_file_reset_52310 read_file_reset 3 52310 NULL
89013 +pms_capture_27142 pms_capture 4 27142 NULL
89014 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
89015 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
89016 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
89017 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
89018 +msg_set_51725 msg_set 3 51725 NULL
89019 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
89020 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
89021 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
89022 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
89023 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
89024 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
89025 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
89026 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
89027 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
89028 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
89029 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
89030 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
89031 +sys_bind_10799 sys_bind 3 10799 NULL
89032 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
89033 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
89034 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
89035 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
89036 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
89037 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
89038 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
89039 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
89040 +send_command_10832 send_command 4 10832 NULL
89041 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
89042 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
89043 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
89044 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
89045 +proc_read_43614 proc_read 3 43614 NULL
89046 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
89047 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
89048 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
89049 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
89050 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
89051 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
89052 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
89053 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
89054 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
89055 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
89056 +vmalloc_15464 vmalloc 1 15464 NULL
89057 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
89058 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
89059 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
89060 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
89061 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
89062 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
89063 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
89064 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
89065 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
89066 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
89067 +adu_write_30487 adu_write 3 30487 NULL
89068 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
89069 +get_scq_10897 get_scq 2 10897 NULL
89070 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
89071 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
89072 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
89073 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
89074 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
89075 +load_module_60056 load_module 2 60056 NULL nohasharray
89076 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
89077 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
89078 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
89079 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
89080 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
89081 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
89082 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
89083 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
89084 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
89085 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
89086 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
89087 +user_read_51881 user_read 3 51881 NULL
89088 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
89089 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
89090 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
89091 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
89092 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
89093 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
89094 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
89095 +async_setkey_35521 async_setkey 3 35521 NULL
89096 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
89097 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
89098 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
89099 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
89100 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
89101 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
89102 +add_tty_40055 add_tty 1 40055 NULL nohasharray
89103 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
89104 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
89105 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
89106 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
89107 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
89108 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
89109 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
89110 +alloc_context_3194 alloc_context 1 3194 NULL
89111 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
89112 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
89113 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
89114 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
89115 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
89116 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
89117 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
89118 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
89119 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
89120 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
89121 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
89122 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
89123 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
89124 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
89125 +init_state_60165 init_state 2 60165 NULL
89126 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
89127 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
89128 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
89129 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
89130 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
89131 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
89132 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
89133 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
89134 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
89135 +calc_hmac_32010 calc_hmac 3 32010 NULL
89136 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
89137 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
89138 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
89139 +kernel_readv_35617 kernel_readv 3 35617 NULL
89140 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
89141 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
89142 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
89143 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
89144 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
89145 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
89146 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
89147 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
89148 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
89149 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
89150 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
89151 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
89152 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
89153 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
89154 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
89155 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
89156 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
89157 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
89158 +store_debug_level_35652 store_debug_level 3 35652 NULL
89159 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
89160 +read_flush_43851 read_flush 3 43851 NULL
89161 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
89162 +cmm_write_2896 cmm_write 3 2896 NULL
89163 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
89164 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
89165 +tunables_write_59563 tunables_write 3 59563 NULL
89166 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
89167 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
89168 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
89169 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
89170 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
89171 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
89172 +dm_table_create_35687 dm_table_create 3 35687 NULL
89173 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
89174 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
89175 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
89176 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
89177 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
89178 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
89179 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
89180 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
89181 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
89182 +debug_read_19322 debug_read 3 19322 NULL
89183 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
89184 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
89185 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
89186 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
89187 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
89188 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
89189 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
89190 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
89191 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
89192 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
89193 +doc_probe_23285 doc_probe 1 23285 NULL
89194 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
89195 +SendString_43928 SendString 3 43928 NULL
89196 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
89197 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
89198 +retry_count_read_52129 retry_count_read 3 52129 NULL
89199 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
89200 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
89201 +read_zero_19366 read_zero 3 19366 NULL
89202 +bch_alloc_4593 bch_alloc 1 4593 NULL
89203 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
89204 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
89205 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
89206 +raid5_resize_63306 raid5_resize 2 63306 NULL
89207 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
89208 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
89209 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
89210 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
89211 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
89212 +depth_write_3021 depth_write 3 3021 NULL
89213 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
89214 +read_file_stations_35795 read_file_stations 3 35795 NULL
89215 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
89216 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
89217 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
89218 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
89219 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
89220 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
89221 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
89222 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
89223 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
89224 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
89225 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
89226 +driver_names_read_60399 driver_names_read 3 60399 NULL
89227 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
89228 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
89229 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
89230 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
89231 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
89232 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
89233 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
89234 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
89235 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
89236 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
89237 +rx_data_60442 rx_data 4 60442 NULL
89238 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
89239 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
89240 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
89241 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
89242 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
89243 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
89244 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
89245 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
89246 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
89247 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
89248 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
89249 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
89250 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
89251 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
89252 +construct_key_11329 construct_key 3 11329 NULL
89253 +evm_write_key_27715 evm_write_key 3 27715 NULL
89254 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
89255 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
89256 +filldir_55137 filldir 3 55137 NULL
89257 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
89258 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
89259 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
89260 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
89261 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
89262 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
89263 +sel_write_create_11353 sel_write_create 3 11353 NULL
89264 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
89265 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
89266 +hwflags_read_52318 hwflags_read 3 52318 NULL
89267 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
89268 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
89269 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
89270 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
89271 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
89272 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
89273 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
89274 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
89275 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
89276 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
89277 +nfsd_read_19568 nfsd_read 5 19568 NULL
89278 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
89279 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
89280 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
89281 +kcalloc_27770 kcalloc 1-2 27770 NULL
89282 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
89283 +bm_status_read_19583 bm_status_read 3 19583 NULL
89284 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
89285 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
89286 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
89287 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
89288 +acl_alloc_35979 acl_alloc 1 35979 NULL
89289 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
89290 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
89291 +str_to_user_11411 str_to_user 2 11411 NULL
89292 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
89293 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
89294 +trace_options_read_11419 trace_options_read 3 11419 NULL
89295 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
89296 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
89297 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
89298 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
89299 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
89300 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
89301 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
89302 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
89303 +console_store_36007 console_store 4 36007 NULL
89304 +bttv_read_11432 bttv_read 3 11432 NULL
89305 +key_key_read_3241 key_key_read 3 3241 NULL
89306 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
89307 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
89308 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
89309 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
89310 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
89311 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
89312 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
89313 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
89314 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
89315 +um_idi_write_18293 um_idi_write 3 18293 NULL
89316 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
89317 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
89318 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
89319 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
89320 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
89321 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
89322 +sys_init_module_36047 sys_init_module 2 36047 NULL
89323 +read_profile_27859 read_profile 3 27859 NULL
89324 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
89325 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
89326 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
89327 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
89328 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
89329 +refill_pool_19477 refill_pool 2 19477 NULL
89330 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
89331 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
89332 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
89333 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
89334 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
89335 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
89336 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
89337 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
89338 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
89339 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
89340 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
89341 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
89342 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
89343 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
89344 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
89345 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
89346 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
89347 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
89348 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
89349 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
89350 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
89351 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
89352 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
89353 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
89354 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
89355 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
89356 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
89357 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
89358 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
89359 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
89360 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
89361 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
89362 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
89363 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
89364 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
89365 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
89366 +init_data_container_60709 init_data_container 1 60709 NULL
89367 +p9_client_read_19750 p9_client_read 5 19750 NULL
89368 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
89369 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
89370 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
89371 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
89372 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
89373 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
89374 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
89375 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
89376 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
89377 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
89378 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
89379 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
89380 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
89381 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
89382 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
89383 +send_stream_3397 send_stream 4 3397 NULL
89384 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
89385 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
89386 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
89387 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
89388 +msix_map_region_3411 msix_map_region 3 3411 NULL
89389 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
89390 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
89391 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
89392 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
89393 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
89394 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
89395 +opticon_write_60775 opticon_write 4 60775 NULL
89396 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
89397 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
89398 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
89399 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
89400 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
89401 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
89402 +vip_read_19832 vip_read 3 19832 NULL
89403 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
89404 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
89405 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
89406 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
89407 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
89408 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
89409 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
89410 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
89411 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
89412 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
89413 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
89414 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
89415 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
89416 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
89417 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
89418 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
89419 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
89420 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
89421 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
89422 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
89423 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
89424 +split_11691 split 2 11691 NULL
89425 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
89426 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
89427 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
89428 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
89429 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
89430 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
89431 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
89432 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
89433 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
89434 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
89435 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
89436 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
89437 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
89438 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
89439 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
89440 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
89441 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
89442 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
89443 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
89444 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
89445 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
89446 +spidev_write_44510 spidev_write 3 44510 NULL
89447 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
89448 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
89449 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
89450 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
89451 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
89452 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
89453 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
89454 +kone_receive_4690 kone_receive 4 4690 NULL
89455 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
89456 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
89457 +evtchn_read_3569 evtchn_read 3 3569 NULL
89458 +video_read_28148 video_read 3 28148 NULL
89459 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
89460 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
89461 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
89462 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
89463 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
89464 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
89465 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
89466 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
89467 +vc_resize_3585 vc_resize 2-3 3585 NULL
89468 +gluebi_write_27905 gluebi_write 3 27905 NULL
89469 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
89470 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
89471 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
89472 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
89473 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
89474 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
89475 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
89476 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
89477 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
89478 +pti_char_write_60960 pti_char_write 3 60960 NULL
89479 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
89480 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
89481 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
89482 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
89483 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
89484 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
89485 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
89486 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
89487 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
89488 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
89489 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
89490 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
89491 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
89492 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
89493 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
89494 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
89495 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
89496 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
89497 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
89498 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
89499 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
89500 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
89501 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
89502 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
89503 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
89504 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
89505 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
89506 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
89507 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
89508 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
89509 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
89510 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
89511 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
89512 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
89513 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
89514 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
89515 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
89516 +symtab_init_61050 symtab_init 2 61050 NULL
89517 +team_options_register_20091 team_options_register 3 20091 NULL
89518 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
89519 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
89520 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
89521 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
89522 +mpi_resize_44674 mpi_resize 2 44674 NULL
89523 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
89524 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
89525 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
89526 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
89527 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
89528 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
89529 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
89530 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
89531 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
89532 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
89533 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
89534 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
89535 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
89536 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
89537 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
89538 +pms_read_53873 pms_read 3 53873 NULL
89539 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
89540 +get_derived_key_61100 get_derived_key 4 61100 NULL
89541 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
89542 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
89543 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
89544 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
89545 +dm_read_15674 dm_read 3 15674 NULL
89546 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
89547 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
89548 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
89549 +kone_send_63435 kone_send 4 63435 NULL
89550 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
89551 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
89552 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
89553 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
89554 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
89555 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
89556 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
89557 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
89558 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
89559 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
89560 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
89561 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
89562 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
89563 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
89564 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
89565 +send_packet_52960 send_packet 4 52960 NULL
89566 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
89567 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
89568 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
89569 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
89570 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
89571 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
89572 +put_cmsg_36589 put_cmsg 4 36589 NULL
89573 +__vmalloc_61168 __vmalloc 1 61168 NULL
89574 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
89575 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
89576 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
89577 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
89578 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
89579 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
89580 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
89581 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
89582 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
89583 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
89584 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
89585 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
89586 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
89587 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
89588 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
89589 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
89590 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
89591 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
89592 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
89593 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
89594 +get_fd_set_3866 get_fd_set 1 3866 NULL
89595 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
89596 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
89597 +unlink_queued_645 unlink_queued 3-4 645 NULL
89598 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
89599 +sisusb_write_44834 sisusb_write 3 44834 NULL
89600 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
89601 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
89602 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
89603 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
89604 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
89605 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
89606 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
89607 +nvram_write_3894 nvram_write 3 3894 NULL
89608 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
89609 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
89610 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
89611 +vcs_write_3910 vcs_write 3 3910 NULL
89612 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
89613 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
89614 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
89615 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
89616 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
89617 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
89618 +do_tty_write_44896 do_tty_write 5 44896 NULL
89619 +set_powered_12129 set_powered 4 12129 NULL
89620 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
89621 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
89622 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
89623 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
89624 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
89625 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
89626 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
89627 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
89628 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
89629 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
89630 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
89631 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
89632 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
89633 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
89634 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
89635 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
89636 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
89637 +gather_array_56641 gather_array 3 56641 NULL
89638 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
89639 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
89640 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
89641 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
89642 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
89643 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
89644 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
89645 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
89646 +do_add_counters_3992 do_add_counters 3 3992 NULL
89647 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
89648 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
89649 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
89650 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
89651 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
89652 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
89653 +mei_write_4005 mei_write 3 4005 NULL
89654 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
89655 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
89656 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
89657 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
89658 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
89659 +receive_copy_12216 receive_copy 3 12216 NULL
89660 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
89661 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
89662 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
89663 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
89664 +change_xattr_61390 change_xattr 5 61390 NULL
89665 +find_skb_20431 find_skb 2 20431 NULL
89666 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
89667 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
89668 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
89669 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
89670 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
89671 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
89672 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
89673 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
89674 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
89675 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
89676 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
89677 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
89678 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
89679 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
89680 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
89681 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
89682 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
89683 +read_buf_20469 read_buf 2 20469 NULL
89684 +cm_write_36858 cm_write 3 36858 NULL
89685 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
89686 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
89687 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
89688 +sel_write_user_45060 sel_write_user 3 45060 NULL
89689 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
89690 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
89691 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
89692 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
89693 +fast_user_write_20494 fast_user_write 5 20494 NULL
89694 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
89695 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
89696 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
89697 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
89698 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
89699 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
89700 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
89701 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
89702 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
89703 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
89704 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
89705 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
89706 +osst_read_40237 osst_read 3 40237 NULL
89707 +tm6000_read_4151 tm6000_read 3 4151 NULL
89708 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
89709 +usbdev_read_45114 usbdev_read 3 45114 NULL
89710 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
89711 +spi_execute_28736 spi_execute 5 28736 NULL
89712 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
89713 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
89714 +get_alua_req_4166 get_alua_req 3 4166 NULL
89715 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
89716 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
89717 +venus_create_20555 venus_create 4 20555 NULL
89718 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
89719 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
89720 +receive_packet_12367 receive_packet 2 12367 NULL
89721 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
89722 +mem_write_22232 mem_write 3 22232 NULL
89723 +read_file_bool_4180 read_file_bool 3 4180 NULL
89724 +send_to_tty_45141 send_to_tty 3 45141 NULL
89725 +fops_read_40672 fops_read 3 40672 NULL
89726 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
89727 +write_leb_36957 write_leb 5 36957 NULL
89728 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
89729 +device_write_45156 device_write 3 45156 NULL
89730 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
89731 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
89732 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
89733 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
89734 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
89735 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
89736 +isp1760_register_628 isp1760_register 1-2 628 NULL
89737 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
89738 +lirc_write_20604 lirc_write 3 20604 NULL
89739 +sel_write_member_28800 sel_write_member 3 28800 NULL
89740 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
89741 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
89742 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
89743 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
89744 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
89745 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
89746 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
89747 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
89748 +setxattr_37006 setxattr 4 37006 NULL
89749 +add_child_45201 add_child 4 45201 NULL
89750 +seq_open_private_61589 seq_open_private 3 61589 NULL
89751 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
89752 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
89753 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
89754 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
89755 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
89756 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
89757 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
89758 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
89759 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
89760 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
89761 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
89762 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
89763 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
89764 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
89765 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
89766 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
89767 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
89768 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
89769 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
89770 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
89771 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
89772 +resize_stripes_61650 resize_stripes 2 61650 NULL
89773 +n2_run_53459 n2_run 3 53459 NULL
89774 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
89775 +parse_command_37079 parse_command 2 37079 NULL
89776 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
89777 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
89778 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
89779 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
89780 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
89781 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
89782 +insert_one_name_61668 insert_one_name 7 61668 NULL
89783 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
89784 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
89785 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
89786 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
89787 +lock_loop_61681 lock_loop 1 61681 NULL
89788 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
89789 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
89790 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
89791 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
89792 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
89793 +push_rx_28939 push_rx 3 28939 NULL
89794 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
89795 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
89796 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
89797 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
89798 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
89799 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
89800 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
89801 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
89802 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
89803 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
89804 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
89805 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
89806 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
89807 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
89808 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
89809 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
89810 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
89811 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
89812 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
89813 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
89814 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
89815 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
89816 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
89817 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
89818 +bin_uuid_28999 bin_uuid 3 28999 NULL
89819 +sys_sendto_20809 sys_sendto 6 20809 NULL
89820 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
89821 +set_registers_53582 set_registers 3 53582 NULL
89822 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
89823 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
89824 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
89825 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
89826 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
89827 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
89828 +keymap_store_45406 keymap_store 4 45406 NULL
89829 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
89830 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
89831 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
89832 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
89833 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
89834 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
89835 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
89836 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
89837 +__do_replace_37227 __do_replace 5 37227 NULL
89838 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
89839 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
89840 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
89841 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
89842 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
89843 +tso_fragment_29050 tso_fragment 3 29050 NULL
89844 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
89845 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
89846 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
89847 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
89848 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
89849 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
89850 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
89851 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
89852 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
89853 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
89854 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
89855 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
89856 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
89857 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
89858 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
89859 +set_link_security_4502 set_link_security 4 4502 NULL
89860 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
89861 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
89862 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
89863 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
89864 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
89865 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
89866 +mmio_read_40348 mmio_read 4 40348 NULL
89867 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
89868 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
89869 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
89870 +ivtv_write_12721 ivtv_write 3 12721 NULL
89871 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
89872 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
89873 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
89874 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
89875 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
89876 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
89877 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
89878 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
89879 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
89880 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
89881 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
89882 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
89883 +send_msg_37323 send_msg 4 37323 NULL
89884 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
89885 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
89886 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
89887 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
89888 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
89889 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
89890 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
89891 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
89892 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
89893 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
89894 +reshape_ring_29147 reshape_ring 2 29147 NULL
89895 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
89896 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
89897 +copy_macs_45534 copy_macs 4 45534 NULL
89898 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
89899 +listxattr_12769 listxattr 3 12769 NULL
89900 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
89901 +wdm_write_53735 wdm_write 3 53735 NULL
89902 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
89903 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
89904 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
89905 +mempool_create_29437 mempool_create 1 29437 NULL
89906 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
89907 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
89908 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
89909 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
89910 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
89911 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
89912 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
89913 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
89914 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
89915 +mgmt_event_12810 mgmt_event 4 12810 NULL
89916 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
89917 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
89918 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
89919 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
89920 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
89921 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
89922 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
89923 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
89924 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
89925 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
89926 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
89927 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
89928 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
89929 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
89930 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
89931 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
89932 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
89933 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
89934 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
89935 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
89936 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
89937 +recover_peb_29238 recover_peb 6-7 29238 NULL
89938 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
89939 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
89940 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
89941 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
89942 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
89943 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
89944 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
89945 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
89946 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
89947 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
89948 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
89949 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
89950 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
89951 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
89952 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
89953 +do_pselect_62061 do_pselect 1 62061 NULL
89954 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
89955 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
89956 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
89957 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
89958 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
89959 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
89960 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
89961 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
89962 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
89963 +sg_read_25799 sg_read 3 25799 NULL
89964 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
89965 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
89966 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
89967 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
89968 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
89969 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
89970 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
89971 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
89972 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
89973 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
89974 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
89975 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
89976 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
89977 +new_skb_21148 new_skb 1 21148 NULL
89978 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
89979 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
89980 +bm_status_write_12964 bm_status_write 3 12964 NULL
89981 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
89982 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
89983 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
89984 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
89985 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
89986 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
89987 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
89988 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
89989 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
89990 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
89991 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
89992 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
89993 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
89994 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
89995 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
89996 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
89997 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
89998 +video_usercopy_62151 video_usercopy 2 62151 NULL
89999 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
90000 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
90001 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
90002 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
90003 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
90004 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
90005 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
90006 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
90007 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
90008 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
90009 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
90010 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
90011 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
90012 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
90013 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
90014 +input_ff_create_21240 input_ff_create 2 21240 NULL
90015 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
90016 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
90017 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
90018 +amthi_read_45831 amthi_read 4 45831 NULL
90019 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
90020 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
90021 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
90022 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
90023 +sys_ipc_4889 sys_ipc 3 4889 NULL
90024 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
90025 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
90026 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
90027 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
90028 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
90029 +do_register_entry_29478 do_register_entry 4 29478 NULL
90030 +isdn_write_45863 isdn_write 3 45863 NULL
90031 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
90032 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
90033 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
90034 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
90035 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
90036 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
90037 +_malloc_54077 _malloc 1 54077 NULL
90038 +add_res_range_21310 add_res_range 4 21310 NULL
90039 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
90040 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
90041 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
90042 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
90043 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
90044 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
90045 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
90046 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
90047 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
90048 +create_xattr_54106 create_xattr 5 54106 NULL
90049 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
90050 +ep_write_59008 ep_write 3 59008 NULL
90051 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
90052 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
90053 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
90054 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
90055 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
90056 +alloc_mr_45935 alloc_mr 1 45935 NULL
90057 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
90058 +isku_receive_54130 isku_receive 4 54130 NULL
90059 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
90060 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
90061 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
90062 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
90063 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
90064 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
90065 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
90066 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
90067 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
90068 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
90069 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
90070 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
90071 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
90072 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
90073 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
90074 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
90075 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
90076 +comedi_read_13199 comedi_read 3 13199 NULL
90077 +flash_write_62354 flash_write 3 62354 NULL
90078 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
90079 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
90080 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
90081 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
90082 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
90083 +proc_file_read_53905 proc_file_read 3 53905 NULL
90084 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
90085 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
90086 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
90087 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
90088 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
90089 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
90090 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
90091 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
90092 +cru_detect_11272 cru_detect 1 11272 NULL
90093 +altera_irscan_62396 altera_irscan 2 62396 NULL
90094 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
90095 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
90096 +fw_download_code_13249 fw_download_code 3 13249 NULL
90097 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
90098 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
90099 +set_ssp_62411 set_ssp 4 62411 NULL
90100 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
90101 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
90102 +get_free_entries_46030 get_free_entries 1 46030 NULL
90103 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
90104 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
90105 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
90106 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
90107 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
90108 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
90109 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
90110 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
90111 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
90112 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
90113 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
90114 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
90115 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
90116 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
90117 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
90118 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
90119 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
90120 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
90121 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
90122 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
90123 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
90124 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
90125 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
90126 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
90127 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
90128 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
90129 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
90130 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
90131 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
90132 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
90133 +probes_write_29711 probes_write 3 29711 NULL
90134 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
90135 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
90136 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
90137 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
90138 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
90139 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
90140 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
90141 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
90142 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
90143 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
90144 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
90145 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
90146 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
90147 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
90148 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
90149 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
90150 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
90151 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
90152 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
90153 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
90154 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
90155 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
90156 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
90157 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
90158 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
90159 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
90160 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
90161 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
90162 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
90163 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
90164 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
90165 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
90166 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
90167 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
90168 +isdn_read_50021 isdn_read 3 50021 NULL
90169 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
90170 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
90171 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
90172 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
90173 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
90174 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
90175 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
90176 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
90177 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
90178 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
90179 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
90180 +get_subdir_62581 get_subdir 3 62581 NULL
90181 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
90182 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
90183 +vfs_readv_38011 vfs_readv 3 38011 NULL
90184 +keyring_read_13438 keyring_read 3 13438 NULL
90185 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
90186 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
90187 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
90188 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
90189 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
90190 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
90191 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
90192 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
90193 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
90194 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
90195 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
90196 +ftrace_write_29551 ftrace_write 3 29551 NULL
90197 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
90198 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
90199 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
90200 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
90201 +dev_write_7708 dev_write 3 7708 NULL
90202 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
90203 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
90204 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
90205 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
90206 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
90207 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
90208 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
90209 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
90210 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
90211 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
90212 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
90213 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
90214 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
90215 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
90216 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
90217 +bm_init_13529 bm_init 2 13529 NULL
90218 +check586_29914 check586 2 29914 NULL
90219 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
90220 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
90221 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
90222 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
90223 +pg_read_17276 pg_read 3 17276 NULL
90224 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
90225 +ep0_read_38095 ep0_read 3 38095 NULL
90226 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
90227 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
90228 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
90229 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
90230 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
90231 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
90232 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
90233 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
90234 +l2down_create_21755 l2down_create 4 21755 NULL
90235 +alloc_tio_13564 alloc_tio 3 13564 NULL
90236 +viacam_read_54526 viacam_read 3 54526 NULL
90237 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
90238 +tunables_read_36385 tunables_read 3 36385 NULL
90239 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
90240 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
90241 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
90242 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
90243 +setsockopt_54539 setsockopt 5 54539 NULL
90244 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
90245 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
90246 +tty_register_device_4544 tty_register_device 2 4544 NULL
90247 +cache_write_13589 cache_write 3 13589 NULL
90248 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
90249 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
90250 +key_replays_read_62746 key_replays_read 3 62746 NULL
90251 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
90252 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
90253 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
90254 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
90255 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
90256 +cdev_add_38176 cdev_add 2-3 38176 NULL
90257 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
90258 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
90259 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
90260 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
90261 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
90262 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
90263 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
90264 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
90265 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
90266 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
90267 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
90268 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
90269 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
90270 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
90271 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
90272 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
90273 +packet_snd_13634 packet_snd 3 13634 NULL
90274 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
90275 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
90276 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
90277 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
90278 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
90279 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
90280 +drp_wmove_30043 drp_wmove 4 30043 NULL
90281 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
90282 +cache_downcall_13666 cache_downcall 3 13666 NULL
90283 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
90284 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
90285 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
90286 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
90287 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
90288 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
90289 +tty_write_5494 tty_write 3 5494 NULL
90290 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
90291 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
90292 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
90293 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
90294 +teiup_create_43201 teiup_create 3 43201 NULL
90295 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
90296 +filldir64_46469 filldir64 3 46469 NULL
90297 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
90298 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
90299 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
90300 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
90301 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
90302 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
90303 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
90304 +spidev_message_5518 spidev_message 3 5518 NULL
90305 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
90306 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
90307 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
90308 +evm_read_key_54674 evm_read_key 3 54674 NULL
90309 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
90310 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
90311 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
90312 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
90313 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
90314 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
90315 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
90316 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
90317 +u32_array_read_2219 u32_array_read 3 2219 NULL
90318 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
90319 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
90320 +sys_add_key_61288 sys_add_key 4 61288 NULL
90321 +kmsg_read_46514 kmsg_read 3 46514 NULL
90322 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
90323 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
90324 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
90325 +recv_stream_30138 recv_stream 4 30138 NULL
90326 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
90327 +getdqbuf_62908 getdqbuf 1 62908 NULL
90328 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
90329 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
90330 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
90331 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
90332 +fir16_create_5574 fir16_create 3 5574 NULL
90333 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
90334 +pt_write_40159 pt_write 3 40159 NULL
90335 +bioset_create_5580 bioset_create 1 5580 NULL
90336 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
90337 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
90338 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
90339 +kzalloc_54740 kzalloc 1 54740 NULL
90340 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
90341 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
90342 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
90343 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
90344 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
90345 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
90346 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
90347 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
90348 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
90349 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
90350 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
90351 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
90352 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
90353 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
90354 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
90355 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
90356 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
90357 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
90358 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
90359 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
90360 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
90361 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
90362 +ti_recv_22027 ti_recv 4 22027 NULL
90363 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
90364 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
90365 +nfsd_write_54809 nfsd_write 6 54809 NULL
90366 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
90367 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
90368 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
90369 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
90370 +get_skb_63008 get_skb 2 63008 NULL
90371 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
90372 +netlink_send_38434 netlink_send 5 38434 NULL
90373 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
90374 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
90375 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
90376 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
90377 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
90378 +write_rio_54837 write_rio 3 54837 NULL
90379 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
90380 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
90381 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
90382 +get_arg_5694 get_arg 3 5694 NULL
90383 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
90384 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
90385 +compat_readv_30273 compat_readv 3 30273 NULL
90386 +printer_read_54851 printer_read 3 54851 NULL
90387 +mem_rw_22085 mem_rw 3 22085 NULL
90388 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
90389 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
90390 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
90391 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
90392 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
90393 +unlink1_63059 unlink1 3 63059 NULL
90394 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
90395 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
90396 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
90397 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
90398 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
90399 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
90400 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
90401 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
90402 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
90403 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
90404 +dev_names_read_38509 dev_names_read 3 38509 NULL
90405 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
90406 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
90407 +get_packet_5747 get_packet 3 5747 NULL
90408 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
90409 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
90410 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
90411 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
90412 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
90413 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
90414 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
90415 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
90416 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
90417 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
90418 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
90419 +resource_from_user_30341 resource_from_user 3 30341 NULL
90420 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
90421 +sound_write_5102 sound_write 3 5102 NULL
90422 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
90423 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
90424 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
90425 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
90426 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
90427 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
90428 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
90429 +com90xx_found_13974 com90xx_found 3 13974 NULL
90430 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
90431 +qcam_read_13977 qcam_read 3 13977 NULL
90432 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
90433 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
90434 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
90435 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
90436 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
90437 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
90438 +generic_readlink_32654 generic_readlink 3 32654 NULL
90439 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
90440 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
90441 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
90442 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
90443 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
90444 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
90445 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
90446 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
90447 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
90448 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
90449 +concat_writev_21451 concat_writev 3 21451 NULL
90450 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
90451 +_queue_data_54983 _queue_data 4 54983 NULL
90452 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
90453 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
90454 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
90455 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
90456 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
90457 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
90458 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
90459 +setup_req_5848 setup_req 3 5848 NULL
90460 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
90461 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
90462 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
90463 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
90464 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
90465 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
90466 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
90467 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
90468 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
90469 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
90470 +cma_create_area_38642 cma_create_area 2 38642 NULL
90471 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
90472 +sriov_enable_59689 sriov_enable 2 59689 NULL
90473 +enable_write_30456 enable_write 3 30456 NULL
90474 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
90475 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
90476 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
90477 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
90478 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
90479 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
90480 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
90481 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
90482 +port_show_regs_5904 port_show_regs 3 5904 NULL
90483 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
90484 +ptp_read_63251 ptp_read 4 63251 NULL
90485 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
90486 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
90487 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
90488 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
90489 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
90490 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
90491 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
90492 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
90493 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
90494 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
90495 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
90496 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
90497 +read_dma_55086 read_dma 3 55086 NULL
90498 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
90499 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
90500 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
90501 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
90502 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
90503 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
90504 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
90505 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
90506 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
90507 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
90508 +em_canid_change_14150 em_canid_change 3 14150 NULL
90509 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
90510 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
90511 +fb_write_46924 fb_write 3 46924 NULL
90512 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
90513 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
90514 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
90515 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
90516 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
90517 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
90518 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
90519 +udf_readpages_38761 udf_readpages 4 38761 NULL
90520 +reada_add_block_54247 reada_add_block 2 54247 NULL
90521 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
90522 +proc_info_read_63344 proc_info_read 3 63344 NULL
90523 +pep_indicate_38611 pep_indicate 5 38611 NULL
90524 +set_le_30581 set_le 4 30581 NULL
90525 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
90526 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
90527 +alloc_private_22399 alloc_private 2 22399 NULL
90528 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
90529 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
90530 +zoran_write_22404 zoran_write 3 22404 NULL
90531 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
90532 +idmouse_read_63374 idmouse_read 3 63374 NULL
90533 +queue_reply_22416 queue_reply 3 22416 NULL
90534 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
90535 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
90536 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
90537 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
90538 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
90539 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
90540 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
90541 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
90542 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
90543 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
90544 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
90545 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
90546 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
90547 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
90548 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
90549 +sys_select_38827 sys_select 1 38827 NULL
90550 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
90551 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
90552 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
90553 +direct_entry_38836 direct_entry 3 38836 NULL
90554 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
90555 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
90556 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
90557 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
90558 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
90559 +write_head_30481 write_head 4 30481 NULL
90560 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
90561 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
90562 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
90563 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
90564 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
90565 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
90566 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
90567 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
90568 +agp_remap_30665 agp_remap 2 30665 NULL
90569 +interfaces_38859 interfaces 2 38859 NULL
90570 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
90571 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
90572 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
90573 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
90574 +qc_capture_19298 qc_capture 3 19298 NULL
90575 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
90576 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
90577 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
90578 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
90579 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
90580 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
90581 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
90582 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
90583 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
90584 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
90585 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
90586 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
90587 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
90588 +read_kcore_63488 read_kcore 3 63488 NULL
90589 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
90590 +__skb_cow_39254 __skb_cow 2 39254 NULL
90591 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
90592 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
90593 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
90594 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
90595 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
90596 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
90597 +mousedev_read_47123 mousedev_read 3 47123 NULL
90598 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
90599 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
90600 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
90601 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
90602 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
90603 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
90604 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
90605 +vme_user_read_55338 vme_user_read 3 55338 NULL
90606 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
90607 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
90608 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
90609 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
90610 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
90611 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
90612 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
90613 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
90614 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
90615 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
90616 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
90617 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
90618 +snapshot_read_22601 snapshot_read 3 22601 NULL
90619 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
90620 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
90621 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
90622 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
90623 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
90624 +__send_to_port_55383 __send_to_port 3 55383 NULL
90625 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
90626 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
90627 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
90628 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
90629 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
90630 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
90631 +get_nodes_39012 get_nodes 3 39012 NULL
90632 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
90633 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
90634 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
90635 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
90636 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
90637 +create_subvol_30836 create_subvol 4 30836 NULL
90638 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
90639 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
90640 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
90641 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
90642 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
90643 +read_oldmem_55658 read_oldmem 3 55658 NULL
90644 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
90645 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
90646 +options_write_47243 options_write 3 47243 NULL
90647 +module_alloc_63630 module_alloc 1 63630 NULL
90648 +alloc_skb_55439 alloc_skb 1 55439 NULL
90649 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
90650 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
90651 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
90652 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
90653 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
90654 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
90655 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
90656 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
90657 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
90658 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
90659 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
90660 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
90661 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
90662 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
90663 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
90664 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
90665 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
90666 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
90667 +vbi_read_63673 vbi_read 3 63673 NULL
90668 +tun_get_user_39099 tun_get_user 4 39099 NULL
90669 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
90670 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
90671 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
90672 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
90673 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
90674 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
90675 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
90676 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
90677 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
90678 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
90679 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
90680 +ax25_output_22736 ax25_output 2 22736 NULL
90681 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
90682 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
90683 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
90684 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
90685 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
90686 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
90687 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
90688 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
90689 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
90690 +hid_input_report_32458 hid_input_report 4 32458 NULL
90691 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
90692 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
90693 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
90694 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
90695 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
90696 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
90697 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
90698 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
90699 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
90700 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
90701 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
90702 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
90703 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
90704 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
90705 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
90706 +get_info_55681 get_info 3 55681 NULL
90707 +setkey_14987 setkey 3 14987 NULL
90708 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
90709 +init_list_set_39188 init_list_set 2-3 39188 NULL
90710 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
90711 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
90712 +l2up_create_6430 l2up_create 3 6430 NULL
90713 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
90714 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
90715 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
90716 +add_partition_55588 add_partition 2 55588 NULL
90717 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
90718 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
90719 +depth_read_31112 depth_read 3 31112 NULL
90720 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
90721 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
90722 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
90723 +profile_replace_14652 profile_replace 3 14652 NULL
90724 +vzalloc_47421 vzalloc 1 47421 NULL
90725 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
90726 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
90727 +sys_writev_28384 sys_writev 3 28384 NULL
90728 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
90729 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
90730 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
90731 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
90732 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
90733 +create_attr_set_22861 create_attr_set 1 22861 NULL
90734 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
90735 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
90736 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
90737 +sel_write_load_63830 sel_write_load 3 63830 NULL
90738 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
90739 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
90740 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
90741 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
90742 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
90743 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
90744 +probe_bios_17467 probe_bios 1 17467 NULL
90745 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
90746 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
90747 +mei_read_6507 mei_read 3 6507 NULL
90748 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
90749 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
90750 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
90751 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
90752 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
90753 +SetArea_50835 SetArea 4 50835 NULL
90754 +tpm_read_50344 tpm_read 3 50344 NULL
90755 +newpart_47485 newpart 6 47485 NULL
90756 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
90757 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
90758 +core_sys_select_47494 core_sys_select 1 47494 NULL
90759 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
90760 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
90761 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
90762 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
90763 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
90764 +unlink_simple_47506 unlink_simple 3 47506 NULL
90765 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
90766 +wdm_read_6549 wdm_read 3 6549 NULL
90767 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
90768 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
90769 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
90770 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
90771 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
90772 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
90773 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
90774 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
90775 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
90776 +filter_read_61692 filter_read 3 61692 NULL
90777 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
90778 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
90779 +debugfs_read_62535 debugfs_read 3 62535 NULL
90780 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
90781 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
90782 +divas_write_63901 divas_write 3 63901 NULL
90783 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
90784 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
90785 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
90786 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
90787 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
90788 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
90789 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
90790 +ipw_write_59807 ipw_write 3 59807 NULL
90791 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
90792 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
90793 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
90794 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
90795 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
90796 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
90797 +cycx_setup_47562 cycx_setup 4 47562 NULL
90798 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
90799 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
90800 +set_local_name_55757 set_local_name 4 55757 NULL
90801 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
90802 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
90803 +read_ldt_47570 read_ldt 2 47570 NULL
90804 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
90805 +pci_iomap_47575 pci_iomap 3 47575 NULL
90806 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
90807 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
90808 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
90809 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
90810 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
90811 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
90812 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
90813 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
90814 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
90815 +conf_read_55786 conf_read 3 55786 NULL
90816 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
90817 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
90818 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
90819 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
90820 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
90821 +user_power_read_39414 user_power_read 3 39414 NULL
90822 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
90823 +uea_request_47613 uea_request 4 47613 NULL
90824 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
90825 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
90826 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
90827 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
90828 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
90829 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
90830 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
90831 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
90832 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
90833 +kmemdup_64015 kmemdup 2 64015 NULL
90834 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
90835 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
90836 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
90837 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
90838 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
90839 +oz_events_read_47535 oz_events_read 3 47535 NULL
90840 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
90841 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
90842 +sys_semop_39457 sys_semop 3 39457 NULL
90843 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
90844 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
90845 +update_pmkid_2481 update_pmkid 4 2481 NULL
90846 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
90847 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
90848 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
90849 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
90850 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
90851 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
90852 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
90853 +mpeg_read_6708 mpeg_read 3 6708 NULL
90854 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
90855 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
90856 +sky2_receive_13407 sky2_receive 2 13407 NULL
90857 +krealloc_14908 krealloc 2 14908 NULL
90858 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
90859 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
90860 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
90861 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
90862 +video_proc_write_6724 video_proc_write 3 6724 NULL
90863 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
90864 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
90865 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
90866 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
90867 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
90868 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
90869 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
90870 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
90871 +command_file_write_31318 command_file_write 3 31318 NULL
90872 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
90873 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
90874 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
90875 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
90876 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
90877 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
90878 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
90879 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
90880 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
90881 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
90882 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
90883 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
90884 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
90885 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
90886 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
90887 +int_proc_write_39542 int_proc_write 3 39542 NULL
90888 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
90889 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
90890 +read_file_ani_23161 read_file_ani 3 23161 NULL
90891 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
90892 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
90893 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
90894 +pp_write_39554 pp_write 3 39554 NULL
90895 +ioremap_23172 ioremap 1-2 23172 NULL
90896 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
90897 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
90898 +usblp_write_23178 usblp_write 3 23178 NULL
90899 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
90900 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
90901 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
90902 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
90903 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
90904 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
90905 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
90906 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
90907 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
90908 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
90909 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
90910 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
90911 +__team_options_register_63941 __team_options_register 3 63941 NULL
90912 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
90913 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
90914 +rvmalloc_46873 rvmalloc 1 46873 NULL
90915 +vmap_15025 vmap 2 15025 NULL
90916 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
90917 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
90918 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
90919 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
90920 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
90921 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
90922 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
90923 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
90924 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
90925 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
90926 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
90927 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
90928 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
90929 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
90930 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
90931 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
90932 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
90933 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
90934 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
90935 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
90936 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
90937 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
90938 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
90939 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
90940 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
90941 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
90942 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
90943 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
90944 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
90945 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
90946 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
90947 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
90948 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
90949 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
90950 +alg_setkey_31485 alg_setkey 3 31485 NULL
90951 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
90952 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
90953 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
90954 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
90955 +vhci_read_47878 vhci_read 3 47878 NULL
90956 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
90957 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
90958 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
90959 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
90960 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
90961 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
90962 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
90963 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
90964 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
90965 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
90966 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
90967 +timeout_read_47915 timeout_read 3 47915 NULL
90968 +hidraw_write_31536 hidraw_write 3 31536 NULL
90969 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
90970 +page_readlink_23346 page_readlink 3 23346 NULL
90971 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
90972 +comedi_write_47926 comedi_write 3 47926 NULL
90973 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
90974 +dsp_write_46218 dsp_write 2 46218 NULL
90975 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
90976 +usbvision_read_31555 usbvision_read 3 31555 NULL
90977 +pd_video_read_24510 pd_video_read 3 24510 NULL
90978 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
90979 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
90980 +request_key_async_6990 request_key_async 4 6990 NULL
90981 +ts_write_64336 ts_write 3 64336 NULL
90982 +handle_response_55951 handle_response 5 55951 NULL
90983 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
90984 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
90985 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
90986 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
90987 +osst_write_31581 osst_write 3 31581 NULL
90988 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
90989 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
90990 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
90991 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
90992 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
90993 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
90994 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
90995 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
90996 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
90997 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
90998 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
90999 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
91000 +ilo_write_64378 ilo_write 3 64378 NULL
91001 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
91002 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
91003 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
91004 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
91005 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
91006 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
91007 +copy_from_user_17559 copy_from_user 3 17559 NULL
91008 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
91009 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
91010 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
91011 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
91012 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
91013 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
91014 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
91015 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
91016 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
91017 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
91018 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
91019 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
91020 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
91021 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
91022 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
91023 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
91024 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
91025 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
91026 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
91027 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
91028 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
91029 +__lgread_31668 __lgread 4 31668 NULL
91030 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
91031 +fd_copyin_56247 fd_copyin 3 56247 NULL
91032 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
91033 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
91034 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
91035 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
91036 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
91037 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
91038 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
91039 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
91040 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
91041 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
91042 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
91043 +event_filter_read_23494 event_filter_read 3 23494 NULL
91044 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
91045 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
91046 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
91047 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
91048 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
91049 +pkt_add_39897 pkt_add 3 39897 NULL
91050 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
91051 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
91052 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
91053 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
91054 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
91055 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
91056 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
91057 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
91058 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
91059 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
91060 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
91061 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
91062 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
91063 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
91064 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
91065 +remove_uuid_64505 remove_uuid 4 64505 NULL
91066 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
91067 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
91068 +create_table_16213 create_table 2 16213 NULL
91069 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
91070 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
91071 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
91072 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
91073 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
91074 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
91075 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
91076 +set_discoverable_48141 set_discoverable 4 48141 NULL
91077 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
91078 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
91079 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
91080 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
91081 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
91082 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
91083 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
91084 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
91085 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
91086 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
91087 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
91088 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
91089 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
91090 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
91091 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
91092 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
91093 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
91094 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
91095 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
91096 +dev_read_56369 dev_read 3 56369 NULL
91097 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
91098 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
91099 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
91100 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
91101 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
91102 +init_ipath_48187 init_ipath 1 48187 NULL
91103 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
91104 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
91105 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
91106 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
91107 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
91108 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
91109 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
91110 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
91111 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
91112 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
91113 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
91114 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
91115 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
91116 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
91117 +use_pool_64607 use_pool 2 64607 NULL
91118 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
91119 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
91120 +store_msg_56417 store_msg 3 56417 NULL
91121 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
91122 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
91123 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
91124 +read_file_recv_48232 read_file_recv 3 48232 NULL
91125 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
91126 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
91127 +fanotify_write_64623 fanotify_write 3 64623 NULL
91128 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
91129 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
91130 +fl_create_56435 fl_create 5 56435 NULL
91131 +gnttab_map_56439 gnttab_map 2 56439 NULL
91132 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
91133 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
91134 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
91135 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
91136 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
91137 +set_connectable_56458 set_connectable 4 56458 NULL
91138 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
91139 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
91140 +add_port_54941 add_port 2 54941 NULL
91141 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
91142 +cx18_read_23699 cx18_read 3 23699 NULL
91143 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
91144 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
91145 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
91146 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
91147 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
91148 +send_set_info_48288 send_set_info 7 48288 NULL
91149 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
91150 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
91151 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
91152 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
91153 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
91154 +new_dir_31919 new_dir 3 31919 NULL
91155 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
91156 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
91157 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
91158 +mgmt_control_7349 mgmt_control 3 7349 NULL
91159 +hash_setkey_48310 hash_setkey 3 48310 NULL
91160 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
91161 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
91162 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
91163 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
91164 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
91165 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
91166 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
91167 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
91168 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
91169 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
91170 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
91171 +vb2_write_31948 vb2_write 3 31948 NULL
91172 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
91173 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
91174 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
91175 +ip_options_get_56538 ip_options_get 4 56538 NULL
91176 +write_62671 write 3 62671 NULL
91177 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
91178 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
91179 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
91180 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
91181 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
91182 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
91183 +skb_add_data_48363 skb_add_data 3 48363 NULL
91184 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
91185 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
91186 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
91187 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
91188 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
91189 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
91190 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
91191 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
91192 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
91193 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
91194 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
91195 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
91196 +system_enable_read_25815 system_enable_read 3 25815 NULL
91197 +allocate_probes_40204 allocate_probes 1 40204 NULL
91198 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
91199 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
91200 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
91201 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
91202 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
91203 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
91204 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
91205 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
91206 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
91207 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
91208 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
91209 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
91210 +fs_path_add_15648 fs_path_add 3 15648 NULL
91211 +event_filter_write_56609 event_filter_write 3 56609 NULL
91212 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
91213 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
91214 +xsd_read_15653 xsd_read 3 15653 NULL
91215 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
91216 +p54_init_common_23850 p54_init_common 1 23850 NULL
91217 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
91218 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
91219 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
91220 +garp_request_join_7471 garp_request_join 4 7471 NULL
91221 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
91222 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
91223 +unifi_read_14899 unifi_read 3 14899 NULL
91224 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
91225 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
91226 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
91227 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
91228 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
91229 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
91230 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
91231 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
91232 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
91233 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
91234 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
91235 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
91236 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
91237 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
91238 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
91239 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
91240 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
91241 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
91242 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
91243 +bio_alloc_32095 bio_alloc 2 32095 NULL
91244 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
91245 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
91246 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
91247 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
91248 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
91249 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
91250 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
91251 +send_control_msg_48498 send_control_msg 6 48498 NULL
91252 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
91253 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
91254 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
91255 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
91256 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
91257 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
91258 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
91259 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
91260 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
91261 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
91262 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
91263 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
91264 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
91265 +alloc_tx_32143 alloc_tx 2 32143 NULL
91266 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
91267 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
91268 +hsc_write_55875 hsc_write 3 55875 NULL
91269 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
91270 +do_test_15766 do_test 1 15766 NULL
91271 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
91272 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
91273 +named_distribute_48544 named_distribute 4 48544 NULL
91274 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
91275 +venus_link_32165 venus_link 5 32165 NULL
91276 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
91277 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
91278 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
91279 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
91280 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
91281 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
91282 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
91283 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
91284 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
91285 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
91286 +groups_alloc_7614 groups_alloc 1 7614 NULL
91287 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
91288 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
91289 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
91290 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
91291 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
91292 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
91293 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
91294 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
91295 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
91296 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
91297 +snapshot_write_28351 snapshot_write 3 28351 NULL
91298 +event_enable_read_7074 event_enable_read 3 7074 NULL
91299 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
91300 +do_syslog_56807 do_syslog 3 56807 NULL
91301 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
91302 +pskb_pull_65005 pskb_pull 2 65005 NULL
91303 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
91304 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
91305 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
91306 +unifi_write_65012 unifi_write 3 65012 NULL
91307 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
91308 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
91309 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
91310 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
91311 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
91312 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
91313 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
91314 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
91315 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
91316 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
91317 +if_write_51756 if_write 3 51756 NULL
91318 +insert_dent_65034 insert_dent 7 65034 NULL
91319 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
91320 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
91321 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
91322 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
91323 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
91324 +lc_create_48662 lc_create 3 48662 NULL
91325 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
91326 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
91327 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
91328 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
91329 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
91330 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
91331 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
91332 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
91333 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
91334 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
91335 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
91336 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
91337 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
91338 +altera_drscan_48698 altera_drscan 2 48698 NULL
91339 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
91340 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
91341 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
91342 +power_read_15939 power_read 3 15939 NULL
91343 +recv_msg_48709 recv_msg 4 48709 NULL
91344 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
91345 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
91346 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
91347 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
91348 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
91349 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
91350 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
91351 +revalidate_19043 revalidate 2 19043 NULL
91352 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
91353 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
91354 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
91355 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
91356 +check_header_56930 check_header 2 56930 NULL
91357 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
91358 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
91359 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
91360 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
91361 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
91362 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
91363 +frame_alloc_15981 frame_alloc 4 15981 NULL
91364 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
91365 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
91366 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
91367 +adu_read_24177 adu_read 3 24177 NULL
91368 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
91369 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
91370 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
91371 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
91372 +vfd_write_14717 vfd_write 3 14717 NULL
91373 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
91374 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
91375 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
91376 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
91377 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
91378 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
91379 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
91380 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
91381 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
91382 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
91383 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
91384 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
91385 +register_device_60015 register_device 2-3 60015 NULL
91386 +got_frame_16028 got_frame 2 16028 NULL
91387 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
91388 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
91389 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
91390 +scsi_register_49094 scsi_register 2 49094 NULL
91391 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
91392 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
91393 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
91394 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
91395 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
91396 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
91397 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
91398 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
91399 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
91400 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
91401 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
91402 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
91403 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
91404 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
91405 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
91406 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
91407 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
91408 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
91409 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
91410 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
91411 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
91412 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
91413 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
91414 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
91415 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
91416 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
91417 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
91418 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
91419 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
91420 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
91421 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
91422 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
91423 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
91424 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
91425 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
91426 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
91427 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
91428 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
91429 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
91430 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
91431 +fsm_init_16134 fsm_init 2 16134 NULL
91432 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
91433 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
91434 +disconnect_32521 disconnect 4 32521 NULL
91435 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
91436 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
91437 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
91438 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
91439 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
91440 +ilo_read_32531 ilo_read 3 32531 NULL
91441 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
91442 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
91443 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
91444 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
91445 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
91446 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
91447 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
91448 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
91449 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
91450 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
91451 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
91452 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
91453 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
91454 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
91455 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
91456 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
91457 +card_send_command_40757 card_send_command 3 40757 NULL
91458 +sys_mbind_7990 sys_mbind 5 7990 NULL
91459 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
91460 +pg_write_40766 pg_write 3 40766 NULL
91461 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
91462 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
91463 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
91464 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
91465 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
91466 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
91467 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
91468 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
91469 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
91470 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
91471 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
91472 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
91473 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
91474 +vcs_read_8017 vcs_read 3 8017 NULL
91475 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
91476 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
91477 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
91478 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
91479 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
91480 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
91481 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
91482 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
91483 +copy_and_check_19089 copy_and_check 3 19089 NULL
91484 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
91485 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
91486 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
91487 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
91488 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
91489 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
91490 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
91491 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
91492 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
91493 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
91494 +smk_user_access_24440 smk_user_access 3 24440 NULL
91495 +xd_rw_49020 xd_rw 3-4 49020 NULL
91496 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
91497 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
91498 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
91499 +kvmalloc_32646 kvmalloc 1 32646 NULL
91500 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
91501 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
91502 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
91503 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
91504 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
91505 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
91506 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
91507 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
91508 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
91509 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
91510 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
91511 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
91512 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
91513 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
91514 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
91515 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
91516 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
91517 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
91518 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
91519 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
91520 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
91521 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
91522 +venus_lookup_8121 venus_lookup 4 8121 NULL
91523 +compat_writev_60063 compat_writev 3 60063 NULL
91524 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
91525 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
91526 +read_file_queue_40895 read_file_queue 3 40895 NULL
91527 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
91528 +waiters_read_40902 waiters_read 3 40902 NULL
91529 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
91530 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
91531 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
91532 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
91533 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
91534 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
91535 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
91536 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
91537 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
91538 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
91539 +alloc_dr_65495 alloc_dr 2 65495 NULL
91540 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
91541 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
91542 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
91543 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
91544 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
91545 +rbd_add_16366 rbd_add 3 16366 NULL
91546 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
91547 +pt_read_49136 pt_read 3 49136 NULL
91548 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
91549 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
91550 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
91551 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
91552 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
91553 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
91554 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
91555 new file mode 100644
91556 index 0000000..d52f2ee
91557 --- /dev/null
91558 +++ b/tools/gcc/size_overflow_plugin.c
91559 @@ -0,0 +1,1941 @@
91560 +/*
91561 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
91562 + * Licensed under the GPL v2, or (at your option) v3
91563 + *
91564 + * Homepage:
91565 + * http://www.grsecurity.net/~ephox/overflow_plugin/
91566 + *
91567 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
91568 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
91569 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
91570 + *
91571 + * Usage:
91572 + * $ gcc -I`gcc -print-file-name=plugin`/include/c-family -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -ggdb -Wall -W -Wno-missing-field-initializers -o size_overflow_plugin.so size_overflow_plugin.c
91573 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
91574 + */
91575 +
91576 +#include "gcc-plugin.h"
91577 +#include "config.h"
91578 +#include "system.h"
91579 +#include "coretypes.h"
91580 +#include "tree.h"
91581 +#include "tree-pass.h"
91582 +#include "intl.h"
91583 +#include "plugin-version.h"
91584 +#include "tm.h"
91585 +#include "toplev.h"
91586 +#include "function.h"
91587 +#include "tree-flow.h"
91588 +#include "plugin.h"
91589 +#include "gimple.h"
91590 +#include "c-common.h"
91591 +#include "diagnostic.h"
91592 +#include "cfgloop.h"
91593 +
91594 +#if BUILDING_GCC_VERSION >= 4007
91595 +#include "c-tree.h"
91596 +#else
91597 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
91598 +#endif
91599 +
91600 +#if BUILDING_GCC_VERSION >= 4008
91601 +#define TODO_dump_func 0
91602 +#endif
91603 +
91604 +struct size_overflow_hash {
91605 + const struct size_overflow_hash * const next;
91606 + const char * const name;
91607 + const unsigned int param;
91608 +};
91609 +
91610 +#include "size_overflow_hash.h"
91611 +
91612 +enum marked {
91613 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
91614 +};
91615 +
91616 +static unsigned int call_count = 0;
91617 +
91618 +#define __unused __attribute__((__unused__))
91619 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
91620 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
91621 +#define BEFORE_STMT true
91622 +#define AFTER_STMT false
91623 +#define CREATE_NEW_VAR NULL_TREE
91624 +#define CODES_LIMIT 32
91625 +#define MAX_PARAM 32
91626 +#define MY_STMT GF_PLF_1
91627 +#define NO_CAST_CHECK GF_PLF_2
91628 +
91629 +#if BUILDING_GCC_VERSION == 4005
91630 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
91631 +#endif
91632 +
91633 +int plugin_is_GPL_compatible;
91634 +void debug_gimple_stmt(gimple gs);
91635 +
91636 +static tree expand(struct pointer_set_t *visited, tree lhs);
91637 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
91638 +static tree report_size_overflow_decl;
91639 +static const_tree const_char_ptr_type_node;
91640 +static unsigned int handle_function(void);
91641 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
91642 +static tree get_size_overflow_type(gimple stmt, const_tree node);
91643 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
91644 +
91645 +static struct plugin_info size_overflow_plugin_info = {
91646 + .version = "20130109beta",
91647 + .help = "no-size-overflow\tturn off size overflow checking\n",
91648 +};
91649 +
91650 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
91651 +{
91652 + unsigned int arg_count;
91653 + enum tree_code code = TREE_CODE(*node);
91654 +
91655 + switch (code) {
91656 + case FUNCTION_DECL:
91657 + arg_count = type_num_arguments(TREE_TYPE(*node));
91658 + break;
91659 + case FUNCTION_TYPE:
91660 + case METHOD_TYPE:
91661 + arg_count = type_num_arguments(*node);
91662 + break;
91663 + default:
91664 + *no_add_attrs = true;
91665 + error("%s: %qE attribute only applies to functions", __func__, name);
91666 + return NULL_TREE;
91667 + }
91668 +
91669 + for (; args; args = TREE_CHAIN(args)) {
91670 + tree position = TREE_VALUE(args);
91671 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
91672 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
91673 + *no_add_attrs = true;
91674 + }
91675 + }
91676 + return NULL_TREE;
91677 +}
91678 +
91679 +static const char* get_asm_name(tree node)
91680 +{
91681 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
91682 +}
91683 +
91684 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
91685 +{
91686 + unsigned int arg_count, arg_num;
91687 + enum tree_code code = TREE_CODE(*node);
91688 +
91689 + switch (code) {
91690 + case FUNCTION_DECL:
91691 + arg_count = type_num_arguments(TREE_TYPE(*node));
91692 + break;
91693 + case FUNCTION_TYPE:
91694 + case METHOD_TYPE:
91695 + arg_count = type_num_arguments(*node);
91696 + break;
91697 + case FIELD_DECL:
91698 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
91699 + if (arg_num != 0) {
91700 + *no_add_attrs = true;
91701 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
91702 + }
91703 + return NULL_TREE;
91704 + default:
91705 + *no_add_attrs = true;
91706 + error("%qE attribute only applies to functions", name);
91707 + return NULL_TREE;
91708 + }
91709 +
91710 + for (; args; args = TREE_CHAIN(args)) {
91711 + tree position = TREE_VALUE(args);
91712 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
91713 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
91714 + *no_add_attrs = true;
91715 + }
91716 + }
91717 + return NULL_TREE;
91718 +}
91719 +
91720 +static struct attribute_spec size_overflow_attr = {
91721 + .name = "size_overflow",
91722 + .min_length = 1,
91723 + .max_length = -1,
91724 + .decl_required = true,
91725 + .type_required = false,
91726 + .function_type_required = false,
91727 + .handler = handle_size_overflow_attribute,
91728 +#if BUILDING_GCC_VERSION >= 4007
91729 + .affects_type_identity = false
91730 +#endif
91731 +};
91732 +
91733 +static struct attribute_spec intentional_overflow_attr = {
91734 + .name = "intentional_overflow",
91735 + .min_length = 1,
91736 + .max_length = -1,
91737 + .decl_required = true,
91738 + .type_required = false,
91739 + .function_type_required = false,
91740 + .handler = handle_intentional_overflow_attribute,
91741 +#if BUILDING_GCC_VERSION >= 4007
91742 + .affects_type_identity = false
91743 +#endif
91744 +};
91745 +
91746 +static void register_attributes(void __unused *event_data, void __unused *data)
91747 +{
91748 + register_attribute(&size_overflow_attr);
91749 + register_attribute(&intentional_overflow_attr);
91750 +}
91751 +
91752 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
91753 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
91754 +{
91755 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
91756 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
91757 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
91758 +
91759 + unsigned int m = 0x57559429;
91760 + unsigned int n = 0x5052acdb;
91761 + const unsigned int *key4 = (const unsigned int *)key;
91762 + unsigned int h = len;
91763 + unsigned int k = len + seed + n;
91764 + unsigned long long p;
91765 +
91766 + while (len >= 8) {
91767 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
91768 + len -= 8;
91769 + }
91770 + if (len >= 4) {
91771 + cwmixb(key4[0]) key4 += 1;
91772 + len -= 4;
91773 + }
91774 + if (len)
91775 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
91776 + cwmixb(h ^ (k + n));
91777 + return k ^ h;
91778 +
91779 +#undef cwfold
91780 +#undef cwmixa
91781 +#undef cwmixb
91782 +}
91783 +
91784 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
91785 +{
91786 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
91787 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
91788 + return fn ^ codes;
91789 +}
91790 +
91791 +static inline tree get_original_function_decl(tree fndecl)
91792 +{
91793 + if (DECL_ABSTRACT_ORIGIN(fndecl))
91794 + return DECL_ABSTRACT_ORIGIN(fndecl);
91795 + return fndecl;
91796 +}
91797 +
91798 +static inline gimple get_def_stmt(const_tree node)
91799 +{
91800 + gcc_assert(node != NULL_TREE);
91801 + gcc_assert(TREE_CODE(node) == SSA_NAME);
91802 + return SSA_NAME_DEF_STMT(node);
91803 +}
91804 +
91805 +static unsigned char get_tree_code(const_tree type)
91806 +{
91807 + switch (TREE_CODE(type)) {
91808 + case ARRAY_TYPE:
91809 + return 0;
91810 + case BOOLEAN_TYPE:
91811 + return 1;
91812 + case ENUMERAL_TYPE:
91813 + return 2;
91814 + case FUNCTION_TYPE:
91815 + return 3;
91816 + case INTEGER_TYPE:
91817 + return 4;
91818 + case POINTER_TYPE:
91819 + return 5;
91820 + case RECORD_TYPE:
91821 + return 6;
91822 + case UNION_TYPE:
91823 + return 7;
91824 + case VOID_TYPE:
91825 + return 8;
91826 + case REAL_TYPE:
91827 + return 9;
91828 + case VECTOR_TYPE:
91829 + return 10;
91830 + case REFERENCE_TYPE:
91831 + return 11;
91832 + case OFFSET_TYPE:
91833 + return 12;
91834 + case COMPLEX_TYPE:
91835 + return 13;
91836 + default:
91837 + debug_tree((tree)type);
91838 + gcc_unreachable();
91839 + }
91840 +}
91841 +
91842 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
91843 +{
91844 + gcc_assert(type != NULL_TREE);
91845 +
91846 + while (type && len < CODES_LIMIT) {
91847 + tree_codes[len] = get_tree_code(type);
91848 + len++;
91849 + type = TREE_TYPE(type);
91850 + }
91851 + return len;
91852 +}
91853 +
91854 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
91855 +{
91856 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
91857 + enum tree_code code = TREE_CODE(type);
91858 + size_t len = 0;
91859 +
91860 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
91861 +
91862 + arg = TYPE_ARG_TYPES(type);
91863 + // skip builtins __builtin_constant_p
91864 + if (!arg && DECL_BUILT_IN(fndecl))
91865 + return 0;
91866 +
91867 + if (TREE_CODE_CLASS(code) == tcc_type)
91868 + result = type;
91869 + else
91870 + result = DECL_RESULT(fndecl);
91871 +
91872 + gcc_assert(result != NULL_TREE);
91873 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
91874 +
91875 + if (arg == NULL_TREE) {
91876 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
91877 + arg_field = DECL_ARGUMENT_FLD(fndecl);
91878 + if (arg_field == NULL_TREE)
91879 + return 0;
91880 + arg = TREE_TYPE(arg_field);
91881 + len = add_type_codes(arg, tree_codes, len);
91882 + gcc_assert(len != 0);
91883 + return len;
91884 + }
91885 +
91886 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
91887 + while (arg && len < CODES_LIMIT) {
91888 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
91889 + arg = TREE_CHAIN(arg);
91890 + }
91891 +
91892 + gcc_assert(len != 0);
91893 + return len;
91894 +}
91895 +
91896 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
91897 +{
91898 + unsigned int hash;
91899 + const struct size_overflow_hash *entry;
91900 + unsigned char tree_codes[CODES_LIMIT];
91901 + size_t len;
91902 + const char *func_name = get_asm_name(fndecl);
91903 +
91904 + len = get_function_decl(fndecl, tree_codes);
91905 + if (len == 0)
91906 + return NULL;
91907 +
91908 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
91909 +
91910 + entry = size_overflow_hash[hash];
91911 + while (entry) {
91912 + if (!strcmp(entry->name, func_name))
91913 + return entry;
91914 + entry = entry->next;
91915 + }
91916 +
91917 + return NULL;
91918 +}
91919 +
91920 +static void check_arg_type(const_tree arg)
91921 +{
91922 + const_tree type = TREE_TYPE(arg);
91923 + enum tree_code code = TREE_CODE(type);
91924 +
91925 + if (code == BOOLEAN_TYPE)
91926 + return;
91927 +
91928 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
91929 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
91930 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
91931 +}
91932 +
91933 +static unsigned int find_arg_number(const_tree arg, tree func)
91934 +{
91935 + tree var;
91936 + unsigned int argnum = 1;
91937 +
91938 + if (TREE_CODE(arg) == SSA_NAME)
91939 + arg = SSA_NAME_VAR(arg);
91940 +
91941 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
91942 + if (strcmp(NAME(arg), NAME(var))) {
91943 + argnum++;
91944 + continue;
91945 + }
91946 + check_arg_type(var);
91947 + return argnum;
91948 + }
91949 + gcc_unreachable();
91950 +}
91951 +
91952 +static tree create_new_var(tree type)
91953 +{
91954 + tree new_var = create_tmp_var(type, "cicus");
91955 +
91956 +#if BUILDING_GCC_VERSION <= 4007
91957 + add_referenced_var(new_var);
91958 + mark_sym_for_renaming(new_var);
91959 +#endif
91960 + return new_var;
91961 +}
91962 +
91963 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
91964 +{
91965 + gimple assign;
91966 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
91967 + tree type = TREE_TYPE(rhs1);
91968 + tree lhs = create_new_var(type);
91969 +
91970 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
91971 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
91972 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
91973 +
91974 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
91975 + update_stmt(assign);
91976 + gimple_set_plf(assign, MY_STMT, true);
91977 + return assign;
91978 +}
91979 +
91980 +static bool is_bool(const_tree node)
91981 +{
91982 + const_tree type;
91983 +
91984 + if (node == NULL_TREE)
91985 + return false;
91986 +
91987 + type = TREE_TYPE(node);
91988 + if (!INTEGRAL_TYPE_P(type))
91989 + return false;
91990 + if (TREE_CODE(type) == BOOLEAN_TYPE)
91991 + return true;
91992 + if (TYPE_PRECISION(type) == 1)
91993 + return true;
91994 + return false;
91995 +}
91996 +
91997 +static tree cast_a_tree(tree type, tree var)
91998 +{
91999 + gcc_assert(type != NULL_TREE);
92000 + gcc_assert(var != NULL_TREE);
92001 + gcc_assert(fold_convertible_p(type, var));
92002 +
92003 + return fold_convert(type, var);
92004 +}
92005 +
92006 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
92007 +{
92008 + gimple assign;
92009 +
92010 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
92011 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
92012 + gcc_unreachable();
92013 +
92014 + if (lhs == CREATE_NEW_VAR)
92015 + lhs = create_new_var(dst_type);
92016 +
92017 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
92018 +
92019 + if (!gsi_end_p(*gsi)) {
92020 + location_t loc = gimple_location(gsi_stmt(*gsi));
92021 + gimple_set_location(assign, loc);
92022 + }
92023 +
92024 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
92025 +
92026 + if (before)
92027 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
92028 + else
92029 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
92030 + update_stmt(assign);
92031 + gimple_set_plf(assign, MY_STMT, true);
92032 +
92033 + return assign;
92034 +}
92035 +
92036 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
92037 +{
92038 + gimple assign;
92039 + gimple_stmt_iterator gsi;
92040 +
92041 + if (rhs == NULL_TREE)
92042 + return NULL_TREE;
92043 +
92044 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
92045 + return rhs;
92046 +
92047 + gsi = gsi_for_stmt(stmt);
92048 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
92049 + gimple_set_plf(assign, MY_STMT, true);
92050 + return gimple_get_lhs(assign);
92051 +}
92052 +
92053 +static tree cast_to_TI_type(gimple stmt, tree node)
92054 +{
92055 + gimple_stmt_iterator gsi;
92056 + gimple cast_stmt;
92057 + tree type = TREE_TYPE(node);
92058 +
92059 + if (types_compatible_p(type, intTI_type_node))
92060 + return node;
92061 +
92062 + gsi = gsi_for_stmt(stmt);
92063 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
92064 + gimple_set_plf(cast_stmt, MY_STMT, true);
92065 + return gimple_get_lhs(cast_stmt);
92066 +}
92067 +
92068 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
92069 +{
92070 + tree lhs;
92071 + gimple_stmt_iterator gsi;
92072 +
92073 + if (rhs1 == NULL_TREE) {
92074 + debug_gimple_stmt(oldstmt);
92075 + error("%s: rhs1 is NULL_TREE", __func__);
92076 + gcc_unreachable();
92077 + }
92078 +
92079 + switch (gimple_code(oldstmt)) {
92080 + case GIMPLE_ASM:
92081 + lhs = rhs1;
92082 + break;
92083 + case GIMPLE_CALL:
92084 + lhs = gimple_call_lhs(oldstmt);
92085 + break;
92086 + case GIMPLE_ASSIGN:
92087 + lhs = gimple_get_lhs(oldstmt);
92088 + break;
92089 + default:
92090 + debug_gimple_stmt(oldstmt);
92091 + gcc_unreachable();
92092 + }
92093 +
92094 + gsi = gsi_for_stmt(oldstmt);
92095 + pointer_set_insert(visited, oldstmt);
92096 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
92097 + basic_block next_bb, cur_bb;
92098 + const_edge e;
92099 +
92100 + gcc_assert(before == false);
92101 + gcc_assert(stmt_can_throw_internal(oldstmt));
92102 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
92103 + gcc_assert(!gsi_end_p(gsi));
92104 +
92105 + cur_bb = gimple_bb(oldstmt);
92106 + next_bb = cur_bb->next_bb;
92107 + e = find_edge(cur_bb, next_bb);
92108 + gcc_assert(e != NULL);
92109 + gcc_assert(e->flags & EDGE_FALLTHRU);
92110 +
92111 + gsi = gsi_after_labels(next_bb);
92112 + gcc_assert(!gsi_end_p(gsi));
92113 +
92114 + before = true;
92115 + oldstmt = gsi_stmt(gsi);
92116 + }
92117 +
92118 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
92119 +}
92120 +
92121 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
92122 +{
92123 + gimple stmt;
92124 + gimple_stmt_iterator gsi;
92125 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
92126 +
92127 + if (gimple_plf(oldstmt, MY_STMT))
92128 + return lhs;
92129 +
92130 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
92131 + rhs1 = gimple_assign_rhs1(oldstmt);
92132 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
92133 + }
92134 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
92135 + rhs2 = gimple_assign_rhs2(oldstmt);
92136 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
92137 + }
92138 +
92139 + stmt = gimple_copy(oldstmt);
92140 + gimple_set_location(stmt, gimple_location(oldstmt));
92141 + gimple_set_plf(stmt, MY_STMT, true);
92142 +
92143 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
92144 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
92145 +
92146 + size_overflow_type = get_size_overflow_type(oldstmt, node);
92147 +
92148 + if (is_bool(lhs))
92149 + new_var = SSA_NAME_VAR(lhs);
92150 + else
92151 + new_var = create_new_var(size_overflow_type);
92152 + new_var = make_ssa_name(new_var, stmt);
92153 + gimple_set_lhs(stmt, new_var);
92154 +
92155 + if (rhs1 != NULL_TREE)
92156 + gimple_assign_set_rhs1(stmt, rhs1);
92157 +
92158 + if (rhs2 != NULL_TREE)
92159 + gimple_assign_set_rhs2(stmt, rhs2);
92160 +#if BUILDING_GCC_VERSION >= 4007
92161 + if (rhs3 != NULL_TREE)
92162 + gimple_assign_set_rhs3(stmt, rhs3);
92163 +#endif
92164 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
92165 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
92166 +
92167 + gsi = gsi_for_stmt(oldstmt);
92168 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
92169 + update_stmt(stmt);
92170 + pointer_set_insert(visited, oldstmt);
92171 + return gimple_get_lhs(stmt);
92172 +}
92173 +
92174 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
92175 +{
92176 + basic_block bb;
92177 + gimple phi;
92178 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
92179 + gimple_seq seq;
92180 +
92181 + bb = gsi_bb(gsi);
92182 +
92183 + phi = create_phi_node(result, bb);
92184 + seq = phi_nodes(bb);
92185 + gsi = gsi_last(seq);
92186 + gsi_remove(&gsi, false);
92187 +
92188 + gsi = gsi_for_stmt(oldstmt);
92189 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
92190 + gimple_set_bb(phi, bb);
92191 + gimple_set_plf(phi, MY_STMT, true);
92192 + return phi;
92193 +}
92194 +
92195 +static basic_block create_a_first_bb(void)
92196 +{
92197 + basic_block first_bb;
92198 +
92199 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
92200 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
92201 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
92202 + return first_bb;
92203 +}
92204 +
92205 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
92206 +{
92207 + basic_block bb;
92208 + const_gimple newstmt;
92209 + gimple_stmt_iterator gsi;
92210 + bool before = BEFORE_STMT;
92211 +
92212 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
92213 + gsi = gsi_for_stmt(get_def_stmt(arg));
92214 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
92215 + return gimple_get_lhs(newstmt);
92216 + }
92217 +
92218 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
92219 + gsi = gsi_after_labels(bb);
92220 + if (bb->index == 0) {
92221 + bb = create_a_first_bb();
92222 + gsi = gsi_start_bb(bb);
92223 + }
92224 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
92225 + return gimple_get_lhs(newstmt);
92226 +}
92227 +
92228 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
92229 +{
92230 + gimple newstmt;
92231 + gimple_stmt_iterator gsi;
92232 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
92233 + gimple def_newstmt = get_def_stmt(new_rhs);
92234 +
92235 + gsi_insert = gsi_insert_after;
92236 + gsi = gsi_for_stmt(def_newstmt);
92237 +
92238 + switch (gimple_code(get_def_stmt(arg))) {
92239 + case GIMPLE_PHI:
92240 + newstmt = gimple_build_assign(new_var, new_rhs);
92241 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
92242 + gsi_insert = gsi_insert_before;
92243 + break;
92244 + case GIMPLE_ASM:
92245 + case GIMPLE_CALL:
92246 + newstmt = gimple_build_assign(new_var, new_rhs);
92247 + break;
92248 + case GIMPLE_ASSIGN:
92249 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
92250 + break;
92251 + default:
92252 + /* unknown gimple_code (handle_build_new_phi_arg) */
92253 + gcc_unreachable();
92254 + }
92255 +
92256 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
92257 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
92258 + gimple_set_plf(newstmt, MY_STMT, true);
92259 + update_stmt(newstmt);
92260 + return newstmt;
92261 +}
92262 +
92263 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
92264 +{
92265 + const_gimple newstmt;
92266 + gimple def_stmt;
92267 + tree new_rhs;
92268 +
92269 + new_rhs = expand(visited, arg);
92270 + if (new_rhs == NULL_TREE)
92271 + return NULL_TREE;
92272 +
92273 + def_stmt = get_def_stmt(new_rhs);
92274 + if (gimple_code(def_stmt) == GIMPLE_NOP)
92275 + return NULL_TREE;
92276 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
92277 +
92278 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
92279 + return gimple_get_lhs(newstmt);
92280 +}
92281 +
92282 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
92283 +{
92284 + gimple phi, oldstmt = get_def_stmt(orig_result);
92285 + tree new_result, size_overflow_type;
92286 + unsigned int i;
92287 + unsigned int n = gimple_phi_num_args(oldstmt);
92288 +
92289 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
92290 +
92291 + new_result = create_new_var(size_overflow_type);
92292 +
92293 + pointer_set_insert(visited, oldstmt);
92294 + phi = overflow_create_phi_node(oldstmt, new_result);
92295 + for (i = 0; i < n; i++) {
92296 + tree arg, lhs;
92297 +
92298 + arg = gimple_phi_arg_def(oldstmt, i);
92299 + if (is_gimple_constant(arg))
92300 + arg = cast_a_tree(size_overflow_type, arg);
92301 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
92302 + if (lhs == NULL_TREE)
92303 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
92304 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
92305 + }
92306 +
92307 + update_stmt(phi);
92308 + return gimple_phi_result(phi);
92309 +}
92310 +
92311 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
92312 +{
92313 + const_gimple assign;
92314 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
92315 + tree origtype = TREE_TYPE(orig_rhs);
92316 +
92317 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
92318 +
92319 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
92320 + return gimple_get_lhs(assign);
92321 +}
92322 +
92323 +static void change_rhs1(gimple stmt, tree new_rhs1)
92324 +{
92325 + tree assign_rhs;
92326 + const_tree rhs = gimple_assign_rhs1(stmt);
92327 +
92328 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
92329 + gimple_assign_set_rhs1(stmt, assign_rhs);
92330 + update_stmt(stmt);
92331 +}
92332 +
92333 +static bool check_mode_type(const_gimple stmt)
92334 +{
92335 + const_tree lhs = gimple_get_lhs(stmt);
92336 + const_tree lhs_type = TREE_TYPE(lhs);
92337 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
92338 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
92339 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
92340 +
92341 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
92342 + return false;
92343 +
92344 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
92345 + return false;
92346 +
92347 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
92348 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
92349 + return false;
92350 +
92351 + return true;
92352 +}
92353 +
92354 +static bool check_undefined_integer_operation(const_gimple stmt)
92355 +{
92356 + const_gimple def_stmt;
92357 + const_tree lhs = gimple_get_lhs(stmt);
92358 + const_tree rhs1 = gimple_assign_rhs1(stmt);
92359 + const_tree rhs1_type = TREE_TYPE(rhs1);
92360 + const_tree lhs_type = TREE_TYPE(lhs);
92361 +
92362 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
92363 + return false;
92364 +
92365 + def_stmt = get_def_stmt(rhs1);
92366 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
92367 + return false;
92368 +
92369 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
92370 + return false;
92371 + return true;
92372 +}
92373 +
92374 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
92375 +{
92376 + const_tree rhs1, lhs, rhs1_type, lhs_type;
92377 + enum machine_mode lhs_mode, rhs_mode;
92378 + gimple def_stmt = get_def_stmt(no_const_rhs);
92379 +
92380 + if (!gimple_assign_cast_p(def_stmt))
92381 + return false;
92382 +
92383 + rhs1 = gimple_assign_rhs1(def_stmt);
92384 + lhs = gimple_get_lhs(def_stmt);
92385 + rhs1_type = TREE_TYPE(rhs1);
92386 + lhs_type = TREE_TYPE(lhs);
92387 + rhs_mode = TYPE_MODE(rhs1_type);
92388 + lhs_mode = TYPE_MODE(lhs_type);
92389 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
92390 + return false;
92391 +
92392 + return true;
92393 +}
92394 +
92395 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
92396 +{
92397 + tree rhs1 = gimple_assign_rhs1(stmt);
92398 + tree lhs = gimple_get_lhs(stmt);
92399 + const_tree rhs1_type = TREE_TYPE(rhs1);
92400 + const_tree lhs_type = TREE_TYPE(lhs);
92401 +
92402 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
92403 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92404 +
92405 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
92406 +}
92407 +
92408 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
92409 +{
92410 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
92411 + tree new_rhs1 = NULL_TREE;
92412 + tree rhs1 = gimple_assign_rhs1(stmt);
92413 + const_tree rhs1_type = TREE_TYPE(rhs1);
92414 + const_tree lhs_type = TREE_TYPE(lhs);
92415 +
92416 + if (gimple_plf(stmt, MY_STMT))
92417 + return lhs;
92418 +
92419 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
92420 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92421 +
92422 + new_rhs1 = expand(visited, rhs1);
92423 +
92424 + if (new_rhs1 == NULL_TREE)
92425 + return create_cast_assign(visited, stmt);
92426 +
92427 + if (gimple_plf(stmt, NO_CAST_CHECK))
92428 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92429 +
92430 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
92431 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
92432 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92433 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
92434 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92435 + }
92436 +
92437 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
92438 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92439 +
92440 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
92441 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
92442 +
92443 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
92444 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92445 +
92446 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
92447 +
92448 + change_rhs1(stmt, new_rhs1);
92449 +
92450 + if (!check_mode_type(stmt))
92451 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92452 +
92453 + size_overflow_type = get_size_overflow_type(stmt, lhs);
92454 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
92455 +
92456 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
92457 +
92458 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92459 +}
92460 +
92461 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
92462 +{
92463 + tree rhs1, lhs = gimple_get_lhs(stmt);
92464 + gimple def_stmt = get_def_stmt(lhs);
92465 +
92466 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
92467 + rhs1 = gimple_assign_rhs1(def_stmt);
92468 +
92469 + if (is_gimple_constant(rhs1))
92470 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92471 +
92472 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
92473 + switch (TREE_CODE(rhs1)) {
92474 + case SSA_NAME:
92475 + return handle_unary_rhs(visited, def_stmt);
92476 + case ARRAY_REF:
92477 + case BIT_FIELD_REF:
92478 + case ADDR_EXPR:
92479 + case COMPONENT_REF:
92480 + case INDIRECT_REF:
92481 +#if BUILDING_GCC_VERSION >= 4006
92482 + case MEM_REF:
92483 +#endif
92484 + case TARGET_MEM_REF:
92485 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92486 + case PARM_DECL:
92487 + case VAR_DECL:
92488 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92489 +
92490 + default:
92491 + debug_gimple_stmt(def_stmt);
92492 + debug_tree(rhs1);
92493 + gcc_unreachable();
92494 + }
92495 +}
92496 +
92497 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
92498 +{
92499 + gimple cond_stmt;
92500 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
92501 +
92502 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
92503 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
92504 + update_stmt(cond_stmt);
92505 +}
92506 +
92507 +static tree create_string_param(tree string)
92508 +{
92509 + tree i_type, a_type;
92510 + const int length = TREE_STRING_LENGTH(string);
92511 +
92512 + gcc_assert(length > 0);
92513 +
92514 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
92515 + a_type = build_array_type(char_type_node, i_type);
92516 +
92517 + TREE_TYPE(string) = a_type;
92518 + TREE_CONSTANT(string) = 1;
92519 + TREE_READONLY(string) = 1;
92520 +
92521 + return build1(ADDR_EXPR, ptr_type_node, string);
92522 +}
92523 +
92524 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
92525 +{
92526 + gimple func_stmt;
92527 + const_gimple def_stmt;
92528 + const_tree loc_line;
92529 + tree loc_file, ssa_name, current_func;
92530 + expanded_location xloc;
92531 + char *ssa_name_buf;
92532 + int len;
92533 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
92534 +
92535 + def_stmt = get_def_stmt(arg);
92536 + xloc = expand_location(gimple_location(def_stmt));
92537 +
92538 + if (!gimple_has_location(def_stmt)) {
92539 + xloc = expand_location(gimple_location(stmt));
92540 + if (!gimple_has_location(stmt))
92541 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92542 + }
92543 +
92544 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
92545 +
92546 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
92547 + loc_file = create_string_param(loc_file);
92548 +
92549 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
92550 + current_func = create_string_param(current_func);
92551 +
92552 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
92553 + call_count++;
92554 + len = asprintf(&ssa_name_buf, "%s_%u %s, count: %u\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max", call_count);
92555 + gcc_assert(len > 0);
92556 + ssa_name = build_string(len + 1, ssa_name_buf);
92557 + free(ssa_name_buf);
92558 + ssa_name = create_string_param(ssa_name);
92559 +
92560 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
92561 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
92562 +
92563 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
92564 +}
92565 +
92566 +static void __unused print_the_code_insertions(const_gimple stmt)
92567 +{
92568 + location_t loc = gimple_location(stmt);
92569 +
92570 + inform(loc, "Integer size_overflow check applied here.");
92571 +}
92572 +
92573 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
92574 +{
92575 + basic_block cond_bb, join_bb, bb_true;
92576 + edge e;
92577 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
92578 +
92579 + cond_bb = gimple_bb(stmt);
92580 + if (before)
92581 + gsi_prev(&gsi);
92582 + if (gsi_end_p(gsi))
92583 + e = split_block_after_labels(cond_bb);
92584 + else
92585 + e = split_block(cond_bb, gsi_stmt(gsi));
92586 + cond_bb = e->src;
92587 + join_bb = e->dest;
92588 + e->flags = EDGE_FALSE_VALUE;
92589 + e->probability = REG_BR_PROB_BASE;
92590 +
92591 + bb_true = create_empty_bb(cond_bb);
92592 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
92593 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
92594 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
92595 +
92596 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
92597 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
92598 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
92599 +
92600 + if (current_loops != NULL) {
92601 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
92602 + add_bb_to_loop(bb_true, cond_bb->loop_father);
92603 + }
92604 +
92605 + insert_cond(cond_bb, arg, cond_code, type_value);
92606 + insert_cond_result(bb_true, stmt, arg, min);
92607 +
92608 +// print_the_code_insertions(stmt);
92609 +}
92610 +
92611 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
92612 +{
92613 + const_tree rhs_type = TREE_TYPE(rhs);
92614 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
92615 +
92616 + gcc_assert(rhs_type != NULL_TREE);
92617 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
92618 + return;
92619 +
92620 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
92621 +
92622 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
92623 + // typemax (-1) < typemin (0)
92624 + if (TREE_OVERFLOW(type_max))
92625 + return;
92626 +
92627 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
92628 +
92629 + cast_rhs_type = TREE_TYPE(cast_rhs);
92630 + type_max_type = TREE_TYPE(type_max);
92631 + type_min_type = TREE_TYPE(type_min);
92632 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
92633 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
92634 +
92635 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
92636 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
92637 +}
92638 +
92639 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
92640 +{
92641 + gimple change_rhs_def_stmt;
92642 + tree lhs = gimple_get_lhs(def_stmt);
92643 + tree lhs_type = TREE_TYPE(lhs);
92644 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
92645 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
92646 +
92647 + if (change_rhs == NULL_TREE)
92648 + return get_size_overflow_type(def_stmt, lhs);
92649 +
92650 + change_rhs_def_stmt = get_def_stmt(change_rhs);
92651 +
92652 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
92653 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92654 +
92655 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
92656 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92657 +
92658 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
92659 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
92660 +
92661 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
92662 + debug_gimple_stmt(def_stmt);
92663 + gcc_unreachable();
92664 + }
92665 +
92666 + return get_size_overflow_type(def_stmt, lhs);
92667 +}
92668 +
92669 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
92670 +{
92671 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
92672 + return false;
92673 + if (!is_gimple_constant(rhs))
92674 + return false;
92675 + return true;
92676 +}
92677 +
92678 +static bool is_subtraction_special(const_gimple stmt)
92679 +{
92680 + gimple rhs1_def_stmt, rhs2_def_stmt;
92681 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
92682 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
92683 + const_tree rhs1 = gimple_assign_rhs1(stmt);
92684 + const_tree rhs2 = gimple_assign_rhs2(stmt);
92685 +
92686 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
92687 + return false;
92688 +
92689 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
92690 +
92691 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
92692 + return false;
92693 +
92694 + rhs1_def_stmt = get_def_stmt(rhs1);
92695 + rhs2_def_stmt = get_def_stmt(rhs2);
92696 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
92697 + return false;
92698 +
92699 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
92700 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
92701 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
92702 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
92703 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
92704 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
92705 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
92706 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
92707 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
92708 + return false;
92709 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
92710 + return false;
92711 +
92712 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
92713 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
92714 + return true;
92715 +}
92716 +
92717 +static tree get_def_stmt_rhs(const_tree var)
92718 +{
92719 + tree rhs1, def_stmt_rhs1;
92720 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
92721 +
92722 + def_stmt = get_def_stmt(var);
92723 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
92724 +
92725 + rhs1 = gimple_assign_rhs1(def_stmt);
92726 + rhs1_def_stmt = get_def_stmt(rhs1);
92727 + if (!gimple_assign_cast_p(rhs1_def_stmt))
92728 + return rhs1;
92729 +
92730 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
92731 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
92732 +
92733 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
92734 + case GIMPLE_CALL:
92735 + case GIMPLE_NOP:
92736 + case GIMPLE_ASM:
92737 + return def_stmt_rhs1;
92738 + case GIMPLE_ASSIGN:
92739 + return rhs1;
92740 + default:
92741 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
92742 + gcc_unreachable();
92743 + }
92744 +}
92745 +
92746 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
92747 +{
92748 + tree new_rhs1, new_rhs2;
92749 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
92750 + gimple assign, stmt = get_def_stmt(lhs);
92751 + tree rhs1 = gimple_assign_rhs1(stmt);
92752 + tree rhs2 = gimple_assign_rhs2(stmt);
92753 +
92754 + if (!is_subtraction_special(stmt))
92755 + return NULL_TREE;
92756 +
92757 + new_rhs1 = expand(visited, rhs1);
92758 + new_rhs2 = expand(visited, rhs2);
92759 +
92760 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
92761 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
92762 +
92763 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
92764 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
92765 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
92766 + }
92767 +
92768 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
92769 + new_lhs = gimple_get_lhs(assign);
92770 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
92771 +
92772 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
92773 +}
92774 +
92775 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
92776 +{
92777 + const_gimple def_stmt;
92778 +
92779 + if (TREE_CODE(rhs) != SSA_NAME)
92780 + return false;
92781 +
92782 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
92783 + return false;
92784 +
92785 + def_stmt = get_def_stmt(rhs);
92786 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
92787 + return false;
92788 +
92789 + return true;
92790 +}
92791 +
92792 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
92793 +{
92794 + tree new_rhs, size_overflow_type, orig_rhs;
92795 + void (*gimple_assign_set_rhs)(gimple, tree);
92796 + tree rhs1 = gimple_assign_rhs1(stmt);
92797 + tree rhs2 = gimple_assign_rhs2(stmt);
92798 + tree lhs = gimple_get_lhs(stmt);
92799 +
92800 + if (change_rhs == NULL_TREE)
92801 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92802 +
92803 + if (new_rhs2 == NULL_TREE) {
92804 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
92805 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
92806 + orig_rhs = rhs1;
92807 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
92808 + } else {
92809 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
92810 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
92811 + orig_rhs = rhs2;
92812 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
92813 + }
92814 +
92815 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
92816 +
92817 + if (check_overflow)
92818 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
92819 +
92820 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
92821 + gimple_assign_set_rhs(stmt, new_rhs);
92822 + update_stmt(stmt);
92823 +
92824 + return create_assign(visited, stmt, lhs, AFTER_STMT);
92825 +}
92826 +
92827 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
92828 +{
92829 + tree rhs1, rhs2, new_lhs;
92830 + gimple def_stmt = get_def_stmt(lhs);
92831 + tree new_rhs1 = NULL_TREE;
92832 + tree new_rhs2 = NULL_TREE;
92833 +
92834 + rhs1 = gimple_assign_rhs1(def_stmt);
92835 + rhs2 = gimple_assign_rhs2(def_stmt);
92836 +
92837 + /* no DImode/TImode division in the 32/64 bit kernel */
92838 + switch (gimple_assign_rhs_code(def_stmt)) {
92839 + case RDIV_EXPR:
92840 + case TRUNC_DIV_EXPR:
92841 + case CEIL_DIV_EXPR:
92842 + case FLOOR_DIV_EXPR:
92843 + case ROUND_DIV_EXPR:
92844 + case TRUNC_MOD_EXPR:
92845 + case CEIL_MOD_EXPR:
92846 + case FLOOR_MOD_EXPR:
92847 + case ROUND_MOD_EXPR:
92848 + case EXACT_DIV_EXPR:
92849 + case POINTER_PLUS_EXPR:
92850 + case BIT_AND_EXPR:
92851 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
92852 + default:
92853 + break;
92854 + }
92855 +
92856 + new_lhs = handle_integer_truncation(visited, lhs);
92857 + if (new_lhs != NULL_TREE)
92858 + return new_lhs;
92859 +
92860 + if (TREE_CODE(rhs1) == SSA_NAME)
92861 + new_rhs1 = expand(visited, rhs1);
92862 + if (TREE_CODE(rhs2) == SSA_NAME)
92863 + new_rhs2 = expand(visited, rhs2);
92864 +
92865 + if (is_a_neg_overflow(def_stmt, rhs2))
92866 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
92867 + if (is_a_neg_overflow(def_stmt, rhs1))
92868 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
92869 +
92870 + if (is_a_constant_overflow(def_stmt, rhs2))
92871 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
92872 + if (is_a_constant_overflow(def_stmt, rhs1))
92873 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
92874 +
92875 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
92876 +}
92877 +
92878 +#if BUILDING_GCC_VERSION >= 4007
92879 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
92880 +{
92881 + if (is_gimple_constant(rhs))
92882 + return cast_a_tree(size_overflow_type, rhs);
92883 + if (TREE_CODE(rhs) != SSA_NAME)
92884 + return NULL_TREE;
92885 + return expand(visited, rhs);
92886 +}
92887 +
92888 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
92889 +{
92890 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
92891 + gimple def_stmt = get_def_stmt(lhs);
92892 +
92893 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
92894 +
92895 + rhs1 = gimple_assign_rhs1(def_stmt);
92896 + rhs2 = gimple_assign_rhs2(def_stmt);
92897 + rhs3 = gimple_assign_rhs3(def_stmt);
92898 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
92899 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
92900 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
92901 +
92902 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
92903 +}
92904 +#endif
92905 +
92906 +static tree get_size_overflow_type(gimple stmt, const_tree node)
92907 +{
92908 + const_tree type;
92909 + tree new_type;
92910 +
92911 + gcc_assert(node != NULL_TREE);
92912 +
92913 + type = TREE_TYPE(node);
92914 +
92915 + if (gimple_plf(stmt, MY_STMT))
92916 + return TREE_TYPE(node);
92917 +
92918 + switch (TYPE_MODE(type)) {
92919 + case QImode:
92920 + new_type = intHI_type_node;
92921 + break;
92922 + case HImode:
92923 + new_type = intSI_type_node;
92924 + break;
92925 + case SImode:
92926 + new_type = intDI_type_node;
92927 + break;
92928 + case DImode:
92929 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
92930 + new_type = intDI_type_node;
92931 + else
92932 + new_type = intTI_type_node;
92933 + break;
92934 + default:
92935 + debug_tree((tree)node);
92936 + error("%s: unsupported gcc configuration.", __func__);
92937 + gcc_unreachable();
92938 + }
92939 +
92940 + if (TYPE_QUALS(type) != 0)
92941 + return build_qualified_type(new_type, TYPE_QUALS(type));
92942 + return new_type;
92943 +}
92944 +
92945 +static tree expand_visited(gimple def_stmt)
92946 +{
92947 + const_gimple next_stmt;
92948 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
92949 +
92950 + gsi_next(&gsi);
92951 + next_stmt = gsi_stmt(gsi);
92952 +
92953 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
92954 +
92955 + switch (gimple_code(next_stmt)) {
92956 + case GIMPLE_ASSIGN:
92957 + return gimple_get_lhs(next_stmt);
92958 + case GIMPLE_PHI:
92959 + return gimple_phi_result(next_stmt);
92960 + case GIMPLE_CALL:
92961 + return gimple_call_lhs(next_stmt);
92962 + default:
92963 + return NULL_TREE;
92964 + }
92965 +}
92966 +
92967 +static tree expand(struct pointer_set_t *visited, tree lhs)
92968 +{
92969 + gimple def_stmt;
92970 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
92971 +
92972 + if (is_gimple_constant(lhs))
92973 + return NULL_TREE;
92974 +
92975 + if (TREE_CODE(lhs) == ADDR_EXPR)
92976 + return NULL_TREE;
92977 +
92978 + if (code == REAL_TYPE)
92979 + return NULL_TREE;
92980 +
92981 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
92982 +
92983 + def_stmt = get_def_stmt(lhs);
92984 +
92985 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
92986 + return NULL_TREE;
92987 +
92988 + if (gimple_plf(def_stmt, MY_STMT))
92989 + return lhs;
92990 +
92991 + if (pointer_set_contains(visited, def_stmt))
92992 + return expand_visited(def_stmt);
92993 +
92994 + switch (gimple_code(def_stmt)) {
92995 + case GIMPLE_PHI:
92996 + return build_new_phi(visited, lhs);
92997 + case GIMPLE_CALL:
92998 + case GIMPLE_ASM:
92999 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
93000 + case GIMPLE_ASSIGN:
93001 + switch (gimple_num_ops(def_stmt)) {
93002 + case 2:
93003 + return handle_unary_ops(visited, def_stmt);
93004 + case 3:
93005 + return handle_binary_ops(visited, lhs);
93006 +#if BUILDING_GCC_VERSION >= 4007
93007 + case 4:
93008 + return handle_ternary_ops(visited, lhs);
93009 +#endif
93010 + }
93011 + default:
93012 + debug_gimple_stmt(def_stmt);
93013 + error("%s: unknown gimple code", __func__);
93014 + gcc_unreachable();
93015 + }
93016 +}
93017 +
93018 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
93019 +{
93020 + const_gimple assign;
93021 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
93022 + tree origtype = TREE_TYPE(origarg);
93023 +
93024 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
93025 +
93026 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
93027 +
93028 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
93029 + update_stmt(stmt);
93030 +}
93031 +
93032 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
93033 +{
93034 + const char *origid;
93035 + tree arg;
93036 + const_tree origarg;
93037 +
93038 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
93039 + return true;
93040 +
93041 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
93042 + while (origarg && *argnum) {
93043 + (*argnum)--;
93044 + origarg = TREE_CHAIN(origarg);
93045 + }
93046 +
93047 + gcc_assert(*argnum == 0);
93048 +
93049 + gcc_assert(origarg != NULL_TREE);
93050 + origid = NAME(origarg);
93051 + *argnum = 0;
93052 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
93053 + if (!strcmp(origid, NAME(arg)))
93054 + return true;
93055 + (*argnum)++;
93056 + }
93057 + return false;
93058 +}
93059 +
93060 +static bool skip_types(const_tree var)
93061 +{
93062 + const_tree type;
93063 +
93064 + switch (TREE_CODE(var)) {
93065 + case ADDR_EXPR:
93066 +#if BUILDING_GCC_VERSION >= 4006
93067 + case MEM_REF:
93068 +#endif
93069 + case ARRAY_REF:
93070 + case BIT_FIELD_REF:
93071 + case INDIRECT_REF:
93072 + case TARGET_MEM_REF:
93073 + case VAR_DECL:
93074 + return true;
93075 + default:
93076 + break;
93077 + }
93078 +
93079 + type = TREE_TYPE(TREE_TYPE(var));
93080 + if (!type)
93081 + return false;
93082 + switch (TREE_CODE(type)) {
93083 + case RECORD_TYPE:
93084 + return true;
93085 + default:
93086 + break;
93087 + }
93088 +
93089 + return false;
93090 +}
93091 +
93092 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
93093 +{
93094 + gimple phi = get_def_stmt(result);
93095 + unsigned int i, n = gimple_phi_num_args(phi);
93096 +
93097 + if (!phi)
93098 + return false;
93099 +
93100 + pointer_set_insert(visited, phi);
93101 + for (i = 0; i < n; i++) {
93102 + const_tree arg = gimple_phi_arg_def(phi, i);
93103 + if (pre_expand(visited, arg))
93104 + return true;
93105 + }
93106 + return false;
93107 +}
93108 +
93109 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
93110 +{
93111 + gimple def_stmt = get_def_stmt(lhs);
93112 + const_tree rhs;
93113 +
93114 + if (!def_stmt)
93115 + return false;
93116 +
93117 + rhs = gimple_assign_rhs1(def_stmt);
93118 + if (pre_expand(visited, rhs))
93119 + return true;
93120 + return false;
93121 +}
93122 +
93123 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
93124 +{
93125 + bool rhs1_found, rhs2_found;
93126 + gimple def_stmt = get_def_stmt(lhs);
93127 + const_tree rhs1, rhs2;
93128 +
93129 + if (!def_stmt)
93130 + return false;
93131 +
93132 + rhs1 = gimple_assign_rhs1(def_stmt);
93133 + rhs2 = gimple_assign_rhs2(def_stmt);
93134 + rhs1_found = pre_expand(visited, rhs1);
93135 + rhs2_found = pre_expand(visited, rhs2);
93136 +
93137 + return rhs1_found || rhs2_found;
93138 +}
93139 +
93140 +static const_tree search_field_decl(const_tree comp_ref)
93141 +{
93142 + const_tree field = NULL_TREE;
93143 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
93144 +
93145 + for (i = 0; i < len; i++) {
93146 + field = TREE_OPERAND(comp_ref, i);
93147 + if (TREE_CODE(field) == FIELD_DECL)
93148 + break;
93149 + }
93150 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
93151 + return field;
93152 +}
93153 +
93154 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
93155 +{
93156 + const_tree attr, p;
93157 +
93158 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
93159 + if (!attr || !TREE_VALUE(attr))
93160 + return MARKED_NO;
93161 +
93162 + p = TREE_VALUE(attr);
93163 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
93164 + return MARKED_NOT_INTENTIONAL;
93165 +
93166 + do {
93167 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
93168 + return MARKED_YES;
93169 + p = TREE_CHAIN(p);
93170 + } while (p);
93171 +
93172 + return MARKED_NO;
93173 +}
93174 +
93175 +static void print_missing_msg(tree func, unsigned int argnum)
93176 +{
93177 + unsigned int new_hash;
93178 + size_t len;
93179 + unsigned char tree_codes[CODES_LIMIT];
93180 + location_t loc = DECL_SOURCE_LOCATION(func);
93181 + const char *curfunc = get_asm_name(func);
93182 +
93183 + len = get_function_decl(func, tree_codes);
93184 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
93185 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
93186 +}
93187 +
93188 +static unsigned int search_missing_attribute(const_tree arg)
93189 +{
93190 + const_tree type = TREE_TYPE(arg);
93191 + tree func = get_original_function_decl(current_function_decl);
93192 + unsigned int argnum;
93193 + const struct size_overflow_hash *hash;
93194 +
93195 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
93196 +
93197 + if (TREE_CODE(type) == POINTER_TYPE)
93198 + return 0;
93199 +
93200 + argnum = find_arg_number(arg, func);
93201 + if (argnum == 0)
93202 + return 0;
93203 +
93204 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
93205 + return argnum;
93206 +
93207 + hash = get_function_hash(func);
93208 + if (!hash || !(hash->param & (1U << argnum))) {
93209 + print_missing_msg(func, argnum);
93210 + return 0;
93211 + }
93212 + return argnum;
93213 +}
93214 +
93215 +static bool is_already_marked(const_tree lhs)
93216 +{
93217 + unsigned int argnum;
93218 + const_tree fndecl;
93219 +
93220 + argnum = search_missing_attribute(lhs);
93221 + fndecl = get_original_function_decl(current_function_decl);
93222 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
93223 + return true;
93224 + return false;
93225 +}
93226 +
93227 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
93228 +{
93229 + const_gimple def_stmt;
93230 +
93231 + if (is_gimple_constant(lhs))
93232 + return false;
93233 +
93234 + if (skip_types(lhs))
93235 + return false;
93236 +
93237 + // skip char type (FIXME: only kernel)
93238 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
93239 + return false;
93240 +
93241 + if (TREE_CODE(lhs) == PARM_DECL)
93242 + return is_already_marked(lhs);
93243 +
93244 + if (TREE_CODE(lhs) == COMPONENT_REF) {
93245 + const_tree field, attr;
93246 +
93247 + field = search_field_decl(lhs);
93248 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
93249 + if (!attr || !TREE_VALUE(attr))
93250 + return false;
93251 + return true;
93252 + }
93253 +
93254 + def_stmt = get_def_stmt(lhs);
93255 +
93256 + if (!def_stmt)
93257 + return false;
93258 +
93259 + if (pointer_set_contains(visited, def_stmt))
93260 + return false;
93261 +
93262 + switch (gimple_code(def_stmt)) {
93263 + case GIMPLE_NOP:
93264 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
93265 + return is_already_marked(lhs);
93266 + return false;
93267 + case GIMPLE_PHI:
93268 + return walk_phi(visited, lhs);
93269 + case GIMPLE_CALL:
93270 + case GIMPLE_ASM:
93271 + return false;
93272 + case GIMPLE_ASSIGN:
93273 + switch (gimple_num_ops(def_stmt)) {
93274 + case 2:
93275 + return walk_unary_ops(visited, lhs);
93276 + case 3:
93277 + return walk_binary_ops(visited, lhs);
93278 + }
93279 + default:
93280 + debug_gimple_stmt((gimple)def_stmt);
93281 + error("%s: unknown gimple code", __func__);
93282 + gcc_unreachable();
93283 + }
93284 +}
93285 +
93286 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
93287 +{
93288 + struct pointer_set_t *visited;
93289 + bool is_found;
93290 + enum marked is_marked;
93291 + location_t loc;
93292 +
93293 + visited = pointer_set_create();
93294 + is_found = pre_expand(visited, arg);
93295 + pointer_set_destroy(visited);
93296 +
93297 + is_marked = mark_status(fndecl, argnum + 1);
93298 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
93299 + return true;
93300 +
93301 + if (is_found) {
93302 + loc = DECL_SOURCE_LOCATION(fndecl);
93303 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
93304 + return true;
93305 + }
93306 + return false;
93307 +}
93308 +
93309 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
93310 +{
93311 + struct pointer_set_t *visited;
93312 + tree arg, newarg;
93313 + bool match;
93314 +
93315 + match = get_function_arg(&argnum, fndecl);
93316 + if (!match)
93317 + return;
93318 + gcc_assert(gimple_call_num_args(stmt) > argnum);
93319 + arg = gimple_call_arg(stmt, argnum);
93320 + if (arg == NULL_TREE)
93321 + return;
93322 +
93323 + if (is_gimple_constant(arg))
93324 + return;
93325 +
93326 + if (search_attributes(fndecl, arg, argnum))
93327 + return;
93328 +
93329 + if (TREE_CODE(arg) != SSA_NAME)
93330 + return;
93331 +
93332 + check_arg_type(arg);
93333 +
93334 + visited = pointer_set_create();
93335 + newarg = expand(visited, arg);
93336 + pointer_set_destroy(visited);
93337 +
93338 + if (newarg == NULL_TREE)
93339 + return;
93340 +
93341 + change_function_arg(stmt, arg, argnum, newarg);
93342 +
93343 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
93344 +}
93345 +
93346 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
93347 +{
93348 + tree p = TREE_VALUE(attr);
93349 + do {
93350 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
93351 + p = TREE_CHAIN(p);
93352 + } while (p);
93353 +}
93354 +
93355 +static void handle_function_by_hash(gimple stmt, tree fndecl)
93356 +{
93357 + tree orig_fndecl;
93358 + unsigned int num;
93359 + const struct size_overflow_hash *hash;
93360 +
93361 + orig_fndecl = get_original_function_decl(fndecl);
93362 + if (C_DECL_IMPLICIT(orig_fndecl))
93363 + return;
93364 + hash = get_function_hash(orig_fndecl);
93365 + if (!hash)
93366 + return;
93367 +
93368 + for (num = 1; num <= MAX_PARAM; num++)
93369 + if (hash->param & (1U << num))
93370 + handle_function_arg(stmt, fndecl, num - 1);
93371 +}
93372 +
93373 +static void set_plf_false(void)
93374 +{
93375 + basic_block bb;
93376 +
93377 + FOR_ALL_BB(bb) {
93378 + gimple_stmt_iterator si;
93379 +
93380 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
93381 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
93382 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
93383 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
93384 + }
93385 +}
93386 +
93387 +static unsigned int handle_function(void)
93388 +{
93389 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
93390 +
93391 + set_plf_false();
93392 +
93393 + do {
93394 + gimple_stmt_iterator gsi;
93395 + next = bb->next_bb;
93396 +
93397 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
93398 + tree fndecl, attr;
93399 + gimple stmt = gsi_stmt(gsi);
93400 +
93401 + if (!(is_gimple_call(stmt)))
93402 + continue;
93403 + fndecl = gimple_call_fndecl(stmt);
93404 + if (fndecl == NULL_TREE)
93405 + continue;
93406 + if (gimple_call_num_args(stmt) == 0)
93407 + continue;
93408 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
93409 + if (!attr || !TREE_VALUE(attr))
93410 + handle_function_by_hash(stmt, fndecl);
93411 + else
93412 + handle_function_by_attribute(stmt, attr, fndecl);
93413 + gsi = gsi_for_stmt(stmt);
93414 + next = gimple_bb(stmt)->next_bb;
93415 + }
93416 + bb = next;
93417 + } while (bb);
93418 + return 0;
93419 +}
93420 +
93421 +static struct gimple_opt_pass size_overflow_pass = {
93422 + .pass = {
93423 + .type = GIMPLE_PASS,
93424 + .name = "size_overflow",
93425 +#if BUILDING_GCC_VERSION >= 4008
93426 + .optinfo_flags = OPTGROUP_NONE,
93427 +#endif
93428 + .gate = NULL,
93429 + .execute = handle_function,
93430 + .sub = NULL,
93431 + .next = NULL,
93432 + .static_pass_number = 0,
93433 + .tv_id = TV_NONE,
93434 + .properties_required = PROP_cfg,
93435 + .properties_provided = 0,
93436 + .properties_destroyed = 0,
93437 + .todo_flags_start = 0,
93438 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
93439 + }
93440 +};
93441 +
93442 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
93443 +{
93444 + tree fntype;
93445 +
93446 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
93447 +
93448 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
93449 + fntype = build_function_type_list(void_type_node,
93450 + const_char_ptr_type_node,
93451 + unsigned_type_node,
93452 + const_char_ptr_type_node,
93453 + const_char_ptr_type_node,
93454 + NULL_TREE);
93455 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
93456 +
93457 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
93458 + TREE_PUBLIC(report_size_overflow_decl) = 1;
93459 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
93460 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
93461 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
93462 +}
93463 +
93464 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93465 +{
93466 + int i;
93467 + const char * const plugin_name = plugin_info->base_name;
93468 + const int argc = plugin_info->argc;
93469 + const struct plugin_argument * const argv = plugin_info->argv;
93470 + bool enable = true;
93471 +
93472 + struct register_pass_info size_overflow_pass_info = {
93473 + .pass = &size_overflow_pass.pass,
93474 + .reference_pass_name = "ssa",
93475 + .ref_pass_instance_number = 1,
93476 + .pos_op = PASS_POS_INSERT_AFTER
93477 + };
93478 +
93479 + if (!plugin_default_version_check(version, &gcc_version)) {
93480 + error(G_("incompatible gcc/plugin versions"));
93481 + return 1;
93482 + }
93483 +
93484 + for (i = 0; i < argc; ++i) {
93485 + if (!strcmp(argv[i].key, "no-size-overflow")) {
93486 + enable = false;
93487 + continue;
93488 + }
93489 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93490 + }
93491 +
93492 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
93493 + if (enable) {
93494 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
93495 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
93496 + }
93497 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
93498 +
93499 + return 0;
93500 +}
93501 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
93502 new file mode 100644
93503 index 0000000..ac2901e
93504 --- /dev/null
93505 +++ b/tools/gcc/stackleak_plugin.c
93506 @@ -0,0 +1,327 @@
93507 +/*
93508 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
93509 + * Licensed under the GPL v2
93510 + *
93511 + * Note: the choice of the license means that the compilation process is
93512 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
93513 + * but for the kernel it doesn't matter since it doesn't link against
93514 + * any of the gcc libraries
93515 + *
93516 + * gcc plugin to help implement various PaX features
93517 + *
93518 + * - track lowest stack pointer
93519 + *
93520 + * TODO:
93521 + * - initialize all local variables
93522 + *
93523 + * BUGS:
93524 + * - none known
93525 + */
93526 +#include "gcc-plugin.h"
93527 +#include "config.h"
93528 +#include "system.h"
93529 +#include "coretypes.h"
93530 +#include "tree.h"
93531 +#include "tree-pass.h"
93532 +#include "flags.h"
93533 +#include "intl.h"
93534 +#include "toplev.h"
93535 +#include "plugin.h"
93536 +//#include "expr.h" where are you...
93537 +#include "diagnostic.h"
93538 +#include "plugin-version.h"
93539 +#include "tm.h"
93540 +#include "function.h"
93541 +#include "basic-block.h"
93542 +#include "gimple.h"
93543 +#include "rtl.h"
93544 +#include "emit-rtl.h"
93545 +
93546 +#if BUILDING_GCC_VERSION >= 4008
93547 +#define TODO_dump_func 0
93548 +#endif
93549 +
93550 +extern void print_gimple_stmt(FILE *, gimple, int, int);
93551 +
93552 +int plugin_is_GPL_compatible;
93553 +
93554 +static int track_frame_size = -1;
93555 +static const char track_function[] = "pax_track_stack";
93556 +static const char check_function[] = "pax_check_alloca";
93557 +static bool init_locals;
93558 +
93559 +static struct plugin_info stackleak_plugin_info = {
93560 + .version = "201302112000",
93561 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
93562 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
93563 +};
93564 +
93565 +static bool gate_stackleak_track_stack(void);
93566 +static unsigned int execute_stackleak_tree_instrument(void);
93567 +static unsigned int execute_stackleak_final(void);
93568 +
93569 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
93570 + .pass = {
93571 + .type = GIMPLE_PASS,
93572 + .name = "stackleak_tree_instrument",
93573 +#if BUILDING_GCC_VERSION >= 4008
93574 + .optinfo_flags = OPTGROUP_NONE,
93575 +#endif
93576 + .gate = gate_stackleak_track_stack,
93577 + .execute = execute_stackleak_tree_instrument,
93578 + .sub = NULL,
93579 + .next = NULL,
93580 + .static_pass_number = 0,
93581 + .tv_id = TV_NONE,
93582 + .properties_required = PROP_gimple_leh | PROP_cfg,
93583 + .properties_provided = 0,
93584 + .properties_destroyed = 0,
93585 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
93586 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
93587 + }
93588 +};
93589 +
93590 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
93591 + .pass = {
93592 + .type = RTL_PASS,
93593 + .name = "stackleak_final",
93594 +#if BUILDING_GCC_VERSION >= 4008
93595 + .optinfo_flags = OPTGROUP_NONE,
93596 +#endif
93597 + .gate = gate_stackleak_track_stack,
93598 + .execute = execute_stackleak_final,
93599 + .sub = NULL,
93600 + .next = NULL,
93601 + .static_pass_number = 0,
93602 + .tv_id = TV_NONE,
93603 + .properties_required = 0,
93604 + .properties_provided = 0,
93605 + .properties_destroyed = 0,
93606 + .todo_flags_start = 0,
93607 + .todo_flags_finish = TODO_dump_func
93608 + }
93609 +};
93610 +
93611 +static bool gate_stackleak_track_stack(void)
93612 +{
93613 + return track_frame_size >= 0;
93614 +}
93615 +
93616 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
93617 +{
93618 + gimple check_alloca;
93619 + tree fntype, fndecl, alloca_size;
93620 +
93621 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
93622 + fndecl = build_fn_decl(check_function, fntype);
93623 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
93624 +
93625 + // insert call to void pax_check_alloca(unsigned long size)
93626 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
93627 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
93628 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
93629 +}
93630 +
93631 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
93632 +{
93633 + gimple track_stack;
93634 + tree fntype, fndecl;
93635 +
93636 + fntype = build_function_type_list(void_type_node, NULL_TREE);
93637 + fndecl = build_fn_decl(track_function, fntype);
93638 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
93639 +
93640 + // insert call to void pax_track_stack(void)
93641 + track_stack = gimple_build_call(fndecl, 0);
93642 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
93643 +}
93644 +
93645 +#if BUILDING_GCC_VERSION == 4005
93646 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
93647 +{
93648 + tree fndecl;
93649 +
93650 + if (!is_gimple_call(stmt))
93651 + return false;
93652 + fndecl = gimple_call_fndecl(stmt);
93653 + if (!fndecl)
93654 + return false;
93655 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
93656 + return false;
93657 +// print_node(stderr, "pax", fndecl, 4);
93658 + return DECL_FUNCTION_CODE(fndecl) == code;
93659 +}
93660 +#endif
93661 +
93662 +static bool is_alloca(gimple stmt)
93663 +{
93664 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
93665 + return true;
93666 +
93667 +#if BUILDING_GCC_VERSION >= 4007
93668 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
93669 + return true;
93670 +#endif
93671 +
93672 + return false;
93673 +}
93674 +
93675 +static unsigned int execute_stackleak_tree_instrument(void)
93676 +{
93677 + basic_block bb, entry_bb;
93678 + bool prologue_instrumented = false, is_leaf = true;
93679 +
93680 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
93681 +
93682 + // 1. loop through BBs and GIMPLE statements
93683 + FOR_EACH_BB(bb) {
93684 + gimple_stmt_iterator gsi;
93685 +
93686 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
93687 + gimple stmt;
93688 +
93689 + stmt = gsi_stmt(gsi);
93690 +
93691 + if (is_gimple_call(stmt))
93692 + is_leaf = false;
93693 +
93694 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
93695 + if (!is_alloca(stmt))
93696 + continue;
93697 +
93698 + // 2. insert stack overflow check before each __builtin_alloca call
93699 + stackleak_check_alloca(&gsi);
93700 +
93701 + // 3. insert track call after each __builtin_alloca call
93702 + stackleak_add_instrumentation(&gsi);
93703 + if (bb == entry_bb)
93704 + prologue_instrumented = true;
93705 + }
93706 + }
93707 +
93708 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
93709 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
93710 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
93711 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
93712 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
93713 + return 0;
93714 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
93715 + return 0;
93716 +
93717 + // 4. insert track call at the beginning
93718 + if (!prologue_instrumented) {
93719 + gimple_stmt_iterator gsi;
93720 +
93721 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
93722 + if (dom_info_available_p(CDI_DOMINATORS))
93723 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
93724 + gsi = gsi_start_bb(bb);
93725 + stackleak_add_instrumentation(&gsi);
93726 + }
93727 +
93728 + return 0;
93729 +}
93730 +
93731 +static unsigned int execute_stackleak_final(void)
93732 +{
93733 + rtx insn, next;
93734 +
93735 + if (cfun->calls_alloca)
93736 + return 0;
93737 +
93738 + // keep calls only if function frame is big enough
93739 + if (get_frame_size() >= track_frame_size)
93740 + return 0;
93741 +
93742 + // 1. find pax_track_stack calls
93743 + for (insn = get_insns(); insn; insn = next) {
93744 + // rtl match: (call_insn 8 7 9 3 (call (mem (symbol_ref ("pax_track_stack") [flags 0x41] <function_decl 0xb7470e80 pax_track_stack>) [0 S1 A8]) (4)) -1 (nil) (nil))
93745 + rtx body;
93746 +
93747 + next = NEXT_INSN(insn);
93748 + if (!CALL_P(insn))
93749 + continue;
93750 + body = PATTERN(insn);
93751 + if (GET_CODE(body) != CALL)
93752 + continue;
93753 + body = XEXP(body, 0);
93754 + if (GET_CODE(body) != MEM)
93755 + continue;
93756 + body = XEXP(body, 0);
93757 + if (GET_CODE(body) != SYMBOL_REF)
93758 + continue;
93759 + if (strcmp(XSTR(body, 0), track_function))
93760 + continue;
93761 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
93762 + // 2. delete call
93763 + delete_insn_and_edges(insn);
93764 +#if BUILDING_GCC_VERSION >= 4007
93765 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
93766 + insn = next;
93767 + next = NEXT_INSN(insn);
93768 + delete_insn_and_edges(insn);
93769 + }
93770 +#endif
93771 + }
93772 +
93773 +// print_simple_rtl(stderr, get_insns());
93774 +// print_rtl(stderr, get_insns());
93775 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
93776 +
93777 + return 0;
93778 +}
93779 +
93780 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93781 +{
93782 + const char * const plugin_name = plugin_info->base_name;
93783 + const int argc = plugin_info->argc;
93784 + const struct plugin_argument * const argv = plugin_info->argv;
93785 + int i;
93786 + struct register_pass_info stackleak_tree_instrument_pass_info = {
93787 + .pass = &stackleak_tree_instrument_pass.pass,
93788 +// .reference_pass_name = "tree_profile",
93789 + .reference_pass_name = "optimized",
93790 + .ref_pass_instance_number = 1,
93791 + .pos_op = PASS_POS_INSERT_BEFORE
93792 + };
93793 + struct register_pass_info stackleak_final_pass_info = {
93794 + .pass = &stackleak_final_rtl_opt_pass.pass,
93795 + .reference_pass_name = "final",
93796 + .ref_pass_instance_number = 1,
93797 + .pos_op = PASS_POS_INSERT_BEFORE
93798 + };
93799 +
93800 + if (!plugin_default_version_check(version, &gcc_version)) {
93801 + error(G_("incompatible gcc/plugin versions"));
93802 + return 1;
93803 + }
93804 +
93805 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
93806 +
93807 + for (i = 0; i < argc; ++i) {
93808 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
93809 + if (!argv[i].value) {
93810 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93811 + continue;
93812 + }
93813 + track_frame_size = atoi(argv[i].value);
93814 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
93815 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
93816 + continue;
93817 + }
93818 + if (!strcmp(argv[i].key, "initialize-locals")) {
93819 + if (argv[i].value) {
93820 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
93821 + continue;
93822 + }
93823 + init_locals = true;
93824 + continue;
93825 + }
93826 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
93827 + }
93828 +
93829 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
93830 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
93831 +
93832 + return 0;
93833 +}
93834 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
93835 index 6789d78..4afd019e 100644
93836 --- a/tools/perf/util/include/asm/alternative-asm.h
93837 +++ b/tools/perf/util/include/asm/alternative-asm.h
93838 @@ -5,4 +5,7 @@
93839
93840 #define altinstruction_entry #
93841
93842 + .macro pax_force_retaddr rip=0, reload=0
93843 + .endm
93844 +
93845 #endif
93846 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
93847 index 1cd693a..f4a7b20 100644
93848 --- a/virt/kvm/kvm_main.c
93849 +++ b/virt/kvm/kvm_main.c
93850 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
93851
93852 static cpumask_var_t cpus_hardware_enabled;
93853 static int kvm_usage_count = 0;
93854 -static atomic_t hardware_enable_failed;
93855 +static atomic_unchecked_t hardware_enable_failed;
93856
93857 struct kmem_cache *kvm_vcpu_cache;
93858 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
93859
93860 -static __read_mostly struct preempt_ops kvm_preempt_ops;
93861 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
93862 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
93863 +static struct preempt_ops kvm_preempt_ops = {
93864 + .sched_in = kvm_sched_in,
93865 + .sched_out = kvm_sched_out,
93866 +};
93867
93868 struct dentry *kvm_debugfs_dir;
93869
93870 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
93871 /* We can read the guest memory with __xxx_user() later on. */
93872 if (user_alloc &&
93873 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
93874 - !access_ok(VERIFY_WRITE,
93875 + !__access_ok(VERIFY_WRITE,
93876 (void __user *)(unsigned long)mem->userspace_addr,
93877 mem->memory_size)))
93878 goto out;
93879 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
93880 return 0;
93881 }
93882
93883 -static struct file_operations kvm_vcpu_fops = {
93884 +static file_operations_no_const kvm_vcpu_fops __read_only = {
93885 .release = kvm_vcpu_release,
93886 .unlocked_ioctl = kvm_vcpu_ioctl,
93887 #ifdef CONFIG_COMPAT
93888 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
93889 return 0;
93890 }
93891
93892 -static struct file_operations kvm_vm_fops = {
93893 +static file_operations_no_const kvm_vm_fops __read_only = {
93894 .release = kvm_vm_release,
93895 .unlocked_ioctl = kvm_vm_ioctl,
93896 #ifdef CONFIG_COMPAT
93897 @@ -2402,7 +2407,7 @@ out:
93898 return r;
93899 }
93900
93901 -static struct file_operations kvm_chardev_ops = {
93902 +static file_operations_no_const kvm_chardev_ops __read_only = {
93903 .unlocked_ioctl = kvm_dev_ioctl,
93904 .compat_ioctl = kvm_dev_ioctl,
93905 .llseek = noop_llseek,
93906 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
93907
93908 if (r) {
93909 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
93910 - atomic_inc(&hardware_enable_failed);
93911 + atomic_inc_unchecked(&hardware_enable_failed);
93912 printk(KERN_INFO "kvm: enabling virtualization on "
93913 "CPU%d failed\n", cpu);
93914 }
93915 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
93916
93917 kvm_usage_count++;
93918 if (kvm_usage_count == 1) {
93919 - atomic_set(&hardware_enable_failed, 0);
93920 + atomic_set_unchecked(&hardware_enable_failed, 0);
93921 on_each_cpu(hardware_enable_nolock, NULL, 1);
93922
93923 - if (atomic_read(&hardware_enable_failed)) {
93924 + if (atomic_read_unchecked(&hardware_enable_failed)) {
93925 hardware_disable_all_nolock();
93926 r = -EBUSY;
93927 }
93928 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
93929 kvm_arch_vcpu_put(vcpu);
93930 }
93931
93932 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93933 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93934 struct module *module)
93935 {
93936 int r;
93937 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93938 if (!vcpu_align)
93939 vcpu_align = __alignof__(struct kvm_vcpu);
93940 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
93941 - 0, NULL);
93942 + SLAB_USERCOPY, NULL);
93943 if (!kvm_vcpu_cache) {
93944 r = -ENOMEM;
93945 goto out_free_3;
93946 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93947 if (r)
93948 goto out_free;
93949
93950 + pax_open_kernel();
93951 kvm_chardev_ops.owner = module;
93952 kvm_vm_fops.owner = module;
93953 kvm_vcpu_fops.owner = module;
93954 + pax_close_kernel();
93955
93956 r = misc_register(&kvm_dev);
93957 if (r) {
93958 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
93959
93960 register_syscore_ops(&kvm_syscore_ops);
93961
93962 - kvm_preempt_ops.sched_in = kvm_sched_in;
93963 - kvm_preempt_ops.sched_out = kvm_sched_out;
93964 -
93965 r = kvm_init_debug();
93966 if (r) {
93967 printk(KERN_ERR "kvm: create debugfs files failed\n");